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

The following examples show how to use org.eclipse.swt.widgets.Control#getSize() . 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
Source Project: logbook   File: ImageWriter.java    License: MIT License 6 votes vote down vote up
/**
 * 指定されたcontrolを画像イメージとして書き込みます。
 *
 * @param control
 *            画像イメージとして書き込むControl
 * @throws IOException
 */
public void write(Control control) throws IOException {
    Point size = control.getSize();
    GC gc = new GC(control);
    try {
        Image image = new Image(Display.getDefault(), size.x, size.y);
        try {
            gc.copyArea(image, 0, 0);
            this.write(image);
        } finally {
            image.dispose();
        }
    } finally {
        gc.dispose();
    }
}
 
Example 2
public ErDiagramInformationControl(ERDiagram diagram, Shell shell, Control composite) {
	super(shell, true);
	this.diagram = diagram;

	create();

	int width  = 300;
	int height = 300;

	Point loc  = composite.toDisplay(0, 0);
	Point size = composite.getSize();

	int x = (size.x - width)  / 2 + loc.x;
	int y = (size.y - height) / 2 + loc.y;

	setSize(width, height);
	setLocation(new Point(x, y));
	addFocusListener(new FocusAdapter() {
		@Override
		public void focusLost(FocusEvent e) {
			dispose();
		}
	});
}
 
Example 3
/**
 * Actually resize ourself.
 */
private void resize() {
	Point headerSize = new Point(0, 0);
	Control header = parentTable.getHeaderControl();
	if (header != null) {
		headerSize = header.getSize();
	}
	Point parentSize = getParent().getSize();
	
	setBounds(0, headerSize.y+2, parentSize.x-4, parentSize.y - headerSize.y-6);
}
 
Example 4
Source Project: nebula   File: CTreeCell.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void locate(Control control) {
		Rectangle area = getClientArea();
		Point loc = new Point(area.x, item.getTop());
		Point size = control.getSize();
		if(hAlign == SWT.RIGHT) loc.x += (area.width-size.x);
		else if(hAlign == SWT.CENTER) loc.x += ((area.width-size.x)/2);
//		if(vAlign == SWT.BOTTOM) loc.y += (area.height-size.y);
//		else if(vAlign == SWT.CENTER) loc.y += ((area.height-size.y)/2);
		control.setLocation(loc);
	}
 
Example 5
@Override
protected Point getDefaultLocation(Point initialSize) {
	Control textWidget = xtextEditor.getAdapter(Control.class);
	Point size = textWidget.getSize();

	Point popupLocation = new Point((size.x / 2) - (initialSize.x / 2), (size.y / 2) - (initialSize.y / 2));
	return textWidget.toDisplay(popupLocation);
}
 
Example 6
@Override
protected void adjustBounds() {
    
    if (!getPersistSize()) {
        Point prefSize;
        int gap5W = SwtUtils.getTextWidth(filteredTree, "WWWWW"); //$NON-NLS-1$
        prefSize = filteredTree.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        prefSize.x += gap5W;
        prefSize.y += SWTFactory.getCharHeight(filteredTree)*3;
        
        Rectangle recDisplay = filteredTree.getDisplay().getPrimaryMonitor().getClientArea();
        prefSize.x = Math.max(prefSize.x, SwtUtils.getTextWidth(filteredTree, "WWWWWWWWWWWWWWWWWWWWWWWWWWW")); //$NON-NLS-1$
        prefSize.x = Math.min(prefSize.x, (int)((double)recDisplay.width / 1.5));
        prefSize.y = Math.min(prefSize.y, (int)((double)recDisplay.height / 1.2));

        // prefSize now is calculateg for all whole content. Clip it by decreased editor window size:
        Control edCtrl = (Control) editor.getAdapter(Control.class);
        Point edSize = edCtrl.getSize();
        prefSize.x = Math.min(prefSize.x, Math.max(edSize.x - gap5W*5, gap5W*5));
        prefSize.y = Math.min(prefSize.y, Math.max(edSize.y - gap5W*2, gap5W*5));

        getShell().setSize(prefSize);
        
        if (!this.getPersistLocation()) {
            int xx = (edSize.x - prefSize.x) / 2;
            int yy = (edSize.y - prefSize.y) / 2;
            Point edPos = edCtrl.toDisplay(new Point(0,0));
            getShell().setLocation(edPos.x + xx, edPos.y + yy);
        }
    }
    
}
 
