Statistics
| Revision:

root / tags / v2_0_0_Build_2050 / applications / appgvSIG / src / org / gvsig / app / addlayer / AddLayerDialog.java @ 38653

History | View | Annotate | Download (7.04 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.app.addlayer;
20

    
21
import java.awt.BorderLayout;
22
import java.awt.Component;
23
import java.awt.Dimension;
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
26

    
27
import javax.swing.JDialog;
28
import javax.swing.JPanel;
29
import javax.swing.JTabbedPane;
30
import javax.swing.event.ChangeEvent;
31
import javax.swing.event.ChangeListener;
32

    
33
import org.cresques.cts.IProjection;
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.andami.ui.mdiManager.WindowInfo;
36
import org.gvsig.app.gui.WizardPanel;
37
import org.gvsig.app.gui.wizards.WizardListener;
38
import org.gvsig.app.project.DefaultProject;
39
import org.gvsig.gui.beans.AcceptCancelPanel;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.dispose.Disposable;
42

    
43
/**
44
 * Frame del cuadro de dialogo que contendra los tabs de aperturas de ficheros
45
 *
46
 * @version 04/09/2007
47
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
48
 */
49
public class AddLayerDialog extends JPanel implements org.gvsig.andami.ui.mdiManager.IWindow , Disposable{
50
        static private IProjection proj           = null;
51
        private JTabbedPane        jTabbedPane    = null;
52
        private AcceptCancelPanel  jPanel         = null;
53
        private boolean            accepted       = false;
54
        private String             title          = PluginServices.getText(this, "add_layer");
55
        private WizardListener     wizardListener = new DialogWizardListener();
56

    
57
        /**
58
   * Creates a new FOpenDialog object.
59
   * @param view Vista que vamos a refrescar
60
   * @param mapControl MapControl que recibe la capa (te puede interesar
61
   *          a?adirla al principal o al Overview.
62
   */
63
        public AddLayerDialog() {
64
                initialize();
65
        }
66

    
67
        /**
68
         * Constructor con un nombre de Frame
69
         * @param title
70
         */
71
        public AddLayerDialog(String title) {
72
                this.title = title;
73
                initialize();
74
        }
75

    
76
        /**
77
   * This method initializes this
78
   */
79
        private void initialize() {
80
                ToolsLocator.getDisposableManager().bind(this);
81
                
82
                this.setLayout(new BorderLayout());
83
                this.setSize(523, 385);
84
                this.setPreferredSize(new Dimension(523, 385));
85
                this.add(getJTabbedPane(), BorderLayout.CENTER);
86
                this.add(getJPanel(), BorderLayout.SOUTH);
87
        }
88

    
89
        /**
90
   * This method initializes jTabbedPane
91
   * @return javax.swing.JTabbedPane
92
   */
93
        private JTabbedPane getJTabbedPane() {
94
                if (jTabbedPane == null) {
95
                        jTabbedPane = new JTabbedPane();
96
                        jTabbedPane.setBounds(0, 0, getWindowInfo().getWidth() - 10, getWindowInfo().getHeight() - 10);
97
                        jTabbedPane.addChangeListener(new ChangeListener() {
98
                                public void stateChanged(ChangeEvent e) {
99
                                        JTabbedPane tabs = (JTabbedPane) e.getSource();
100
                                        Component sel_tab = tabs.getSelectedComponent();
101
                                        if (sel_tab instanceof WizardPanel) {
102
                                            WizardPanel wipa = (WizardPanel) sel_tab;
103
                                            wizardListener.wizardStateChanged(
104
                                                wipa.areSettingsValid());
105
                                        }
106
                                        // getJPanel().setOkButtonEnabled(!(tabs.getSelectedComponent() instanceof WizardPanel));
107
                                }
108
                        });
109
                }
110

    
111
                return jTabbedPane;
112
        }
113

    
114
        /**
115
         * A?ade en una pesta?a un Jpanel con un titulo
116
         * @param title
117
         * @param panel
118
         */
119
        public void addTab(String title, JPanel panel) {
120
                getJTabbedPane().addTab(title, panel);
121
        }
122

    
123
        /**
124
         * A?ade en una pesta?a un WizardPanel con un titulo
125
         * @param title
126
         * @param panel
127
         */
128
        public void addWizardTab(String title, WizardPanel panel) {
129
                panel.addWizardListener(wizardListener);
130
                getJTabbedPane().addTab(title, panel);
131
        }
132

    
133
        /**
134
         * Devuelve el JPanel seleccionado en las pesta?as
135
         * @return
136
         */
137
        public JPanel getSelectedTab() {
138
                return (JPanel) getJTabbedPane().getSelectedComponent();
139
        }
140

    
141
        /*
142
         * (non-Javadoc)
143
         * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
144
         */
145
        public WindowInfo getWindowInfo() {
146
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
147
                m_viewinfo.setTitle(this.title);
148
                m_viewinfo.setHeight(500);
149
                m_viewinfo.setWidth(520);
150
                return m_viewinfo;
151
        }
152

    
153
        /**
154
   * This method initializes jPanel
155
   * @return javax.swing.JPanel
156
   */
157
        private AcceptCancelPanel getJPanel() {
158
                if (jPanel == null) {
159
                        ActionListener okAction = new ActionListener() {
160
                                public void actionPerformed(ActionEvent e) {
161
                                        accepted = true;
162
                                        closeWindow();
163
                                }
164
                        };
165
                        ActionListener cancelAction = new ActionListener() {
166
                                public void actionPerformed(ActionEvent e) {
167
                                        closeWindow();
168
                                }
169
                        };
170
                        jPanel = new AcceptCancelPanel(okAction, cancelAction);
171
                        jPanel.setOkButtonEnabled(false);
172
                }
173
                return jPanel;
174
        }
175

    
176
        /**
177
         * @return
178
         */
179
        public boolean isAccepted() {
180
                return accepted;
181
        }
182

    
183
        /**
184
         * Listener para el Wizard de apertura de fichero
185
         * @version 05/09/2007
186
         * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
187
         */
188
        public class DialogWizardListener implements WizardListener {
189
                /*
190
                 * (non-Javadoc)
191
                 * @see com.iver.cit.gvsig.gui.wizards.WizardListener#error(java.lang.Exception)
192
                 */
193
                public void error(Exception e) {}
194

    
195
                /*
196
                 * (non-Javadoc)
197
                 * @see com.iver.cit.gvsig.gui.wizards.WizardListener#wizardStateChanged(boolean)
198
                 */
199
                public void wizardStateChanged(boolean finishable) {
200
                        getJPanel().setOkButtonEnabled(finishable);
201
                }
202
        }
203

    
204
        /**
205
         * Devuelve la ultima proyecci?n usada
206
         * @return
207
         */
208
        public static IProjection getLastProjection() {
209
                if (proj == null) {
210
                        proj = DefaultProject.getDefaultProjection();
211
                }
212
                return proj;
213
        }
214

    
215
        /**
216
         * Define la ultima proyeccion
217
         * @param proj
218
         */
219
        public static void setLastProjection(IProjection proj) {
220
                AddLayerDialog.proj = proj;
221
        }
222

    
223
        public Object getWindowProfile() {
224
                return WindowInfo.DIALOG_PROFILE;
225
        }
226

    
227
        private void closeWindow() {
228
//                JTabbedPane tabbed = getJTabbedPane();
229
//                for (int i = 0; i < tabbed.getTabCount(); i++) {
230
//                        Component component = tabbed.getComponentAt(i);
231
//                        if (component instanceof WizardPanel) {
232
//                                ((WizardPanel) component).close();
233
//                        }
234
//                }
235
                if (PluginServices.getMainFrame() == null) {
236
                        ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
237
                } else {
238
                        PluginServices.getMDIManager().closeWindow(AddLayerDialog.this);
239
                }
240
        }
241

    
242
        public void dispose() {
243
                JTabbedPane tabbed = getJTabbedPane();
244
                for (int i = 0; i < tabbed.getTabCount(); i++) {
245
                        Component component = tabbed.getComponentAt(i);
246
                        if (component instanceof WizardPanel) {
247
                                ((WizardPanel) component).close();
248
                        }
249
                }
250
                ToolsLocator.getDisposableManager().release(this);
251
        }
252
        
253
}