svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / addlayer / AddLayerDialog.java @ 43891
History | View | Annotate | Download (8.28 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2017 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.app.addlayer; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Component; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
|
31 |
import javax.swing.JDialog; |
32 |
import javax.swing.JPanel; |
33 |
import javax.swing.JTabbedPane; |
34 |
import javax.swing.event.ChangeEvent; |
35 |
import javax.swing.event.ChangeListener; |
36 |
|
37 |
import org.cresques.cts.IProjection; |
38 |
import org.gvsig.andami.PluginServices; |
39 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
40 |
import org.gvsig.app.gui.WizardPanel; |
41 |
import org.gvsig.app.gui.wizards.WizardListener; |
42 |
import org.gvsig.app.project.DefaultProject; |
43 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
44 |
import org.gvsig.tools.ToolsLocator; |
45 |
import org.gvsig.tools.dispose.Disposable; |
46 |
import org.slf4j.Logger; |
47 |
import org.slf4j.LoggerFactory; |
48 |
|
49 |
/**
|
50 |
* Frame del cuadro de dialogo que contendra los tabs de aperturas de ficheros
|
51 |
*
|
52 |
* @version 04/09/2007
|
53 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
54 |
*/
|
55 |
public class AddLayerDialog extends JPanel implements org.gvsig.andami.ui.mdiManager.IWindow, Disposable { |
56 |
|
57 |
private static Logger logger = LoggerFactory.getLogger(AddLayerDialog.class); |
58 |
static private IProjection proj = null; |
59 |
private JTabbedPane jTabbedPane = null; |
60 |
private AcceptCancelPanel jPanel = null; |
61 |
private boolean accepted = false; |
62 |
private String title = PluginServices.getText(this, "add_layer"); |
63 |
private final WizardListener wizardListener = new DialogWizardListener(); |
64 |
|
65 |
/**
|
66 |
* Creates a new FOpenDialog object.
|
67 |
*/
|
68 |
public AddLayerDialog() {
|
69 |
initialize(); |
70 |
} |
71 |
|
72 |
/**
|
73 |
* Constructor con un nombre de Frame
|
74 |
*
|
75 |
* @param title
|
76 |
*/
|
77 |
public AddLayerDialog(String title) { |
78 |
this.title = title;
|
79 |
initialize(); |
80 |
} |
81 |
|
82 |
/**
|
83 |
* This method initializes this
|
84 |
*/
|
85 |
private void initialize() { |
86 |
ToolsLocator.getDisposableManager().bind(this);
|
87 |
|
88 |
this.setLayout(new BorderLayout()); |
89 |
this.setSize(523, 385); |
90 |
this.setPreferredSize(new Dimension(523, 385)); |
91 |
this.add(getJTabbedPane(), BorderLayout.CENTER); |
92 |
this.add(getJPanel(), BorderLayout.SOUTH); |
93 |
} |
94 |
|
95 |
/**
|
96 |
* This method initializes jTabbedPane
|
97 |
*
|
98 |
* @return javax.swing.JTabbedPane
|
99 |
*/
|
100 |
private JTabbedPane getJTabbedPane() { |
101 |
if (jTabbedPane == null) { |
102 |
jTabbedPane = new JTabbedPane(); |
103 |
jTabbedPane.setBounds(0, 0, getWindowInfo().getWidth() - 10, getWindowInfo().getHeight() - 10); |
104 |
jTabbedPane.addChangeListener(new ChangeListener() { |
105 |
@Override
|
106 |
public void stateChanged(ChangeEvent e) { |
107 |
JTabbedPane tabs = (JTabbedPane) e.getSource(); |
108 |
Component sel_tab = tabs.getSelectedComponent();
|
109 |
if (sel_tab instanceof WizardPanel) { |
110 |
WizardPanel wipa = (WizardPanel) sel_tab; |
111 |
wizardListener.wizardStateChanged( |
112 |
wipa.areSettingsValid()); |
113 |
} |
114 |
// getJPanel().setOkButtonEnabled(!(tabs.getSelectedComponent() instanceof WizardPanel));
|
115 |
} |
116 |
}); |
117 |
} |
118 |
|
119 |
return jTabbedPane;
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* A?ade en una pesta?a un Jpanel con un titulo
|
124 |
*
|
125 |
* @param title
|
126 |
* @param panel
|
127 |
*/
|
128 |
public void addTab(String title, JPanel panel) { |
129 |
getJTabbedPane().addTab(title, panel); |
130 |
} |
131 |
|
132 |
/**
|
133 |
* A?ade en una pesta?a un WizardPanel con un titulo
|
134 |
*
|
135 |
* @param title
|
136 |
* @param panel
|
137 |
*/
|
138 |
public void addWizardTab(String title, WizardPanel panel) { |
139 |
panel.addWizardListener(wizardListener); |
140 |
getJTabbedPane().addTab(title, panel); |
141 |
} |
142 |
|
143 |
/**
|
144 |
* Devuelve el JPanel seleccionado en las pesta?as
|
145 |
*
|
146 |
* @return
|
147 |
*/
|
148 |
public JPanel getSelectedTab() { |
149 |
return (JPanel) getJTabbedPane().getSelectedComponent(); |
150 |
} |
151 |
|
152 |
/*
|
153 |
* (non-Javadoc)
|
154 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
155 |
*/
|
156 |
@Override
|
157 |
public WindowInfo getWindowInfo() {
|
158 |
WindowInfo m_viewinfo = new WindowInfo(
|
159 |
WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE); |
160 |
m_viewinfo.setTitle(this.title);
|
161 |
m_viewinfo.setHeight(500);
|
162 |
m_viewinfo.setWidth(530);
|
163 |
return m_viewinfo;
|
164 |
} |
165 |
|
166 |
public void updateOkButtonState() { |
167 |
if (this.getSelectedTab() instanceof WizardPanel) { |
168 |
WizardPanel wp = (WizardPanel) this.getSelectedTab();
|
169 |
getJPanel().setOkButtonEnabled(wp.areSettingsValid()); |
170 |
} |
171 |
} |
172 |
|
173 |
/**
|
174 |
* This method initializes jPanel
|
175 |
*
|
176 |
* @return javax.swing.JPanel
|
177 |
*/
|
178 |
private AcceptCancelPanel getJPanel() {
|
179 |
if (jPanel == null) { |
180 |
ActionListener okAction = new ActionListener() { |
181 |
@Override
|
182 |
public void actionPerformed(ActionEvent e) { |
183 |
accepted = true;
|
184 |
closeWindow(); |
185 |
} |
186 |
}; |
187 |
ActionListener cancelAction = new ActionListener() { |
188 |
@Override
|
189 |
public void actionPerformed(ActionEvent e) { |
190 |
closeWindow(); |
191 |
} |
192 |
}; |
193 |
jPanel = new AcceptCancelPanel(okAction, cancelAction);
|
194 |
jPanel.setOkButtonEnabled(false);
|
195 |
} |
196 |
return jPanel;
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* @return
|
201 |
*/
|
202 |
public boolean isAccepted() { |
203 |
return accepted;
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* Listener para el Wizard de apertura de fichero
|
208 |
*
|
209 |
* @version 05/09/2007
|
210 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
211 |
*/
|
212 |
public class DialogWizardListener implements WizardListener { |
213 |
/*
|
214 |
* (non-Javadoc)
|
215 |
* @see com.iver.cit.gvsig.gui.wizards.WizardListener#error(java.lang.Exception)
|
216 |
*/
|
217 |
|
218 |
@Override
|
219 |
public void error(Exception e) { |
220 |
} |
221 |
|
222 |
/*
|
223 |
* (non-Javadoc)
|
224 |
* @see com.iver.cit.gvsig.gui.wizards.WizardListener#wizardStateChanged(boolean)
|
225 |
*/
|
226 |
@Override
|
227 |
public void wizardStateChanged(boolean finishable) { |
228 |
getJPanel().setOkButtonEnabled(finishable); |
229 |
} |
230 |
} |
231 |
|
232 |
// /**
|
233 |
// * Devuelve la ultima proyecci?n usada
|
234 |
// *
|
235 |
// * @return
|
236 |
// */
|
237 |
// public static IProjection getLastProjection() {
|
238 |
// if (proj == null) {
|
239 |
// proj = DefaultProject.getDefaultProjection();
|
240 |
// }
|
241 |
// return proj;
|
242 |
// }
|
243 |
//
|
244 |
// /**
|
245 |
// * Define la ultima proyeccion
|
246 |
// *
|
247 |
// * @param proj
|
248 |
// */
|
249 |
// public static void setLastProjection(IProjection proj) {
|
250 |
// AddLayerDialog.proj = proj;
|
251 |
// }
|
252 |
|
253 |
@Override
|
254 |
public Object getWindowProfile() { |
255 |
return WindowInfo.DIALOG_PROFILE;
|
256 |
} |
257 |
|
258 |
private void closeWindow() { |
259 |
if (PluginServices.getMainFrame() == null) { |
260 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
261 |
} else {
|
262 |
PluginServices.getMDIManager().closeWindow(AddLayerDialog.this); |
263 |
} |
264 |
} |
265 |
|
266 |
@Override
|
267 |
public void dispose() { |
268 |
JTabbedPane tabbed = getJTabbedPane();
|
269 |
for (int i = 0; i < tabbed.getTabCount(); i++) { |
270 |
Component component = tabbed.getComponentAt(i);
|
271 |
if (component instanceof WizardPanel) { |
272 |
((WizardPanel) component).close(); |
273 |
} |
274 |
} |
275 |
ToolsLocator.getDisposableManager().release(this);
|
276 |
} |
277 |
|
278 |
} |