Example 7
protected void saveChildControlSizes() {
    // Save control sizes
    Control [] children = getChildren();
    int iChildToSave = 0;
    for (int i = 0; i < children.length && iChildToSave < 2; i++){
        Control child = children[i];
        if (! (child instanceof Sash)){
            currentSashInfo.savedSizes[iChildToSave] = child.getSize();
            iChildToSave++;
        }
    }
}
 
Example 8
Source Project: uima-uimaj   File: HeaderPage.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Setup 1 column layout.
 *
 * @param managedForm the managed form
 * @return the composite
 */
public Composite setup1ColumnLayout(IManagedForm managedForm) {
  final ScrolledForm sform = managedForm.getForm();
  final Composite form = sform.getBody();
  form.setLayout(new GridLayout(1, false)); // this is required !
  Composite xtra = toolkit.createComposite(form);
  xtra.setLayout(new GridLayout(1, false));
  xtra.setLayoutData(new GridData(GridData.FILL_BOTH));

  Control c = form.getParent();
  while (!(c instanceof ScrolledComposite))
    c = c.getParent();
  ((GridData) xtra.getLayoutData()).widthHint = c.getSize().x;
  return xtra;
}
 
Example 9
Source Project: uima-uimaj   File: HeaderPage.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Setup 2 column layout.
 *
 * @param managedForm the managed form
 * @param w1 the w 1
 * @param w2 the w 2
 * @return the form 2 panel
 */
public Form2Panel setup2ColumnLayout(IManagedForm managedForm, int w1, int w2) {
  final ScrolledForm sform = managedForm.getForm();
  final Composite form = sform.getBody();
  form.setLayout(new GridLayout(1, false)); // this is required !
  Composite xtra = toolkit.createComposite(form);
  xtra.setLayout(new GridLayout(1, false));
  xtra.setLayoutData(new GridData(GridData.FILL_BOTH));
  Control c = xtra.getParent();
  while (!(c instanceof ScrolledComposite))
    c = c.getParent();
  ((GridData) xtra.getLayoutData()).widthHint = c.getSize().x;
  ((GridData) xtra.getLayoutData()).heightHint = c.getSize().y;
  sashForm = new SashForm(xtra, SWT.HORIZONTAL);

  sashForm.setLayoutData(new GridData(GridData.FILL_BOTH)); // needed

  leftPanel = newComposite(sashForm);
  ((GridLayout) leftPanel.getLayout()).marginHeight = 5;
  ((GridLayout) leftPanel.getLayout()).marginWidth = 5;
  rightPanel = newComposite(sashForm);
  ((GridLayout) rightPanel.getLayout()).marginHeight = 5;
  ((GridLayout) rightPanel.getLayout()).marginWidth = 5;
  sashForm.setWeights(new int[] { w1, w2 });
  leftPanelPercent = (float) w1 / (float) (w1 + w2);
  rightPanelPercent = (float) w2 / (float) (w1 + w2);

  rightPanel.addControlListener(new ControlAdapter() {
    @Override
    public void controlResized(ControlEvent e) {
      setSashFormWidths();
    }
  });

  return new Form2Panel(form, leftPanel, rightPanel);
}
 
Example 10
private void drawGridLines(PaintEvent e, boolean isHeader) {
	Color oldColor = e.gc.getForeground();
	try {
		// Get the colors we need
		Display display = Display.getCurrent();
		Color lineColor = display
				.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
		Color secondaryColor = display
				.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
		Color hilightColor = display
				.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
		if (!isHeader) {
			lineColor = display
					.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW);
		}

		// Get the control
		Control toPaint = (Control) e.widget;
		Point controlSize = toPaint.getSize();

		// Draw the bottom line(s)
		e.gc.setForeground(lineColor);
		e.gc.drawLine(0, controlSize.y - 1, controlSize.x,
				controlSize.y - 1);
		if (isHeader) {
			e.gc.setForeground(secondaryColor);
			e.gc.drawLine(0, controlSize.y - 2, controlSize.x,
					controlSize.y - 2);
			e.gc.setForeground(hilightColor);
			e.gc.drawLine(0, 1, controlSize.x, 1);
		}

		// Now draw lines around the child controls, if there are any
		if (toPaint instanceof Composite) {
			Composite row = (Composite) toPaint;
			Control[] children = row.getChildren();
			for (int i = 0; i < children.length; i++) {
				Rectangle childBounds = children[i].getBounds();

				// Paint the beginning lines
				if (isHeader) {
					e.gc.setForeground(hilightColor);
					e.gc.drawLine(childBounds.x - 2, 1, childBounds.x - 2,
							controlSize.y - 2);
				}

				// Paint the ending lines
				e.gc.setForeground(lineColor);
				int lineLeft = childBounds.x + childBounds.width + 1;
				e.gc.drawLine(lineLeft, 0, lineLeft, controlSize.y);
				if (isHeader) {
					e.gc.setForeground(secondaryColor);
					e.gc.drawLine(lineLeft - 1, 0, lineLeft - 1,
							controlSize.y - 1);
				}
			}
		}
	} finally {
		e.gc.setForeground(oldColor);
	}
}
 
