Statistics
| Revision:

gvsig-educa / org.gvsig.educa.thematicmap / trunk / org.gvsig.educa.thematicmap / org.gvsig.educa.thematicmap.lib / org.gvsig.educa.thematicmap.lib.impl / src / main / java / org / gvsig / educa / thematicmap / impl / editor / DefaultThematicMapCompilationEditor.java @ 220

History | View | Annotate | Download (8.95 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.educa.thematicmap.impl.editor;
23

    
24
import java.awt.BorderLayout;
25
import java.net.URL;
26
import java.util.ArrayList;
27
import java.util.List;
28

    
29
import javax.swing.BorderFactory;
30
import javax.swing.ImageIcon;
31
import javax.swing.JComponent;
32
import javax.swing.JPanel;
33

    
34
import org.gvsig.educa.thematicmap.ThematicMapLocator;
35
import org.gvsig.educa.thematicmap.ThematicMapManager;
36
import org.gvsig.educa.thematicmap.ThematicMapWindowManager.MESSAGE_DIALOG_TYPE;
37
import org.gvsig.educa.thematicmap.compilation.CompilationValidationMessage;
38
import org.gvsig.educa.thematicmap.compilation.ThematicMapCompilation;
39
import org.gvsig.educa.thematicmap.editor.ThematicMapCompilationEditor;
40
import org.gvsig.educa.thematicmap.editor.ThematicMapCompilationEditorListener;
41
import org.gvsig.educa.thematicmap.impl.IconThemeHelper;
42
import org.gvsig.gui.beans.wizard.WizardPanel;
43
import org.gvsig.gui.beans.wizard.WizardPanelActionListener;
44
import org.gvsig.gui.beans.wizard.WizardPanelWithLogo;
45

    
46
/**
47
 * <p>
48
 * Default implementation of {@link ThematicMapCompilationEditor}
49
 * </p>
50
 * <p>
51
 * This uses <i>org.gvsig.ui</i> Wizard implementation.
52
 * </p>
53
 * <p>
54
 * There are three steps:
55
 * <ol>
56
 * <li>{@link StepIdentification}: Base values for <i>Thematic Map</i>
57
 * identification</li>
58
 * <li>{@link StepLayers}: Layers definition which will compound the <i>Thematic
59
 * Map</i></li>
60
 * <li>{@link StepValidation}: validation of all data</li>
61
 * </ol>
62
 * </p>
63
 * 
64
 * @author gvSIG Team
65
 * @version $Id$
66
 * 
67
 */
68
public class DefaultThematicMapCompilationEditor extends JPanel implements
69
    ThematicMapCompilationEditor, WizardPanel, WizardPanelActionListener {
70

    
71
    /**
72
     *
73
     */
74
    private static final long serialVersionUID = -9153359086582532100L;
75

    
76
    private final ThematicMapManager manager;
77
    private final ThematicMapCompilation compilation;
78

    
79
    /**
80
     * Wizard component
81
     */
82
    private WizardPanelWithLogo wizard;
83

    
84
    /**
85
     * Wizard step for input Thematic Map information values
86
     */
87
    private StepIdentification stepIdentification;
88

    
89
    /**
90
     * Wizard step to configure layer composition
91
     */
92
    private StepLayers stepLayers;
93

    
94
    /**
95
     * Wizard step to validate all data
96
     */
97
    private StepValidation stepValidation;
98

    
99
    /**
100
     * UI initialized flag
101
     */
102
    private boolean initialized = false;
103

    
104
    private ThematicMapCompilationEditorListener listener;
105

    
106
    private final boolean editLayers;
107

    
108
    private boolean allowChangeId = true;
109

    
110
    public DefaultThematicMapCompilationEditor(
111
        ThematicMapCompilation compilation) {
112
        this(compilation, true);
113
    }
114

    
115
    /**
116
     * @param thematicMapCompilation
117
     * @param editLayers
118
     */
119
    public DefaultThematicMapCompilationEditor(
120
        ThematicMapCompilation compilation, boolean editLayers) {
121
        manager = ThematicMapLocator.getManager();
122

    
123
        this.compilation = compilation;
124
        this.editLayers = editLayers;
125
    }
126

    
127
    /**
128
     * Initialize all UI component of the panel
129
     */
130
    private void initializeUI() {
131
        if (initialized) {
132
            return;
133
        }
134
        setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
135

    
136
//        URL iconURL =
137
//            getClass().getClassLoader().getResource(
138
//                "images/thematicmap-editor.png");
139
        
140
        ImageIcon icon = IconThemeHelper.getImageIcon("thematicmap-editor-wizard");
141

    
142
        wizard = new WizardPanelWithLogo(icon);
143

    
144
        stepIdentification = new StepIdentification(this, allowChangeId);
145
        stepValidation = new StepValidation(this);
146

    
147
        wizard.addOptionPanel(stepIdentification);
148
        if (editLayers) {
149
            stepLayers = new StepLayers(this);
150
            wizard.addOptionPanel(stepLayers);
151
        }
152
        wizard.addOptionPanel(stepValidation);
153

    
154
        wizard.setWizardListener(this);
155
        setFinishButtonEnabled(false);
156

    
157
        this.setLayout(new BorderLayout());
158
        this.add(wizard, BorderLayout.CENTER);
159

    
160
        wizard.show();
161

    
162
        initialized = true;
163
    }
164

    
165
    /** {@inheridDoc} */
166
    public JComponent getSwingComponent() {
167
        initializeUI();
168
        return this;
169
    }
170

    
171
    /** {@inheridDoc} */
172
    public ThematicMapCompilation getCompilation() {
173
        return compilation;
174
    }
175

    
176
    /** {@inheridDoc} */
177
    public boolean goToFirstStep() {
178
        wizard.doAction(WizardPanelWithLogo.ACTION_FINISH);
179
        return true;
180
    }
181

    
182
    /** {@inheridDoc} */
183
    public boolean goNextStep() {
184
        wizard.doAction(WizardPanelWithLogo.ACTION_NEXT);
185
        return true;
186
    }
187

    
188
    /** {@inheridDoc} */
189
    public boolean goPreviousStep() {
190
        wizard.doAction(WizardPanelWithLogo.ACTION_PREVIOUS);
191
        return true;
192
    }
193

    
194
    /** {@inheridDoc} */
195
    public boolean goToLastStep() {
196
        wizard.doAction(WizardPanelWithLogo.ACTION_FINISH);
197
        return true;
198
    }
199

    
200
    /** {@inheridDoc} */
201
    public boolean isLastStep() {
202
        return wizard.getWizardComponents().getCurrentIndex() == wizard
203
            .getWizardComponents().getWizardPanelList().size() - 1;
204
    }
205

    
206
    /** {@inheridDoc} */
207
    public boolean isFirstStep() {
208
        return wizard.getWizardComponents().getCurrentIndex() == 0;
209
    }
210

    
211
    /** {@inheridDoc} */
212
    public boolean isCompilationValid() {
213
        List<CompilationValidationMessage> messages =
214
            new ArrayList<CompilationValidationMessage>();
215
        return compilation.isValid(messages);
216
    }
217

    
218
    public void setNextButtonEnabled(boolean isEnabled) {
219
        wizard.setNextButtonEnabled(isEnabled);
220
    }
221

    
222
    public void setCancelButtonEnabled(boolean isEnabled) {
223
        wizard.setCancelButtonEnabled(isEnabled);
224
    }
225

    
226
    public void setFinishButtonEnabled(boolean isEnabled) {
227
        wizard.setFinishButtonEnabled(isEnabled);
228
    }
229

    
230
    public void setBackButtonEnabled(boolean isEnabled) {
231
        wizard.setBackButtonEnabled(isEnabled);
232
    }
233

    
234
    /**
235
     * Finalizes wizard
236
     */
237
    public void finish() {
238
        // Checks all steps
239
        if (!updateFinishButton()) {
240
            return;
241
        }
242

    
243
        // Checks that compilation is valid
244
        if (!isCompilationValid()) {
245
            manager.getWindowManager().showMessageDialog(
246
                this.getSwingComponent(),
247
                manager.getTranslation("thematic_map_compilation_editor"),
248
                manager.getTranslation("current_values_are_not_valid"),
249
                MESSAGE_DIALOG_TYPE.ERROR);
250
            return;
251
        }
252
        close();
253
        this.listener.finished(this);
254
    }
255

    
256
    /**
257
     * Cancels wizard
258
     */
259
    public void cancel() {
260
        close();
261
        this.listener.canceled(this);
262
    }
263

    
264
    /**
265
     * Close this panel
266
     */
267
    private void close() {
268
        this.setVisible(false);
269
    }
270

    
271
    /** {@inheridDoc} */
272
    public void setListener(ThematicMapCompilationEditorListener listener) {
273
        this.listener = listener;
274
    }
275

    
276
    /**
277
     * Checks all steps states
278
     * 
279
     * @return true if all steps are ok
280
     */
281
    public boolean updateFinishButton() {
282
        if (!stepIdentification.isPanelDataOk()) {
283
            setFinishButtonEnabled(false);
284
            return false;
285
        }
286
        if (editLayers && !stepLayers.isPanelDataOk()) {
287
            setFinishButtonEnabled(false);
288
            return false;
289
        }
290
        if (!stepValidation.isPanelDataOk()) {
291
            setFinishButtonEnabled(false);
292
            return false;
293
        }
294
        setFinishButtonEnabled(true);
295
        return true;
296
    }
297

    
298
    /** {@inheridDoc} */
299
    public void setWizardPanelActionListener(
300
        WizardPanelActionListener wizardActionListener) {
301
        // Nothing to do
302

    
303
    }
304

    
305
    /** {@inheridDoc} */
306
    public WizardPanelActionListener getWizardPanelActionListener() {
307
        return this;
308
    }
309

    
310
    /** {@inheridDoc} */
311
    public void finish(WizardPanel wizardPanel) {
312
        finish();
313

    
314
    }
315

    
316
    /** {@inheridDoc} */
317
    public void cancel(WizardPanel wizardPanel) {
318
        cancel();
319

    
320
    }
321

    
322
    public void allowChangeId(boolean allow) {
323
        allowChangeId = allow;
324
        if (stepIdentification != null) {
325
            stepIdentification.allowChangeId(allow);
326
        }
327

    
328
    }
329

    
330
    public boolean isAllowedChangeId() {
331
        return allowChangeId;
332
    }
333
}