KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > layout > LayoutUtil


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.ui.internal.layout;
13
14 import org.eclipse.swt.graphics.Rectangle;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Control;
17 import org.eclipse.swt.widgets.Layout;
18 import org.eclipse.swt.widgets.Shell;
19
20 /**
21  * Contains various methods for manipulating layouts
22  *
23  * @since 3.0
24  */

25 public class LayoutUtil {
26
27     /**
28      * Should be called whenever a control's contents have changed. Will
29      * trigger a layout parent controls if necessary.
30      *
31      * @param changedControl
32      */

33     public static void resize(Control changedControl) {
34         Composite parent = changedControl.getParent();
35
36         Layout parentLayout = parent.getLayout();
37
38         if (parentLayout instanceof ICachingLayout) {
39             ((ICachingLayout) parentLayout).flush(changedControl);
40         }
41
42         if (parent instanceof Shell) {
43             parent.layout(true);
44         } else {
45             Rectangle currentBounds = parent.getBounds();
46
47             resize(parent);
48
49             // If the parent was resized, then it has already triggered a
50
// layout. Otherwise, we need to manually force it to layout again.
51
if (currentBounds.equals(parent.getBounds())) {
52                 parent.layout(true);
53             }
54         }
55     }
56 }
57
Popular Tags