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 / ProjectionPickerControllerImpl.java @ 47426
History | View | Annotate | Download (4.73 KB)
1 | 44077 | jjdelcerro | package org.gvsig.fmap.dal.swing.impl; |
---|---|---|---|
2 | 43925 | jjdelcerro | |
3 | 45602 | jjdelcerro | import org.gvsig.fmap.dal.swing.ProjectionPickerController; |
4 | 43925 | jjdelcerro | import java.awt.event.ActionEvent; |
5 | 45602 | jjdelcerro | import java.net.URL; |
6 | 43925 | jjdelcerro | import javax.swing.JButton; |
7 | import javax.swing.JComponent; |
||
8 | import javax.swing.JTextField; |
||
9 | 47286 | jjdelcerro | import javax.swing.SwingUtilities; |
10 | 45602 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
11 | 43925 | jjdelcerro | import org.cresques.DataTypes; |
12 | import org.cresques.cts.ICoordTrans; |
||
13 | import org.cresques.cts.IProjection; |
||
14 | import org.gvsig.app.gui.panels.CRSSelectPanelFactory; |
||
15 | import org.gvsig.app.gui.panels.crs.ISelectCrsPanel; |
||
16 | 46863 | jjdelcerro | import org.gvsig.featureform.swing.impl.DefaultJFeaturesForm; |
17 | import static org.gvsig.fmap.dal.swing.impl.DefaultDALSwingLibrary.LIBRARY_NAME; |
||
18 | 45602 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel; |
19 | 43925 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
20 | import org.gvsig.tools.i18n.I18nManager; |
||
21 | 46238 | jjdelcerro | import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
22 | 43925 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
23 | 46488 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingManager; |
24 | 46863 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingUtils; |
25 | 43925 | jjdelcerro | import org.gvsig.tools.swing.api.pickercontroller.AbstractPickerController; |
26 | import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
||
27 | 45602 | jjdelcerro | import org.gvsig.tools.swing.icontheme.IconTheme; |
28 | 43925 | jjdelcerro | |
29 | /**
|
||
30 | *
|
||
31 | * @author jjdelcerro
|
||
32 | */
|
||
33 | 45602 | jjdelcerro | public class ProjectionPickerControllerImpl |
34 | 43925 | jjdelcerro | extends AbstractPickerController<IProjection>
|
35 | 45602 | jjdelcerro | implements ProjectionPickerController
|
36 | 43925 | jjdelcerro | { |
37 | |||
38 | private final JTextField txtProjection; |
||
39 | private final JButton btnSelectProjection; |
||
40 | private IProjection projection;
|
||
41 | |||
42 | 45602 | jjdelcerro | public ProjectionPickerControllerImpl(
|
43 | 43925 | jjdelcerro | JTextField txtProjection,
|
44 | JButton btnSelectProjection
|
||
45 | ) { |
||
46 | this.txtProjection = txtProjection;
|
||
47 | this.btnSelectProjection = btnSelectProjection;
|
||
48 | this.projection = null; |
||
49 | this.initComponents();
|
||
50 | } |
||
51 | |||
52 | private void initComponents() { |
||
53 | 46488 | jjdelcerro | ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
54 | |||
55 | 43925 | jjdelcerro | this.txtProjection.setEditable(false); |
56 | this.txtProjection.setText(""); |
||
57 | 47339 | jjdelcerro | toolsSwingManager.addClearButton(txtProjection, (e) -> {set(null);});
|
58 | 46488 | jjdelcerro | toolsSwingManager.setDefaultPopupMenu(txtProjection); |
59 | |||
60 | 45602 | jjdelcerro | this.btnSelectProjection.addActionListener((ActionEvent e) -> { |
61 | doSelectProjection(); |
||
62 | 43925 | jjdelcerro | }); |
63 | 45602 | jjdelcerro | if( StringUtils.equals(this.btnSelectProjection.getText(), "...") && this.existsIcon("picker-crs") ) { |
64 | 43925 | jjdelcerro | this.btnSelectProjection.setText(""); |
65 | this.btnSelectProjection.setIcon(this.getIcon("picker-crs")); |
||
66 | } |
||
67 | } |
||
68 | |||
69 | private void doSelectProjection() { |
||
70 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
71 | |||
72 | ISelectCrsPanel crsSelectPanel = CRSSelectPanelFactory.getUIFactory().getSelectCrsPanel( |
||
73 | this.projection,
|
||
74 | true
|
||
75 | ); |
||
76 | WindowManager winManager = ToolsSwingLocator.getWindowManager(); |
||
77 | winManager.showWindow( |
||
78 | (JComponent) crsSelectPanel,
|
||
79 | i18n.getTranslation("selecciona_sistema_de_referencia"),
|
||
80 | WindowManager.MODE.DIALOG |
||
81 | ); |
||
82 | if (crsSelectPanel.isOkPressed()) {
|
||
83 | this.set(crsSelectPanel.getProjection());
|
||
84 | 45634 | fdiaz | this.fireChangeEvent();
|
85 | 43925 | jjdelcerro | } |
86 | } |
||
87 | |||
88 | 45602 | jjdelcerro | @Override
|
89 | 43925 | jjdelcerro | public ICoordTrans getCoordinateTransformation() {
|
90 | return null; |
||
91 | } |
||
92 | |||
93 | @Override
|
||
94 | public IProjection get() {
|
||
95 | return this.projection; |
||
96 | } |
||
97 | |||
98 | @Override
|
||
99 | public void set(IProjection projection) { |
||
100 | 47286 | jjdelcerro | if( !SwingUtilities.isEventDispatchThread() ) { |
101 | SwingUtilities.invokeLater(()-> {set(projection);});
|
||
102 | return;
|
||
103 | } |
||
104 | 43925 | jjdelcerro | this.projection = projection;
|
105 | if( this.projection == null ) { |
||
106 | this.txtProjection.setText(""); |
||
107 | } else {
|
||
108 | this.txtProjection.setText(this.projection.getAbrev()); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | @Override
|
||
113 | public void coerceAndSet(Object o) { |
||
114 | this.set((IProjection) this.coerce(DataTypes.CRS, o, null)); |
||
115 | } |
||
116 | |||
117 | @Override
|
||
118 | public void setEnabled(boolean bln) { |
||
119 | this.btnSelectProjection.setEnabled(bln);
|
||
120 | } |
||
121 | |||
122 | @Override
|
||
123 | public boolean isEnabled() { |
||
124 | return this.btnSelectProjection.isEnabled(); |
||
125 | } |
||
126 | |||
127 | @Override
|
||
128 | public void setEditable(boolean editable) { |
||
129 | super.setEditable(editable);
|
||
130 | this.btnSelectProjection.setEnabled(editable);
|
||
131 | } |
||
132 | |||
133 | @Override
|
||
134 | public boolean isEmpty() { |
||
135 | return this.projection == null; |
||
136 | } |
||
137 | 45602 | jjdelcerro | |
138 | public static void selfRegister() { |
||
139 | 46863 | jjdelcerro | |
140 | boolean n = ToolsSwingUtils.registerIcons(
|
||
141 | ProjectionPickerControllerImpl.class, |
||
142 | "projectionpicker",
|
||
143 | LIBRARY_NAME, |
||
144 | 47426 | jjdelcerro | new String[]{ "picker", "picker-crs", "picker-crs"} |
145 | 46863 | jjdelcerro | ); |
146 | |||
147 | 45602 | jjdelcerro | } |
148 | 43925 | jjdelcerro | |
149 | } |