svn-gvsig-desktop / tags / v1_0_2_Build_897 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / panels / FileBasedPanel.java @ 10444
History | View | Annotate | Download (4.9 KB)
1 |
package com.iver.cit.gvsig.gui.cad.panels; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.awt.event.KeyEvent; |
5 |
import java.io.File; |
6 |
|
7 |
import javax.swing.JButton; |
8 |
import javax.swing.JFileChooser; |
9 |
import javax.swing.JLabel; |
10 |
import javax.swing.JTextField; |
11 |
|
12 |
import jwizardcomponent.JWizardComponents; |
13 |
import jwizardcomponent.JWizardPanel; |
14 |
|
15 |
import com.iver.andami.PluginServices; |
16 |
import com.iver.andami.ui.mdiManager.IWindow; |
17 |
import com.iver.cit.gvsig.project.documents.gui.FOpenDialog; |
18 |
import com.iver.cit.gvsig.gui.panels.CRSSelectPanel; |
19 |
import com.iver.utiles.SimpleFileFilter; |
20 |
|
21 |
public class FileBasedPanel extends JWizardPanel { |
22 |
|
23 |
private static final long serialVersionUID = -1431370928697152515L; |
24 |
private JLabel jLabel = null; |
25 |
private JTextField jTextFieldPath = null; |
26 |
private JButton jButtonSelectPath = null; |
27 |
private CRSSelectPanel crsSelectPanel = null; |
28 |
private String fileExt; |
29 |
|
30 |
// private class MyInputEventListener implements CaretListener
|
31 |
// {
|
32 |
// public void caretUpdate(CaretEvent arg0) {
|
33 |
// if (jTextFieldPath.getText().length() > 0)
|
34 |
// setFinishButtonEnabled(true);
|
35 |
// else
|
36 |
// setFinishButtonEnabled(false);
|
37 |
//
|
38 |
// }
|
39 |
//
|
40 |
// }
|
41 |
|
42 |
|
43 |
public FileBasedPanel(JWizardComponents wizardComponents) {
|
44 |
super(wizardComponents);
|
45 |
initialize(); |
46 |
} |
47 |
|
48 |
/**
|
49 |
* This method initializes this
|
50 |
*
|
51 |
*/
|
52 |
private void initialize() { |
53 |
jLabel = new JLabel(); |
54 |
jLabel.setText(PluginServices.getText(this,"enter_path_to_file")); |
55 |
jLabel.setBounds(new java.awt.Rectangle(12,17,319,15)); |
56 |
this.setLayout(null); |
57 |
this.setSize(new java.awt.Dimension(380,214)); |
58 |
this.add(jLabel, null); |
59 |
this.add(getJTextFieldPath(), null); |
60 |
this.add(getJButtonSelectPath(), null); |
61 |
|
62 |
this.add(getChooserPanel(), null); |
63 |
setFinishButtonEnabled(false);
|
64 |
} |
65 |
|
66 |
/**
|
67 |
* This method initializes jTextFieldPath
|
68 |
*
|
69 |
* @return javax.swing.JTextField
|
70 |
*/
|
71 |
private JTextField getJTextFieldPath() { |
72 |
if (jTextFieldPath == null) { |
73 |
jTextFieldPath = new JTextField(); |
74 |
jTextFieldPath.setPreferredSize(new java.awt.Dimension(210,20)); |
75 |
jTextFieldPath.setBounds(new java.awt.Rectangle(12,38,319,23)); |
76 |
jTextFieldPath.addKeyListener(new java.awt.event.KeyAdapter() {
|
77 |
public void keyReleased(KeyEvent arg0) { |
78 |
if (!jTextFieldPath.getText().equals("")) |
79 |
setFinishButtonEnabled(true);
|
80 |
else
|
81 |
setFinishButtonEnabled(false);
|
82 |
} |
83 |
|
84 |
}); |
85 |
} |
86 |
return jTextFieldPath;
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* This method initializes jButtonSelectPath
|
91 |
*
|
92 |
* @return javax.swing.JButton
|
93 |
*/
|
94 |
private JButton getJButtonSelectPath() { |
95 |
if (jButtonSelectPath == null) { |
96 |
jButtonSelectPath = new JButton(); |
97 |
jButtonSelectPath.setText("...");
|
98 |
jButtonSelectPath.setBounds(new java.awt.Rectangle(332,38,32,22)); |
99 |
jButtonSelectPath.addActionListener(new java.awt.event.ActionListener() {
|
100 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
101 |
JFileChooser jfc = new JFileChooser(); |
102 |
SimpleFileFilter filterShp = new SimpleFileFilter(fileExt, PluginServices.getText(this,"file")+" "+fileExt); |
103 |
jfc.setFileFilter(filterShp); |
104 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
105 |
File newFile = jfc.getSelectedFile();
|
106 |
String path = newFile.getAbsolutePath();
|
107 |
if (!(path.toLowerCase().endsWith("." + fileExt))) |
108 |
{ |
109 |
path = path + "." + fileExt;
|
110 |
} |
111 |
jTextFieldPath.setText(path); |
112 |
setFinishButtonEnabled(true);
|
113 |
}else{
|
114 |
setFinishButtonEnabled(false);
|
115 |
} |
116 |
|
117 |
} |
118 |
}); |
119 |
} |
120 |
return jButtonSelectPath;
|
121 |
} |
122 |
|
123 |
public String getPath() { |
124 |
return jTextFieldPath.getText();
|
125 |
} |
126 |
|
127 |
/**
|
128 |
* Use it to set the extension of the file you want to receive.
|
129 |
* (Without . : Example: for shps: shp for dxfs: dxf)
|
130 |
* @param extension
|
131 |
*/
|
132 |
public void setFileExtension(String extension) |
133 |
{ |
134 |
this.fileExt = extension;
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* This method initializes chooserPanel
|
139 |
*
|
140 |
* @return javax.swing.JPanel
|
141 |
*/
|
142 |
private CRSSelectPanel getChooserPanel() {
|
143 |
if (crsSelectPanel == null) { |
144 |
crsSelectPanel = CRSSelectPanel.getPanel(FOpenDialog.getLastProjection()); |
145 |
crsSelectPanel.setBounds(new java.awt.Rectangle(16,98,348,44)); |
146 |
IWindow view= PluginServices.getMDIManager().getActiveWindow(); |
147 |
if (view instanceof com.iver.cit.gvsig.project.documents.view.gui.View){ |
148 |
if (((com.iver.cit.gvsig.project.documents.view.gui.View)view).getMapControl().getMapContext().getLayers().getLayersCount()!=0){ |
149 |
crsSelectPanel.getJBtnChangeProj().setEnabled(false);
|
150 |
} |
151 |
} |
152 |
crsSelectPanel.addActionListener(new java.awt.event.ActionListener() {
|
153 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
154 |
if (crsSelectPanel.isOkPressed()) {
|
155 |
FOpenDialog.setLastProjection(crsSelectPanel.getCurProj()); |
156 |
} |
157 |
} |
158 |
}); |
159 |
} |
160 |
return crsSelectPanel;
|
161 |
} |
162 |
|
163 |
} // @jve:decl-index=0:visual-constraint="10,10"
|