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