gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.app / org.gvsig.raster.app.common / src / main / java / org / gvsig / raster / mainplugin / beans / createlayer / SelectDirectoryPanel.java @ 2861
History | View | Annotate | Download (4.76 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
package org.gvsig.raster.mainplugin.beans.createlayer; |
23 |
|
24 |
import java.awt.Dimension; |
25 |
import java.awt.GridBagConstraints; |
26 |
import java.awt.GridBagLayout; |
27 |
import java.awt.Insets; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
import java.io.File; |
31 |
|
32 |
import javax.swing.JButton; |
33 |
import javax.swing.JLabel; |
34 |
import javax.swing.JPanel; |
35 |
import javax.swing.JTextField; |
36 |
|
37 |
import org.gvsig.andami.PluginServices; |
38 |
import org.gvsig.gui.beans.swing.JFileChooser; |
39 |
|
40 |
|
41 |
/**
|
42 |
* Panel para la selecci?n de directorios.
|
43 |
*
|
44 |
* 13/05/2008
|
45 |
* @author Nacho Brodin nachobrodin@gmail.com
|
46 |
*/
|
47 |
public class SelectDirectoryPanel extends JPanel implements ActionListener { |
48 |
private static final long serialVersionUID = 1L; |
49 |
private JTextField directoryTextField = null; |
50 |
private JLabel jLabelDirectory = null; |
51 |
private JButton jBChooseDirectory = null; |
52 |
private ActionListener listener = null; |
53 |
|
54 |
/**
|
55 |
* Constructor.
|
56 |
* Inicializa los componentes gr?ficos
|
57 |
*/
|
58 |
public SelectDirectoryPanel() {
|
59 |
init(); |
60 |
} |
61 |
|
62 |
/**
|
63 |
* This method initializes jPNameFile
|
64 |
* @return javax.swing.JPanel
|
65 |
*/
|
66 |
private void init() { |
67 |
GridBagConstraints gridBagConstraints = null; |
68 |
|
69 |
setLayout(new GridBagLayout()); |
70 |
|
71 |
gridBagConstraints = new GridBagConstraints(); |
72 |
gridBagConstraints.insets = new Insets(2, 5, 5, 2); |
73 |
add(getJLabelDirectory(), gridBagConstraints); |
74 |
|
75 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
76 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
77 |
gridBagConstraints.weightx = 1.0;
|
78 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 2); |
79 |
add(getDirectoryTextField(), gridBagConstraints); |
80 |
|
81 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
82 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 5); |
83 |
add(getJBChooseDirectory(), gridBagConstraints); |
84 |
|
85 |
getJBChooseDirectory().addActionListener(this);
|
86 |
} |
87 |
|
88 |
public void setListener(ActionListener listener) { |
89 |
this.listener = listener;
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* Obtiene el bot?n de asignaci?n de directorio
|
94 |
* @return JButton
|
95 |
*/
|
96 |
public JButton getJBChooseDirectory() { |
97 |
if (jBChooseDirectory == null) { |
98 |
jBChooseDirectory = new JButton(PluginServices.getText(this, "cambiar_ruta")); |
99 |
jBChooseDirectory.setEnabled(false);
|
100 |
} |
101 |
return jBChooseDirectory;
|
102 |
} |
103 |
|
104 |
/**
|
105 |
* Obtiene la etiqueta con la ruta
|
106 |
* @return JLabel
|
107 |
*/
|
108 |
public JLabel getJLabelDirectory() { |
109 |
if (jLabelDirectory == null) { |
110 |
jLabelDirectory = new JLabel(PluginServices.getText(this, "ruta") + ":"); |
111 |
jLabelDirectory.setEnabled(false);
|
112 |
} |
113 |
return jLabelDirectory;
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* Obtiene el campo de texto con la ruta de directorio
|
118 |
* @return JTextField
|
119 |
*/
|
120 |
public JTextField getDirectoryTextField() { |
121 |
if (directoryTextField == null) { |
122 |
directoryTextField = new JTextField(); |
123 |
directoryTextField.setText(JFileChooser.getLastPath(this.getClass().getName(), (File) null).toString()); |
124 |
directoryTextField.setEditable(false);
|
125 |
directoryTextField.setEnabled(false);
|
126 |
directoryTextField.setPreferredSize(new Dimension(200, directoryTextField.getPreferredSize().height)); |
127 |
} |
128 |
return directoryTextField;
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* Accion que sucede cuando se pulsa el boton de cambiar directorio
|
133 |
*/
|
134 |
public void actionPerformed(ActionEvent e) { |
135 |
JFileChooser chooser = new JFileChooser(this.getClass().getName(), new File(getDirectoryTextField().getText())); |
136 |
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
137 |
chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_directorio")); |
138 |
|
139 |
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) |
140 |
getDirectoryTextField().setText(chooser.getSelectedFile().toString()); |
141 |
else
|
142 |
chooser.setLastPath(new File(getDirectoryTextField().getText())); |
143 |
|
144 |
if(listener != null) |
145 |
listener.actionPerformed(new ActionEvent(this, 0, getPath())); |
146 |
} |
147 |
|
148 |
/**
|
149 |
* Obtiene la ruta al directorio.
|
150 |
* @return String
|
151 |
*/
|
152 |
public String getPath() { |
153 |
return getDirectoryTextField().getText();
|
154 |
} |
155 |
} |