KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > dialogs > ControlAnimator


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  ******************************************************************************/

11
12 package org.eclipse.jface.dialogs;
13
14 import org.eclipse.swt.graphics.Point;
15 import org.eclipse.swt.graphics.Rectangle;
16 import org.eclipse.swt.widgets.Control;
17
18 /**
19  * ControlAnimator provides a simple implementation to display or hide a control
20  * at the bottom of the parent composite. Other animations will be written as
21  * subclasses of this class. <p>
22  * Instances of this class can be created using an AnimatorFactory.
23  *
24  * @since 3.2
25  */

26
27
28 public class ControlAnimator {
29     /** the control that will be displayed or hidden */
30     protected Control control;
31     
32     /**
33      * Constructs a new ControlAnimator instance and passes along the
34      * control that will be displayed or hidden.
35      *
36      * @param control the control that will be displayed or hidden.
37      */

38     public ControlAnimator(Control control) {
39         this.control = control;
40     }
41
42     /**
43      * Displays or hides a control at the bottom of the parent composite
44      * and makes use of the control's SWT visible flag.<p>
45      * Subclasses should override this method.</p>
46      *
47      * @param visible <code>true</code> if the control should be shown,
48      * and <code>false</code> otherwise.
49      */

50     public void setVisible(boolean visible){
51         // Using the SWT visible flag to determine if the control has
52
// already been displayed or hidden. Return if already displayed
53
// and visible is true, or if already hidden and visible is false.
54
if (!(control.isVisible() ^ visible))
55             return;
56         control.setVisible(visible);
57         Rectangle parentBounds = control.getParent().getBounds();
58         int bottom = parentBounds.height;
59         final int endY = visible ? bottom - control.getBounds().height
60                 : bottom;
61         Point loc = control.getLocation();
62         control.setLocation(loc.x,endY);
63     }
64     
65 }
66
Popular Tags