Statistics
| Revision:

gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.app / org.gvsig.geoprocess.app.mainplugin / src / main / java / org / gvsig / geoprocess / sextante / gui / toolbox / ToolboxDialog.java @ 237

History | View | Annotate | Download (7.34 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007,2012 gvSIG Association.
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
package org.gvsig.geoprocess.sextante.gui.toolbox;
22

    
23
import java.awt.BorderLayout;
24
import java.awt.Dimension;
25
import java.beans.PropertyChangeEvent;
26
import java.beans.PropertyChangeListener;
27
import java.util.ArrayList;
28
import java.util.List;
29

    
30
import javax.swing.ImageIcon;
31
import javax.swing.JDialog;
32
import javax.swing.JPanel;
33

    
34
import es.unex.sextante.gui.core.SextanteGUI;
35
import es.unex.sextante.gui.toolbox.IToolboxDialog;
36
import es.unex.sextante.gui.toolbox.ToolboxPanel;
37

    
38
import org.gvsig.andami.PluginServices;
39
import org.gvsig.andami.ui.mdiManager.IWindow;
40
import org.gvsig.andami.ui.mdiManager.IWindowListener;
41
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
42
import org.gvsig.andami.ui.mdiManager.WindowInfo;
43
import org.gvsig.app.extension.ProjectExtension;
44
import org.gvsig.app.project.Project;
45
import org.gvsig.app.project.documents.ProjectDocumentListener;
46
import org.gvsig.app.project.documents.view.DefaultViewDocument;
47
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
48
import org.gvsig.fmap.mapcontext.layers.CancelationException;
49
import org.gvsig.fmap.mapcontext.layers.FLayers;
50
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent;
51
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener;
52
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent;
53
import org.gvsig.i18n.Messages;
54

    
55
public class ToolboxDialog extends JPanel implements SingletonWindow,
56
    IWindowListener, LayerCollectionListener, PropertyChangeListener,
57
    ProjectDocumentListener, IToolboxDialog {
58

    
59
    private static final long serialVersionUID = 1L;
60
    private final List<FLayers> listLayers = new ArrayList<FLayers>();
61
    private WindowInfo viewInfo;
62
    private ToolboxPanel m_Panel;
63

    
64
    public ToolboxDialog() {
65

    
66
        super();
67

    
68
        if (SextanteGUI.getInputFactory().getDataObjects() == null) {
69
            SextanteGUI.getInputFactory().createDataObjects();
70
        }
71

    
72
        initGUI();
73
        addListeners();
74

    
75
    }
76

    
77
    private void addListeners() {
78

    
79
        // Register a propertyChangeListener to capture events when a new
80
        // document is added in gvSIG
81
        final Project p =
82
            ((ProjectExtension) PluginServices
83
                .getExtension(ProjectExtension.class)).getProject();
84
        p.addPropertyChangeListener(this);
85

    
86
        // Register addLayerCollectionListener in existing views
87
        final IWindow[] window = PluginServices.getMDIManager().getAllWindows();
88
        for (int i = 0; i < window.length; i++) {
89
            if (window[i] instanceof AbstractViewPanel) {
90
                final FLayers layers =
91
                    ((AbstractViewPanel) window[i]).getMapControl()
92
                        .getMapContext().getLayers();
93
                if (listLayers.indexOf(layers) == -1) {
94
                    layers.addLayerCollectionListener(this);
95
                    listLayers.add(layers);
96
                }
97
            }
98
        }
99

    
100
    }
101

    
102
    private void removeListeners() {
103
        return;
104
    }
105

    
106
    private void initGUI() {
107

    
108
        m_Panel = new ToolboxPanel(this, null, new ImageIcon());
109
        final BorderLayout thisLayout = new BorderLayout();
110
        this.setLayout(thisLayout);
111
        this.setSize(new Dimension(m_Panel.getWidth(), m_Panel.getHeight()));
112
        this.add(m_Panel);
113

    
114
    }
115

    
116
    public WindowInfo getWindowInfo() {
117

    
118
        if (viewInfo == null) {
119
            viewInfo =
120
                new WindowInfo(WindowInfo.PALETTE | WindowInfo.MAXIMIZABLE
121
                    | WindowInfo.RESIZABLE);
122
        }
123
        return viewInfo;
124

    
125
    }
126

    
127
    public Object getWindowProfile() {
128
        return WindowInfo.TOOL_PROFILE;
129
    }
130

    
131
    public Object getWindowModel() {
132

    
133
        return Messages.getText("Geoprocessing");
134

    
135
    }
136

    
137
    public ToolboxPanel getToolboxPanel() {
138

    
139
        return m_Panel;
140
    }
141

    
142
    public void cancel() {
143

    
144
        removeListeners();
145

    
146
        if (PluginServices.getMainFrame() == null) {
147
            ((JDialog) (getParent().getParent().getParent().getParent()))
148
                .dispose();
149
        } else {
150
            PluginServices.getMDIManager().closeWindow(ToolboxDialog.this);
151
        }
152

    
153
    }
154

    
155
    public void windowActivated() {
156
    }
157

    
158
    public void windowClosed() {
159

    
160
        removeListeners();
161
        SextanteGUI.getInputFactory().clearDataObjects();
162

    
163
    }
164

    
165
    /**
166
     * Event thrown when a new document is added
167
     */
168
    public void propertyChange(final PropertyChangeEvent evt) {
169
        if (evt.getPropertyName().equals("addDocument")) {
170
            if (evt.getNewValue() instanceof DefaultViewDocument) {
171
                final DefaultViewDocument dvd =
172
                    (DefaultViewDocument) evt.getNewValue();
173
                dvd.addListener(this);
174
            }
175
        }
176
    }
177

    
178
    /**
179
     * Event thrown when a window (View) is created. This method registers a
180
     * listener in FLayers. When a new layer is going to be
181
     * added or removed the methods layerAdded and layerRemoved will catch this
182
     * event.
183
     */
184
    public void windowCreated(final IWindow window) {
185
        if (window instanceof AbstractViewPanel) {
186
            final FLayers layers =
187
                ((AbstractViewPanel) window).getMapControl().getMapContext()
188
                    .getLayers();
189
            if (listLayers.indexOf(layers) == -1) {
190
                layers.addLayerCollectionListener(this);
191
                listLayers.add(layers);
192
            }
193
        }
194
    }
195

    
196
    public void layerAdded(final LayerCollectionEvent e) {
197

    
198
        // this could be done more elegantly, just adding the new layers...
199
        // but it works fine this way ;-)
200
        SextanteGUI.getInputFactory().clearDataObjects();
201
        SextanteGUI.getInputFactory().createDataObjects();
202

    
203
    }
204

    
205
    public void layerRemoved(final LayerCollectionEvent e) {
206

    
207
        SextanteGUI.getInputFactory().clearDataObjects();
208
        SextanteGUI.getInputFactory().createDataObjects();
209

    
210
    }
211

    
212
    public void layerMoved(final LayerPositionEvent e) {
213
    }
214

    
215
    public void layerAdding(final LayerCollectionEvent e)
216
        throws CancelationException {
217
    }
218

    
219
    public void layerMoving(final LayerPositionEvent e)
220
        throws CancelationException {
221
    }
222

    
223
    public void layerRemoving(final LayerCollectionEvent e)
224
        throws CancelationException {
225
    }
226

    
227
    public void visibilityChanged(final LayerCollectionEvent e)
228
        throws CancelationException {
229
    }
230

    
231
    public JDialog getDialog() {
232
        return null;
233
    }
234

    
235
    public void setAlgorithmsCount(final int iCount) {
236
        getWindowInfo().setTitle(
237
            Messages.getText("Geoprocessing") + " - "
238
                + Integer.toString(iCount) + " "
239
                + Messages.getText("Algorithms"));
240
    }
241

    
242
}