Revision 10293 branches/simbologia/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/GraduatedSymbols.java
GraduatedSymbols.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.1.2.1 2007-02-12 15:14:41 jaume |
|
46 |
* Revision 1.1.2.2 2007-02-13 16:19:19 jaume |
|
47 |
* graduated symbol legends (start commiting) |
|
48 |
* |
|
49 |
* Revision 1.1.2.1 2007/02/12 15:14:41 jaume |
|
47 | 50 |
* refactored interval legend and added graduated symbol legend |
48 | 51 |
* |
49 | 52 |
* |
50 | 53 |
*/ |
51 | 54 |
package com.iver.cit.gvsig.project.documents.view.legend.gui; |
52 | 55 |
|
56 |
import java.awt.Color; |
|
57 |
import java.awt.Dimension; |
|
53 | 58 |
import java.awt.FlowLayout; |
59 |
import java.awt.event.ActionEvent; |
|
60 |
import java.awt.event.ActionListener; |
|
61 |
import java.text.NumberFormat; |
|
54 | 62 |
|
55 | 63 |
import javax.swing.BorderFactory; |
56 | 64 |
import javax.swing.JLabel; |
65 |
import javax.swing.JOptionPane; |
|
57 | 66 |
import javax.swing.JPanel; |
58 | 67 |
|
59 | 68 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
60 | 69 |
|
61 | 70 |
import com.iver.andami.PluginServices; |
71 |
import com.iver.andami.messages.NotificationManager; |
|
62 | 72 |
import com.iver.cit.gvsig.fmap.DriverException; |
73 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
63 | 74 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
75 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
|
76 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
|
77 |
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
|
78 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol; |
|
79 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol; |
|
64 | 80 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
65 | 81 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
66 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
|
|
82 |
import com.iver.cit.gvsig.fmap.rendering.FInterval;
|
|
67 | 83 |
import com.iver.cit.gvsig.fmap.rendering.GraduatedSymbolLegend; |
68 | 84 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
69 |
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend; |
|
85 |
import com.iver.cit.gvsig.fmap.rendering.NullIntervalValue; |
|
86 |
import com.iver.cit.gvsig.gui.styling.SymbolSelector; |
|
70 | 87 |
|
71 | 88 |
import de.ios.framework.swing.JNumberField; |
72 | 89 |
|
... | ... | |
74 | 91 |
|
75 | 92 |
private JNumberField txtMinSize; |
76 | 93 |
private JNumberField txtMaxSize; |
77 |
private Legend oldLegend; |
|
94 |
private ISymbol templateSymbol; |
|
95 |
private JSymbolPreviewButton btnTemplate; |
|
96 |
private int shapeType; |
|
78 | 97 |
|
79 | 98 |
public JPanel getOptionPanel() { |
80 | 99 |
if (optionPanel == null) { |
81 | 100 |
optionPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
82 | 101 |
optionPanel.setBorder(BorderFactory. |
83 | 102 |
createTitledBorder(null, |
84 |
PluginServices.getText(this, "symbol_size")));
|
|
103 |
PluginServices.getText(this, "symbol"))); |
|
85 | 104 |
|
86 | 105 |
GridBagLayoutPanel aux = new GridBagLayoutPanel(); |
106 |
aux.addComponent(new JLabel(PluginServices.getText(this, "size"))); |
|
87 | 107 |
aux.addComponent(PluginServices.getText(this, "from")+":", |
88 | 108 |
getTxtMinSize()); |
89 | 109 |
aux.addComponent(PluginServices.getText(this, "to")+":", |
90 | 110 |
getTxtMaxSize()); |
111 |
aux.addComponent(PluginServices.getText(this, "template"), getBtnTemplate()); |
|
91 | 112 |
optionPanel.add(aux); |
92 | 113 |
|
93 | 114 |
} |
94 | 115 |
return optionPanel; |
95 | 116 |
} |
96 | 117 |
|
118 |
private JSymbolPreviewButton getBtnTemplate() { |
|
119 |
if (btnTemplate == null) { |
|
120 |
btnTemplate = new JSymbolPreviewButton(); |
|
121 |
btnTemplate.addActionListener(new ActionListener() { |
|
122 |
public void actionPerformed(ActionEvent e) { |
|
123 |
SymbolSelector sSelect = new SymbolSelector(templateSymbol, shapeType); |
|
124 |
PluginServices.getMDIManager().addWindow(sSelect); |
|
125 |
templateSymbol = sSelect.getSymbol(); |
|
126 |
btnTemplate.setSymbol(templateSymbol); |
|
127 |
} |
|
128 |
}); |
|
129 |
btnTemplate.setPreferredSize(new Dimension(100, 35)); |
|
130 |
} |
|
131 |
return btnTemplate; |
|
132 |
} |
|
133 |
|
|
97 | 134 |
private JNumberField getTxtMaxSize() { |
98 | 135 |
if (txtMaxSize == null) { |
99 | 136 |
txtMaxSize = new JNumberField(); |
... | ... | |
111 | 148 |
|
112 | 149 |
public void setData(FLayer lyr, Legend legend) { |
113 | 150 |
this.layer = (FLyrVect) lyr; |
114 |
// this.oldLegend = legend; |
|
151 |
int layerShapeType = 0; |
|
152 |
try { |
|
153 |
setShapeType(this.layer.getShapeType()); |
|
154 |
} catch (DriverException e) { |
|
155 |
NotificationManager.addError(PluginServices.getText(this, "generating_intervals"), e); |
|
156 |
} |
|
157 |
|
|
158 |
if (symbolTable != null) |
|
159 |
pnlCenter.remove(symbolTable); |
|
160 |
|
|
161 |
|
|
162 |
symbolTable = new FSymbolTable("intervals", shapeType); |
|
163 |
pnlCenter.add(symbolTable); |
|
115 | 164 |
fillFieldNames(); |
116 | 165 |
|
117 | 166 |
if (legend instanceof GraduatedSymbolLegend) { |
167 |
renderer = (GraduatedSymbolLegend) legend; |
|
118 | 168 |
GraduatedSymbolLegend theRenderer = (GraduatedSymbolLegend) legend; |
119 |
getChkDefaultvalues().setSelected(theRenderer.isUseDefaultSymbol());
|
|
169 |
getChkDefaultvalues().setSelected(theRenderer.isUseDefaultSymbol());
|
|
120 | 170 |
cmbField.getModel().setSelectedItem(theRenderer.getFieldName()); |
121 | 171 |
symbolTable.fillTableFromSymbolList(theRenderer.getSymbols(), |
122 | 172 |
theRenderer.getValues(), theRenderer.getDescriptions()); |
... | ... | |
124 | 174 |
String.valueOf(theRenderer.getMaxSymbolSize())); |
125 | 175 |
getTxtMinSize().setText( |
126 | 176 |
String.valueOf(theRenderer.getMinSymbolSize())); |
177 |
|
|
127 | 178 |
} else { |
128 |
try { |
|
129 | 179 |
// Si la capa viene con otro tipo de leyenda, creamos |
130 | 180 |
// una nueva del tipo que maneja este panel |
131 |
renderer = new GraduatedSymbolLegend(layer.getShapeType()); |
|
132 |
} catch (DriverException e) { |
|
133 |
// TODO Auto-generated catch block |
|
134 |
e.printStackTrace(); |
|
135 |
} |
|
181 |
renderer = new GraduatedSymbolLegend(layerShapeType); |
|
136 | 182 |
} |
137 | 183 |
|
138 | 184 |
cmbFieldType.setSelectedIndex(renderer.getIntervalType()); |
139 | 185 |
} |
140 | 186 |
|
141 |
public Legend getLegend() { |
|
142 |
// TODO Implement it |
|
143 |
throw new Error("Not yet implemented!"); |
|
187 |
/** |
|
188 |
* Polygon type does not have any sense in this context, it is considered |
|
189 |
* as Marker type. Lines are lines, and markers ar markers. |
|
190 |
* @param shapeType |
|
191 |
*/ |
|
192 |
private void setShapeType(int shapeType) { |
|
193 |
switch (shapeType) { |
|
194 |
case FShape.POINT: |
|
195 |
case FShape.POLYGON: |
|
196 |
this.shapeType = FShape.POINT; |
|
197 |
break; |
|
144 | 198 |
|
199 |
case FShape.LINE: |
|
200 |
this.shapeType = FShape.LINE; |
|
201 |
break; |
|
202 |
default: |
|
203 |
throw new Error("Unknown symbol type"); |
|
204 |
} |
|
205 |
|
|
145 | 206 |
} |
146 | 207 |
|
147 | 208 |
public String getDescription() { |
148 | 209 |
return PluginServices.getText(this, "draw_quantities_using_symbol_size_to_show_relative_values"); |
149 | 210 |
} |
150 | 211 |
|
212 |
public Legend getLegend() { |
|
213 |
GraduatedSymbolLegend l = (GraduatedSymbolLegend) super.getLegend(); |
|
214 |
l.setMinSymbolSize(getTxtMinSize().getValue().doubleValue()); |
|
215 |
l.setMaxSymbolSize(getTxtMaxSize().getValue().doubleValue()); |
|
216 |
l.setDefaultSymbol(templateSymbol); |
|
217 |
return l; |
|
218 |
} |
|
219 |
|
|
151 | 220 |
public ISymbol getPreviewSymbol() { |
152 | 221 |
// TODO Implement it |
153 | 222 |
return null; |
... | ... | |
169 | 238 |
return GraduatedSymbolLegend.class; |
170 | 239 |
} |
171 | 240 |
|
241 |
|
|
242 |
private ISymbol newSymbol(int shapeType, double size) { |
|
243 |
if (templateSymbol == null) { |
|
244 |
switch (shapeType) { |
|
245 |
case FShape.POINT: |
|
246 |
case FShape.POLYGON: |
|
247 |
templateSymbol = new SimpleMarkerSymbol(); |
|
248 |
((SimpleMarkerSymbol) templateSymbol).setSize(size); |
|
249 |
((SimpleMarkerSymbol) templateSymbol).setColor(Color.DARK_GRAY); |
|
250 |
break; |
|
251 |
|
|
252 |
case FShape.LINE: |
|
253 |
templateSymbol = new SimpleLineSymbol(); |
|
254 |
((SimpleLineSymbol) templateSymbol).setWidth(size); |
|
255 |
((SimpleLineSymbol) templateSymbol).setColor(Color.DARK_GRAY); |
|
256 |
break; |
|
257 |
default: |
|
258 |
throw new Error("Unknown symbol type"); |
|
259 |
} |
|
260 |
// clone symbol |
|
261 |
return SymbologyFactory.createSymbolFromXML(templateSymbol.getXMLEntity(), null); |
|
262 |
} else { |
|
263 |
// clone symbol |
|
264 |
ISymbol mySymbol = SymbologyFactory.createSymbolFromXML(templateSymbol.getXMLEntity(), null); |
|
265 |
|
|
266 |
if (mySymbol instanceof ILineSymbol) { |
|
267 |
ILineSymbol lSym = (ILineSymbol) templateSymbol; |
|
268 |
lSym.setWidth(size); |
|
269 |
|
|
270 |
} |
|
271 |
if (mySymbol instanceof IMarkerSymbol) { |
|
272 |
IMarkerSymbol mSym = (IMarkerSymbol) templateSymbol; |
|
273 |
mSym.setSize(size); |
|
274 |
|
|
275 |
} |
|
276 |
return mySymbol; |
|
277 |
} |
|
278 |
} |
|
279 |
/** |
|
280 |
* Damos una primera pasada para saber los l?mites inferior y superior y |
|
281 |
* rellenar un array con los valores. Luego dividimos ese array en |
|
282 |
* intervalos. |
|
283 |
*/ |
|
284 |
protected void fillTableValues() { |
|
285 |
try { |
|
286 |
|
|
287 |
symbolTable.removeAllItems(); |
|
288 |
|
|
289 |
FInterval[] arrayIntervalos = calculateIntervals(); |
|
290 |
if (arrayIntervalos == null) |
|
291 |
return; |
|
292 |
|
|
293 |
FInterval interval; |
|
294 |
NumberFormat.getInstance().setMaximumFractionDigits(2); |
|
295 |
renderer.clear(); |
|
296 |
|
|
297 |
float minSize = getTxtMinSize().getValue().floatValue(); |
|
298 |
float maxSize = getTxtMaxSize().getValue().floatValue(); |
|
299 |
ISymbol theSymbol; |
|
300 |
|
|
301 |
if (chkdefaultvalues.isSelected()) { |
|
302 |
auxLegend.getDefaultSymbol().setDescription("Default"); |
|
303 |
auxLegend.addSymbol(new NullIntervalValue(), |
|
304 |
auxLegend.getDefaultSymbol()); |
|
305 |
} |
|
306 |
|
|
307 |
int symbolType; |
|
308 |
symbolType = layer.getShapeType(); |
|
309 |
int numSymbols = 0; |
|
310 |
|
|
311 |
double step = (maxSize - minSize) / arrayIntervalos.length; |
|
312 |
double size = minSize; |
|
313 |
for (int k = 0; k < arrayIntervalos.length; k++) { |
|
314 |
interval = arrayIntervalos[k]; |
|
315 |
theSymbol = newSymbol(symbolType, size); |
|
316 |
|
|
317 |
auxLegend.addSymbol(interval, theSymbol); |
|
318 |
System.out.println("addSymbol = " + interval + |
|
319 |
" theSymbol = " + theSymbol.getDescription()); |
|
320 |
numSymbols++; |
|
321 |
|
|
322 |
if (numSymbols > 100) { |
|
323 |
int resp = JOptionPane.showConfirmDialog(this, |
|
324 |
PluginServices.getText(this, "mas_de_100_simbolos"), |
|
325 |
PluginServices.getText(this, "quiere_continuar"), |
|
326 |
JOptionPane.YES_NO_OPTION, |
|
327 |
JOptionPane.WARNING_MESSAGE); |
|
328 |
|
|
329 |
if ((resp == JOptionPane.NO_OPTION) || |
|
330 |
(resp == JOptionPane.DEFAULT_OPTION)) { |
|
331 |
return; |
|
332 |
} |
|
333 |
} |
|
334 |
|
|
335 |
|
|
336 |
theSymbol.setDescription(NumberFormat.getInstance().format(interval.getMin()) + |
|
337 |
" - " + |
|
338 |
NumberFormat.getInstance().format(interval.getMax())); |
|
339 |
|
|
340 |
size = size + step; |
|
341 |
} // for |
|
342 |
|
|
343 |
symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
|
344 |
auxLegend.getValues(), auxLegend.getDescriptions()); |
|
345 |
|
|
346 |
} catch (DriverException e) { |
|
347 |
NotificationManager.addError(PluginServices.getText(this, "could_not_get_shape_type"), e); |
|
348 |
} |
|
349 |
|
|
350 |
bDelAll.setEnabled(true); |
|
351 |
bDel.setEnabled(true); |
|
352 |
|
|
353 |
} |
|
172 | 354 |
} // @jve:decl-index=0:visual-constraint="10,10" |
Also available in: Unified diff