📄 wizardpage.java
字号:
package net.sf.dz.util.wizard;import java.awt.event.ActionEvent;import java.awt.event.ActionListener; import java.awt.event.ItemEvent;import java.awt.event.ItemListener; import java.util.EventObject;import java.util.HashSet;import java.util.Iterator;import java.util.Set;import java.util.SortedSet;import java.util.TreeSet;import javax.swing.event.CaretEvent;import javax.swing.event.CaretListener; import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.JPanel;import org.freehold.jukebox.logger.LogAware;import org.freehold.jukebox.logger.LogChannel;import org.freehold.jukebox.logger.Logger;/** * A wizard page representation. * * All the pages in the wizard have to extend this class, for it provides * the basic navigation and validation functions. * * @author Copyright © <a href="mailto:vt@freehold.crocodile.org">Vadim Tkachenko</a> 2001-2004 * @version $Id: WizardPage.java,v 1.13 2004/07/22 06:28:49 vtt Exp $ */abstract public class WizardPage extends LogAware implements ActionListener, CaretListener, ItemListener, ListSelectionListener { public final LogChannel CH_WP; private JPanel contentPane = new JPanel(); private String title; private Wizard owner; public WizardPage(Logger logger, Wizard owner, String title) { super(logger); if ( owner == null || title == null ) { throw new IllegalArgumentException("Neither owner nor title can be null"); } this.owner = owner; this.title = title; CH_WP = new LogChannel("WizardPage: " + title); } public final Wizard getOwner() { return owner; } public final String getTitle() { return title; } abstract public String getHelpURL(); public final JPanel getContentPane() { return contentPane; } public final void actionPerformed(ActionEvent e) { actionPerformed2(e); owner.validateButtons(); } protected void actionPerformed2(ActionEvent e) { reportUnprocessed(e); } public final void caretUpdate(CaretEvent e) { caretUpdate2(e); owner.validateButtons(); } protected void caretUpdate2(CaretEvent e) { reportUnprocessed(e); } public final void itemStateChanged(ItemEvent e) { itemStateChanged2(e); owner.validateButtons(); } protected void itemStateChanged2(ItemEvent e) { reportUnprocessed(e); } public final void valueChanged(ListSelectionEvent e) { valueChanged2(e); owner.validateButtons(); } protected void valueChanged2(ListSelectionEvent e) { reportUnprocessed(e); } /** * Inform the user that the event was not processed. * * This is the case when we made a mistake and missed an event handler. * * @param e Event to complain about. */ protected final void reportUnprocessed(EventObject e) { System.err.println("Wizard page: " + getTitle() + " (" + getClass().getName() + ")"); System.err.println("Unprocessed event: " + e); } /** * Validate the page. * * @return Error text, if any, or "" to indicate a valid page. */ abstract public String validate(); /** * Is the page enabled? * * If it is not, it will not be shown. * * @return true if the page is enabled. */ abstract public boolean isEnabled(); /** * Process page initialization. * * This method is called when the page is activated, whether at initial * display or a result of "Next" or "Back" operation. * * This method is not abstract, as opposed to others, because it is * rarely required. */ public void activate() { System.err.println("Wizard page: " + getTitle() + " (" + getClass().getName() + ")"); System.err.println("No activation procedure supplied"); } /** * Get the context values associated with the keys starting with a given * prefix. * * @param prefix A prefix to look up. * * @return An unordered set of values for all the prefixes starting with * the given. */ public Set getContextValues(String prefix) { Set result = new HashSet(); for ( Iterator i = getOwner().getContext().keySet().iterator(); i.hasNext(); ) { String key = i.next().toString(); if ( key.startsWith(prefix) ) { result.add(getOwner().getContext().get(key)); } } return result; } /** * Get the context values associated with the keys starting with a given * prefix, sorted. * * @param prefix A prefix to look up. * * @return An unordered set of values for all the prefixes starting with * the given. * * @exception ClassCastException if you're not careful and result set * contains values that are not <code>Comparable</code>. */ public SortedSet getSortedContextValues(String prefix) { return new TreeSet(getContextValues(prefix)); } public boolean isVisible() { return getOwner().isVisible(this); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -