KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > swing > tabcontrol > plaf > FxProvider


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * FxProvider.java
21  *
22  * Created on March 27, 2004, 9:04 PM
23  */

24
25 package org.netbeans.swing.tabcontrol.plaf;
26
27 import javax.swing.*;
28
29 /** Class which can provide sliding or other eye-candy effects as a component
30  * is displayed. To use, subclass TabbedContainerUI and create an instance
31  * in createFxProvider. The abstract doFinish() method is expected to call
32  * TabbedContainerUI.showComponent(), so this is best implemented as an inner
33  * class of a TabbbedContainerUI implementation.
34  *
35  * @author Tim Boudreau
36  */

37 public abstract class FxProvider {
38     protected JComponent comp;
39     protected JRootPane root;
40     private boolean running = false;
41     protected Object JavaDoc orientation = null;
42     /** Creates a new instance of FxProvider */
43     public FxProvider() {
44     }
45     
46     /** Start the effect running. This method will set up the fields with
47      * the passed values, set the running flag, and then call <code>doStart()</code>.
48      * If <code>isRunning()</code> is true, calls <code>abort()</code> before
49      * initializing.
50      */

51     public final void start(JComponent comp, JRootPane root, Object JavaDoc orientation) {
52         if (running) {
53             if (comp == this.comp && root == this.root) {
54                 return;
55             } else {
56                 abort();
57             }
58         }
59         this.comp = comp;
60         this.root = root;
61         this.orientation = orientation;
62         running = true;
63         doStart();
64     }
65     
66     /**
67      * Perform any cleanup necessary and complete the effect.
68      * Sets the running flag to false, calls <code>doFinish()</code> (in which
69      * the implementation should call showComponent() on the TabbedContainerUI
70      * to actually show the component for which an effect has been being
71      * presented. <strong>After</strong> calling <code>finish()</code>, it
72      * calls <code>cleanup()</code>. The common use case is for the effect
73      * to be painted on the window's glass pane, so the idea is to leave that
74      * onscreen while doing the work that will display the actual component,
75      * and then hide the glass pane containing the effect's product once the
76      * window is in its new state, with the component displayed.
77      */

78     public final void finish() {
79         running = false;
80         doFinish();
81         cleanup();
82     }
83     
84     /** Abort a running effect, so that finish will never be called. Sets
85      * the running flag to false and calls <code>cleanup()</code>. */

86     public final void abort() {
87         running = false;
88         cleanup();
89         comp = null;
90         root = null;
91     }
92     
93     /** Determine if an effect is currently running */
94     public final boolean isRunning() {
95         return running;
96     }
97
98     /** Clean up any artifacts of the effect, shut down timers, etc. */
99     public abstract void cleanup();
100     
101     /** Implement whatever is needed to begin running the effect - starting a
102      * timer, playing with the glass pane, creating offscreen images, etc.,
103      * here */

104     protected abstract void doStart();
105     
106     /** Finish the operation - this method should be implemented to actually
107      * install the component and leave the displayer in its final state */

108     protected abstract void doFinish();
109     
110 }
111
Popular Tags