Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / preferencespage / DbfDefaultEncodingPage.java @ 31219

History | View | Annotate | Download (5.39 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2008 Software Colaborativo.
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
 */
32

    
33
/* CVS MESSAGES:
34
*
35
*/
36
package com.iver.cit.gvsig.gui.preferencespage;
37

    
38
import java.nio.charset.Charset;
39
import java.nio.charset.UnsupportedCharsetException;
40
import java.util.prefs.Preferences;
41

    
42
import javax.swing.ImageIcon;
43
import javax.swing.JOptionPane;
44
import javax.swing.JPanel;
45
import javax.swing.JTextArea;
46
import javax.swing.JTextField;
47

    
48
import org.apache.log4j.Logger;
49

    
50
import com.iver.andami.PluginServices;
51
import com.iver.andami.preferences.AbstractPreferencePage;
52
import com.iver.andami.preferences.StoreException;
53
import com.iver.cit.gvsig.fmap.drivers.dbf.DbaseFile;
54
import com.iver.cit.gvsig.fmap.drivers.dbf.DbfEncodings;
55
import com.iver.cit.gvsig.fmap.drivers.shp.DbaseFileNIO;
56
import com.iver.utiles.swing.JComboBox;
57

    
58
/**
59
 * @author Fjp
60
 * TODO: To be developed in future releases.
61
 *
62
 */
63
public class DbfDefaultEncodingPage extends AbstractPreferencePage {
64
        private static Preferences prefs = Preferences.userRoot().node( "gvSIG.encoding.dbf" );
65
        private JTextArea jTextArea = null;
66
        private JComboBox cmbDefaultDbfCharset;
67
        private DbfEncodings dbfEncodings = DbfEncodings.getInstance();
68
        private ImageIcon icon;
69

    
70
        public DbfDefaultEncodingPage() {
71
                super();
72
                icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/icu_logo_encoding.gif"));
73
                addComponent(getJTextArea());
74
                int[] ids=dbfEncodings.getSupportedDbfLanguageIDs();
75
                String[] encodings=new String[ids.length-1];
76
                for (int i=1;i<encodings.length;i++){
77
                        encodings[i]=dbfEncodings.getCharsetForDbfId(ids[i]);
78
                }
79

    
80
                addComponent(PluginServices.getText(this, "dbf_default_encoding") + ":",
81
                        cmbDefaultDbfCharset = new JComboBox(encodings));
82
        }
83

    
84
        public void initializeValues() {
85
                if (prefs.get("dbf_encoding", null) != null) {
86
                        String charsetName=prefs.get("dbf_encoding", DbaseFile.getDefaultCharset().toString());
87
                        Charset newDefaultCharset=null;
88
                        try{
89
                                newDefaultCharset = Charset.forName(charsetName);
90
                        }catch (UnsupportedCharsetException e) {
91
                                JOptionPane.showMessageDialog(null, "Unsupported CharSet for the System");
92
                                Logger.getLogger(this.getClass()).warn(e.getLocalizedMessage(), e);
93
                                newDefaultCharset = Charset.defaultCharset();
94
                        }
95
        //                Charset newDefaultCharset = Charset.forName(charsetName);
96
                        cmbDefaultDbfCharset.setSelectedItem(charsetName);
97
                        DbaseFile.setDefaultCharset(newDefaultCharset);
98
                        DbaseFileNIO.setDefaultCharset(newDefaultCharset);
99
                }
100
        }
101

    
102
        public String getID() {
103
                return this.getClass().getName();
104
        }
105

    
106
        public String getTitle() {
107
                return PluginServices.getText(this, "dbf_default_encoding");
108
        }
109

    
110
        public JPanel getPanel() {
111
                return this;
112
        }
113

    
114
        /* (non-Javadoc)
115
         * @see com.iver.andami.preferences.AbstractPreferencePage#storeValues()
116
         */
117
        public void storeValues() throws StoreException {
118
                String charsetName = (String)cmbDefaultDbfCharset.getSelectedItem();
119
                if (Charset.isSupported(charsetName))
120
                {
121
                        prefs.put("dbf_encoding", charsetName);
122
                        Charset newDefaultCharset = Charset.forName(charsetName);
123
                        DbaseFile.setDefaultCharset(newDefaultCharset);
124
                        DbaseFileNIO.setDefaultCharset(newDefaultCharset);
125
                }
126
                else
127
                {
128
                        if (cmbDefaultDbfCharset.getSelectedIndex() == 0) {
129
                                prefs.remove("dbf_encoding");
130
                                DbaseFile.setDefaultCharset(null);
131
                                DbaseFileNIO.setDefaultCharset(null);
132
                        }
133
                        else
134
                                throw new StoreException("Bad charsetName");
135
                }
136

    
137

    
138
                // ?Guardar en alguna clase el charset?
139
        }
140

    
141
        public void initializeDefaults() {
142
                cmbDefaultDbfCharset.setSelectedItem(dbfEncodings.getCharsetForDbfId(0));
143
        }
144

    
145
        public ImageIcon getIcon() {
146
                return icon;
147
        }
148
        /**
149
         * This method initializes jTextArea
150
         *
151
         * @return javax.swing.JTextArea
152
         */
153
        private JTextArea getJTextArea() {
154
                if (jTextArea == null) {
155
                        jTextArea = new JTextArea();
156
                        jTextArea.setBounds(new java.awt.Rectangle(13,7,285,57));
157
                        jTextArea.setForeground(java.awt.Color.black);
158
                        jTextArea.setBackground(java.awt.SystemColor.control);
159
                        jTextArea.setRows(3);
160
                        jTextArea.setWrapStyleWord(true);
161
                        jTextArea.setLineWrap(true);
162
                        jTextArea.setEditable(false);
163
                        jTextArea.setText(PluginServices.getText(this,"default_charset_name_for_dbf"));
164
                }
165
                return jTextArea;
166
        }
167

    
168
        public boolean isValueChanged() {
169
                return super.hasChanged();
170
        }
171

    
172
        public void setChangesApplied() {
173
                setChanged(false);
174
        }
175
}