Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extAnnotations / src / com / iver / cit / gvsig / project / documents / view / legend / preferences / Annotation_Preferences.java @ 12131

History | View | Annotate | Download (9.42 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.cit.gvsig.project.documents.view.gui.FontOptions;
60
import com.iver.utiles.StringUtilities;
61
import com.iver.utiles.XMLEntity;
62
import com.iver.utiles.swing.JComboBox;
63
/**
64
 *  Default configuration page.
65
 *  <b><b>
66
 *  Here the user can establish what settings wants to use by default annotations.
67
 *
68
 *
69
 * @author Vicente Caballero Navarro
70
 */
71
public class Annotation_Preferences extends AbstractPreferencePage {
72
        public static String DEFAULT_ANNOTATION_TEXT = "default_annotation_text";
73

    
74
        public static String DEFAULT_ANNOTATION_TYPEFONT = "default_annotation_typefont";
75

    
76
        public static String DEFAULT_ANNOTATION_ROTATE = "default_annotation_rotate";
77

    
78
        public static String DEFAULT_ANNOTATION_STYLEFONT = "default_annotation_stylefont";
79

    
80
        public static String DEFAULT_ANNOTATION_HEIGHT = "default_annotation_height";
81

    
82
        public static String DEFAULT_ANNOTATION_COLOR = "default_annotation_color";
83

    
84
        protected String id;
85
        private ImageIcon icon;
86
        private JTextField txtDefaultText;
87
        private JComboBox cmbDefaultTypeFont;
88
        private JComboBox cmbDefaultStyleFont;
89
        private JTextField txtDefaultRotate;
90
        private JTextField txtDefaultHeight;
91
        private ColorChooserPanel jccDefaultColor;
92
//        private JSlider jsDefaultColorAlpha;
93
        private boolean panelStarted = false;
94

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

    
105
        public void initializeValues() {
106
                if (!panelStarted) getPanel();
107

    
108
                PluginServices ps = PluginServices.getPluginServices(this);
109
                XMLEntity xml = ps.getPersistentXML();
110

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

    
170
        public String getID() {
171
                return id;
172
        }
173

    
174
        public String getTitle() {
175
                return PluginServices.getText(this, "annotation_preferences");
176
        }
177

    
178
        public JPanel getPanel() {
179
                if (panelStarted) return this;
180
                panelStarted = true;
181

    
182
                // just a separator
183
                addComponent(new JLabel(" "));
184

    
185
                addComponent(new JLabel(PluginServices.getText(this,"change_options_of_annotations")));
186

    
187
                JPanel optionsPanel = new JPanel();
188
                optionsPanel.setBorder(new TitledBorder(PluginServices.getText(this, "options.annotations")));
189
                optionsPanel.setLayout(new GridBagLayout());
190

    
191
                addComponent(new JLabel(PluginServices.getText(this,"text")),
192
                                txtDefaultText = new JTextField());
193

    
194
                addComponent(new JLabel(PluginServices.getText(this,"fonttype")),
195
                                cmbDefaultTypeFont = new JComboBox());
196
                String[] types=FontOptions.getFontTypes();
197
                for (int i=0;i<types.length;i++){
198
                        cmbDefaultTypeFont.addItem(types[i]);
199
                }
200
                cmbDefaultTypeFont.setSelectedItem(FontOptions.ARIAL);
201
                addComponent(new JLabel(PluginServices.getText(this,"fontstyle")),
202
                                cmbDefaultStyleFont = new JComboBox());
203
                String[] styles=FontOptions.getFontStyles();
204
                for (int i=0;i<styles.length;i++){
205
                        cmbDefaultStyleFont.addItem(styles[i]);
206
                }
207
                cmbDefaultStyleFont.setSelectedItem(FontOptions.PLAIN);
208
                addComponent(new JLabel(PluginServices.getText(this,"fontheight")),
209
                                txtDefaultHeight = new JTextField());
210

    
211
                addComponent(new JLabel(PluginServices.getText(this,"fontrotate")),
212
                                txtDefaultRotate = new JTextField());
213

    
214
                addComponent(new JLabel(PluginServices.getText(this,"fontcolor")),
215
                                jccDefaultColor = new ColorChooserPanel());
216
//                                jsDefaultColorAlpha = new JSlider());
217

    
218
                //addComponent(optionsPanel);
219
                addComponent(new JLabel(" "));
220

    
221
                initializeValues();
222
                return this;
223
        }
224

    
225
        public void storeValues() throws StoreException {
226
                Color fontColor=jccDefaultColor.getColor();
227
                String text=txtDefaultText.getText();
228
                String fontType=(String)cmbDefaultTypeFont.getSelectedItem();
229
                int fontStyle=cmbDefaultStyleFont.getSelectedIndex();
230
                int fontHeight=Integer.parseInt(txtDefaultHeight.getText());
231
                int fontRotate=Integer.parseInt(txtDefaultRotate.getText());
232

    
233
                PluginServices ps = PluginServices.getPluginServices(this);
234
                XMLEntity xml = ps.getPersistentXML();
235

    
236
                xml.putProperty(DEFAULT_ANNOTATION_COLOR,
237
                        StringUtilities.color2String(fontColor));
238
                xml.putProperty(DEFAULT_ANNOTATION_TEXT,
239
                        text);
240
                xml.putProperty(DEFAULT_ANNOTATION_TYPEFONT,
241
                        fontType);
242
                xml.putProperty(DEFAULT_ANNOTATION_STYLEFONT,
243
                                fontStyle);
244
                xml.putProperty(DEFAULT_ANNOTATION_HEIGHT,
245
                                fontHeight);
246
                xml.putProperty(DEFAULT_ANNOTATION_ROTATE,
247
                                fontRotate);
248
//
249
//                Annotation_Mapping.DEFAULTCOLOR=fontColor.getRGB();
250
//                Annotation_Mapping.DEFAULTTEXT=text;
251
//                Annotation_Mapping.DEFAULTTYPEFONT=fontType;
252
//                Annotation_Mapping.DEFAULTSTYLEFONT=fontStyle;
253
//                Annotation_Mapping.DEFAULTHEIGHT=fontHeight;
254
//                Annotation_Mapping.DEFAULTROTATE=fontRotate;
255
        }
256

    
257

    
258
        public void initializeDefaults() {
259
                Color fontColor=Color.black;
260
                String text="";
261
                String fontType=FontOptions.ARIAL;
262
                int fontStyle=Font.PLAIN;
263
                int fontHeight=10;
264
                int fontRotate=0;
265

    
266
                jccDefaultColor.setColor(fontColor);
267
//                jsDefaultColorAlpha.setValue(fontColor.getAlpha());
268

    
269
                txtDefaultText.setText(text);
270
                cmbDefaultTypeFont.setSelectedItem(fontType);
271
                cmbDefaultStyleFont.setSelectedItem(FontOptions.PLAIN);
272
                txtDefaultHeight.setText(String.valueOf(fontHeight));
273
                txtDefaultRotate.setText(String.valueOf(fontRotate));
274

    
275
                Annotation_Mapping.DEFAULTCOLOR=fontColor.getRGB();
276
                Annotation_Mapping.DEFAULTTEXT=text;
277
                Annotation_Mapping.DEFAULTTYPEFONT=fontType;
278
                Annotation_Mapping.DEFAULTSTYLEFONT=fontStyle;
279
                Annotation_Mapping.DEFAULTHEIGHT=fontHeight;
280
                Annotation_Mapping.DEFAULTROTATE=fontRotate;
281
        }
282

    
283
        public ImageIcon getIcon() {
284
                return icon;
285
        }
286

    
287
        public boolean isValueChanged() {
288
                return super.hasChanged();
289
        }
290

    
291
        public void setChangesApplied() {
292
                setChanged(false);
293
        }
294
}