root / trunk / extensions / extSextanteGvsigBindings / src / es / unex / sextante / gvsig / gui / ToolboxDialog.java @ 24989
History | View | Annotate | Download (5.21 KB)
1 |
package es.unex.sextante.gvsig.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 com.iver.andami.PluginServices; |
13 |
import com.iver.andami.ui.mdiManager.IWindow; |
14 |
import com.iver.andami.ui.mdiManager.IWindowListener; |
15 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
16 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
17 |
import com.iver.cit.gvsig.ProjectExtension; |
18 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
19 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
20 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent; |
21 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener; |
22 |
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent; |
23 |
import com.iver.cit.gvsig.project.Project; |
24 |
import com.iver.cit.gvsig.project.documents.ProjectDocumentListener; |
25 |
import com.iver.cit.gvsig.project.documents.view.ProjectView; |
26 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
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 |
p.addPropertyChangeListener(this);
|
58 |
|
59 |
//Register addLayerCollectionListener in existing views
|
60 |
IWindow[] window = PluginServices.getMDIManager().getAllWindows();
|
61 |
for (int i = 0; i < window.length; i++) { |
62 |
if(window[i] instanceof BaseView) { |
63 |
FLayers layers = ((BaseView)window[i]).getMapControl().getMapContext().getLayers(); |
64 |
if(listLayers.indexOf(layers) == -1) { |
65 |
layers.addLayerCollectionListener(this);
|
66 |
listLayers.add(layers); |
67 |
} |
68 |
} |
69 |
} |
70 |
|
71 |
|
72 |
} |
73 |
|
74 |
private void removeListeners() { |
75 |
|
76 |
//TODO:RELLENAR ESTO
|
77 |
|
78 |
} |
79 |
|
80 |
private void initGUI() { |
81 |
|
82 |
m_Panel = new ToolboxPanel(null); |
83 |
m_iCount = m_Panel.getAlgorithmsCount(); |
84 |
BorderLayout thisLayout = new BorderLayout(); |
85 |
this.setLayout(thisLayout);
|
86 |
this.setSize(new Dimension(m_Panel.getWidth(), m_Panel.getHeight())); |
87 |
this.add(m_Panel);
|
88 |
|
89 |
} |
90 |
|
91 |
public WindowInfo getWindowInfo() {
|
92 |
|
93 |
if (viewInfo == null) { |
94 |
viewInfo=new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE);
|
95 |
|
96 |
viewInfo.setTitle("SEXTANTE - " + Integer.toString(m_iCount) |
97 |
+ Sextante.getText("Algoritmos"));
|
98 |
} |
99 |
return viewInfo;
|
100 |
|
101 |
} |
102 |
|
103 |
public Object getWindowProfile() { |
104 |
return WindowInfo.TOOL_PROFILE;
|
105 |
} |
106 |
|
107 |
public Object getWindowModel() { |
108 |
|
109 |
return "SEXTANTE"; |
110 |
|
111 |
} |
112 |
|
113 |
public ToolboxPanel getToolboxPanel(){
|
114 |
|
115 |
return m_Panel;
|
116 |
} |
117 |
|
118 |
public void cancel(){ |
119 |
|
120 |
removeListeners(); |
121 |
|
122 |
if (PluginServices.getMainFrame() == null){ |
123 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
124 |
} |
125 |
else{
|
126 |
PluginServices.getMDIManager().closeWindow(ToolboxDialog.this); |
127 |
} |
128 |
|
129 |
} |
130 |
|
131 |
public void windowActivated() {} |
132 |
|
133 |
public void windowClosed() { |
134 |
|
135 |
removeListeners(); |
136 |
SextanteGUI.getInputFactory().clearDataObjects(); |
137 |
|
138 |
} |
139 |
|
140 |
/**
|
141 |
* Event throwed when a new document is added
|
142 |
*/
|
143 |
public void propertyChange(PropertyChangeEvent evt) { |
144 |
if(evt.getPropertyName().equals("addDocument")) { |
145 |
if(evt.getNewValue() instanceof ProjectView) { |
146 |
ProjectView pd = (ProjectView)evt.getNewValue(); |
147 |
pd.addProjectViewListener(this);
|
148 |
} |
149 |
} |
150 |
} |
151 |
|
152 |
/**
|
153 |
* Event throwed when a window (View) is created. This method register a listener
|
154 |
* in FLayers. When a new layer is going to be added or removed the methods layerAdded and
|
155 |
* layerRemoved will catch this event.
|
156 |
*/
|
157 |
public void windowCreated(IWindow window) { |
158 |
if(window instanceof BaseView) { |
159 |
FLayers layers = ((BaseView)window).getMapControl().getMapContext().getLayers(); |
160 |
if(listLayers.indexOf(layers) == -1) { |
161 |
layers.addLayerCollectionListener(this);
|
162 |
listLayers.add(layers); |
163 |
} |
164 |
} |
165 |
} |
166 |
|
167 |
public void layerAdded(LayerCollectionEvent e) { |
168 |
|
169 |
// this could be done more elegantly, just adding the new layers...
|
170 |
// but it works fine this way ;-)
|
171 |
SextanteGUI.getInputFactory().clearDataObjects(); |
172 |
SextanteGUI.getInputFactory().createDataObjects(); |
173 |
|
174 |
} |
175 |
|
176 |
public void layerRemoved(LayerCollectionEvent e) { |
177 |
|
178 |
SextanteGUI.getInputFactory().clearDataObjects(); |
179 |
SextanteGUI.getInputFactory().createDataObjects(); |
180 |
|
181 |
} |
182 |
|
183 |
public void layerMoved(LayerPositionEvent e) {} |
184 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException {} |
185 |
public void layerMoving(LayerPositionEvent e) throws CancelationException {} |
186 |
public void layerRemoving(LayerCollectionEvent e) throws CancelationException {} |
187 |
public void visibilityChanged(LayerCollectionEvent e) throws CancelationException {} |
188 |
|
189 |
} |