001/* ----------------------------------------------------------------------------
002   The Kiwi Toolkit - A Java Class Library
003   Copyright (C) 1998-2004 Mark A. Lindner
004
005   This library is free software; you can redistribute it and/or
006   modify it under the terms of the GNU General Public License as
007   published by the Free Software Foundation; either version 2 of the
008   License, or (at your option) any later version.
009
010   This library is distributed in the hope that it will be useful,
011   but WITHOUT ANY WARRANTY; without even the implied warranty of
012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013   General Public License for more details.
014
015   You should have received a copy of the GNU General Public License
016   along with this library; if not, write to the Free Software
017   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
018   02111-1307, USA.
019 
020   The author may be contacted at: mark_a_lindner@yahoo.com
021   ----------------------------------------------------------------------------
022   $Log: WizardPanel.java,v $
023   Revision 1.10  2004/05/12 18:54:47  markl
024   comment block updates
025
026   Revision 1.9  2003/01/19 09:50:54  markl
027   Javadoc & comment header updates.
028
029   Revision 1.8  2001/03/12 09:56:54  markl
030   KLabel/KLabelArea changes.
031
032   Revision 1.7  2001/03/12 09:28:02  markl
033   Source code and Javadoc cleanup.
034
035   Revision 1.6  2000/08/26 09:04:41  markl
036   Changed Wizard*.java APIs to facilitate easier control over forward/
037   backward navigation.
038
039   Revision 1.5  1999/02/28 11:44:08  markl
040   Minor fixes.
041
042   Revision 1.4  1999/02/28 00:27:35  markl
043   Fixed a layout problem by adding a call to validate().
044
045   Revision 1.3  1999/02/27 14:43:59  markl
046   softened etched border
047
048   Revision 1.2  1999/01/10 03:05:32  markl
049   added GPL header & RCS tag
050   ----------------------------------------------------------------------------
051*/
052
053package kiwi.ui;
054
055import java.awt.*;
056import javax.swing.*;
057import javax.swing.border.*;
058import javax.swing.event.*;
059
060import kiwi.event.*;
061import kiwi.util.*;
062
063/** This class represents a single user interface panel for a
064  * <code>WizardView</code> component. Subclassers should not construct the
065  * panel's user interface in the constructor, but rather, should provide an
066  * implementation for <code>buildUI()</code> that fills this purpose.
067  *
068  * @author Mark Lindner
069  *
070  * @see kiwi.ui.WizardView
071  * @see kiwi.ui.WizardPanelSequence
072  */
073
074public abstract class WizardPanel extends KPanel
075  {
076  private ChangeSupport support;
077  private KLabel l_title;
078  /** The configuration object for the <code>WizardPanelSequence</code> that
079    * owns this <code>WizardPanel</code>.
080    */
081  protected Config config;
082  private static Font defaultFont = new Font("Dialog", Font.BOLD, 14);
083
084  /** Construct a new <code>WizardPanel</code>.
085    */
086  
087  public WizardPanel()
088    {
089    support = new ChangeSupport(this);
090    setOpaque(false);
091    
092    setLayout(new BorderLayout(5, 5));
093
094    KPanel p_top = new KPanel();
095    p_top.setLayout(new BorderLayout(5, 5));
096
097    l_title = new KLabel("Untitled");
098    p_top.add("Center", l_title);
099
100    add("North", p_top);
101
102    KPanel p_center = new KPanel();
103    p_center.setBorder(
104      new CompoundBorder(new SoftBevelBorder(BevelBorder.LOWERED),
105                         KiwiUtils.defaultBorder));
106    p_center.setLayout(new GridLayout(1, 0));
107    
108    p_center.add(buildUI());
109    
110    add("Center", p_center);
111    }
112
113  /** Build the user interface for this <code>WizardPanel</code>. This method
114    * must build and return the component that will be displayed in this
115    * <code>WizardPanel</code>. Typically the implementor will instantiate
116    * a container such as <code>KPanel</code>, add interface components to it,
117    * and then return that container.
118    *
119    * @return The component that will be displayed in this panel.
120    */
121  
122  protected abstract Component buildUI();
123
124  /** Synchronize this <code>WizardPanel</code>'s user interface. This method
125    * is called by the <code>WizardView</code> immediately before this panel is
126    * made visible to the user. This allows the implementor to update the
127    * state of the components that make up this panel's interface, perhaps
128    * based on the current values of the <code>WizardPanelSequence</code>'s
129    * <code>Config</code> properties.
130    */
131  
132  public abstract void syncUI();
133
134  /** Synchronize this <code>WizardPanel</code>'s data. This method is called
135    * by the <code>WizardView</code> immediately after this panel is made
136    * invisible (such as when the user moves to the next or previous panel).
137    * This allows the implementor to update the <code>Config</code> properties
138    * based on the values entered in the panel's user interface.
139    */
140  
141  public abstract void syncData();
142
143  /** Set the title for this <code>WizardPanel</code>. The title is displayed
144    * at the top of the panel.
145    *
146    * @param title The new title, or <code>null</code> if no title is needed.
147    */
148  
149  protected final void setTitle(String title)
150    {
151    l_title.setText(title);
152    }
153  
154  /* attach a reference to the global configuration object */
155  
156  final void setConfig(Config config)
157    {
158    this.config = config;
159    }
160
161  /** Begin focus in this component. This method is called by the
162    * <code>WizardView</code> immediately after this panel is made visible to
163    * the user. It allows the panel to give input focus to the appropriate
164    * component in its user interface. The default implementation requests
165    * focus for the panel's first child component.
166    */
167  
168  public void beginFocus()
169    {
170    if(getComponentCount() > 0)
171      getComponent(0).requestFocus();
172    }
173
174  /** Add a <code>ChangeListener</code> to this object's list of listeners.
175    *
176    * @param listener The listener to add.
177    */  
178  
179  public void addChangeListener(ChangeListener listener)
180    {
181    support.addChangeListener(listener);
182    }
183
184  /** Remove a <code>ChangeListener</code> from this object's list of
185    * listeners.
186    *
187    * @param listener The listener to remove.
188    */
189  
190  public void removeChangeListener(ChangeListener listener)
191    {
192    support.removeChangeListener(listener);
193    }
194
195  /** Fire a change event. <code>WizardPanel</code>s should fire
196    * <code>ChangeEvent</code>s whenever a change in their internal state
197    * would affect the appearance of the <code>WizardView</code>. For example,
198    * the user may complete data entry in a panel, which should undim the
199    * <code>WizardView</code>'s <i>Next</i> button to allow the user to proceed
200    * to the next panel.
201    */
202  
203  protected void fireChangeEvent()
204    {
205    support.fireChangeEvent();
206    }
207
208  /** Determine if the user can move forward to the next panel.
209   *
210   * @return <code>true</code> if the next panel can be shown, and
211   * <code>false</code> otherwise. The default implementation returns
212   * <code>true</code>.
213   */
214
215  public boolean canMoveForward()
216    {
217    return(true);
218    }
219
220  /** Determine if the user can move backward to the previous panel.
221   *
222   * @return <code>true</code> if the previous panel can be shown, and
223   * <code>false</code> otherwise. The default implementation returns
224   * <code>true</code>.
225   */
226
227  public boolean canMoveBackward()
228    {
229    return(true);
230    }
231
232  }
233
234/* end of source file */