svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.labeling.app / org.gvsig.labeling.app.mainplugin / src / main / java / org / gvsig / labeling / gui / layerproperties / LabelClassProperties.java @ 40911
History | View | Annotate | Download (28 KB)
1 | 40911 | jldominguez | /* 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.labeling.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.GridBagConstraints; |
||
48 | import java.awt.GridBagLayout; |
||
49 | import java.awt.GridLayout; |
||
50 | import java.awt.event.ActionEvent; |
||
51 | import java.awt.event.ActionListener; |
||
52 | |||
53 | import javax.swing.AbstractCellEditor; |
||
54 | import javax.swing.BorderFactory; |
||
55 | import javax.swing.ButtonGroup; |
||
56 | import javax.swing.JButton; |
||
57 | import javax.swing.JCheckBox; |
||
58 | import javax.swing.JComponent; |
||
59 | import javax.swing.JLabel; |
||
60 | import javax.swing.JOptionPane; |
||
61 | import javax.swing.JPanel; |
||
62 | import javax.swing.JRadioButton; |
||
63 | import javax.swing.JScrollPane; |
||
64 | import javax.swing.JTable; |
||
65 | import javax.swing.JTextField; |
||
66 | import javax.swing.table.DefaultTableModel; |
||
67 | import javax.swing.table.TableCellEditor; |
||
68 | import javax.swing.table.TableColumnModel; |
||
69 | |||
70 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
71 | import org.gvsig.andami.ui.mdiManager.WindowInfo; |
||
72 | import org.gvsig.app.ApplicationLocator; |
||
73 | import org.gvsig.app.gui.styling.SingleStyleSelectorFilter; |
||
74 | import org.gvsig.app.gui.styling.StylePreviewer; |
||
75 | import org.gvsig.app.gui.styling.StyleSelector; |
||
76 | import org.gvsig.fmap.dal.exception.DataException; |
||
77 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
78 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
79 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
80 | import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
||
81 | import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol; |
||
82 | import org.gvsig.fmap.mapcontext.rendering.symbols.styles.IBackgroundFileStyle; |
||
83 | import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ILabelStyle; |
||
84 | import org.gvsig.fmap.mapcontext.rendering.symbols.styles.IStyle; |
||
85 | import org.gvsig.gui.beans.AcceptCancelPanel; |
||
86 | import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
||
87 | import org.gvsig.gui.beans.swing.JBlank; |
||
88 | import org.gvsig.i18n.Messages; |
||
89 | import org.gvsig.labeling.lang.LabelClassUtils; |
||
90 | import org.gvsig.symbology.SymbologyLocator; |
||
91 | import org.slf4j.Logger; |
||
92 | import org.slf4j.LoggerFactory; |
||
93 | |||
94 | |||
95 | /**
|
||
96 | *
|
||
97 | * LabelClassProperties.java
|
||
98 | *
|
||
99 | *
|
||
100 | * @author jaume dominguez faus - jaume.dominguez@iver.es May 27, 2008
|
||
101 | *
|
||
102 | */
|
||
103 | public class LabelClassProperties extends JPanel implements IWindow, |
||
104 | ActionListener {
|
||
105 | |||
106 | private static final Logger logger = |
||
107 | LoggerFactory.getLogger(LabelClassProperties.class); |
||
108 | |||
109 | private static final String TEST_SQL = "TEST_SQL"; |
||
110 | private static final String DELETE_FIELD = "DELETE_FIELD"; |
||
111 | private static final long serialVersionUID = 6528513396536811057L; |
||
112 | private static final String ADD_FIELD = "ADD_FIELD"; |
||
113 | private static final String SELECT_STYLE = "SELECT_STYLE"; |
||
114 | private static final String CLEAR_STYLE = "CLEAR_STYLE"; |
||
115 | private static final String VERIFY = "VERIFY"; |
||
116 | private JTextField txtName; |
||
117 | private ILabelClass lc, clonedClass;
|
||
118 | private JTable tblExpressions; |
||
119 | private JButton btnRemoveField; |
||
120 | private JButton btnAddField; |
||
121 | private JButton btnVerify; |
||
122 | private JComponent styPreviewer; |
||
123 | private JButton btnSelStyle; |
||
124 | private JRadioButton rdBtnFilteredFeatures; |
||
125 | private JRadioButton rdBtnAllFeatures; |
||
126 | private JTextField txtSQL; |
||
127 | private JCheckBox chkLabelFeatures; |
||
128 | private LabelTextStylePanel textStyle;
|
||
129 | private JPanel sqlPnl; |
||
130 | private LabelClassPreview labelPreview;
|
||
131 | |||
132 | /*
|
||
133 | private String[] fieldNames;
|
||
134 | private int[] fieldTypes;
|
||
135 | */
|
||
136 | private FeatureStore featureStore = null; |
||
137 | private JButton btnDontUseStyle; |
||
138 | private boolean accepted = true; |
||
139 | |||
140 | |||
141 | |||
142 | /**
|
||
143 | * <p>
|
||
144 | * Creates a new instance of the dialog that configures all the properties
|
||
145 | * of a LabelClass.
|
||
146 | * </p>
|
||
147 | * @param strategy
|
||
148 | * @param asWindow
|
||
149 | */
|
||
150 | public LabelClassProperties(FeatureStore fsto) {
|
||
151 | |||
152 | featureStore = fsto; |
||
153 | initialize(); |
||
154 | } |
||
155 | |||
156 | private void initialize() { |
||
157 | setPreferredSize(new Dimension(810, 580)); |
||
158 | setLayout(new BorderLayout(1, 1)); |
||
159 | |||
160 | txtName = new JTextField(40); |
||
161 | JPanel northPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 15, 2)); |
||
162 | northPanel.add(new JLabel(Messages.getText("name") + ":")); |
||
163 | northPanel.add(txtName); |
||
164 | add(northPanel, BorderLayout.NORTH);
|
||
165 | |||
166 | JPanel centerPanel = new JPanel(new BorderLayout(10, 10)); |
||
167 | textStyle = new LabelTextStylePanel();
|
||
168 | textStyle.addActionListener(this);
|
||
169 | centerPanel.add(textStyle, BorderLayout.NORTH);
|
||
170 | |||
171 | JPanel labelExpressionsPanel = new JPanel(new BorderLayout(1, 1)); |
||
172 | |||
173 | labelExpressionsPanel.add(new JBlank(10, 30), BorderLayout.WEST); |
||
174 | labelExpressionsPanel.add(new JScrollPane(getTableFields()), |
||
175 | BorderLayout.CENTER);
|
||
176 | |||
177 | JPanel a = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 0)); |
||
178 | a.add(new JLabel("<html><b>"+Messages.getText("text_fields")+"</b></html>")); |
||
179 | centerPanel.add(labelExpressionsPanel, BorderLayout.CENTER);
|
||
180 | |||
181 | |||
182 | GridLayout gbl = new GridLayout(3, 1, 0, 6); |
||
183 | JPanel auxp = new JPanel(gbl); |
||
184 | auxp.add(getBtnVerify()); |
||
185 | auxp.add(getBtnAddField()); |
||
186 | auxp.add(getBtnRemoveField()); |
||
187 | auxp.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10)); |
||
188 | JPanel auxpp = new JPanel(); |
||
189 | auxpp.add(auxp); |
||
190 | |||
191 | centerPanel.add(auxpp, BorderLayout.EAST);
|
||
192 | |||
193 | |||
194 | GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
||
195 | // aux.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(
|
||
196 | // this, "features")));
|
||
197 | rdBtnAllFeatures = new JRadioButton(Messages.getText("all_features")); |
||
198 | rdBtnFilteredFeatures = new JRadioButton(Messages.getText("filtered_features") |
||
199 | +" (SQL GDBMS)");
|
||
200 | |||
201 | rdBtnAllFeatures.addActionListener(this);
|
||
202 | rdBtnFilteredFeatures.addActionListener(this);
|
||
203 | |||
204 | ButtonGroup g = new ButtonGroup(); |
||
205 | g.add(rdBtnAllFeatures); |
||
206 | g.add(rdBtnFilteredFeatures); |
||
207 | aux.addComponent(chkLabelFeatures = new JCheckBox( |
||
208 | Messages.getText("label_features_in_this_class")));
|
||
209 | aux.addComponent("", rdBtnAllFeatures);
|
||
210 | aux.addComponent("", rdBtnFilteredFeatures);
|
||
211 | sqlPnl = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
||
212 | sqlPnl.add(new JLabel(" SQL: select * from ")); |
||
213 | sqlPnl.add(new JLabel("%" + Messages.getText("layer_name") |
||
214 | + "%"));
|
||
215 | sqlPnl.add(new JLabel(" where ")); |
||
216 | sqlPnl.add(txtSQL = new JTextField(40)); |
||
217 | sqlPnl.add(new JLabel(";")); |
||
218 | aux.addComponent("", sqlPnl);
|
||
219 | |||
220 | |||
221 | JPanel auxPanel = new JPanel(new BorderLayout(1,1)); |
||
222 | |||
223 | JPanel aux2 = new JPanel(); |
||
224 | auxPanel.setBorder(BorderFactory.createTitledBorder(
|
||
225 | Messages.getText("background_style")));
|
||
226 | |||
227 | aux2.add(getStylePreviewer()); |
||
228 | |||
229 | gbl = new GridLayout(2, 1, 0, 6); |
||
230 | JPanel aux3 = new JPanel(gbl); |
||
231 | aux3.add(getBtnSelectStyle()); |
||
232 | aux3.add(getBtnDontUseStyle()); |
||
233 | aux3.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10)); |
||
234 | auxpp = new JPanel(); |
||
235 | auxpp.add(aux3); |
||
236 | |||
237 | auxPanel.add(aux2,BorderLayout.CENTER);
|
||
238 | auxPanel.add(auxpp,BorderLayout.EAST);
|
||
239 | |||
240 | JPanel aux4 = new JPanel(new GridLayout(1,2)); |
||
241 | aux4.add(auxPanel); |
||
242 | aux2 = new JPanel(new BorderLayout()); |
||
243 | aux2.setBorder(BorderFactory.createTitledBorder(Messages.getText("preview"))); |
||
244 | aux2.add(labelPreview = new LabelClassPreview(), BorderLayout.CENTER); |
||
245 | aux4.add(aux2); |
||
246 | |||
247 | GridBagLayoutPanel aux5 = new GridBagLayoutPanel();
|
||
248 | aux5.addComponent("", aux);
|
||
249 | aux5.addComponent(new JBlank(3, 5)); |
||
250 | aux5.addComponent("", aux4);
|
||
251 | centerPanel.add(aux5, BorderLayout.SOUTH);
|
||
252 | add(centerPanel, BorderLayout.CENTER);
|
||
253 | |||
254 | add(new AcceptCancelPanel(this, this), BorderLayout.SOUTH); |
||
255 | |||
256 | chkLabelFeatures.addActionListener(this);
|
||
257 | txtName.addActionListener(this);
|
||
258 | |||
259 | } |
||
260 | |||
261 | private JComponent getStylePreviewer() { |
||
262 | |||
263 | if (styPreviewer == null) { |
||
264 | styPreviewer = new StylePreviewer();
|
||
265 | styPreviewer.setPreferredSize(new java.awt.Dimension(90,90)); |
||
266 | styPreviewer.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); |
||
267 | ((StylePreviewer) styPreviewer).setShowOutline(true);
|
||
268 | } |
||
269 | return styPreviewer;
|
||
270 | |||
271 | } |
||
272 | |||
273 | private JButton getBtnSelectStyle() { |
||
274 | if (btnSelStyle == null) { |
||
275 | btnSelStyle = new JButton(Messages.getText("select")); |
||
276 | btnSelStyle.setActionCommand(SELECT_STYLE); |
||
277 | btnSelStyle.addActionListener(this);
|
||
278 | } |
||
279 | |||
280 | return btnSelStyle;
|
||
281 | } |
||
282 | |||
283 | |||
284 | private JButton getBtnRemoveField() { |
||
285 | if (btnRemoveField == null) { |
||
286 | btnRemoveField = new JButton(Messages.getText("remove")); |
||
287 | btnRemoveField.setActionCommand(DELETE_FIELD); |
||
288 | btnRemoveField.addActionListener(this);
|
||
289 | } |
||
290 | |||
291 | return btnRemoveField;
|
||
292 | } |
||
293 | |||
294 | private JButton getBtnAddField() { |
||
295 | if (btnAddField == null) { |
||
296 | btnAddField = new JButton(Messages.getText("add")); |
||
297 | btnAddField.setActionCommand(ADD_FIELD); |
||
298 | btnAddField.addActionListener(this);
|
||
299 | } |
||
300 | |||
301 | return btnAddField;
|
||
302 | } |
||
303 | |||
304 | private JButton getBtnVerify() { |
||
305 | if(btnVerify == null) { |
||
306 | btnVerify = new JButton(Messages.getText("verify")); |
||
307 | btnVerify.setActionCommand(VERIFY); |
||
308 | btnVerify.addActionListener(this);
|
||
309 | } |
||
310 | return btnVerify;
|
||
311 | } |
||
312 | |||
313 | private JButton getBtnDontUseStyle() { |
||
314 | if (btnDontUseStyle == null) { |
||
315 | btnDontUseStyle = new JButton(Messages.getText("no_style")); |
||
316 | btnDontUseStyle.setActionCommand(CLEAR_STYLE); |
||
317 | btnDontUseStyle.addActionListener(this);
|
||
318 | } |
||
319 | |||
320 | return btnDontUseStyle;
|
||
321 | } |
||
322 | |||
323 | private JTable getTableFields() { |
||
324 | if (tblExpressions == null) { |
||
325 | tblExpressions = new JTable(); |
||
326 | tblExpressions.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||
327 | } |
||
328 | |||
329 | return tblExpressions;
|
||
330 | } |
||
331 | |||
332 | |||
333 | private void setComponentEnabled(Component c, boolean b) { |
||
334 | if (c instanceof JComponent) { |
||
335 | JComponent c1 = (JComponent) c; |
||
336 | for (int i = 0; i < c1.getComponentCount(); i++) { |
||
337 | setComponentEnabled(c1.getComponent(i), b); |
||
338 | } |
||
339 | } |
||
340 | c.setEnabled(b); |
||
341 | } |
||
342 | |||
343 | |||
344 | |||
345 | public void setLabelClass(ILabelClass labelClass) { |
||
346 | if (labelClass == null) |
||
347 | return;
|
||
348 | |||
349 | lc = labelClass; |
||
350 | clonedClass = (ILabelClass) LabelClassUtils.clone(lc); |
||
351 | |||
352 | labelPreview.setLabelClass(clonedClass); |
||
353 | boolean clo_use_sql = LabelClassUtils.isUseSqlQuery(clonedClass);
|
||
354 | if (!clo_use_sql) {
|
||
355 | rdBtnAllFeatures.setSelected(true);
|
||
356 | txtSQL.setText("");
|
||
357 | } else {
|
||
358 | rdBtnFilteredFeatures.setSelected(true);
|
||
359 | txtSQL.setText(clonedClass.getSQLQuery()); |
||
360 | } |
||
361 | |||
362 | chkLabelFeatures.setSelected(clonedClass.isVisible()); |
||
363 | rdBtnFilteredFeatures.setSelected(clo_use_sql); |
||
364 | rdBtnAllFeatures.setSelected(!clo_use_sql); |
||
365 | ((StylePreviewer) styPreviewer).setStyle(clonedClass.getLabelStyle()); |
||
366 | txtName.setText(clonedClass.getName()); |
||
367 | |||
368 | // String expr = lc.getStringLabelExpression();
|
||
369 | |||
370 | /*
|
||
371 | String EOExpr = LabelExpressionParser.tokenFor(LabelExpressionParser.EOEXPR);
|
||
372 | if (expr == null)
|
||
373 | expr = EOExpr;
|
||
374 | expr = expr.trim();
|
||
375 | if (!expr.endsWith(EOExpr)) {
|
||
376 | throw new Error("Invalid expression. Missing EOExpr token ("+EOExpr+").\n"+expr);
|
||
377 | }
|
||
378 | expr = expr.substring(0, expr.length()-1);
|
||
379 | */
|
||
380 | |||
381 | // expr = expr.trim();
|
||
382 | |||
383 | ITextSymbol lcTextSymbol = lc.getTextSymbol(); |
||
384 | ITextSymbol clonedSymbol = null;
|
||
385 | |||
386 | try {
|
||
387 | clonedSymbol = (ITextSymbol) lcTextSymbol.clone(); |
||
388 | } catch (CloneNotSupportedException e) { |
||
389 | logger.error("While clonin.", e);
|
||
390 | } |
||
391 | |||
392 | textStyle.setModel( |
||
393 | clonedSymbol, //lc.getTextSymbol(),
|
||
394 | lc.getUnit(), |
||
395 | lc.getReferenceSystem()); |
||
396 | |||
397 | getTableFields().setRowHeight(22);
|
||
398 | getTableFields().setModel(new FieldTableExpressions(lc.getLabelExpressions()));
|
||
399 | TableColumnModel colMod = getTableFields().getColumnModel();
|
||
400 | colMod.getColumn(0).setPreferredWidth(100); |
||
401 | colMod.getColumn(0).setWidth(100); |
||
402 | colMod.getColumn(1).setResizable(true); |
||
403 | colMod.getColumn(1).setPreferredWidth(513); |
||
404 | |||
405 | FeatureAttributeDescriptor[] atts = null; |
||
406 | |||
407 | try {
|
||
408 | atts = featureStore.getDefaultFeatureType().getAttributeDescriptors(); |
||
409 | } catch (DataException e) {
|
||
410 | logger.error("While getting attributes.", e);
|
||
411 | } |
||
412 | |||
413 | getTableFields().setDefaultEditor( |
||
414 | Object.class,
|
||
415 | new DefaultEditor(atts));
|
||
416 | repaint(); |
||
417 | |||
418 | actionPerformed(new ActionEvent(this, 0, null)); |
||
419 | } |
||
420 | |||
421 | private class DefaultEditor extends AbstractCellEditor implements |
||
422 | TableCellEditor, ActionListener { |
||
423 | |||
424 | JPanel editor;
|
||
425 | LabelExpressionEditorPanel dialog; |
||
426 | private JTextField text; |
||
427 | private JButton button; |
||
428 | protected static final String EDIT = "edit"; |
||
429 | |||
430 | public DefaultEditor(FeatureAttributeDescriptor[] atts) { |
||
431 | editor = new JPanel(); |
||
432 | editor.setLayout(new GridBagLayout()); |
||
433 | GridBagConstraints cons = new GridBagConstraints(); |
||
434 | // cons.anchor = GridBagConstraints.FIRST_LINE_START;
|
||
435 | cons.fill = cons.BOTH; |
||
436 | cons.weightx=1.0;
|
||
437 | cons.weighty =1.0;
|
||
438 | text = new JTextField(); |
||
439 | editor.add(text, cons); |
||
440 | |||
441 | GridBagConstraints cons1 = new GridBagConstraints(); |
||
442 | // cons.anchor = GridBagConstraints.FIRST_LINE_END;
|
||
443 | cons1.fill = cons1.VERTICAL; |
||
444 | cons1.weighty =1.0;
|
||
445 | // cons.gridheight = GridBagConstraints.REMAINDER;
|
||
446 | button = new JButton("..."); |
||
447 | button.setActionCommand(DefaultEditor.EDIT); |
||
448 | button.addActionListener(this);
|
||
449 | editor.add(button,cons1); |
||
450 | |||
451 | editor.updateUI(); |
||
452 | |||
453 | // Set up the dialog that the button brings up.
|
||
454 | dialog = new LabelExpressionEditorPanel(atts);
|
||
455 | } |
||
456 | |||
457 | public void actionPerformed(ActionEvent e) { |
||
458 | if (EDIT.equals(e.getActionCommand())) {
|
||
459 | |||
460 | dialog.setValue(text.getText()); |
||
461 | ApplicationLocator.getManager().getUIManager().addWindow(dialog); |
||
462 | //fireEditingStopped(); // Make the renderer reappear.
|
||
463 | text.setText(dialog.getValue()); |
||
464 | } |
||
465 | } |
||
466 | |||
467 | // Implement the one CellEditor method that AbstractCellEditor doesn't.
|
||
468 | public Object getCellEditorValue() { |
||
469 | return text.getText();
|
||
470 | } |
||
471 | |||
472 | // Implement the one method defined by TableCellEditor.
|
||
473 | public Component getTableCellEditorComponent(JTable table, |
||
474 | Object value, boolean isSelected, int row, int column) { |
||
475 | text.setText((String) value);
|
||
476 | return editor;
|
||
477 | } |
||
478 | } |
||
479 | |||
480 | |||
481 | |||
482 | |||
483 | public WindowInfo getWindowInfo() {
|
||
484 | WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG
|
||
485 | | WindowInfo.RESIZABLE); |
||
486 | wi.setTitle(Messages.getText("label_class_properties"));
|
||
487 | wi.setWidth(getPreferredSize().width + 8);
|
||
488 | wi.setHeight(getPreferredSize().height); |
||
489 | return wi;
|
||
490 | } |
||
491 | |||
492 | public Object getWindowProfile() { |
||
493 | return WindowInfo.DIALOG_PROFILE;
|
||
494 | } |
||
495 | |||
496 | |||
497 | /*
|
||
498 | * Return a hashtable with example values.
|
||
499 | * Only for verification purposes.
|
||
500 | private Hashtable<String, Value> getValuesTable(String[] fNames, int[] fTypes) {
|
||
501 | |||
502 | Hashtable<String, Value> parser_symbol_table = new Hashtable<String, Value>();
|
||
503 | |||
504 | Random rand = new Random();
|
||
505 | byte b = 0;
|
||
506 | short s = (short)rand.nextInt(Short.MAX_VALUE);
|
||
507 | int i = rand.nextInt();
|
||
508 | long l = rand.nextLong();
|
||
509 | boolean bool = rand.nextBoolean();
|
||
510 | float f = rand.nextFloat();
|
||
511 | double d = rand.nextDouble();
|
||
512 | |||
513 | for (int j = 0; j < fNames.length; j++) {
|
||
514 | Value value=null;
|
||
515 | |||
516 | int type = fTypes[j];
|
||
517 | switch (type) {
|
||
518 | case Types.BIGINT:
|
||
519 | value = ValueFactory.createValue(l);
|
||
520 | break;
|
||
521 | case Types.BIT:
|
||
522 | case Types.BOOLEAN:
|
||
523 | value = ValueFactory.createValue(bool);
|
||
524 | break;
|
||
525 | case Types.CHAR:
|
||
526 | case Types.VARCHAR:
|
||
527 | case Types.LONGVARCHAR:
|
||
528 | value = ValueFactory.createValue("");
|
||
529 | break;
|
||
530 | case Types.DATE:
|
||
531 | Date auxDate = new Date();
|
||
532 | if (auxDate != null){
|
||
533 | value = ValueFactory.createValue(auxDate);
|
||
534 | }
|
||
535 | break;
|
||
536 | case Types.DECIMAL:
|
||
537 | case Types.NUMERIC:
|
||
538 | case Types.FLOAT:
|
||
539 | case Types.DOUBLE:
|
||
540 | value = ValueFactory.createValue(d);
|
||
541 | break;
|
||
542 | case Types.INTEGER:
|
||
543 | value = ValueFactory.createValue(i);
|
||
544 | break;
|
||
545 | case Types.REAL:
|
||
546 | value = ValueFactory.createValue(f);
|
||
547 | break;
|
||
548 | case Types.SMALLINT:
|
||
549 | value = ValueFactory.createValue(s);
|
||
550 | break;
|
||
551 | case Types.TINYINT:
|
||
552 | value = ValueFactory.createValue(b);
|
||
553 | break;
|
||
554 | case Types.BINARY:
|
||
555 | case Types.VARBINARY:
|
||
556 | case Types.LONGVARBINARY:
|
||
557 | byte[] auxByteArray = {b}; //new byte[1];
|
||
558 | value = ValueFactory.createValue(auxByteArray);
|
||
559 | break;
|
||
560 | case Types.TIMESTAMP:
|
||
561 | value = ValueFactory.createValue(new Timestamp(l));
|
||
562 | break;
|
||
563 | case Types.TIME:
|
||
564 | value = ValueFactory.createValue(new Time(l));
|
||
565 | break;
|
||
566 | default:
|
||
567 | value = ValueFactory.createValue("");
|
||
568 | break;
|
||
569 | }
|
||
570 | parser_symbol_table.put(fNames[j], value);
|
||
571 | }
|
||
572 | return parser_symbol_table;
|
||
573 | }
|
||
574 | */
|
||
575 | |||
576 | |||
577 | /*
|
||
578 | private boolean verifyExpresion(String expresion, Hashtable<String, Value> symbols){
|
||
579 | LabelExpressionParser parser;
|
||
580 | try {
|
||
581 | parser = new LabelExpressionParser(new StringReader(expresion),symbols);
|
||
582 | parser.LabelExpression();
|
||
583 | Expression expr = ((Expression)parser.getStack().pop());
|
||
584 | expr.evaluate();
|
||
585 | } catch (ExpressionException e2) {
|
||
586 | return false;
|
||
587 | } catch (Exception e3) {
|
||
588 | return false;
|
||
589 | }
|
||
590 | return true;
|
||
591 | }
|
||
592 | */
|
||
593 | |||
594 | private boolean verifyExpressions(){ |
||
595 | |||
596 | String[] expressions = ((FieldTableExpressions) getTableFields().getModel()).getExpression(); |
||
597 | if(expressions.length == 1 && expressions[0].equals("")){ |
||
598 | return true; |
||
599 | } |
||
600 | boolean result = true; |
||
601 | String message = ""; |
||
602 | for (int i = 0; i < expressions.length; i++) { |
||
603 | String expresion = expressions[i];
|
||
604 | |||
605 | if( !LabelClassUtils.validExpression(expresion, featureStore, false) ){ |
||
606 | result = false;
|
||
607 | if(message.compareTo("")!=0){ |
||
608 | message = message + " , " + (i+1); |
||
609 | } else {
|
||
610 | message = " " + Messages.getText("at_fields")+" "+(i+1); |
||
611 | } |
||
612 | } |
||
613 | } |
||
614 | message = message +".";
|
||
615 | if(!result){
|
||
616 | JOptionPane.showMessageDialog(
|
||
617 | ApplicationLocator.getManager().getRootComponent(), |
||
618 | Messages.getText("malformed_or_empty_expression") + message,
|
||
619 | Messages.getText("verify"),
|
||
620 | JOptionPane.ERROR_MESSAGE);
|
||
621 | } else {
|
||
622 | JOptionPane.showMessageDialog(
|
||
623 | ApplicationLocator.getManager().getRootComponent(), |
||
624 | Messages.getText("_Expressions_are_correct"),
|
||
625 | Messages.getText("verify"),
|
||
626 | JOptionPane.INFORMATION_MESSAGE);
|
||
627 | } |
||
628 | return result;
|
||
629 | } |
||
630 | |||
631 | public boolean isAccepted(){ |
||
632 | return accepted;
|
||
633 | } |
||
634 | |||
635 | public void actionPerformed(ActionEvent e) { |
||
636 | setComponentEnabled(sqlPnl, rdBtnFilteredFeatures.isSelected()); |
||
637 | applySettings(); |
||
638 | if ("OK".equals(e.getActionCommand())) { |
||
639 | clonedClass.setUnit(textStyle.getUnit()); |
||
640 | clonedClass.setReferenceSystem(textStyle.getReferenceSystem()); |
||
641 | clonedClass.setTextSymbol(textStyle.getTextSymbol()); |
||
642 | lc = clonedClass; |
||
643 | accepted = true;
|
||
644 | try {
|
||
645 | ApplicationLocator.getManager().getUIManager().closeWindow(this);
|
||
646 | } catch (Exception ex) { |
||
647 | // this only happens when running this as stand-alone app
|
||
648 | // from main method;
|
||
649 | logger.error("While closing window.", ex);
|
||
650 | } |
||
651 | } else if ("CANCEL".equals(e.getActionCommand())) { |
||
652 | accepted = false;
|
||
653 | setLabelClass(lc); |
||
654 | try {
|
||
655 | ApplicationLocator.getManager().getUIManager().closeWindow(this);
|
||
656 | } catch (Exception ex) { |
||
657 | // this only happens when running this as stand-alone app
|
||
658 | // from main method;
|
||
659 | logger.error("While closing window.", ex);
|
||
660 | } |
||
661 | } else if (CLEAR_STYLE.equals(e.getActionCommand())) { |
||
662 | clonedClass.setLabelStyle(null);
|
||
663 | // styPreviewer.setStyle(null);
|
||
664 | ((StylePreviewer) styPreviewer).setStyle(null);
|
||
665 | } else if (TEST_SQL.equals(e.getActionCommand())) { |
||
666 | logger.info("TEST_SQL = " + TEST_SQL);
|
||
667 | } else if (DELETE_FIELD.equals(e.getActionCommand())) { |
||
668 | int[] rowInd = getTableFields().getSelectedRows(); |
||
669 | for (int i = rowInd.length-1; i >= 0 ; i--) { |
||
670 | delField(rowInd[i]); |
||
671 | } |
||
672 | clonedClass.setLabelExpressions(((FieldTableExpressions) getTableFields().getModel()).getExpression()); |
||
673 | setLabelClass(clonedClass); |
||
674 | } else if (VERIFY.equals(e.getActionCommand())) { |
||
675 | verifyExpressions(); |
||
676 | } else if (ADD_FIELD.equals(e.getActionCommand())) { |
||
677 | addField(); |
||
678 | } else if (SELECT_STYLE.equals(e.getActionCommand())) { |
||
679 | |||
680 | IStyle myStyle = ((StylePreviewer)styPreviewer).getStyle(); |
||
681 | |||
682 | FeatureType fty = null;
|
||
683 | |||
684 | try {
|
||
685 | fty = featureStore.getDefaultFeatureType(); |
||
686 | } catch (DataException e1) {
|
||
687 | logger.error("While getting feat type.", e1);
|
||
688 | } |
||
689 | |||
690 | int geotype = fty.getDefaultGeometryAttribute().getGeomType().getType();
|
||
691 | |||
692 | SingleStyleSelectorFilter filter = |
||
693 | new SingleStyleSelectorFilter(ILabelStyle.class);
|
||
694 | StyleSelector stySel = null;
|
||
695 | |||
696 | try {
|
||
697 | stySel = new StyleSelector(myStyle, geotype, filter);
|
||
698 | } catch (IllegalArgumentException iae) { |
||
699 | JOptionPane.showMessageDialog(this, |
||
700 | Messages.getText("_Option_not_available_for_this_geometry_type"),
|
||
701 | getWindowInfo().getTitle(), |
||
702 | JOptionPane.WARNING_MESSAGE);
|
||
703 | return;
|
||
704 | } |
||
705 | |||
706 | ApplicationLocator.getManager().getUIManager().addWindow(stySel); |
||
707 | ILabelStyle sty = (ILabelStyle) stySel.getSelectedObject(); |
||
708 | |||
709 | if (sty != null) { |
||
710 | // gather the style and apply to the class
|
||
711 | clonedClass.setLabelStyle(sty); |
||
712 | clonedClass.setUnit(stySel.getUnit()); |
||
713 | clonedClass.setReferenceSystem(stySel.getReferenceSystem()); |
||
714 | setLabelClass(clonedClass); |
||
715 | } |
||
716 | |||
717 | // styPreviewer.setStyle(sty);
|
||
718 | ((StylePreviewer) styPreviewer).setStyle(sty); |
||
719 | |||
720 | }else if (e.getSource().equals(rdBtnAllFeatures) || e.getSource().equals(rdBtnFilteredFeatures)){ |
||
721 | clonedClass.setUseSqlQuery(rdBtnFilteredFeatures.isSelected()); |
||
722 | } |
||
723 | |||
724 | repaint(); |
||
725 | } |
||
726 | |||
727 | private void applySettings() { |
||
728 | clonedClass.setVisible(chkLabelFeatures.isSelected()); |
||
729 | clonedClass.setName(txtName.getText()); |
||
730 | clonedClass.setSQLQuery(txtSQL.getText()); |
||
731 | JTable tableFields=getTableFields();
|
||
732 | TableCellEditor cellEditor=tableFields.getCellEditor();
|
||
733 | if(cellEditor != null){ |
||
734 | int row = tableFields.getEditingRow();
|
||
735 | int column = tableFields.getEditingColumn();
|
||
736 | cellEditor.stopCellEditing(); |
||
737 | Object value = cellEditor.getCellEditorValue();
|
||
738 | |||
739 | if (value != null) { |
||
740 | ((FieldTableExpressions) tableFields. |
||
741 | getModel()).setValueAt(value, row, column); |
||
742 | } |
||
743 | } |
||
744 | clonedClass.setLabelExpressions( |
||
745 | ((FieldTableExpressions) tableFields. |
||
746 | getModel()).getExpression()); |
||
747 | clonedClass.setTextSymbol(textStyle.getTextSymbol()); |
||
748 | } |
||
749 | |||
750 | private void addField() { |
||
751 | addField("");
|
||
752 | } |
||
753 | |||
754 | private void addField(String fieldExpr) { |
||
755 | FieldTableExpressions m = ((FieldTableExpressions) getTableFields().getModel()); |
||
756 | m.addRow(new Object[] { m.getRowCount()+1, fieldExpr }); |
||
757 | } |
||
758 | |||
759 | private void delField(int fieldIndex) { |
||
760 | try {
|
||
761 | ((FieldTableExpressions) getTableFields().getModel()).removeRow(fieldIndex); |
||
762 | } catch (ArrayIndexOutOfBoundsException ex) {} |
||
763 | } |
||
764 | |||
765 | |||
766 | public ILabelClass getLabelClass() {
|
||
767 | return lc;
|
||
768 | } |
||
769 | |||
770 | |||
771 | |||
772 | private static final Object[] TABLE_HEADERS = new String[] { |
||
773 | |||
774 | Messages.getText("field_number"),
|
||
775 | Messages.getText("label_expression")
|
||
776 | }; |
||
777 | |||
778 | /*
|
||
779 | private static String fieldSeparator =
|
||
780 | LabelExpressionParser.tokenImage[LabelExpressionParser.EOFIELD].replaceAll("\"", "");
|
||
781 | */
|
||
782 | |||
783 | private class FieldTableExpressions extends DefaultTableModel { |
||
784 | private static final long serialVersionUID = 2002427714889477770L; |
||
785 | public FieldTableExpressions(String[] expressions) { |
||
786 | super();
|
||
787 | |||
788 | if(expressions != null && expressions.length > 0){ |
||
789 | Integer[] aux = new Integer[expressions.length]; |
||
790 | for (int i = 0; i < aux.length; i++) { |
||
791 | aux[i] = i+1;
|
||
792 | } |
||
793 | |||
794 | Object[][] values = new Object[aux.length][2]; |
||
795 | for (int i = 0; i < values.length; i++) { |
||
796 | values[i][0] = aux[i];
|
||
797 | values[i][1] = expressions[i];
|
||
798 | } |
||
799 | setDataVector(values, TABLE_HEADERS); |
||
800 | } |
||
801 | else{
|
||
802 | Object[][] values = new Object[1][2]; |
||
803 | values[0][0] = 1; |
||
804 | values[0][1] = ""; |
||
805 | setDataVector(values,TABLE_HEADERS); |
||
806 | } |
||
807 | |||
808 | } |
||
809 | |||
810 | |||
811 | @Override
|
||
812 | public boolean isCellEditable(int row, int column) { |
||
813 | return column == 1; |
||
814 | } |
||
815 | |||
816 | public String[] getExpression() { |
||
817 | |||
818 | String[] expressions = new String[getRowCount()]; |
||
819 | |||
820 | for (int i = 0; i < getRowCount(); i++) { |
||
821 | expressions[i] = ""+(String) getValueAt(i,1); |
||
822 | } |
||
823 | return expressions;
|
||
824 | } |
||
825 | |||
826 | } |
||
827 | |||
828 | // public static void main(String[] args) {
|
||
829 | // JFrame f = new JFrame("Test LabelClassProperties panel");
|
||
830 | //
|
||
831 | // String xmlString =
|
||
832 | // "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
|
||
833 | // "<xml-tag xmlns=\"http://www.gvsig.gva.es\">\n" +
|
||
834 | // " <property key=\"className\" value=\"com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelClass\"/>\n" +
|
||
835 | // " <property key=\"isVisible\" value=\"false\"/>\n" +
|
||
836 | // " <property key=\"name\" value=\"Default\"/>\n" +
|
||
837 | // " <property key=\"labelExpression\" value=\"[TIPO] : lao39805502232 : Substring([MOTO], 2,2);\"/>\n" +
|
||
838 | // " <property key=\"unit\" value=\"-1\"/>\n" +
|
||
839 | // " <property key=\"referenceSystem\" value=\"0\"/>\n" +
|
||
840 | // " <property key=\"sqlQuery\" value=\"TIPO = 'C'\"/>\n" +
|
||
841 | // " <property key=\"priority\" value=\"0\"/>\n" +
|
||
842 | // " <xml-tag>\n" +
|
||
843 | // " <property key=\"className\" value=\"org.gvsig.symbology.fmap.styles.SimpleLabelStyle\"/>\n" +
|
||
844 | // " <property key=\"desc\" value=\"Placa Carrer VLC.style\"/>\n" +
|
||
845 | // " <property key=\"markerPointX\" value=\"0.0\"/>\n" +
|
||
846 | // " <property key=\"markerPointY\" value=\"0.0\"/>\n" +
|
||
847 | // " <property key=\"minXArray\" value=\"0.35 ,0.25\"/>\n" +
|
||
848 | // " <property key=\"minYArray\" value=\"0.15 ,0.5\"/>\n" +
|
||
849 | // " <property key=\"widthArray\" value=\"0.5 ,0.6\"/>\n" +
|
||
850 | // " <property key=\"heightArray\" value=\"0.27 ,0.37\"/>\n" +
|
||
851 | // " <property key=\"id\" value=\"labelStyle\"/>\n" +
|
||
852 | // " <xml-tag>\n" +
|
||
853 | // " <property key=\"className\" value=\"org.gvsig.symbology.fmap.styles.RemoteFileStyle\"/>\n" +
|
||
854 | // " <property key=\"source\" value=\"http://www.boomlapop.com/boomlapop.jpg\"/>\n" +
|
||
855 | // " <property key=\"desc\"/>\n" +
|
||
856 | // " <property key=\"id\" value=\"LabelStyle\"/>\n" +
|
||
857 | // " </xml-tag>\n" +
|
||
858 | // " </xml-tag>\n" +
|
||
859 | // " <xml-tag>\n" +
|
||
860 | // " <property key=\"className\" value=\"com.iver.cit.gvsig.fmap.core.symbols.SimpleTextSymbol\"/>\n" +
|
||
861 | // " <property key=\"desc\"/>\n" +
|
||
862 | // " <property key=\"isShapeVisible\" value=\"true\"/>\n" +
|
||
863 | // " <property key=\"font\" value=\"Arial\"/>\n" +
|
||
864 | // " <property key=\"fontStyle\" value=\"1\"/>\n" +
|
||
865 | // " <property key=\"size\" value=\"12\"/>\n" +
|
||
866 | // " <property key=\"text\" value=\"GeneralLabeling.sample_text\"/>\n" +
|
||
867 | // " <property key=\"textColor\" value=\"255,255,0,255\"/>\n" +
|
||
868 | // " <property key=\"unit\" value=\"-1\"/>\n" +
|
||
869 | // " <property key=\"referenceSystem\" value=\"0\"/>\n" +
|
||
870 | // " <property key=\"id\" value=\"TextSymbol\"/>\n" +
|
||
871 | // " </xml-tag>\n" +
|
||
872 | // "</xml-tag>\n" +
|
||
873 | // "";
|
||
874 | //
|
||
875 | // LabelClass lc = null;
|
||
876 | // try {
|
||
877 | // XMLEntity xml = new XMLEntity((XmlTag) XmlTag.unmarshal(
|
||
878 | // XMLEncodingUtils.getReader(new ByteArrayInputStream(xmlString.getBytes()))));
|
||
879 | // lc = new LabelClass();
|
||
880 | // lc.setXMLEntity(xml);
|
||
881 | // } catch (Exception e) {
|
||
882 | // e.printStackTrace();
|
||
883 | // }
|
||
884 | // String[] names = new String[] { "Field1", "Field2", "Field3" };
|
||
885 | // int[] types = new int[] { Types.VARCHAR, Types.INTEGER, Types.DOUBLE };
|
||
886 | // final LabelClassProperties lcp = new LabelClassProperties(
|
||
887 | // names, types ) {
|
||
888 | // private static final long serialVersionUID = -1843509415649666459L;
|
||
889 | //
|
||
890 | // @Override
|
||
891 | // public void actionPerformed(ActionEvent e) {
|
||
892 | // super.actionPerformed(e);
|
||
893 | // if ("OK".equals(e.getActionCommand())) {
|
||
894 | // Sys tem.out.println(getLabelClass().getXMLEntity());
|
||
895 | // }
|
||
896 | // }
|
||
897 | // };
|
||
898 | // lcp.setLabelClass(lc);
|
||
899 | // f.setContentPane(lcp);
|
||
900 | // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||
901 | // f.pack();
|
||
902 | // f.setVisible(true);
|
||
903 | //
|
||
904 | // }
|
||
905 | |||
906 | } |