Example 11
Source Project: SWET   File: SWTUtil.java    License: MIT License 4 votes vote down vote up
public static void packWidth(Control control) {
	Point prefSize = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
	Point currSize = control.getSize();
	control.setSize(prefSize.x, currSize.y);
}
 
Example 12
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 13
public void setViewLayout(int layout) {
	if (fCurrentLayout != layout || layout == VIEW_LAYOUT_AUTOMATIC) {
		fInComputeLayout= true;
		try {
			boolean methodViewerNeedsUpdate= false;

			if (fMethodViewerViewForm != null && !fMethodViewerViewForm.isDisposed()
					&& fTypeMethodsSplitter != null && !fTypeMethodsSplitter.isDisposed()) {

				boolean horizontal= false;
				if (layout == VIEW_LAYOUT_SINGLE) {
					fMethodViewerViewForm.setVisible(false);
					showMembersInHierarchy(false);
					updateMethodViewer(null);
				} else {
					if (fCurrentLayout == VIEW_LAYOUT_SINGLE) {
						fMethodViewerViewForm.setVisible(true);
						methodViewerNeedsUpdate= true;
					}
					if (layout == VIEW_LAYOUT_AUTOMATIC) {
						if (fParent != null && !fParent.isDisposed()) {
							Point size= fParent.getSize();
							if (size.x != 0 && size.y != 0) {
								// bug 185397 - Hierarchy View flips orientation multiple times on resize
								Control viewFormToolbar= fTypeViewerViewForm.getTopLeft();
								if (viewFormToolbar != null && !viewFormToolbar.isDisposed() && viewFormToolbar.isVisible()) {
									size.y -= viewFormToolbar.getSize().y;
								}
								horizontal= size.x > size.y;
							} else if (size.x == 0 && size.y == 0) {
								return;
							}
						}
						if (fCurrentLayout == VIEW_LAYOUT_AUTOMATIC) {
							boolean wasHorizontal= fTypeMethodsSplitter.getOrientation() == SWT.HORIZONTAL;
							if (wasHorizontal == horizontal) {
								return; // no real change
							}
						}

					} else if (layout == VIEW_LAYOUT_HORIZONTAL) {
						horizontal= true;
					}
					fTypeMethodsSplitter.setOrientation(horizontal ? SWT.HORIZONTAL : SWT.VERTICAL);
				}
				updateMainToolbar(horizontal);
				fTypeMethodsSplitter.layout();
			}
			if (methodViewerNeedsUpdate) {
				updateMethodViewer(fSelectedType);
			}
			fDialogSettings.put(DIALOGSTORE_VIEWLAYOUT, layout);
			fCurrentLayout= layout;

			updateCheckedState();
		} finally {
			fInComputeLayout= false;
		}
	}
}
 
Example 14
Source Project: nebula   File: ResizeEffect.java    License: Eclipse Public License 2.0 3 votes vote down vote up
/**
 * @deprecated
 * @param w
 * @param x
 * @param y
 * @param duration
 * @param movement
 * @param onStop
 * @param onCancel
 */
public static void resize(AnimationRunner runner, Control w, int x, int y,
		int duration, IMovement movement, Runnable onStop, Runnable onCancel) {
	Point oldSize = w.getSize();
	IEffect effect = new ResizeEffect(w, oldSize, new Point(x, y),
			duration, movement, onStop, onCancel);
	runner.runEffect(effect);
}
 
Example 15
Source Project: nebula   File: Resize.java    License: Eclipse Public License 2.0 3 votes vote down vote up
/**
 * @deprecated
 * @param w
 * @param x
 * @param y
 * @param duration
 * @param movement
 * @param onStop
 * @param onCancel
 */
public static void resize(AnimationRunner runner, Control w, int x, int y,
		int duration, IMovement movement, Runnable onStop, Runnable onCancel) {
	Point oldSize = w.getSize();
	IEffect effect = new Resize(w, oldSize, new Point(x, y),
			duration, movement, onStop, onCancel);
	runner.runEffect(effect);
}