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

The following examples show how to use org.eclipse.swt.widgets.Control#getBounds() . 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 File: GuiResource.java    From hop with Apache License 2.0 6 votes vote down vote up
public static Point calculateControlPosition( Control control ) {
  // Calculate the exact location...
  //
  Rectangle r = control.getBounds();
  Point p = control.getParent().toDisplay( r.x, r.y );

  return p;

  /*
   * Point location = control.getLocation();
   *
   * Composite parent = control.getParent(); while (parent!=null) {
   *
   * Composite newParent = parent.getParent(); if (newParent!=null) { location.x+=parent.getLocation().x;
   * location.y+=parent.getLocation().y; } else { if (parent instanceof Shell) { // Top level shell. Shell shell =
   * (Shell)parent; Rectangle bounds = shell.getBounds(); Rectangle clientArea = shell.getClientArea(); location.x +=
   * bounds.width-clientArea.width; location.y += bounds.height-clientArea.height; } } parent = newParent; }
   *
   * return location;
   */
}
 
Example 2
Source File: SWTUtil.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
 */
@Override
public void mouseDown(MouseEvent e) {
  Control theControl = (Control) e.widget;

  Display display = theControl.getDisplay();
  Shell tip = new Shell(theControl.getShell(), SWT.ON_TOP | SWT.TOOL);
  tip.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
  FillLayout layout = new FillLayout();
  layout.marginHeight = 1;
  layout.marginWidth = 2;
  tip.setLayout(layout);
  Label label = new Label(tip, SWT.NONE);
  label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
  label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));

  label.setText(theControl.getToolTipText());
  label.addMouseTrackListener(this);
  Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
  Rectangle rect = theControl.getBounds();
  Point pt = theControl.getParent().toDisplay(rect.x, rect.y);
  tip.setBounds(pt.x, pt.y, size.x, size.y);
  tip.setVisible(true);
}
 
Example 3
Source File: CheckboxCellContentProvider.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates an <code>Image</code> from the specified <code>Control</code>
 * (widget).
 * 
 * @param control
 *            The <code>Control</code> to convert to an <code>Image</code>.
 * @return An <code>Image</code> of the specified <code>Control</code>.
 */
private static Image createImage(Control control) {

	// We have to create a separate Image per combination of
	// checked/unchecked (of course). We also have to create a single GC per
	// Image (not so obvious, but re-using them does not appear to work well
	// and does not sync with the UI thread properly, so you get the same
	// image multiple times [but not all the time]).

	Image image = new Image(control.getDisplay(), control.getBounds());
	GC gc = new GC(image);
	control.print(gc);
	gc.dispose();

	return image;
}
 
Example 4
Source File: GrowEffect.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @deprecated
 * @param w
 * @param duration
 * @param movement
 * @param onStop
 * @param onCancel
 */
public void grow(AnimationRunner runner, Control w, int duration,
		IMovement movement, Runnable onStop, Runnable onCancel) {
	IEffect effect = new GrowEffect(w, w.getBounds(), new Rectangle(w
			.getBounds().x + 10, w.getBounds().y + 10,
			w.getBounds().width + 10, w.getBounds().height + 10), duration,
			movement, onStop, onCancel);
	runner.runEffect(effect);
}
 
Example 5
Source File: Grow.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @deprecated
 * @param w
 * @param duration
 * @param movement
 * @param onStop
 * @param onCancel
 */
public void grow(AnimationRunner runner, Control w, int duration,
		IMovement movement, Runnable onStop, Runnable onCancel) {
	IEffect effect = new Grow(w, w.getBounds(), new Rectangle(w
			.getBounds().x + 10, w.getBounds().y + 10,
			w.getBounds().width + 10, w.getBounds().height + 10), duration,
			movement, onStop, onCancel);
	runner.runEffect(effect);
}
 
Example 6
Source File: AnimatedGIFRunner.java    From http4e with Apache License 2.0 5 votes vote down vote up
AnimatedGIFRunner(
      Control control, 
      ImageLoader imageLoaderGIF, 
      final Image backgroundImage){
   
   this.control = control;
   controlGC = new GC(control);
   shellBackground = control.getBackground();
   this.imageLoader = imageLoaderGIF;
   this.imageDataArray = imageLoader.data;
   if(imageDataArray == null || imageDataArray.length < 2){
      throw new RuntimeException("Illegal ImageLoader.");
   }
   isStopped = false;
   this.backgroundImage = backgroundImage;
   Rectangle ctrR = control.getBounds();
   positionX = (ctrR.width - CoreConstants.IMAGES_HEIGHT)/2;
   positionY = (ctrR.height - CoreConstants.IMAGES_HEIGHT)/2;

   control.addPaintListener(new PaintListener() {
      public void paintControl( PaintEvent e){
         GC graphics = e.gc;
         if(!graphics.isDisposed()) {
            graphics.drawImage(backgroundImage, positionX, positionY);
            graphics.dispose();
         }
      }
   });
}
 
Example 7
Source File: LiveSashForm.java    From http4e with Apache License 2.0 5 votes vote down vote up
private void drawBorderAround(Control c, GC gc)
{
  int sh = getChildBorder(c);
  if(sh == SWT.SHADOW_NONE) return;

  Display disp = getDisplay();
  Color shadow = disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
  Color highlight = disp.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
  if(shadow == null || highlight == null) return;
  Rectangle r = c.getBounds();

  switch(sh)
  {
    case SWT.SHADOW_IN:
      drawBevelRect(gc, r.x-1, r.y-1, r.width+1, r.height+1, shadow, highlight);
      break;

    case SWT.SHADOW_OUT:
      drawBevelRect(gc, r.x-1, r.y-1, r.width+1, r.height+1, highlight, shadow);
      break;

    case SWT.SHADOW_ETCHED_IN:
      drawBevelRect(gc, r.x-1, r.y-1, r.width+1, r.height+1, highlight, shadow);
      drawBevelRect(gc, r.x-2, r.y-2, r.width+3, r.height+3, shadow, highlight);
      break;

    case SWT.SHADOW_ETCHED_OUT:
      drawBevelRect(gc, r.x-1, r.y-1, r.width+1, r.height+1, shadow, highlight);
      drawBevelRect(gc, r.x-2, r.y-2, r.width+3, r.height+3, highlight, shadow);
      break;
  }
}
 
Example 8
Source File: IImageSave.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Save the image, This default implementation save the canvas as a PNG image.
 *
 * @param filename
 *            the file to write to
 * @param format
 *            the image format, specified in {@link SWT} constants
 *            ({@link SWT#IMAGE_PNG}, {@link SWT#IMAGE_GIF},
 *            {@link SWT#IMAGE_JPEG} or {@link SWT#IMAGE_BMP}).
 */
default void saveImage(String filename, int format) {
    Control control = getControl();
    Image image = new Image(Display.getDefault(), control.getBounds());
    GC gc = new GC(image);
    control.print(gc);
    gc.dispose();
    ImageData data = image.getImageData();
    ImageLoader loader = new ImageLoader();
    loader.data = new ImageData[] { data };
    loader.save(filename, format);
    image.dispose();
}
 
Example 9
Source File: GUIResource.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static Point calculateControlPosition( Control control ) {
  // Calculate the exact location...
  //
  Rectangle r = control.getBounds();
  return control.getParent().toDisplay( r.x, r.y );
}