root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / preferencespage / SymbologyPage.java @ 22996
History | View | Annotate | Download (15.5 KB)
1 |
package com.iver.cit.gvsig.gui.preferencespage; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Color; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.FlowLayout; |
7 |
import java.awt.Font; |
8 |
import java.awt.GridBagLayout; |
9 |
import java.awt.GridLayout; |
10 |
import java.awt.event.ActionEvent; |
11 |
import java.awt.event.ActionListener; |
12 |
import java.io.File; |
13 |
|
14 |
import javax.swing.BoxLayout; |
15 |
import javax.swing.ImageIcon; |
16 |
import javax.swing.JButton; |
17 |
import javax.swing.JCheckBox; |
18 |
import javax.swing.JLabel; |
19 |
import javax.swing.JPanel; |
20 |
import javax.swing.JSlider; |
21 |
import javax.swing.JTextField; |
22 |
import javax.swing.border.TitledBorder; |
23 |
import javax.swing.event.ChangeEvent; |
24 |
import javax.swing.event.ChangeListener; |
25 |
import javax.swing.filechooser.FileFilter; |
26 |
|
27 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
28 |
import org.gvsig.gui.beans.swing.JBlank; |
29 |
import org.gvsig.gui.beans.swing.JComboBoxFontSizes; |
30 |
import org.gvsig.gui.beans.swing.JComboBoxFonts; |
31 |
import org.gvsig.gui.beans.swing.JFileChooser; |
32 |
|
33 |
import com.iver.andami.PluginServices; |
34 |
import com.iver.andami.preferences.AbstractPreferencePage; |
35 |
import com.iver.andami.preferences.StoreException; |
36 |
import com.iver.cit.gvsig.fmap.core.FShape; |
37 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
38 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
39 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.JSymbolPreviewButton; |
40 |
import com.iver.utiles.StringUtilities; |
41 |
import com.iver.utiles.XMLEntity; |
42 |
|
43 |
|
44 |
/**
|
45 |
* This class extends AbstractPreferencesPage. This component is a preferences page for
|
46 |
* symbology and allows select default fore color, fill color, font and size text and
|
47 |
* the path where the images that compound symbols are located.
|
48 |
*
|
49 |
*/
|
50 |
public class SymbologyPage extends AbstractPreferencePage{ |
51 |
|
52 |
private static final long serialVersionUID = 1L; |
53 |
|
54 |
private ColorChooserPanel defaultColor = null; |
55 |
private ColorChooserPanel defaultFillColor = null; |
56 |
private JSlider jsDefaultSelectionAlpha = null; |
57 |
private JSlider jsFillSelelctionAlpha = null; |
58 |
protected String id; |
59 |
private boolean panelStarted = false; |
60 |
private JButton btnSelectProjectsFolder=null; |
61 |
private ActionListener btnFileChooserAction=null; |
62 |
private JTextField txtProjectsFolder=null; |
63 |
private JComboBoxFonts fonts= null; |
64 |
private JComboBoxFontSizes sizes= null; |
65 |
private ImageIcon icon=null; |
66 |
private JCheckBox aleatoryFillColor; |
67 |
|
68 |
|
69 |
private static final String SYMBOL_FORECOLOR_PROPERTY_NAME = "ForeColor"; |
70 |
private static final String SYMBOL_FILLCOLOR_PROPERTY_NAME = "FillColor"; |
71 |
private static final String SYMBOL_FONT_TYPE_PROPERTY_NAME = "FontType"; |
72 |
private static final String SYMBOL_FONT_SIZE_PROPERTY_NAME = "FontSize"; |
73 |
private static final String SYMBOL_IMAGE_FOLDER_PROPERTY_NAME = "ImageFolder"; |
74 |
private static final String SYMBOL_ALEATORY_FORECOLOR = "AleatoryForeColor"; |
75 |
private static final String SYMBOL_ALEATORY_FILLCOLOR = "AleatoryFillColor"; |
76 |
|
77 |
|
78 |
|
79 |
public SymbologyPage(){
|
80 |
super();
|
81 |
icon=PluginServices.getIconTheme().get("symbol-pref");
|
82 |
id = this.getClass().getName();
|
83 |
} |
84 |
|
85 |
// pending of a proposed refactor, don't erase
|
86 |
public void persistPreferences() throws StoreException { |
87 |
File f;
|
88 |
String path, propertyName;
|
89 |
Color foreColor=defaultColor.getColor();
|
90 |
Color fillColor=defaultFillColor.getColor();
|
91 |
PluginServices ps = PluginServices.getPluginServices(this);
|
92 |
XMLEntity xml = ps.getPersistentXML(); |
93 |
|
94 |
xml.putProperty(SYMBOL_FORECOLOR_PROPERTY_NAME, |
95 |
StringUtilities.color2String(foreColor)); |
96 |
|
97 |
|
98 |
xml.putProperty(SYMBOL_FILLCOLOR_PROPERTY_NAME, |
99 |
StringUtilities.color2String(fillColor)); |
100 |
xml.putProperty(SYMBOL_ALEATORY_FILLCOLOR,aleatoryFillColor.isSelected()); |
101 |
|
102 |
propertyName = SYMBOL_IMAGE_FOLDER_PROPERTY_NAME; |
103 |
path = txtProjectsFolder.getText(); |
104 |
|
105 |
if (path.equals("")) { |
106 |
if (xml.contains(propertyName)) {
|
107 |
xml.remove(propertyName); |
108 |
} |
109 |
} else {
|
110 |
f = new File(path); |
111 |
if (f.exists()) {
|
112 |
if (xml.contains(propertyName)) {
|
113 |
xml.remove(propertyName); |
114 |
} |
115 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
116 |
} |
117 |
} |
118 |
|
119 |
String nameFont=(String)fonts.getSelectedItem(); |
120 |
Integer sizeFontAux =(Integer)sizes.getSelectedItem(); |
121 |
int sizeFont=sizeFontAux.intValue();
|
122 |
|
123 |
propertyName=SYMBOL_FONT_TYPE_PROPERTY_NAME; |
124 |
xml.putProperty(propertyName, nameFont); |
125 |
|
126 |
propertyName=SYMBOL_FONT_SIZE_PROPERTY_NAME; |
127 |
xml.putProperty(propertyName, sizeFont); |
128 |
|
129 |
|
130 |
} |
131 |
|
132 |
@Override
|
133 |
public void setChangesApplied() { |
134 |
setChanged(false);
|
135 |
|
136 |
} |
137 |
|
138 |
public void applyValuesFromPersistence() throws StoreException { |
139 |
PluginServices ps = PluginServices.getPluginServices(this);
|
140 |
XMLEntity xml = ps.getPersistentXML(); |
141 |
xml = ps.getPersistentXML(); |
142 |
|
143 |
|
144 |
|
145 |
if(xml.contains(SYMBOL_FORECOLOR_PROPERTY_NAME)){
|
146 |
//Color
|
147 |
Color color=StringUtilities.string2Color(xml.getStringProperty(SYMBOL_FORECOLOR_PROPERTY_NAME));
|
148 |
SymbologyFactory.DefaultSymbolColor=color; |
149 |
}else{
|
150 |
SymbologyFactory.DefaultSymbolColor=SymbologyFactory.FactoryDefaultSymbolColor; |
151 |
} |
152 |
|
153 |
|
154 |
//FillColor
|
155 |
if(xml.contains(SYMBOL_FILLCOLOR_PROPERTY_NAME)){
|
156 |
Color colorFill=StringUtilities.string2Color(xml.getStringProperty(SYMBOL_FILLCOLOR_PROPERTY_NAME));
|
157 |
SymbologyFactory.DefaultFillSymbolColor=colorFill; |
158 |
}else{
|
159 |
SymbologyFactory.DefaultFillSymbolColor=SymbologyFactory.FactoryDefaultFillSymbolColor; |
160 |
} |
161 |
|
162 |
//Path
|
163 |
if(xml.contains(SYMBOL_IMAGE_FOLDER_PROPERTY_NAME)){
|
164 |
SymbologyFactory.SymbolLibraryPath=xml.getStringProperty(SYMBOL_IMAGE_FOLDER_PROPERTY_NAME); |
165 |
}else{
|
166 |
SymbologyFactory.SymbolLibraryPath=SymbologyFactory.FactorySymbolLibraryPath; |
167 |
} |
168 |
//Font
|
169 |
if(xml.contains(SYMBOL_FONT_TYPE_PROPERTY_NAME)){
|
170 |
int size=xml.getIntProperty(SYMBOL_FONT_SIZE_PROPERTY_NAME);
|
171 |
String type=xml.getStringProperty(SYMBOL_FONT_TYPE_PROPERTY_NAME);
|
172 |
Font font= new Font(type, Font.BOLD, size); |
173 |
SymbologyFactory.DefaultTextFont=font; |
174 |
}else{
|
175 |
SymbologyFactory.DefaultTextFont=SymbologyFactory.FactoryDefaultTextFont; |
176 |
} |
177 |
|
178 |
} |
179 |
|
180 |
public String getID() { |
181 |
return id;
|
182 |
} |
183 |
|
184 |
public ImageIcon getIcon() { |
185 |
return icon;
|
186 |
} |
187 |
|
188 |
public JPanel getPanel() { |
189 |
if(panelStarted)return this; |
190 |
panelStarted=true;
|
191 |
addComponent(new JLabel(" ")); |
192 |
|
193 |
GridBagLayoutPanel selectionDefaultColorPanel = new GridBagLayoutPanel();
|
194 |
selectionDefaultColorPanel.setBorder(new TitledBorder(PluginServices.getText(this, "default_color"))); |
195 |
selectionDefaultColorPanel.setLayout(new GridBagLayout()); |
196 |
selectionDefaultColorPanel.add(new JLabel(PluginServices.getText(this,"fill"))); |
197 |
selectionDefaultColorPanel.add(defaultColor = new ColorChooserPanel());
|
198 |
|
199 |
selectionDefaultColorPanel.add(new JLabel(PluginServices.getText(this,"alpha"))); |
200 |
selectionDefaultColorPanel.add(jsDefaultSelectionAlpha = new JSlider(0,255)); |
201 |
selectionDefaultColorPanel.add(new JBlank(50,50)); |
202 |
|
203 |
jsDefaultSelectionAlpha.setPreferredSize(new Dimension(100,30)); |
204 |
jsDefaultSelectionAlpha.addChangeListener(new ChangeListener(){ |
205 |
public void stateChanged(ChangeEvent e) { |
206 |
defaultColor.setAlpha(((JSlider)e.getSource()).getValue());
|
207 |
}}); |
208 |
addComponent(new JLabel(" ")); |
209 |
addComponent(selectionDefaultColorPanel); |
210 |
|
211 |
GridBagLayoutPanel selectionFillColor = new GridBagLayoutPanel();
|
212 |
selectionFillColor.setBorder(new TitledBorder(PluginServices.getText(this, "default_fill_color"))); |
213 |
selectionFillColor.setLayout(new GridBagLayout()); |
214 |
selectionFillColor.add(new JLabel(PluginServices.getText(this,"fill"))); |
215 |
selectionFillColor.add(defaultFillColor = new ColorChooserPanel());
|
216 |
|
217 |
selectionFillColor.add(new JLabel(PluginServices.getText(this,"alpha"))); |
218 |
selectionFillColor.add(jsFillSelelctionAlpha = new JSlider(0,255)); |
219 |
|
220 |
jsFillSelelctionAlpha.setPreferredSize(new Dimension(100,30)); |
221 |
jsFillSelelctionAlpha.addChangeListener(new ChangeListener(){ |
222 |
public void stateChanged(ChangeEvent e) { |
223 |
defaultFillColor.setAlpha(((JSlider)e.getSource()).getValue());
|
224 |
}}); |
225 |
|
226 |
selectionFillColor.add(new JBlank(50,50)); |
227 |
selectionFillColor.add(aleatoryFillColor = new JCheckBox()); |
228 |
selectionFillColor.add(new JLabel(" " + PluginServices.getText(this,"aleatory"))); |
229 |
|
230 |
|
231 |
aleatoryFillColor.addActionListener(new ActionListener(){ |
232 |
|
233 |
public void actionPerformed(ActionEvent e) { |
234 |
if(e.getSource() == aleatoryFillColor){
|
235 |
defaultFillColor.setEnabled(!aleatoryFillColor.isSelected()); |
236 |
jsFillSelelctionAlpha.setEnabled(!aleatoryFillColor.isSelected()); |
237 |
} |
238 |
} |
239 |
|
240 |
}); |
241 |
|
242 |
addComponent(new JLabel(" ")); |
243 |
addComponent(selectionFillColor); |
244 |
|
245 |
btnFileChooserAction = new ActionListener() { |
246 |
public void actionPerformed(ActionEvent e) { |
247 |
String path;
|
248 |
if (e.getSource().equals(btnSelectProjectsFolder)) {
|
249 |
path = txtProjectsFolder.getText(); |
250 |
|
251 |
|
252 |
FileFilter def = new FileFilter(){ |
253 |
public boolean accept(File f) { |
254 |
return (f.isDirectory());
|
255 |
} |
256 |
|
257 |
public String getDescription() { |
258 |
return null; |
259 |
} |
260 |
}; |
261 |
|
262 |
File file = new File(path); |
263 |
JFileChooser fc;
|
264 |
if (file.exists()) {
|
265 |
fc = new JFileChooser("SYMBOLOGY_PREFERENCE_PAGE_FILECHOOSER", file); |
266 |
} else {
|
267 |
fc= new JFileChooser("SYMBOLOGY_PREFERENCE_PAGE_FILECHOOSER",JFileChooser.getLastPath("SYMBOLOGY_PREFERENCE_PAGE_FILECHOOSER", file)); |
268 |
} |
269 |
|
270 |
|
271 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
272 |
fc.setMultiSelectionEnabled(false);
|
273 |
fc.setAcceptAllFileFilterUsed(false);
|
274 |
fc.addChoosableFileFilter(def); |
275 |
int result = fc.showOpenDialog(SymbologyPage.this);
|
276 |
|
277 |
if (result == JFileChooser.APPROVE_OPTION && (file = fc.getSelectedFile()) != null) |
278 |
if (e.getSource().equals(btnSelectProjectsFolder))
|
279 |
txtProjectsFolder.setText(file.getAbsolutePath()); |
280 |
} |
281 |
} |
282 |
|
283 |
}; |
284 |
btnSelectProjectsFolder = new JButton(PluginServices.getText(this, "browse")); |
285 |
btnSelectProjectsFolder.addActionListener(btnFileChooserAction); |
286 |
|
287 |
JPanel panelBrowser = new JPanel(); |
288 |
panelBrowser.setBorder(new TitledBorder(PluginServices.getText(this, "folder_images"))); |
289 |
|
290 |
panelBrowser.add(txtProjectsFolder = new JTextField(30)); |
291 |
panelBrowser.add(btnSelectProjectsFolder); |
292 |
|
293 |
addComponent(panelBrowser); |
294 |
|
295 |
fonts= new JComboBoxFonts();
|
296 |
sizes = new JComboBoxFontSizes();
|
297 |
|
298 |
JPanel panelFont = new JPanel(new FlowLayout()); |
299 |
panelFont.setBorder(new TitledBorder(PluginServices.getText(this, "default_font"))); |
300 |
panelFont.add(fonts); |
301 |
panelFont.add(sizes); |
302 |
|
303 |
addComponent(panelFont); |
304 |
initializeValues(); |
305 |
return this; |
306 |
} |
307 |
|
308 |
public String getTitle() { |
309 |
return PluginServices.getText(this, "symbology"); |
310 |
} |
311 |
// pending of a refactoring do not delete (swap commented lines)
|
312 |
// public void initializeComponents() {
|
313 |
public void initializeValues() { |
314 |
if (!panelStarted) getPanel();
|
315 |
|
316 |
PluginServices ps = PluginServices.getPluginServices(this);
|
317 |
XMLEntity xml = ps.getPersistentXML(); |
318 |
|
319 |
|
320 |
//Default Color
|
321 |
if (xml.contains(SYMBOL_FORECOLOR_PROPERTY_NAME)) {
|
322 |
Color color=StringUtilities.string2Color(xml.getStringProperty(SYMBOL_FORECOLOR_PROPERTY_NAME));
|
323 |
defaultColor.setColor(color); |
324 |
defaultColor.setAlpha(color.getAlpha()); |
325 |
jsDefaultSelectionAlpha.setValue(color.getAlpha()); |
326 |
SymbologyFactory.DefaultSymbolColor = color; |
327 |
}else{
|
328 |
Color color=SymbologyFactory.FactoryDefaultSymbolColor;
|
329 |
defaultColor.setColor(color); |
330 |
defaultColor.setAlpha(color.getAlpha()); |
331 |
jsDefaultSelectionAlpha.setValue(color.getAlpha()); |
332 |
SymbologyFactory.DefaultSymbolColor = color; |
333 |
} |
334 |
|
335 |
if(xml.contains(SYMBOL_ALEATORY_FILLCOLOR)){
|
336 |
aleatoryFillColor.setSelected(xml.getBooleanProperty(SYMBOL_ALEATORY_FILLCOLOR)); |
337 |
SymbologyFactory.DefaultAleatoryFillColor = aleatoryFillColor.isSelected(); |
338 |
}else{
|
339 |
aleatoryFillColor.setSelected(SymbologyFactory.FactoryDefaultAleatoryFillColor); |
340 |
SymbologyFactory.DefaultAleatoryFillColor = aleatoryFillColor.isSelected(); |
341 |
} |
342 |
|
343 |
//Fill Color
|
344 |
if (xml.contains(SYMBOL_FILLCOLOR_PROPERTY_NAME)) {
|
345 |
Color color=StringUtilities.string2Color(xml.getStringProperty(SYMBOL_FILLCOLOR_PROPERTY_NAME));
|
346 |
defaultFillColor.setColor(color); |
347 |
defaultFillColor.setAlpha(color.getAlpha()); |
348 |
jsFillSelelctionAlpha.setValue(color.getAlpha()); |
349 |
SymbologyFactory.DefaultFillSymbolColor = color; |
350 |
}else{
|
351 |
Color color=SymbologyFactory.FactoryDefaultFillSymbolColor;
|
352 |
defaultFillColor.setColor(color); |
353 |
defaultFillColor.setAlpha(color.getAlpha()); |
354 |
jsFillSelelctionAlpha.setValue(color.getAlpha()); |
355 |
SymbologyFactory.DefaultFillSymbolColor = color; |
356 |
} |
357 |
|
358 |
defaultFillColor.setEnabled(!aleatoryFillColor.isSelected()); |
359 |
jsFillSelelctionAlpha.setEnabled(!aleatoryFillColor.isSelected()); |
360 |
|
361 |
//Path
|
362 |
if (xml.contains(SYMBOL_IMAGE_FOLDER_PROPERTY_NAME)) {
|
363 |
String path=xml.getStringProperty(SYMBOL_IMAGE_FOLDER_PROPERTY_NAME);
|
364 |
txtProjectsFolder.setText(path); |
365 |
SymbologyFactory.SymbolLibraryPath = path; |
366 |
}else{
|
367 |
txtProjectsFolder.setText(SymbologyFactory.FactorySymbolLibraryPath); |
368 |
SymbologyFactory.SymbolLibraryPath = SymbologyFactory.FactorySymbolLibraryPath; |
369 |
} |
370 |
|
371 |
//Font Size
|
372 |
if(xml.contains(SYMBOL_FONT_TYPE_PROPERTY_NAME)){
|
373 |
String type=xml.getStringProperty(SYMBOL_FONT_TYPE_PROPERTY_NAME);
|
374 |
fonts.setSelectedItem(type); |
375 |
} |
376 |
else{
|
377 |
String font =SymbologyFactory.FactoryDefaultTextFont.getFontName();
|
378 |
fonts.setSelectedItem(font); |
379 |
} |
380 |
|
381 |
if(xml.contains(SYMBOL_FONT_SIZE_PROPERTY_NAME)){
|
382 |
int size=xml.getIntProperty(SYMBOL_FONT_SIZE_PROPERTY_NAME);
|
383 |
sizes.setSelectedItem(size); |
384 |
} |
385 |
else{
|
386 |
int size =SymbologyFactory.FactoryDefaultTextFont.getSize();
|
387 |
sizes.setSelectedItem(size); |
388 |
} |
389 |
SymbologyFactory.DefaultTextFont = new Font(fonts.getFont().getName(),fonts.getFont().getStyle(),(Integer) sizes.getSelectedItem()); |
390 |
} |
391 |
|
392 |
public void initializeDefaults() { |
393 |
defaultColor.setColor(SymbologyFactory.FactoryDefaultSymbolColor); |
394 |
jsDefaultSelectionAlpha.setValue(255);
|
395 |
|
396 |
defaultFillColor.setColor(SymbologyFactory.FactoryDefaultFillSymbolColor); |
397 |
jsFillSelelctionAlpha.setValue(255);
|
398 |
|
399 |
fonts.setSelectedItem(SymbologyFactory.FactoryDefaultTextFont.getFamily()); |
400 |
sizes.setSelectedItem(SymbologyFactory.FactoryDefaultTextFont.getSize()); |
401 |
txtProjectsFolder.setText(SymbologyFactory.FactorySymbolLibraryPath); |
402 |
|
403 |
aleatoryFillColor.setSelected(SymbologyFactory.FactoryDefaultAleatoryFillColor); |
404 |
} |
405 |
|
406 |
public boolean isValueChanged() { |
407 |
return super.hasChanged(); |
408 |
} |
409 |
|
410 |
// pending of a refactoring, following method would be removed
|
411 |
@Override
|
412 |
public void storeValues() throws StoreException { |
413 |
setPropertiesFromPanel(); |
414 |
persistPreferences(); |
415 |
} |
416 |
|
417 |
private void setPropertiesFromPanel(){ |
418 |
|
419 |
if(defaultColor.getColor()!=null){ |
420 |
Color color = defaultColor.getColor();
|
421 |
color = new Color(color.getRed(),color.getGreen(),color.getBlue(),jsDefaultSelectionAlpha.getValue()); |
422 |
SymbologyFactory.DefaultSymbolColor = color; |
423 |
} |
424 |
|
425 |
if(aleatoryFillColor != null){ |
426 |
SymbologyFactory.DefaultAleatoryFillColor = aleatoryFillColor.isSelected(); |
427 |
} |
428 |
//Fill Color
|
429 |
if (defaultFillColor.getColor() != null) { |
430 |
Color color = defaultFillColor.getColor();
|
431 |
color = new Color(color.getRed(),color.getGreen(),color.getBlue(),jsFillSelelctionAlpha.getValue()); |
432 |
SymbologyFactory.DefaultFillSymbolColor = color; |
433 |
} |
434 |
|
435 |
//Path
|
436 |
if (txtProjectsFolder.getText() != null) { |
437 |
SymbologyFactory.SymbolLibraryPath = txtProjectsFolder.getText(); |
438 |
} |
439 |
|
440 |
//Font Size
|
441 |
if(fonts.getFont() != null && sizes.getSelectedItem() != null){ |
442 |
Font font = fonts.getFont();
|
443 |
font= new Font(fonts.getFont().getFontName(), Font.BOLD, (Integer)sizes.getSelectedItem()); |
444 |
SymbologyFactory.DefaultTextFont = font; |
445 |
} |
446 |
|
447 |
|
448 |
} |
449 |
|
450 |
} |