Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / addlayer / fileopen / solve / gui / FileNotFoundSolvePanel.java @ 24986

History | View | Annotate | Download (7.14 KB)

1
package com.iver.cit.gvsig.addlayer.fileopen.solve.gui;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.FlowLayout;
5
import java.awt.event.ActionListener;
6
import java.io.File;
7

    
8
import javax.swing.JButton;
9
import javax.swing.JFileChooser;
10
import javax.swing.JLabel;
11
import javax.swing.JPanel;
12
import javax.swing.JTextField;
13

    
14
import org.gvsig.gui.beans.AcceptCancelPanel;
15

    
16
import com.hardcode.driverManager.DriverLoadException;
17
import com.iver.andami.PluginServices;
18
import com.iver.andami.ui.mdiManager.IWindow;
19
import com.iver.andami.ui.mdiManager.WindowInfo;
20
import com.iver.cit.gvsig.addlayer.fileopen.solve.FileNotFoundSolve;
21
import com.iver.cit.gvsig.addlayer.fileopen.vectorial.VectorialFileFilter;
22
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
23

    
24
/**
25
 * IWindow to solve error when file not found.
26
 *
27
 * @author Vicente Caballero Navarro
28
 */
29
public class FileNotFoundSolvePanel extends JPanel implements IWindow{
30
        private JPanel jPanel = null;
31
        private JPanel jPanel1 = null;
32
        private JPanel jPanel2 = null;
33
        private JPanel jPanel3 = null;
34
        private JTextField jTextField = null;
35
        private JTextField jTextField1 = null;
36
        private JButton jButton = null;
37
        private AcceptCancelPanel accept = null;
38
        private JFileChooser fileChooser;
39
        private static String lastPath;
40
        private FileNotFoundSolve model;
41
        File myfile = null;
42
        private JPanel jPanel4 = null;
43
        private JLabel jLabel1 = null;
44

    
45
        /**
46
         * This is the default constructor
47
         */
48
        public FileNotFoundSolvePanel(FileNotFoundSolve fnfs) {
49
                super();
50
                this.model=fnfs;
51
                initialize();
52

    
53
        }
54

    
55
        /**
56
         * This method initializes this
57
         *
58
         * @return void
59
         */
60
        private void initialize() {
61
                this.setLayout(new FlowLayout());
62
                this.setSize(426, 174);
63
                this.add(getJPanel(), null);
64
        }
65

    
66
        /**
67
         * This method initializes jPanel
68
         *
69
         * @return javax.swing.JPanel
70
         */
71
        private JPanel getJPanel() {
72
                if (jPanel == null) {
73
                        jPanel = new JPanel();
74
                        jPanel.setLayout(new BorderLayout());
75
                        jPanel.add(getJPanel1(), java.awt.BorderLayout.NORTH);
76
                        jPanel.add(getJPanel2(), java.awt.BorderLayout.CENTER);
77
                        jPanel.add(getJPanel3(), java.awt.BorderLayout.SOUTH);
78
                }
79
                return jPanel;
80
        }
81

    
82
        /**
83
         * This method initializes jPanel1
84
         *
85
         * @return javax.swing.JPanel
86
         */
87
        private JPanel getJPanel1() {
88
                if (jPanel1 == null) {
89
                        jPanel1 = new JPanel();
90
                        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"incorrect_path"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
91
                        jPanel1.add(getJTextField(), null);
92
                }
93
                return jPanel1;
94
        }
95

    
96
        /**
97
         * This method initializes jPanel2
98
         *
99
         * @return javax.swing.JPanel
100
         */
101
        private JPanel getJPanel2() {
102
                if (jPanel2 == null) {
103
                        jPanel2 = new JPanel();
104
                        jPanel2.setLayout(new BorderLayout());
105
                        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"new_file_properties"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
106
                        jPanel2.add(getJPanel4(), java.awt.BorderLayout.CENTER);
107
                }
108
                return jPanel2;
109
        }
110

    
111
        /**
112
         * This method initializes jPanel3
113
         *
114
         * @return javax.swing.JPanel
115
         */
116
        private JPanel getJPanel3() {
117
                if (jPanel3 == null) {
118
                        jPanel3 = new JPanel();
119
                        jPanel3.add(getAcceptCancelPanel());
120
                }
121
                return jPanel3;
122
        }
123
        private AcceptCancelPanel getAcceptCancelPanel() {
124
                if (accept == null) {
125
                        ActionListener okAction, cancelAction;
126
                        okAction = new java.awt.event.ActionListener() {
127
                                public void actionPerformed(java.awt.event.ActionEvent e) {
128
                                        model.createLayer(new File(getJTextField1().getText()));
129
                                        PluginServices.getMDIManager().closeWindow(
130
                                                        FileNotFoundSolvePanel.this);
131
                                }
132
                        };
133
                        cancelAction = new java.awt.event.ActionListener() {
134
                                public void actionPerformed(java.awt.event.ActionEvent e) {
135
                                        PluginServices.getMDIManager().closeWindow(
136
                                                        FileNotFoundSolvePanel.this);
137
                                }
138
                        };
139
                        accept = new AcceptCancelPanel(okAction, cancelAction);
140
                        accept.setPreferredSize(new java.awt.Dimension(300, 300));
141
                        accept.setEnabled(true);
142
                        accept.setVisible(true);
143
                }
144
                return accept;
145
        }
146

    
147
        /**
148
         * This method initializes jTextField
149
         *
150
         * @return javax.swing.JTextField
151
         */
152
        private JTextField getJTextField() {
153
                if (jTextField == null) {
154
                        jTextField = new JTextField();
155
                        jTextField.setPreferredSize(new java.awt.Dimension(400,23));
156
                        jTextField.setEditable(false);
157
                        jTextField.setText(((VectorialFileDriver)model.getDriver()).getFile().getAbsolutePath());
158
                }
159
                return jTextField;
160
        }
161

    
162
        /**
163
         * This method initializes jTextField1
164
         *
165
         * @return javax.swing.JTextField
166
         */
167
        private JTextField getJTextField1() {
168
                if (jTextField1 == null) {
169
                        jTextField1 = new JTextField();
170
                        jTextField1.setPreferredSize(new java.awt.Dimension(300,23));
171
                }
172
                return jTextField1;
173
        }
174

    
175
        /**
176
         * This method initializes jButton
177
         *
178
         * @return javax.swing.JButton
179
         */
180
        private JButton getJButton() {
181
                if (jButton == null) {
182
                        jButton = new JButton();
183
                        jButton.setPreferredSize(new java.awt.Dimension(34,20));
184
                        jButton.setText("...");
185
                        jButton.addActionListener(new java.awt.event.ActionListener() {
186
                                public void actionPerformed(java.awt.event.ActionEvent e) {
187
                                        myfile=addObjects();
188
                                        if (myfile!=null)
189
                                                getJTextField1().setText(myfile.getAbsolutePath());
190
                                }
191
                        });
192
                }
193
                return jButton;
194
        }
195
        public File addObjects() {
196
                fileChooser = new JFileChooser(lastPath);
197
                fileChooser.setMultiSelectionEnabled(false);
198
                fileChooser.setAcceptAllFileFilterUsed(false);
199

    
200
                        try {
201
                                VectorialFileFilter vff=new VectorialFileFilter(model.getDriver().getName());
202
                                fileChooser.addChoosableFileFilter(vff);
203
                                fileChooser.setFileFilter(vff);
204
                        } catch (DriverLoadException e) {
205
                                e.printStackTrace();
206
                        }
207
                int result = fileChooser.showOpenDialog(this);
208

    
209
                File newFile = null;
210
                if (result == JFileChooser.APPROVE_OPTION) {
211
                        lastPath = fileChooser.getCurrentDirectory().getAbsolutePath();
212
                        newFile = fileChooser.getSelectedFile();
213
                        return newFile;
214
                }
215
                return null;
216
        }
217

    
218
        /* (non-Javadoc)
219
         * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
220
         */
221
        public WindowInfo getWindowInfo() {
222
                WindowInfo wi=new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
223
                wi.setTitle(PluginServices.getText(this,"dont_find_the_file")+ ": "+model.getLayer().getName());
224
                return wi;
225
        }
226

    
227
        /**
228
         * This method initializes jPanel4
229
         *
230
         * @return javax.swing.JPanel
231
         */
232
        private JPanel getJPanel4() {
233
                if (jPanel4 == null) {
234
                        jLabel1 = new JLabel();
235
                        jLabel1.setText(PluginServices.getText(this,"path"));
236
                        FlowLayout flowLayout1 = new FlowLayout();
237
                        flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT);
238
                        jPanel4 = new JPanel();
239
                        jPanel4.setLayout(flowLayout1);
240
                        jPanel4.add(jLabel1, null);
241
                        jPanel4.add(getJTextField1(), null);
242
                        jPanel4.add(getJButton(), null);
243
                }
244
                return jPanel4;
245
        }
246

    
247
        public Object getWindowProfile() {
248
                return WindowInfo.DIALOG_PROFILE;
249
        }
250

    
251
}  //  @jve:decl-index=0:visual-constraint="71,10"