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 @ 45634
History | View | Annotate | Download (4.17 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.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel; |
16 |
import org.gvsig.tools.ToolsLocator; |
17 |
import org.gvsig.tools.i18n.I18nManager; |
18 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
19 |
import org.gvsig.tools.swing.api.pickercontroller.AbstractPickerController; |
20 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
21 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
22 |
|
23 |
/**
|
24 |
*
|
25 |
* @author jjdelcerro
|
26 |
*/
|
27 |
public class ProjectionPickerControllerImpl |
28 |
extends AbstractPickerController<IProjection>
|
29 |
implements ProjectionPickerController
|
30 |
{ |
31 |
|
32 |
private final JTextField txtProjection; |
33 |
private final JButton btnSelectProjection; |
34 |
private IProjection projection;
|
35 |
|
36 |
public ProjectionPickerControllerImpl(
|
37 |
JTextField txtProjection,
|
38 |
JButton btnSelectProjection
|
39 |
) { |
40 |
this.txtProjection = txtProjection;
|
41 |
this.btnSelectProjection = btnSelectProjection;
|
42 |
this.projection = null; |
43 |
this.initComponents();
|
44 |
} |
45 |
|
46 |
private void initComponents() { |
47 |
this.txtProjection.setEditable(false); |
48 |
this.txtProjection.setText(""); |
49 |
this.btnSelectProjection.addActionListener((ActionEvent e) -> { |
50 |
doSelectProjection(); |
51 |
}); |
52 |
if( StringUtils.equals(this.btnSelectProjection.getText(), "...") && 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 |
this.fireChangeEvent();
|
74 |
} |
75 |
} |
76 |
|
77 |
@Override
|
78 |
public ICoordTrans getCoordinateTransformation() {
|
79 |
return null; |
80 |
} |
81 |
|
82 |
@Override
|
83 |
public IProjection get() {
|
84 |
return this.projection; |
85 |
} |
86 |
|
87 |
@Override
|
88 |
public void set(IProjection projection) { |
89 |
this.projection = projection;
|
90 |
if( this.projection == null ) { |
91 |
this.txtProjection.setText(""); |
92 |
} else {
|
93 |
this.txtProjection.setText(this.projection.getAbrev()); |
94 |
} |
95 |
} |
96 |
|
97 |
@Override
|
98 |
public void coerceAndSet(Object o) { |
99 |
this.set((IProjection) this.coerce(DataTypes.CRS, o, null)); |
100 |
} |
101 |
|
102 |
@Override
|
103 |
public void setEnabled(boolean bln) { |
104 |
this.btnSelectProjection.setEnabled(bln);
|
105 |
} |
106 |
|
107 |
@Override
|
108 |
public boolean isEnabled() { |
109 |
return this.btnSelectProjection.isEnabled(); |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public void setEditable(boolean editable) { |
114 |
super.setEditable(editable);
|
115 |
this.btnSelectProjection.setEnabled(editable);
|
116 |
} |
117 |
|
118 |
@Override
|
119 |
public boolean isEmpty() { |
120 |
return this.projection == null; |
121 |
} |
122 |
|
123 |
public static void selfRegister() { |
124 |
String[][] iconNames = new String[][]{ |
125 |
new String[]{"Common", "picker-crs"} |
126 |
|
127 |
}; |
128 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
129 |
for (String[] icon : iconNames) { |
130 |
URL url = ProjectionPickerControllerImpl.class.getResource("projectionpicker/"+icon[1] + ".png"); |
131 |
theme.registerDefault("DALSwing", icon[0], icon[1], null, url); |
132 |
} |
133 |
} |
134 |
|
135 |
} |