Java Code Examples for org.eclipse.swt.widgets.Control#computeSize()

The following examples show how to use org.eclipse.swt.widgets.Control#computeSize() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
protected void layout(final Composite composite, final boolean flushCache) {
    if (flushCache || !_calculated) {
        recalculate(composite);
    }

    final Control[] children = composite.getChildren();

    final Rectangle bounds = composite.getClientArea();

    int y = _ganttHeaderSize;
    for (int i = 0; i < children.length; i++) {
        final Control child = children[i];
        final Point wantedSize = child.computeSize(SWT.DEFAULT, SWT.DEFAULT);

        child.setLocation(0, y);
        child.setSize(bounds.width, bounds.height - y);
        y += wantedSize.y;
    }

}
 
Example 2
/**
 * Creates page for hover preferences.
 *
 * @param parent the parent composite
 * @return the control for the preference page
 */
public Control createControl(Composite parent) {
	initializeDialogUnits(parent);

	ScrolledPageContent scrolled= new ScrolledPageContent(parent, SWT.H_SCROLL | SWT.V_SCROLL);
	scrolled.setExpandHorizontal(true);
	scrolled.setExpandVertical(true);

	Control control= createSyntaxPage(scrolled);

	scrolled.setContent(control);
	final Point size= control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
	scrolled.setMinSize(size.x, size.y);

	return scrolled;
}
 
Example 3
/**
 * Computes the ideal render widths of non-{@link ChatLine}s and returns the maximum.
 *
 * @return the maximum ideal render width of all non-{@link ChatLine}s
 */
private int computeMaxNonChatLineWidth() {
  int maxNonChatLineWidth = 0;
  for (Control chatItem : contentComposite.getChildren()) {
    if (!(chatItem instanceof ChatLine)) {
      int currentNonChatLineWidth = chatItem.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
      maxNonChatLineWidth = Math.max(currentNonChatLineWidth, maxNonChatLineWidth);
    }
  }
  return maxNonChatLineWidth;
}
 
Example 4
/**
 * @param pageContainer
 * @param left
 * @param right
 */
private void setWidthHints( SashForm pageContainer, Control left,
		Control right )
{
	int leftWidth = left.computeSize( SWT.DEFAULT, SWT.DEFAULT ).x;
	int rightWidth = right.computeSize( SWT.DEFAULT, SWT.DEFAULT ).x;

	pageContainer.setWeights( new int[]{
			leftWidth, rightWidth
	} );

}
 
Example 5
private void recalculate(final Composite composite) {
    final Control[] children = composite.getChildren();

    if (children == null || children.length == 0) {
        return;
    }

    if (_ganttChart == null) {
        return;
    }

    int widgetHeaderHeight = 0;
    int borderHeight = 0;
    for (int i = 0; i < children.length; i++) {
        final Control child = children[i];
        final Point wantedSize = child.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        _maxY += wantedSize.y;
        _maxX = Math.max(_maxX, wantedSize.x);
        if (child instanceof Tree) {
            widgetHeaderHeight = ((Tree) child).getHeaderHeight();
            borderHeight = ((Tree) child).getBorderWidth();
        } else if (child instanceof Table) {
            widgetHeaderHeight = ((Table) child).getHeaderHeight();
            borderHeight = ((Table) child).getBorderWidth();
        }
    }

    final ISettings settings = _ganttChart.getSettings();
    if (settings.drawHeader()) {
        _ganttHeaderSize = settings.getHeaderDayHeight() + settings.getHeaderMonthHeight() + settings.getEventsTopSpacer() - widgetHeaderHeight - borderHeight;
    } else {
        _ganttHeaderSize = 0;
    }

    _calculated = true;
}
 
Example 6
/**
 * Calculates the difference in size between the given page and the page
 * container. A larger page results in a positive delta.
 * 
 * @param page
 *            the page
 * @return the size difference encoded as a
 *         <code>new Point(deltaWidth,deltaHeight)</code>
 */
