Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / wizard / WizardPanelWithLogo.java @ 43126

History | View | Annotate | Download (6 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.wizard;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.Color;
28

    
29
import javax.swing.ImageIcon;
30
import javax.swing.JLabel;
31
import javax.swing.JPanel;
32
import javax.swing.JSeparator;
33

    
34
import jwizardcomponent.CancelAction;
35
import jwizardcomponent.DefaultJWizardComponents;
36
import jwizardcomponent.FinishAction;
37
import jwizardcomponent.common.SimpleButtonPanel;
38

    
39
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
40
import org.gvsig.gui.beans.wizard.panel.OptionPanelContainer;
41
import org.slf4j.Logger;
42
import org.slf4j.LoggerFactory;
43

    
44
public class WizardPanelWithLogo extends JPanel {
45

    
46
    private static final Logger LOG = LoggerFactory.getLogger(WizardPanelWithLogo.class);
47
            
48
    private static final long serialVersionUID = 7506729926181935234L;
49
    public final static int ACTION_PREVIOUS = 0;
50
    public final static int ACTION_NEXT = 1;
51
    public final static int ACTION_CANCEL = 2;
52
    public final static int ACTION_FINISH = 3;
53

    
54
    DefaultJWizardComponents wizardComponents;
55

    
56
    JPanel buttonPanel;
57
    JLabel statusLabel = new JLabel();
58

    
59
    ImageIcon logo;
60
    private int direction = WizardPanelWithLogo.ACTION_NEXT;
61

    
62
    public WizardPanelWithLogo(ImageIcon logo) {
63
        this.logo = logo;
64
        wizardComponents = new DefaultJWizardComponents();
65
        init();
66
    }
67

    
68
    public WizardPanelWithLogo() {
69
        wizardComponents = new DefaultJWizardComponents();
70
        this.logo = null;
71
        init();
72
    }
73

    
74
    private void init() {
75

    
76
        this.setLayout(new BorderLayout());
77
        if (logo != null) {
78
            JPanel logoPanel = new JPanel();
79
            logoPanel.add(new JLabel(logo));
80
            logoPanel.setBackground(Color.WHITE);
81
            this.add(logoPanel, BorderLayout.WEST);
82
        }
83

    
84
        this.add(wizardComponents.getWizardPanelsContainer(),
85
            BorderLayout.CENTER);
86

    
87
        JPanel auxPanel = new JPanel(new BorderLayout());
88
        auxPanel.add(new JSeparator(), BorderLayout.NORTH);
89

    
90
        buttonPanel = new SimpleButtonPanel(wizardComponents);
91
        auxPanel.add(buttonPanel);
92
        this.add(auxPanel, BorderLayout.SOUTH);
93

    
94
        wizardComponents.setFinishAction(new FinishAction(wizardComponents) {
95

    
96
            @Override
97
            public void performAction() {
98
                // dispose();
99
            }
100
        });
101
        wizardComponents.setCancelAction(new CancelAction(wizardComponents) {
102

    
103
            @Override
104
            public void performAction() {
105
                // dispose();
106
            }
107
        });
108
    }
109

    
110
    public void doAction(int action) {
111
        switch (action) {
112
        case ACTION_NEXT:
113
            getWizardComponents().getNextButton().getActionListeners()[0]
114
                .actionPerformed(null);
115
            break;
116
        case ACTION_PREVIOUS:
117
            getWizardComponents().getBackButton().getActionListeners()[0]
118
                .actionPerformed(null);
119
            break;
120
        }
121
    }
122

    
123
    public DefaultJWizardComponents getWizardComponents() {
124
        return wizardComponents;
125
    }
126

    
127
    public void setWizardComponents(DefaultJWizardComponents aWizardComponents) {
128
        wizardComponents = aWizardComponents;
129
    }
130

    
131
    @Override
132
    public void show() {
133
        wizardComponents.updateComponents();
134
        super.setVisible(true);
135
    }
136
    
137
    public void updatePanel() {
138
        try {
139
            OptionPanelContainer page = (OptionPanelContainer) getWizardComponents().getCurrentPanel();
140
            page.update();
141
        } catch (Exception ex) {
142

    
143
        }
144
    }
145

    
146
    public void addOptionPanel(OptionPanel optionPanel) {
147
        getWizardComponents().addWizardPanel(
148
            new OptionPanelContainer(this, optionPanel)
149
        );
150
    }
151

    
152
    public void setNextButtonEnabled(boolean isEnabled) {
153
        getWizardComponents().getNextButton().setEnabled(isEnabled);
154
    }
155

    
156
    public void setFinishButtonEnabled(boolean isVisible) {
157
        getWizardComponents().getFinishButton().setEnabled(isVisible);
158
    }
159

    
160
    public void setCancelButtonEnabled(boolean isVisible) {
161
        getWizardComponents().getCancelButton().setEnabled(isVisible);
162
    }
163

    
164
    private void setFinishAction(FinishAction finishAction) {
165
        getWizardComponents().setFinishAction(finishAction);
166
    }
167

    
168
    private void setCancelAction(CancelAction cancelAction) {
169
        getWizardComponents().setCancelAction(cancelAction);
170
    }
171

    
172
    public void setWizardListener(WizardPanel wizardPanel) {
173
        setFinishAction(new WizardPanelFinishAction(getWizardComponents(),
174
            wizardPanel));
175
        setCancelAction(new WizardPanelCancelAction(getWizardComponents(),
176
            wizardPanel));
177
    }
178

    
179
    public void setBackButtonEnabled(boolean isEnabled) {
180
        getWizardComponents().getBackButton().setEnabled(isEnabled);
181
    }
182
    
183
    public int getDirection() {
184
        return this.direction;
185
    }
186
    
187
    public void setDirection(int direction) {
188
        this.direction = direction;
189
    }
190
    
191
    public void skip() {
192
        int index = -1;
193
        try {
194
            this.doAction(this.getDirection());
195
        } catch (Exception ex) {
196
            LOG.warn("Can't skip current panel ("+index+").",ex);
197
        }
198
    }
199
}