01: /**
02: * Wizard Framework
03: * Copyright 2004 - 2005 Andrew Pietsch
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: * $Id: StaticModelOverview.java,v 1.4 2006/05/13 19:54:32 pietschy Exp $
20: */package org.pietschy.wizard.models;
21:
22: import org.pietschy.wizard.WizardStep;
23: import org.pietschy.wizard.Wizard;
24: import org.pietschy.wizard.I18n;
25:
26: import javax.swing.*;
27: import java.beans.PropertyChangeListener;
28: import java.beans.PropertyChangeEvent;
29: import java.awt.*;
30: import java.util.Iterator;
31: import java.util.HashMap;
32:
33: /**
34: * This class provides an overview panel for instances of {@link StaticModel}.
35: */
36: public class StaticModelOverview extends JPanel implements
37: PropertyChangeListener {
38: private StaticModel model;
39: private HashMap labels = new HashMap();
40:
41: public StaticModelOverview(StaticModel model) {
42: this .model = model;
43: this .model.addPropertyChangeListener(this );
44: setBackground(Color.WHITE);
45: // we do this to ensure laf's like quaqua still render as opaque.
46: setOpaque(true);
47: setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
48: setLayout(new BoxLayout(this , BoxLayout.PAGE_AXIS));
49:
50: JLabel title = new JLabel(I18n
51: .getString("StaticModelOverview.title"));
52: title.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));
53: ;
54: title.setAlignmentX(0);
55: title.setMaximumSize(new Dimension(Integer.MAX_VALUE, title
56: .getMaximumSize().height));
57: add(title);
58: int i = 1;
59: for (Iterator iter = model.stepIterator(); iter.hasNext();) {
60: WizardStep step = (WizardStep) iter.next();
61: JLabel label = new JLabel("" + i++ + ". " + step.getName());
62:
63: label.setBackground(new Color(240, 240, 240));
64: label
65: .setBorder(BorderFactory.createEmptyBorder(2, 4, 2,
66: 4));
67: label.setAlignmentX(0);
68: label.setMaximumSize(new Dimension(Integer.MAX_VALUE, label
69: .getMaximumSize().height));
70: add(label);
71: labels.put(step, label);
72: }
73:
74: add(Box.createGlue());
75: }
76:
77: public void propertyChange(PropertyChangeEvent evt) {
78: if (evt.getPropertyName().equals("activeStep")) {
79: JLabel old = (JLabel) labels.get(evt.getOldValue());
80: if (old != null)
81: formatInactive(old);
82:
83: JLabel label = (JLabel) labels.get(evt.getNewValue());
84: formatActive(label);
85: repaint();
86: }
87: }
88:
89: protected void formatActive(JLabel label) {
90: label.setOpaque(true);
91: }
92:
93: protected void formatInactive(JLabel label) {
94: label.setOpaque(false);
95: }
96: }
|