private Point calculatePageSizeDelta(IWizardPage page) {
	Control pageControl = page.getControl();
	if (pageControl == null) {
		// control not created yet
		return new Point(0, 0);
	}
	Point contentSize = pageControl.computeSize(SWT.DEFAULT, SWT.DEFAULT,
			true);
	Rectangle rect = pageContainerLayout.getClientArea(pageContainer);
	Point containerSize = new Point(rect.width, rect.height);
	return new Point(Math.max(0, contentSize.x - containerSize.x), Math
			.max(0, contentSize.y - containerSize.y));
}
 
Example 7
/**
 * Calculates the difference in size between the given page and the page
 * container. A larger page results in a positive delta.
 * 
 * @param page
 *            the page
 * @return the size difference encoded as a
 *         <code>new Point(deltaWidth,deltaHeight)</code>
 */
private Point calculatePageSizeDelta(IWizardPage page) {
	Control pageControl = page.getControl();
	if (pageControl == null) {
		// control not created yet
		return new Point(0, 0);
	}
	Point contentSize = pageControl.computeSize(SWT.DEFAULT, SWT.DEFAULT,
			true);
	Rectangle rect = pageContainerLayout.getClientArea(pageContainer);
	Point containerSize = new Point(rect.width, rect.height);
	return new Point(Math.max(0, contentSize.x - containerSize.x), Math
			.max(0, contentSize.y - containerSize.y));
}
 
Example 8
/**
 * {@inheritDoc}
 */
@Override
public Point computeSize(final Composite composite, final int wHint, final int hHint, final boolean force) {
	if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {
		return new Point(wHint, hHint);
	}

	int x = fMinimalWidth;
	int y = fMinimalHight;
	final Control[] children = composite.getChildren();
	for (final Control child : children) {
		final Point size = child.computeSize(SWT.DEFAULT, SWT.DEFAULT, force);
		x = Math.max(x, size.x);
		y = Math.max(y, size.y);
	}

	final Rectangle area = fContainer.getClientArea();
	if (area.width > x) {
		fContainer.setExpandHorizontal(true);
	} else {
		fContainer.setExpandHorizontal(false);
	}

	if (area.height > y) {
		fContainer.setExpandVertical(true);
	} else {
		fContainer.setExpandVertical(false);
	}

	if (wHint != SWT.DEFAULT) {
		x = wHint;
	}
	if (hHint != SWT.DEFAULT) {
		y = hHint;
	}

	return new Point(x, y);
}
 
Example 9
protected Control createContents(Composite ancestor) {
	ScrolledPageContent scrolled= new ScrolledPageContent(ancestor, SWT.H_SCROLL | SWT.V_SCROLL);
	scrolled.setExpandHorizontal(true);
	scrolled.setExpandVertical(true);
	
	Control control= super.createContents(scrolled);

	scrolled.setContent(control); 
	final Point size= control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
	scrolled.setMinSize(size.x, size.y);
	
	return scrolled;
}
 
Example 10
@Override
protected Control createContents(Composite parent) {
    Control control = super.createContents(parent);

    /* set the shell minimum size */
    Point clientArea = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle trim = getShell().computeTrim(0, 0, clientArea.x, clientArea.y);
    getShell().setMinimumSize(trim.width, trim.height);

    return control;
}
 
Example 11
Source Project: AndroidRobot   File: LogAnalysis.java    License: Apache License 2.0 5 votes vote down vote up
private void createStatusBar() {
    coolBar1 = new CoolBar(shell, SWT.NONE);
    FormData formData1 = new FormData();
    formData1.left = new FormAttachment(0, 0);
    formData1.right = new FormAttachment(100, 0);
    formData1.top = new FormAttachment(100, -24);
    formData1.bottom = new FormAttachment(100, 0);
    coolBar1.setLayoutData(formData1);
    CoolItem coolItem1 = new CoolItem(coolBar1, SWT.NONE);
    toolBar1 = new ToolBar(coolBar1, SWT.NONE);

    ToolItem tiStatusBarTotal = new ToolItem(toolBar1, SWT.NONE);
    ToolItem tiStatusBarPass = new ToolItem(toolBar1, SWT.NONE);
    ToolItem tiStatusBarFail = new ToolItem(toolBar1, SWT.NONE);
    ToolItem tiStatusBarRate = new ToolItem(toolBar1, SWT.NONE);

    tiStatusBarPass.setText("通过:0");
    tiStatusBarFail.setText("失败:0");
    tiStatusBarRate.setText("通过率:0%");
    tiStatusBarTotal.setText("总用例数:0");

    coolItem1.setControl(toolBar1);

    Control control = coolItem1.getControl();
    Point pt = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    pt = coolItem1.computeSize(pt.x, pt.y);
    coolItem1.setSize(pt);

    coolBar1.pack();
}
 
