root / trunk / extensions / extWMS / src / com / iver / cit / gvsig / gui / panels / LayerTree.java @ 4508
History | View | Annotate | Download (6.19 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 4508 2006-03-21 17:50:19Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.5 2006-03-21 17:49:04 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.4 2006/02/28 15:25:14 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.2.2.4 2006/02/17 12:57:34 jaume
|
53 |
* 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
|
54 |
*
|
55 |
* Revision 1.2.2.3 2006/01/31 16:25:24 jaume
|
56 |
* correcciones de bugs
|
57 |
*
|
58 |
* Revision 1.3 2006/01/26 16:07:14 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.2.2.1 2006/01/26 12:59:32 jaume
|
62 |
* 0.5
|
63 |
*
|
64 |
* Revision 1.2 2006/01/24 14:36:33 jaume
|
65 |
* This is the new version
|
66 |
*
|
67 |
* Revision 1.1.2.1 2006/01/17 12:56:03 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
*
|
71 |
*/
|
72 |
/**
|
73 |
*
|
74 |
*/
|
75 |
package com.iver.cit.gvsig.gui.panels; |
76 |
|
77 |
import java.awt.Component; |
78 |
import java.awt.Dimension; |
79 |
|
80 |
import javax.swing.JToolTip; |
81 |
import javax.swing.JTree; |
82 |
import javax.swing.ToolTipManager; |
83 |
import javax.swing.tree.DefaultTreeCellRenderer; |
84 |
|
85 |
import com.iver.andami.PluginServices; |
86 |
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode; |
87 |
import com.iver.cit.gvsig.gui.beans.controls.MultiLineToolTip; |
88 |
|
89 |
/**
|
90 |
* LayerTree extends the standard JTree class to allow use custom tooltips.
|
91 |
* It is just JTree containing WMSLayerNode at its nodes.
|
92 |
*
|
93 |
* @author jaume
|
94 |
*
|
95 |
*/
|
96 |
public class LayerTree extends JTree { |
97 |
public boolean showLayerNames = false; |
98 |
private int count = 0; |
99 |
public LayerTree(){
|
100 |
super();
|
101 |
ToolTipManager.sharedInstance().registerComponent(this); |
102 |
ToolTipManager.sharedInstance().setDismissDelay(60*1000); |
103 |
setCellRenderer(new MyRenderer());
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* Layer tree specific renderer allowing to show multiple line
|
108 |
* tooltips
|
109 |
* @author jaume
|
110 |
*
|
111 |
*/
|
112 |
private class MyRenderer extends DefaultTreeCellRenderer { |
113 |
|
114 |
|
115 |
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { |
116 |
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
|
117 |
if (value instanceof WMSLayerNode){ |
118 |
WMSLayerNode layer = (WMSLayerNode) value; |
119 |
|
120 |
String myLatLonTxt = layer.getLatLonBox();
|
121 |
if (myLatLonTxt == null) |
122 |
myLatLonTxt = "-";
|
123 |
|
124 |
String myAbstract = layer.getAbstract();
|
125 |
|
126 |
if (myAbstract == null) |
127 |
myAbstract = "-";
|
128 |
else
|
129 |
myAbstract = format(myAbstract.trim(), 100);
|
130 |
|
131 |
String text =
|
132 |
PluginServices.getText(this, "abstract") + ":\n" + myAbstract + |
133 |
"\n\n" +
|
134 |
PluginServices.getText(this, "covered_extension") + ":\n" + myLatLonTxt; |
135 |
|
136 |
setToolTipText(text); |
137 |
|
138 |
if (!showLayerNames) {
|
139 |
if (layer.getName() != null || layer.getName() == "") { |
140 |
text = layer.toString(); |
141 |
text = text.substring(text.indexOf(']')+2, text.length()); |
142 |
setText(text); |
143 |
} |
144 |
} |
145 |
|
146 |
// Dimension sz = getPreferredSize();
|
147 |
// sz.setSize((sz.getWidth()+50) - (3*count), sz.getHeight());
|
148 |
// setPreferredSize(sz);
|
149 |
// count++;
|
150 |
|
151 |
} else {
|
152 |
setToolTipText(null);
|
153 |
} |
154 |
return this; |
155 |
} |
156 |
} |
157 |
|
158 |
|
159 |
/**
|
160 |
* Cuts the message text to force its lines to be shorter or equal to
|
161 |
* lineLength.
|
162 |
* @param message, the message.
|
163 |
* @param lineLength, the max line length in number of characters.
|
164 |
* @return the formated message.
|
165 |
*/
|
166 |
public static String format(String message, int lineLength){ |
167 |
if (message.length() <= lineLength) return message; |
168 |
String[] lines = message.split("\n"); |
169 |
String theMessage = ""; |
170 |
for (int i = 0; i < lines.length; i++) { |
171 |
String line = lines[i].trim();
|
172 |
if (line.length()<lineLength)
|
173 |
theMessage += line+"\n";
|
174 |
else {
|
175 |
String[] chunks = line.split(" "); |
176 |
String newLine = ""; |
177 |
for (int j = 0; j < chunks.length; j++) { |
178 |
int currentLength = newLine.length();
|
179 |
chunks[j] = chunks[j].trim(); |
180 |
if (chunks[j].length()==0) |
181 |
continue;
|
182 |
if ((currentLength + chunks[j].length() + " ".length()) <= lineLength) |
183 |
newLine += chunks[j] + " ";
|
184 |
else {
|
185 |
newLine += "\n"+chunks[j]+" "; |
186 |
theMessage += newLine; |
187 |
newLine = "";
|
188 |
} |
189 |
} |
190 |
} |
191 |
} |
192 |
return theMessage;
|
193 |
} |
194 |
|
195 |
public JToolTip createToolTip() { |
196 |
MultiLineToolTip tip = new MultiLineToolTip();
|
197 |
tip.setComponent(this);
|
198 |
return tip;
|
199 |
} |
200 |
} |