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 @ 40558
History | View | Annotate | Download (10.1 KB)
1 |
/**
|
---|---|
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 |
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 |
import org.gvsig.andami.PluginServices; |
48 |
import org.gvsig.andami.preferences.AbstractPreferencePage; |
49 |
import org.gvsig.andami.preferences.StoreException; |
50 |
import org.gvsig.app.gui.panels.ColorChooserPanel; |
51 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
52 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences; |
53 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
54 |
import org.gvsig.gui.beans.swing.JBlank; |
55 |
import org.gvsig.gui.beans.swing.JComboBoxFontSizes; |
56 |
import org.gvsig.gui.beans.swing.JComboBoxFonts; |
57 |
import org.gvsig.gui.beans.swing.JFileChooser; |
58 |
|
59 |
|
60 |
|
61 |
/**
|
62 |
* This class extends AbstractPreferencesPage. This component is a preferences page for
|
63 |
* symbology and allows select default fore color, fill color, font and size text and
|
64 |
* the path where the images that compound symbols are located.
|
65 |
*
|
66 |
*/
|
67 |
public class SymbologyPage extends AbstractPreferencePage { |
68 |
|
69 |
private static final long serialVersionUID = 1L; |
70 |
|
71 |
private SymbolPreferences preferences = null; |
72 |
|
73 |
private ColorChooserPanel defaultColor = null; |
74 |
private ColorChooserPanel defaultFillColor = null; |
75 |
private JSlider jsDefaultSelectionAlpha = null; |
76 |
private JSlider jsFillSelelctionAlpha = null; |
77 |
protected String id; |
78 |
private boolean panelStarted = false; |
79 |
private JButton btnSelectProjectsFolder=null; |
80 |
private ActionListener btnFileChooserAction=null; |
81 |
private JTextField txtProjectsFolder=null; |
82 |
private JComboBoxFonts fonts= null; |
83 |
private JComboBoxFontSizes sizes= null; |
84 |
private ImageIcon icon=null; |
85 |
private JCheckBox aleatoryFillColor; |
86 |
|
87 |
public SymbologyPage(){
|
88 |
super();
|
89 |
id = this.getClass().getName();
|
90 |
} |
91 |
|
92 |
public SymbolPreferences getPreferences() {
|
93 |
if(preferences == null) |
94 |
preferences = MapContextLocator.getSymbolManager().getSymbolPreferences(); |
95 |
return preferences;
|
96 |
} |
97 |
|
98 |
@Override
|
99 |
public void setChangesApplied() { |
100 |
setChanged(false);
|
101 |
|
102 |
} |
103 |
|
104 |
public String getID() { |
105 |
return id;
|
106 |
} |
107 |
|
108 |
public ImageIcon getIcon() { |
109 |
if (icon == null){ |
110 |
icon=PluginServices.getIconTheme().get("symbol-pref");
|
111 |
} |
112 |
return icon;
|
113 |
} |
114 |
|
115 |
public JPanel getPanel() { |
116 |
if(panelStarted)return this; |
117 |
panelStarted=true;
|
118 |
addComponent(new JLabel(" ")); |
119 |
|
120 |
GridBagLayoutPanel selectionDefaultColorPanel = new GridBagLayoutPanel();
|
121 |
selectionDefaultColorPanel.setBorder(new TitledBorder(PluginServices.getText(this, "default_color"))); |
122 |
selectionDefaultColorPanel.setLayout(new GridBagLayout()); |
123 |
selectionDefaultColorPanel.add(new JLabel(PluginServices.getText(this,"fill"))); |
124 |
selectionDefaultColorPanel.add(defaultColor = new ColorChooserPanel());
|
125 |
|
126 |
selectionDefaultColorPanel.add(new JLabel(PluginServices.getText(this,"alpha"))); |
127 |
selectionDefaultColorPanel.add(jsDefaultSelectionAlpha = new JSlider(0,255)); |
128 |
selectionDefaultColorPanel.add(new JBlank(50,50)); |
129 |
|
130 |
jsDefaultSelectionAlpha.setPreferredSize(new Dimension(100,30)); |
131 |
jsDefaultSelectionAlpha.addChangeListener(new ChangeListener(){ |
132 |
public void stateChanged(ChangeEvent e) { |
133 |
defaultColor.setAlpha(((JSlider)e.getSource()).getValue());
|
134 |
}}); |
135 |
addComponent(new JLabel(" ")); |
136 |
addComponent(selectionDefaultColorPanel); |
137 |
|
138 |
GridBagLayoutPanel selectionFillColor = new GridBagLayoutPanel();
|
139 |
selectionFillColor.setBorder(new TitledBorder(PluginServices.getText(this, "default_fill_color"))); |
140 |
selectionFillColor.setLayout(new GridBagLayout()); |
141 |
selectionFillColor.add(new JLabel(PluginServices.getText(this,"fill"))); |
142 |
selectionFillColor.add(defaultFillColor = new ColorChooserPanel());
|
143 |
|
144 |
selectionFillColor.add(new JLabel(PluginServices.getText(this,"alpha"))); |
145 |
selectionFillColor.add(jsFillSelelctionAlpha = new JSlider(0,255)); |
146 |
|
147 |
jsFillSelelctionAlpha.setPreferredSize(new Dimension(100,30)); |
148 |
jsFillSelelctionAlpha.addChangeListener(new ChangeListener(){ |
149 |
public void stateChanged(ChangeEvent e) { |
150 |
defaultFillColor.setAlpha(((JSlider)e.getSource()).getValue());
|
151 |
}}); |
152 |
|
153 |
selectionFillColor.add(new JBlank(50,50)); |
154 |
selectionFillColor.add(aleatoryFillColor = new JCheckBox()); |
155 |
selectionFillColor.add(new JLabel(" " + PluginServices.getText(this,"aleatory"))); |
156 |
|
157 |
|
158 |
aleatoryFillColor.addActionListener(new ActionListener(){ |
159 |
|
160 |
public void actionPerformed(ActionEvent e) { |
161 |
if(e.getSource() == aleatoryFillColor){
|
162 |
defaultFillColor.setEnabled(!aleatoryFillColor.isSelected()); |
163 |
jsFillSelelctionAlpha.setEnabled(!aleatoryFillColor.isSelected()); |
164 |
} |
165 |
} |
166 |
|
167 |
}); |
168 |
|
169 |
addComponent(new JLabel(" ")); |
170 |
addComponent(selectionFillColor); |
171 |
|
172 |
btnFileChooserAction = new ActionListener() { |
173 |
public void actionPerformed(ActionEvent e) { |
174 |
String path;
|
175 |
if (e.getSource().equals(btnSelectProjectsFolder)) {
|
176 |
path = txtProjectsFolder.getText(); |
177 |
|
178 |
|
179 |
FileFilter def = new FileFilter(){ |
180 |
public boolean accept(File f) { |
181 |
return (f.isDirectory());
|
182 |
} |
183 |
|
184 |
public String getDescription() { |
185 |
return null; |
186 |
} |
187 |
}; |
188 |
|
189 |
File file = new File(path); |
190 |
JFileChooser fc;
|
191 |
if (file.exists()) {
|
192 |
fc = new JFileChooser("SYMBOLOGY_PREFERENCE_PAGE_FILECHOOSER", file); |
193 |
} else {
|
194 |
fc= new JFileChooser("SYMBOLOGY_PREFERENCE_PAGE_FILECHOOSER",JFileChooser.getLastPath("SYMBOLOGY_PREFERENCE_PAGE_FILECHOOSER", file)); |
195 |
} |
196 |
|
197 |
|
198 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
199 |
fc.setMultiSelectionEnabled(false);
|
200 |
fc.setAcceptAllFileFilterUsed(false);
|
201 |
fc.addChoosableFileFilter(def); |
202 |
int result = fc.showOpenDialog(SymbologyPage.this);
|
203 |
|
204 |
if (result == JFileChooser.APPROVE_OPTION && (file = fc.getSelectedFile()) != null) |
205 |
if (e.getSource().equals(btnSelectProjectsFolder))
|
206 |
txtProjectsFolder.setText(file.getAbsolutePath()); |
207 |
} |
208 |
} |
209 |
|
210 |
}; |
211 |
btnSelectProjectsFolder = new JButton(PluginServices.getText(this, "browse")); |
212 |
btnSelectProjectsFolder.addActionListener(btnFileChooserAction); |
213 |
|
214 |
JPanel panelBrowser = new JPanel(); |
215 |
panelBrowser.setBorder(new TitledBorder(PluginServices.getText(this, "folder_images"))); |
216 |
|
217 |
panelBrowser.add(txtProjectsFolder = new JTextField(30)); |
218 |
panelBrowser.add(btnSelectProjectsFolder); |
219 |
|
220 |
addComponent(panelBrowser); |
221 |
|
222 |
fonts= new JComboBoxFonts();
|
223 |
sizes = new JComboBoxFontSizes();
|
224 |
|
225 |
JPanel panelFont = new JPanel(new FlowLayout()); |
226 |
panelFont.setBorder(new TitledBorder(PluginServices.getText(this, "default_font"))); |
227 |
panelFont.add(fonts); |
228 |
panelFont.add(sizes); |
229 |
|
230 |
addComponent(panelFont); |
231 |
initializeValues(); |
232 |
return this; |
233 |
} |
234 |
|
235 |
public String getTitle() { |
236 |
return PluginServices.getText(this, "symbology"); |
237 |
} |
238 |
|
239 |
public void initializeValues() { |
240 |
if (!panelStarted)
|
241 |
getPanel(); |
242 |
|
243 |
defaultColor.setColor(getPreferences().getDefaultSymbolColor()); |
244 |
defaultColor.setAlpha(getPreferences().getDefaultSymbolColor().getAlpha()); |
245 |
jsDefaultSelectionAlpha.setValue(getPreferences().getDefaultSymbolColor().getAlpha()); |
246 |
|
247 |
aleatoryFillColor.setSelected(getPreferences().isDefaultSymbolFillColorAleatory()); |
248 |
|
249 |
defaultFillColor.setColor(getPreferences().getDefaultSymbolFillColor()); |
250 |
defaultFillColor.setAlpha(getPreferences().getDefaultSymbolFillColor().getAlpha()); |
251 |
jsFillSelelctionAlpha.setValue(getPreferences().getDefaultSymbolFillColor().getAlpha()); |
252 |
|
253 |
txtProjectsFolder.setText(getPreferences().getSymbolLibraryPath()); |
254 |
|
255 |
fonts.setSelectedItem(getPreferences().getDefaultSymbolFont().getFamily()); |
256 |
sizes.setSelectedItem(getPreferences().getDefaultSymbolFont().getSize()); |
257 |
|
258 |
defaultFillColor.setEnabled(!aleatoryFillColor.isSelected()); |
259 |
jsFillSelelctionAlpha.setEnabled(!aleatoryFillColor.isSelected()); |
260 |
|
261 |
} |
262 |
|
263 |
public void initializeDefaults() { |
264 |
|
265 |
} |
266 |
|
267 |
public boolean isValueChanged() { |
268 |
return super.hasChanged(); |
269 |
} |
270 |
|
271 |
@Override
|
272 |
public void storeValues() throws StoreException { |
273 |
persistPreferences(); |
274 |
} |
275 |
|
276 |
private void persistPreferences() { |
277 |
if(defaultColor.getColor() != null) { |
278 |
Color color = defaultColor.getColor();
|
279 |
color = new Color(color.getRed(), |
280 |
color.getGreen(), |
281 |
color.getBlue(), |
282 |
jsDefaultSelectionAlpha.getValue()); |
283 |
getPreferences().setDefaultSymbolColor(color); |
284 |
} |
285 |
|
286 |
if(aleatoryFillColor != null) { |
287 |
getPreferences().setDefaultSymbolFillColorAleatory(aleatoryFillColor.isSelected()); |
288 |
} |
289 |
|
290 |
if (defaultFillColor.getColor() != null) { |
291 |
Color color = defaultFillColor.getColor();
|
292 |
color = new Color(color.getRed(),color.getGreen(),color.getBlue(),jsFillSelelctionAlpha.getValue()); |
293 |
getPreferences().setDefaultSymbolFillColor(color); |
294 |
} |
295 |
|
296 |
if (txtProjectsFolder.getText() != null) { |
297 |
getPreferences().setSymbolLibraryPath(txtProjectsFolder.getText()); |
298 |
} |
299 |
|
300 |
if(fonts.getFont() != null && sizes.getSelectedItem() != null){ |
301 |
String f = (String)fonts.getSelectedItem(); |
302 |
Font font = new Font(f, Font.PLAIN, (Integer)sizes.getSelectedItem()); |
303 |
getPreferences().setDefaultSymbolFont(font); |
304 |
} |
305 |
} |
306 |
} |