All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.juife.swing.wizard.WizardPage Maven / Gradle / Ivy

There is a newer version: 0.7
Show newest version
/*
 *   juife - Java User Interface Framework Extensions
 *
 *   Copyright (C) 2005-2007 Grigor Iliev 
 *
 *   This file is part of juife.
 *
 *   juife is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Lesser General Public
 *   License version 2.1 as published by the Free Software Foundation.
 *
 *   juife is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *   Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with juife; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *   MA  02110-1301, USA
 */

package net.sf.juife.swing.wizard;

import java.awt.Dialog;

import javax.swing.JPanel;

import net.sf.juife.swing.JuifeUtils;
import net.sf.juife.swing.Wizard;


/**
 * The base class for all types of wizard pages.
 * Override this class if you want to create a custom wizard page of a specific type.
 * @see WizardPage.Type
 * @author  Grigor Iliev
 */
public class WizardPage extends JPanel {
	private String description;
	private String subtitle;
	
	private Wizard wizard = null;
	
	/** Represents the type of a wizard page. */
	public enum Type {
		/** Represents an overview page. */
		OVERVIEW_PAGE,
		
		/** Represents a requirements page. */
		REQUIREMENTS_PAGE,
		
		/** Represents an user-input page. */
		USER_INPUT_PAGE,
		
		/**
		 * Represents a conformation page.
		 * Use CONFIRMATION_PAGE_EX if
		 * you want the 'Next' button to be displayed.
		 */
		CONFIRMATION_PAGE,
		
		/**
		 * Represents a conformation page.
		 * The difference between CONFIRMATION_PAGE and
		 * CONFIRMATION_PAGE_EX is the visibility of the 'Next' button.
		 * Use CONFIRMATION_PAGE if
		 * you don't want the 'Next' button to be displayed.
		 */
		CONFIRMATION_PAGE_EX,
		
		/** Represents a progress page. */
		PROGRESS_PAGE,
		
		/** Represents a summary page. */
		SUMMARY_PAGE
	}
	
	/** Specifies the type of this page. */
	private Type pageType;
	
	/**
	 * Represents the optional buttons to be shown
	 * in the wizard when the page becomes current.
	 */
	public enum OptionalButtons {
		/** Indicates that none of the optional buttons will be shown. */
		NONE,
		
		/**
		 * Indicates that only the 'Help' button from the optional buttons will be shown.
		 */
		HELP,
		
		/**
		 * Indicates that only the 'Last' button from the optional buttons will be shown.
		 */
		LAST,
		
		/** Indicates that both 'Help' and 'Last' buttons will be shown. */
		HELP_AND_LAST
	}
	
	/**
	 * Specifies the optional buttons that will be shown
	 * in the wizard when this wizard page becomes current.
	 */
	private OptionalButtons optionalButtons;
	
	
	/**
	 * Creates a new WizardPage with null subtitle and description.
	 */
	public
	WizardPage() { this(null); }
	
	/**
	 * Creates a WizardPage with the specified subtitle and 
	 * null description.
	 * @param subtitle The subtitle text to be shown
	 * in the wizard when this page becomes current.
	 */
	public
	WizardPage(String subtitle) { this(subtitle, null); }
	
	/**
	 * Creates a WizardPage with the specified subtitle and description.
	 * @param subtitle The subtitle text to be shown
	 * in the wizard when this page becomes current.
	 * @param description A brief description of the page.
	 */
	public
	WizardPage(String subtitle, String description) {
		this(subtitle, description, Type.USER_INPUT_PAGE);
	}
	
	/**
	 * Creates a WizardPage with the
	 * specified subtitle, description and page type.
	 * @param subtitle The subtitle text to be shown
	 * in the wizard when this page becomes current.
	 * @param description A brief description of the page.
	 * @param pageType Specifies the page type.
	 */
	public
	WizardPage(String subtitle, String description, Type pageType) {
		this(subtitle, description, pageType, OptionalButtons.NONE);
	}
	
	/**
	 * Creates a WizardPage with the specified
	 * subtitle, description, page type and optional buttons.
	 * @param subtitle The subtitle text to be shown
	 * in the wizard when this page becomes current.
	 * @param description A brief description of the page.
	 * @param pageType Specifies the page type.
	 * @param optionalButtons Specifies the optional buttons
	 * to be shown in the wizard when this wizard page becomes current.
	 */
	public
	WizardPage (
		String subtitle,
		String description,
		Type pageType,
		OptionalButtons optionalButtons
	) {
		setSubtitle(subtitle);
		setDescription(description);
		setPageType(pageType);
		setOptionalButtons(optionalButtons);
	}
	
	/**
	 * Gets a brief description about this page.
	 * @return Returns a brief description about this page or null
	 * if this is not the first page in current step
	 */
	public String
	getDescription() { return description; }
	
