Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / addlayer / AddLayerDialog.java @ 31496

History | View | Annotate | Download (6.78 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
//                                        getJPanel().setOkButtonEnabled(!(tabs.getSelectedComponent() instanceof WizardPanel));
101
                                }
102
                        });
103
                }
104

    
105
                return jTabbedPane;
106
        }
107

    
108
        /**
109
         * A?ade en una pesta?a un Jpanel con un titulo
110
         * @param title
111
         * @param panel
112
         */
113
        public void addTab(String title, JPanel panel) {
114
                getJTabbedPane().addTab(title, panel);
115
        }
116

    
117
        /**
118
         * A?ade en una pesta?a un WizardPanel con un titulo
119
         * @param title
120
         * @param panel
121
         */
122
        public void addWizardTab(String title, WizardPanel panel) {
123
                panel.addWizardListener(wizardListener);
124
                getJTabbedPane().addTab(title, panel);
125
        }
126

    
127
        /**
128
         * Devuelve el JPanel seleccionado en las pesta?as
129
         * @return
130
         */
131
        public JPanel getSelectedTab() {
132
                return (JPanel) getJTabbedPane().getSelectedComponent();
133
        }
134

    
135
        /*
136
         * (non-Javadoc)
137
         * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
138
         */
139
        public WindowInfo getWindowInfo() {
140
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
141
                m_viewinfo.setTitle(this.title);
142
                m_viewinfo.setHeight(500);
143
                m_viewinfo.setWidth(520);
144
                return m_viewinfo;
145
        }
146

    
147
        /**
148
   * This method initializes jPanel
149
   * @return javax.swing.JPanel
150
   */
151
        private AcceptCancelPanel getJPanel() {
152
                if (jPanel == null) {
153
                        ActionListener okAction = new ActionListener() {
154
                                public void actionPerformed(ActionEvent e) {
155
                                        accepted = true;
156
                                        closeWindow();
157
                                }
158
                        };
159
                        ActionListener cancelAction = new ActionListener() {
160
                                public void actionPerformed(ActionEvent e) {
161
                                        closeWindow();
162
                                }
163
                        };
164
                        jPanel = new AcceptCancelPanel(okAction, cancelAction);
165
                }
166
                return jPanel;
167
        }
168

    
169
        /**
170
         * @return
171
         */
172
        public boolean isAccepted() {
173
                return accepted;
174
        }
175

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

    
188
                /*
189
                 * (non-Javadoc)
190
                 * @see com.iver.cit.gvsig.gui.wizards.WizardListener#wizardStateChanged(boolean)
191
                 */
192
                public void wizardStateChanged(boolean finishable) {
193
                        getJPanel().setOkButtonEnabled(finishable);
194
                }
195
        }
196

    
197
        /**
198
         * Devuelve la ultima proyecci?n usada
199
         * @return
200
         */
201
        public static IProjection getLastProjection() {
202
                if (proj == null) {
203
                        proj = DefaultProject.getDefaultProjection();
204
                }
205
                return proj;
206
        }
207

    
208
        /**
209
         * Define la ultima proyeccion
210
         * @param proj
211
         */
212
        public static void setLastProjection(IProjection proj) {
213
                AddLayerDialog.proj = proj;
214
        }
215

    
216
        public Object getWindowProfile() {
217
                return WindowInfo.DIALOG_PROFILE;
218
        }
219

    
220
        private void closeWindow() {
221
//                JTabbedPane tabbed = getJTabbedPane();
222
//                for (int i = 0; i < tabbed.getTabCount(); i++) {
223
//                        Component component = tabbed.getComponentAt(i);
224
//                        if (component instanceof WizardPanel) {
225
//                                ((WizardPanel) component).close();
226
//                        }
227
//                }
228
                if (PluginServices.getMainFrame() == null) {
229
                        ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
230
                } else {
231
                        PluginServices.getMDIManager().closeWindow(AddLayerDialog.this);
232
                }
233
        }
234

    
235
        public void dispose() {
236
                JTabbedPane tabbed = getJTabbedPane();
237
                for (int i = 0; i < tabbed.getTabCount(); i++) {
238
                        Component component = tabbed.getComponentAt(i);
239
                        if (component instanceof WizardPanel) {
240
                                ((WizardPanel) component).close();
241
                        }
242
                }
243
                ToolsLocator.getDisposableManager().release(this);
244
        }
245
        
246
}