svn-gvsig-desktop / trunk / extSymbology / src / org / gvsig / symbology / gui / layerproperties / GeneralLabeling.java @ 18755
History | View | Annotate | Download (26.2 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.Dimension; |
46 |
import java.awt.FlowLayout; |
47 |
import java.awt.Font; |
48 |
import java.awt.GridLayout; |
49 |
import java.awt.event.ActionEvent; |
50 |
import java.awt.event.ActionListener; |
51 |
import java.awt.event.MouseAdapter; |
52 |
import java.awt.event.MouseEvent; |
53 |
import java.util.ArrayList; |
54 |
import java.util.Comparator; |
55 |
import java.util.Hashtable; |
56 |
import java.util.Iterator; |
57 |
import java.util.TreeSet; |
58 |
|
59 |
import javax.swing.BorderFactory; |
60 |
import javax.swing.JCheckBox; |
61 |
import javax.swing.JComponent; |
62 |
import javax.swing.JLabel; |
63 |
import javax.swing.JOptionPane; |
64 |
import javax.swing.JPanel; |
65 |
import javax.swing.JScrollPane; |
66 |
import javax.swing.JTextField; |
67 |
|
68 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
69 |
import org.gvsig.gui.beans.controls.dnd.JDnDList; |
70 |
import org.gvsig.gui.beans.controls.dnd.JDnDListModel; |
71 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
72 |
import org.gvsig.gui.beans.swing.JBlank; |
73 |
import org.gvsig.gui.beans.swing.JButton; |
74 |
import org.gvsig.symbology.fmap.labeling.GeneralLabelingStrategy; |
75 |
import org.gvsig.symbology.fmap.labeling.LabelClassComparatorByPriority; |
76 |
|
77 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
78 |
import com.iver.andami.PluginServices; |
79 |
import com.iver.andami.messages.NotificationManager; |
80 |
import com.iver.andami.ui.mdiManager.IWindow; |
81 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
82 |
import com.iver.cit.gvsig.fmap.core.CartographicSupport; |
83 |
import com.iver.cit.gvsig.fmap.core.FShape; |
84 |
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle; |
85 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
86 |
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol; |
87 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
88 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
89 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingMethod; |
90 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingStrategy; |
91 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.IPlacementConstraints; |
92 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.IZoomConstraints; |
93 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelClass; |
94 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelingFactory; |
95 |
import com.iver.cit.gvsig.gui.styling.SelectorFilter; |
96 |
import com.iver.cit.gvsig.gui.styling.StyleSelector; |
97 |
import com.iver.cit.gvsig.gui.styling.SymbolPreviewer; |
98 |
import com.iver.cit.gvsig.gui.styling.SymbolSelector; |
99 |
import com.iver.cit.gvsig.gui.utils.FontChooser; |
100 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.ILabelingStrategyPanel; |
101 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.ISymbolSelector; |
102 |
import com.iver.utiles.swing.JComboBox; |
103 |
|
104 |
public class GeneralLabeling extends JPanel implements ILabelingStrategyPanel, ActionListener { |
105 |
private static Hashtable<String, Class> methods = new Hashtable<String, Class>(); |
106 |
private static int newClassSuffix = 0; |
107 |
private JButton btnVisualization; |
108 |
private JButton btnRenameClass; |
109 |
private JButton btnSQLQuery; |
110 |
private JButton btnDelClass; |
111 |
private JButton btnAddClass; |
112 |
private JComboBox cmbExpressions; |
113 |
private JButton btnEditExpression; |
114 |
private SymbolPreviewer previewer;
|
115 |
private JButton btnFont; |
116 |
private JButton btnPlacement; |
117 |
private JButton btnLabelStyles; |
118 |
private JComboBoxLabelingMethod cmbMethod;
|
119 |
private GridBagLayoutPanel classesPanel;
|
120 |
private JComboBox cmbClasses; |
121 |
private ArrayList<String> expressions; |
122 |
private IPlacementConstraints placementConstraints;
|
123 |
private IZoomConstraints zoomConstraints;
|
124 |
private JButton btnSymbol; |
125 |
private boolean noEvent; |
126 |
private JCheckBox chkLabel; |
127 |
private JCheckBox chkTextOnly; |
128 |
private FLyrVect layer;
|
129 |
private String[] fieldNames; |
130 |
private JDnDList lstClassPriorities;
|
131 |
private JCheckBox chkDefinePriorities; |
132 |
private JScrollPane scrlPan; |
133 |
// private String[] numericFieldNames;
|
134 |
|
135 |
public GeneralLabeling() {
|
136 |
initialize(); |
137 |
} |
138 |
|
139 |
private void initialize() { |
140 |
setLayout(new BorderLayout()); |
141 |
GridBagLayoutPanel left = new GridBagLayoutPanel();
|
142 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,0)); |
143 |
aux.add(new JLabel(PluginServices.getText(this, "method")+":")); |
144 |
aux.add(getCmbMethod()); |
145 |
aux.setPreferredSize(new Dimension(605, 40)); |
146 |
left.addComponent(aux); |
147 |
|
148 |
|
149 |
classesPanel = new GridBagLayoutPanel();
|
150 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,0)); |
151 |
aux.add(new JLabel(PluginServices.getText(this, "class")+":")); |
152 |
aux.add(getCmbClasses()); |
153 |
aux.add(getChkLabelFeatures()); |
154 |
aux.setPreferredSize(new Dimension(602, 40)); |
155 |
classesPanel.addComponent(aux); |
156 |
|
157 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0)); |
158 |
aux.add(getBtnAddClass()); |
159 |
aux.add(getBtnDelClass()); |
160 |
aux.add(getBtnRenameClass()); |
161 |
aux.add(getBtnSQLQuery()); |
162 |
aux.setPreferredSize(new Dimension(602, 30)); |
163 |
classesPanel.addComponent(aux); |
164 |
classesPanel.setBorder(BorderFactory.createTitledBorder(
|
165 |
null, PluginServices.getText(this, "classes"))); |
166 |
left.addComponent(classesPanel); |
167 |
|
168 |
|
169 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0)); |
170 |
aux.setBorder(BorderFactory.createTitledBorder(
|
171 |
null, PluginServices.getText(this, "text_string"))); |
172 |
aux.add(new JLabel(PluginServices.getText(this, "expression")+":")); |
173 |
aux.add(getCmbExpressions()); |
174 |
aux.add(getBtnEditExpression()); |
175 |
aux.setPreferredSize(new Dimension(612, 60)); |
176 |
left.addComponent(aux); |
177 |
|
178 |
|
179 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0)); |
180 |
aux.setBorder(BorderFactory.createTitledBorder(
|
181 |
null, PluginServices.getText(this, "text_symbol"))); |
182 |
aux.add(getSymbolPreviewer()); |
183 |
|
184 |
JPanel aux2 = new JPanel(); |
185 |
aux2.add(getBtnFont()); |
186 |
aux2.add(getBtnSymbol()); |
187 |
|
188 |
aux2.setLayout(new GridLayout(aux2.getComponentCount(), 1)); |
189 |
aux.add(aux2); |
190 |
aux.setPreferredSize(new Dimension(612, 100)); |
191 |
left.addComponent(aux); |
192 |
|
193 |
|
194 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0)); |
195 |
aux.setBorder(BorderFactory.createTitledBorder(
|
196 |
null, PluginServices.getText(this, "options"))); |
197 |
aux.add(getBtnVisualization()); |
198 |
aux.add(getBtnPlacement()); |
199 |
aux.add(getBtnLabelStyles()); |
200 |
aux.setPreferredSize(new Dimension(612, 60)); |
201 |
|
202 |
left.addComponent(aux); |
203 |
|
204 |
add(left, BorderLayout.CENTER);
|
205 |
|
206 |
JPanel right = new JPanel(new BorderLayout(15, 15)); |
207 |
aux = new JPanel(new BorderLayout(15, 15)); |
208 |
aux.add(getChkDefinePriorities(), BorderLayout.NORTH);
|
209 |
aux.add(getScrlClassPriorities(), BorderLayout.CENTER);
|
210 |
right.add(new JBlank(10, 10), BorderLayout.NORTH); |
211 |
right.add(aux, BorderLayout.CENTER);
|
212 |
right.add(new JBlank(10, 10), BorderLayout.SOUTH); |
213 |
right.add(new JBlank(10, 10), BorderLayout.EAST); |
214 |
add(right, BorderLayout.EAST);
|
215 |
} |
216 |
|
217 |
private Component getScrlClassPriorities() { |
218 |
if (scrlPan == null) { |
219 |
scrlPan = new JScrollPane(); |
220 |
scrlPan.setViewportView(getLstClassPriorities()); |
221 |
scrlPan.setPreferredSize(new Dimension(180, 300)); |
222 |
} |
223 |
return scrlPan;
|
224 |
|
225 |
|
226 |
} |
227 |
|
228 |
private JCheckBox getChkDefinePriorities() { |
229 |
if (chkDefinePriorities == null) { |
230 |
chkDefinePriorities = new JCheckBox(PluginServices.getText(this, "label_priority")); |
231 |
chkDefinePriorities.addActionListener(this);
|
232 |
chkDefinePriorities.setName("CHK_DEFINE_PRIORITIES");
|
233 |
} |
234 |
return chkDefinePriorities;
|
235 |
} |
236 |
|
237 |
private JDnDList getLstClassPriorities() {
|
238 |
if (lstClassPriorities == null) { |
239 |
lstClassPriorities = new JDnDList();
|
240 |
lstClassPriorities.setName("CLASS_PRIORITY_LIST");
|
241 |
lstClassPriorities.addMouseListener(new MouseAdapter() { |
242 |
@Override
|
243 |
public void mouseReleased(MouseEvent e) { |
244 |
JDnDListModel m = (JDnDListModel) lstClassPriorities.getModel(); |
245 |
for (int i = 0; i < m.getSize(); i++) { |
246 |
((LabelClass) m.getElementAt(i)).setPriority(i); |
247 |
} |
248 |
} |
249 |
}); |
250 |
|
251 |
} |
252 |
return lstClassPriorities;
|
253 |
} |
254 |
|
255 |
private void refreshControls() { |
256 |
// classes combo box
|
257 |
refreshClasses(); |
258 |
|
259 |
// fires an event from the methods combo box
|
260 |
actionPerformed(new ActionEvent(getCmbMethod(), 0, null)); |
261 |
} |
262 |
|
263 |
private JButton getBtnVisualization() { |
264 |
if (btnVisualization == null) { |
265 |
btnVisualization = new JButton( |
266 |
PluginServices.getText(this, "visualization")+"..."); |
267 |
btnVisualization.setName("BTNVISUALIZATION");
|
268 |
btnVisualization.addActionListener(this);
|
269 |
} |
270 |
return btnVisualization;
|
271 |
} |
272 |
|
273 |
private JButton getBtnLabelStyles() { |
274 |
if (btnLabelStyles == null) { |
275 |
btnLabelStyles = new JButton( |
276 |
PluginServices.getText(this, "label_styles")+"..."); |
277 |
btnLabelStyles.setName("BTNLABELSTYLES");
|
278 |
btnLabelStyles.addActionListener(this);
|
279 |
} |
280 |
return btnLabelStyles;
|
281 |
} |
282 |
|
283 |
private JButton getBtnPlacement() { |
284 |
if (btnPlacement == null) { |
285 |
btnPlacement = new JButton( |
286 |
PluginServices.getText(this, "placement")+"..."); |
287 |
btnPlacement.setName("BTNPLACEMENT");
|
288 |
btnPlacement.addActionListener(this);
|
289 |
} |
290 |
return btnPlacement;
|
291 |
} |
292 |
|
293 |
private JButton getBtnFont() { |
294 |
if (btnFont == null) { |
295 |
btnFont = new JButton( |
296 |
PluginServices.getText(this,"fuente")+"..."); |
297 |
btnFont.setName("BTNFONT");
|
298 |
btnFont.addActionListener(this);
|
299 |
} |
300 |
return btnFont;
|
301 |
} |
302 |
|
303 |
|
304 |
private Component getBtnSymbol() { |
305 |
if (btnSymbol == null) { |
306 |
btnSymbol = new JButton(PluginServices.getText(this, "symbol")); |
307 |
btnSymbol.setName("BTNSYMBOL");
|
308 |
btnSymbol.addActionListener(this);
|
309 |
} |
310 |
|
311 |
return btnSymbol;
|
312 |
} |
313 |
|
314 |
private SymbolPreviewer getSymbolPreviewer() {
|
315 |
if (previewer == null) { |
316 |
previewer = new SymbolPreviewer();
|
317 |
previewer.setPreferredSize(new Dimension(420, 65)); |
318 |
} |
319 |
return previewer;
|
320 |
} |
321 |
|
322 |
private JComboBox getCmbMethod() { |
323 |
if (cmbMethod == null) { |
324 |
Iterator<String> it = methods.keySet().iterator(); |
325 |
ArrayList<MethodItem> aux = new ArrayList<MethodItem>(); |
326 |
while (it.hasNext()) {
|
327 |
String name = it.next();
|
328 |
|
329 |
Class methodClass = (Class) methods.get(name); |
330 |
ILabelingMethod method; |
331 |
try {
|
332 |
method = (ILabelingMethod) methodClass.newInstance(); |
333 |
MethodItem newItem = new MethodItem(name, method);
|
334 |
aux.add(newItem); |
335 |
|
336 |
} catch (InstantiationException e) { |
337 |
NotificationManager.addError("Trying to instantiate an interface" +
|
338 |
" or abstract class + "+methodClass.getName(), e);
|
339 |
} catch (IllegalAccessException e) { |
340 |
NotificationManager.addError("IllegalAccessException: does " +
|
341 |
methodClass.getName() + " class have an anonymous" +
|
342 |
" constructor?", e);
|
343 |
} |
344 |
|
345 |
} |
346 |
cmbMethod = new JComboBoxLabelingMethod(aux.toArray(new MethodItem[0])); |
347 |
cmbMethod.setSize(new Dimension(300, 22)); |
348 |
cmbMethod.setName("CMBMETHOD");
|
349 |
cmbMethod.addActionListener(this);
|
350 |
} |
351 |
return cmbMethod;
|
352 |
} |
353 |
|
354 |
private JButton getBtnEditExpression() { |
355 |
if (btnEditExpression == null) { |
356 |
btnEditExpression = new JButton( |
357 |
PluginServices.getText(this, "edit_expression")+"..."); |
358 |
btnEditExpression.setName("BTNEDITEXPRESSION");
|
359 |
btnEditExpression.addActionListener(this);
|
360 |
} |
361 |
return btnEditExpression;
|
362 |
} |
363 |
|
364 |
private JComboBox getCmbExpressions() { |
365 |
if (cmbExpressions == null) { |
366 |
cmbExpressions = new JComboBox(); |
367 |
cmbExpressions.setPreferredSize(new Dimension(150, 20)); |
368 |
cmbExpressions.setName("CMBEXPRESSIONS");
|
369 |
cmbExpressions.addActionListener(this);
|
370 |
} |
371 |
return cmbExpressions;
|
372 |
|
373 |
} |
374 |
|
375 |
private JButton getBtnSQLQuery() { |
376 |
if (btnSQLQuery == null) { |
377 |
btnSQLQuery = new JButton(PluginServices.getText(this, "SQL_query")); |
378 |
btnSQLQuery.setName("BTNSQLQUERY");
|
379 |
btnSQLQuery.addActionListener(this);
|
380 |
} |
381 |
return btnSQLQuery;
|
382 |
} |
383 |
|
384 |
private JButton getBtnRenameClass() { |
385 |
if (btnRenameClass == null) { |
386 |
btnRenameClass = new JButton(PluginServices.getText(this, "remane_class")); |
387 |
btnRenameClass.setName("BTNRENAMECLASS");
|
388 |
btnRenameClass.addActionListener(this);
|
389 |
} |
390 |
return btnRenameClass;
|
391 |
} |
392 |
|
393 |
private JButton getBtnDelClass() { |
394 |
if (btnDelClass == null) { |
395 |
btnDelClass = new JButton(PluginServices.getText(this, "delete_class")); |
396 |
btnDelClass.setName("BTNDELCLASS");
|
397 |
btnDelClass.addActionListener(this);
|
398 |
} |
399 |
return btnDelClass;
|
400 |
} |
401 |
|
402 |
private JButton getBtnAddClass() { |
403 |
if (btnAddClass == null) { |
404 |
btnAddClass = new JButton(PluginServices.getText(this, "add_class")); |
405 |
btnAddClass.setName("BTNADDCLASS");
|
406 |
btnAddClass.addActionListener(this);
|
407 |
} |
408 |
return btnAddClass;
|
409 |
} |
410 |
|
411 |
private JCheckBox getChkLabelFeatures() { |
412 |
if (chkLabel == null) { |
413 |
chkLabel = new JCheckBox(); |
414 |
chkLabel.setText(PluginServices.getText(this, "label_features_in_this_class")); |
415 |
chkLabel.setName("CHKLABEL");
|
416 |
chkLabel.addActionListener(this);
|
417 |
} |
418 |
return chkLabel;
|
419 |
} |
420 |
|
421 |
private JComboBox getCmbClasses() { |
422 |
if (cmbClasses == null) { |
423 |
cmbClasses = new JComboBox(); |
424 |
cmbClasses.setPreferredSize(new Dimension(150, 20)); |
425 |
cmbClasses.setName("CMBCLASSES");
|
426 |
cmbClasses.addActionListener(this);
|
427 |
} |
428 |
return cmbClasses;
|
429 |
} |
430 |
|
431 |
public ILabelingStrategy getLabelingStrategy() {
|
432 |
// ILabelingMethod method = getMethod();
|
433 |
|
434 |
|
435 |
return LabelingFactory.
|
436 |
createStrategy((FLayer) layer, |
437 |
getMethod(), |
438 |
getPlacementConstraints(), |
439 |
getZoomConstraints()); |
440 |
} |
441 |
|
442 |
public void setModel(FLayer layer, ILabelingStrategy str) { |
443 |
if (layer instanceof FLyrVect) { |
444 |
this.layer = (FLyrVect) layer;
|
445 |
FLyrVect lv = (FLyrVect) layer; |
446 |
try {
|
447 |
fieldNames = lv.getRecordset().getFieldNames(); |
448 |
//
|
449 |
// // detect the numeric fields
|
450 |
// ArrayList<String> l = new ArrayList<String>();
|
451 |
// for (int i = 0; i < fieldNames.length; i++) {
|
452 |
// switch (lv.getRecordset().getFieldType(i)) {
|
453 |
// case Types.DECIMAL:
|
454 |
// case Types.NUMERIC:
|
455 |
// case Types.FLOAT:
|
456 |
// case Types.DOUBLE:
|
457 |
// case Types.INTEGER:
|
458 |
// case Types.REAL:
|
459 |
// case Types.SMALLINT:
|
460 |
// case Types.TINYINT:
|
461 |
// case Types.BIGINT:
|
462 |
// l.add(fieldNames[i]);
|
463 |
// break;
|
464 |
// }
|
465 |
// }
|
466 |
// numericFieldNames = l.toArray(new String[l.size()]);
|
467 |
|
468 |
if (str instanceof GeneralLabelingStrategy) { |
469 |
setMethod(str.getLabelingMethod()); |
470 |
placementConstraints = str.getPlacementConstraints(); |
471 |
} |
472 |
refreshControls(); |
473 |
} catch (ReadDriverException e) {
|
474 |
NotificationManager.addError(PluginServices.getText(this, "accessing_file_structure"), e); |
475 |
} |
476 |
} |
477 |
|
478 |
|
479 |
} |
480 |
|
481 |
|
482 |
public static void addLabelingMethod(String name, Class iLabelingMethodClass) { |
483 |
methods.put(name, iLabelingMethodClass); |
484 |
} |
485 |
|
486 |
private void setMethod(ILabelingMethod labelingMethod) { |
487 |
getCmbMethod().setSelectedItem(new MethodItem(null, labelingMethod)); |
488 |
} |
489 |
|
490 |
private ILabelingMethod getMethod() {
|
491 |
return ((MethodItem) getCmbMethod().getSelectedItem()).method;
|
492 |
} |
493 |
|
494 |
private void refreshCmbExpressions() { |
495 |
|
496 |
ArrayList<String> exp = getExpressions(); |
497 |
|
498 |
noEvent = true;
|
499 |
LabelClass lc = getActiveClass(); |
500 |
if ( lc != null && |
501 |
lc.getLabelExpression()!=null &&
|
502 |
!lc.getLabelExpression().equals("") &&
|
503 |
!exp.contains(lc.getLabelExpression())) { |
504 |
exp.add(0, lc.getLabelExpression());
|
505 |
} |
506 |
|
507 |
getCmbExpressions().removeAllItems(); |
508 |
for (int i = 0; i < exp.size(); i++) { |
509 |
getCmbExpressions().addItem(exp.get(i)); |
510 |
} |
511 |
if (lc != null) { |
512 |
getCmbExpressions().setSelectedItem(lc.getLabelExpression()); |
513 |
} else {
|
514 |
getCmbExpressions().setSelectedItem(exp.get(0));
|
515 |
} |
516 |
noEvent = false;
|
517 |
} |
518 |
|
519 |
private ArrayList<String> getExpressions() { |
520 |
if (expressions == null) { |
521 |
expressions = new ArrayList<String>(); |
522 |
try {
|
523 |
for (int i = 0; i < fieldNames.length; i++) { |
524 |
expressions.add("["+fieldNames[i]+"];"); |
525 |
} |
526 |
} catch (Exception e) { |
527 |
NotificationManager.addError( |
528 |
PluginServices.getText( |
529 |
this, "could_not_retreive_layer_names"), e); |
530 |
} |
531 |
} |
532 |
return expressions;
|
533 |
} |
534 |
|
535 |
private void refreshClasses() { |
536 |
// label classes
|
537 |
getCmbClasses().removeAllItems(); |
538 |
LabelClass[] lClasses = getMethod().getLabelClasses();
|
539 |
for (int i = 0; i < lClasses.length; i++) { |
540 |
getCmbClasses().addItem(lClasses[i]); |
541 |
|
542 |
} |
543 |
|
544 |
// expressions combo box
|
545 |
refreshCmbExpressions(); |
546 |
|
547 |
// panel priorities
|
548 |
refreshPnlPriorities(); |
549 |
|
550 |
} |
551 |
|
552 |
private void refreshPnlPriorities() { |
553 |
TreeSet<LabelClass> ts = new TreeSet<LabelClass>(new LabelClassComparatorByPriority()); |
554 |
|
555 |
LabelClass[] lClasses = getMethod().getLabelClasses();
|
556 |
for (int i = 0; i < lClasses.length; i++) { |
557 |
ts.add(lClasses[i]); |
558 |
} |
559 |
|
560 |
// refresh label priority panel
|
561 |
getChkDefinePriorities().setSelected(getMethod().definesPriorities()); |
562 |
JDnDListModel m = new JDnDListModel();
|
563 |
for (LabelClass labelClass : ts) {
|
564 |
m.addElement(labelClass); |
565 |
} |
566 |
getLstClassPriorities().setModel(m); |
567 |
|
568 |
} |
569 |
|
570 |
private LabelClass getActiveClass() {
|
571 |
return (LabelClass) getCmbClasses().getSelectedItem();
|
572 |
} |
573 |
|
574 |
private IZoomConstraints getZoomConstraints() {
|
575 |
return zoomConstraints;
|
576 |
} |
577 |
|
578 |
private IPlacementConstraints getPlacementConstraints() {
|
579 |
return placementConstraints;
|
580 |
} |
581 |
|
582 |
public void actionPerformed(ActionEvent e) { |
583 |
if (noEvent) return; |
584 |
JComponent c = (JComponent)e.getSource(); |
585 |
|
586 |
if (c.equals(btnAddClass)) {
|
587 |
LabelClass newClass = new LabelClass();
|
588 |
newClass.setName(PluginServices.getText(this, "labeling")+String.valueOf(++newClassSuffix)); |
589 |
getMethod().addLabelClass(newClass); |
590 |
refreshClasses(); |
591 |
getCmbClasses().setSelectedItem(newClass); |
592 |
} else if (c.equals(btnDelClass)) { |
593 |
LabelClass clazz = getActiveClass(); |
594 |
getMethod().deleteLabelClass(clazz); |
595 |
refreshClasses(); |
596 |
} else if (c.equals(btnEditExpression)) { |
597 |
ExprEditorPanel ep = new ExprEditorPanel((String) getCmbExpressions(). |
598 |
getSelectedItem()); |
599 |
PluginServices.getMDIManager().addWindow( ep ); |
600 |
getCmbExpressions().addItem(ep.getExpression()); |
601 |
getCmbExpressions().setSelectedItem(ep.getExpression()); |
602 |
} else if (c.equals(btnFont)) { |
603 |
Font labelFont = getActiveClass().getTextSymbol().getFont();
|
604 |
Font newFont = FontChooser.showDialog(PluginServices.getText(this, "font"), labelFont); |
605 |
if (newFont != null) { |
606 |
getActiveClass().getTextSymbol().setFont(newFont); |
607 |
} |
608 |
refreshTextSymbolPreviewer(); |
609 |
} else if (c.equals(btnLabelStyles)) { |
610 |
LabelClass clazz = getActiveClass(); |
611 |
// here open symbol selector
|
612 |
|
613 |
StyleSelector stySel = new StyleSelector(
|
614 |
clazz.getLabelStyle(), |
615 |
FShape.TEXT ); |
616 |
stySel.setUnit(clazz.getUnit()); |
617 |
stySel.setReferenceSystem(clazz.getReferenceSystem()); |
618 |
PluginServices.getMDIManager().addWindow(stySel); |
619 |
ILabelStyle sty = (ILabelStyle) stySel.getSelectedObject(); |
620 |
if (sty != null) { |
621 |
// gather the style and apply to the class
|
622 |
clazz.setLabelStyle(sty); |
623 |
clazz.setUnit(stySel.getUnit()); |
624 |
clazz.setReferenceSystem(stySel.getReferenceSystem()); |
625 |
|
626 |
} |
627 |
} else if (c.equals(btnPlacement)) { |
628 |
|
629 |
try {
|
630 |
PlacementProperties pp = new PlacementProperties(
|
631 |
(FLyrVect) layer, |
632 |
getPlacementConstraints()); |
633 |
PluginServices.getMDIManager().addWindow(pp); |
634 |
placementConstraints = pp.getPlacementConstraints(); |
635 |
} catch (ClassCastException ccEx) { |
636 |
NotificationManager.addError("Placement constraints not prepared for:"
|
637 |
+layer.getClass().getName(), |
638 |
ccEx); |
639 |
} catch (ReadDriverException dEx) {
|
640 |
NotificationManager.addWarning("Should be unreachable code", dEx);
|
641 |
NotificationManager.addError(PluginServices.getText(this, "usupported_layer_type"), dEx); |
642 |
} |
643 |
|
644 |
} else if (c.equals(btnRenameClass)) { |
645 |
LabelClass clazz = getActiveClass(); |
646 |
String newName = JOptionPane.showInputDialog( |
647 |
PluginServices.getText(this, "enter_new_name")); |
648 |
if (newName != null) |
649 |
getMethod().renameLabelClass(clazz, newName); |
650 |
refreshClasses(); |
651 |
} else if (c.equals(btnSQLQuery)) { |
652 |
LabelClass clazz = getActiveClass(); |
653 |
String query = clazz.getSQLQuery();
|
654 |
query = JOptionPane.showInputDialog(null, |
655 |
"select from "+layer.getName()+" where ", |
656 |
"SQL query",
|
657 |
JOptionPane.QUESTION_MESSAGE);
|
658 |
if (!query.equals("")) { |
659 |
clazz.setSQLQuery(query); |
660 |
} |
661 |
|
662 |
} else if (c.equals(btnVisualization)) { |
663 |
|
664 |
} else if (c.equals(chkLabel)) { |
665 |
LabelClass lc = (LabelClass) getCmbClasses().getSelectedItem(); |
666 |
if (lc == null) |
667 |
lc = getMethod().getDefaultLabelClass(); |
668 |
lc.setVisible(chkLabel.isSelected()); |
669 |
} else if (c.equals(chkTextOnly)) { |
670 |
|
671 |
} else if (c.equals(cmbClasses)) { |
672 |
// refresh expressions
|
673 |
LabelClass lc = (LabelClass) cmbClasses.getSelectedItem(); |
674 |
if (lc != null && lc.getLabelExpression() != null && !getExpressions().contains(lc.getLabelExpression())) { |
675 |
getExpressions().add(0, lc.getLabelExpression());
|
676 |
} |
677 |
refreshCmbExpressions(); |
678 |
} else if (c.equals(cmbExpressions)) { |
679 |
LabelClass lc = (LabelClass) getCmbClasses().getSelectedItem(); |
680 |
if (lc == null) |
681 |
lc = getMethod().getDefaultLabelClass(); |
682 |
lc.setLabelExpression((String) cmbExpressions.getSelectedItem());
|
683 |
} else if (c.equals(cmbMethod)) { |
684 |
// disable components in class panel
|
685 |
// multiple class or not enables or disables the class panel
|
686 |
setComponentEnabled(classesPanel, getMethod().allowsMultipleClass()); |
687 |
refreshClasses(); |
688 |
|
689 |
refreshTextSymbolPreviewer(); |
690 |
} else if (c.equals(chkDefinePriorities)) { |
691 |
getMethod().setDefinesPriorities(chkDefinePriorities.isSelected()); |
692 |
refreshPnlPriorities(); |
693 |
} else if (c.equals(btnSymbol)) { |
694 |
LabelClass clazz = getActiveClass(); |
695 |
// here open symbol selector
|
696 |
|
697 |
ISymbolSelector symSel = SymbolSelector.createSymbolSelector(clazz.getTextSymbol(), |
698 |
FShape.TEXT, |
699 |
new SelectorFilter() {
|
700 |
public boolean accepts(Object obj) { |
701 |
if (obj instanceof ISymbol) { |
702 |
ISymbol sym = (ISymbol) obj; |
703 |
return sym.getSymbolType() == FShape.TEXT;
|
704 |
} |
705 |
return false; |
706 |
} |
707 |
}); |
708 |
|
709 |
PluginServices.getMDIManager().addWindow(symSel); |
710 |
ISymbol sym = (ISymbol) symSel.getSelectedObject(); |
711 |
if (sym != null) { |
712 |
// gather the symbol and apply to the class
|
713 |
if (sym instanceof CartographicSupport) { |
714 |
CartographicSupport csSty = (CartographicSupport) sym; |
715 |
clazz.setUnit(csSty.getUnit()); |
716 |
clazz.setReferenceSystem(csSty.getReferenceSystem()); |
717 |
} |
718 |
clazz.setTextSymbol((ITextSymbol) sym); |
719 |
|
720 |
} |
721 |
|
722 |
refreshTextSymbolPreviewer(); |
723 |
} |
724 |
} |
725 |
|
726 |
|
727 |
private void refreshTextSymbolPreviewer() { |
728 |
ITextSymbol textSym = getActiveClass().getTextSymbol(); |
729 |
textSym.setText(PluginServices.getText(this, "GeneralLabeling.sample_text")); |
730 |
getSymbolPreviewer().setSymbol(textSym); |
731 |
|
732 |
} |
733 |
|
734 |
private void setComponentEnabled(Component c, boolean b) { |
735 |
if (c instanceof JComponent) { |
736 |
JComponent c1 = (JComponent) c; |
737 |
for (int i = 0; i < c1.getComponentCount(); i++) { |
738 |
setComponentEnabled(c1.getComponent(i), b); |
739 |
} |
740 |
} |
741 |
c.setEnabled(b); |
742 |
} |
743 |
|
744 |
public String getLabelingStrategyName() { |
745 |
return PluginServices.getText(this, "user_defined_labels"); |
746 |
} |
747 |
|
748 |
public Class getLabelingStrategyClass() { |
749 |
return GeneralLabelingStrategy.class;
|
750 |
} |
751 |
|
752 |
private class JComboBoxLabelingMethod extends JComboBox { |
753 |
private static final long serialVersionUID = 5935267402200698145L; |
754 |
|
755 |
public JComboBoxLabelingMethod(MethodItem[] items) { |
756 |
super(items);
|
757 |
} |
758 |
|
759 |
@Override
|
760 |
public void setSelectedItem(Object anObject) { |
761 |
if (anObject instanceof MethodItem) { |
762 |
MethodItem methodItem = (MethodItem) anObject; |
763 |
super.setSelectedItem(methodItem);
|
764 |
((MethodItem) super.getSelectedItem()).method = methodItem.method;
|
765 |
} |
766 |
} |
767 |
} |
768 |
private class MethodItem { |
769 |
private String name; |
770 |
private ILabelingMethod method;
|
771 |
|
772 |
private MethodItem(String name, ILabelingMethod method) { |
773 |
this.name = name;
|
774 |
this.method = method;
|
775 |
} |
776 |
|
777 |
public String toString() { |
778 |
return name;
|
779 |
} |
780 |
|
781 |
@Override
|
782 |
public boolean equals(Object obj) { |
783 |
if (obj != null && obj instanceof MethodItem) { |
784 |
MethodItem methodItem = (MethodItem) obj; |
785 |
return methodItem.method.getClass().equals(this.method.getClass()); |
786 |
} |
787 |
return false; |
788 |
} |
789 |
} |
790 |
private class ExprEditorPanel extends JPanel implements IWindow { |
791 |
private static final long serialVersionUID = -3867224882591879900L; |
792 |
private ActionListener action = new ActionListener() { |
793 |
public void actionPerformed(ActionEvent e) { |
794 |
if ("OK".equals(e.getActionCommand())) { |
795 |
if (validateExpr())
|
796 |
PluginServices.getMDIManager().closeWindow( |
797 |
ExprEditorPanel.this); |
798 |
else
|
799 |
JOptionPane.showMessageDialog(ExprEditorPanel.this,
|
800 |
PluginServices.getText(this, "syntax_error"), |
801 |
PluginServices.getText(this, "error"), |
802 |
JOptionPane.ERROR_MESSAGE);
|
803 |
} else {
|
804 |
getTxtExpression().setText(lastExtression); |
805 |
PluginServices.getMDIManager().closeWindow( |
806 |
ExprEditorPanel.this); |
807 |
} |
808 |
} |
809 |
}; |
810 |
private JTextField txtExpression; |
811 |
private String lastExtression; |
812 |
|
813 |
public ExprEditorPanel(String currentExpression) { |
814 |
super();
|
815 |
initialize(); |
816 |
lastExtression = currentExpression; |
817 |
getTxtExpression().setText(currentExpression); |
818 |
|
819 |
} |
820 |
|
821 |
private void initialize() { |
822 |
GridBagLayoutPanel content = new GridBagLayoutPanel();
|
823 |
content.addComponent(new JLabel(" "+PluginServices.getText(this, "label_expression_help"))); |
824 |
content.addComponent( |
825 |
" "+PluginServices.getText(this, "expression")+":", |
826 |
getTxtExpression()); |
827 |
setLayout(new BorderLayout(5, 5)); |
828 |
|
829 |
add(content, BorderLayout.CENTER);
|
830 |
add(new AcceptCancelPanel(action, action), BorderLayout.SOUTH); |
831 |
setSize(new Dimension(300, 80)); |
832 |
} |
833 |
|
834 |
private JTextField getTxtExpression() { |
835 |
if (txtExpression == null) { |
836 |
txtExpression = new JTextField(25); |
837 |
} |
838 |
return txtExpression;
|
839 |
} |
840 |
|
841 |
public String getExpression() { |
842 |
return getTxtExpression().getText();
|
843 |
} |
844 |
|
845 |
public WindowInfo getWindowInfo() {
|
846 |
WindowInfo viewInfo = new WindowInfo(WindowInfo.MODALDIALOG);
|
847 |
viewInfo.setWidth(getWidth()); |
848 |
viewInfo.setHeight(getHeight()); |
849 |
viewInfo.setTitle(PluginServices.getText(this,"label_expression_editor")); |
850 |
return viewInfo;
|
851 |
} |
852 |
|
853 |
private boolean validateExpr() { |
854 |
// TODO : implement it
|
855 |
return true; |
856 |
} |
857 |
} |
858 |
} |