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 @ 45739
History | View | Annotate | Download (8.46 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 43619 | jjdelcerro | * Copyright (C) 2007-2017 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | 42568 | jjdelcerro | * 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 | 40435 | jjdelcerro | *
|
11 | 42568 | jjdelcerro | * 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 | 40435 | jjdelcerro | *
|
16 | 42568 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
20 | 42568 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40435 | jjdelcerro | */
|
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 | 45672 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingUtils; |
47 | 41662 | jjdelcerro | import org.slf4j.Logger; |
48 | import org.slf4j.LoggerFactory; |
||
49 | 40435 | jjdelcerro | |
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 | 42568 | jjdelcerro | public class AddLayerDialog extends JPanel implements org.gvsig.andami.ui.mdiManager.IWindow, Disposable { |
57 | 40435 | jjdelcerro | |
58 | 42568 | jjdelcerro | 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 | 42569 | jjdelcerro | private final WizardListener wizardListener = new DialogWizardListener(); |
65 | 40435 | jjdelcerro | |
66 | 42568 | jjdelcerro | /**
|
67 | * Creates a new FOpenDialog object.
|
||
68 | */
|
||
69 | public AddLayerDialog() {
|
||
70 | initialize(); |
||
71 | } |
||
72 | 40435 | jjdelcerro | |
73 | 42568 | jjdelcerro | /**
|
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 | 40435 | jjdelcerro | |
83 | 42568 | jjdelcerro | /**
|
84 | * This method initializes this
|
||
85 | */
|
||
86 | private void initialize() { |
||
87 | ToolsLocator.getDisposableManager().bind(this);
|
||
88 | 40435 | jjdelcerro | |
89 | 42568 | jjdelcerro | 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 | 40435 | jjdelcerro | |
96 | 42568 | jjdelcerro | /**
|
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 | 42569 | jjdelcerro | @Override
|
107 | 42568 | jjdelcerro | 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 | 40435 | jjdelcerro | |
120 | 42568 | jjdelcerro | return jTabbedPane;
|
121 | } |
||
122 | 40435 | jjdelcerro | |
123 | 42568 | jjdelcerro | /**
|
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 | 40435 | jjdelcerro | |
133 | 42568 | jjdelcerro | /**
|
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 | 40435 | jjdelcerro | |
144 | 42568 | jjdelcerro | /**
|
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 | 42569 | jjdelcerro | @Override
|
158 | 42568 | jjdelcerro | public WindowInfo getWindowInfo() {
|
159 | WindowInfo m_viewinfo = new WindowInfo(
|
||
160 | WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE); |
||
161 | m_viewinfo.setTitle(this.title);
|
||
162 | 45672 | jjdelcerro | m_viewinfo.setHeight(ToolsSwingUtils.rows2px(30));
|
163 | m_viewinfo.setWidth(ToolsSwingUtils.cols2px(70));
|
||
164 | 42568 | jjdelcerro | 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 | 41662 | jjdelcerro | } |
172 | 42568 | jjdelcerro | } |
173 | 40435 | jjdelcerro | |
174 | 42568 | jjdelcerro | /**
|
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 | 42569 | jjdelcerro | @Override
|
183 | 42568 | jjdelcerro | public void actionPerformed(ActionEvent e) { |
184 | accepted = true;
|
||
185 | closeWindow(); |
||
186 | } |
||
187 | }; |
||
188 | ActionListener cancelAction = new ActionListener() { |
||
189 | 42569 | jjdelcerro | @Override
|
190 | 42568 | jjdelcerro | 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 | 40435 | jjdelcerro | |
200 | 42568 | jjdelcerro | /**
|
201 | * @return
|
||
202 | */
|
||
203 | public boolean isAccepted() { |
||
204 | return accepted;
|
||
205 | } |
||
206 | 40435 | jjdelcerro | |
207 | 42568 | jjdelcerro | /**
|
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 | 40435 | jjdelcerro | |
219 | 42569 | jjdelcerro | @Override
|
220 | 42568 | jjdelcerro | public void error(Exception e) { |
221 | } |
||
222 | 40435 | jjdelcerro | |
223 | 42568 | jjdelcerro | /*
|
224 | * (non-Javadoc)
|
||
225 | * @see com.iver.cit.gvsig.gui.wizards.WizardListener#wizardStateChanged(boolean)
|
||
226 | */
|
||
227 | 42569 | jjdelcerro | @Override
|
228 | 42568 | jjdelcerro | public void wizardStateChanged(boolean finishable) { |
229 | getJPanel().setOkButtonEnabled(finishable); |
||
230 | } |
||
231 | } |
||
232 | 40435 | jjdelcerro | |
233 | 42568 | jjdelcerro | /**
|
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 | 40435 | jjdelcerro | |
245 | 42568 | jjdelcerro | /**
|
246 | * Define la ultima proyeccion
|
||
247 | *
|
||
248 | * @param proj
|
||
249 | */
|
||
250 | public static void setLastProjection(IProjection proj) { |
||
251 | AddLayerDialog.proj = proj; |
||
252 | } |
||
253 | 40435 | jjdelcerro | |
254 | 42569 | jjdelcerro | @Override
|
255 | 42568 | jjdelcerro | public Object getWindowProfile() { |
256 | return WindowInfo.DIALOG_PROFILE;
|
||
257 | } |
||
258 | |||
259 | private void closeWindow() { |
||
260 | if (PluginServices.getMainFrame() == null) { |
||
261 | 45739 | jjdelcerro | try {
|
262 | ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
||
263 | } catch(Exception ex) { |
||
264 | logger.debug("Can't close window.",ex);
|
||
265 | } |
||
266 | 42568 | jjdelcerro | } else {
|
267 | PluginServices.getMDIManager().closeWindow(AddLayerDialog.this); |
||
268 | } |
||
269 | } |
||
270 | |||
271 | 42569 | jjdelcerro | @Override
|
272 | 42568 | jjdelcerro | public void dispose() { |
273 | JTabbedPane tabbed = getJTabbedPane();
|
||
274 | for (int i = 0; i < tabbed.getTabCount(); i++) { |
||
275 | Component component = tabbed.getComponentAt(i);
|
||
276 | if (component instanceof WizardPanel) { |
||
277 | ((WizardPanel) component).close(); |
||
278 | } |
||
279 | } |
||
280 | ToolsLocator.getDisposableManager().release(this);
|
||
281 | } |
||
282 | |||
283 | } |