Statistics
| Revision:

root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / LayerTree.java @ 4886

History | View | Annotate | Download (6.41 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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

    
42
/* CVS MESSAGES:
43
*
44
* $Id: LayerTree.java 4886 2006-04-19 12:50:16Z jorpiell $
45
* $Log$
46
* Revision 1.1  2006-04-19 12:50:16  jorpiell
47
* Primer commit de la aplicaci?n. Se puede hacer un getCapabilities y ver el mensaje de vienvenida del servidor
48
*
49
* Revision 1.6  2006/03/27 15:10:06  jaume
50
* images moved to libUI, and some code clean up
51
*
52
* Revision 1.5  2006/03/21 17:49:04  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.4  2006/02/28 15:25:14  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.2.2.4  2006/02/17 12:57:34  jaume
59
* oculta/eXconde los nombres de las capas y adem?s corrige el error de selecci?n de varios styles si hay alguna capa seleccionada repetida
60
*
61
* Revision 1.2.2.3  2006/01/31 16:25:24  jaume
62
* correcciones de bugs
63
*
64
* Revision 1.3  2006/01/26 16:07:14  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.2.2.1  2006/01/26 12:59:32  jaume
68
* 0.5
69
*
70
* Revision 1.2  2006/01/24 14:36:33  jaume
71
* This is the new version
72
*
73
* Revision 1.1.2.1  2006/01/17 12:56:03  jaume
74
* *** empty log message ***
75
*
76
*
77
*/
78
/**
79
 * 
80
 */
81
package com.iver.cit.gvsig.gui.panels;
82

    
83
import java.awt.Component;
84

    
85
import javax.swing.JToolTip;
86
import javax.swing.JTree;
87
import javax.swing.ToolTipManager;
88
import javax.swing.tree.DefaultTreeCellRenderer;
89

    
90
import org.gvsig.gui.beans.controls.MultiLineToolTip;
91

    
92
import com.iver.andami.PluginServices;
93
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
94

    
95
/**
96
 * LayerTree extends the standard JTree class to allow use custom tooltips.
97
 * It is just JTree containing WMSLayerNode at its nodes.
98
 * 
99
 * @author jaume
100
 *
101
 */
102
public class LayerTree extends JTree {
103
        public boolean showLayerNames = false;
104
        private int count = 0;
105
        public LayerTree(){
106
        super();
107
        ToolTipManager.sharedInstance().registerComponent(this);
108
        ToolTipManager.sharedInstance().setDismissDelay(60*1000);
109
        setCellRenderer(new MyRenderer());
110
    }
111

    
112
    /**
113
     * Layer tree specific renderer allowing to show multiple line
114
     * tooltips 
115
     * @author jaume
116
     *
117
     */
118
    private class MyRenderer extends DefaultTreeCellRenderer {
119
       
120
        
121
       public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
122
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
123
            if (value instanceof WFSLayerNode){
124
                WFSLayerNode layer = (WFSLayerNode) value;
125
                
126
//                String myLatLonTxt = layer.getLatLonBox();
127
//                if (myLatLonTxt == null)
128
//                    myLatLonTxt = "-";
129
//                
130
                String myAbstract = layer.getDescription();
131
                
132
                if (myAbstract == null)
133
                    myAbstract = "-";
134
                else 
135
                    myAbstract = format(myAbstract.trim(), 100);
136
                
137
                String text =
138
                    PluginServices.getText(this, "abstract") + ":\n" + myAbstract +
139
                    "\n\n";
140
//                    PluginServices.getText(this, "covered_extension") + ":\n" + myLatLonTxt;
141
                
142
                setToolTipText(text);
143
                
144
                if (!showLayerNames) {
145
                        if (layer.getName() != null || layer.getName() == "") {
146
                                text = layer.toString();
147
                                text = text.substring(text.indexOf(']')+2, text.length());
148
                                setText(text);
149
                        }
150
                }
151
                
152
//                Dimension sz  = getPreferredSize();
153
//                sz.setSize((sz.getWidth()+50) - (3*count), sz.getHeight());
154
//                setPreferredSize(sz);
155
//                count++;
156
                
157
            } else {
158
                setToolTipText(null);
159
            }
160
            return this;
161
        }
162
    }
163
    
164
    
165
    /**
166
     * Cuts the message text to force its lines to be shorter or equal to 
167
     * lineLength.
168
     * @param message, the message.
169
     * @param lineLength, the max line length in number of characters.
170
     * @return the formated message.
171
     */
172
    public static String format(String message, int lineLength){
173
        if (message.length() <= lineLength) return message;
174
        String[] lines = message.split("\n");
175
        String theMessage = "";
176
        for (int i = 0; i < lines.length; i++) {
177
            String line = lines[i].trim();
178
            if (line.length()<lineLength)
179
                theMessage += line+"\n";
180
            else {
181
                String[] chunks = line.split(" ");
182
                String newLine = "";
183
                for (int j = 0; j < chunks.length; j++) {
184
                    int currentLength = newLine.length();
185
                    chunks[j] = chunks[j].trim();
186
                    if (chunks[j].length()==0)
187
                        continue;
188
                    if ((currentLength + chunks[j].length() + " ".length()) <= lineLength)
189
                        newLine += chunks[j] + " ";
190
                    else {
191
                        newLine += "\n"+chunks[j]+" ";
192
                        theMessage += newLine;
193
                        newLine = "";
194
                    }
195
                }
196
            }
197
        }
198
        return theMessage;
199
    }
200
    
201
    public JToolTip createToolTip() {
202
            MultiLineToolTip tip = new MultiLineToolTip();
203
            tip.setComponent(this);
204
            return tip;
205
    }
206
}