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 @ 45602
History | View | Annotate | Download (4.14 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 |
} |
74 |
} |
75 |
|
76 |
@Override
|
77 |
public ICoordTrans getCoordinateTransformation() {
|
78 |
return null; |
79 |
} |
80 |
|
81 |
@Override
|
82 |
public IProjection get() {
|
83 |
return this.projection; |
84 |
} |
85 |
|
86 |
@Override
|
87 |
public void set(IProjection projection) { |
88 |
this.projection = projection;
|
89 |
if( this.projection == null ) { |
90 |
this.txtProjection.setText(""); |
91 |
} else {
|
92 |
this.txtProjection.setText(this.projection.getAbrev()); |
93 |
} |
94 |
} |
95 |
|
96 |
@Override
|
97 |
public void coerceAndSet(Object o) { |
98 |
this.set((IProjection) this.coerce(DataTypes.CRS, o, null)); |
99 |
} |
100 |
|
101 |
@Override
|
102 |
public void setEnabled(boolean bln) { |
103 |
this.btnSelectProjection.setEnabled(bln);
|
104 |
} |
105 |
|
106 |
@Override
|
107 |
public boolean isEnabled() { |
108 |
return this.btnSelectProjection.isEnabled(); |
109 |
} |
110 |
|
111 |
@Override
|
112 |
public void setEditable(boolean editable) { |
113 |
super.setEditable(editable);
|
114 |
this.btnSelectProjection.setEnabled(editable);
|
115 |
} |
116 |
|
117 |
@Override
|
118 |
public boolean isEmpty() { |
119 |
return this.projection == null; |
120 |
} |
121 |
|
122 |
public static void selfRegister() { |
123 |
String[][] iconNames = new String[][]{ |
124 |
new String[]{"Common", "picker-crs"} |
125 |
|
126 |
}; |
127 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
128 |
for (String[] icon : iconNames) { |
129 |
URL url = ProjectionPickerControllerImpl.class.getResource("projectionpicker/"+icon[1] + ".png"); |
130 |
theme.registerDefault("DALSwing", icon[0], icon[1], null, url); |
131 |
} |
132 |
} |
133 |
|
134 |
} |