svn-gvsig-desktop / trunk / extensions / extSymbology / src / org / gvsig / symbology / gui / layerproperties / LabelClassProperties.java @ 24117
History | View | Annotate | Download (20.5 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.GridLayout; |
48 |
import java.awt.event.ActionEvent; |
49 |
import java.awt.event.ActionListener; |
50 |
import java.awt.event.FocusEvent; |
51 |
import java.awt.event.FocusListener; |
52 |
import java.awt.event.KeyEvent; |
53 |
import java.awt.event.KeyListener; |
54 |
import java.io.ByteArrayInputStream; |
55 |
import java.sql.Types; |
56 |
|
57 |
import javax.swing.BorderFactory; |
58 |
import javax.swing.ButtonGroup; |
59 |
import javax.swing.JCheckBox; |
60 |
import javax.swing.JComponent; |
61 |
import javax.swing.JFrame; |
62 |
import javax.swing.JLabel; |
63 |
import javax.swing.JPanel; |
64 |
import javax.swing.JRadioButton; |
65 |
import javax.swing.JScrollPane; |
66 |
import javax.swing.JTable; |
67 |
import javax.swing.JTextField; |
68 |
import javax.swing.table.DefaultTableModel; |
69 |
import javax.swing.table.TableColumnModel; |
70 |
|
71 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
72 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
73 |
import org.gvsig.gui.beans.swing.JBlank; |
74 |
import org.gvsig.gui.beans.swing.JButton; |
75 |
import org.gvsig.symbology.fmap.labeling.parse.LabelExpressionParser; |
76 |
import org.gvsig.symbology.fmap.styles.SimpleLabelStyle; |
77 |
|
78 |
import com.iver.andami.PluginServices; |
79 |
import com.iver.andami.ui.mdiManager.IWindow; |
80 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
81 |
import com.iver.cit.gvsig.fmap.core.FShape; |
82 |
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle; |
83 |
import com.iver.cit.gvsig.fmap.core.styles.IStyle; |
84 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelClass; |
85 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelingFactory; |
86 |
import com.iver.cit.gvsig.gui.styling.AbstractStyleSelectorFilter; |
87 |
import com.iver.cit.gvsig.gui.styling.StylePreviewer; |
88 |
import com.iver.cit.gvsig.gui.styling.StyleSelector; |
89 |
import com.iver.utiles.XMLEntity; |
90 |
import com.iver.utiles.xml.XMLEncodingUtils; |
91 |
import com.iver.utiles.xmlEntity.generate.XmlTag; |
92 |
|
93 |
/**
|
94 |
*
|
95 |
* LabelClassProperties.java
|
96 |
*
|
97 |
*
|
98 |
* @author jaume dominguez faus - jaume.dominguez@iver.es May 27, 2008
|
99 |
*
|
100 |
*/
|
101 |
public class LabelClassProperties extends JPanel implements IWindow, |
102 |
ActionListener {
|
103 |
private static final String TEST_SQL = "TEST_SQL"; |
104 |
private static final String DELETE_FIELD = "DELETE_FIELD"; |
105 |
private static final long serialVersionUID = 6528513396536811057L; |
106 |
private static final String ADD_FIELD = "ADD_FIELD"; |
107 |
private static final String SELECT_STYLE = "SELECT_STYLE"; |
108 |
private static final String CLEAR_STYLE = "CLEAR_STYLE"; |
109 |
private JTextField txtName; |
110 |
private LabelClass lc, clonedClass;
|
111 |
private JTable tblExpressions; |
112 |
private JButton btnRemoveField; |
113 |
private JButton btnAddField; |
114 |
private JComponent styPreviewer; |
115 |
private JButton btnSelStyle; |
116 |
private JRadioButton rdBtnFilteredFeatures; |
117 |
private JRadioButton rdBtnAllFeatures; |
118 |
private JTextField txtSQL; |
119 |
private JCheckBox chkLabelFeatures; |
120 |
private LabelTextStylePanel textStyle;
|
121 |
private JPanel sqlPnl; |
122 |
private LabelClassPreview labelPreview;
|
123 |
private String[] fieldNames; |
124 |
private int[] fieldTypes; |
125 |
private JButton btnDontUseStyle; |
126 |
|
127 |
|
128 |
/**
|
129 |
* <p>
|
130 |
* Creates a new instance of the dialog that configures all the properties
|
131 |
* of a LabelClass.
|
132 |
* </p>
|
133 |
* @param asWindow
|
134 |
*/
|
135 |
public LabelClassProperties(String[] fieldNames, int[] fieldTypes) { |
136 |
if (fieldNames==null) { |
137 |
throw new IllegalArgumentException("fieldNames "+ |
138 |
PluginServices.getText(this, "cannot_be_null")); |
139 |
} |
140 |
|
141 |
if (fieldTypes==null) { |
142 |
throw new IllegalArgumentException("fieldTypes "+ |
143 |
PluginServices.getText(this, "cannot_be_null")); |
144 |
|
145 |
} |
146 |
|
147 |
if (fieldNames.length != fieldTypes.length) {
|
148 |
throw new IllegalArgumentException( |
149 |
PluginServices.getText(this, "names_and_types_count_are_disctint")); |
150 |
} |
151 |
this.fieldNames = fieldNames;
|
152 |
this.fieldTypes = fieldTypes;
|
153 |
initialize(); |
154 |
} |
155 |
|
156 |
private void initialize() { |
157 |
setPreferredSize(new Dimension(800, 450)); |
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(PluginServices.getText(this, "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>"+PluginServices |
179 |
.getText(this, "text_fields")+"</b></html>")); |
180 |
centerPanel.add(labelExpressionsPanel, BorderLayout.CENTER);
|
181 |
GridBagLayoutPanel aux = new GridBagLayoutPanel();// (new |
182 |
// FlowLayout(FlowLayout.CENTER));
|
183 |
aux.setPreferredSize(new Dimension(120, 100)); |
184 |
aux.addComponent(getBtnAddField()); |
185 |
aux.addComponent(getBtnRemoveField()); |
186 |
centerPanel.add(aux, BorderLayout.EAST);
|
187 |
|
188 |
|
189 |
aux = new GridBagLayoutPanel();
|
190 |
// aux.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(
|
191 |
// this, "features")));
|
192 |
rdBtnAllFeatures = new JRadioButton(PluginServices.getText(this, |
193 |
"all_features"));
|
194 |
rdBtnFilteredFeatures = new JRadioButton(PluginServices.getText(this, |
195 |
"filtered_features"));
|
196 |
|
197 |
rdBtnAllFeatures.addActionListener(this);
|
198 |
rdBtnFilteredFeatures.addActionListener(this);
|
199 |
|
200 |
ButtonGroup g = new ButtonGroup(); |
201 |
g.add(rdBtnAllFeatures); |
202 |
g.add(rdBtnFilteredFeatures); |
203 |
aux.addComponent(chkLabelFeatures = new JCheckBox(PluginServices |
204 |
.getText(this, "label_features_in_this_class"))); |
205 |
aux.addComponent("", rdBtnAllFeatures);
|
206 |
aux.addComponent("", rdBtnFilteredFeatures);
|
207 |
sqlPnl = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
208 |
sqlPnl.add(new JLabel(" SQL: select * from ")); |
209 |
sqlPnl.add(new JLabel("%" + PluginServices.getText(this, "layer_name") |
210 |
+ "%"));
|
211 |
sqlPnl.add(new JLabel(" where ")); |
212 |
sqlPnl.add(txtSQL = new JTextField(40)); |
213 |
sqlPnl.add(new JLabel(";")); |
214 |
aux.addComponent("", sqlPnl);
|
215 |
|
216 |
|
217 |
JPanel auxPanel = new JPanel(new BorderLayout(1,1)); |
218 |
|
219 |
JPanel aux2 = new JPanel(); |
220 |
auxPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(
|
221 |
this, "background_style"))); |
222 |
|
223 |
aux2.add(getStylePreviewer()); |
224 |
|
225 |
|
226 |
|
227 |
GridBagLayoutPanel aux3 = new GridBagLayoutPanel();
|
228 |
aux3.setPreferredSize(new Dimension(120, 100)); |
229 |
aux3.addComponent(getBtnSelectStyle()); |
230 |
aux3.addComponent(getBtnDontUseStyle()); |
231 |
|
232 |
auxPanel.add(aux2,BorderLayout.CENTER);
|
233 |
auxPanel.add(aux3,BorderLayout.EAST);
|
234 |
|
235 |
JPanel aux4 = new JPanel(new GridLayout(1,2)); |
236 |
aux4.add(auxPanel); |
237 |
aux2 = new JPanel(new BorderLayout()); |
238 |
aux2.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(
|
239 |
this, "preview"))); |
240 |
aux2.add(labelPreview = new LabelClassPreview(), BorderLayout.CENTER); |
241 |
aux4.add(aux2); |
242 |
|
243 |
GridBagLayoutPanel aux5 = new GridBagLayoutPanel();
|
244 |
aux5.addComponent("", aux);
|
245 |
aux5.addComponent(new JBlank(3, 5)); |
246 |
aux5.addComponent("", aux4);
|
247 |
centerPanel.add(aux5, BorderLayout.SOUTH);
|
248 |
add(centerPanel, BorderLayout.CENTER);
|
249 |
|
250 |
add(new AcceptCancelPanel(this, this), BorderLayout.SOUTH); |
251 |
|
252 |
chkLabelFeatures.addActionListener(this);
|
253 |
txtName.addActionListener(this);
|
254 |
|
255 |
} |
256 |
|
257 |
private JComponent getStylePreviewer() { |
258 |
|
259 |
if (styPreviewer == null) { |
260 |
styPreviewer = new StylePreviewer();
|
261 |
styPreviewer.setPreferredSize(new java.awt.Dimension(90,90)); |
262 |
styPreviewer.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); |
263 |
((StylePreviewer) styPreviewer).setShowOutline(true);
|
264 |
} |
265 |
return styPreviewer;
|
266 |
|
267 |
} |
268 |
|
269 |
private JButton getBtnSelectStyle() { |
270 |
if (btnSelStyle == null) { |
271 |
btnSelStyle = new JButton(PluginServices.getText(this, "select")); |
272 |
btnSelStyle.setActionCommand(SELECT_STYLE); |
273 |
btnSelStyle.addActionListener(this);
|
274 |
} |
275 |
|
276 |
return btnSelStyle;
|
277 |
} |
278 |
|
279 |
|
280 |
private JButton getBtnRemoveField() { |
281 |
if (btnRemoveField == null) { |
282 |
btnRemoveField = new JButton(PluginServices.getText(this, "remove")); |
283 |
btnRemoveField.setActionCommand(DELETE_FIELD); |
284 |
btnRemoveField.addActionListener(this);
|
285 |
} |
286 |
|
287 |
return btnRemoveField;
|
288 |
} |
289 |
|
290 |
private JButton getBtnAddField() { |
291 |
if (btnAddField == null) { |
292 |
btnAddField = new JButton(PluginServices.getText(this, "add")); |
293 |
btnAddField.setActionCommand(ADD_FIELD); |
294 |
btnAddField.addActionListener(this);
|
295 |
} |
296 |
|
297 |
return btnAddField;
|
298 |
} |
299 |
|
300 |
private JButton getBtnDontUseStyle() { |
301 |
if (btnDontUseStyle == null) { |
302 |
btnDontUseStyle = new JButton(PluginServices.getText(this, "no_style")); |
303 |
btnDontUseStyle.setActionCommand(CLEAR_STYLE); |
304 |
btnDontUseStyle.addActionListener(this);
|
305 |
} |
306 |
|
307 |
return btnDontUseStyle;
|
308 |
} |
309 |
|
310 |
private JTable getTableFields() { |
311 |
if (tblExpressions == null) { |
312 |
tblExpressions = new JTable(); |
313 |
tblExpressions.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
314 |
tblExpressions.addFocusListener(new FocusListener(){ |
315 |
|
316 |
public void focusGained(FocusEvent e) {} |
317 |
|
318 |
public void focusLost(FocusEvent e) { |
319 |
if(tblExpressions.getCellEditor() != null){ |
320 |
tblExpressions.getCellEditor().stopCellEditing(); |
321 |
tblExpressions.repaint(); |
322 |
} |
323 |
clonedClass.setLabelExpressions(((FieldTableExpressions) getTableFields().getModel()).getExpression()); |
324 |
} |
325 |
|
326 |
}); |
327 |
} |
328 |
|
329 |
return tblExpressions;
|
330 |
} |
331 |
|
332 |
private void setComponentEnabled(Component c, boolean b) { |
333 |
if (c instanceof JComponent) { |
334 |
JComponent c1 = (JComponent) c; |
335 |
for (int i = 0; i < c1.getComponentCount(); i++) { |
336 |
setComponentEnabled(c1.getComponent(i), b); |
337 |
} |
338 |
} |
339 |
c.setEnabled(b); |
340 |
} |
341 |
|
342 |
|
343 |
|
344 |
public void setLabelClass(LabelClass labelClass) { |
345 |
if (labelClass == null) |
346 |
return;
|
347 |
|
348 |
lc = labelClass; |
349 |
clonedClass = LabelingFactory |
350 |
.createLabelClassFromXML(lc.getXMLEntity()); |
351 |
|
352 |
labelPreview.setLabelClass(clonedClass); |
353 |
if (!clonedClass.isUseSqlQuery()) {
|
354 |
rdBtnAllFeatures.setSelected(true);
|
355 |
txtSQL.setText("");
|
356 |
} else {
|
357 |
rdBtnFilteredFeatures.setSelected(true);
|
358 |
txtSQL.setText(clonedClass.getSQLQuery()); |
359 |
} |
360 |
|
361 |
chkLabelFeatures.setSelected(clonedClass.isVisible()); |
362 |
rdBtnFilteredFeatures.setSelected(clonedClass.isUseSqlQuery()); |
363 |
rdBtnAllFeatures.setSelected(!clonedClass.isUseSqlQuery()); |
364 |
((StylePreviewer) styPreviewer).setStyle(clonedClass.getLabelStyle()); |
365 |
txtName.setText(clonedClass.getName()); |
366 |
String expr = lc.getStringLabelExpression();
|
367 |
|
368 |
|
369 |
String EOExpr = LabelExpressionParser.tokenFor(LabelExpressionParser.EOEXPR);
|
370 |
|
371 |
if (expr == null) |
372 |
expr = EOExpr; |
373 |
|
374 |
|
375 |
expr = expr.trim(); |
376 |
if (!expr.endsWith(EOExpr)) {
|
377 |
throw new Error("Invalid expression. Missing EOExpr token ("+EOExpr+").\n"+expr); |
378 |
} |
379 |
expr = expr.substring(0, expr.length()-1); |
380 |
|
381 |
expr = expr.trim(); |
382 |
|
383 |
textStyle.setModel( |
384 |
lc.getTextSymbol(), |
385 |
lc.getUnit(), |
386 |
lc.getReferenceSystem()); |
387 |
|
388 |
|
389 |
|
390 |
|
391 |
getTableFields().setModel(new FieldTableExpressions(lc.getLabelExpressions()));
|
392 |
TableColumnModel colMod = getTableFields().getColumnModel();
|
393 |
colMod.getColumn(0).setPreferredWidth(100); |
394 |
colMod.getColumn(0).setWidth(100); |
395 |
colMod.getColumn(1).setPreferredWidth(517); |
396 |
repaint(); |
397 |
|
398 |
actionPerformed(new ActionEvent(this, 0, null)); |
399 |
|
400 |
} |
401 |
|
402 |
|
403 |
public WindowInfo getWindowInfo() {
|
404 |
WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG
|
405 |
| WindowInfo.RESIZABLE); |
406 |
wi.setTitle(PluginServices.getText(this, "label_class_properties")); |
407 |
wi.setWidth(getPreferredSize().width + 8);
|
408 |
wi.setHeight(getPreferredSize().height); |
409 |
return wi;
|
410 |
} |
411 |
|
412 |
|
413 |
public void actionPerformed(ActionEvent e) { |
414 |
setComponentEnabled(sqlPnl, rdBtnFilteredFeatures.isSelected()); |
415 |
applySettings(); |
416 |
if ("OK".equals(e.getActionCommand())) { |
417 |
clonedClass.setUnit(textStyle.getUnit()); |
418 |
clonedClass.setReferenceSystem(textStyle.getReferenceSystem()); |
419 |
lc = clonedClass; |
420 |
try {
|
421 |
PluginServices.getMDIManager().closeWindow(this);
|
422 |
} catch (Exception ex) { |
423 |
// this only happens when running this as stand-alone app
|
424 |
// from main method;
|
425 |
ex.printStackTrace(); |
426 |
} |
427 |
} else if ("CANCEL".equals(e.getActionCommand())) { |
428 |
try {
|
429 |
PluginServices.getMDIManager().closeWindow(this);
|
430 |
} catch (Exception ex) { |
431 |
// this only happens when running this as stand-alone app
|
432 |
// from main method;
|
433 |
ex.printStackTrace(); |
434 |
} |
435 |
} else if (CLEAR_STYLE.equals(e.getActionCommand())) { |
436 |
clonedClass.setLabelStyle(null);
|
437 |
// styPreviewer.setStyle(null);
|
438 |
((StylePreviewer) styPreviewer).setStyle(null);
|
439 |
} else if (TEST_SQL.equals(e.getActionCommand())) { |
440 |
System.out.println(TEST_SQL);
|
441 |
} else if (DELETE_FIELD.equals(e.getActionCommand())) { |
442 |
int[] rowInd = getTableFields().getSelectedRows(); |
443 |
for (int i = rowInd.length-1; i >= 0 ; i--) { |
444 |
delField(rowInd[i]); |
445 |
} |
446 |
clonedClass.setLabelExpressions(((FieldTableExpressions) getTableFields().getModel()).getExpression()); |
447 |
setLabelClass(clonedClass); |
448 |
} else if (ADD_FIELD.equals(e.getActionCommand())) { |
449 |
addField(); |
450 |
} else if (SELECT_STYLE.equals(e.getActionCommand())) { |
451 |
|
452 |
IStyle myStyle = ((StylePreviewer)styPreviewer).getStyle(); |
453 |
StyleSelector stySel = new StyleSelector(
|
454 |
myStyle, |
455 |
FShape.TEXT, new AbstractStyleSelectorFilter(new SimpleLabelStyle()) { |
456 |
}); |
457 |
|
458 |
|
459 |
PluginServices.getMDIManager().addWindow(stySel); |
460 |
ILabelStyle sty = (ILabelStyle) stySel.getSelectedObject(); |
461 |
|
462 |
if (sty != null) { |
463 |
// gather the style and apply to the class
|
464 |
clonedClass.setLabelStyle(sty); |
465 |
clonedClass.setUnit(stySel.getUnit()); |
466 |
clonedClass.setReferenceSystem(stySel.getReferenceSystem()); |
467 |
setLabelClass(clonedClass); |
468 |
} |
469 |
|
470 |
// styPreviewer.setStyle(sty);
|
471 |
((StylePreviewer) styPreviewer).setStyle(sty); |
472 |
|
473 |
}else if (e.getSource().equals(rdBtnAllFeatures) || e.getSource().equals(rdBtnFilteredFeatures)){ |
474 |
clonedClass.setUseSqlQuery(rdBtnFilteredFeatures.isSelected()); |
475 |
} |
476 |
|
477 |
repaint(); |
478 |
} |
479 |
|
480 |
private void applySettings() { |
481 |
clonedClass.setVisible(chkLabelFeatures.isSelected()); |
482 |
clonedClass.setName(txtName.getText()); |
483 |
clonedClass.setSQLQuery(txtSQL.getText()); |
484 |
clonedClass.setLabelExpressions( |
485 |
((FieldTableExpressions) getTableFields(). |
486 |
getModel()).getExpression()); |
487 |
clonedClass.setTextSymbol(textStyle.getTextSymbol()); |
488 |
} |
489 |
|
490 |
private void addField() { |
491 |
addField("");
|
492 |
} |
493 |
|
494 |
private void addField(String fieldExpr) { |
495 |
FieldTableExpressions m = ((FieldTableExpressions) getTableFields().getModel()); |
496 |
m.addRow(new Object[] { m.getRowCount()+1, fieldExpr }); |
497 |
} |
498 |
|
499 |
private void delField(int fieldIndex) { |
500 |
try {
|
501 |
((FieldTableExpressions) getTableFields().getModel()).removeRow(fieldIndex); |
502 |
} catch (ArrayIndexOutOfBoundsException ex) {} |
503 |
} |
504 |
|
505 |
|
506 |
public LabelClass getLabelClass() {
|
507 |
return lc;
|
508 |
} |
509 |
|
510 |
|
511 |
|
512 |
private static final Object[] TABLE_HEADERS = new String[] { |
513 |
PluginServices.getText(FieldTableExpressions.class, "field_number"),
|
514 |
PluginServices.getText(FieldTableExpressions.class, "label_expression"),
|
515 |
|
516 |
}; |
517 |
private static String fieldSeparator = LabelExpressionParser.tokenImage[LabelExpressionParser.EOFIELD].replaceAll("\"", ""); |
518 |
private class FieldTableExpressions extends DefaultTableModel { |
519 |
private static final long serialVersionUID = 2002427714889477770L; |
520 |
public FieldTableExpressions(String[] expressions) { |
521 |
super();
|
522 |
|
523 |
if(expressions != null && expressions.length > 0){ |
524 |
Integer[] aux = new Integer[expressions.length]; |
525 |
for (int i = 0; i < aux.length; i++) { |
526 |
aux[i] = i+1;
|
527 |
} |
528 |
|
529 |
Object[][] values = new Object[aux.length][2]; |
530 |
for (int i = 0; i < values.length; i++) { |
531 |
values[i][0] = aux[i];
|
532 |
values[i][1] = expressions[i];
|
533 |
} |
534 |
setDataVector(values, TABLE_HEADERS); |
535 |
} |
536 |
else{
|
537 |
Object[][] values = new Object[1][2]; |
538 |
values[0][0] = 1; |
539 |
values[0][1] = ""; |
540 |
setDataVector(values,TABLE_HEADERS); |
541 |
} |
542 |
|
543 |
} |
544 |
|
545 |
|
546 |
@Override
|
547 |
public boolean isCellEditable(int row, int column) { |
548 |
// System.out.println("FieldTableExpressions.isCellEditable() "+(column == 1));
|
549 |
return column == 1; |
550 |
} |
551 |
|
552 |
public String[] getExpression() { |
553 |
|
554 |
String[] expressions = new String[getRowCount()]; |
555 |
|
556 |
for (int i = 0; i < getRowCount(); i++) { |
557 |
expressions[i] = ""+(String) getValueAt(i,1); |
558 |
} |
559 |
return expressions;
|
560 |
} |
561 |
|
562 |
} |
563 |
|
564 |
public static void main(String[] args) { |
565 |
JFrame f = new JFrame("Test LabelClassProperties panel"); |
566 |
|
567 |
String xmlString =
|
568 |
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
|
569 |
"<xml-tag xmlns=\"http://www.gvsig.gva.es\">\n" +
|
570 |
" <property key=\"className\" value=\"com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelClass\"/>\n" +
|
571 |
" <property key=\"isVisible\" value=\"false\"/>\n" +
|
572 |
" <property key=\"name\" value=\"Default\"/>\n" +
|
573 |
" <property key=\"labelExpression\" value=\"[TIPO] : lao39805502232 : Substring([MOTO], 2,2);\"/>\n" +
|
574 |
" <property key=\"unit\" value=\"-1\"/>\n" +
|
575 |
" <property key=\"referenceSystem\" value=\"0\"/>\n" +
|
576 |
" <property key=\"sqlQuery\" value=\"TIPO = 'C'\"/>\n" +
|
577 |
" <property key=\"priority\" value=\"0\"/>\n" +
|
578 |
" <xml-tag>\n" +
|
579 |
" <property key=\"className\" value=\"org.gvsig.symbology.fmap.styles.SimpleLabelStyle\"/>\n" +
|
580 |
" <property key=\"desc\" value=\"Placa Carrer VLC.style\"/>\n" +
|
581 |
" <property key=\"markerPointX\" value=\"0.0\"/>\n" +
|
582 |
" <property key=\"markerPointY\" value=\"0.0\"/>\n" +
|
583 |
" <property key=\"minXArray\" value=\"0.35 ,0.25\"/>\n" +
|
584 |
" <property key=\"minYArray\" value=\"0.15 ,0.5\"/>\n" +
|
585 |
" <property key=\"widthArray\" value=\"0.5 ,0.6\"/>\n" +
|
586 |
" <property key=\"heightArray\" value=\"0.27 ,0.37\"/>\n" +
|
587 |
" <property key=\"id\" value=\"labelStyle\"/>\n" +
|
588 |
" <xml-tag>\n" +
|
589 |
" <property key=\"className\" value=\"org.gvsig.symbology.fmap.styles.RemoteFileStyle\"/>\n" +
|
590 |
" <property key=\"source\" value=\"http://www.boomlapop.com/boomlapop.jpg\"/>\n" +
|
591 |
" <property key=\"desc\"/>\n" +
|
592 |
" <property key=\"id\" value=\"LabelStyle\"/>\n" +
|
593 |
" </xml-tag>\n" +
|
594 |
" </xml-tag>\n" +
|
595 |
" <xml-tag>\n" +
|
596 |
" <property key=\"className\" value=\"com.iver.cit.gvsig.fmap.core.symbols.SimpleTextSymbol\"/>\n" +
|
597 |
" <property key=\"desc\"/>\n" +
|
598 |
" <property key=\"isShapeVisible\" value=\"true\"/>\n" +
|
599 |
" <property key=\"font\" value=\"Arial\"/>\n" +
|
600 |
" <property key=\"fontStyle\" value=\"1\"/>\n" +
|
601 |
" <property key=\"size\" value=\"12\"/>\n" +
|
602 |
" <property key=\"text\" value=\"GeneralLabeling.sample_text\"/>\n" +
|
603 |
" <property key=\"textColor\" value=\"255,255,0,255\"/>\n" +
|
604 |
" <property key=\"unit\" value=\"-1\"/>\n" +
|
605 |
" <property key=\"referenceSystem\" value=\"0\"/>\n" +
|
606 |
" <property key=\"id\" value=\"TextSymbol\"/>\n" +
|
607 |
" </xml-tag>\n" +
|
608 |
"</xml-tag>\n" +
|
609 |
"";
|
610 |
|
611 |
LabelClass lc = null;
|
612 |
try {
|
613 |
XMLEntity xml = new XMLEntity((XmlTag) XmlTag.unmarshal(
|
614 |
XMLEncodingUtils.getReader(new ByteArrayInputStream(xmlString.getBytes())))); |
615 |
lc = new LabelClass();
|
616 |
lc.setXMLEntity(xml); |
617 |
} catch (Exception e) { |
618 |
e.printStackTrace(); |
619 |
} |
620 |
String[] names = new String[] { "Field1", "Field2", "Field3" }; |
621 |
int[] types = new int[] { Types.VARCHAR, Types.INTEGER, Types.DOUBLE }; |
622 |
final LabelClassProperties lcp = new LabelClassProperties( |
623 |
names, types ) { |
624 |
private static final long serialVersionUID = -1843509415649666459L; |
625 |
|
626 |
@Override
|
627 |
public void actionPerformed(ActionEvent e) { |
628 |
super.actionPerformed(e);
|
629 |
if ("OK".equals(e.getActionCommand())) { |
630 |
System.out.println(getLabelClass().getXMLEntity());
|
631 |
} |
632 |
} |
633 |
}; |
634 |
lcp.setLabelClass(lc); |
635 |
f.setContentPane(lcp); |
636 |
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
637 |
f.pack(); |
638 |
f.setVisible(true);
|
639 |
|
640 |
} |
641 |
|
642 |
} |