Statistics
| Revision:

root / branches / v10 / extensions / extAnnotations / src / com / iver / cit / gvsig / project / documents / view / legend / preferences / Annotation_Preferences.java @ 11743

History | View | Annotate | Download (8.82 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

    
42
package com.iver.cit.gvsig.project.documents.view.legend.preferences;
43

    
44
import java.awt.Color;
45
import java.awt.Font;
46
import java.awt.GridBagLayout;
47

    
48
import javax.swing.ImageIcon;
49
import javax.swing.JLabel;
50
import javax.swing.JPanel;
51
import javax.swing.JTextField;
52
import javax.swing.border.TitledBorder;
53

    
54
import com.iver.andami.PluginServices;
55
import com.iver.andami.preferences.AbstractPreferencePage;
56
import com.iver.andami.preferences.StoreException;
57
import com.iver.cit.gvsig.fmap.layers.Annotation_Mapping;
58
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
59
import com.iver.utiles.StringUtilities;
60
import com.iver.utiles.XMLEntity;
61
/**
62
 *  Default configuration page.
63
 *  <b><b>
64
 *  Here the user can establish what settings wants to use by default annotations.
65
 *
66
 *
67
 * @author Vicente Caballero Navarro
68
 */
69
public class Annotation_Preferences extends AbstractPreferencePage {
70
        public static String DEFAULT_ANNOTATION_TEXT = "default_annotation_text";
71

    
72
        public static String DEFAULT_ANNOTATION_TYPEFONT = "default_annotation_typefont";
73

    
74
        public static String DEFAULT_ANNOTATION_ROTATE = "default_annotation_rotate";
75

    
76
        public static String DEFAULT_ANNOTATION_STYLEFONT = "default_annotation_stylefont";
77

    
78
        public static String DEFAULT_ANNOTATION_HEIGHT = "default_annotation_height";
79

    
80
        public static String DEFAULT_ANNOTATION_COLOR = "default_annotation_color";
81

    
82
        protected String id;
83
        private ImageIcon icon;
84
        private JTextField txtDefaultText;
85
        private JTextField txtDefaultTypeFont;
86
        private JTextField txtDefaultStyleFont;
87
        private JTextField txtDefaultRotate;
88
        private JTextField txtDefaultHeight;
89
        private ColorChooserPanel jccDefaultColor;
90
//        private JSlider jsDefaultColorAlpha;
91
        private boolean panelStarted = false;
92

    
93
        /**
94
         * Creates a new panel containing View preferences settings.
95
         *
96
         */
97
        public Annotation_Preferences() {
98
                super();
99
                id = this.getClass().getName();
100
                icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/AnnotationProperties.png"));
101
        }
102

    
103
        public void initializeValues() {
104
                if (!panelStarted) getPanel();
105

    
106
                PluginServices ps = PluginServices.getPluginServices(this);
107
                XMLEntity xml = ps.getPersistentXML();
108

    
109
                if (xml.contains(DEFAULT_ANNOTATION_TEXT)) {
110
                        String text=xml.getStringProperty(DEFAULT_ANNOTATION_TEXT);
111
                        txtDefaultText.setText(text);
112
                        Annotation_Mapping.DEFAULTTEXT=text;
113
                }else{
114
                        txtDefaultText.setText("");
115
                        Annotation_Mapping.DEFAULTTEXT="";
116
                }
117
                if (xml.contains(DEFAULT_ANNOTATION_TYPEFONT)) {
118
                        String text=xml.getStringProperty(DEFAULT_ANNOTATION_TYPEFONT);
119
                        txtDefaultTypeFont.setText(text);
120
                        Annotation_Mapping.DEFAULTTYPEFONT=text;
121
                }else{
122
                        txtDefaultTypeFont.setText("Arial");
123
                        Annotation_Mapping.DEFAULTTYPEFONT="Arial";
124
                }
125
                if (xml.contains(DEFAULT_ANNOTATION_STYLEFONT)) {
126
                        int styleFont=xml.getIntProperty(DEFAULT_ANNOTATION_STYLEFONT);
127
                        txtDefaultStyleFont.setText(String.valueOf(styleFont));
128
                        Annotation_Mapping.DEFAULTSTYLEFONT=styleFont;
129
                }else{
130
                        txtDefaultStyleFont.setText(String.valueOf(Font.PLAIN));
131
                        Annotation_Mapping.DEFAULTSTYLEFONT=Font.PLAIN;
132
                }
133
                if (xml.contains(DEFAULT_ANNOTATION_COLOR)) {
134
                        String stringColor=xml.getStringProperty(DEFAULT_ANNOTATION_COLOR);
135
                        Color color=StringUtilities.string2Color(stringColor);
136
                        jccDefaultColor.setColor(color);
137
                        jccDefaultColor.setAlpha(color.getAlpha());
138
//                        jsDefaultColorAlpha.setValue(color.getAlpha());
139
                        Annotation_Mapping.DEFAULTCOLOR=color.getRGB();
140
                }else{
141
                        Color color=Color.black;
142
                        jccDefaultColor.setColor(color);
143
                        jccDefaultColor.setAlpha(color.getAlpha());
144
//                        jsDefaultColorAlpha.setValue(color.getAlpha());
145
                        Annotation_Mapping.DEFAULTCOLOR=color.getRGB();
146
                }
147
                if (xml.contains(DEFAULT_ANNOTATION_HEIGHT)) {
148
                        int height=xml.getIntProperty(DEFAULT_ANNOTATION_HEIGHT);
149
                        txtDefaultHeight.setText(String.valueOf(height));
150
                        Annotation_Mapping.DEFAULTHEIGHT=height;
151
                }else{
152
                        txtDefaultHeight.setText("10");
153
                        Annotation_Mapping.DEFAULTHEIGHT=10;
154
                }
155
                if (xml.contains(DEFAULT_ANNOTATION_ROTATE)) {
156
                        int rotate=xml.getIntProperty(DEFAULT_ANNOTATION_ROTATE);
157
                        txtDefaultRotate.setText(String.valueOf(rotate));
158
                        Annotation_Mapping.DEFAULTROTATE=rotate;
159
                }else{
160
                        txtDefaultRotate.setText("0");
161
                        Annotation_Mapping.DEFAULTROTATE=0;
162
                }
163
        }
164

    
165
        public String getID() {
166
                return id;
167
        }
168

    
169
        public String getTitle() {
170
                return PluginServices.getText(this, "annotation_preferences");
171
        }
172

    
173
        public JPanel getPanel() {
174
                if (panelStarted) return this;
175
                panelStarted = true;
176

    
177
                // just a separator
178
                addComponent(new JLabel(" "));
179

    
180
                addComponent(new JLabel(PluginServices.getText(this,"change_options_of_annotations")));
181

    
182
                JPanel optionsPanel = new JPanel();
183
                optionsPanel.setBorder(new TitledBorder(PluginServices.getText(this, "options.annotations")));
184
                optionsPanel.setLayout(new GridBagLayout());
185

    
186
                addComponent(new JLabel(PluginServices.getText(this,"text")),
187
                                txtDefaultText = new JTextField());
188

    
189
                addComponent(new JLabel(PluginServices.getText(this,"fonttype")),
190
                                txtDefaultTypeFont = new JTextField());
191

    
192
                addComponent(new JLabel(PluginServices.getText(this,"fontstyle")),
193
                                txtDefaultStyleFont = new JTextField());
194

    
195
                addComponent(new JLabel(PluginServices.getText(this,"fontheight")),
196
                                txtDefaultHeight = new JTextField());
197

    
198
                addComponent(new JLabel(PluginServices.getText(this,"fontrotate")),
199
                                txtDefaultRotate = new JTextField());
200

    
201
                addComponent(new JLabel(PluginServices.getText(this,"fontcolor")),
202
                                jccDefaultColor = new ColorChooserPanel());
203
//                                jsDefaultColorAlpha = new JSlider());
204

    
205
                //addComponent(optionsPanel);
206
                addComponent(new JLabel(" "));
207

    
208
                initializeValues();
209
                return this;
210
        }
211

    
212
        public void storeValues() throws StoreException {
213
                Color fontColor=jccDefaultColor.getColor();
214
                String text=txtDefaultText.getText();
215
                String fontType=txtDefaultTypeFont.getText();
216
                int fontStyle=Integer.parseInt(txtDefaultStyleFont.getText());
217
                int fontHeight=Integer.parseInt(txtDefaultHeight.getText());
218
                int fontRotate=Integer.parseInt(txtDefaultRotate.getText());
219

    
220
                PluginServices ps = PluginServices.getPluginServices(this);
221
                XMLEntity xml = ps.getPersistentXML();
222

    
223
                xml.putProperty(DEFAULT_ANNOTATION_COLOR,
224
                        StringUtilities.color2String(fontColor));
225
                xml.putProperty(DEFAULT_ANNOTATION_TEXT,
226
                        text);
227
                xml.putProperty(DEFAULT_ANNOTATION_TYPEFONT,
228
                        fontType);
229
                xml.putProperty(DEFAULT_ANNOTATION_STYLEFONT,
230
                                fontStyle);
231
                xml.putProperty(DEFAULT_ANNOTATION_HEIGHT,
232
                                fontHeight);
233
                xml.putProperty(DEFAULT_ANNOTATION_ROTATE,
234
                                fontRotate);
235
//
236
//                Annotation_Mapping.DEFAULTCOLOR=fontColor.getRGB();
237
//                Annotation_Mapping.DEFAULTTEXT=text;
238
//                Annotation_Mapping.DEFAULTTYPEFONT=fontType;
239
//                Annotation_Mapping.DEFAULTSTYLEFONT=fontStyle;
240
//                Annotation_Mapping.DEFAULTHEIGHT=fontHeight;
241
//                Annotation_Mapping.DEFAULTROTATE=fontRotate;
242
        }
243

    
244

    
245
        public void initializeDefaults() {
246
                Color fontColor=Color.black;
247
                String text="";
248
                String fontType="Arial";
249
                int fontStyle=Font.PLAIN;
250
                int fontHeight=10;
251
                int fontRotate=0;
252

    
253
                jccDefaultColor.setColor(fontColor);
254
//                jsDefaultColorAlpha.setValue(fontColor.getAlpha());
255

    
256
                txtDefaultText.setText(text);
257
                txtDefaultTypeFont.setText(fontType);
258
                txtDefaultStyleFont.setText(String.valueOf(fontStyle));
259
                txtDefaultHeight.setText(String.valueOf(fontHeight));
260
                txtDefaultRotate.setText(String.valueOf(fontRotate));
261

    
262
                Annotation_Mapping.DEFAULTCOLOR=fontColor.getRGB();
263
                Annotation_Mapping.DEFAULTTEXT=text;
264
                Annotation_Mapping.DEFAULTTYPEFONT=fontType;
265
                Annotation_Mapping.DEFAULTSTYLEFONT=fontStyle;
266
                Annotation_Mapping.DEFAULTHEIGHT=fontHeight;
267
                Annotation_Mapping.DEFAULTROTATE=fontRotate;
268
        }
269

    
270
        public ImageIcon getIcon() {
271
                return icon;
272
        }
273

    
274
        public boolean isValueChanged() {
275
                return super.hasChanged();
276
        }
277

    
278
        public void setChangesApplied() {
279
                setChanged(false);
280
        }
281
}