svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / ProjectionPickerController.java @ 44154
History | View | Annotate | Download (3.54 KB)
1 | 44077 | jjdelcerro | package org.gvsig.fmap.dal.swing.impl; |
---|---|---|---|
2 | 43925 | jjdelcerro | |
3 | import java.awt.event.ActionEvent; |
||
4 | import java.awt.event.ActionListener; |
||
5 | import javax.swing.JButton; |
||
6 | import javax.swing.JComponent; |
||
7 | import javax.swing.JTextField; |
||
8 | import org.cresques.DataTypes; |
||
9 | import org.cresques.cts.ICoordTrans; |
||
10 | import org.cresques.cts.IProjection; |
||
11 | import org.gvsig.app.gui.panels.CRSSelectPanelFactory; |
||
12 | import org.gvsig.app.gui.panels.crs.ISelectCrsPanel; |
||
13 | import org.gvsig.tools.ToolsLocator; |
||
14 | import org.gvsig.tools.i18n.I18nManager; |
||
15 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
16 | import org.gvsig.tools.swing.api.pickercontroller.AbstractPickerController; |
||
17 | import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
||
18 | import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
||
19 | |||
20 | /**
|
||
21 | *
|
||
22 | * @author jjdelcerro
|
||
23 | */
|
||
24 | public class ProjectionPickerController |
||
25 | extends AbstractPickerController<IProjection>
|
||
26 | implements PickerController<IProjection>
|
||
27 | { |
||
28 | |||
29 | private final JTextField txtProjection; |
||
30 | private final JButton btnSelectProjection; |
||
31 | private IProjection projection;
|
||
32 | |||
33 | public ProjectionPickerController(
|
||
34 | JTextField txtProjection,
|
||
35 | JButton btnSelectProjection
|
||
36 | ) { |
||
37 | this.txtProjection = txtProjection;
|
||
38 | this.btnSelectProjection = btnSelectProjection;
|
||
39 | this.projection = null; |
||
40 | this.initComponents();
|
||
41 | } |
||
42 | |||
43 | private void initComponents() { |
||
44 | this.txtProjection.setEditable(false); |
||
45 | this.txtProjection.setText(""); |
||
46 | this.btnSelectProjection.addActionListener(new ActionListener() { |
||
47 | @Override
|
||
48 | public void actionPerformed(ActionEvent e) { |
||
49 | doSelectProjection(); |
||
50 | } |
||
51 | }); |
||
52 | if( this.existsIcon("picker-crs") ) { |
||
53 | this.btnSelectProjection.setText(""); |
||
54 | this.btnSelectProjection.setIcon(this.getIcon("picker-crs")); |
||
55 | } |
||
56 | } |
||
57 | |||
58 | private void doSelectProjection() { |
||
59 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
60 | |||
61 | ISelectCrsPanel crsSelectPanel = CRSSelectPanelFactory.getUIFactory().getSelectCrsPanel( |
||
62 | this.projection,
|
||
63 | true
|
||
64 | ); |
||
65 | WindowManager winManager = ToolsSwingLocator.getWindowManager(); |
||
66 | winManager.showWindow( |
||
67 | (JComponent) crsSelectPanel,
|
||
68 | i18n.getTranslation("selecciona_sistema_de_referencia"),
|
||
69 | WindowManager.MODE.DIALOG |
||
70 | ); |
||
71 | if (crsSelectPanel.isOkPressed()) {
|
||
72 | this.set(crsSelectPanel.getProjection());
|
||
73 | } |
||
74 | } |
||
75 | |||
76 | public ICoordTrans getCoordinateTransformation() {
|
||
77 | return null; |
||
78 | } |
||
79 | |||
80 | @Override
|
||
81 | public IProjection get() {
|
||
82 | return this.projection; |
||
83 | } |
||
84 | |||
85 | @Override
|
||
86 | public void set(IProjection projection) { |
||
87 | this.projection = projection;
|
||
88 | if( this.projection == null ) { |
||
89 | this.txtProjection.setText(""); |
||
90 | } else {
|
||
91 | this.txtProjection.setText(this.projection.getAbrev()); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | @Override
|
||
96 | public void coerceAndSet(Object o) { |
||
97 | this.set((IProjection) this.coerce(DataTypes.CRS, o, null)); |
||
98 | } |
||
99 | |||
100 | @Override
|
||
101 | public void setEnabled(boolean bln) { |
||
102 | this.btnSelectProjection.setEnabled(bln);
|
||
103 | } |
||
104 | |||
105 | @Override
|
||
106 | public boolean isEnabled() { |
||
107 | return this.btnSelectProjection.isEnabled(); |
||
108 | } |
||
109 | |||
110 | @Override
|
||
111 | public void setEditable(boolean editable) { |
||
112 | super.setEditable(editable);
|
||
113 | this.btnSelectProjection.setEnabled(editable);
|
||
114 | } |
||
115 | |||
116 | @Override
|
||
117 | public boolean isEmpty() { |
||
118 | return this.projection == null; |
||
119 | } |
||
120 | |||
121 | } |