Statistics
| Revision:

gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.sextante.app / org.gvsig.sextante.app.extension / src / main / java / org / gvsig / geoprocess / gui / ToolboxDialog.java @ 172

History | View | Annotate | Download (6.35 KB)

1
package org.gvsig.geoprocess.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 es.unex.sextante.gui.core.SextanteGUI;
13
import es.unex.sextante.gui.toolbox.IToolboxDialog;
14
import es.unex.sextante.gui.toolbox.ToolboxPanel;
15

    
16
import org.gvsig.andami.PluginServices;
17
import org.gvsig.andami.ui.mdiManager.IWindow;
18
import org.gvsig.andami.ui.mdiManager.IWindowListener;
19
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
20
import org.gvsig.andami.ui.mdiManager.WindowInfo;
21
import org.gvsig.app.extension.ProjectExtension;
22
import org.gvsig.app.project.Project;
23
import org.gvsig.app.project.documents.ProjectDocumentListener;
24
import org.gvsig.app.project.documents.view.DefaultViewDocument;
25
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
26
import org.gvsig.fmap.mapcontext.layers.CancelationException;
27
import org.gvsig.fmap.mapcontext.layers.FLayers;
28
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent;
29
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener;
30
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent;
31

    
32
public class ToolboxDialog extends JPanel implements SingletonWindow,
33
    IWindowListener, LayerCollectionListener, PropertyChangeListener,
34
    ProjectDocumentListener, IToolboxDialog {
35

    
36
    private static final long serialVersionUID = 1L;
37
    private final ArrayList<FLayers> listLayers = new ArrayList<FLayers>();
38
    private WindowInfo viewInfo;
39
    private ToolboxPanel m_Panel;
40

    
41
   public ToolboxDialog() {
42

    
43
        super();
44

    
45
        if (SextanteGUI.getInputFactory().getDataObjects() == null) {
46
            SextanteGUI.getInputFactory().createDataObjects();
47
        }
48

    
49
        initGUI();
50
        addListeners();
51

    
52
    }
53

    
54

    
55
    private void addListeners() {
56

    
57
        // Register a propertyChangeListener to capture events when a new
58
        // document is added in gvSIG
59
        final Project p =
60
            ((ProjectExtension) PluginServices
61
                .getExtension(ProjectExtension.class)).getProject();
62
        p.addPropertyChangeListener(this);
63

    
64
        // Register addLayerCollectionListener in existing views
65
        final IWindow[] window = PluginServices.getMDIManager().getAllWindows();
66
        for (int i = 0; i < window.length; i++) {
67
            if (window[i] instanceof AbstractViewPanel) {
68
                final FLayers layers =
69
                    ((AbstractViewPanel) window[i]).getMapControl()
70
                        .getMapContext().getLayers();
71
                if (listLayers.indexOf(layers) == -1) {
72
                    layers.addLayerCollectionListener(this);
73
                    listLayers.add(layers);
74
            }
75
            }
76
        }
77

    
78
    }
79

    
80
    private void removeListeners() {
81
        return;
82
    }
83

    
84
    private void initGUI() {
85

    
86
        m_Panel = new ToolboxPanel(this, null, null);
87
        final BorderLayout thisLayout = new BorderLayout();
88
        this.setLayout(thisLayout);
89
        this.setSize(new Dimension(m_Panel.getWidth(), m_Panel.getHeight()));
90
        this.add(m_Panel);
91

    
92
    }
93

    
94
    public WindowInfo getWindowInfo() {
95

    
96
        if (viewInfo == null) {
97
            viewInfo =
98
                new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE);
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

    
120
    public void cancel() {
121

    
122
        removeListeners();
123

    
124
        if (PluginServices.getMainFrame() == null) {
125
            ((JDialog) (getParent().getParent().getParent().getParent()))
126
                .dispose();
127
        } else {
128
            PluginServices.getMDIManager().closeWindow(ToolboxDialog.this);
129
        }
130

    
131
    }
132

    
133

    
134
    public void windowActivated() {
135
    }
136

    
137

    
138
    public void windowClosed() {
139

    
140
        removeListeners();
141
        SextanteGUI.getInputFactory().clearDataObjects();
142

    
143
    }
144

    
145

    
146
    /**
147
     * Event thrown when a new document is added
148
     */
149
    public void propertyChange(final PropertyChangeEvent evt) {
150
        if (evt.getPropertyName().equals("addDocument")) {
151
            if (evt.getNewValue() instanceof DefaultViewDocument) {
152
                final DefaultViewDocument dvd =
153
                    (DefaultViewDocument) evt.getNewValue();
154
                dvd.addListener(this);
155
            }
156
        }
157
    }
158

    
159

    
160
    /**
161
     * Event thrown when a window (View) is created. This method registers a
162
     * listener in FLayers. When a new layer is going to be
163
     * added or removed the methods layerAdded and layerRemoved will catch this
164
     * event.
165
     */
166
    public void windowCreated(final IWindow window) {
167
        if (window instanceof AbstractViewPanel) {
168
            final FLayers layers =
169
                ((AbstractViewPanel) window).getMapControl().getMapContext()
170
                    .getLayers();
171
            if (listLayers.indexOf(layers) == -1) {
172
                layers.addLayerCollectionListener(this);
173
                listLayers.add(layers);
174
            }
175
        }
176
    }
177

    
178

    
179
    public void layerAdded(final LayerCollectionEvent e) {
180

    
181
        // this could be done more elegantly, just adding the new layers...
182
        // but it works fine this way ;-)
183
        SextanteGUI.getInputFactory().clearDataObjects();
184
        SextanteGUI.getInputFactory().createDataObjects();
185

    
186
    }
187

    
188

    
189
    public void layerRemoved(final LayerCollectionEvent e) {
190

    
191
        SextanteGUI.getInputFactory().clearDataObjects();
192
        SextanteGUI.getInputFactory().createDataObjects();
193

    
194
    }
195

    
196

    
197
    public void layerMoved(final LayerPositionEvent e) {
198
    }
199

    
200

    
201
    public void layerAdding(final LayerCollectionEvent e)
202
        throws CancelationException {
203
    }
204

    
205

    
206
    public void layerMoving(final LayerPositionEvent e)
207
        throws CancelationException {
208
    }
209

    
210

    
211
    public void layerRemoving(final LayerCollectionEvent e)
212
        throws CancelationException {
213
    }
214

    
215

    
216
    public void visibilityChanged(final LayerCollectionEvent e)
217
        throws CancelationException {
218
    }
219

    
220

    
221
    public JDialog getDialog() {
222
        return null;
223
    }
224

    
225

    
226
    public void setAlgorithmsCount(final int iCount) {
227
        getWindowInfo().setTitle(
228
            "SEXTANTE - " + Integer.toString(iCount) + " "
229
                + PluginServices.getText(this, "Algorithms"));
230
    }
231

    
232
}