svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / gui / cad / panels / FileBasedPanel.java @ 40557
History | View | Annotate | Download (5.86 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.editing.gui.cad.panels; |
25 |
|
26 |
import java.awt.Component; |
27 |
import java.awt.event.KeyEvent; |
28 |
import java.io.File; |
29 |
|
30 |
import javax.swing.JButton; |
31 |
import javax.swing.JFileChooser; |
32 |
import javax.swing.JLabel; |
33 |
import javax.swing.JTextField; |
34 |
|
35 |
import jwizardcomponent.JWizardComponents; |
36 |
import jwizardcomponent.JWizardPanel; |
37 |
|
38 |
import org.gvsig.andami.PluginServices; |
39 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
40 |
import org.gvsig.app.addlayer.AddLayerDialog; |
41 |
import org.gvsig.app.gui.panels.CRSSelectPanel; |
42 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
43 |
import org.gvsig.utils.SimpleFileFilter; |
44 |
|
45 |
|
46 |
public class FileBasedPanel extends JWizardPanel { |
47 |
|
48 |
private static final long serialVersionUID = -1431370928697152515L; |
49 |
private JLabel jLabel = null; |
50 |
private JTextField jTextFieldPath = null; |
51 |
private JButton jButtonSelectPath = null; |
52 |
private CRSSelectPanel crsSelectPanel = null; |
53 |
private String fileExt; |
54 |
|
55 |
// private class MyInputEventListener implements CaretListener
|
56 |
// {
|
57 |
// public void caretUpdate(CaretEvent arg0) {
|
58 |
// if (jTextFieldPath.getText().length() > 0)
|
59 |
// setFinishButtonEnabled(true);
|
60 |
// else
|
61 |
// setFinishButtonEnabled(false);
|
62 |
//
|
63 |
// }
|
64 |
//
|
65 |
// }
|
66 |
|
67 |
|
68 |
public FileBasedPanel(JWizardComponents wizardComponents) {
|
69 |
super(wizardComponents);
|
70 |
initialize(); |
71 |
} |
72 |
|
73 |
/**
|
74 |
* This method initializes this
|
75 |
*
|
76 |
*/
|
77 |
private void initialize() { |
78 |
jLabel = new JLabel(); |
79 |
jLabel.setText(PluginServices.getText(this,"enter_path_to_file")); |
80 |
jLabel.setBounds(new java.awt.Rectangle(12,17,319,15)); |
81 |
this.setLayout(null); |
82 |
this.setSize(new java.awt.Dimension(380,214)); |
83 |
this.add(jLabel, null); |
84 |
this.add(getJTextFieldPath(), null); |
85 |
this.add(getJButtonSelectPath(), null); |
86 |
|
87 |
this.add(getChooserPanel(), null); |
88 |
setFinishButtonEnabled(false);
|
89 |
} |
90 |
|
91 |
/**
|
92 |
* This method initializes jTextFieldPath
|
93 |
*
|
94 |
* @return javax.swing.JTextField
|
95 |
*/
|
96 |
private JTextField getJTextFieldPath() { |
97 |
if (jTextFieldPath == null) { |
98 |
jTextFieldPath = new JTextField(); |
99 |
jTextFieldPath.setPreferredSize(new java.awt.Dimension(210,20)); |
100 |
jTextFieldPath.setBounds(new java.awt.Rectangle(12,38,319,23)); |
101 |
jTextFieldPath.addKeyListener(new java.awt.event.KeyAdapter() {
|
102 |
public void keyReleased(KeyEvent arg0) { |
103 |
if (!jTextFieldPath.getText().equals("")) |
104 |
setFinishButtonEnabled(true);
|
105 |
else
|
106 |
setFinishButtonEnabled(false);
|
107 |
} |
108 |
|
109 |
}); |
110 |
} |
111 |
return jTextFieldPath;
|
112 |
} |
113 |
|
114 |
/**
|
115 |
* This method initializes jButtonSelectPath
|
116 |
*
|
117 |
* @return javax.swing.JButton
|
118 |
*/
|
119 |
private JButton getJButtonSelectPath() { |
120 |
if (jButtonSelectPath == null) { |
121 |
jButtonSelectPath = new JButton(); |
122 |
jButtonSelectPath.setText("...");
|
123 |
jButtonSelectPath.setBounds(new java.awt.Rectangle(332,38,32,22)); |
124 |
jButtonSelectPath.addActionListener(new java.awt.event.ActionListener() {
|
125 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
126 |
JFileChooser jfc = new JFileChooser(); |
127 |
SimpleFileFilter filterShp = new SimpleFileFilter(fileExt, PluginServices.getText(this,"file")+" "+fileExt); |
128 |
jfc.setFileFilter(filterShp); |
129 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
130 |
File newFile = jfc.getSelectedFile();
|
131 |
String path = newFile.getAbsolutePath();
|
132 |
if (!(path.toLowerCase().endsWith("." + fileExt))) |
133 |
{ |
134 |
path = path + "." + fileExt;
|
135 |
} |
136 |
jTextFieldPath.setText(path); |
137 |
setFinishButtonEnabled(true);
|
138 |
}else{
|
139 |
setFinishButtonEnabled(false);
|
140 |
} |
141 |
|
142 |
} |
143 |
}); |
144 |
} |
145 |
return jButtonSelectPath;
|
146 |
} |
147 |
|
148 |
public String getPath() { |
149 |
return jTextFieldPath.getText();
|
150 |
} |
151 |
|
152 |
/**
|
153 |
* Use it to set the extension of the file you want to receive.
|
154 |
* (Without . : Example: for shps: shp for dxfs: dxf)
|
155 |
* @param extension
|
156 |
*/
|
157 |
public void setFileExtension(String extension) |
158 |
{ |
159 |
this.fileExt = extension;
|
160 |
} |
161 |
|
162 |
/**
|
163 |
* This method initializes chooserPanel
|
164 |
*
|
165 |
* @return javax.swing.JPanel
|
166 |
*/
|
167 |
private CRSSelectPanel getChooserPanel() {
|
168 |
if (crsSelectPanel == null) { |
169 |
crsSelectPanel = CRSSelectPanel.getPanel(AddLayerDialog.getLastProjection()); |
170 |
crsSelectPanel.setBounds(new java.awt.Rectangle(16,98,348,44)); |
171 |
IWindow view= PluginServices.getMDIManager().getActiveWindow(); |
172 |
if (view instanceof org.gvsig.app.project.documents.view.gui.DefaultViewPanel){ |
173 |
if (((DefaultViewPanel)view).getMapControl().getMapContext().getLayers().getLayersCount()!=0){ |
174 |
crsSelectPanel.getJBtnChangeProj().setEnabled(false);
|
175 |
} |
176 |
} |
177 |
crsSelectPanel.addActionListener(new java.awt.event.ActionListener() {
|
178 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
179 |
if (crsSelectPanel.isOkPressed()) {
|
180 |
AddLayerDialog.setLastProjection(crsSelectPanel.getCurProj()); |
181 |
} |
182 |
} |
183 |
}); |
184 |
} |
185 |
return crsSelectPanel;
|
186 |
} |
187 |
|
188 |
} // @jve:decl-index=0:visual-constraint="10,10"
|