svn-gvsig-desktop / tags / v2_0_0_Build_2038 / applications / appgvSIG / src / org / gvsig / app / gui / WizardPanel.java @ 36798
History | View | Annotate | Download (5.23 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
package org.gvsig.app.gui; |
23 |
|
24 |
import java.awt.Window; |
25 |
|
26 |
import javax.swing.JPanel; |
27 |
|
28 |
import org.cresques.cts.IProjection; |
29 |
import org.gvsig.andami.messages.NotificationManager; |
30 |
import org.gvsig.app.ApplicationLocator; |
31 |
import org.gvsig.app.ApplicationManager; |
32 |
import org.gvsig.app.gui.wizards.WizardListener; |
33 |
import org.gvsig.app.gui.wizards.WizardListenerSupport; |
34 |
import org.gvsig.app.prepareAction.PrepareContextView; |
35 |
import org.gvsig.fmap.dal.DataStoreParameters; |
36 |
import org.gvsig.fmap.mapcontext.MapContext; |
37 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
38 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
39 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
40 |
import org.gvsig.fmap.mapcontrol.MapControl; |
41 |
|
42 |
public abstract class WizardPanel extends JPanel { |
43 |
|
44 |
private static final long serialVersionUID = 5317749209668850863L; |
45 |
private String tabName = "TabName"; |
46 |
private MapControl mapCtrl = null; |
47 |
private WizardListenerSupport listenerSupport = new WizardListenerSupport(); |
48 |
|
49 |
public void addWizardListener(WizardListener listener) { |
50 |
listenerSupport.addWizardListener(listener); |
51 |
} |
52 |
|
53 |
public void callError(Exception descripcion) { |
54 |
listenerSupport.callError(descripcion); |
55 |
} |
56 |
|
57 |
public void removeWizardListener(WizardListener listener) { |
58 |
listenerSupport.removeWizardListener(listener); |
59 |
} |
60 |
|
61 |
public void callStateChanged(boolean finishable) { |
62 |
listenerSupport.callStateChanged(finishable); |
63 |
} |
64 |
|
65 |
protected void setTabName(String name) { |
66 |
tabName = name; |
67 |
} |
68 |
|
69 |
public String getTabName() { |
70 |
return tabName;
|
71 |
} |
72 |
|
73 |
abstract public void initWizard(); |
74 |
|
75 |
/**
|
76 |
* @deprecated use {@link #executeWizard()} instead.
|
77 |
*/
|
78 |
abstract public void execute(); |
79 |
|
80 |
/**
|
81 |
* Executes the wizard and returns anything created in the process.
|
82 |
*
|
83 |
* @return anything created in the process
|
84 |
*/
|
85 |
public Object executeWizard() { |
86 |
execute(); |
87 |
return null; |
88 |
} |
89 |
|
90 |
abstract public void close(); |
91 |
|
92 |
abstract public DataStoreParameters[] getParameters(); |
93 |
|
94 |
/**
|
95 |
* You can use it to extract information from
|
96 |
* the mapControl that will receive the new layer.
|
97 |
* For example, projection to use, or visible extent.
|
98 |
*
|
99 |
* @return Returns the mapCtrl.
|
100 |
*/
|
101 |
public MapControl getMapCtrl() {
|
102 |
return mapCtrl;
|
103 |
} |
104 |
|
105 |
/**
|
106 |
* @param mapCtrl
|
107 |
* The mapCtrl to set.
|
108 |
*/
|
109 |
public void setMapCtrl(MapControl mapCtrl) { |
110 |
this.mapCtrl = mapCtrl;
|
111 |
} |
112 |
|
113 |
protected void doAddLayer(final MapControl mapControl, |
114 |
final String layerName, final DataStoreParameters parameters) { |
115 |
final ApplicationManager application = ApplicationLocator.getManager();
|
116 |
final MapContextManager manager =
|
117 |
MapContextLocator.getMapContextManager(); |
118 |
final MapContext mapContext = mapControl.getMapContext();
|
119 |
|
120 |
Thread task = new Thread(new Runnable() { |
121 |
|
122 |
public void run() { |
123 |
FLayer layer = null;
|
124 |
FLayer preparedLayer = null;
|
125 |
try {
|
126 |
layer = manager.createLayer(layerName, parameters); |
127 |
preparedLayer = |
128 |
application.prepareOpenLayer(layer, |
129 |
new PrepareContextView() {
|
130 |
|
131 |
public Window getOwnerWindow() { |
132 |
return null; |
133 |
} |
134 |
|
135 |
public MapControl getMapControl() {
|
136 |
return mapControl;
|
137 |
} |
138 |
|
139 |
public IProjection getViewProjection() {
|
140 |
return mapControl.getProjection();
|
141 |
} |
142 |
}); |
143 |
if (preparedLayer != null) { |
144 |
mapContext.getLayers().addLayer(preparedLayer); |
145 |
} |
146 |
} catch (Exception e) { |
147 |
NotificationManager.addError(e); |
148 |
return;
|
149 |
} finally {
|
150 |
if (preparedLayer != null && preparedLayer != layer) { |
151 |
preparedLayer.dispose(); |
152 |
preparedLayer = null;
|
153 |
} |
154 |
if (layer != null) { |
155 |
layer.dispose(); |
156 |
layer = null;
|
157 |
} |
158 |
} |
159 |
} |
160 |
}); |
161 |
task.start(); |
162 |
} |
163 |
} |