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 | 29596 | jpiera | package org.gvsig.app.gui.preferencespage; |
---|---|---|---|
2 | 18623 | jdominguez | |
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 | 23712 | vcaballero | import javax.swing.JCheckBox; |
15 | 18623 | jdominguez | 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 | 29596 | jpiera | 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 | 30011 | cordinyana | import org.gvsig.fmap.mapcontext.MapContextLocator; |
29 | 30892 | cordinyana | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences; |
30 | 23712 | vcaballero | import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
31 | import org.gvsig.gui.beans.swing.JBlank; |
||
32 | 18623 | jdominguez | 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 | 23712 | vcaballero | *
|
43 | 18623 | jdominguez | */
|
44 | 38442 | nbrodin | public class SymbologyPage extends AbstractPreferencePage { |
45 | 23712 | vcaballero | |
46 | 18623 | jdominguez | private static final long serialVersionUID = 1L; |
47 | 30011 | cordinyana | |
48 | 38442 | nbrodin | private SymbolPreferences preferences = null; |
49 | 23712 | vcaballero | |
50 | 18623 | jdominguez | 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 | 23712 | vcaballero | private JCheckBox aleatoryFillColor; |
63 | |||
64 | 18623 | jdominguez | public SymbologyPage(){
|
65 | super();
|
||
66 | id = this.getClass().getName();
|
||
67 | } |
||
68 | 30892 | cordinyana | |
69 | public SymbolPreferences getPreferences() {
|
||
70 | 38442 | nbrodin | if(preferences == null) |
71 | preferences = MapContextLocator.getSymbolManager().getSymbolPreferences(); |
||
72 | 30892 | cordinyana | return preferences;
|
73 | } |
||
74 | 23712 | vcaballero | |
75 | 18623 | jdominguez | @Override
|
76 | public void setChangesApplied() { |
||
77 | setChanged(false);
|
||
78 | 23712 | vcaballero | |
79 | 18623 | jdominguez | } |
80 | |||
81 | public String getID() { |
||
82 | return id;
|
||
83 | } |
||
84 | |||
85 | public ImageIcon getIcon() { |
||
86 | 25750 | vcaballero | if (icon == null){ |
87 | icon=PluginServices.getIconTheme().get("symbol-pref");
|
||
88 | } |
||
89 | 18623 | jdominguez | return icon;
|
90 | } |
||
91 | |||
92 | public JPanel getPanel() { |
||
93 | if(panelStarted)return this; |
||
94 | panelStarted=true;
|
||
95 | addComponent(new JLabel(" ")); |
||
96 | 23712 | vcaballero | |
97 | GridBagLayoutPanel selectionDefaultColorPanel = new GridBagLayoutPanel();
|
||
98 | 18623 | jdominguez | 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 | 23712 | vcaballero | |
103 | 18623 | jdominguez | selectionDefaultColorPanel.add(new JLabel(PluginServices.getText(this,"alpha"))); |
104 | selectionDefaultColorPanel.add(jsDefaultSelectionAlpha = new JSlider(0,255)); |
||
105 | 23712 | vcaballero | selectionDefaultColorPanel.add(new JBlank(50,50)); |
106 | |||
107 | 18623 | jdominguez | 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 | 23712 | vcaballero | addComponent(new JLabel(" ")); |
113 | 18623 | jdominguez | addComponent(selectionDefaultColorPanel); |
114 | 23712 | vcaballero | |
115 | GridBagLayoutPanel selectionFillColor = new GridBagLayoutPanel();
|
||
116 | 18623 | jdominguez | 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 | 23712 | vcaballero | |
121 | 18623 | jdominguez | selectionFillColor.add(new JLabel(PluginServices.getText(this,"alpha"))); |
122 | selectionFillColor.add(jsFillSelelctionAlpha = new JSlider(0,255)); |
||
123 | 23712 | vcaballero | |
124 | 18623 | jdominguez | 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 | 23712 | vcaballero | |
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 | 18623 | jdominguez | addComponent(new JLabel(" ")); |
147 | addComponent(selectionFillColor); |
||
148 | 23712 | vcaballero | |
149 | 18623 | jdominguez | btnFileChooserAction = new ActionListener() { |
150 | public void actionPerformed(ActionEvent e) { |
||
151 | String path;
|
||
152 | if (e.getSource().equals(btnSelectProjectsFolder)) {
|
||
153 | path = txtProjectsFolder.getText(); |
||
154 | |||
155 | 23712 | vcaballero | |
156 | 18623 | jdominguez | 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 | 23712 | vcaballero | |
175 | 18623 | jdominguez | 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 | 23712 | vcaballero | if (result == JFileChooser.APPROVE_OPTION && (file = fc.getSelectedFile()) != null) |
182 | if (e.getSource().equals(btnSelectProjectsFolder))
|
||
183 | 18623 | jdominguez | txtProjectsFolder.setText(file.getAbsolutePath()); |
184 | } |
||
185 | } |
||
186 | |||
187 | }; |
||
188 | btnSelectProjectsFolder = new JButton(PluginServices.getText(this, "browse")); |
||
189 | btnSelectProjectsFolder.addActionListener(btnFileChooserAction); |
||
190 | 23712 | vcaballero | |
191 | 18623 | jdominguez | 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 | 23712 | vcaballero | |
197 | 18623 | jdominguez | addComponent(panelBrowser); |
198 | 23712 | vcaballero | |
199 | 18623 | jdominguez | fonts= new JComboBoxFonts();
|
200 | sizes = new JComboBoxFontSizes();
|
||
201 | 23712 | vcaballero | |
202 | 18623 | jdominguez | 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 | 23712 | vcaballero | |
207 | 18623 | jdominguez | addComponent(panelFont); |
208 | 23712 | vcaballero | initializeValues(); |
209 | 18623 | jdominguez | return this; |
210 | } |
||
211 | |||
212 | public String getTitle() { |
||
213 | return PluginServices.getText(this, "symbology"); |
||
214 | } |
||
215 | 38442 | nbrodin | |
216 | 18623 | jdominguez | public void initializeValues() { |
217 | 38442 | nbrodin | if (!panelStarted)
|
218 | getPanel(); |
||
219 | 18623 | jdominguez | |
220 | 38442 | nbrodin | defaultColor.setColor(getPreferences().getDefaultSymbolColor()); |
221 | defaultColor.setAlpha(getPreferences().getDefaultSymbolColor().getAlpha()); |
||
222 | jsDefaultSelectionAlpha.setValue(getPreferences().getDefaultSymbolColor().getAlpha()); |
||
223 | |||
224 | aleatoryFillColor.setSelected(getPreferences().isDefaultSymbolFillColorAleatory()); |
||
225 | 18623 | jdominguez | |
226 | 38442 | nbrodin | defaultFillColor.setColor(getPreferences().getDefaultSymbolFillColor()); |
227 | defaultFillColor.setAlpha(getPreferences().getDefaultSymbolFillColor().getAlpha()); |
||
228 | jsFillSelelctionAlpha.setValue(getPreferences().getDefaultSymbolFillColor().getAlpha()); |
||
229 | |||
230 | txtProjectsFolder.setText(getPreferences().getSymbolLibraryPath()); |
||
231 | 30892 | cordinyana | |
232 | 38442 | nbrodin | fonts.setSelectedItem(getPreferences().getDefaultSymbolFont().getFamily()); |
233 | sizes.setSelectedItem(getPreferences().getDefaultSymbolFont().getSize()); |
||
234 | |||
235 | 23712 | vcaballero | defaultFillColor.setEnabled(!aleatoryFillColor.isSelected()); |
236 | jsFillSelelctionAlpha.setEnabled(!aleatoryFillColor.isSelected()); |
||
237 | |||
238 | 18623 | jdominguez | } |
239 | |||
240 | public void initializeDefaults() { |
||
241 | 38442 | nbrodin | |
242 | 18623 | jdominguez | } |
243 | 38442 | nbrodin | |
244 | 18623 | jdominguez | public boolean isValueChanged() { |
245 | return super.hasChanged(); |
||
246 | } |
||
247 | |||
248 | @Override
|
||
249 | public void storeValues() throws StoreException { |
||
250 | 23712 | vcaballero | persistPreferences(); |
251 | 18623 | jdominguez | } |
252 | 23712 | vcaballero | |
253 | 38442 | nbrodin | private void persistPreferences() { |
254 | if(defaultColor.getColor() != null) { |
||
255 | 23712 | vcaballero | Color color = defaultColor.getColor();
|
256 | 38442 | nbrodin | color = new Color(color.getRed(), |
257 | color.getGreen(), |
||
258 | color.getBlue(), |
||
259 | jsDefaultSelectionAlpha.getValue()); |
||
260 | getPreferences().setDefaultSymbolColor(color); |
||
261 | 23712 | vcaballero | } |
262 | |||
263 | 38442 | nbrodin | if(aleatoryFillColor != null) { |
264 | getPreferences().setDefaultSymbolFillColorAleatory(aleatoryFillColor.isSelected()); |
||
265 | 23712 | vcaballero | } |
266 | 38442 | nbrodin | |
267 | 23712 | vcaballero | if (defaultFillColor.getColor() != null) { |
268 | Color color = defaultFillColor.getColor();
|
||
269 | color = new Color(color.getRed(),color.getGreen(),color.getBlue(),jsFillSelelctionAlpha.getValue()); |
||
270 | 38442 | nbrodin | getPreferences().setDefaultSymbolFillColor(color); |
271 | 23712 | vcaballero | } |
272 | |||
273 | if (txtProjectsFolder.getText() != null) { |
||
274 | 38442 | nbrodin | getPreferences().setSymbolLibraryPath(txtProjectsFolder.getText()); |
275 | 23712 | vcaballero | } |
276 | |||
277 | if(fonts.getFont() != null && sizes.getSelectedItem() != null){ |
||
278 | 38442 | nbrodin | String f = (String)fonts.getSelectedItem(); |
279 | Font font = new Font(f, Font.PLAIN, (Integer)sizes.getSelectedItem()); |
||
280 | getPreferences().setDefaultSymbolFont(font); |
||
281 | 23712 | vcaballero | } |
282 | } |
||
283 | 18623 | jdominguez | } |