45 lines
1.4 KiB
Java
45 lines
1.4 KiB
Java
/*
|
|
* Copyright (c) 2009 Declarative Engineering LLC.
|
|
* All rights reserved. This program and the accompanying materials
|
|
* are made available under the terms of the Declarative Engineering LLC
|
|
* verson 1 which accompanies this distribution, and is available at
|
|
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
|
*/
|
|
package com.foundation.view.swt.layout;
|
|
|
|
import org.eclipse.swt.graphics.Point;
|
|
import org.eclipse.swt.graphics.Rectangle;
|
|
import org.eclipse.swt.widgets.Composite;
|
|
import org.eclipse.swt.widgets.Control;
|
|
|
|
/**
|
|
* The layout base class.
|
|
*/
|
|
public abstract class Layout extends org.eclipse.swt.widgets.Layout {
|
|
/**
|
|
* Layout constructor.
|
|
*/
|
|
public Layout() {
|
|
}//Layout()//
|
|
/**
|
|
* Computes the current size of the composite using this layout.
|
|
* @param composite The composite that uses this layout.
|
|
* @return The current size of the composite.
|
|
*/
|
|
public Point computeCurrentSize(Composite composite) {
|
|
Point result = new Point(0, 0);
|
|
Control[] children = composite.getChildren();
|
|
|
|
//Note: This works well, but doesn't account for bottom and right margins. Subclasses can overload this to add the margins.//
|
|
for(int i = 0; i < children.length; i++) {
|
|
Rectangle rect = children[i].getBounds();
|
|
|
|
if(children[i].isVisible()) {
|
|
result.x = Math.max(result.x, rect.x + rect.width);
|
|
result.y = Math.max(result.y, rect.y + rect.height);
|
|
}//if//
|
|
}//for//
|
|
|
|
return result;
|
|
}//computeCurrentSize()//
|
|
}//Layout// |