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 17491 bsanchez
/* 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 18014 bsanchez
import org.gvsig.raster.Configuration;
36 17491 bsanchez
import org.gvsig.raster.RasterLibrary;
37 22364 nbrodin
import org.gvsig.raster.util.BasePanel;
38 17491 bsanchez
39
import com.iver.andami.PluginServices;
40
/**
41 20274 bsanchez
 * PreferenceTemporal es una clase para la configuracion de los directorios
42
 * temporales de raster en gvSIG.
43
 *
44 17491 bsanchez
 * @version 12/12/2007
45
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
46
 */
47 22364 nbrodin
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 17491 bsanchez
53 22364 nbrodin
        /**
54
         *Inicializa componentes gr?ficos y traduce
55
         */
56 17491 bsanchez
        public PreferenceTemporal() {
57 22364 nbrodin
                init();
58 17491 bsanchez
                translate();
59
        }
60 22364 nbrodin
61
        /*
62
         * (non-Javadoc)
63
         * @see org.gvsig.raster.util.BasePanel#translate()
64 20274 bsanchez
         */
65 22364 nbrodin
        protected void translate() {
66
                setBorder(BorderFactory.createTitledBorder(getText(this, "rutas")));
67 17491 bsanchez
                getLabelTemporales().setText(getText(this, "temporales") + ":");
68
                getButtonOpen().setText(getText(this, "seleccionar_directorio"));
69
        }
70
71 22364 nbrodin
        /*
72
         * (non-Javadoc)
73
         * @see org.gvsig.raster.util.BasePanel#init()
74
         */
75
        protected void init() {
76 17491 bsanchez
                GridBagConstraints gridBagConstraints;
77
78 22364 nbrodin
                setLayout(new GridBagLayout());
79 17491 bsanchez
80
                gridBagConstraints = new GridBagConstraints();
81
                gridBagConstraints.insets = new Insets(5, 5, 5, 2);
82 22364 nbrodin
                add(getLabelTemporales(), gridBagConstraints);
83 17491 bsanchez
84
                gridBagConstraints = new GridBagConstraints();
85
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
86
                gridBagConstraints.weightx = 1.0;
87
                gridBagConstraints.insets = new Insets(5, 2, 5, 2);
88 22364 nbrodin
                add(getTextFieldDirectory(), gridBagConstraints);
89 17491 bsanchez
90
                gridBagConstraints = new GridBagConstraints();
91
                gridBagConstraints.insets = new Insets(5, 2, 5, 5);
92 22364 nbrodin
                add(getButtonOpen(), gridBagConstraints);
93 17491 bsanchez
        }
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 20274 bsanchez
        /**
120
         * Carga los valores por defecto del componente
121
         */
122 17491 bsanchez
        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 20274 bsanchez
        /**
130
         * Carga los valores establecidos por el usuario en el componente
131
         */
132 17491 bsanchez
        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 20274 bsanchez
        /**
140
         * Guarda los valores establecidos por el usuario
141
         */
142 17491 bsanchez
        public void storeValues() {
143
                Configuration.setValue("path_temp_cache_directory", getTextFieldDirectory().getText());
144
        }
145
146 20274 bsanchez
        /*
147
         * (non-Javadoc)
148
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
149
         */
150 17491 bsanchez
        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 22364 nbrodin
                if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
156 17491 bsanchez
                        getTextFieldDirectory().setText(chooser.getSelectedFile().getAbsolutePath());
157
158
                JFileChooser.setLastPath(this.getClass().getName(), new File(getTextFieldDirectory().getText()));
159
        }
160
}