23 |
23 |
package org.gvsig.app.gui.preferencespage;
|
24 |
24 |
|
25 |
25 |
import java.awt.Color;
|
26 |
|
import java.awt.event.ActionEvent;
|
27 |
|
import java.awt.event.ActionListener;
|
28 |
26 |
import java.awt.event.ItemEvent;
|
29 |
27 |
import java.awt.event.ItemListener;
|
30 |
|
|
31 |
28 |
import javax.swing.DefaultComboBoxModel;
|
32 |
29 |
import javax.swing.ImageIcon;
|
33 |
|
import javax.swing.JButton;
|
34 |
|
import javax.swing.JColorChooser;
|
35 |
30 |
import javax.swing.JPanel;
|
36 |
|
import javax.swing.JSlider;
|
37 |
|
import javax.swing.JTextField;
|
38 |
31 |
import javax.swing.SpinnerNumberModel;
|
39 |
|
import javax.swing.SwingUtilities;
|
40 |
32 |
import javax.swing.UIManager;
|
41 |
33 |
import javax.swing.event.ChangeEvent;
|
42 |
34 |
import javax.swing.event.ChangeListener;
|
43 |
|
import org.apache.commons.lang3.BooleanUtils;
|
44 |
|
|
45 |
35 |
import org.cresques.cts.IProjection;
|
46 |
36 |
import org.gvsig.andami.IconThemeHelper;
|
47 |
37 |
import org.gvsig.andami.PluginServices;
|
... | ... | |
49 |
39 |
import org.gvsig.andami.preferences.IPreference;
|
50 |
40 |
import org.gvsig.andami.preferences.StoreException;
|
51 |
41 |
import org.gvsig.app.ApplicationLocator;
|
52 |
|
import org.gvsig.app.gui.panels.CRSSelectPanel;
|
53 |
|
import org.gvsig.app.gui.panels.crs.ISelectCrsPanel;
|
54 |
42 |
import org.gvsig.app.project.ProjectPreferences;
|
55 |
|
import org.gvsig.fmap.crs.CRSFactory;
|
|
43 |
import org.gvsig.fmap.dal.swing.DALSwingLocator;
|
|
44 |
import org.gvsig.fmap.dal.swing.ProjectionPickerController;
|
56 |
45 |
import org.gvsig.fmap.mapcontext.MapContext;
|
57 |
46 |
import org.gvsig.fmap.mapcontext.MapContextLocator;
|
58 |
|
import org.gvsig.i18n.Messages;
|
59 |
|
|
60 |
47 |
import org.gvsig.tools.ToolsLocator;
|
61 |
|
import org.gvsig.tools.dynobject.DynObject;
|
62 |
48 |
import org.gvsig.tools.i18n.I18nManager;
|
63 |
49 |
import org.gvsig.tools.swing.api.ToolsSwingLocator;
|
64 |
|
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
|
|
50 |
import org.gvsig.tools.swing.api.ToolsSwingManager;
|
|
51 |
import org.gvsig.tools.swing.api.pickercontroller.ColorPickerController;
|
65 |
52 |
import org.gvsig.utils.XMLEntity;
|
66 |
53 |
|
67 |
54 |
/**
|
... | ... | |
95 |
82 |
private static int FACTORY_DEFAULT_DISTANCE_UNITS;
|
96 |
83 |
private static int FACTORY_DEFAULT_DISTANCE_AREA;
|
97 |
84 |
|
98 |
|
private final ImageIcon icon;
|
|
85 |
private ImageIcon icon;
|
99 |
86 |
|
100 |
|
private ProjectionController defaultProjection = null;
|
101 |
|
private ColorChooserController defaultViewBackColor = null;
|
102 |
|
private ColorChooserController defaultSelectionColor = null;
|
|
87 |
private ProjectionPickerController defaultProjection;
|
103 |
88 |
|
|
89 |
private ColorPickerController defaultViewBackColor = null;
|
|
90 |
private ColorPickerController defaultSelectionColor = null;
|
|
91 |
|
104 |
92 |
private boolean hasChanges = false;
|
105 |
93 |
|
106 |
|
private static class ProjectionController implements ActionListener {
|
107 |
|
|
108 |
|
private static final long serialVersionUID = -1442364274073324390L;
|
109 |
|
|
110 |
|
private final JTextField txtLabel;
|
111 |
|
private final JButton btnShowDialog;
|
112 |
|
private IProjection proj = null;
|
113 |
|
private ChangeListener changeListener;
|
114 |
|
|
115 |
|
public ProjectionController(JTextField txtLabel, JButton btnShowDialog) {
|
116 |
|
this.txtLabel = txtLabel;
|
117 |
|
this.btnShowDialog = btnShowDialog;
|
118 |
|
|
119 |
|
this.btnShowDialog.addActionListener(this);
|
120 |
|
this.set(null);
|
121 |
|
}
|
122 |
|
|
123 |
|
public void addChangeListener(ChangeListener changeListener) {
|
124 |
|
this.changeListener = changeListener;
|
125 |
|
}
|
126 |
|
|
127 |
|
public void fireChanged() {
|
128 |
|
if (this.changeListener != null) {
|
129 |
|
this.changeListener.stateChanged(null);
|
130 |
|
}
|
131 |
|
}
|
132 |
|
|
133 |
|
public void set(IProjection proj) {
|
134 |
|
this.proj = proj;
|
135 |
|
if (this.proj == null) {
|
136 |
|
this.txtLabel.setText("");
|
137 |
|
} else {
|
138 |
|
this.txtLabel.setText(proj.getAbrev());
|
139 |
|
}
|
140 |
|
}
|
141 |
|
|
142 |
|
public IProjection get() {
|
143 |
|
return this.proj;
|
144 |
|
}
|
145 |
|
|
146 |
|
@Override
|
147 |
|
public void actionPerformed(ActionEvent e) {
|
148 |
|
ISelectCrsPanel panel = CRSSelectPanel.getUIFactory().getSelectCrsPanel(
|
149 |
|
CRSFactory.getCRS(this.txtLabel.getText()), false);
|
150 |
|
ToolsSwingLocator.getWindowManager().showWindow(
|
151 |
|
panel.asJComponent(),
|
152 |
|
ToolsLocator.getI18nManager().getTranslation("selecciona_sistema_de_referencia"),
|
153 |
|
WindowManager.MODE.DIALOG
|
154 |
|
);
|
155 |
|
if (panel.isOkPressed()) {
|
156 |
|
this.set(panel.getProjection());
|
157 |
|
this.fireChanged();
|
158 |
|
}
|
159 |
|
}
|
160 |
|
|
161 |
|
}
|
162 |
|
|
163 |
|
private static class ColorChooserController implements ActionListener, ChangeListener {
|
164 |
|
|
165 |
|
private final JTextField txtLabel;
|
166 |
|
private final JButton btnShowDialog;
|
167 |
|
private final JSlider sldAlpha;
|
168 |
|
private Color color;
|
169 |
|
private boolean allowNull;
|
170 |
|
private ChangeListener changeListener;
|
171 |
|
|
172 |
|
public ColorChooserController(JTextField txtLabel, JButton btnShowDialog, JSlider sldAlpha, boolean allowNull) {
|
173 |
|
this.txtLabel = txtLabel;
|
174 |
|
this.btnShowDialog = btnShowDialog;
|
175 |
|
this.sldAlpha = sldAlpha;
|
176 |
|
this.btnShowDialog.addActionListener(this);
|
177 |
|
if (this.sldAlpha != null) {
|
178 |
|
this.sldAlpha.addChangeListener(this);
|
179 |
|
}
|
180 |
|
this.allowNull = allowNull;
|
181 |
|
if (!this.allowNull) {
|
182 |
|
this.color = Color.BLACK;
|
183 |
|
}
|
184 |
|
}
|
185 |
|
|
186 |
|
public ColorChooserController(JTextField txtLabel, JButton btnShowDialog) {
|
187 |
|
this(txtLabel, btnShowDialog, null, false);
|
188 |
|
}
|
189 |
|
|
190 |
|
public ColorChooserController(JTextField txtLabel, JButton btnShowDialog, JSlider sldAlpha) {
|
191 |
|
this(txtLabel, btnShowDialog, sldAlpha, false);
|
192 |
|
}
|
193 |
|
|
194 |
|
@Override
|
195 |
|
public void stateChanged(ChangeEvent e) {
|
196 |
|
if (this.color == null) {
|
197 |
|
set(Color.BLACK);
|
198 |
|
}
|
199 |
|
if (this.sldAlpha == null) {
|
200 |
|
this.color = new Color(
|
201 |
|
color.getRed(),
|
202 |
|
color.getGreen(),
|
203 |
|
color.getBlue()
|
204 |
|
);
|
205 |
|
} else {
|
206 |
|
this.color = new Color(
|
207 |
|
color.getRed(),
|
208 |
|
color.getGreen(),
|
209 |
|
color.getBlue(),
|
210 |
|
this.sldAlpha.getValue()
|
211 |
|
);
|
212 |
|
}
|
213 |
|
this.txtLabel.setBackground(this.color);
|
214 |
|
}
|
215 |
|
|
216 |
|
public void addChangeListener(ChangeListener changeListener) {
|
217 |
|
this.changeListener = changeListener;
|
218 |
|
}
|
219 |
|
|
220 |
|
public void fireChanged() {
|
221 |
|
if (this.changeListener != null) {
|
222 |
|
this.changeListener.stateChanged(null);
|
223 |
|
}
|
224 |
|
}
|
225 |
|
|
226 |
|
@Override
|
227 |
|
public void actionPerformed(ActionEvent e) {
|
228 |
|
Color c = JColorChooser.showDialog(
|
229 |
|
SwingUtilities.windowForComponent(this.btnShowDialog),
|
230 |
|
Messages.getText("choose_color"),
|
231 |
|
this.get()
|
232 |
|
);
|
233 |
|
if (c == null) {
|
234 |
|
return;
|
235 |
|
}
|
236 |
|
set(c);
|
237 |
|
}
|
238 |
|
|
239 |
|
private void set(Color color) {
|
240 |
|
if (color == null) {
|
241 |
|
if (allowNull) {
|
242 |
|
this.color = null;
|
243 |
|
return;
|
244 |
|
}
|
245 |
|
color = Color.BLACK;
|
246 |
|
}
|
247 |
|
this.color = color;
|
248 |
|
this.txtLabel.setBackground(this.color);
|
249 |
|
if (this.sldAlpha != null) {
|
250 |
|
this.sldAlpha.setValue(this.color.getAlpha());
|
251 |
|
}
|
252 |
|
}
|
253 |
|
|
254 |
|
public Color get() {
|
255 |
|
return this.color;
|
256 |
|
}
|
257 |
|
|
258 |
|
}
|
259 |
|
|
260 |
94 |
/**
|
261 |
95 |
* Creates a new panel containing View preferences settings.
|
262 |
96 |
*
|
... | ... | |
266 |
100 |
|
267 |
101 |
initUnitsNames();
|
268 |
102 |
|
269 |
|
icon = IconThemeHelper.getImageIcon("document-view-icon");
|
|
103 |
|
270 |
104 |
|
|
105 |
|
|
106 |
this.initComponents();
|
|
107 |
this.translateAll();
|
|
108 |
this.initializeValues();
|
|
109 |
}
|
|
110 |
|
|
111 |
private void initComponents(){
|
271 |
112 |
this.chkKeepScaleOnResizing.setEnabled(false);
|
272 |
113 |
|
273 |
|
this.defaultProjection = new ProjectionController(
|
|
114 |
this.defaultProjection = DALSwingLocator.getDataSwingManager().createProjectionPickerController(
|
274 |
115 |
this.txtDefaultProjection,
|
275 |
116 |
this.btnChangeProjection
|
276 |
117 |
);
|
277 |
118 |
this.defaultProjection.addChangeListener(this);
|
278 |
119 |
|
279 |
|
this.defaultSelectionColor = new ColorChooserController(
|
|
120 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
|
|
121 |
this.defaultSelectionColor = toolsSwingManager.createColorPickerController(
|
280 |
122 |
this.txtDefaultSelectionColor,
|
281 |
123 |
this.btnDefaultSelectionColor,
|
282 |
124 |
this.sldDefaultSelectionColor
|
283 |
125 |
);
|
284 |
126 |
this.defaultSelectionColor.addChangeListener(this);
|
285 |
127 |
|
286 |
|
this.defaultViewBackColor = new ColorChooserController(
|
|
128 |
this.defaultViewBackColor = toolsSwingManager.createColorPickerController(
|
287 |
129 |
this.txtDefaultViewBackColor,
|
288 |
130 |
this.btnDefaultViewBackColor
|
289 |
131 |
);
|
|
132 |
|
290 |
133 |
this.defaultViewBackColor.addChangeListener(this);
|
291 |
134 |
|
292 |
135 |
this.chkInvisibleNewLayers.addChangeListener(this);
|
... | ... | |
296 |
139 |
this.jCmbDistanceUnits.addItemListener(this);
|
297 |
140 |
this.jCmbMapUnits.addItemListener(this);
|
298 |
141 |
|
299 |
|
this.translateAll();
|
300 |
|
this.initializeValues();
|
301 |
142 |
}
|
302 |
143 |
|
303 |
144 |
private void translateAll() {
|
... | ... | |
326 |
167 |
|
327 |
168 |
@Override
|
328 |
169 |
public void initializeValues() {
|
329 |
|
Double zif;
|
330 |
|
Double zof;
|
331 |
|
|
332 |
170 |
ProjectPreferences projectPreferences = ApplicationLocator.getProjectManager().getProjectPreferences();
|
333 |
|
PluginServices plugin = PluginsLocator.getManager().getPlugin(this);
|
334 |
|
DynObject props = plugin.getPluginProperties();
|
335 |
|
XMLEntity xml = plugin.getPersistentXML();
|
336 |
171 |
|
337 |
172 |
this.defaultProjection.set(projectPreferences.getDefaultProjection());
|
338 |
173 |
|
... | ... | |
453 |
288 |
0.25 //step
|
454 |
289 |
)
|
455 |
290 |
);
|
456 |
|
// txtZoomInFactor.setText(String.valueOf(DEFAULT_ZOOM_IN_FACTOR));
|
457 |
|
// txtZoomOutFactor.setText(String.valueOf(DEFAULT_ZOOM_OUT_FACTOR));
|
458 |
291 |
this.chkInvisibleNewLayers.setSelected(false);
|
459 |
292 |
this.chkKeepScaleOnResizing.setSelected(false);
|
460 |
293 |
this.chkHideLegendOfNonVisibleLayers.setSelected(true);
|
... | ... | |
474 |
307 |
|
475 |
308 |
@Override
|
476 |
309 |
public ImageIcon getIcon() {
|
|
310 |
if(icon == null){
|
|
311 |
icon = IconThemeHelper.getImageIcon("document-view-icon");
|
|
312 |
}
|
477 |
313 |
return icon;
|
478 |
314 |
}
|
479 |
315 |
|