~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to core/swing/tabcontrol/src/org/netbeans/swing/tabcontrol/plaf/FxProvider.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
/*
 
42
 * FxProvider.java
 
43
 *
 
44
 * Created on March 27, 2004, 9:04 PM
 
45
 */
 
46
 
 
47
package org.netbeans.swing.tabcontrol.plaf;
 
48
 
 
49
import javax.swing.*;
 
50
 
 
51
/** Class which can provide sliding or other eye-candy effects as a component
 
52
 * is displayed.  To use, subclass TabbedContainerUI and create an instance
 
53
 * in createFxProvider.  The abstract doFinish() method is expected to call
 
54
 * TabbedContainerUI.showComponent(), so this is best implemented as an inner
 
55
 * class of a TabbbedContainerUI implementation.
 
56
 *
 
57
 * @author  Tim Boudreau
 
58
 */
 
59
public abstract class FxProvider {
 
60
    protected JComponent comp;
 
61
    protected JRootPane root;
 
62
    private boolean running = false;
 
63
    protected Object orientation = null;
 
64
    /** Creates a new instance of FxProvider */
 
65
    public FxProvider() {
 
66
    }
 
67
    
 
68
    /** Start the effect running.  This method will set up the fields with 
 
69
     * the passed values, set the running flag, and then call <code>doStart()</code>.
 
70
     * If <code>isRunning()</code> is true, calls <code>abort()</code> before
 
71
     * initializing.
 
72
     */
 
73
    public final void start(JComponent comp, JRootPane root, Object orientation) {
 
74
        if (running) {
 
75
            if (comp == this.comp && root == this.root) {
 
76
                return;
 
77
            } else {
 
78
                abort();
 
79
            }
 
80
        }
 
81
        this.comp = comp;
 
82
        this.root = root;
 
83
        this.orientation = orientation;
 
84
        running = true;
 
85
        doStart();
 
86
    }
 
87
    
 
88
    /** 
 
89
     * Perform any cleanup necessary and complete the effect.
 
90
     * Sets the running flag to false, calls <code>doFinish()</code> (in which
 
91
     * the implementation should call showComponent() on the TabbedContainerUI
 
92
     * to actually show the component for which an effect has been being 
 
93
     * presented. <strong>After</strong> calling <code>finish()</code>, it 
 
94
     * calls <code>cleanup()</code>.  The common use case is for the effect
 
95
     * to be painted on the window's glass pane, so the idea is to leave that
 
96
     * onscreen while doing the work that will display the actual component,
 
97
     * and then hide the glass pane containing the effect's product once the
 
98
     * window is in its new state, with the component displayed.
 
99
     */
 
100
    public final void finish() {
 
101
        running = false;
 
102
        doFinish();
 
103
        cleanup();
 
104
    }
 
105
    
 
106
    /** Abort a running effect, so that finish will never be called.  Sets
 
107
     * the running flag to false and calls <code>cleanup()</code>. */
 
108
    public final void abort() {
 
109
        running = false;
 
110
        cleanup();
 
111
        comp = null;
 
112
        root = null;
 
113
    }
 
114
    
 
115
    /** Determine if an effect is currently running */
 
116
    public final boolean isRunning() {
 
117
        return running;
 
118
    }
 
119
 
 
120
    /** Clean up any artifacts of the effect, shut down timers, etc. */
 
121
    public abstract void cleanup();
 
122
    
 
123
    /** Implement whatever is needed to begin running the effect - starting a
 
124
     * timer, playing with the glass pane, creating offscreen images, etc.,
 
125
     * here */
 
126
    protected abstract void doStart();
 
127
    
 
128
    /** Finish the operation - this method should be implemented to actually
 
129
     * install the component and leave the displayer in its final state */
 
130
    protected abstract void doFinish();
 
131
    
 
132
}