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 @ 46863
History | View | Annotate | Download (4.51 KB)
1 |
package org.gvsig.fmap.dal.swing.impl; |
---|---|
2 |
|
3 |
import org.gvsig.fmap.dal.swing.ProjectionPickerController; |
4 |
import java.awt.event.ActionEvent; |
5 |
import java.net.URL; |
6 |
import javax.swing.JButton; |
7 |
import javax.swing.JComponent; |
8 |
import javax.swing.JTextField; |
9 |
import org.apache.commons.lang3.StringUtils; |
10 |
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 |
import org.gvsig.featureform.swing.impl.DefaultJFeaturesForm; |
16 |
import static org.gvsig.fmap.dal.swing.impl.DefaultDALSwingLibrary.LIBRARY_NAME; |
17 |
import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel; |
18 |
import org.gvsig.tools.ToolsLocator; |
19 |
import org.gvsig.tools.i18n.I18nManager; |
20 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
21 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
22 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
23 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
24 |
import org.gvsig.tools.swing.api.pickercontroller.AbstractPickerController; |
25 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
26 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
27 |
|
28 |
/**
|
29 |
*
|
30 |
* @author jjdelcerro
|
31 |
*/
|
32 |
public class ProjectionPickerControllerImpl |
33 |
extends AbstractPickerController<IProjection>
|
34 |
implements ProjectionPickerController
|
35 |
{ |
36 |
|
37 |
private final JTextField txtProjection; |
38 |
private final JButton btnSelectProjection; |
39 |
private IProjection projection;
|
40 |
|
41 |
public ProjectionPickerControllerImpl(
|
42 |
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 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
53 |
|
54 |
this.txtProjection.setEditable(false); |
55 |
this.txtProjection.setText(""); |
56 |
toolsSwingManager.addClearButton(txtProjection); |
57 |
toolsSwingManager.setDefaultPopupMenu(txtProjection); |
58 |
|
59 |
this.btnSelectProjection.addActionListener((ActionEvent e) -> { |
60 |
doSelectProjection(); |
61 |
}); |
62 |
if( StringUtils.equals(this.btnSelectProjection.getText(), "...") && this.existsIcon("picker-crs") ) { |
63 |
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 |
this.fireChangeEvent();
|
84 |
} |
85 |
} |
86 |
|
87 |
@Override
|
88 |
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 |
|
133 |
public static void selfRegister() { |
134 |
|
135 |
boolean n = ToolsSwingUtils.registerIcons(
|
136 |
ProjectionPickerControllerImpl.class, |
137 |
"projectionpicker",
|
138 |
LIBRARY_NAME, |
139 |
new String[]{ "picker", "picker-crs"} |
140 |
); |
141 |
|
142 |
} |
143 |
|
144 |
} |