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 @ 40558
History | View | Annotate | Download (7.15 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(WindowInfo.MODALDIALOG);
|
152 |
m_viewinfo.setTitle(this.title);
|
153 |
m_viewinfo.setHeight(500);
|
154 |
m_viewinfo.setWidth(530);
|
155 |
return m_viewinfo;
|
156 |
} |
157 |
|
158 |
/**
|
159 |
* This method initializes jPanel
|
160 |
* @return javax.swing.JPanel
|
161 |
*/
|
162 |
private AcceptCancelPanel getJPanel() {
|
163 |
if (jPanel == null) { |
164 |
ActionListener okAction = new ActionListener() { |
165 |
public void actionPerformed(ActionEvent e) { |
166 |
accepted = true;
|
167 |
closeWindow(); |
168 |
} |
169 |
}; |
170 |
ActionListener cancelAction = new ActionListener() { |
171 |
public void actionPerformed(ActionEvent e) { |
172 |
closeWindow(); |
173 |
} |
174 |
}; |
175 |
jPanel = new AcceptCancelPanel(okAction, cancelAction);
|
176 |
jPanel.setOkButtonEnabled(false);
|
177 |
} |
178 |
return jPanel;
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* @return
|
183 |
*/
|
184 |
public boolean isAccepted() { |
185 |
return accepted;
|
186 |
} |
187 |
|
188 |
/**
|
189 |
* Listener para el Wizard de apertura de fichero
|
190 |
* @version 05/09/2007
|
191 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
192 |
*/
|
193 |
public class DialogWizardListener implements WizardListener { |
194 |
/*
|
195 |
* (non-Javadoc)
|
196 |
* @see com.iver.cit.gvsig.gui.wizards.WizardListener#error(java.lang.Exception)
|
197 |
*/
|
198 |
public void error(Exception e) {} |
199 |
|
200 |
/*
|
201 |
* (non-Javadoc)
|
202 |
* @see com.iver.cit.gvsig.gui.wizards.WizardListener#wizardStateChanged(boolean)
|
203 |
*/
|
204 |
public void wizardStateChanged(boolean finishable) { |
205 |
getJPanel().setOkButtonEnabled(finishable); |
206 |
} |
207 |
} |
208 |
|
209 |
/**
|
210 |
* Devuelve la ultima proyecci?n usada
|
211 |
* @return
|
212 |
*/
|
213 |
public static IProjection getLastProjection() { |
214 |
if (proj == null) { |
215 |
proj = DefaultProject.getDefaultProjection(); |
216 |
} |
217 |
return proj;
|
218 |
} |
219 |
|
220 |
/**
|
221 |
* Define la ultima proyeccion
|
222 |
* @param proj
|
223 |
*/
|
224 |
public static void setLastProjection(IProjection proj) { |
225 |
AddLayerDialog.proj = proj; |
226 |
} |
227 |
|
228 |
public Object getWindowProfile() { |
229 |
return WindowInfo.DIALOG_PROFILE;
|
230 |
} |
231 |
|
232 |
private void closeWindow() { |
233 |
// JTabbedPane tabbed = getJTabbedPane();
|
234 |
// for (int i = 0; i < tabbed.getTabCount(); i++) {
|
235 |
// Component component = tabbed.getComponentAt(i);
|
236 |
// if (component instanceof WizardPanel) {
|
237 |
// ((WizardPanel) component).close();
|
238 |
// }
|
239 |
// }
|
240 |
if (PluginServices.getMainFrame() == null) { |
241 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
242 |
} else {
|
243 |
PluginServices.getMDIManager().closeWindow(AddLayerDialog.this); |
244 |
} |
245 |
} |
246 |
|
247 |
public void dispose() { |
248 |
JTabbedPane tabbed = getJTabbedPane();
|
249 |
for (int i = 0; i < tabbed.getTabCount(); i++) { |
250 |
Component component = tabbed.getComponentAt(i);
|
251 |
if (component instanceof WizardPanel) { |
252 |
((WizardPanel) component).close(); |
253 |
} |
254 |
} |
255 |
ToolsLocator.getDisposableManager().release(this);
|
256 |
} |
257 |
|
258 |
} |