root / branches / v2_0_0_prep / extensions / extSextanteGvsigBindings / src / org / gvsig / sextante / gui / ToolboxDialog.java @ 31496
History | View | Annotate | Download (5.35 KB)
1 |
package org.gvsig.sextante.gui; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Dimension; |
5 |
import java.beans.PropertyChangeEvent; |
6 |
import java.beans.PropertyChangeListener; |
7 |
import java.util.ArrayList; |
8 |
|
9 |
import javax.swing.JDialog; |
10 |
import javax.swing.JPanel; |
11 |
|
12 |
import org.gvsig.andami.PluginServices; |
13 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
14 |
import org.gvsig.andami.ui.mdiManager.IWindowListener; |
15 |
import org.gvsig.andami.ui.mdiManager.SingletonWindow; |
16 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
17 |
import org.gvsig.app.project.Project; |
18 |
import org.gvsig.app.project.ProjectManager; |
19 |
import org.gvsig.app.project.documents.ProjectDocumentListener; |
20 |
import org.gvsig.app.project.documents.view.DefaultViewDocument; |
21 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
22 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
23 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
24 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent; |
25 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener; |
26 |
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent; |
27 |
|
28 |
import es.unex.sextante.core.Sextante; |
29 |
import es.unex.sextante.gui.core.SextanteGUI; |
30 |
import es.unex.sextante.gui.toolbox.ToolboxPanel; |
31 |
|
32 |
public class ToolboxDialog extends JPanel implements SingletonWindow, IWindowListener, LayerCollectionListener, |
33 |
PropertyChangeListener, ProjectDocumentListener {
|
34 |
|
35 |
private ArrayList<FLayers> listLayers = new ArrayList<FLayers>(); |
36 |
private WindowInfo viewInfo;
|
37 |
private ToolboxPanel m_Panel;
|
38 |
private int m_iCount; |
39 |
|
40 |
public ToolboxDialog(){
|
41 |
|
42 |
super();
|
43 |
|
44 |
if (SextanteGUI.getInputFactory().getDataObjects() == null){ |
45 |
SextanteGUI.getInputFactory().createDataObjects(); |
46 |
} |
47 |
|
48 |
initGUI(); |
49 |
addListeners(); |
50 |
|
51 |
} |
52 |
|
53 |
private void addListeners() { |
54 |
|
55 |
//Register a propertyChangeListener to capture event when a new document is added in gvSIG
|
56 |
// Project p = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
|
57 |
final Project p = ProjectManager.getInstance().getCurrentProject();
|
58 |
p.addPropertyChangeListener(this);
|
59 |
|
60 |
//Register addLayerCollectionListener in existing views
|
61 |
IWindow[] window = PluginServices.getMDIManager().getAllWindows();
|
62 |
for (int i = 0; i < window.length; i++) { |
63 |
if(window[i] instanceof AbstractViewPanel) { |
64 |
FLayers layers = ((AbstractViewPanel)window[i]).getMapControl().getMapContext().getLayers(); |
65 |
if(listLayers.indexOf(layers) == -1) { |
66 |
layers.addLayerCollectionListener(this);
|
67 |
listLayers.add(layers); |
68 |
} |
69 |
} |
70 |
} |
71 |
|
72 |
|
73 |
} |
74 |
|
75 |
private void removeListeners() { |
76 |
|
77 |
//TODO:RELLENAR ESTO
|
78 |
|
79 |
} |
80 |
|
81 |
private void initGUI() { |
82 |
|
83 |
m_Panel = new ToolboxPanel(null, null); |
84 |
m_iCount = m_Panel.getAlgorithmsCount(); |
85 |
BorderLayout thisLayout = new BorderLayout(); |
86 |
this.setLayout(thisLayout);
|
87 |
this.setSize(new Dimension(m_Panel.getWidth(), m_Panel.getHeight())); |
88 |
this.add(m_Panel);
|
89 |
|
90 |
} |
91 |
|
92 |
public WindowInfo getWindowInfo() {
|
93 |
|
94 |
if (viewInfo == null) { |
95 |
viewInfo=new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE);
|
96 |
|
97 |
viewInfo.setTitle("SEXTANTE - " + Integer.toString(m_iCount) |
98 |
+ Sextante.getText("Algoritmos"));
|
99 |
} |
100 |
return viewInfo;
|
101 |
|
102 |
} |
103 |
|
104 |
public Object getWindowProfile() { |
105 |
return WindowInfo.TOOL_PROFILE;
|
106 |
} |
107 |
|
108 |
public Object getWindowModel() { |
109 |
|
110 |
return "SEXTANTE"; |
111 |
|
112 |
} |
113 |
|
114 |
public ToolboxPanel getToolboxPanel(){
|
115 |
|
116 |
return m_Panel;
|
117 |
} |
118 |
|
119 |
public void cancel(){ |
120 |
|
121 |
removeListeners(); |
122 |
|
123 |
if (PluginServices.getMainFrame() == null){ |
124 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
125 |
} |
126 |
else{
|
127 |
PluginServices.getMDIManager().closeWindow(ToolboxDialog.this); |
128 |
} |
129 |
|
130 |
} |
131 |
|
132 |
public void windowActivated() {} |
133 |
|
134 |
public void windowClosed() { |
135 |
|
136 |
removeListeners(); |
137 |
SextanteGUI.getInputFactory().clearDataObjects(); |
138 |
|
139 |
} |
140 |
|
141 |
/**
|
142 |
* Event throwed when a new document is added
|
143 |
*/
|
144 |
public void propertyChange(PropertyChangeEvent evt) { |
145 |
if(evt.getPropertyName().equals("addDocument")) { |
146 |
if(evt.getNewValue() instanceof DefaultViewDocument) { |
147 |
DefaultViewDocument pd = (DefaultViewDocument)evt.getNewValue(); |
148 |
pd.addListener(this);
|
149 |
} |
150 |
} |
151 |
} |
152 |
|
153 |
/**
|
154 |
* Event throwed when a window (View) is created. This method register a listener
|
155 |
* in FLayers. When a new layer is going to be added or removed the methods layerAdded and
|
156 |
* layerRemoved will catch this event.
|
157 |
*/
|
158 |
public void windowCreated(IWindow window) { |
159 |
if(window instanceof AbstractViewPanel) { |
160 |
FLayers layers = ((AbstractViewPanel)window).getMapControl().getMapContext().getLayers(); |
161 |
if(listLayers.indexOf(layers) == -1) { |
162 |
layers.addLayerCollectionListener(this);
|
163 |
listLayers.add(layers); |
164 |
} |
165 |
} |
166 |
} |
167 |
|
168 |
public void layerAdded(LayerCollectionEvent e) { |
169 |
|
170 |
// this could be done more elegantly, just adding the new layers...
|
171 |
// but it works fine this way ;-)
|
172 |
SextanteGUI.getInputFactory().clearDataObjects(); |
173 |
SextanteGUI.getInputFactory().createDataObjects(); |
174 |
|
175 |
} |
176 |
|
177 |
public void layerRemoved(LayerCollectionEvent e) { |
178 |
|
179 |
SextanteGUI.getInputFactory().clearDataObjects(); |
180 |
SextanteGUI.getInputFactory().createDataObjects(); |
181 |
|
182 |
} |
183 |
|
184 |
public void layerMoved(LayerPositionEvent e) {} |
185 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException {} |
186 |
public void layerMoving(LayerPositionEvent e) throws CancelationException {} |
187 |
public void layerRemoving(LayerCollectionEvent e) throws CancelationException {} |
188 |
public void visibilityChanged(LayerCollectionEvent e) throws CancelationException {} |
189 |
|
190 |
} |