alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.modules.xml.core.wizard;

import java.util.*;
import java.beans.*;

import javax.swing.*;
import javax.swing.event.*;

import org.openide.*;
import org.openide.util.HelpCtx;
import java.net.URL;

/**
 * Base class of wizardable panels. updateModel
 * and initView methods need to be implemented. They are called as user goes 
 * over wizard steps and it must (re)store current state.
 * 

* For proper functionality it must be wrapped by {@link WizardStep}. * * @author Petr Kuzel * @version */ public abstract class AbstractPanel extends JPanel implements Customizer { /** Serial Version UID */ private static final long serialVersionUID =508989667995691L; /** * After a setObject() call contains current model driving wizard. */ protected DocumentModel model; // associated wizard step wrapper (initialized by step. private WizardStep step; /** * User just leaved the panel, update model */ protected abstract void updateModel(); /** * User just entered the panel, init view by model values */ protected abstract void initView(); /** * User just reentered the panel. */ protected abstract void updateView(); // customizer impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public void setObject(Object model) { if ( not(model instanceof DocumentModel) ) { throw new IllegalArgumentException("DocumentModel class expected."); // NOI18N } this.model = (DocumentModel) model; initView(); } public void addPropertyChangeListener(PropertyChangeListener p1) { } public void removePropertyChangeListener(PropertyChangeListener p1) { } protected static boolean not(boolean expr) { return ! expr; } /** * Gives access to WizardStep wrapper. * It is supported only for AbstractPanel with associated WizardStep. * @return step or IllegalStateException exception. */ protected final WizardStep getStep() { if (step == null) throw new IllegalStateException("new WizardStep(this) have not been called!"); return step; } /** * WizardDescriptor.Panel adapter for AbstractPanel. * It solved isValid() clash between Component and WizardDescriptor.Panel. */ public static class WizardStep implements WizardDescriptor.Panel { private final AbstractPanel peer; private Vector listeners = new Vector(); private final ChangeEvent EVENT = new ChangeEvent(this); private boolean valid = true; public WizardStep(AbstractPanel peer) { if (peer == null) throw new NullPointerException(); this.peer = peer; peer.step = this; } public java.awt.Component getComponent() { return peer; } public void readSettings(Object settings) { peer.updateView(); } /** * Cunstruct help ctx from WizardPanel_helpURL property. */ public final HelpCtx getHelp() { // URL url = (URL) getClientProperty("WizardPanel_helpURL"); // if (url != null) { return new HelpCtx(peer.getClass()); // warning getClass(0 returns a subclass // } // return null; } public void addChangeListener(javax.swing.event.ChangeListener l) { listeners.add(l); } public void storeSettings(Object settings) { peer.updateModel(); } public boolean isValid() { return valid; } protected final void setValid(boolean valid) { if (this.valid == valid) return; this.valid = valid; synchronized (listeners) { Iterator it = listeners.iterator(); while (it.hasNext()) { ChangeListener next = (ChangeListener) it.next(); next.stateChanged(EVENT); } } } public void removeChangeListener(ChangeListener l) { listeners.remove(l); } } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.