	/**
	 * Sets a brief description about this page. This description is used by Wizard to
	 * create a list of steps in his Left Pane.
	 * 

Notice that each step in the list can correspond to more than one wizard pages. * To achieve this set the description text only in the first page and null * in next pages of current step

*/ public void setDescription(String s) { description = s; } /** * Gets the subtitle for this page. * @return the subtitle for this page. */ public String getSubtitle() { return subtitle; } /** * Sets the subtitle for this page. */ public void setSubtitle(String subtitle) { this.subtitle = subtitle; } /** * Gets the type of this page. * @return The type of this page. */ public Type getPageType() { return pageType; } /** * Sets the type of this page. * @param pageType The new type of this page. */ public void setPageType(Type pageType) { this.pageType = pageType; } /** * Determines the optional buttons that will be shown * in the wizard when this page becomes current. * @return An OptionalButtons instance specifying the optional * buttons that will be shown in the wizard when this wizard page becomes current. */ public OptionalButtons getOptionalButtons() { return optionalButtons; } /** * Sets the optional buttons to be displayed * in the wizard when this page becomes current. * @param optionalButtons Specifies the optional buttons * to be shown in the wizard when this wizard page becomes current. */ public void setOptionalButtons(OptionalButtons optionalButtons) { this.optionalButtons = optionalButtons; } /** * Gets the Wizard to which this page belongs to. * Note that this method will return null until the * page becomes current in the wizard. * @return the Wizard to which this page belongs to, * or null. * @see #setWizard */ public Wizard getWizard() { return wizard; } /** * Sets the Wizard to which this page belongs to. * @param wizard the Wizard to which this page belongs to. */ public void setWizard(Wizard wizard) { this.wizard = wizard; } /** * Gets the WizardModel to which this page belongs to. * @return the WizardModel to which this page belongs to, * or null if getWizard() returns null. * @see #getWizard */ public WizardModel getWizardModel() { return getWizard() == null ? null : getWizard().getModel(); } /** * Gets the wizard's dialog. * This method can be used to change the wizard's size, location, etc. * @return The wizard's dialog. */ public Dialog getWizardDialog() { return (Dialog)JuifeUtils.getWindow(this); } /** * Invoked when the page is going to become current in the wizard. * Override this method to do some initializations before the page is shown in the wizard. * The execution of this method should not be time consuming. * The current implementation does nothing. */ public void preinitPage() { } /** * Invoked when the page becomes current in the wizard. * Override this method to do some initializations after the page is shown in the wizard. * The execution of this method should not be time consuming. * The current implementation does nothing. */ public void postinitPage() { } /** * Invoked when the user clicks the 'Back' button * while this page is the current page of the wizard. * Override this method to cancel the movement to previous page, or * to do some additional tasks before that. The return value determines * whether the movement to previous page should be done. * You should return true to allow the wizard to go to * previous page, and false to cancel this operation. * @return true */ public boolean mayGoToPrevious() { return true; } /** * Invoked when the user clicks the 'Next' button * while this page is the current page of the wizard. * Override this method to cancel the movement to next page, or * to do some additional tasks before that. The return value determines * whether the movement to next page should be done. * You should return true to allow the wizard to go to * next page, and false to cancel this operation. * @return true */ public boolean mayGoToNext() { return true; } /** * Invoked when the user clicks the 'Last' button * while this page is the current page of the wizard. * Override this method to cancel the movement to last page, or * to do some additional tasks before that. The return value determines * whether the movement to last page should be done. * You should return true to allow the wizard to go to * last page, and false to cancel this operation. * @return true */ public boolean mayGoToLast() { return true; } /** * Invoked when the user clicks the 'Finish' button * while this page is the current page of the wizard. * Override this method to cancel this operation, or to do some * additional tasks before that. The return value determines * whether this operation should be done. * You should return true to allow the wizard to * finish, and false to cancel this operation. * @return true */ public boolean mayFinish() { return true; } /** * Invoked when the user clicks the 'Cancel' button * while this page is the current page of the wizard. * Override this method to cancel this operation, or to do some * additional tasks before that. The return value determines * whether this operation should be done. * You should return true to allow the wizard to * cancel, and false otherwise. * @return true */ public boolean mayCancel() { return true; } /** * Invoked when the user clicks the 'Close' button * while this page is the current page of the wizard. * Override this method to cancel this operation, or to do some * additional tasks before that. The return value determines * whether this operation should be done. * You should return true to allow the wizard to * close, and false otherwise. * @return true */ public boolean mayClose() { return true; } /** * Invoked when the user clicks the Help button of the wizard. * Override this method to show some additional help to the user about this page. */ public void showHelp() { } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy