svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / gui / preferencespage / SymbologyPage.java @ 47469
History | View | Annotate | Download (10.8 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | 40435 | jjdelcerro | package org.gvsig.app.gui.preferencespage; |
25 | |||
26 | import java.awt.Color; |
||
27 | import java.awt.Dimension; |
||
28 | import java.awt.FlowLayout; |
||
29 | import java.awt.Font; |
||
30 | import java.awt.GridBagLayout; |
||
31 | import java.awt.event.ActionEvent; |
||
32 | import java.awt.event.ActionListener; |
||
33 | import java.io.File; |
||
34 | |||
35 | import javax.swing.ImageIcon; |
||
36 | import javax.swing.JButton; |
||
37 | import javax.swing.JCheckBox; |
||
38 | import javax.swing.JLabel; |
||
39 | import javax.swing.JPanel; |
||
40 | import javax.swing.JSlider; |
||
41 | import javax.swing.JTextField; |
||
42 | import javax.swing.border.TitledBorder; |
||
43 | import javax.swing.event.ChangeEvent; |
||
44 | import javax.swing.event.ChangeListener; |
||
45 | import javax.swing.filechooser.FileFilter; |
||
46 | |||
47 | 40723 | jldominguez | import org.gvsig.andami.IconThemeHelper; |
48 | 40974 | jldominguez | import org.gvsig.andami.PluginServices; |
49 | 40435 | jjdelcerro | import org.gvsig.andami.preferences.AbstractPreferencePage; |
50 | import org.gvsig.andami.preferences.StoreException; |
||
51 | import org.gvsig.app.gui.panels.ColorChooserPanel; |
||
52 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
53 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences; |
||
54 | import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
||
55 | import org.gvsig.gui.beans.swing.JBlank; |
||
56 | import org.gvsig.gui.beans.swing.JComboBoxFontSizes; |
||
57 | import org.gvsig.gui.beans.swing.JComboBoxFonts; |
||
58 | import org.gvsig.gui.beans.swing.JFileChooser; |
||
59 | 40723 | jldominguez | import org.gvsig.i18n.Messages; |
60 | 40435 | jjdelcerro | |
61 | |||
62 | |||
63 | /**
|
||
64 | * This class extends AbstractPreferencesPage. This component is a preferences page for
|
||
65 | * symbology and allows select default fore color, fill color, font and size text and
|
||
66 | * the path where the images that compound symbols are located.
|
||
67 | *
|
||
68 | */
|
||
69 | public class SymbologyPage extends AbstractPreferencePage { |
||
70 | |||
71 | private static final long serialVersionUID = 1L; |
||
72 | |||
73 | private SymbolPreferences preferences = null; |
||
74 | |||
75 | private ColorChooserPanel defaultColor = null; |
||
76 | private ColorChooserPanel defaultFillColor = null; |
||
77 | private JSlider jsDefaultSelectionAlpha = null; |
||
78 | private JSlider jsFillSelelctionAlpha = null; |
||
79 | protected String id; |
||
80 | private boolean panelStarted = false; |
||
81 | private JButton btnSelectProjectsFolder=null; |
||
82 | private ActionListener btnFileChooserAction=null; |
||
83 | private JTextField txtProjectsFolder=null; |
||
84 | private JComboBoxFonts fonts= null; |
||
85 | private JComboBoxFontSizes sizes= null; |
||
86 | private ImageIcon icon=null; |
||
87 | private JCheckBox aleatoryFillColor; |
||
88 | |||
89 | public SymbologyPage(){
|
||
90 | super();
|
||
91 | id = this.getClass().getName();
|
||
92 | } |
||
93 | |||
94 | public SymbolPreferences getPreferences() {
|
||
95 | if(preferences == null) |
||
96 | preferences = MapContextLocator.getSymbolManager().getSymbolPreferences(); |
||
97 | return preferences;
|
||
98 | } |
||
99 | |||
100 | @Override
|
||
101 | public void setChangesApplied() { |
||
102 | setChanged(false);
|
||
103 | |||
104 | } |
||
105 | |||
106 | public String getID() { |
||
107 | return id;
|
||
108 | } |
||
109 | |||
110 | public ImageIcon getIcon() { |
||
111 | if (icon == null){ |
||
112 | 40723 | jldominguez | icon = IconThemeHelper.getImageIcon("symbology-preferences");
|
113 | 40435 | jjdelcerro | } |
114 | return icon;
|
||
115 | } |
||
116 | |||
117 | public JPanel getPanel() { |
||
118 | if(panelStarted)return this; |
||
119 | panelStarted=true;
|
||
120 | addComponent(new JLabel(" ")); |
||
121 | |||
122 | GridBagLayoutPanel selectionDefaultColorPanel = new GridBagLayoutPanel();
|
||
123 | 40723 | jldominguez | selectionDefaultColorPanel.setBorder(new TitledBorder( |
124 | Messages.getText("_Default_color")));
|
||
125 | 40435 | jjdelcerro | selectionDefaultColorPanel.setLayout(new GridBagLayout()); |
126 | 40723 | jldominguez | selectionDefaultColorPanel.add(new JLabel( |
127 | Messages.getText("fill")));
|
||
128 | 40435 | jjdelcerro | selectionDefaultColorPanel.add(defaultColor = new ColorChooserPanel());
|
129 | |||
130 | 40723 | jldominguez | selectionDefaultColorPanel.add(new JLabel( |
131 | Messages.getText("alpha")));
|
||
132 | 40435 | jjdelcerro | selectionDefaultColorPanel.add(jsDefaultSelectionAlpha = new JSlider(0,255)); |
133 | selectionDefaultColorPanel.add(new JBlank(50,50)); |
||
134 | |||
135 | jsDefaultSelectionAlpha.setPreferredSize(new Dimension(100,30)); |
||
136 | jsDefaultSelectionAlpha.addChangeListener(new ChangeListener(){ |
||
137 | public void stateChanged(ChangeEvent e) { |
||
138 | defaultColor.setAlpha(((JSlider)e.getSource()).getValue());
|
||
139 | }}); |
||
140 | addComponent(new JLabel(" ")); |
||
141 | addComponent(selectionDefaultColorPanel); |
||
142 | |||
143 | GridBagLayoutPanel selectionFillColor = new GridBagLayoutPanel();
|
||
144 | 40723 | jldominguez | selectionFillColor.setBorder(new TitledBorder( |
145 | Messages.getText("_Default_fill_color")));
|
||
146 | 40435 | jjdelcerro | selectionFillColor.setLayout(new GridBagLayout()); |
147 | 40723 | jldominguez | selectionFillColor.add(new JLabel( |
148 | Messages.getText("fill")));
|
||
149 | 40435 | jjdelcerro | selectionFillColor.add(defaultFillColor = new ColorChooserPanel());
|
150 | |||
151 | 40723 | jldominguez | selectionFillColor.add(new JLabel( |
152 | Messages.getText("alpha")));
|
||
153 | 40435 | jjdelcerro | selectionFillColor.add(jsFillSelelctionAlpha = new JSlider(0,255)); |
154 | |||
155 | jsFillSelelctionAlpha.setPreferredSize(new Dimension(100,30)); |
||
156 | jsFillSelelctionAlpha.addChangeListener(new ChangeListener(){ |
||
157 | public void stateChanged(ChangeEvent e) { |
||
158 | defaultFillColor.setAlpha(((JSlider)e.getSource()).getValue());
|
||
159 | }}); |
||
160 | |||
161 | selectionFillColor.add(new JBlank(50,50)); |
||
162 | selectionFillColor.add(aleatoryFillColor = new JCheckBox()); |
||
163 | 40723 | jldominguez | selectionFillColor.add(new JLabel(" " + |
164 | Messages.getText("_Random")));
|
||
165 | 40435 | jjdelcerro | |
166 | |||
167 | aleatoryFillColor.addActionListener(new ActionListener(){ |
||
168 | |||
169 | public void actionPerformed(ActionEvent e) { |
||
170 | if(e.getSource() == aleatoryFillColor){
|
||
171 | defaultFillColor.setEnabled(!aleatoryFillColor.isSelected()); |
||
172 | jsFillSelelctionAlpha.setEnabled(!aleatoryFillColor.isSelected()); |
||
173 | } |
||
174 | } |
||
175 | |||
176 | }); |
||
177 | |||
178 | addComponent(new JLabel(" ")); |
||
179 | addComponent(selectionFillColor); |
||
180 | |||
181 | btnFileChooserAction = new ActionListener() { |
||
182 | public void actionPerformed(ActionEvent e) { |
||
183 | String path;
|
||
184 | if (e.getSource().equals(btnSelectProjectsFolder)) {
|
||
185 | path = txtProjectsFolder.getText(); |
||
186 | |||
187 | |||
188 | FileFilter def = new FileFilter(){ |
||
189 | public boolean accept(File f) { |
||
190 | return (f.isDirectory());
|
||
191 | } |
||
192 | |||
193 | public String getDescription() { |
||
194 | return null; |
||
195 | } |
||
196 | }; |
||
197 | |||
198 | File file = new File(path); |
||
199 | JFileChooser fc;
|
||
200 | if (file.exists()) {
|
||
201 | fc = new JFileChooser("SYMBOLOGY_PREFERENCE_PAGE_FILECHOOSER", file); |
||
202 | } else {
|
||
203 | fc= new JFileChooser("SYMBOLOGY_PREFERENCE_PAGE_FILECHOOSER",JFileChooser.getLastPath("SYMBOLOGY_PREFERENCE_PAGE_FILECHOOSER", file)); |
||
204 | } |
||
205 | |||
206 | |||
207 | fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||
208 | fc.setMultiSelectionEnabled(false);
|
||
209 | fc.setAcceptAllFileFilterUsed(false);
|
||
210 | fc.addChoosableFileFilter(def); |
||
211 | int result = fc.showOpenDialog(SymbologyPage.this);
|
||
212 | |||
213 | if (result == JFileChooser.APPROVE_OPTION && (file = fc.getSelectedFile()) != null) |
||
214 | if (e.getSource().equals(btnSelectProjectsFolder))
|
||
215 | txtProjectsFolder.setText(file.getAbsolutePath()); |
||
216 | } |
||
217 | } |
||
218 | |||
219 | }; |
||
220 | 40723 | jldominguez | btnSelectProjectsFolder = new JButton( |
221 | Messages.getText("browse"));
|
||
222 | 40435 | jjdelcerro | btnSelectProjectsFolder.addActionListener(btnFileChooserAction); |
223 | |||
224 | JPanel panelBrowser = new JPanel(); |
||
225 | 40723 | jldominguez | panelBrowser.setBorder(new TitledBorder( |
226 | Messages.getText("_Symbols_folder")));
|
||
227 | 40435 | jjdelcerro | |
228 | panelBrowser.add(txtProjectsFolder = new JTextField(30)); |
||
229 | panelBrowser.add(btnSelectProjectsFolder); |
||
230 | |||
231 | addComponent(panelBrowser); |
||
232 | |||
233 | fonts= new JComboBoxFonts();
|
||
234 | sizes = new JComboBoxFontSizes();
|
||
235 | |||
236 | JPanel panelFont = new JPanel(new FlowLayout()); |
||
237 | 40723 | jldominguez | panelFont.setBorder(new TitledBorder( |
238 | Messages.getText("_Default_font")));
|
||
239 | 40435 | jjdelcerro | panelFont.add(fonts); |
240 | panelFont.add(sizes); |
||
241 | |||
242 | addComponent(panelFont); |
||
243 | initializeValues(); |
||
244 | return this; |
||
245 | } |
||
246 | |||
247 | public String getTitle() { |
||
248 | 40723 | jldominguez | return Messages.getText("Simbologia"); |
249 | 40435 | jjdelcerro | } |
250 | |||
251 | public void initializeValues() { |
||
252 | if (!panelStarted)
|
||
253 | getPanel(); |
||
254 | |||
255 | defaultColor.setColor(getPreferences().getDefaultSymbolColor()); |
||
256 | defaultColor.setAlpha(getPreferences().getDefaultSymbolColor().getAlpha()); |
||
257 | jsDefaultSelectionAlpha.setValue(getPreferences().getDefaultSymbolColor().getAlpha()); |
||
258 | |||
259 | aleatoryFillColor.setSelected(getPreferences().isDefaultSymbolFillColorAleatory()); |
||
260 | |||
261 | defaultFillColor.setColor(getPreferences().getDefaultSymbolFillColor()); |
||
262 | defaultFillColor.setAlpha(getPreferences().getDefaultSymbolFillColor().getAlpha()); |
||
263 | jsFillSelelctionAlpha.setValue(getPreferences().getDefaultSymbolFillColor().getAlpha()); |
||
264 | |||
265 | txtProjectsFolder.setText(getPreferences().getSymbolLibraryPath()); |
||
266 | |||
267 | fonts.setSelectedItem(getPreferences().getDefaultSymbolFont().getFamily()); |
||
268 | sizes.setSelectedItem(getPreferences().getDefaultSymbolFont().getSize()); |
||
269 | |||
270 | defaultFillColor.setEnabled(!aleatoryFillColor.isSelected()); |
||
271 | jsFillSelelctionAlpha.setEnabled(!aleatoryFillColor.isSelected()); |
||
272 | |||
273 | } |
||
274 | |||
275 | public void initializeDefaults() { |
||
276 | 40974 | jldominguez | |
277 | defaultColor.setColor(Color.DARK_GRAY);
|
||
278 | defaultColor.setAlpha(255);
|
||
279 | jsDefaultSelectionAlpha.setValue(255);
|
||
280 | |||
281 | aleatoryFillColor.setSelected(true);
|
||
282 | |||
283 | defaultFillColor.setColor(new Color(60, 235, 235)); |
||
284 | defaultFillColor.setAlpha(255);
|
||
285 | jsFillSelelctionAlpha.setValue(255);
|
||
286 | |||
287 | String path = PluginServices.getPluginServices(this). |
||
288 | getPluginHomeFolder().getAbsolutePath() + File.separator + "Symbols"; |
||
289 | txtProjectsFolder.setText(path); |
||
290 | |||
291 | fonts.setSelectedItem("SansSerif");
|
||
292 | sizes.setSelectedItem(14);
|
||
293 | |||
294 | defaultFillColor.setEnabled(!aleatoryFillColor.isSelected()); |
||
295 | jsFillSelelctionAlpha.setEnabled(!aleatoryFillColor.isSelected()); |
||
296 | 40435 | jjdelcerro | } |
297 | |||
298 | public boolean isValueChanged() { |
||
299 | return super.hasChanged(); |
||
300 | } |
||
301 | |||
302 | @Override
|
||
303 | public void storeValues() throws StoreException { |
||
304 | persistPreferences(); |
||
305 | } |
||
306 | |||
307 | private void persistPreferences() { |
||
308 | if(defaultColor.getColor() != null) { |
||
309 | Color color = defaultColor.getColor();
|
||
310 | color = new Color(color.getRed(), |
||
311 | color.getGreen(), |
||
312 | color.getBlue(), |
||
313 | jsDefaultSelectionAlpha.getValue()); |
||
314 | getPreferences().setDefaultSymbolColor(color); |
||
315 | } |
||
316 | |||
317 | if(aleatoryFillColor != null) { |
||
318 | getPreferences().setDefaultSymbolFillColorAleatory(aleatoryFillColor.isSelected()); |
||
319 | } |
||
320 | |||
321 | if (defaultFillColor.getColor() != null) { |
||
322 | Color color = defaultFillColor.getColor();
|
||
323 | color = new Color(color.getRed(),color.getGreen(),color.getBlue(),jsFillSelelctionAlpha.getValue()); |
||
324 | getPreferences().setDefaultSymbolFillColor(color); |
||
325 | } |
||
326 | |||
327 | if (txtProjectsFolder.getText() != null) { |
||
328 | getPreferences().setSymbolLibraryPath(txtProjectsFolder.getText()); |
||
329 | } |
||
330 | |||
331 | if(fonts.getFont() != null && sizes.getSelectedItem() != null){ |
||
332 | String f = (String)fonts.getSelectedItem(); |
||
333 | Font font = new Font(f, Font.PLAIN, (Integer)sizes.getSelectedItem()); |
||
334 | getPreferences().setDefaultSymbolFont(font); |
||
335 | } |
||
336 | } |
||
337 | } |