Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / gui / preferences / panels / PreferenceTemporal.java @ 22364

History | View | Annotate | Download (5.24 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
package org.gvsig.raster.gui.preferences.panels;
20

    
21
import java.awt.Dimension;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.Insets;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27
import java.io.File;
28

    
29
import javax.swing.BorderFactory;
30
import javax.swing.JButton;
31
import javax.swing.JLabel;
32
import javax.swing.JTextField;
33

    
34
import org.gvsig.gui.beans.swing.JFileChooser;
35
import org.gvsig.raster.Configuration;
36
import org.gvsig.raster.RasterLibrary;
37
import org.gvsig.raster.util.BasePanel;
38

    
39
import com.iver.andami.PluginServices;
40
/**
41
 * PreferenceTemporal es una clase para la configuracion de los directorios
42
 * temporales de raster en gvSIG.
43
 * 
44
 * @version 12/12/2007
45
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
46
 */
47
public class PreferenceTemporal extends BasePanel implements ActionListener {
48
        private static final long serialVersionUID   = 1L;
49
        private JLabel            labelTemporales    = null;
50
        private JButton           buttonOpen         = null;
51
        private JTextField        textFieldDirectory = null;
52

    
53
        /**
54
         *Inicializa componentes gr?ficos y traduce
55
         */
56
        public PreferenceTemporal() {
57
                init();
58
                translate();
59
        }
60
        
61
        /*
62
         * (non-Javadoc)
63
         * @see org.gvsig.raster.util.BasePanel#translate()
64
         */
65
        protected void translate() {
66
                setBorder(BorderFactory.createTitledBorder(getText(this, "rutas")));
67
                getLabelTemporales().setText(getText(this, "temporales") + ":");
68
                getButtonOpen().setText(getText(this, "seleccionar_directorio"));
69
        }
70

    
71
        /*
72
         * (non-Javadoc)
73
         * @see org.gvsig.raster.util.BasePanel#init()
74
         */
75
        protected void init() {
76
                GridBagConstraints gridBagConstraints;
77

    
78
                setLayout(new GridBagLayout());
79

    
80
                gridBagConstraints = new GridBagConstraints();
81
                gridBagConstraints.insets = new Insets(5, 5, 5, 2);
82
                add(getLabelTemporales(), gridBagConstraints);
83

    
84
                gridBagConstraints = new GridBagConstraints();
85
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
86
                gridBagConstraints.weightx = 1.0;
87
                gridBagConstraints.insets = new Insets(5, 2, 5, 2);
88
                add(getTextFieldDirectory(), gridBagConstraints);
89

    
90
                gridBagConstraints = new GridBagConstraints();
91
                gridBagConstraints.insets = new Insets(5, 2, 5, 5);
92
                add(getButtonOpen(), gridBagConstraints);
93
        }
94

    
95
        private JLabel getLabelTemporales() {
96
                if (labelTemporales == null) {
97
                        labelTemporales = new JLabel();
98
                }
99
                return labelTemporales;
100
        }
101

    
102
        private JButton getButtonOpen() {
103
                if (buttonOpen == null) {
104
                        buttonOpen = new JButton();
105
                        buttonOpen.addActionListener(this);
106
                }
107
                return buttonOpen;
108
        }
109

    
110
        private JTextField getTextFieldDirectory() {
111
                if (textFieldDirectory == null) {
112
                        textFieldDirectory = new JTextField();
113
                        textFieldDirectory.setEditable(false);
114
                        textFieldDirectory.setPreferredSize(new Dimension(0, textFieldDirectory.getPreferredSize().height));
115
                }
116
                return textFieldDirectory;
117
        }
118

    
119
        /**
120
         * Carga los valores por defecto del componente
121
         */
122
        public void initializeDefaults() {
123
                File file = new File((String) Configuration.getDefaultValue("path_temp_cache_directory"));
124
                if (!file.exists())
125
                        file.mkdir();
126
                getTextFieldDirectory().setText(file.getAbsolutePath());
127
        }
128

    
129
        /**
130
         * Carga los valores establecidos por el usuario en el componente
131
         */
132
        public void initializeValues() {
133
                File file = new File(Configuration.getValue("path_temp_cache_directory", RasterLibrary.tempCacheDirectoryPath));
134
                if (!file.exists())
135
                        file.mkdir();
136
                getTextFieldDirectory().setText(file.getAbsolutePath());
137
        }
138

    
139
        /**
140
         * Guarda los valores establecidos por el usuario
141
         */
142
        public void storeValues() {
143
                Configuration.setValue("path_temp_cache_directory", getTextFieldDirectory().getText());
144
        }
145

    
146
        /*
147
         * (non-Javadoc)
148
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
149
         */
150
        public void actionPerformed(ActionEvent e) {
151
                JFileChooser chooser = new JFileChooser(this.getClass().getName(), new File(getTextFieldDirectory().getText()));
152
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
153
                chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_directorio"));
154

    
155
                if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
156
                        getTextFieldDirectory().setText(chooser.getSelectedFile().getAbsolutePath());
157

    
158
                JFileChooser.setLastPath(this.getClass().getName(), new File(getTextFieldDirectory().getText()));
159
        }
160
}