Statistics
| Revision:

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

History | View | Annotate | Download (6.48 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.swing.JComboBox;
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

    
71

    
72
        protected String id;
73
        private ImageIcon icon;
74
        private JTextField txtDefaultText;
75
        private JComboBox cmbDefaultTypeFont;
76
        private JComboBox cmbDefaultStyleFont;
77
        private JTextField txtDefaultRotate;
78
        private JTextField txtDefaultHeight;
79
        private ColorChooserPanel jccDefaultColor;
80
//        private JSlider jsDefaultColorAlpha;
81
        private static boolean panelStarted = false;
82

    
83
        /**
84
         * Creates a new panel containing View preferences settings.
85
         *
86
         */
87
        public Annotation_Preferences() {
88
                super();
89
                id = this.getClass().getName();
90
                icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/AnnotationProperties.png"));
91
        }
92

    
93
        public void initializeValues() {
94
                if (!panelStarted) getPanel();
95

    
96
                txtDefaultText.setText(Annotation_Mapping.DEFAULTTEXT);
97
                cmbDefaultTypeFont.setSelectedItem(Annotation_Mapping.DEFAULTTYPEFONT);
98
                String style=FontOptions.getFontStyles()[Annotation_Mapping.DEFAULTSTYLEFONT];
99
                cmbDefaultStyleFont.setSelectedItem(style);
100
                Color color=new Color(Annotation_Mapping.DEFAULTCOLOR);
101
                jccDefaultColor.setColor(color);
102
                jccDefaultColor.setAlpha(color.getAlpha());
103
                txtDefaultHeight.setText(String.valueOf(Annotation_Mapping.DEFAULTHEIGHT));
104
                txtDefaultRotate.setText(String.valueOf(Annotation_Mapping.DEFAULTROTATE));
105
        }
106

    
107
        public String getID() {
108
                return id;
109
        }
110

    
111
        public String getTitle() {
112
                return PluginServices.getText(this, "annotation_preferences");
113
        }
114

    
115
        public JPanel getPanel() {
116
                if (panelStarted) return this;
117
                panelStarted = true;
118

    
119
                // just a separator
120
                addComponent(new JLabel(" "));
121

    
122
                addComponent(new JLabel(PluginServices.getText(this,"change_options_of_annotations")));
123

    
124
                JPanel optionsPanel = new JPanel();
125
                optionsPanel.setBorder(new TitledBorder(PluginServices.getText(this, "options.annotations")));
126
                optionsPanel.setLayout(new GridBagLayout());
127

    
128
                addComponent(new JLabel(PluginServices.getText(this,"text")),
129
                                txtDefaultText = new JTextField());
130

    
131
                addComponent(new JLabel(PluginServices.getText(this,"fonttype")),
132
                                cmbDefaultTypeFont = new JComboBox());
133
                String[] types=FontOptions.getFontTypes();
134
                for (int i=0;i<types.length;i++){
135
                        cmbDefaultTypeFont.addItem(types[i]);
136
                }
137
                cmbDefaultTypeFont.setSelectedItem(FontOptions.ARIAL);
138
                addComponent(new JLabel(PluginServices.getText(this,"fontstyle")),
139
                                cmbDefaultStyleFont = new JComboBox());
140
                String[] styles=FontOptions.getFontStyles();
141
                for (int i=0;i<styles.length;i++){
142
                        cmbDefaultStyleFont.addItem(styles[i]);
143
                }
144
                cmbDefaultStyleFont.setSelectedItem(FontOptions.PLAIN);
145
                addComponent(new JLabel(PluginServices.getText(this,"fontheight")),
146
                                txtDefaultHeight = new JTextField());
147

    
148
                addComponent(new JLabel(PluginServices.getText(this,"fontrotate")),
149
                                txtDefaultRotate = new JTextField());
150

    
151
                addComponent(new JLabel(PluginServices.getText(this,"fontcolor")),
152
                                jccDefaultColor = new ColorChooserPanel());
153
//                                jsDefaultColorAlpha = new JSlider());
154

    
155
                //addComponent(optionsPanel);
156
                addComponent(new JLabel(" "));
157

    
158
                initializeValues();
159
                return this;
160
        }
161

    
162
        public void storeValues() throws StoreException {
163
                Color fontColor=jccDefaultColor.getColor();
164
                String text=txtDefaultText.getText();
165
                String fontType=(String)cmbDefaultTypeFont.getSelectedItem();
166
                int fontStyle=cmbDefaultStyleFont.getSelectedIndex();
167
                int fontHeight=Integer.parseInt(txtDefaultHeight.getText());
168
                int fontRotate=Integer.parseInt(txtDefaultRotate.getText());
169

    
170
                Annotation_Mapping.storeValues(fontColor,text,fontType,fontStyle,fontHeight,fontRotate);
171
        }
172

    
173

    
174
        public void initializeDefaults() {
175
                Color fontColor=Color.black;
176
                String text="";
177
                String fontType=FontOptions.ARIAL;
178
                int fontStyle=Font.PLAIN;
179
                int fontHeight=10;
180
                int fontRotate=0;
181

    
182
                jccDefaultColor.setColor(fontColor);
183
//                jsDefaultColorAlpha.setValue(fontColor.getAlpha());
184

    
185
                txtDefaultText.setText(text);
186
                cmbDefaultTypeFont.setSelectedItem(fontType);
187
                cmbDefaultStyleFont.setSelectedItem(FontOptions.PLAIN);
188
                txtDefaultHeight.setText(String.valueOf(fontHeight));
189
                txtDefaultRotate.setText(String.valueOf(fontRotate));
190

    
191
                Annotation_Mapping.DEFAULTCOLOR=fontColor.getRGB();
192
                Annotation_Mapping.DEFAULTTEXT=text;
193
                Annotation_Mapping.DEFAULTTYPEFONT=fontType;
194
                Annotation_Mapping.DEFAULTSTYLEFONT=fontStyle;
195
                Annotation_Mapping.DEFAULTHEIGHT=fontHeight;
196
                Annotation_Mapping.DEFAULTROTATE=fontRotate;
197
        }
198

    
199
        public ImageIcon getIcon() {
200
                return icon;
201
        }
202

    
203
        public boolean isValueChanged() {
204
                return super.hasChanged();
205
        }
206

    
207
        public void setChangesApplied() {
208
                setChanged(false);
209
        }
210
}