svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / fmap / mapcontrol / swing / dynformfield / CoordinateReferenceSystem / JDynFormFieldCoordinateReferenceSystem.java @ 42470
History | View | Annotate | Download (3.54 KB)
1 |
package org.gvsig.fmap.mapcontrol.swing.dynformfield.CoordinateReferenceSystem; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.event.ActionEvent; |
5 |
import java.awt.event.ActionListener; |
6 |
import java.awt.event.FocusEvent; |
7 |
import java.awt.event.FocusListener; |
8 |
|
9 |
import javax.swing.JButton; |
10 |
import javax.swing.JComponent; |
11 |
import javax.swing.JPanel; |
12 |
import javax.swing.JTextField; |
13 |
|
14 |
import org.cresques.Messages; |
15 |
import org.cresques.cts.IProjection; |
16 |
import org.gvsig.app.gui.panels.CRSSelectPanelFactory; |
17 |
import org.gvsig.app.gui.panels.crs.ISelectCrsPanel; |
18 |
import org.gvsig.tools.dataTypes.CoercionException; |
19 |
import org.gvsig.tools.dynform.JDynFormField; |
20 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
21 |
import org.gvsig.tools.dynform.spi.dynformfield.JCustomTextField; |
22 |
import org.gvsig.tools.dynobject.DynObject; |
23 |
import org.gvsig.tools.service.spi.ServiceManager; |
24 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
25 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE; |
26 |
|
27 |
public class JDynFormFieldCoordinateReferenceSystem extends AbstractJDynFormField implements JDynFormField, FocusListener { |
28 |
|
29 |
protected IProjection assignedValue = null; |
30 |
protected IProjection currentValue = null; |
31 |
protected JTextField jtext = null; |
32 |
protected JButton jbutton = null; |
33 |
|
34 |
public JDynFormFieldCoordinateReferenceSystem(DynObject parameters,
|
35 |
ServiceManager serviceManager) { |
36 |
super(parameters, serviceManager);
|
37 |
this.assignedValue = (IProjection) this.getParameterValue(); |
38 |
} |
39 |
|
40 |
public Object getAssignedValue() { |
41 |
return this.assignedValue; |
42 |
} |
43 |
|
44 |
public void initComponent() { |
45 |
this.contents = new JPanel(); |
46 |
this.contents.setLayout(new BorderLayout()); |
47 |
|
48 |
this.jtext = new JCustomTextField(getLabel()); |
49 |
this.jtext.addFocusListener(this); |
50 |
this.jtext.setEditable(false); |
51 |
this.jbutton = new JButton("..."); |
52 |
this.jbutton.addActionListener(new ActionListener() { |
53 |
public void actionPerformed(ActionEvent e) { |
54 |
onClickBrowse(); |
55 |
} |
56 |
}); |
57 |
|
58 |
this.contents.add(jtext, BorderLayout.CENTER); |
59 |
this.contents.add(jbutton, BorderLayout.LINE_END); |
60 |
this.contents.setVisible(true); |
61 |
this.setValue(this.assignedValue); |
62 |
} |
63 |
|
64 |
public void onClickBrowse() { |
65 |
fireFieldEnterEvent(); |
66 |
this.problemIndicator().restore();
|
67 |
|
68 |
ISelectCrsPanel csSelect = CRSSelectPanelFactory.getUIFactory().getSelectCrsPanel(this.currentValue, true); |
69 |
ToolsSwingLocator.getWindowManager().showWindow((JComponent) csSelect, Messages.getText("selecciona_sistema_de_referencia"), MODE.DIALOG); |
70 |
if (csSelect.isOkPressed()) {
|
71 |
this.currentValue = csSelect.getProjection();
|
72 |
this.jtext.setText(this.currentValue.getAbrev()); |
73 |
} |
74 |
} |
75 |
|
76 |
public boolean hasValidValue() { |
77 |
return true; |
78 |
} |
79 |
|
80 |
public void focusGained(FocusEvent arg0) { |
81 |
fireFieldEnterEvent(); |
82 |
this.problemIndicator().restore();
|
83 |
} |
84 |
|
85 |
public void focusLost(FocusEvent arg0) { |
86 |
fireFieldExitEvent(); |
87 |
} |
88 |
|
89 |
public void setValue(Object value) { |
90 |
IProjection x = null;
|
91 |
try {
|
92 |
x = (IProjection) this.getDefinition().getDataType().coerce(value);
|
93 |
} catch (CoercionException e) {
|
94 |
throw new IllegalFieldValue(this, e.getMessage()); |
95 |
} |
96 |
this.currentValue = x;
|
97 |
if (x != null) { |
98 |
this.jtext.setText(x.getAbrev());
|
99 |
} |
100 |
this.assignedValue = x;
|
101 |
} |
102 |
|
103 |
public Object getValue() { |
104 |
return this.currentValue; |
105 |
} |
106 |
|
107 |
} |