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