Example 12
private void updateSize(Control control) {
  if (control == null) {
    return;
  }
  Point size = control.computeSize(getClientArea().width - 20, SWT.DEFAULT,
      true);
  control.setSize(size);
  setMinSize(size);
}
 
Example 13
private void updatedScrolMinSize(final Control control, final ScrolledComposite sc) {
    final Point point = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    sc.setMinSize(new Point(point.x, point.y));
}
 
Example 14
private int computeMaxWidth( Control button, int size )
{
	int widthHint = button.computeSize( -1, -1 ).x
			- button.getBorderWidth( );
	return widthHint > size ? widthHint : size;
}
 
Example 15
Source Project: SWET   File: SWTUtil.java    License: MIT License 4 votes vote down vote up
public static void packHeight(Control control) {
	Point prefSize = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
	Point currSize = control.getSize();
	control.setSize(currSize.x, prefSize.y);
}
 
Example 16
private int getMaxWidth( Control control, int size )
{
	int width = control.computeSize( -1, -1 ).x;
	return width > size ? width : size;
}
 
Example 17
public static final void updateOnlyVerticalScrollableComposite(ScrolledComposite scrolledComposite) {
	Control content = scrolledComposite.getContent();
	
	if (content == null)
		return;
	
	if( content instanceof Composite ) {
		((Composite)content).layout();
	}
	
	Rectangle clientArea = scrolledComposite.getClientArea();
	
	Point computeSize = content.computeSize(clientArea.width, SWT.DEFAULT, true);
	
	scrolledComposite.setMinSize(computeSize);
	scrolledComposite.layout();
	
	content.requestLayout();
}
 
Example 18
Source Project: ermasterr   File: ComboContributionItem.java    License: Apache License 2.0 4 votes vote down vote up
private int computeWidth(final Control control) {
    return control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x;
}
 
Example 19
private void resizeSelectedPart()
{
    IPresentablePart part = getSite().getSelectedPart();
    
    if (part == null) return;
    
    Control partTB = part.getToolBar();
    
    Rectangle bounds = eBarItem.getControl().getBounds();        
    
    Point partTBSize = new Point(0,0);
    if (partTB != null)
    {
        partTBSize = partTB.computeSize(bounds.width,SWT.DEFAULT);
   
        Rectangle tbBounds = new Rectangle(0,0,bounds.width,partTBSize.y);
        
        tbBounds = eBar.getDisplay().map(eBarItem.getControl(), partTB.getParent(), tbBounds);
        
        partTB.setBounds(tbBounds);
        
        bounds.y += tbBounds.height;
        bounds.height -= tbBounds.height;        
    }
    
    bounds = eBar.getDisplay().map(eBar, partParent, bounds);

    part.setBounds(bounds);
}
 
Example 20
/** 
 * {@inheritDoc}
 */
@Override
public void setBounds(Rectangle bounds)
{
    borderComposite.setBounds(bounds);
    
    Rectangle clientArea = borderComposite.getClientArea();
    
    IPresentablePart part = getSite().getSelectedPart();
    
    if (part == null) return;
    
    Control partTB = part.getToolBar();
    
    Rectangle tbBounds = new Rectangle(0,0,0,0);
    
    if (partTB != null)
    {
        Point size = partTB.computeSize(clientArea.width, SWT.DEFAULT);
        
        tbBounds.width = size.x;
        tbBounds.height = Math.min(size.y, clientArea.height);

        tbBounds = borderComposite.getDisplay().map(borderComposite, partTB.getParent(), tbBounds);
        
        partTB.setBounds(tbBounds);
        
        clientArea.y += tbBounds.height;
        clientArea.height -= tbBounds.height;  
    }
    
    clientArea = borderComposite.getDisplay().map(borderComposite, partParent, clientArea);

    part.setBounds(clientArea);
}