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 @ 45672
History | View | Annotate | Download (8.34 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.gvsig.tools.swing.api.ToolsSwingUtils; |
47 |
import org.slf4j.Logger; |
48 |
import org.slf4j.LoggerFactory; |
49 |
|
50 |
/**
|
51 |
* Frame del cuadro de dialogo que contendra los tabs de aperturas de ficheros
|
52 |
*
|
53 |
* @version 04/09/2007
|
54 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
55 |
*/
|
56 |
public class AddLayerDialog extends JPanel implements org.gvsig.andami.ui.mdiManager.IWindow, Disposable { |
57 |
|
58 |
private static Logger logger = LoggerFactory.getLogger(AddLayerDialog.class); |
59 |
static private IProjection proj = null; |
60 |
private JTabbedPane jTabbedPane = null; |
61 |
private AcceptCancelPanel jPanel = null; |
62 |
private boolean accepted = false; |
63 |
private String title = PluginServices.getText(this, "add_layer"); |
64 |
private final WizardListener wizardListener = new DialogWizardListener(); |
65 |
|
66 |
/**
|
67 |
* Creates a new FOpenDialog object.
|
68 |
*/
|
69 |
public AddLayerDialog() {
|
70 |
initialize(); |
71 |
} |
72 |
|
73 |
/**
|
74 |
* Constructor con un nombre de Frame
|
75 |
*
|
76 |
* @param title
|
77 |
*/
|
78 |
public AddLayerDialog(String title) { |
79 |
this.title = title;
|
80 |
initialize(); |
81 |
} |
82 |
|
83 |
/**
|
84 |
* This method initializes this
|
85 |
*/
|
86 |
private void initialize() { |
87 |
ToolsLocator.getDisposableManager().bind(this);
|
88 |
|
89 |
this.setLayout(new BorderLayout()); |
90 |
this.setSize(523, 385); |
91 |
this.setPreferredSize(new Dimension(523, 385)); |
92 |
this.add(getJTabbedPane(), BorderLayout.CENTER); |
93 |
this.add(getJPanel(), BorderLayout.SOUTH); |
94 |
} |
95 |
|
96 |
/**
|
97 |
* This method initializes jTabbedPane
|
98 |
*
|
99 |
* @return javax.swing.JTabbedPane
|
100 |
*/
|
101 |
private JTabbedPane getJTabbedPane() { |
102 |
if (jTabbedPane == null) { |
103 |
jTabbedPane = new JTabbedPane(); |
104 |
jTabbedPane.setBounds(0, 0, getWindowInfo().getWidth() - 10, getWindowInfo().getHeight() - 10); |
105 |
jTabbedPane.addChangeListener(new ChangeListener() { |
106 |
@Override
|
107 |
public void stateChanged(ChangeEvent e) { |
108 |
JTabbedPane tabs = (JTabbedPane) e.getSource(); |
109 |
Component sel_tab = tabs.getSelectedComponent();
|
110 |
if (sel_tab instanceof WizardPanel) { |
111 |
WizardPanel wipa = (WizardPanel) sel_tab; |
112 |
wizardListener.wizardStateChanged( |
113 |
wipa.areSettingsValid()); |
114 |
} |
115 |
// getJPanel().setOkButtonEnabled(!(tabs.getSelectedComponent() instanceof WizardPanel));
|
116 |
} |
117 |
}); |
118 |
} |
119 |
|
120 |
return jTabbedPane;
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* A?ade en una pesta?a un Jpanel con un titulo
|
125 |
*
|
126 |
* @param title
|
127 |
* @param panel
|
128 |
*/
|
129 |
public void addTab(String title, JPanel panel) { |
130 |
getJTabbedPane().addTab(title, panel); |
131 |
} |
132 |
|
133 |
/**
|
134 |
* A?ade en una pesta?a un WizardPanel con un titulo
|
135 |
*
|
136 |
* @param title
|
137 |
* @param panel
|
138 |
*/
|
139 |
public void addWizardTab(String title, WizardPanel panel) { |
140 |
panel.addWizardListener(wizardListener); |
141 |
getJTabbedPane().addTab(title, panel); |
142 |
} |
143 |
|
144 |
/**
|
145 |
* Devuelve el JPanel seleccionado en las pesta?as
|
146 |
*
|
147 |
* @return
|
148 |
*/
|
149 |
public JPanel getSelectedTab() { |
150 |
return (JPanel) getJTabbedPane().getSelectedComponent(); |
151 |
} |
152 |
|
153 |
/*
|
154 |
* (non-Javadoc)
|
155 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
156 |
*/
|
157 |
@Override
|
158 |
public WindowInfo getWindowInfo() {
|
159 |
WindowInfo m_viewinfo = new WindowInfo(
|
160 |
WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE); |
161 |
m_viewinfo.setTitle(this.title);
|
162 |
m_viewinfo.setHeight(ToolsSwingUtils.rows2px(30));
|
163 |
m_viewinfo.setWidth(ToolsSwingUtils.cols2px(70));
|
164 |
return m_viewinfo;
|
165 |
} |
166 |
|
167 |
public void updateOkButtonState() { |
168 |
if (this.getSelectedTab() instanceof WizardPanel) { |
169 |
WizardPanel wp = (WizardPanel) this.getSelectedTab();
|
170 |
getJPanel().setOkButtonEnabled(wp.areSettingsValid()); |
171 |
} |
172 |
} |
173 |
|
174 |
/**
|
175 |
* This method initializes jPanel
|
176 |
*
|
177 |
* @return javax.swing.JPanel
|
178 |
*/
|
179 |
private AcceptCancelPanel getJPanel() {
|
180 |
if (jPanel == null) { |
181 |
ActionListener okAction = new ActionListener() { |
182 |
@Override
|
183 |
public void actionPerformed(ActionEvent e) { |
184 |
accepted = true;
|
185 |
closeWindow(); |
186 |
} |
187 |
}; |
188 |
ActionListener cancelAction = new ActionListener() { |
189 |
@Override
|
190 |
public void actionPerformed(ActionEvent e) { |
191 |
closeWindow(); |
192 |
} |
193 |
}; |
194 |
jPanel = new AcceptCancelPanel(okAction, cancelAction);
|
195 |
jPanel.setOkButtonEnabled(false);
|
196 |
} |
197 |
return jPanel;
|
198 |
} |
199 |
|
200 |
/**
|
201 |
* @return
|
202 |
*/
|
203 |
public boolean isAccepted() { |
204 |
return accepted;
|
205 |
} |
206 |
|
207 |
/**
|
208 |
* Listener para el Wizard de apertura de fichero
|
209 |
*
|
210 |
* @version 05/09/2007
|
211 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
212 |
*/
|
213 |
public class DialogWizardListener implements WizardListener { |
214 |
/*
|
215 |
* (non-Javadoc)
|
216 |
* @see com.iver.cit.gvsig.gui.wizards.WizardListener#error(java.lang.Exception)
|
217 |
*/
|
218 |
|
219 |
@Override
|
220 |
public void error(Exception e) { |
221 |
} |
222 |
|
223 |
/*
|
224 |
* (non-Javadoc)
|
225 |
* @see com.iver.cit.gvsig.gui.wizards.WizardListener#wizardStateChanged(boolean)
|
226 |
*/
|
227 |
@Override
|
228 |
public void wizardStateChanged(boolean finishable) { |
229 |
getJPanel().setOkButtonEnabled(finishable); |
230 |
} |
231 |
} |
232 |
|
233 |
/**
|
234 |
* Devuelve la ultima proyecci?n usada
|
235 |
*
|
236 |
* @return
|
237 |
*/
|
238 |
public static IProjection getLastProjection() { |
239 |
if (proj == null) { |
240 |
proj = DefaultProject.getDefaultProjection(); |
241 |
} |
242 |
return proj;
|
243 |
} |
244 |
|
245 |
/**
|
246 |
* Define la ultima proyeccion
|
247 |
*
|
248 |
* @param proj
|
249 |
*/
|
250 |
public static void setLastProjection(IProjection proj) { |
251 |
AddLayerDialog.proj = proj; |
252 |
} |
253 |
|
254 |
@Override
|
255 |
public Object getWindowProfile() { |
256 |
return WindowInfo.DIALOG_PROFILE;
|
257 |
} |
258 |
|
259 |
private void closeWindow() { |
260 |
if (PluginServices.getMainFrame() == null) { |
261 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
262 |
} else {
|
263 |
PluginServices.getMDIManager().closeWindow(AddLayerDialog.this); |
264 |
} |
265 |
} |
266 |
|
267 |
@Override
|
268 |
public void dispose() { |
269 |
JTabbedPane tabbed = getJTabbedPane();
|
270 |
for (int i = 0; i < tabbed.getTabCount(); i++) { |
271 |
Component component = tabbed.getComponentAt(i);
|
272 |
if (component instanceof WizardPanel) { |
273 |
((WizardPanel) component).close(); |
274 |
} |
275 |
} |
276 |
ToolsLocator.getDisposableManager().release(this);
|
277 |
} |
278 |
|
279 |
} |