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