Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / addlayer / AddLayerDialog.java @ 15673

History | View | Annotate | Download (6.2 KB)

1 13541 bsanchez
/* 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 com.iver.cit.gvsig.addlayer;
20
21
import java.awt.BorderLayout;
22
import java.awt.Dimension;
23
import java.awt.event.ActionEvent;
24
import java.awt.event.ActionListener;
25
26
import javax.swing.JDialog;
27
import javax.swing.JPanel;
28
import javax.swing.JTabbedPane;
29
import javax.swing.event.ChangeEvent;
30
import javax.swing.event.ChangeListener;
31
32
import org.cresques.cts.IProjection;
33
import org.gvsig.gui.beans.AcceptCancelPanel;
34
35
import com.iver.andami.PluginServices;
36
import com.iver.andami.ui.mdiManager.IWindow;
37
import com.iver.andami.ui.mdiManager.WindowInfo;
38
import com.iver.cit.gvsig.gui.WizardPanel;
39
import com.iver.cit.gvsig.gui.wizards.WizardListener;
40
import com.iver.cit.gvsig.project.Project;
41
/**
42
 * Frame del cuadro de dialogo que contendra los tabs de aperturas de ficheros
43
 *
44
 * @version 04/09/2007
45
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
46
 */
47
public class AddLayerDialog extends JPanel implements com.iver.andami.ui.mdiManager.IWindow {
48
        static private IProjection proj           = null;
49
        private JTabbedPane        jTabbedPane    = null;
50
        private AcceptCancelPanel  jPanel         = null;
51
        private boolean            accepted       = false;
52
        private String             title          = PluginServices.getText(this, "add_layer");
53
        private WizardListener     wizardListener = new DialogWizardListener();
54
55
        /**
56
   * Creates a new FOpenDialog object.
57
   * @param view Vista que vamos a refrescar
58
   * @param mapControl MapControl que recibe la capa (te puede interesar
59
   *          a?adirla al principal o al Overview.
60
   */
61
        public AddLayerDialog() {
62
                initialize();
63
        }
64
65
        /**
66
         * Constructor con un nombre de Frame
67
         * @param title
68
         */
69
        public AddLayerDialog(String title) {
70
                this.title = title;
71
                initialize();
72
        }
73
74
        /**
75
   * This method initializes this
76
   */
77
        private void initialize() {
78
                this.setLayout(new BorderLayout());
79
                this.setSize(523, 385);
80
                this.setPreferredSize(new Dimension(523, 385));
81
                this.add(getJTabbedPane(), BorderLayout.CENTER);
82
                this.add(getJPanel(), BorderLayout.SOUTH);
83
        }
84
85
        /**
86
   * This method initializes jTabbedPane
87
   * @return javax.swing.JTabbedPane
88
   */
89
        private JTabbedPane getJTabbedPane() {
90
                if (jTabbedPane == null) {
91
                        jTabbedPane = new JTabbedPane();
92
                        jTabbedPane.setBounds(0, 0, getWindowInfo().getWidth() - 10, getWindowInfo().getHeight() - 10);
93
                        jTabbedPane.addChangeListener(new ChangeListener() {
94
                                public void stateChanged(ChangeEvent e) {
95
                                        JTabbedPane tabs = (JTabbedPane) e.getSource();
96
                                        getJPanel().setOkButtonEnabled(!(tabs.getSelectedComponent() instanceof WizardPanel));
97
                                }
98
                        });
99
                }
100
101
                return jTabbedPane;
102
        }
103
104
        /**
105
         * A?ade en una pesta?a un Jpanel con un titulo
106
         * @param title
107
         * @param panel
108
         */
109
        public void addTab(String title, JPanel panel) {
110
                getJTabbedPane().addTab(title, panel);
111
        }
112
113
        /**
114
         * A?ade en una pesta?a un WizardPanel con un titulo
115
         * @param title
116
         * @param panel
117
         */
118
        public void addWizardTab(String title, WizardPanel panel) {
119
                panel.addWizardListener(wizardListener);
120
                getJTabbedPane().addTab(title, panel);
121
        }
122
123
        /**
124
         * Devuelve el JPanel seleccionado en las pesta?as
125
         * @return
126
         */
127
        public JPanel getSelectedTab() {
128
                return (JPanel) getJTabbedPane().getSelectedComponent();
129
        }
130
131
        /*
132
         * (non-Javadoc)
133
         * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
134
         */
135
        public WindowInfo getWindowInfo() {
136
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
137
                m_viewinfo.setTitle(this.title);
138
                m_viewinfo.setHeight(500);
139
                m_viewinfo.setWidth(520);
140
                return m_viewinfo;
141
        }
142
143
        /**
144
   * This method initializes jPanel
145
   * @return javax.swing.JPanel
146
   */
147
        private AcceptCancelPanel getJPanel() {
148
                if (jPanel == null) {
149
                        ActionListener okAction = new ActionListener() {
150
                                public void actionPerformed(ActionEvent e) {
151
                                        accepted = true;
152
                                        if (PluginServices.getMainFrame() == null) {
153
                                                ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
154
                                        } else {
155
                                                PluginServices.getMDIManager().closeWindow((IWindow) AddLayerDialog.this);
156
                                        }
157
                                }
158
                        };
159
                        ActionListener cancelAction = new ActionListener() {
160
                                public void actionPerformed(ActionEvent e) {
161
                                        if (PluginServices.getMainFrame() != null) {
162
                                                PluginServices.getMDIManager().closeWindow((IWindow) AddLayerDialog.this);
163
                                        } else {
164
                                                ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
165
                                        }
166
                                }
167
                        };
168
                        jPanel = new AcceptCancelPanel(okAction, cancelAction);
169
                }
170
                return jPanel;
171
        }
172
173
        /**
174
         * @return
175
         */
176
        public boolean isAccepted() {
177
                return accepted;
178
        }
179
180
        /**
181
         * Listener para el Wizard de apertura de fichero
182
         * @version 05/09/2007
183
         * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
184
         */
185
        public class DialogWizardListener implements WizardListener {
186
                /*
187
                 * (non-Javadoc)
188
                 * @see com.iver.cit.gvsig.gui.wizards.WizardListener#error(java.lang.Exception)
189
                 */
190
                public void error(Exception e) {}
191
192
                /*
193
                 * (non-Javadoc)
194
                 * @see com.iver.cit.gvsig.gui.wizards.WizardListener#wizardStateChanged(boolean)
195
                 */
196
                public void wizardStateChanged(boolean finishable) {
197
                        getJPanel().setOkButtonEnabled(finishable);
198
                }
199
        }
200
201
        /**
202
         * Devuelve la ultima proyecci?n usada
203
         * @return
204
         */
205
        public static IProjection getLastProjection() {
206
                if (proj == null)
207
                        proj = Project.getDefaultProjection();
208
                return proj;
209
        }
210
211
        /**
212
         * Define la ultima proyeccion
213
         * @param proj
214
         */
215
        public static void setLastProjection(IProjection proj) {
216
                AddLayerDialog.proj = proj;
217
        }
218
}