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