KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > view > ui > slides > SlideOperationImpl


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 package org.netbeans.core.windows.view.ui.slides;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Rectangle JavaDoc;
24 import javax.swing.JComponent JavaDoc;
25 import javax.swing.JLayeredPane JavaDoc;
26 import javax.swing.event.ChangeEvent JavaDoc;
27 import javax.swing.event.ChangeListener JavaDoc;
28 import org.netbeans.core.windows.Constants;
29 import org.netbeans.swing.tabcontrol.SlideBarDataModel;
30
31
32 /**
33  * Basic implementation of known types of SlideOperation.
34  *
35  * Isn't intended to be used directly, but through SlideOperationFactory.
36  *
37  * @author Dafe Simonek
38  */

39 class SlideOperationImpl implements SlideOperation, ChangeListener JavaDoc {
40
41     /** Type of slide operation */
42     private final int type;
43     /** Overall component that will be sliden, in winsys top component
44      * surrounded by titlebar and border envelope */

45     private final Component JavaDoc component;
46     /** Slide effect */
47     private final SlidingFx effect;
48     /** true when component should be activated after slide */
49     private final boolean requestsActivation;
50     /** Desktop side where slide operation happens */
51     private final String JavaDoc side;
52     /** Bounds from where should effect start */
53     protected Rectangle JavaDoc startBounds;
54     /** Bounds into which should effect finish */
55     protected Rectangle JavaDoc finishBounds;
56     /** Pane on which operation should take effect */
57     private JLayeredPane JavaDoc pane;
58     /** layer of layered pane to draw into */
59     private Integer JavaDoc layer;
60     
61     /** Creates a new instance of SlideInOperation */
62     SlideOperationImpl(int type, Component JavaDoc component, int orientation,
63          SlidingFx effect, boolean requestsActivation) {
64         this(type, component, orientation2Side(orientation), effect, requestsActivation);
65     }
66     
67     SlideOperationImpl(int type, Component JavaDoc component, String JavaDoc side,
68          SlidingFx effect, boolean requestsActivation) {
69         this.type = type;
70         this.component = component;
71         this.effect = effect;
72         this.requestsActivation = requestsActivation;
73         this.side = side;
74     }
75
76     public void run(JLayeredPane JavaDoc pane, Integer JavaDoc layer) {
77         if (effect != null && effect.shouldOperationWait()) {
78             // OK, effect is asynchronous and we should wait for effect finish,
79
// so register and wait for stateChanged notification
80
this.pane = pane;
81             this.layer = layer;
82             effect.setFinishListener(this);
83             effect.showEffect(pane, layer, this);
84         } else {
85             if (effect != null) {
86                 effect.showEffect(pane, layer, this);
87             }
88             performOperation(pane, layer);
89         }
90     }
91
92     /** Notification of effect finish is delivered here. Invokes operation */
93     public void stateChanged(ChangeEvent JavaDoc e) {
94         performOperation(pane, layer);
95         pane = null;
96         layer = null;
97     }
98     
99     private void performOperation(JLayeredPane JavaDoc pane, Integer JavaDoc layer) {
100         // XXX - TBD
101
switch (type) {
102             case SLIDE_IN:
103                 component.setBounds(finishBounds);
104                 pane.add(component, layer);
105                 break;
106             case SLIDE_OUT:
107                 pane.remove(component);
108                 break;
109             case SLIDE_RESIZE:
110                 component.setBounds(finishBounds);
111                 ((JComponent JavaDoc)component).revalidate();
112                 break;
113         }
114     }
115
116     public void setFinishBounds(Rectangle JavaDoc bounds) {
117         this.finishBounds = bounds;
118     }
119
120     public void setStartBounds(Rectangle JavaDoc bounds) {
121         this.startBounds = bounds;
122     }
123
124     public String JavaDoc getSide() {
125         return side;
126     }
127
128     public Component JavaDoc getComponent() {
129         return component;
130     }
131
132     public Rectangle JavaDoc getFinishBounds() {
133         return finishBounds;
134     }
135
136     public Rectangle JavaDoc getStartBounds() {
137         return startBounds;
138     }
139
140     public boolean requestsActivation() {
141         return requestsActivation;
142     }
143
144     protected static String JavaDoc orientation2Side (int orientation) {
145         String JavaDoc side = Constants.LEFT;
146         if (orientation == SlideBarDataModel.WEST) {
147             side = Constants.LEFT;
148         } else if (orientation == SlideBarDataModel.EAST) {
149             side = Constants.RIGHT;
150         } else if (orientation == SlideBarDataModel.SOUTH) {
151             side = Constants.BOTTOM;
152         }
153         return side;
154     }
155
156     public int getType () {
157         return type;
158     }
159
160     public void prepareEffect() {
161         if (effect != null) {
162             effect.prepareEffect(this);
163         }
164     }
165
166     static int side2Orientation(String JavaDoc side) {
167         int orientation = SlideBarDataModel.WEST;
168         if (Constants.LEFT.equals(side)) {
169             orientation = SlideBarDataModel.WEST;
170         } else if (Constants.RIGHT.equals(side)) {
171             orientation = SlideBarDataModel.EAST;
172         } else if (Constants.BOTTOM.equals(side)) {
173             orientation = SlideBarDataModel.SOUTH;
174         }
175         return orientation;
176     }
177 }
178
Popular Tags