Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_905 / libraries / libIverUtiles / src / com / iver / utiles / connections / ConnRenderer.java @ 10767

History | View | Annotate | Download (4.74 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.utiles.connections;
42

    
43
import java.awt.Component;
44

    
45
import javax.swing.ImageIcon;
46
import javax.swing.JTree;
47
import javax.swing.tree.DefaultMutableTreeNode;
48
import javax.swing.tree.DefaultTreeCellRenderer;
49

    
50

    
51

    
52
/**
53
 * Renderer of the JTree.
54
 *
55
 * @author Vicente Caballero Navarro
56
 */
57
public class ConnRenderer extends DefaultTreeCellRenderer {
58
        //private static final ImageIcon bdConnectIcon= new ImageIcon(ConnRenderer.class.getClassLoader()
59
        //                  .getResource("images/gtk-ok.png"));
60
        
61
        //private String directory=PluginServices.getPluginServices(this)
62
        //  .getPluginDirectory().getPath();
63
private String directory=null;
64
        private static ImageIcon bdConnectIcon = null;
65
        private static ImageIcon bdConnectkeyIcon = null;
66
    private static ImageIcon bdNoConnectIcon = null;
67
    private static ImageIcon bdNoConnectkeyIcon = null;
68
    private static ImageIcon tableIcon = null;
69
        
70
    public ConnRenderer(){
71
    directory=".";
72
            
73
        bdConnectIcon = new ImageIcon(ConnRenderer.class.getResource(
74
        "images/gtk-ok.png"));
75
        bdConnectkeyIcon = new ImageIcon(ConnRenderer.class.getResource(
76
        "images/gtk-ok-key.png"));
77
    bdNoConnectIcon = new ImageIcon(ConnRenderer.class.getResource(
78
        "images/gtk-no.png"));
79
    bdNoConnectkeyIcon = new ImageIcon(ConnRenderer.class.getResource(
80
        "images/gtk-no-key.png"));
81
    tableIcon = new ImageIcon(ConnRenderer.class.getResource(
82
        "images/gtk-properties.png"));
83
   }
84
    public Component getTreeCellRendererComponent(JTree tree, Object value,
85
        boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
86
        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
87
            row, hasFocus);
88

    
89
        if (isConnection(value)) {
90
            if (isConnected(value)) {
91
                    if (havePassword(value))
92
                            setIcon(bdConnectIcon); //Conectado
93
                    else
94
                            setIcon(bdConnectkeyIcon); //Conectado sin clave
95
            } else {
96
                    if (havePassword(value))
97
                            setIcon(bdNoConnectIcon); //Desconectado
98
                    else
99
                            setIcon(bdNoConnectkeyIcon); //Desconectado sin clave
100
            }
101
        } else {
102
            setIcon(tableIcon);
103
        }
104

    
105
        return this;
106
    }
107

    
108
    /**
109
     * Returns true if is a connection.
110
     *
111
     * @param value Tree?s node.
112
     *
113
     * @return True if is a connection.
114
     */
115
    private boolean isConnection(Object value) {
116
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
117
        if (node.getUserObject() instanceof ConnectionTrans) {
118
            return true;
119
        }
120
        return false;
121
    }
122

    
123
    /**
124
     * Returns true if the connection that is passed for parameter is connected.
125
     *
126
     * @param value Tree?s node.
127
     *
128
     * @return True if is connected.
129
     */
130
    private boolean isConnected(Object value) {
131
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
132
        if (node.getUserObject() instanceof ConnectionTrans) {
133
                ConnectionTrans connTrans=(ConnectionTrans) node.getUserObject();
134
                return connTrans.isConnected();
135
        }
136
        return false;
137
    }
138
    
139
    /**
140
     * Returns true if the connection has kept the password.
141
     *
142
     * @param value Tree?s node.
143
     *
144
     * @return True if is connected.
145
     */
146
    private boolean havePassword(Object value){
147
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
148
        if (node.getUserObject() instanceof ConnectionTrans) {
149
                ConnectionTrans connTrans=(ConnectionTrans) node.getUserObject();
150
                return connTrans.isSavePassword();
151
        }
152
        return false;
153
    }
154
}