root / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / panels / ESRIpanel.java @ 8127
History | View | Annotate | Download (3.05 KB)
1 |
package org.gvsig.crs.gui.panels; |
---|---|
2 |
import java.awt.Dimension; |
3 |
import java.awt.FlowLayout; |
4 |
import java.awt.GridLayout; |
5 |
import java.awt.event.ActionEvent; |
6 |
import java.awt.event.ActionListener; |
7 |
import java.io.File; |
8 |
|
9 |
import javax.swing.JButton; |
10 |
import javax.swing.JFileChooser; |
11 |
import javax.swing.JFrame; |
12 |
import javax.swing.JLabel; |
13 |
import javax.swing.JPanel; |
14 |
import javax.swing.JTextField; |
15 |
import javax.swing.filechooser.FileFilter; |
16 |
|
17 |
import com.iver.andami.PluginServices; |
18 |
|
19 |
public class ESRIpanel extends JPanel implements ActionListener { |
20 |
|
21 |
/**
|
22 |
*
|
23 |
*/
|
24 |
private static final long serialVersionUID = 1L; |
25 |
private JLabel open_esri; |
26 |
private JTextField jTextOpen; |
27 |
private JFileChooser openChooser; |
28 |
private JButton jButtonOpen; |
29 |
File f = new File("C:/Archivos de programa/FWTools1.0.0a7/data/Geographic Coordinate Systems"); |
30 |
|
31 |
public ESRIpanel() {
|
32 |
initialize(); |
33 |
} |
34 |
|
35 |
private void initialize(){ |
36 |
this.setPreferredSize(new Dimension(525,400)); |
37 |
this.setLayout(new GridLayout(2,2)); |
38 |
this.setLayout(new FlowLayout(FlowLayout.CENTER,5,5)); |
39 |
this.add(getOpenESRI(), null); |
40 |
this.add(getOpenTextField(), null); |
41 |
this.add(getButtonOpen(), null); |
42 |
} |
43 |
|
44 |
private JLabel getOpenESRI() { |
45 |
if(open_esri == null) { |
46 |
open_esri = new JLabel(); |
47 |
open_esri.setPreferredSize(new Dimension(80,20)); |
48 |
open_esri.setText(PluginServices.getText(this,"Abrir .prj:")); |
49 |
} |
50 |
return open_esri;
|
51 |
} |
52 |
|
53 |
private JTextField getOpenTextField() { |
54 |
if(jTextOpen == null) { |
55 |
jTextOpen = new JTextField(); |
56 |
jTextOpen.setPreferredSize(new Dimension(200,20)); |
57 |
jTextOpen.setText("");
|
58 |
} |
59 |
return jTextOpen;
|
60 |
} |
61 |
|
62 |
private JFileChooser getOpen(){ |
63 |
if(openChooser == null){ |
64 |
openChooser = new JFileChooser(); |
65 |
openChooser.addChoosableFileFilter(new FiltroESRI());
|
66 |
openChooser.setEnabled(false);
|
67 |
} |
68 |
return openChooser;
|
69 |
} |
70 |
|
71 |
private JButton getButtonOpen() { |
72 |
if(jButtonOpen == null) { |
73 |
jButtonOpen = new JButton(); |
74 |
jButtonOpen.setText("");
|
75 |
jButtonOpen.setPreferredSize(new Dimension(20,20)); |
76 |
jButtonOpen.addActionListener(this);
|
77 |
} |
78 |
return jButtonOpen;
|
79 |
} |
80 |
|
81 |
public void actionPerformed(ActionEvent e) { |
82 |
// TODO Auto-generated method stub
|
83 |
if (e.getSource() == this.getButtonOpen()){ |
84 |
add(getOpen(), null);
|
85 |
openChooser.setCurrentDirectory(f); |
86 |
int returnVal = openChooser.showOpenDialog(ESRIpanel.this);
|
87 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
88 |
File file = openChooser.getSelectedFile();
|
89 |
jTextOpen.setText(file.getAbsolutePath()); |
90 |
} |
91 |
} |
92 |
} |
93 |
} |
94 |
|
95 |
class FiltroESRI extends FileFilter{ |
96 |
|
97 |
final static String prj = "prj"; |
98 |
|
99 |
public boolean accept(File f) { |
100 |
if (f.isDirectory()) {
|
101 |
return true; |
102 |
} |
103 |
|
104 |
String s = f.getName();
|
105 |
int i = s.lastIndexOf('.'); |
106 |
|
107 |
if (i > 0 && i < s.length() - 1) { |
108 |
String extension = s.substring(i+1).toLowerCase(); |
109 |
if (prj.equals(extension)){
|
110 |
return true; |
111 |
} else {
|
112 |
return false; |
113 |
} |
114 |
} |
115 |
|
116 |
return false; |
117 |
} |
118 |
|
119 |
public String getDescription() { |
120 |
return "Archivos .prj"; |
121 |
} |
122 |
} |
123 |
|