Revision 1241
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/java/org/gvsig/raster/swing/impl/openfile/OpenFileContainerImpl.java | ||
---|---|---|
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.swing.impl.openfile; |
|
23 |
|
|
24 |
import java.awt.Dimension; |
|
25 |
import java.awt.GridBagConstraints; |
|
26 |
import java.awt.GridBagLayout; |
|
27 |
import java.io.File; |
|
28 |
import java.util.List; |
|
29 |
|
|
30 |
import javax.swing.ImageIcon; |
|
31 |
import javax.swing.JButton; |
|
32 |
import javax.swing.JPanel; |
|
33 |
import javax.swing.JTextField; |
|
34 |
|
|
35 |
import org.gvsig.andami.IconThemeHelper; |
|
36 |
import org.gvsig.gui.beans.Messages; |
|
37 |
import org.gvsig.raster.swing.openfile.OpenFileContainer; |
|
38 |
|
|
39 |
/** |
|
40 |
* Implementation of a open file panel |
|
41 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
42 |
*/ |
|
43 |
public class OpenFileContainerImpl extends JPanel implements OpenFileContainer { |
|
44 |
private static final long serialVersionUID = 5823371652872582451L; |
|
45 |
|
|
46 |
private JButton jButton = null; |
|
47 |
private JTextField tOpen = null; |
|
48 |
private OpenFileListener listener = null; |
|
49 |
private boolean showBorder = true; |
|
50 |
|
|
51 |
private boolean isButtonVisible = true; |
|
52 |
|
|
53 |
public OpenFileContainerImpl(boolean showBorder, String[] fileFilter) { |
|
54 |
this.showBorder = showBorder; |
|
55 |
listener = new OpenFileListener(this, fileFilter); |
|
56 |
initialize(); |
|
57 |
listener.setButton(this.getJButton()); |
|
58 |
} |
|
59 |
|
|
60 |
public OpenFileContainerImpl(boolean showBorder, List<String> fileFilter) { |
|
61 |
this(showBorder, (String[])fileFilter.toArray(new String[0])); |
|
62 |
listener.setButton(this.getJButton()); |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* This method initializes this |
|
67 |
* |
|
68 |
*/ |
|
69 |
private void initialize() { |
|
70 |
this.setLayout(new GridBagLayout()); |
|
71 |
if(showBorder) |
|
72 |
this.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Messages.getText("open_file"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
|
73 |
|
|
74 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
75 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
|
76 |
gridBagConstraints1.weightx = 1; |
|
77 |
gridBagConstraints1.insets = new java.awt.Insets(0, 2, 0, 0); |
|
78 |
|
|
79 |
this.add(getTOpen(), gridBagConstraints1); |
|
80 |
|
|
81 |
gridBagConstraints1.gridx = 1; |
|
82 |
gridBagConstraints1.weightx = 0; |
|
83 |
|
|
84 |
this.add(getJButton(), gridBagConstraints1); |
|
85 |
|
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* This method initializes jButton |
|
90 |
* |
|
91 |
* @return javax.swing.JButton |
|
92 |
*/ |
|
93 |
private JButton getJButton() { |
|
94 |
if (jButton == null) { |
|
95 |
ImageIcon icon = null; |
|
96 |
try { |
|
97 |
icon = IconThemeHelper.getImageIcon("icon-folder-open"); |
|
98 |
} catch (Exception e) { |
|
99 |
} |
|
100 |
if(icon == null) |
|
101 |
icon = new ImageIcon(System.getProperty("user.dir") + "/src/main/resources/images/icon-folder-open.gif", ""); |
|
102 |
|
|
103 |
jButton = new JButton(icon); |
|
104 |
jButton.setPreferredSize(new Dimension(22, 22)); |
|
105 |
jButton.addActionListener(listener); |
|
106 |
jButton.setVisible(isButtonVisible); |
|
107 |
getTOpen().setEnabled(isButtonVisible); |
|
108 |
} |
|
109 |
return jButton; |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* This method initializes jTextField |
|
114 |
* |
|
115 |
* @return javax.swing.JTextField |
|
116 |
*/ |
|
117 |
public JTextField getTOpen() { |
|
118 |
if (tOpen == null) { |
|
119 |
tOpen = new JTextField(); |
|
120 |
tOpen.setPreferredSize(new Dimension(0, 22)); |
|
121 |
} |
|
122 |
return tOpen; |
|
123 |
} |
|
124 |
|
|
125 |
/* |
|
126 |
* (non-Javadoc) |
|
127 |
* @see org.gvsig.raster.swing.openfile.OpenFileContainer#setPath(java.lang.String) |
|
128 |
*/ |
|
129 |
public void setPath(String path) { |
|
130 |
getTOpen().setText(path); |
|
131 |
} |
|
132 |
|
|
133 |
|
|
134 |
/** |
|
135 |
* Devuelve el file cuya ruta corresponde con el campo de texto. |
|
136 |
* @return |
|
137 |
*/ |
|
138 |
public File getFile() { |
|
139 |
File fil = null; |
|
140 |
if(this.getTOpen().getText() != "") { |
|
141 |
try { |
|
142 |
fil = new File(this.getTOpen().getText()); |
|
143 |
} catch(Exception exc) { |
|
144 |
System.err.println("Ruta o archivo no v?lido"); |
|
145 |
} |
|
146 |
} |
|
147 |
return fil; |
|
148 |
} |
|
149 |
|
|
150 |
public void setEnabled(boolean enabled) { |
|
151 |
getTOpen().setEnabled(enabled); |
|
152 |
getJButton().setEnabled(enabled); |
|
153 |
} |
|
154 |
|
|
155 |
} |
|
0 | 156 |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/java/org/gvsig/raster/swing/impl/openfile/OpenFileListener.java | ||
---|---|---|
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.swing.impl.openfile; |
|
23 |
|
|
24 |
import java.awt.event.ActionEvent; |
|
25 |
import java.awt.event.ActionListener; |
|
26 |
import java.io.File; |
|
27 |
|
|
28 |
import javax.swing.JButton; |
|
29 |
import javax.swing.JFileChooser; |
|
30 |
|
|
31 |
/** |
|
32 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
33 |
*/ |
|
34 |
public class OpenFileListener implements ActionListener { |
|
35 |
|
|
36 |
private JButton button = null; |
|
37 |
private String fName = null; |
|
38 |
private OpenFileContainerImpl controlPanel = null; |
|
39 |
private String[] fileFilter = null; |
|
40 |
|
|
41 |
public OpenFileListener(OpenFileContainerImpl panel, String[] fileFilter) { |
|
42 |
this.controlPanel = panel; |
|
43 |
this.fileFilter = fileFilter; |
|
44 |
} |
|
45 |
|
|
46 |
public void setButton(JButton but) { |
|
47 |
this.button = but; |
|
48 |
} |
|
49 |
|
|
50 |
|
|
51 |
public void actionPerformed(ActionEvent e) { |
|
52 |
if(e.getSource() == this.button) { |
|
53 |
JFileChooser file = new JFileChooser(); |
|
54 |
file.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); |
|
55 |
file.setDialogTitle("Select File"); |
|
56 |
if(fileFilter != null) { |
|
57 |
for (int i = 0; i < fileFilter.length; i++) { |
|
58 |
file.addChoosableFileFilter(new ReadFilter(file, fileFilter[i])); |
|
59 |
} |
|
60 |
int returnVal = file.showOpenDialog(controlPanel); |
|
61 |
if(returnVal == JFileChooser.APPROVE_OPTION){ |
|
62 |
fName = file.getSelectedFile().toString(); |
|
63 |
controlPanel.getTOpen().setText(fName); |
|
64 |
} |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
} |
|
69 |
|
|
70 |
public String getFileName(){ |
|
71 |
return fName; |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
class ReadFilter extends javax.swing.filechooser.FileFilter{ |
|
76 |
|
|
77 |
JFileChooser chooser = null; |
|
78 |
String filter = null; |
|
79 |
|
|
80 |
public ReadFilter(JFileChooser cho,String fil){ |
|
81 |
this.chooser = cho; |
|
82 |
this.filter = fil; |
|
83 |
} |
|
84 |
|
|
85 |
public boolean accept(File f) { |
|
86 |
return f.isDirectory() || f.getName().toLowerCase().endsWith("."+filter); |
|
87 |
} |
|
88 |
|
|
89 |
public String getDescription() { |
|
90 |
return "."+filter; |
|
91 |
} |
|
92 |
|
|
93 |
} |
|
0 | 94 |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/java/org/gvsig/raster/swing/impl/openfile/FileTextField.java | ||
---|---|---|
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.swing.impl.openfile; |
|
23 |
|
|
24 |
import java.awt.GridBagConstraints; |
|
25 |
import java.awt.GridBagLayout; |
|
26 |
import java.awt.Insets; |
|
27 |
import java.awt.event.ActionEvent; |
|
28 |
import java.awt.event.ActionListener; |
|
29 |
import java.awt.event.FocusEvent; |
|
30 |
import java.awt.event.FocusListener; |
|
31 |
import java.io.File; |
|
32 |
|
|
33 |
import javax.swing.JButton; |
|
34 |
import javax.swing.JPanel; |
|
35 |
import javax.swing.JTextField; |
|
36 |
|
|
37 |
import org.gvsig.gui.beans.Messages; |
|
38 |
import org.gvsig.gui.beans.swing.JFileChooser; |
|
39 |
import org.gvsig.raster.swing.openfile.FileFilter; |
|
40 |
|
|
41 |
public class FileTextField extends JPanel { |
|
42 |
private static final long serialVersionUID = 1L; |
|
43 |
private JTextField tf_fileName = null; |
|
44 |
private JButton bt_chooseFile = null; |
|
45 |
private File selectedFile = null; |
|
46 |
private JFileChooser jfc; |
|
47 |
/** |
|
48 |
* Used to create file choosers with 'memory' |
|
49 |
*/ |
|
50 |
private String JFC_ID = null; |
|
51 |
|
|
52 |
public static final int ACTION_EVENT_FIELD_DISABLED = 0; |
|
53 |
public static final int ACTION_EVENT_FIELD_ENABLED = 1; |
|
54 |
public static final int ACTION_EVENT_VALUE_CHANGED = 1; |
|
55 |
|
|
56 |
public FileTextField() { |
|
57 |
super(); |
|
58 |
JFC_ID = this.getClass().getName(); |
|
59 |
initializeUI(); |
|
60 |
} |
|
61 |
|
|
62 |
public FileTextField(String id) { |
|
63 |
super(); |
|
64 |
JFC_ID = id; |
|
65 |
initializeUI(); |
|
66 |
} |
|
67 |
|
|
68 |
private void initializeUI() { |
|
69 |
jfc = new JFileChooser(JFC_ID, (String) null); |
|
70 |
setLayout(new GridBagLayout()); |
|
71 |
|
|
72 |
GridBagConstraints constraints = new GridBagConstraints(); |
|
73 |
constraints.gridx = 0; |
|
74 |
constraints.gridy = 0; |
|
75 |
constraints.gridwidth = 1; |
|
76 |
constraints.gridheight = 1; |
|
77 |
constraints.fill = GridBagConstraints.BOTH; |
|
78 |
constraints.anchor = GridBagConstraints.WEST; |
|
79 |
constraints.weightx = 1.0; |
|
80 |
constraints.weighty = 1.0; |
|
81 |
constraints.insets = new Insets(0,0,0,4); |
|
82 |
this.add(getNameField(), constraints); |
|
83 |
|
|
84 |
getChooseFileButton().addActionListener(new ActionListener() { |
|
85 |
|
|
86 |
public void actionPerformed(ActionEvent e) { |
|
87 |
if (e.getSource()==getChooseFileButton()) { |
|
88 |
int action = jfc.showDialog(FileTextField.this, Messages.getText("Open")); |
|
89 |
if (action == JFileChooser.APPROVE_OPTION) { |
|
90 |
setSelectedFile(jfc.getSelectedFile()); |
|
91 |
setEnabled(true); |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
}); |
|
96 |
constraints.gridx = 1; |
|
97 |
constraints.gridy = 0; |
|
98 |
constraints.gridwidth = 1; |
|
99 |
constraints.gridheight = 1; |
|
100 |
constraints.fill = GridBagConstraints.BOTH; |
|
101 |
constraints.anchor = GridBagConstraints.WEST; |
|
102 |
constraints.weightx = 0.0; |
|
103 |
constraints.weighty = 1.0; |
|
104 |
constraints.insets = new Insets(0,0,0,0); |
|
105 |
this.add(getChooseFileButton(), constraints); |
|
106 |
} |
|
107 |
|
|
108 |
private JTextField getNameField() { |
|
109 |
if (tf_fileName==null) { |
|
110 |
tf_fileName = new JTextField(); |
|
111 |
tf_fileName.addFocusListener(new FocusListener() { |
|
112 |
public void focusGained(FocusEvent e) {} |
|
113 |
|
|
114 |
public void focusLost(FocusEvent e) { |
|
115 |
updateSelectedFile(); |
|
116 |
} |
|
117 |
}); |
|
118 |
} |
|
119 |
return tf_fileName; |
|
120 |
} |
|
121 |
|
|
122 |
private JButton getChooseFileButton() { |
|
123 |
if (bt_chooseFile==null) { |
|
124 |
bt_chooseFile = new JButton("..."); |
|
125 |
} |
|
126 |
return bt_chooseFile; |
|
127 |
} |
|
128 |
|
|
129 |
|
|
130 |
public void setSelectedFile(File file) { |
|
131 |
File oldFile = selectedFile; |
|
132 |
selectedFile = normalizeExtension(file); |
|
133 |
getNameField().setText(selectedFile.toString()); |
|
134 |
if (file.isDirectory()) { |
|
135 |
jfc.setLastPath(file); |
|
136 |
} |
|
137 |
else { |
|
138 |
jfc.setSelectedFile(file); |
|
139 |
jfc.setLastPath(file.getParentFile()); |
|
140 |
} |
|
141 |
fireValueChanged(oldFile, file); |
|
142 |
} |
|
143 |
|
|
144 |
public File getSelectedFile() { |
|
145 |
return updateSelectedFile(); |
|
146 |
} |
|
147 |
|
|
148 |
private File normalizeExtension(File file) { |
|
149 |
javax.swing.filechooser.FileFilter filter = (javax.swing.filechooser.FileFilter) jfc.getFileFilter(); |
|
150 |
if (!filter.accept(file)) { |
|
151 |
String path = file.getPath(); |
|
152 |
if (filter instanceof FileFilter) { |
|
153 |
FileFilter ourFilter = (FileFilter) filter; |
|
154 |
if (path.endsWith(".")) { |
|
155 |
path = path+ourFilter.getDefaultExtension(); |
|
156 |
} |
|
157 |
else { |
|
158 |
path = path+"."+ourFilter.getDefaultExtension(); |
|
159 |
} |
|
160 |
file = new File(path); |
|
161 |
} |
|
162 |
} |
|
163 |
return file; |
|
164 |
} |
|
165 |
|
|
166 |
private File updateSelectedFile() { |
|
167 |
File oldFile = selectedFile; |
|
168 |
String text = getNameField().getText(); |
|
169 |
if ( (oldFile!=null && !oldFile.getPath().equals(text)) |
|
170 |
|| ((oldFile==null) && !text.equals(""))){ |
|
171 |
File newFile = normalizeExtension(new File(getNameField().getText())); |
|
172 |
selectedFile = newFile; |
|
173 |
fireValueChanged(oldFile, newFile); |
|
174 |
} |
|
175 |
return selectedFile; |
|
176 |
} |
|
177 |
|
|
178 |
protected void fireValueChanged(File oldValue, File newValue) { |
|
179 |
firePropertyChange("selectedFileChanged", oldValue, newValue); |
|
180 |
} |
|
181 |
|
|
182 |
protected void fireEnabledChanged(boolean oldValue, boolean newValue) { |
|
183 |
firePropertyChange("enabled", oldValue, newValue); |
|
184 |
} |
|
185 |
|
|
186 |
public void setEnabled(boolean enabled) { |
|
187 |
boolean oldValue = isEnabled(); |
|
188 |
super.setEnabled(enabled); |
|
189 |
getNameField().setEnabled(enabled); |
|
190 |
getChooseFileButton().setEnabled(enabled); |
|
191 |
fireEnabledChanged(oldValue, enabled); |
|
192 |
} |
|
193 |
|
|
194 |
public javax.swing.filechooser.FileFilter getFileFilter() { |
|
195 |
return jfc.getFileFilter(); |
|
196 |
} |
|
197 |
|
|
198 |
public int getFileSelectionMode() { |
|
199 |
return jfc.getFileSelectionMode(); |
|
200 |
} |
|
201 |
|
|
202 |
public boolean removeChoosableFileFilter(FileFilter f) { |
|
203 |
return jfc.removeChoosableFileFilter(f); |
|
204 |
} |
|
205 |
|
|
206 |
public void setFileFilter(FileFilter filter) { |
|
207 |
|
|
208 |
jfc.setFileFilter(filter); |
|
209 |
|
|
210 |
} |
|
211 |
|
|
212 |
public void addChoosableFileFilter(FileFilter filter) { |
|
213 |
jfc.addChoosableFileFilter(filter); |
|
214 |
} |
|
215 |
|
|
216 |
public FileFilter getAcceptAllFileFilter() { |
|
217 |
return (FileFilter) jfc.getAcceptAllFileFilter(); |
|
218 |
} |
|
219 |
|
|
220 |
public boolean isAcceptAllFileFilterUsed() { |
|
221 |
return jfc.isAcceptAllFileFilterUsed(); |
|
222 |
} |
|
223 |
|
|
224 |
public void resetChoosableFileFilters() { |
|
225 |
jfc.resetChoosableFileFilters(); |
|
226 |
} |
|
227 |
|
|
228 |
public void setAcceptAllFileFilterUsed(boolean b) { |
|
229 |
jfc.setAcceptAllFileFilterUsed(b); |
|
230 |
} |
|
231 |
|
|
232 |
} |
|
0 | 233 |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/java/org/gvsig/raster/swing/impl/ExtendedFileFilter.java | ||
---|---|---|
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.swing.impl; |
|
23 |
|
|
24 |
import java.io.File; |
|
25 |
import java.util.ArrayList; |
|
26 |
|
|
27 |
import javax.swing.filechooser.FileFilter; |
|
28 |
|
|
29 |
|
|
30 |
/** |
|
31 |
* ExtendedFileFilter es una clase para usarla junto a los JFileChooser. |
|
32 |
* Ofrece una funcionalidad simple para poder agregar extensiones de manera |
|
33 |
* comoda y rapida. Las descripciones ya las pone con un formato, asi que esto |
|
34 |
* es opcional poner una descripci?n especifica. |
|
35 |
* |
|
36 |
* Un ejemplo t?pico de como se usaria: |
|
37 |
* <pre> |
|
38 |
* // Usamos el JFileChooser de libUIComponents |
|
39 |
* JFileChooser chooser = new JFileChooser(this.getClass().toString(), (File) null); |
|
40 |
* // Desactivamos el modo de ver todos los ficheros |
|
41 |
* chooser.setAcceptAllFileFilterUsed(false); |
|
42 |
* // Activamos la multiseleccion |
|
43 |
* chooser.setMultiSelectionEnabled(true); |
|
44 |
* // Nos guardamos cada tipo de fichero en uno que contenga todos |
|
45 |
* ExtendedFileFilter allFilters = new ExtendedFileFilter(); |
|
46 |
* for (int i = 0; i < formats.length; i++) { |
|
47 |
* ExtendedFileFilter fileFilter = new ExtendedFileFilter(); |
|
48 |
* fileFilter.addExtension(formats[i]); |
|
49 |
* // Agregamos el filefilter al JFileChooser |
|
50 |
* chooser.addChoosableFileFilter(fileFilter); |
|
51 |
* // Agregamos el mismo filtro a un ExtendedFileFilter global |
|
52 |
* allFilters.addExtension(formats[i]); |
|
53 |
* } |
|
54 |
* // Poner una descripcion (OPCIONAL) para todos los ficheros. |
|
55 |
* allFilters.setDescription(PluginServices.getText(this, "todos_soportados")); |
|
56 |
* // Lo a?adimos |
|
57 |
* chooser.addChoosableFileFilter(allFilters); |
|
58 |
* // Y lo dejamos seleccionado por defecto |
|
59 |
* chooser.setFileFilter(allFilters); |
|
60 |
* </pre> |
|
61 |
* |
|
62 |
* @version 21/11/2007 |
|
63 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
64 |
*/ |
|
65 |
public class ExtendedFileFilter extends FileFilter { |
|
66 |
String description = null; |
|
67 |
|
|
68 |
ArrayList<String> extensions = new ArrayList<String>(); |
|
69 |
|
|
70 |
/** |
|
71 |
* Constructor de un ExtendedFileFilter |
|
72 |
*/ |
|
73 |
public ExtendedFileFilter() { |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Construye un ExtendedFileFilter con una extensi?n ya agregada |
|
78 |
* @param extension |
|
79 |
*/ |
|
80 |
public ExtendedFileFilter(String extension) { |
|
81 |
addExtension(extension); |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* A?ade una extensi?n a la lista de extensiones soportadas |
|
86 |
* @param extension |
|
87 |
*/ |
|
88 |
public void addExtension(String extension) { |
|
89 |
if (extension == null) |
|
90 |
return; |
|
91 |
|
|
92 |
extensions.add(extension); |
|
93 |
} |
|
94 |
|
|
95 |
/* |
|
96 |
* (non-Javadoc) |
|
97 |
* @see javax.swing.filechooser.FileFilter#accept(java.io.File) |
|
98 |
*/ |
|
99 |
public boolean accept(File f) { |
|
100 |
if (f.isDirectory()) |
|
101 |
return true; |
|
102 |
|
|
103 |
String s = f.getName(); |
|
104 |
int i = s.lastIndexOf('.'); |
|
105 |
|
|
106 |
if (i > 0 && i < s.length() - 1) { |
|
107 |
String extension = s.substring(i + 1).toLowerCase(); |
|
108 |
for (int j = 0; j < extensions.size(); j++) { |
|
109 |
if (extensions.get(j).toString().toLowerCase().equals(extension)) |
|
110 |
return true; |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
return false; |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* Normaliza el nombre de un fichero, a?adiendo la extension si fuera |
|
119 |
* necesario |
|
120 |
* @param file |
|
121 |
* @return |
|
122 |
*/ |
|
123 |
public String getNormalizedFilename(File file) { |
|
124 |
String s = file.getName(); |
|
125 |
int i = s.lastIndexOf('.'); |
|
126 |
|
|
127 |
if (i > 0 && i < s.length() - 1) { |
|
128 |
String extension = s.substring(i + 1).toLowerCase(); |
|
129 |
for (int j = 0; j < extensions.size(); j++) { |
|
130 |
if (extensions.get(j).toString().toLowerCase().equals(extension)) |
|
131 |
return file.toString(); |
|
132 |
} |
|
133 |
} |
|
134 |
|
|
135 |
return file.toString() + "." + extensions.get(0).toString().toLowerCase(); |
|
136 |
} |
|
137 |
|
|
138 |
/* |
|
139 |
* (non-Javadoc) |
|
140 |
* @see javax.swing.filechooser.FileFilter#getDescription() |
|
141 |
*/ |
|
142 |
public String getDescription() { |
|
143 |
String format1 = ""; |
|
144 |
String format2 = ""; |
|
145 |
for (int j = 0; j < extensions.size(); j++) { |
|
146 |
if (format1.length() != 0) { |
|
147 |
format1 = format1 + ", "; |
|
148 |
format2 = format2 + "; "; |
|
149 |
} |
|
150 |
// Files JPG, GIF, ... (*.jpg; *.gif ...) |
|
151 |
if (j >= 4) { |
|
152 |
format1 = "..."; |
|
153 |
format2 = "..."; |
|
154 |
break; |
|
155 |
} |
|
156 |
format1 = format1 + extensions.get(j).toString().toUpperCase(); |
|
157 |
format2 = format2 + "*." + extensions.get(j).toString().toLowerCase(); |
|
158 |
} |
|
159 |
if (description == null) |
|
160 |
return "files" + " " + format1 + " (" + format2 + ")"; |
|
161 |
|
|
162 |
return description + " (" + format2 + ")"; |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* Especifica la descripcion del item |
|
167 |
* @param description the description to set |
|
168 |
*/ |
|
169 |
public void setDescription(String description) { |
|
170 |
this.description = description; |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* Borra una extension de la lista de extensiones |
|
175 |
* @param extension |
|
176 |
*/ |
|
177 |
public void removeExtension(String extension) { |
|
178 |
extensions.remove(extension); |
|
179 |
} |
|
180 |
|
|
181 |
/** |
|
182 |
* Borra todas las extensiones existentes |
|
183 |
*/ |
|
184 |
public void clearExtensions() { |
|
185 |
extensions.clear(); |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* Devuelve una lista con las extensiones disponibles |
|
190 |
* @return |
|
191 |
*/ |
|
192 |
public ArrayList<String> getExtensions() { |
|
193 |
return extensions; |
|
194 |
} |
|
195 |
} |
|
0 | 196 |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/java/org/gvsig/raster/swing/impl/newlayer/CreateNewLayerPanelImpl.java | ||
---|---|---|
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.swing.impl.newlayer; |
|
23 |
|
|
24 |
import java.awt.BorderLayout; |
|
25 |
import java.awt.Component; |
|
26 |
import java.awt.Dimension; |
|
27 |
import java.awt.GridBagConstraints; |
|
28 |
import java.awt.GridBagLayout; |
|
29 |
import java.awt.Insets; |
|
30 |
import java.awt.event.ItemEvent; |
|
31 |
import java.awt.event.ItemListener; |
|
32 |
import java.io.File; |
|
33 |
import java.util.ArrayList; |
|
34 |
|
|
35 |
import javax.swing.BorderFactory; |
|
36 |
import javax.swing.ButtonGroup; |
|
37 |
import javax.swing.JComponent; |
|
38 |
import javax.swing.JLabel; |
|
39 |
import javax.swing.JPanel; |
|
40 |
import javax.swing.JRadioButton; |
|
41 |
import javax.swing.JTextField; |
|
42 |
import javax.swing.filechooser.FileFilter; |
|
43 |
|
|
44 |
import org.gvsig.andami.PluginServices; |
|
45 |
import org.gvsig.andami.Utilities; |
|
46 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
47 |
import org.gvsig.gui.beans.swing.JFileChooser; |
|
48 |
import org.gvsig.raster.swing.impl.ExtendedFileFilter; |
|
49 |
import org.gvsig.raster.swing.impl.openfile.OpenFileContainerImpl; |
|
50 |
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel; |
|
51 |
import org.gvsig.raster.swing.newlayer.FileNameManagement; |
|
52 |
import org.gvsig.raster.swing.openfile.OpenFileContainer; |
|
53 |
|
|
54 |
/** |
|
55 |
* Panel to create a new layer. This panel gives the option to select a file |
|
56 |
* or open in memory. |
|
57 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
58 |
*/ |
|
59 |
public class CreateNewLayerPanelImpl extends JPanel implements CreateNewLayerPanel { |
|
60 |
private static final long serialVersionUID = -8569485642371687008L; |
|
61 |
private JRadioButton jRBFileGenerate = null; |
|
62 |
private JRadioButton jRBOpenMemory = null; |
|
63 |
private JTextField filenameTextField = null; |
|
64 |
private JLabel labelFilename = null; |
|
65 |
private JPanel panelNameFile = null; |
|
66 |
private boolean compress = false; |
|
67 |
private ArrayList<String> extList = null; |
|
68 |
private FileNameManagement fileNameManagement = null; |
|
69 |
private OpenFileContainer openFileContainer = null; |
|
70 |
|
|
71 |
/** |
|
72 |
* Constructor de un CreateLayerPanel |
|
73 |
*/ |
|
74 |
public CreateNewLayerPanelImpl(FileNameManagement fileNameManagement) { |
|
75 |
this.fileNameManagement = fileNameManagement; |
|
76 |
this.extList = fileNameManagement.getPrefixSupported(); |
|
77 |
initialize(); |
|
78 |
translate(); |
|
79 |
} |
|
80 |
|
|
81 |
|
|
82 |
private void initialize() { |
|
83 |
ButtonGroup buttonGroup2; |
|
84 |
GridBagConstraints gridBagConstraints; |
|
85 |
|
|
86 |
setLayout(new GridBagLayout()); |
|
87 |
|
|
88 |
setBorder(BorderFactory.createTitledBorder("")); |
|
89 |
buttonGroup2 = new ButtonGroup(); |
|
90 |
buttonGroup2.add(getRadioFileGenerate()); |
|
91 |
gridBagConstraints = new GridBagConstraints(); |
|
92 |
gridBagConstraints.fill = GridBagConstraints.BOTH; |
|
93 |
gridBagConstraints.weightx = 1.0D; |
|
94 |
gridBagConstraints.anchor = GridBagConstraints.WEST; |
|
95 |
gridBagConstraints.insets = new Insets(2, 2, 5, 2); |
|
96 |
|
|
97 |
add(getRadioFileGenerate(), gridBagConstraints); |
|
98 |
|
|
99 |
gridBagConstraints.gridy = 1; |
|
100 |
gridBagConstraints.insets = new Insets(2, 25, 5, 2); |
|
101 |
add((JComponent)getFileSelectorPanel(), gridBagConstraints); |
|
102 |
|
|
103 |
buttonGroup2.add(getRadioOpenMemory()); |
|
104 |
gridBagConstraints.gridx = 0; |
|
105 |
gridBagConstraints.gridy = 2; |
|
106 |
gridBagConstraints.anchor = GridBagConstraints.WEST; |
|
107 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
|
108 |
add(getRadioOpenMemory(), gridBagConstraints); |
|
109 |
|
|
110 |
gridBagConstraints.gridy = 3; |
|
111 |
gridBagConstraints.insets = new Insets(2, 25, 2, 2); |
|
112 |
add(getFileNamePanel(), gridBagConstraints); |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* Seccion donde ir?n todas las traducciones invariables del componente |
|
117 |
*/ |
|
118 |
private void translate() { |
|
119 |
getRadioFileGenerate().setText(PluginServices.getText(this, "generar_fichero")); |
|
120 |
getRadioOpenMemory().setText(PluginServices.getText(this, "abrir_memoria")); |
|
121 |
getLabelFilename().setText(PluginServices.getText(this, "nombre_capa") + ":"); |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* Devuelve el JRadioButton de generar fichero |
|
126 |
* @return |
|
127 |
*/ |
|
128 |
public JRadioButton getRadioFileGenerate() { |
|
129 |
if (jRBFileGenerate == null) { |
|
130 |
jRBFileGenerate = new JRadioButton(); |
|
131 |
jRBFileGenerate.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
|
132 |
jRBFileGenerate.setMargin(new Insets(0, 0, 0, 0)); |
|
133 |
} |
|
134 |
return jRBFileGenerate; |
|
135 |
} |
|
136 |
|
|
137 |
/** |
|
138 |
* Devuelve el JRadioButton de Abrir en memoria |
|
139 |
* @return |
|
140 |
*/ |
|
141 |
public JRadioButton getRadioOpenMemory() { |
|
142 |
if (jRBOpenMemory == null) { |
|
143 |
jRBOpenMemory = new JRadioButton(); |
|
144 |
jRBOpenMemory.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
|
145 |
jRBOpenMemory.setMargin(new Insets(0, 0, 0, 0)); |
|
146 |
|
|
147 |
jRBOpenMemory.addItemListener(new ItemListener() { |
|
148 |
public void itemStateChanged(ItemEvent evt) { |
|
149 |
jRBOpenMemoryStateChanged(evt); |
|
150 |
} |
|
151 |
}); |
|
152 |
jRBOpenMemory.setSelected(true); |
|
153 |
} |
|
154 |
return jRBOpenMemory; |
|
155 |
} |
|
156 |
|
|
157 |
/** |
|
158 |
* This method initializes filenameTextField |
|
159 |
* |
|
160 |
* @return javax.swing.JTextField |
|
161 |
*/ |
|
162 |
private JTextField getFilenameTextField() { |
|
163 |
if (filenameTextField == null) { |
|
164 |
filenameTextField = new JTextField(); |
|
165 |
filenameTextField.setPreferredSize(new Dimension(150, filenameTextField.getPreferredSize().height)); |
|
166 |
//fileUtil.addOnlyLayerNameListener(this); |
|
167 |
} |
|
168 |
return filenameTextField; |
|
169 |
} |
|
170 |
|
|
171 |
public OpenFileContainer getFileSelectorPanel() { |
|
172 |
if (openFileContainer == null) { |
|
173 |
openFileContainer = new OpenFileContainerImpl(false, extList); |
|
174 |
} |
|
175 |
return openFileContainer; |
|
176 |
} |
|
177 |
|
|
178 |
|
|
179 |
public JPanel getFileNamePanel() { |
|
180 |
if (panelNameFile == null) { |
|
181 |
panelNameFile = new JPanel(); |
|
182 |
panelNameFile.setLayout(new BorderLayout()); |
|
183 |
panelNameFile.add(getLabelFilename(), BorderLayout.WEST); |
|
184 |
panelNameFile.add(getFilenameTextField(), BorderLayout.CENTER); |
|
185 |
//updateNewLayerText(); |
|
186 |
} |
|
187 |
return panelNameFile; |
|
188 |
} |
|
189 |
|
|
190 |
private JLabel getLabelFilename() { |
|
191 |
if (labelFilename == null) { |
|
192 |
labelFilename = new JLabel(); |
|
193 |
} |
|
194 |
return labelFilename; |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
198 |
* Establece si esta habilitado o no el cuadro de texto de entrada de nombre de |
|
199 |
* fichero |
|
200 |
* @param value |
|
201 |
*/ |
|
202 |
public void setFilenameEnabled(boolean value) { |
|
203 |
getFilenameTextField().setEnabled(value); |
|
204 |
getLabelFilename().setEnabled(value); |
|
205 |
} |
|
206 |
|
|
207 |
/** |
|
208 |
* Poner los estados de los RadioButton en caso de que cambien de valor |
|
209 |
* @param evt |
|
210 |
*/ |
|
211 |
protected void jRBOpenMemoryStateChanged(ItemEvent evt) { |
|
212 |
if (getRadioOpenMemory().getSelectedObjects() != null) { |
|
213 |
getFileSelectorPanel().setEnabled(false); |
|
214 |
setFilenameEnabled(true); |
|
215 |
} else { |
|
216 |
getFileSelectorPanel().setEnabled(true); |
|
217 |
setFilenameEnabled(false); |
|
218 |
} |
|
219 |
} |
|
220 |
|
|
221 |
/** |
|
222 |
* Establece el texto de la etiqueta del nombre de fichero |
|
223 |
* @param text |
|
224 |
*/ |
|
225 |
public void setLabelFilename(String text) { |
|
226 |
getLabelFilename().setText(text); |
|
227 |
} |
|
228 |
|
|
229 |
/** |
|
230 |
* Devuelve la ruta del fichero donde se va a guardar, en caso de guardarse |
|
231 |
* en memoria, calcula el nombre sin preguntar y devuelve la ruta. |
|
232 |
* @return |
|
233 |
*/ |
|
234 |
public String getFileSelected() { |
|
235 |
String path = ""; |
|
236 |
if (getRadioFileGenerate().isSelected()) { |
|
237 |
JFileChooser chooser = new JFileChooser("NEW_LAYER_RASTER_PANEL", JFileChooser.getLastPath("NEW_LAYER_RASTER_PANEL", null)); |
|
238 |
chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero")); |
|
239 |
|
|
240 |
FileFilter selected = null; |
|
241 |
for (int i = 0; i < extList.size(); i++) { |
|
242 |
FileFilter filter = new ExtendedFileFilter((String) extList.get(i)); |
|
243 |
if (extList.get(i).equals("tif")) { |
|
244 |
selected = filter; |
|
245 |
} |
|
246 |
chooser.addChoosableFileFilter(filter); |
|
247 |
} |
|
248 |
if (selected != null) |
|
249 |
chooser.setFileFilter(selected); |
|
250 |
|
|
251 |
// Cargamos el panel de propiedades en el selector |
|
252 |
chooser.setAcceptAllFileFilterUsed(false); |
|
253 |
|
|
254 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
|
255 |
|
|
256 |
if (!(w instanceof Component)) |
|
257 |
w = null; |
|
258 |
|
|
259 |
if (chooser.showSaveDialog((Component) w) != JFileChooser.APPROVE_OPTION) |
|
260 |
return null; |
|
261 |
|
|
262 |
JFileChooser.setLastPath("NEW_LAYER_RASTER_PANEL", chooser.getSelectedFile()); |
|
263 |
|
|
264 |
ExtendedFileFilter fileFilter = (ExtendedFileFilter) chooser.getFileFilter(); |
|
265 |
path = fileFilter.getNormalizedFilename(chooser.getSelectedFile()); |
|
266 |
} else { |
|
267 |
|
|
268 |
String file = getFilenameTextField().getText(); |
|
269 |
if (file.compareTo(fileNameManagement.getUniqueLayerName()) == 0) |
|
270 |
fileNameManagement.usesUniqueLayerName(); |
|
271 |
|
|
272 |
if (!compress) |
|
273 |
path = Utilities.createTempDirectory() + File.separator + file + ".tif"; |
|
274 |
else |
|
275 |
path = Utilities.createTempDirectory() + File.separator + file + ".jp2"; |
|
276 |
updateNewLayerText(); |
|
277 |
} |
|
278 |
return path; |
|
279 |
} |
|
280 |
|
|
281 |
/** |
|
282 |
* Especificar el nombre de la nueva capa para el recuadro de texto asignando |
|
283 |
* en cada llamada un nombre consecutivo. |
|
284 |
*/ |
|
285 |
public void updateNewLayerText() { |
|
286 |
getFilenameTextField().setText(fileNameManagement.getUniqueLayerName()); |
|
287 |
} |
|
288 |
} |
|
0 | 289 |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.swing/org.gvsig.raster.swing.impl/src/main/java/org/gvsig/raster/swing/impl/DefaultRasterSwingManager.java | ||
---|---|---|
36 | 36 |
import org.gvsig.raster.swing.impl.buttonbar.ButtonBarContainerImpl; |
37 | 37 |
import org.gvsig.raster.swing.impl.canvas.DefaultGCanvas; |
38 | 38 |
import org.gvsig.raster.swing.impl.infobypoint.MainInfoByPointPanelImpl; |
39 |
import org.gvsig.raster.swing.impl.newlayer.CreateNewLayerPanelImpl; |
|
40 |
import org.gvsig.raster.swing.impl.openfile.OpenFileContainerImpl; |
|
39 | 41 |
import org.gvsig.raster.swing.impl.preview.PreviewBasePanel; |
40 | 42 |
import org.gvsig.raster.swing.impl.preview.SinglePreviewPanel; |
41 | 43 |
import org.gvsig.raster.swing.infobypoint.MainInfoByPointPanel; |
44 |
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel; |
|
45 |
import org.gvsig.raster.swing.newlayer.FileNameManagement; |
|
46 |
import org.gvsig.raster.swing.openfile.OpenFileContainer; |
|
42 | 47 |
import org.gvsig.raster.swing.preview.DataSourcePreview; |
43 | 48 |
import org.gvsig.raster.swing.preview.PreviewPanel; |
44 | 49 |
import org.gvsig.raster.swing.preview.PreviewRenderProcess; |
... | ... | |
157 | 162 |
public ButtonBar createButtonBar() { |
158 | 163 |
return new ButtonBarContainerImpl(); |
159 | 164 |
} |
165 |
|
|
166 |
/* |
|
167 |
* (non-Javadoc) |
|
168 |
* @see org.gvsig.raster.swing.RasterSwingManager#createNewLayerPanel(org.gvsig.raster.swing.newlayer.FileNameManagement, java.util.ArrayList) |
|
169 |
*/ |
|
170 |
public CreateNewLayerPanel createNewLayerPanel( |
|
171 |
FileNameManagement fileNameManagement) { |
|
172 |
return new CreateNewLayerPanelImpl(fileNameManagement); |
|
173 |
} |
|
174 |
|
|
175 |
/* |
|
176 |
* (non-Javadoc) |
|
177 |
* @see org.gvsig.raster.swing.RasterSwingManager#createOpenFileContainer(boolean, java.lang.String[]) |
|
178 |
*/ |
|
179 |
public OpenFileContainer createOpenFileContainer(boolean showBorder, String[] fileFilter) { |
|
180 |
return new OpenFileContainerImpl(showBorder, fileFilter); |
|
181 |
} |
|
160 | 182 |
} |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.swing/org.gvsig.raster.swing.api/src/main/java/org/gvsig/raster/swing/openfile/OpenFileContainer.java | ||
---|---|---|
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.swing.openfile; |
|
23 |
|
|
24 |
import java.io.File; |
|
25 |
|
|
26 |
/** |
|
27 |
* Panel to choose a file from disk |
|
28 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
29 |
*/ |
|
30 |
public interface OpenFileContainer { |
|
31 |
/** |
|
32 |
* Gets the selected file |
|
33 |
* @return |
|
34 |
*/ |
|
35 |
public File getFile(); |
|
36 |
|
|
37 |
/** |
|
38 |
* Sets a path in the field of text |
|
39 |
* @param path |
|
40 |
*/ |
|
41 |
public void setPath(String path); |
|
42 |
|
|
43 |
public void setEnabled(boolean enabled); |
|
44 |
} |
|
0 | 45 |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.swing/org.gvsig.raster.swing.api/src/main/java/org/gvsig/raster/swing/openfile/FileFilter.java | ||
---|---|---|
1 |
package org.gvsig.raster.swing.openfile; |
|
2 |
|
|
3 |
|
|
4 |
public abstract class FileFilter extends javax.swing.filechooser.FileFilter { |
|
5 |
|
|
6 |
/** |
|
7 |
* <p>Gets the default file extension, which will be |
|
8 |
* added to the selected file if its extension is not |
|
9 |
* valid.</p> |
|
10 |
* |
|
11 |
* @return |
|
12 |
*/ |
|
13 |
public abstract String getDefaultExtension(); |
|
14 |
} |
|
0 | 15 |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.swing/org.gvsig.raster.swing.api/src/main/java/org/gvsig/raster/swing/RasterSwingManager.java | ||
---|---|---|
31 | 31 |
import org.gvsig.raster.swing.buttonbar.ButtonBar; |
32 | 32 |
import org.gvsig.raster.swing.gcanvas.GCanvas; |
33 | 33 |
import org.gvsig.raster.swing.infobypoint.MainInfoByPointPanel; |
34 |
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel; |
|
35 |
import org.gvsig.raster.swing.newlayer.FileNameManagement; |
|
36 |
import org.gvsig.raster.swing.openfile.OpenFileContainer; |
|
34 | 37 |
import org.gvsig.raster.swing.preview.DataSourcePreview; |
35 | 38 |
import org.gvsig.raster.swing.preview.PreviewPanel; |
36 | 39 |
import org.gvsig.raster.swing.preview.PreviewRenderProcess; |
... | ... | |
136 | 139 |
*/ |
137 | 140 |
public ButtonBar createButtonBar(); |
138 | 141 |
|
142 |
/** |
|
143 |
* Creates a panel to build a new layer |
|
144 |
* @param fileNameManagement |
|
145 |
* @param extList |
|
146 |
* List of file extensions to accept |
|
147 |
* @return |
|
148 |
*/ |
|
149 |
public CreateNewLayerPanel createNewLayerPanel(FileNameManagement fileNameManagement); |
|
150 |
|
|
151 |
/** |
|
152 |
* Creates a panel to open files |
|
153 |
* @param showBorder |
|
154 |
* @param fileFilter |
|
155 |
* @return |
|
156 |
*/ |
|
157 |
public OpenFileContainer createOpenFileContainer(boolean showBorder, String[] fileFilter); |
|
139 | 158 |
} |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.swing/org.gvsig.raster.swing.api/src/main/java/org/gvsig/raster/swing/newlayer/CreateNewLayerPanel.java | ||
---|---|---|
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.swing.newlayer; |
|
23 |
|
|
24 |
|
|
25 |
/** |
|
26 |
* Panel to create a new layer. This panel gives the option to select a file |
|
27 |
* or open in memory. |
|
28 |
* |
|
29 |
*/ |
|
30 |
public interface CreateNewLayerPanel { |
|
31 |
|
|
32 |
} |
|
0 | 33 |
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.swing/org.gvsig.raster.swing.api/src/main/java/org/gvsig/raster/swing/newlayer/FileNameManagement.java | ||
---|---|---|
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.swing.newlayer; |
|
23 |
|
|
24 |
import java.util.ArrayList; |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* Interface to manage the name of a new layer. |
|
29 |
* |
|
30 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
31 |
*/ |
|
32 |
public interface FileNameManagement { |
|
33 |
|
|
34 |
public String getUniqueLayerName(); |
|
35 |
|
|
36 |
public void usesUniqueLayerName(); |
|
37 |
|
|
38 |
public ArrayList<String> getPrefixSupported(); |
|
39 |
} |
|
0 | 40 |
Also available in: Unified diff