KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > custom > CLayoutData


1 /*******************************************************************************
2  * Copyright (c) 2005 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 package org.eclipse.swt.custom;
12
13 import org.eclipse.swt.*;
14 import org.eclipse.swt.graphics.*;
15 import org.eclipse.swt.widgets.*;
16
17 class CLayoutData {
18
19     int defaultWidth = -1, defaultHeight = -1;
20     int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1;
21     
22 Point computeSize (Control control, int wHint, int hHint, boolean flushCache) {
23     if (flushCache) flushCache();
24     if (wHint == SWT.DEFAULT && hHint == SWT.DEFAULT) {
25         if (defaultWidth == -1 || defaultHeight == -1) {
26             Point size = control.computeSize (wHint, hHint, flushCache);
27             defaultWidth = size.x;
28             defaultHeight = size.y;
29         }
30         return new Point(defaultWidth, defaultHeight);
31     }
32     if (currentWidth == -1 || currentHeight == -1 || wHint != currentWhint || hHint != currentHhint) {
33         Point size = control.computeSize (wHint, hHint, flushCache);
34         currentWhint = wHint;
35         currentHhint = hHint;
36         currentWidth = size.x;
37         currentHeight = size.y;
38     }
39     return new Point(currentWidth, currentHeight);
40 }
41 void flushCache () {
42     defaultWidth = defaultHeight = -1;
43     currentWidth = currentHeight = -1;
44 }
45 }
46
Popular Tags