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-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
/*
 * FxProvider.java
 *
 * Created on March 27, 2004, 9:04 PM
 */

package org.netbeans.swing.tabcontrol.plaf;

import javax.swing.*;

/** Class which can provide sliding or other eye-candy effects as a component
 * is displayed.  To use, subclass TabbedContainerUI and create an instance 
 * in createFxProvider.  The abstract doFinish() method is expected to call
 * TabbedContainerUI.showComponent(), so this is best implemented as an inner
 * class of a TabbbedContainerUI implementation.
 *
 * @author  Tim Boudreau
 */
public abstract class FxProvider {
    protected JComponent comp;
    protected JRootPane root;
    private boolean running = false;
    protected Object orientation = null;
    /** Creates a new instance of FxProvider */
    public FxProvider() {
    }
    
    /** Start the effect running.  This method will set up the fields with 
     * the passed values, set the running flag, and then call doStart().
     * If isRunning() is true, calls abort() before
     * initializing.
     */
    public final void start(JComponent comp, JRootPane root, Object orientation) {
        if (running) {
            if (comp == this.comp && root == this.root) {
                return;
            } else {
                abort();
            }
        }
        this.comp = comp;
        this.root = root;
        this.orientation = orientation;
        running = true;
        doStart();
    }
    
    /** 
     * Perform any cleanup necessary and complete the effect.
     * Sets the running flag to false, calls doFinish() (in which
     * the implementation should call showComponent() on the TabbedContainerUI
     * to actually show the component for which an effect has been being 
     * presented. After calling finish(), it 
     * calls cleanup().  The common use case is for the effect
     * to be painted on the window's glass pane, so the idea is to leave that
     * onscreen while doing the work that will display the actual component,
     * and then hide the glass pane containing the effect's product once the
     * window is in its new state, with the component displayed.
     */
    public final void finish() {
        running = false;
        doFinish();
        cleanup();
    }
    
    /** Abort a running effect, so that finish will never be called.  Sets
     * the running flag to false and calls cleanup(). */
    public final void abort() {
        running = false;
        cleanup();
        comp = null;
        root = null;
    }
    
    /** Determine if an effect is currently running */
    public final boolean isRunning() {
        return running;
    }

    /** Clean up any artifacts of the effect, shut down timers, etc. */
    public abstract void cleanup();
    
    /** Implement whatever is needed to begin running the effect - starting a
     * timer, playing with the glass pane, creating offscreen images, etc.,
     * here */
    protected abstract void doStart();
    
    /** Finish the operation - this method should be implemented to actually
     * install the component and leave the displayer in its final state */
    protected abstract void doFinish();
    
}
... 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.