Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / addlayer / AddLayerDialog.java @ 41563

History | View | Annotate | Download (6.95 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.addlayer;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.Component;
28
import java.awt.Dimension;
29
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionListener;
31

    
32
import javax.swing.JDialog;
33
import javax.swing.JPanel;
34
import javax.swing.JTabbedPane;
35
import javax.swing.event.ChangeEvent;
36
import javax.swing.event.ChangeListener;
37

    
38
import org.cresques.cts.IProjection;
39
import org.gvsig.andami.PluginServices;
40
import org.gvsig.andami.ui.mdiManager.WindowInfo;
41
import org.gvsig.app.gui.WizardPanel;
42
import org.gvsig.app.gui.wizards.WizardListener;
43
import org.gvsig.app.project.DefaultProject;
44
import org.gvsig.gui.beans.AcceptCancelPanel;
45
import org.gvsig.tools.ToolsLocator;
46
import org.gvsig.tools.dispose.Disposable;
47

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

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

    
72
        /**
73
         * Constructor con un nombre de Frame
74
         * @param title
75
         */
76
        public AddLayerDialog(String title) {
77
                this.title = title;
78
                initialize();
79
        }
80

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

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

    
116
                return jTabbedPane;
117
        }
118

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

    
128
        /**
129
         * A?ade en una pesta?a un WizardPanel con un titulo
130
         * @param title
131
         * @param panel
132
         */
133
        public void addWizardTab(String title, WizardPanel panel) {
134
                panel.addWizardListener(wizardListener);
135
                getJTabbedPane().addTab(title, panel);
136
        }
137

    
138
        /**
139
         * Devuelve el JPanel seleccionado en las pesta?as
140
         * @return
141
         */
142
        public JPanel getSelectedTab() {
143
                return (JPanel) getJTabbedPane().getSelectedComponent();
144
        }
145

    
146
        /*
147
         * (non-Javadoc)
148
         * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
149
         */
150
        public WindowInfo getWindowInfo() {
151
                WindowInfo m_viewinfo = new WindowInfo(
152
                        WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
153
                m_viewinfo.setTitle(this.title);
154
                m_viewinfo.setHeight(500);
155
                m_viewinfo.setWidth(530);
156
                return m_viewinfo;
157
        }
158

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

    
182
        /**
183
         * @return
184
         */
185
        public boolean isAccepted() {
186
                return accepted;
187
        }
188

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

    
201
                /*
202
                 * (non-Javadoc)
203
                 * @see com.iver.cit.gvsig.gui.wizards.WizardListener#wizardStateChanged(boolean)
204
                 */
205
                public void wizardStateChanged(boolean finishable) {
206
                        getJPanel().setOkButtonEnabled(finishable);
207
                }
208
        }
209

    
210
        /**
211
         * Devuelve la ultima proyecci?n usada
212
         * @return
213
         */
214
        public static IProjection getLastProjection() {
215
                if (proj == null) {
216
                        proj = DefaultProject.getDefaultProjection();
217
                }
218
                return proj;
219
        }
220

    
221
        /**
222
         * Define la ultima proyeccion
223
         * @param proj
224
         */
225
        public static void setLastProjection(IProjection proj) {
226
                AddLayerDialog.proj = proj;
227
        }
228

    
229
        public Object getWindowProfile() {
230
                return WindowInfo.DIALOG_PROFILE;
231
        }
232

    
233
        private void closeWindow() {
234
                if (PluginServices.getMainFrame() == null) {
235
                        ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
236
                } else {
237
                        PluginServices.getMDIManager().closeWindow(AddLayerDialog.this);
238
                }
239
        }
240

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