root / trunk / extensions / extSymbology / src / org / gvsig / symbology / gui / layerproperties / GeneralLabeling.java @ 28412
History | View | Annotate | Download (29.9 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 org.gvsig.symbology.gui.layerproperties; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Component; |
45 |
import java.awt.Container; |
46 |
import java.awt.Dimension; |
47 |
import java.awt.FlowLayout; |
48 |
import java.awt.event.ActionEvent; |
49 |
import java.awt.event.ActionListener; |
50 |
import java.beans.PropertyChangeEvent; |
51 |
import java.util.ArrayList; |
52 |
import java.util.Comparator; |
53 |
import java.util.Date; |
54 |
import java.util.Hashtable; |
55 |
import java.util.Iterator; |
56 |
import java.util.TreeMap; |
57 |
|
58 |
import javax.swing.BorderFactory; |
59 |
import javax.swing.JCheckBox; |
60 |
import javax.swing.JComponent; |
61 |
import javax.swing.JLabel; |
62 |
import javax.swing.JPanel; |
63 |
|
64 |
import org.apache.log4j.Logger; |
65 |
import org.gvsig.gui.beans.swing.JButton; |
66 |
import org.gvsig.symbology.fmap.labeling.ExtendedLabelingFactory; |
67 |
import org.gvsig.symbology.fmap.labeling.GeneralLabelingStrategy; |
68 |
|
69 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
70 |
import com.iver.andami.PluginServices; |
71 |
import com.iver.andami.messages.NotificationManager; |
72 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
73 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
74 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
75 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
76 |
import com.iver.cit.gvsig.fmap.rendering.IVectorLegend; |
77 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.DefaultLabelingMethod; |
78 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingMethod; |
79 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingStrategy; |
80 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.IPlacementConstraints; |
81 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.IZoomConstraints; |
82 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelingFactory; |
83 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ZoomConstraintsImpl; |
84 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.ILabelingStrategyPanel; |
85 |
import com.iver.utiles.swing.JComboBox; |
86 |
|
87 |
|
88 |
public class GeneralLabeling extends JPanel implements ILabelingStrategyPanel, ActionListener { |
89 |
private static final long serialVersionUID = 8864709758980903351L; |
90 |
private static Comparator comparator=new Comparator<Class<? extends ILabelingMethod>>(){ |
91 |
public int compare(Class<? extends ILabelingMethod> o1, |
92 |
Class<? extends ILabelingMethod> o2) { |
93 |
return o1.getName().compareTo(o2.getName());
|
94 |
}}; |
95 |
private static TreeMap< |
96 |
Class<? extends ILabelingMethod>, |
97 |
Class<? extends AbstractLabelingMethodPanel> |
98 |
> methods |
99 |
= new TreeMap< |
100 |
Class<? extends ILabelingMethod>, |
101 |
Class<? extends AbstractLabelingMethodPanel> |
102 |
>(comparator); |
103 |
private JButton btnVisualization; |
104 |
private JButton btnPlacement; |
105 |
private JComboBox cmbMethod; |
106 |
private JPanel methodPanel; |
107 |
private IPlacementConstraints placementConstraints;
|
108 |
private IZoomConstraints zoomConstraints;
|
109 |
private boolean noEvent; |
110 |
private FLyrVect targetLayer;
|
111 |
private JCheckBox chkAllowLabelOverlapping; |
112 |
private FLyrVect auxLayer;
|
113 |
private GeneralLabelingStrategy gStr;
|
114 |
private AbstractLabelingMethodPanel previousMethodPanel = null; |
115 |
public GeneralLabeling() {
|
116 |
initialize(); |
117 |
} |
118 |
|
119 |
private void initialize() { |
120 |
setLayout(new BorderLayout()); |
121 |
JPanel center = new JPanel(new BorderLayout(10, 10)); |
122 |
center.setBorder(BorderFactory.createTitledBorder(
|
123 |
null, PluginServices.getText(this, "classes"))); |
124 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,0)); |
125 |
aux.add(new JLabel(PluginServices.getText(this, "method")+":")); |
126 |
aux.add(getCmbMethod()); |
127 |
aux.setPreferredSize(new Dimension(605, 40)); |
128 |
center.add(aux, BorderLayout.NORTH);
|
129 |
|
130 |
|
131 |
// el panell del m?tode de moltes FeatureDependantLabelingMethod
|
132 |
methodPanel = getMethodPanel(); |
133 |
center.add(methodPanel, BorderLayout.CENTER);
|
134 |
add(center, BorderLayout.CENTER);
|
135 |
|
136 |
JPanel south = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0)); |
137 |
south.setBorder(BorderFactory.createTitledBorder(
|
138 |
null, PluginServices.getText(this, "options"))); |
139 |
south.add(getBtnVisualization()); |
140 |
south.add(getBtnPlacement()); |
141 |
south.add(getChkAllowLabelOverlapping()); |
142 |
south.setPreferredSize(new Dimension(612, 60)); |
143 |
|
144 |
add(south, BorderLayout.SOUTH);
|
145 |
} |
146 |
|
147 |
|
148 |
private JPanel getMethodPanel() { |
149 |
if (methodPanel == null){ |
150 |
methodPanel = new JPanel(new BorderLayout(10, 0)); |
151 |
} |
152 |
return methodPanel;
|
153 |
} |
154 |
|
155 |
private JCheckBox getChkAllowLabelOverlapping() { |
156 |
if (chkAllowLabelOverlapping == null) { |
157 |
chkAllowLabelOverlapping = new JCheckBox(PluginServices.getText(this, "allow_label_overlapping")); |
158 |
chkAllowLabelOverlapping.addActionListener(this);
|
159 |
} |
160 |
return chkAllowLabelOverlapping;
|
161 |
} |
162 |
|
163 |
private void refreshControls() { |
164 |
// fires an event from the methods combo box
|
165 |
actionPerformed(new ActionEvent(getCmbMethod(), 0, null)); |
166 |
} |
167 |
|
168 |
private JButton getBtnVisualization() { |
169 |
if (btnVisualization == null) { |
170 |
btnVisualization = new JButton( |
171 |
PluginServices.getText(this, "visualization")+"..."); |
172 |
btnVisualization.setName("BTNVISUALIZATION");
|
173 |
btnVisualization.addActionListener(this);
|
174 |
} |
175 |
return btnVisualization;
|
176 |
} |
177 |
|
178 |
private JButton getBtnPlacement() { |
179 |
if (btnPlacement == null) { |
180 |
btnPlacement = new JButton( |
181 |
PluginServices.getText(this, "placement")+"..."); |
182 |
btnPlacement.setName("BTNPLACEMENT");
|
183 |
btnPlacement.addActionListener(this);
|
184 |
} |
185 |
return btnPlacement;
|
186 |
} |
187 |
|
188 |
private JComboBox getCmbMethod() { |
189 |
if (cmbMethod == null) { |
190 |
Iterator<Class<? extends AbstractLabelingMethodPanel>> it = methods.values().iterator(); |
191 |
ArrayList<AbstractLabelingMethodPanel> panels = new ArrayList<AbstractLabelingMethodPanel>(); |
192 |
while (it.hasNext()) {
|
193 |
try {
|
194 |
panels.add(it.next().newInstance()); |
195 |
} catch (Exception e) { |
196 |
throw new Error(e); |
197 |
} |
198 |
} |
199 |
cmbMethod = new JComboBox(panels.toArray()); |
200 |
cmbMethod.setSize(new Dimension(300, 22)); |
201 |
cmbMethod.setName("CMBMETHOD");
|
202 |
cmbMethod.addActionListener(this);
|
203 |
} |
204 |
return cmbMethod;
|
205 |
} |
206 |
|
207 |
public ILabelingStrategy getLabelingStrategy() {
|
208 |
ILabelingStrategy st = ExtendedLabelingFactory. |
209 |
createStrategy((FLayer) targetLayer, |
210 |
getMethod(), |
211 |
getPlacementConstraints(), |
212 |
getZoomConstraints()); |
213 |
if (st instanceof GeneralLabelingStrategy) { |
214 |
GeneralLabelingStrategy gStr = (GeneralLabelingStrategy) st; |
215 |
gStr.setAllowOverlapping(getChkAllowLabelOverlapping().isSelected()); |
216 |
gStr.setZoomConstraints(getZoomConstraints()); |
217 |
} |
218 |
return st;
|
219 |
} |
220 |
|
221 |
public void setModel(FLayer layer, ILabelingStrategy str) { |
222 |
if (layer instanceof FLyrVect) { |
223 |
try {
|
224 |
targetLayer = (FLyrVect) layer;//.cloneLayer();
|
225 |
|
226 |
VectorialDriver vd = (VectorialDriver) ((FLyrVect) layer).getSource().getDriver(); |
227 |
|
228 |
auxLayer = (FLyrVect) LayerFactory.createLayer(layer.getName(),vd, layer.getProjection()); |
229 |
|
230 |
auxLayer.setLegend((IVectorLegend)targetLayer.getLegend()); |
231 |
|
232 |
|
233 |
if (auxLayer.getProjection() == null) { |
234 |
Logger.getLogger(getClass()).debug("Possible bug detected in " + |
235 |
"FLyrVect.cloneLayer() (missing projection in cloned layer)");
|
236 |
// this line should be unnecessary (and included in cloneLayer) method);
|
237 |
auxLayer.setProjection(targetLayer.getProjection()); |
238 |
} |
239 |
//
|
240 |
|
241 |
if (str instanceof GeneralLabelingStrategy) { |
242 |
gStr = (GeneralLabelingStrategy) LabelingFactory. |
243 |
createStrategyFromXML(str.getXMLEntity(), auxLayer/*layer.cloneLayer()*/);
|
244 |
auxLayer.setLabelingStrategy(gStr); |
245 |
gStr.setLayer(auxLayer); |
246 |
setMethod(gStr.getLabelingMethod(), auxLayer); |
247 |
placementConstraints = gStr.getPlacementConstraints(); |
248 |
zoomConstraints = gStr.getZoomConstraints(); |
249 |
getChkAllowLabelOverlapping().setSelected(gStr.isAllowingOverlap()); |
250 |
} |
251 |
} catch (ReadDriverException e) {
|
252 |
NotificationManager.addError(PluginServices.getText(this, "accessing_file_structure"), e); |
253 |
} catch (Exception e) { |
254 |
NotificationManager.addError(PluginServices.getText(this, "accessing_file_structure"), e); |
255 |
} |
256 |
refreshControls(); |
257 |
} |
258 |
} |
259 |
|
260 |
|
261 |
public static void addLabelingMethod(Class<? extends AbstractLabelingMethodPanel> iLabelingMethodClass) { |
262 |
try {
|
263 |
methods.put( |
264 |
iLabelingMethodClass.newInstance().getLabelingMethodClass(), |
265 |
iLabelingMethodClass); |
266 |
} catch (Exception e) { |
267 |
NotificationManager.addError( |
268 |
PluginServices.getText(GeneralLabeling.class, "cannot_install_labeling_method"), e);
|
269 |
} |
270 |
} |
271 |
|
272 |
private void setMethod(ILabelingMethod labelingMethod, FLyrVect srcLayer) { |
273 |
getMethodPanel().removeAll(); |
274 |
AbstractLabelingMethodPanel p; |
275 |
try {
|
276 |
p = methods.get(labelingMethod.getClass()).newInstance(); |
277 |
System.out.println("last labeling method was"+p.getClass().getName()); |
278 |
p.setModel(labelingMethod, srcLayer); |
279 |
cmbMethod.setSelectedItem(p); |
280 |
} catch (Exception e) { |
281 |
// should be impossible;
|
282 |
NotificationManager.addWarning(e.getLocalizedMessage()); |
283 |
} |
284 |
|
285 |
} |
286 |
|
287 |
private ILabelingMethod getMethod() {
|
288 |
AbstractLabelingMethodPanel p = ((AbstractLabelingMethodPanel)cmbMethod.getSelectedItem()); |
289 |
if(p != null){ |
290 |
return p.getMethod();
|
291 |
} |
292 |
|
293 |
return new DefaultLabelingMethod(); |
294 |
} |
295 |
|
296 |
private IZoomConstraints getZoomConstraints() {
|
297 |
if (zoomConstraints == null) { |
298 |
zoomConstraints = new ZoomConstraintsImpl();
|
299 |
} |
300 |
return zoomConstraints;
|
301 |
} |
302 |
|
303 |
private IPlacementConstraints getPlacementConstraints() {
|
304 |
return placementConstraints;
|
305 |
} |
306 |
|
307 |
public void actionPerformed(ActionEvent e) { |
308 |
System.err.println("GeneralLabeling.actionPerformed() "+((Component)e.getSource()).getName()); |
309 |
if (noEvent) return; |
310 |
JComponent c = (JComponent)e.getSource(); |
311 |
|
312 |
if (c.equals(btnPlacement)) {
|
313 |
|
314 |
try {
|
315 |
IPlacementConstraints oldValue = getPlacementConstraints(); |
316 |
IPlacementProperties pp = PlacementProperties.createPlacementProperties( |
317 |
getPlacementConstraints(), |
318 |
((FLyrVect) auxLayer).getShapeType()); |
319 |
PluginServices.getMDIManager().addWindow(pp); |
320 |
placementConstraints = pp.getPlacementConstraints(); |
321 |
|
322 |
((AbstractLabelingMethodPanel) cmbMethod.getSelectedItem()). |
323 |
propertyChange(new PropertyChangeEvent( |
324 |
this,
|
325 |
AbstractLabelingMethodPanel.PLACEMENT_CONSTRAINTS, |
326 |
oldValue, |
327 |
placementConstraints)); |
328 |
|
329 |
} catch (ClassCastException ccEx) { |
330 |
NotificationManager.addError( |
331 |
"Placement constraints not prepared for:"
|
332 |
+auxLayer.getClass().getName(), |
333 |
ccEx); |
334 |
} catch (ReadDriverException dEx) {
|
335 |
NotificationManager.addWarning( |
336 |
"Should be unreachable code",
|
337 |
dEx); |
338 |
NotificationManager.addError( |
339 |
PluginServices.getText( |
340 |
this,
|
341 |
"usupported_layer_type"),
|
342 |
dEx); |
343 |
} |
344 |
|
345 |
} else if (c.equals(btnVisualization)) { |
346 |
IZoomConstraints oldValue = getZoomConstraints(); |
347 |
LabelScaleRange lsr = new LabelScaleRange(oldValue.getMinScale(), oldValue.getMaxScale());
|
348 |
PluginServices.getMDIManager().addWindow(lsr); |
349 |
zoomConstraints = new ZoomConstraintsImpl();
|
350 |
zoomConstraints.setMaxScale(lsr.getMaxScale()); |
351 |
zoomConstraints.setMinScale(lsr.getMinScale()); |
352 |
zoomConstraints.setMode( |
353 |
lsr.getMaxScale() ==-1 && lsr.getMinScale() == -1 ? |
354 |
IZoomConstraints.DEFINED_BY_THE_LAYER : |
355 |
IZoomConstraints.DEFINED_BY_THE_USER); |
356 |
|
357 |
((AbstractLabelingMethodPanel) cmbMethod.getSelectedItem()). |
358 |
propertyChange(new PropertyChangeEvent( |
359 |
this,
|
360 |
AbstractLabelingMethodPanel.ZOOM_CONSTRAINTS, |
361 |
oldValue, |
362 |
getZoomConstraints())); |
363 |
|
364 |
} else if (c.equals(chkAllowLabelOverlapping)) { |
365 |
boolean newValue = chkAllowLabelOverlapping.isSelected();
|
366 |
((AbstractLabelingMethodPanel) cmbMethod.getSelectedItem()). |
367 |
propertyChange(new PropertyChangeEvent( |
368 |
this,
|
369 |
AbstractLabelingMethodPanel.ALLOW_OVERLAP, |
370 |
!newValue, |
371 |
newValue)); |
372 |
|
373 |
} else if (c.equals(cmbMethod)) { |
374 |
AbstractLabelingMethodPanel p = (AbstractLabelingMethodPanel) cmbMethod.getSelectedItem(); |
375 |
if(previousMethodPanel == null || previousMethodPanel != p ){ |
376 |
Container cont = methodPanel.getParent();
|
377 |
cont.remove(methodPanel); |
378 |
emptyContainer(methodPanel); |
379 |
|
380 |
try {
|
381 |
if(gStr != null){ |
382 |
if(gStr.getLabelingMethod() != null){ |
383 |
p.setModel(gStr.getLabelingMethod(), auxLayer); |
384 |
} |
385 |
} else {
|
386 |
p.setModel(getMethod(),auxLayer); |
387 |
} |
388 |
methodPanel.add( |
389 |
p, |
390 |
BorderLayout.CENTER);
|
391 |
|
392 |
methodPanel.repaint(); |
393 |
setVisible(false);
|
394 |
setVisible(true);
|
395 |
} catch (ReadDriverException e1) {
|
396 |
NotificationManager.addInfo(new Date(System.currentTimeMillis()).toString(), e1); |
397 |
} |
398 |
cont.add(methodPanel, BorderLayout.CENTER);
|
399 |
} |
400 |
previousMethodPanel = p; |
401 |
} |
402 |
System.out.println("GeneralLabeling.actionPerformed() exit "+((Component)e.getSource()).getName()); |
403 |
} |
404 |
|
405 |
private void emptyContainer(Container c) { |
406 |
for (int i = 0; i < c.getComponentCount(); i++) { |
407 |
if (c.getComponent(i) instanceof Container) { |
408 |
emptyContainer((Container) c.getComponent(i));
|
409 |
} |
410 |
c.remove(i); |
411 |
} |
412 |
} |
413 |
|
414 |
public String getLabelingStrategyName() { |
415 |
return PluginServices.getText(this, "user_defined_labels"); |
416 |
} |
417 |
|
418 |
public Class<? extends ILabelingStrategy> getLabelingStrategyClass() { |
419 |
return GeneralLabelingStrategy.class;
|
420 |
} |
421 |
|
422 |
public void setEnabled(boolean enabled) { |
423 |
super.setEnabled(enabled);
|
424 |
getBtnPlacement().setEnabled(enabled); |
425 |
getBtnVisualization().setEnabled(enabled); |
426 |
getChkAllowLabelOverlapping().setEnabled(enabled); |
427 |
getCmbMethod().setEnabled(enabled); |
428 |
JPanel mp = getMethodPanel();//.setEnabled(enabled); |
429 |
mp.setEnabled(enabled); |
430 |
for (int i=0; i<mp.getComponentCount(); i++){ |
431 |
Component c = mp.getComponent(i);
|
432 |
c.setEnabled(enabled); |
433 |
} |
434 |
|
435 |
} |
436 |
} |
437 |
|
438 |
/*
|
439 |
class _GeneralLabeling extends JPanel implements ILabelingStrategyPanel, ActionListener {
|
440 |
private static final long serialVersionUID = 8864709758980903351L;
|
441 |
private static Hashtable<String, Class<? extends ILabelingMethod>> methods
|
442 |
= new Hashtable<String, Class<? extends ILabelingMethod>>();
|
443 |
private static int newClassSuffix = 0;
|
444 |
private JButton btnVisualization;
|
445 |
private JButton btnRenameClass;
|
446 |
private JButton btnSQLQuery;
|
447 |
private JButton btnDelClass;
|
448 |
private JButton btnAddClass;
|
449 |
private JButton btnPlacement;
|
450 |
private JComboBoxLabelingMethod cmbMethod;
|
451 |
private GridBagLayoutPanel classesPanel;
|
452 |
private JComboBox cmbClasses;
|
453 |
private IPlacementConstraints placementConstraints;
|
454 |
private IZoomConstraints zoomConstraints;
|
455 |
private long minScaleView = -1, maxScaleView = -1;
|
456 |
private boolean noEvent;
|
457 |
private JCheckBox chkLabel;
|
458 |
private JCheckBox chkTextOnly;
|
459 |
private FLyrVect layer;
|
460 |
private String[] fieldNames;
|
461 |
private JDnDList lstClassPriorities;
|
462 |
private JCheckBox chkDefinePriorities;
|
463 |
private JScrollPane scrlPan;
|
464 |
private LabelClassRenderingProperties labelClassRenderingProperties;
|
465 |
private JCheckBox chkAllowLabelOverlapping;
|
466 |
|
467 |
public _GeneralLabeling() {
|
468 |
initialize();
|
469 |
}
|
470 |
|
471 |
private void initialize() {
|
472 |
setLayout(new BorderLayout());
|
473 |
GridBagLayoutPanel left = new GridBagLayoutPanel();
|
474 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,0));
|
475 |
aux.add(new JLabel(PluginServices.getText(this, "method")+":"));
|
476 |
aux.add(getCmbMethod());
|
477 |
aux.setPreferredSize(new Dimension(605, 40));
|
478 |
left.addComponent(aux);
|
479 |
|
480 |
|
481 |
classesPanel = new GridBagLayoutPanel();
|
482 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,0));
|
483 |
aux.add(new JLabel(PluginServices.getText(this, "class")+":"));
|
484 |
aux.add(getCmbClasses());
|
485 |
aux.add(getChkLabelFeatures());
|
486 |
aux.setPreferredSize(new Dimension(602, 40));
|
487 |
classesPanel.addComponent(aux);
|
488 |
|
489 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
|
490 |
aux.add(getBtnAddClass());
|
491 |
aux.add(getBtnDelClass());
|
492 |
aux.add(getBtnRenameClass());
|
493 |
aux.add(getBtnSQLQuery());
|
494 |
classesPanel.addComponent(aux);
|
495 |
classesPanel.setBorder(BorderFactory.createTitledBorder(
|
496 |
null, PluginServices.getText(this, "classes")));
|
497 |
left.addComponent(classesPanel);
|
498 |
|
499 |
|
500 |
left.addComponent(labelClassRenderingProperties = new LabelClassRenderingProperties());
|
501 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
|
502 |
aux.setBorder(BorderFactory.createTitledBorder(
|
503 |
null, PluginServices.getText(this, "options")));
|
504 |
aux.add(getBtnVisualization());
|
505 |
|
506 |
aux.add(getBtnPlacement());
|
507 |
aux.add(getChkAllowLabelOverlapping());
|
508 |
aux.setPreferredSize(new Dimension(612, 60));
|
509 |
|
510 |
left.addComponent(aux);
|
511 |
|
512 |
add(left, BorderLayout.CENTER);
|
513 |
|
514 |
JPanel right = new JPanel(new BorderLayout(15, 15));
|
515 |
aux = new JPanel(new BorderLayout(15, 15));
|
516 |
aux.add(getChkDefinePriorities(), BorderLayout.NORTH);
|
517 |
aux.add(getScrlClassPriorities(), BorderLayout.CENTER);
|
518 |
right.add(new JBlank(10, 10), BorderLayout.NORTH);
|
519 |
right.add(aux, BorderLayout.CENTER);
|
520 |
right.add(new JBlank(10, 10), BorderLayout.SOUTH);
|
521 |
right.add(new JBlank(10, 10), BorderLayout.EAST);
|
522 |
add(right, BorderLayout.EAST);
|
523 |
}
|
524 |
|
525 |
|
526 |
private JCheckBox getChkAllowLabelOverlapping() {
|
527 |
if (chkAllowLabelOverlapping == null) {
|
528 |
chkAllowLabelOverlapping = new JCheckBox(PluginServices.getText(this, "allow_label_overlapping"));
|
529 |
|
530 |
}
|
531 |
|
532 |
return chkAllowLabelOverlapping;
|
533 |
}
|
534 |
|
535 |
private Component getScrlClassPriorities() {
|
536 |
if (scrlPan == null) {
|
537 |
scrlPan = new JScrollPane();
|
538 |
scrlPan.setViewportView(getLstClassPriorities());
|
539 |
scrlPan.setPreferredSize(new Dimension(180, 300));
|
540 |
}
|
541 |
return scrlPan;
|
542 |
}
|
543 |
|
544 |
private JCheckBox getChkDefinePriorities() {
|
545 |
if (chkDefinePriorities == null) {
|
546 |
chkDefinePriorities = new JCheckBox(PluginServices.getText(this, "label_priority"));
|
547 |
chkDefinePriorities.addActionListener(this);
|
548 |
chkDefinePriorities.setName("CHK_DEFINE_PRIORITIES");
|
549 |
}
|
550 |
return chkDefinePriorities;
|
551 |
}
|
552 |
|
553 |
private JDnDList getLstClassPriorities() {
|
554 |
if (lstClassPriorities == null) {
|
555 |
lstClassPriorities = new JDnDList();
|
556 |
lstClassPriorities.setName("CLASS_PRIORITY_LIST");
|
557 |
lstClassPriorities.addMouseListener(new MouseAdapter() {
|
558 |
@Override
|
559 |
public void mouseReleased(MouseEvent e) {
|
560 |
JDnDListModel m = (JDnDListModel) lstClassPriorities.getModel();
|
561 |
for (int i = 0; i < m.getSize(); i++) {
|
562 |
((LabelClass) m.getElementAt(i)).setPriority(i);
|
563 |
}
|
564 |
}
|
565 |
});
|
566 |
|
567 |
}
|
568 |
return lstClassPriorities;
|
569 |
}
|
570 |
|
571 |
private void refreshControls() {
|
572 |
// classes combo box
|
573 |
refreshClasses();
|
574 |
|
575 |
// fires an event from the methods combo box
|
576 |
actionPerformed(new ActionEvent(getCmbMethod(), 0, null));
|
577 |
}
|
578 |
|
579 |
private JButton getBtnVisualization() {
|
580 |
if (btnVisualization == null) {
|
581 |
btnVisualization = new JButton(
|
582 |
PluginServices.getText(this, "visualization")+"...");
|
583 |
btnVisualization.setName("BTNVISUALIZATION");
|
584 |
btnVisualization.addActionListener(this);
|
585 |
}
|
586 |
return btnVisualization;
|
587 |
}
|
588 |
|
589 |
private JButton getBtnPlacement() {
|
590 |
if (btnPlacement == null) {
|
591 |
btnPlacement = new JButton(
|
592 |
PluginServices.getText(this, "placement")+"...");
|
593 |
btnPlacement.setName("BTNPLACEMENT");
|
594 |
btnPlacement.addActionListener(this);
|
595 |
}
|
596 |
return btnPlacement;
|
597 |
}
|
598 |
|
599 |
private JComboBox getCmbMethod() {
|
600 |
if (cmbMethod == null) {
|
601 |
Iterator<String> it = methods.keySet().iterator();
|
602 |
ArrayList<MethodItem> aux = new ArrayList<MethodItem>();
|
603 |
while (it.hasNext()) {
|
604 |
String name = it.next();
|
605 |
|
606 |
Class<? extends ILabelingMethod> methodClass = (Class<? extends ILabelingMethod>) methods.get(name);
|
607 |
ILabelingMethod method;
|
608 |
try {
|
609 |
method = (ILabelingMethod) methodClass.newInstance();
|
610 |
MethodItem newItem = new MethodItem(name, method);
|
611 |
aux.add(newItem);
|
612 |
|
613 |
} catch (InstantiationException e) {
|
614 |
NotificationManager.addError("Trying to instantiate an interface" +
|
615 |
" or abstract class + "+methodClass.getName(), e);
|
616 |
} catch (IllegalAccessException e) {
|
617 |
NotificationManager.addError("IllegalAccessException: does " +
|
618 |
methodClass.getName() + " class have an anonymous" +
|
619 |
" constructor?", e);
|
620 |
}
|
621 |
|
622 |
}
|
623 |
cmbMethod = new JComboBoxLabelingMethod(aux.toArray(new MethodItem[0]));
|
624 |
cmbMethod.setSize(new Dimension(300, 22));
|
625 |
cmbMethod.setName("CMBMETHOD");
|
626 |
cmbMethod.addActionListener(this);
|
627 |
}
|
628 |
return cmbMethod;
|
629 |
}
|
630 |
|
631 |
private JButton getBtnSQLQuery() {
|
632 |
if (btnSQLQuery == null) {
|
633 |
btnSQLQuery = new JButton(PluginServices.getText(this, "SQL_query"));
|
634 |
btnSQLQuery.setName("BTNSQLQUERY");
|
635 |
btnSQLQuery.addActionListener(this);
|
636 |
}
|
637 |
return btnSQLQuery;
|
638 |
}
|
639 |
|
640 |
private JButton getBtnRenameClass() {
|
641 |
if (btnRenameClass == null) {
|
642 |
btnRenameClass = new JButton(PluginServices.getText(this, "remane_class"));
|
643 |
btnRenameClass.setName("BTNRENAMECLASS");
|
644 |
btnRenameClass.addActionListener(this);
|
645 |
}
|
646 |
return btnRenameClass;
|
647 |
}
|
648 |
|
649 |
private JButton getBtnDelClass() {
|
650 |
if (btnDelClass == null) {
|
651 |
btnDelClass = new JButton(PluginServices.getText(this, "delete_class"));
|
652 |
btnDelClass.setName("BTNDELCLASS");
|
653 |
btnDelClass.addActionListener(this);
|
654 |
}
|
655 |
return btnDelClass;
|
656 |
}
|
657 |
|
658 |
private JButton getBtnAddClass() {
|
659 |
if (btnAddClass == null) {
|
660 |
btnAddClass = new JButton(PluginServices.getText(this, "add_class"));
|
661 |
btnAddClass.setName("BTNADDCLASS");
|
662 |
btnAddClass.addActionListener(this);
|
663 |
}
|
664 |
return btnAddClass;
|
665 |
}
|
666 |
|
667 |
private JCheckBox getChkLabelFeatures() {
|
668 |
if (chkLabel == null) {
|
669 |
chkLabel = new JCheckBox();
|
670 |
chkLabel.setText(PluginServices.getText(this, "label_features_in_this_class"));
|
671 |
chkLabel.setName("CHKLABEL");
|
672 |
chkLabel.addActionListener(this);
|
673 |
}
|
674 |
return chkLabel;
|
675 |
}
|
676 |
|
677 |
private JComboBox getCmbClasses() {
|
678 |
if (cmbClasses == null) {
|
679 |
cmbClasses = new JComboBox();
|
680 |
cmbClasses.setPreferredSize(new Dimension(150, 20));
|
681 |
cmbClasses.setName("CMBCLASSES");
|
682 |
cmbClasses.addActionListener(this);
|
683 |
}
|
684 |
return cmbClasses;
|
685 |
}
|
686 |
|
687 |
public ILabelingStrategy getLabelingStrategy() {
|
688 |
ILabelingStrategy st = ExtendedLabelingFactory.
|
689 |
createStrategy((FLayer) layer,
|
690 |
getMethod(),
|
691 |
getPlacementConstraints(),
|
692 |
getZoomConstraints());
|
693 |
if (st instanceof GeneralLabelingStrategy) {
|
694 |
GeneralLabelingStrategy gStr = (GeneralLabelingStrategy) st;
|
695 |
gStr.setAllowOverlapping(getChkAllowLabelOverlapping().isSelected());
|
696 |
gStr.setMinScaleView(minScaleView);
|
697 |
gStr.setMaxScaleView(maxScaleView);
|
698 |
}
|
699 |
return st;
|
700 |
}
|
701 |
|
702 |
public void setModel(FLayer layer, ILabelingStrategy str) {
|
703 |
if (layer instanceof FLyrVect) {
|
704 |
this.layer = (FLyrVect) layer;
|
705 |
FLyrVect lv = (FLyrVect) layer;
|
706 |
try {
|
707 |
fieldNames = lv.getRecordset().getFieldNames();
|
708 |
labelClassRenderingProperties.setFieldNames(fieldNames);
|
709 |
if (str instanceof GeneralLabelingStrategy) {
|
710 |
try {
|
711 |
GeneralLabelingStrategy gStr = (GeneralLabelingStrategy) LabelingFactory.createStrategyFromXML(str.getXMLEntity(), layer.cloneLayer());
|
712 |
setMethod(str.getLabelingMethod());
|
713 |
placementConstraints = str.getPlacementConstraints();
|
714 |
getChkAllowLabelOverlapping().setSelected(gStr.isAllowingOverlap());
|
715 |
minScaleView = gStr.getMinScaleView();
|
716 |
maxScaleView = gStr.getMaxScaleView();
|
717 |
|
718 |
} catch (ReadDriverException e) {
|
719 |
NotificationManager.addError(PluginServices.getText(this, "accessing_file_structure"), e);
|
720 |
} catch (Exception e) {
|
721 |
NotificationManager.addError(PluginServices.getText(this, "accessing_file_structure"), e);
|
722 |
}
|
723 |
}
|
724 |
|
725 |
refreshControls();
|
726 |
labelClassRenderingProperties.setModel(getActiveClass());
|
727 |
|
728 |
} catch (ReadDriverException e) {
|
729 |
NotificationManager.addError(PluginServices.getText(this, "accessing_file_structure"), e);
|
730 |
}
|
731 |
}
|
732 |
}
|
733 |
|
734 |
|
735 |
public static void addLabelingMethod(String name, Class<? extends ILabelingMethod> iLabelingMethodClass) {
|
736 |
methods.put(name, iLabelingMethodClass);
|
737 |
}
|
738 |
|
739 |
private void setMethod(ILabelingMethod labelingMethod) {
|
740 |
getCmbMethod().setSelectedItem(new MethodItem(null, labelingMethod));
|
741 |
}
|
742 |
|
743 |
private ILabelingMethod getMethod() {
|
744 |
return ((MethodItem) getCmbMethod().getSelectedItem()).method;
|
745 |
}
|
746 |
|
747 |
private void refreshClasses() {
|
748 |
// label classes
|
749 |
getCmbClasses().removeAllItems();
|
750 |
LabelClass[] lClasses = getMethod().getLabelClasses();
|
751 |
for (int i = 0; i < lClasses.length; i++) {
|
752 |
getCmbClasses().addItem(lClasses[i]);
|
753 |
|
754 |
}
|
755 |
|
756 |
labelClassRenderingProperties.setModel(
|
757 |
(LabelClass) getCmbClasses().getSelectedItem());
|
758 |
// expressions combo box
|
759 |
// refreshCmbExpressions();
|
760 |
|
761 |
// panel priorities
|
762 |
refreshPnlPriorities();
|
763 |
|
764 |
}
|
765 |
|
766 |
private void refreshPnlPriorities() {
|
767 |
TreeSet<LabelClass> ts = new TreeSet<LabelClass>(new LabelClassComparatorByPriority());
|
768 |
|
769 |
LabelClass[] lClasses = getMethod().getLabelClasses();
|
770 |
for (int i = 0; i < lClasses.length; i++) {
|
771 |
ts.add(lClasses[i]);
|
772 |
}
|
773 |
|
774 |
// refresh label priority panel
|
775 |
getChkDefinePriorities().setSelected(getMethod().definesPriorities());
|
776 |
JDnDListModel m = new JDnDListModel();
|
777 |
for (LabelClass labelClass : ts) {
|
778 |
m.addElement(labelClass);
|
779 |
}
|
780 |
getLstClassPriorities().setModel(m);
|
781 |
|
782 |
}
|
783 |
|
784 |
private LabelClass getActiveClass() {
|
785 |
return (LabelClass) getCmbClasses().getSelectedItem();
|
786 |
}
|
787 |
|
788 |
private IZoomConstraints getZoomConstraints() {
|
789 |
return zoomConstraints;
|
790 |
}
|
791 |
|
792 |
private IPlacementConstraints getPlacementConstraints() {
|
793 |
return placementConstraints;
|
794 |
}
|
795 |
|
796 |
public void actionPerformed(ActionEvent e) {
|
797 |
if (noEvent) return;
|
798 |
JComponent c = (JComponent)e.getSource();
|
799 |
|
800 |
if (c.equals(btnAddClass)) {
|
801 |
LabelClass newClass = new LabelClass();
|
802 |
newClass.setName(PluginServices.getText(this, "labeling")+String.valueOf(++newClassSuffix));
|
803 |
getMethod().addLabelClass(newClass);
|
804 |
refreshClasses();
|
805 |
getCmbClasses().setSelectedItem(newClass);
|
806 |
} else if (c.equals(btnDelClass)) {
|
807 |
LabelClass clazz = getActiveClass();
|
808 |
getMethod().deleteLabelClass(clazz);
|
809 |
refreshClasses();
|
810 |
} else if (c.equals(btnRenameClass)) {
|
811 |
LabelClass clazz = getActiveClass();
|
812 |
String newName = JOptionPane.showInputDialog(
|
813 |
PluginServices.getText(this, "enter_new_name"));
|
814 |
if (newName != null)
|
815 |
getMethod().renameLabelClass(clazz, newName);
|
816 |
refreshClasses();
|
817 |
} else if (c.equals(btnSQLQuery)) {
|
818 |
LabelClass clazz = getActiveClass();
|
819 |
String query = clazz.getSQLQuery();
|
820 |
query = JOptionPane.showInputDialog(null,
|
821 |
"select from "+layer.getName()+" where ",
|
822 |
"SQL query",
|
823 |
JOptionPane.QUESTION_MESSAGE);
|
824 |
if (!query.equals("")) {
|
825 |
clazz.setSQLQuery(query);
|
826 |
}
|
827 |
|
828 |
} else if (c.equals(chkLabel)) {
|
829 |
LabelClass lc = (LabelClass) getCmbClasses().getSelectedItem();
|
830 |
if (lc == null)
|
831 |
lc = getMethod().getDefaultLabelClass();
|
832 |
lc.setVisible(chkLabel.isSelected());
|
833 |
} else if (c.equals(chkTextOnly)) {
|
834 |
|
835 |
} else if (c.equals(cmbClasses)) {
|
836 |
// refresh expressions
|
837 |
// LabelClass lc = (LabelClass) cmbClasses.getSelectedItem();
|
838 |
// if (lc != null && lc.getLabelExpression() != null && !getExpressions().contains(lc.getLabelExpression())) {
|
839 |
// getExpressions().add(0, lc.getLabelExpression());
|
840 |
// }
|
841 |
// refreshCmbExpressions();
|
842 |
} else if (c.equals(btnPlacement)) {
|
843 |
|
844 |
try {
|
845 |
IPlacementProperties pp = PlacementProperties.createPlacementProperties(
|
846 |
getPlacementConstraints(),
|
847 |
((FLyrVect) layer).getShapeType());
|
848 |
PluginServices.getMDIManager().addWindow(pp);
|
849 |
placementConstraints = pp.getPlacementConstraints();
|
850 |
} catch (ClassCastException ccEx) {
|
851 |
NotificationManager.addError("Placement constraints not prepared for:"
|
852 |
+layer.getClass().getName(),
|
853 |
ccEx);
|
854 |
} catch (ReadDriverException dEx) {
|
855 |
NotificationManager.addWarning("Should be unreachable code", dEx);
|
856 |
NotificationManager.addError(PluginServices.getText(this, "usupported_layer_type"), dEx);
|
857 |
}
|
858 |
|
859 |
} else if (c.equals(btnVisualization)) {
|
860 |
LabelScaleRange lsr = new LabelScaleRange(minScaleView, maxScaleView);
|
861 |
PluginServices.getMDIManager().addWindow(lsr);
|
862 |
minScaleView = lsr.getMinScale();
|
863 |
maxScaleView = lsr.getMaxScale();
|
864 |
} else if (c.equals(cmbMethod)) {
|
865 |
// disable components in class panel
|
866 |
// multiple class or not enables or disables the class panel
|
867 |
setComponentEnabled(classesPanel, getMethod().allowsMultipleClass());
|
868 |
refreshClasses();
|
869 |
|
870 |
} else if (c.equals(chkDefinePriorities)) {
|
871 |
getMethod().setDefinesPriorities(chkDefinePriorities.isSelected());
|
872 |
refreshPnlPriorities();
|
873 |
}
|
874 |
}
|
875 |
|
876 |
private void setComponentEnabled(Component c, boolean b) {
|
877 |
if (c instanceof JComponent) {
|
878 |
JComponent c1 = (JComponent) c;
|
879 |
for (int i = 0; i < c1.getComponentCount(); i++) {
|
880 |
setComponentEnabled(c1.getComponent(i), b);
|
881 |
}
|
882 |
}
|
883 |
c.setEnabled(b);
|
884 |
}
|
885 |
|
886 |
public String getLabelingStrategyName() {
|
887 |
return PluginServices.getText(this, "user_defined_labels");
|
888 |
}
|
889 |
|
890 |
public Class getLabelingStrategyClass() {
|
891 |
return GeneralLabelingStrategy.class;
|
892 |
}
|
893 |
|
894 |
private class JComboBoxLabelingMethod extends JComboBox {
|
895 |
private static final long serialVersionUID = 5935267402200698145L;
|
896 |
|
897 |
public JComboBoxLabelingMethod(MethodItem[] items) {
|
898 |
super(items);
|
899 |
}
|
900 |
|
901 |
@Override
|
902 |
public void setSelectedItem(Object anObject) {
|
903 |
if (anObject instanceof MethodItem) {
|
904 |
MethodItem methodItem = (MethodItem) anObject;
|
905 |
for (int i = 0; i < getItemCount(); i++) {
|
906 |
MethodItem aux = (MethodItem) getItemAt(i);
|
907 |
if (aux.equals(methodItem)) {
|
908 |
aux.method=methodItem.method;
|
909 |
}
|
910 |
}
|
911 |
super.setSelectedItem(methodItem);
|
912 |
// ((MethodItem) super.getSelectedItem()).method = methodItem.method;
|
913 |
}
|
914 |
}
|
915 |
}
|
916 |
private class MethodItem {
|
917 |
private String name;
|
918 |
private ILabelingMethod method;
|
919 |
|
920 |
private MethodItem(String name, ILabelingMethod method) {
|
921 |
this.name = name;
|
922 |
this.method = method;
|
923 |
}
|
924 |
|
925 |
public String toString() {
|
926 |
return name;
|
927 |
}
|
928 |
|
929 |
@Override
|
930 |
public boolean equals(Object obj) {
|
931 |
if (obj != null && obj instanceof MethodItem) {
|
932 |
MethodItem methodItem = (MethodItem) obj;
|
933 |
return methodItem.method.getClass().equals(this.method.getClass());
|
934 |
}
|
935 |
return false;
|
936 |
}
|
937 |
}
|
938 |
|
939 |
}*/
|