Statistics
| Revision:

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 @ 42265

History | View | Annotate | Download (6.62 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.ToolsLocator;
43
import org.gvsig.tools.dynobject.DynObject;
44
import org.gvsig.tools.i18n.I18nManager;
45
/**
46
 *  Default configuration page.
47
 *  <b><b>
48
 *  Here the user can establish what settings wants to use by default annotations.
49
 *
50
 *
51
 * @author Vicente Caballero Navarro
52
 */
53
public class AnnotationPreferencesPage extends AbstractPreferencePage {
54
        /**
55
         * 
56
         */
57
        private static final long serialVersionUID = -472617080926223575L;
58
        protected String id;
59
        //private ImageIcon icon;
60
        private JTextField txtDefaultText;
61
//        private JComboBox cmbDefaultTypeFont;
62
//        private JComboBox cmbDefaultStyleFont;
63
//        private JTextField txtDefaultRotate;
64
//        private JTextField txtDefaultHeight;
65
//        private ColorChooserPanel jccDefaultColor;
66
        private JAnnotationPreferencesPanel panel = null;
67
        
68
        private AnnotationManager annotationManager = null;
69
        
70

    
71
        /**
72
         * Creates a new panel containing View preferences settings.
73
         *
74
         */
75
        public AnnotationPreferencesPage() {
76
                super();
77
                id = this.getClass().getName();
78
                this.annotationManager = AnnotationLocator.getManager();
79
        }
80

    
81
        public void initializeValues() {
82
                getPanel(); // init UI                
83

    
84
                PluginServices ps = PluginServices.getPluginServices(this);
85
                DynObject props = ps.getPluginProperties();
86
                
87
                // first defaults, then stored if not null
88
                initializeDefaults();
89
                
90
                String str = null;
91
                Double dou = null;
92
                Integer col = null;
93
                
94
                str = (String) props.getDynValue(AnnotationExtension.PERSIST_DEF_TEXT_VALUE_KEY);
95
                if (str != null) {
96
                    txtDefaultText.setText(str);
97
                }
98
                str = (String) props.getDynValue(AnnotationExtension.PERSIST_DEF_FONT_TYPE_KEY);
99
        if (str != null) {
100
            panel.setDefaultFontType(str);
101
        }
102
        str = (String) props.getDynValue(AnnotationExtension.PERSIST_DEF_FONT_STYLE_KEY);
103
        if (str != null) {
104
            panel.setDefaultFontStyle(str);
105
        }
106
        dou = (Double) props.getDynValue(AnnotationExtension.PERSIST_DEF_FONT_HEIGHT_KEY);
107
        if (dou != null) {
108
            panel.setDefaultFontHeight(dou);   
109
        }
110
        dou = (Double) props.getDynValue(AnnotationExtension.PERSIST_DEF_FONT_ROTATION_KEY);
111
        if (str != null) {
112
            panel.setDefaultFontRotation(dou);   
113
        }
114
        col = (Integer) props.getDynValue(AnnotationExtension.PERSIST_DEF_FONT_COLOR_KEY);
115
        if (str != null) {
116
            panel.setDefaultFontColor(col);
117
        }
118
        }
119

    
120
        public String getID() {
121
                return id;
122
        }
123

    
124
        public String getTitle() {
125
                return PluginServices.getText(this, "annotation_preferences");
126
        }
127

    
128
        public JPanel getPanel() {
129
                        if (panel==null) {
130
                            I18nManager i18nManager = ToolsLocator.getI18nManager();
131
                            JLabel lbl = new JLabel(PluginServices.getText(this,"text"));
132
                                addComponent(lbl,
133
                                                txtDefaultText = new JTextField(), GridBagConstraints.BOTH, new Insets(4,0,4,8));
134
                                lbl.setToolTipText(i18nManager.getTranslation("text_to_insert_when_non_value_at_field"));
135
                                panel = AnnotationSwingLocator.getSwingManager().createAnnotationPreferences();
136
                                addComponent(panel);
137
                        }
138
                        return this;
139
        }
140

    
141
        public void storeValues() throws StoreException {
142
            
143
            // Store in manager
144
            annotationManager.setDefaultTextValue(txtDefaultText.getText());
145
        annotationManager.setDefaultFontType(panel.getDefaultFontType());
146
        annotationManager.setDefaultFontStyle(panel.getDefaultFontStyle());
147
        annotationManager.setDefaultFontHeight(panel.getDefaultFontHeight());   
148
        annotationManager.setDefaultFontColor(panel.getDefaultFontColor());
149
        annotationManager.setDefaultFontRotation(panel.getDefaultFontRotation());
150
            
151
        // Persist
152
            PluginServices ps = PluginServices.getPluginServices(this);
153
            DynObject props = ps.getPluginProperties();
154
            
155
            props.setDynValue(AnnotationExtension.PERSIST_DEF_FONT_COLOR_KEY,
156
                panel.getDefaultFontColor());
157
        props.setDynValue(AnnotationExtension.PERSIST_DEF_TEXT_VALUE_KEY,
158
            txtDefaultText.getText());
159
        props.setDynValue(AnnotationExtension.PERSIST_DEF_FONT_TYPE_KEY,
160
            panel.getDefaultFontType());
161
        props.setDynValue(AnnotationExtension.PERSIST_DEF_FONT_STYLE_KEY,
162
            panel.getDefaultFontStyle());
163
        props.setDynValue(AnnotationExtension.PERSIST_DEF_FONT_HEIGHT_KEY,
164
            panel.getDefaultFontHeight());
165
        props.setDynValue(AnnotationExtension.PERSIST_DEF_FONT_ROTATION_KEY,
166
            panel.getDefaultFontRotation());
167
        
168
        ps.savePluginProperties();
169
        }
170

    
171

    
172
        public void initializeDefaults() {
173
                txtDefaultText.setText(annotationManager.getDefaultTextValue());
174
                panel.setDefaultFontType(annotationManager.getDefaultFontType());
175
                panel.setDefaultFontStyle(annotationManager.getDefaultFontStyle());
176
                panel.setDefaultFontHeight(annotationManager.getDefaultFontHeight());        
177
                panel.setDefaultFontColor(annotationManager.getDefaultFontColor());
178
                panel.setDefaultFontRotation(annotationManager.getDefaultFontRotation());                
179
        }
180

    
181
        public ImageIcon getIcon() {
182
                return IconThemeHelper.getImageIcon("annotation-preferences");
183
        }
184

    
185
        public boolean isValueChanged() {
186
                return super.hasChanged();
187
        }
188

    
189
        public void setChangesApplied() {
190
                setChanged(false);
191
        }
192
}