svn-gvsig-desktop / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / LayerList.java @ 4911
History | View | Annotate | Download (4.54 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 |
package com.iver.cit.gvsig.gui.panels; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.Dimension; |
45 |
|
46 |
import javax.swing.DefaultListCellRenderer; |
47 |
import javax.swing.JList; |
48 |
|
49 |
import com.iver.andami.PluginServices; |
50 |
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode; |
51 |
|
52 |
/**
|
53 |
* Class implementing a JList component adapted to the WCSLayer needs, such as a
|
54 |
* multiline tooltip.
|
55 |
*
|
56 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
57 |
*
|
58 |
*/
|
59 |
public class LayerList extends JList { |
60 |
/**
|
61 |
*
|
62 |
*/
|
63 |
private static final long serialVersionUID = 5939037011302925975L; |
64 |
|
65 |
public boolean showLayerNames = false; |
66 |
|
67 |
private int count = 0; |
68 |
|
69 |
public LayerList() {
|
70 |
super();
|
71 |
setCellRenderer(new MyRenderer());
|
72 |
} |
73 |
|
74 |
private class MyRenderer extends DefaultListCellRenderer { |
75 |
/**
|
76 |
*
|
77 |
*/
|
78 |
private static final long serialVersionUID = -330306573320034784L; |
79 |
|
80 |
public Component getListCellRendererComponent(JList list, Object value, |
81 |
int index, boolean isSelected, boolean cellHasFocus) { |
82 |
super.getListCellRendererComponent(list, value, index, isSelected,
|
83 |
cellHasFocus); |
84 |
if (value instanceof WFSLayerNode) { |
85 |
WFSLayerNode layer = (WFSLayerNode) value; |
86 |
|
87 |
if (!showLayerNames) {
|
88 |
if (layer.getName() != null || layer.getName() == "") { |
89 |
String text = layer.toString();
|
90 |
text = text.substring(text.indexOf(']') + 2, text |
91 |
.length()); |
92 |
setText(text); |
93 |
} |
94 |
} |
95 |
String myAbstract = layer.getAbstract();
|
96 |
// String myLonLatTxt = layer.getLonLatEnvelope();
|
97 |
|
98 |
if (myAbstract == null) |
99 |
myAbstract = "-";
|
100 |
else
|
101 |
myAbstract = format(myAbstract.trim(), 100);
|
102 |
String text = PluginServices.getText(this, "abstract") + ":\n" |
103 |
+ myAbstract + "\n\n"
|
104 |
+ PluginServices.getText(this, "covered_extension"); |
105 |
// + ":\n" + myLonLatTxt;
|
106 |
|
107 |
setToolTipText(text); |
108 |
|
109 |
Dimension sz = getPreferredSize();
|
110 |
sz.setSize((sz.getWidth() + 50) - (50 * count), sz.getHeight()); |
111 |
setPreferredSize(sz); |
112 |
count++; |
113 |
} |
114 |
return this; |
115 |
} |
116 |
} |
117 |
|
118 |
// public JToolTip createToolTip() {
|
119 |
// MultiLineToolTip tip = new MultiLineToolTip();
|
120 |
// tip.setComponent(this);
|
121 |
// return tip;
|
122 |
// }
|
123 |
|
124 |
/**
|
125 |
* Cuts the message text to force its lines to be shorter or equal to
|
126 |
* lineLength.
|
127 |
*
|
128 |
* @param message,
|
129 |
* the message.
|
130 |
* @param lineLength,
|
131 |
* the max line length in number of characters.
|
132 |
* @return the formated message.
|
133 |
*/
|
134 |
public static String format(String message, int lineLength) { |
135 |
if (message.length() <= lineLength)
|
136 |
return message;
|
137 |
String[] lines = message.split("\n"); |
138 |
String theMessage = ""; |
139 |
for (int i = 0; i < lines.length; i++) { |
140 |
String line = lines[i].trim();
|
141 |
if (line.length() < lineLength)
|
142 |
theMessage += line + "\n";
|
143 |
else {
|
144 |
String[] chunks = line.split(" "); |
145 |
String newLine = ""; |
146 |
for (int j = 0; j < chunks.length; j++) { |
147 |
int currentLength = newLine.length();
|
148 |
chunks[j] = chunks[j].trim(); |
149 |
if (chunks[j].length() == 0) |
150 |
continue;
|
151 |
if ((currentLength + chunks[j].length() + " ".length()) <= lineLength) |
152 |
newLine += chunks[j] + " ";
|
153 |
else {
|
154 |
newLine += "\n" + chunks[j] + " "; |
155 |
theMessage += newLine; |
156 |
newLine = "";
|
157 |
} |
158 |
} |
159 |
} |
160 |
} |
161 |
return theMessage;
|
162 |
} |
163 |
|
164 |
/**
|
165 |
* Adds a vector of features
|
166 |
* @param features
|
167 |
*/
|
168 |
public void addFeatures(Object[] features){ |
169 |
this.setListData(features);
|
170 |
} |
171 |
} |