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