svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.annotation.app / org.gvsig.annotation.app.mainplugin / src / main / java / org / gvsig / annotation / app / extension / AnnotationPreferencesPage.java @ 40561
History | View | Annotate | Download (6.37 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.annotation.app.extension; |
25 |
|
26 |
import java.awt.GridBagConstraints; |
27 |
import java.awt.Insets; |
28 |
|
29 |
import javax.swing.ImageIcon; |
30 |
import javax.swing.JLabel; |
31 |
import javax.swing.JPanel; |
32 |
import javax.swing.JTextField; |
33 |
|
34 |
import org.gvsig.andami.IconThemeHelper; |
35 |
import org.gvsig.andami.PluginServices; |
36 |
import org.gvsig.andami.preferences.AbstractPreferencePage; |
37 |
import org.gvsig.andami.preferences.StoreException; |
38 |
import org.gvsig.annotation.AnnotationLocator; |
39 |
import org.gvsig.annotation.AnnotationManager; |
40 |
import org.gvsig.annotation.swing.AnnotationSwingLocator; |
41 |
import org.gvsig.annotation.swing.JAnnotationPreferencesPanel; |
42 |
import org.gvsig.tools.dynobject.DynObject; |
43 |
/**
|
44 |
* Default configuration page.
|
45 |
* <b><b>
|
46 |
* Here the user can establish what settings wants to use by default annotations.
|
47 |
*
|
48 |
*
|
49 |
* @author Vicente Caballero Navarro
|
50 |
*/
|
51 |
public class AnnotationPreferencesPage extends AbstractPreferencePage { |
52 |
/**
|
53 |
*
|
54 |
*/
|
55 |
private static final long serialVersionUID = -472617080926223575L; |
56 |
protected String id; |
57 |
//private ImageIcon icon;
|
58 |
private JTextField txtDefaultText; |
59 |
// private JComboBox cmbDefaultTypeFont;
|
60 |
// private JComboBox cmbDefaultStyleFont;
|
61 |
// private JTextField txtDefaultRotate;
|
62 |
// private JTextField txtDefaultHeight;
|
63 |
// private ColorChooserPanel jccDefaultColor;
|
64 |
private JAnnotationPreferencesPanel panel = null; |
65 |
|
66 |
private AnnotationManager annotationManager = null; |
67 |
|
68 |
|
69 |
/**
|
70 |
* Creates a new panel containing View preferences settings.
|
71 |
*
|
72 |
*/
|
73 |
public AnnotationPreferencesPage() {
|
74 |
super();
|
75 |
id = this.getClass().getName();
|
76 |
this.annotationManager = AnnotationLocator.getManager();
|
77 |
} |
78 |
|
79 |
public void initializeValues() { |
80 |
getPanel(); // init UI
|
81 |
|
82 |
PluginServices ps = PluginServices.getPluginServices(this);
|
83 |
DynObject props = ps.getPluginProperties(); |
84 |
|
85 |
// first defaults, then stored if not null
|
86 |
initializeDefaults(); |
87 |
|
88 |
String str = null; |
89 |
Double dou = null; |
90 |
Integer col = null; |
91 |
|
92 |
str = (String) props.getDynValue(AnnotationExtension.PERSIST_DEF_TEXT_VALUE_KEY);
|
93 |
if (str != null) { |
94 |
txtDefaultText.setText(str); |
95 |
} |
96 |
str = (String) props.getDynValue(AnnotationExtension.PERSIST_DEF_FONT_TYPE_KEY);
|
97 |
if (str != null) { |
98 |
panel.setDefaultFontType(str); |
99 |
} |
100 |
str = (String) props.getDynValue(AnnotationExtension.PERSIST_DEF_FONT_STYLE_KEY);
|
101 |
if (str != null) { |
102 |
panel.setDefaultFontStyle(str); |
103 |
} |
104 |
dou = (Double) props.getDynValue(AnnotationExtension.PERSIST_DEF_FONT_HEIGHT_KEY);
|
105 |
if (dou != null) { |
106 |
panel.setDefaultFontHeight(dou); |
107 |
} |
108 |
dou = (Double) props.getDynValue(AnnotationExtension.PERSIST_DEF_FONT_ROTATION_KEY);
|
109 |
if (str != null) { |
110 |
panel.setDefaultFontRotation(dou); |
111 |
} |
112 |
col = (Integer) props.getDynValue(AnnotationExtension.PERSIST_DEF_FONT_COLOR_KEY);
|
113 |
if (str != null) { |
114 |
panel.setDefaultFontColor(col); |
115 |
} |
116 |
} |
117 |
|
118 |
public String getID() { |
119 |
return id;
|
120 |
} |
121 |
|
122 |
public String getTitle() { |
123 |
return PluginServices.getText(this, "annotation_preferences"); |
124 |
} |
125 |
|
126 |
public JPanel getPanel() { |
127 |
if (panel==null) { |
128 |
addComponent(new JLabel(PluginServices.getText(this,"text")), |
129 |
txtDefaultText = new JTextField(), GridBagConstraints.BOTH, new Insets(4,0,4,8)); |
130 |
panel = AnnotationSwingLocator.getSwingManager().createAnnotationPreferences(); |
131 |
addComponent(panel); |
132 |
} |
133 |
return this; |
134 |
} |
135 |
|
136 |
public void storeValues() throws StoreException { |
137 |
|
138 |
// Store in manager
|
139 |
annotationManager.setDefaultTextValue(txtDefaultText.getText()); |
140 |
annotationManager.setDefaultFontType(panel.getDefaultFontType()); |
141 |
annotationManager.setDefaultFontStyle(panel.getDefaultFontStyle()); |
142 |
annotationManager.setDefaultFontHeight(panel.getDefaultFontHeight()); |
143 |
annotationManager.setDefaultFontColor(panel.getDefaultFontColor()); |
144 |
annotationManager.setDefaultFontRotation(panel.getDefaultFontRotation()); |
145 |
|
146 |
// Persist
|
147 |
PluginServices ps = PluginServices.getPluginServices(this);
|
148 |
DynObject props = ps.getPluginProperties(); |
149 |
|
150 |
props.setDynValue(AnnotationExtension.PERSIST_DEF_FONT_COLOR_KEY, |
151 |
panel.getDefaultFontColor()); |
152 |
props.setDynValue(AnnotationExtension.PERSIST_DEF_TEXT_VALUE_KEY, |
153 |
txtDefaultText.getText()); |
154 |
props.setDynValue(AnnotationExtension.PERSIST_DEF_FONT_TYPE_KEY, |
155 |
panel.getDefaultFontType()); |
156 |
props.setDynValue(AnnotationExtension.PERSIST_DEF_FONT_STYLE_KEY, |
157 |
panel.getDefaultFontStyle()); |
158 |
props.setDynValue(AnnotationExtension.PERSIST_DEF_FONT_HEIGHT_KEY, |
159 |
panel.getDefaultFontHeight()); |
160 |
props.setDynValue(AnnotationExtension.PERSIST_DEF_FONT_ROTATION_KEY, |
161 |
panel.getDefaultFontRotation()); |
162 |
|
163 |
ps.savePluginProperties(); |
164 |
} |
165 |
|
166 |
|
167 |
public void initializeDefaults() { |
168 |
txtDefaultText.setText(annotationManager.getDefaultTextValue()); |
169 |
panel.setDefaultFontType(annotationManager.getDefaultFontType()); |
170 |
panel.setDefaultFontStyle(annotationManager.getDefaultFontStyle()); |
171 |
panel.setDefaultFontHeight(annotationManager.getDefaultFontHeight()); |
172 |
panel.setDefaultFontColor(annotationManager.getDefaultFontColor()); |
173 |
panel.setDefaultFontRotation(annotationManager.getDefaultFontRotation()); |
174 |
} |
175 |
|
176 |
public ImageIcon getIcon() { |
177 |
return IconThemeHelper.getImageIcon("annotation-preferences"); |
178 |
} |
179 |
|
180 |
public boolean isValueChanged() { |
181 |
return super.hasChanged(); |
182 |
} |
183 |
|
184 |
public void setChangesApplied() { |
185 |
setChanged(false);
|
186 |
} |
187 |
} |