Java源码示例:org.eclipse.jface.util.Geometry

示例1
/**
 * Given the desired position of the shell, this method returns an adjusted position such that the window is no
 * larger than its monitor, and does not extend beyond the edge of the monitor. This is used for computing the
 * initial window position via the parent shell, clients can use this as a utility method if they want to limit the
 * region in which the window may be moved.
 *
 * @param shell
 *            the shell which shell bounds is being calculated.
 * @param preferredSize
 *            the preferred position of the window.
 * @return a rectangle as close as possible to preferredSize that does not extend outside the monitor.
 */
public static Rectangle getConstrainedShellBounds(final Shell shell, final Point preferredSize) {

	final Point location = getInitialLocation(shell, preferredSize);
	final Rectangle result = new Rectangle(location.x, location.y, preferredSize.x, preferredSize.y);

	final Monitor monitor = getClosestMonitor(shell.getDisplay(), Geometry.centerPoint(result));

	final Rectangle bounds = monitor.getClientArea();

	if (result.height > bounds.height) {
		result.height = bounds.height;
	}

	if (result.width > bounds.width) {
		result.width = bounds.width;
	}

	result.x = Math.max(bounds.x, Math.min(result.x, bounds.x
			+ bounds.width - result.width));
	result.y = Math.max(bounds.y, Math.min(result.y, bounds.y
			+ bounds.height - result.height));

	return result;
}
 
示例2
/**
 * Returns the initial location to use for the shell. The default implementation centers the shell horizontally (1/2
 * of the difference to the left and 1/2 to the right) and vertically (1/3 above and 2/3 below) relative to the
 * active workbench windows shell, or display bounds if there is no parent shell.
 *
 * @param shell
 *            the shell which initial location has to be calculated.
 * @param initialSize
 *            the initial size of the shell, as returned by <code>getInitialSize</code>.
 * @return the initial location of the shell
 */
public static Point getInitialLocation(final Shell shell, final Point initialSize) {
	final Composite parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

	Monitor monitor = shell.getDisplay().getPrimaryMonitor();
	if (parent != null) {
		monitor = parent.getMonitor();
	}

	final Rectangle monitorBounds = monitor.getClientArea();
	Point centerPoint;
	if (parent != null) {
		centerPoint = Geometry.centerPoint(parent.getBounds());
	} else {
		centerPoint = Geometry.centerPoint(monitorBounds);
	}

	return new Point(centerPoint.x - (initialSize.x / 2), Math.max(
			monitorBounds.y, Math.min(centerPoint.y - (initialSize.y * 2 / 3),
					monitorBounds.y + monitorBounds.height - initialSize.y)));
}
 
示例3
/**
 * Returns the monitor whose client area contains the given point. If no monitor contains the point, returns the
 * monitor that is closest to the point.
 *
 * @param toSearch
 *            point to find (display coordinates).
 * @param toFind
 *            point to find (display coordinates).
 * @return the monitor closest to the given point.
 */
private static Monitor getClosestMonitor(final Display toSearch, final Point toFind) {
	int closest = Integer.MAX_VALUE;

	final Monitor[] monitors = toSearch.getMonitors();
	Monitor result = monitors[0];

	for (int index = 0; index < monitors.length; index++) {
		final Monitor current = monitors[index];

		final Rectangle clientArea = current.getClientArea();

		if (clientArea.contains(toFind)) {
			return current;
		}

		final int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind);
		if (distance < closest) {
			closest = distance;
			result = current;
		}
	}

	return result;
}
 
示例4
protected Point computePopupLocation() {
	if (popup == null || popup.isDisposed())
		return null;

	LinkedPosition position = renameLinkedMode.getCurrentLinkedPosition();
	if (position == null)
		return null;
	ISourceViewer viewer = editor.getInternalSourceViewer();
	ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer;
	int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset);

	StyledText textWidget = viewer.getTextWidget();
	Point pos = textWidget.getLocationAtOffset(widgetOffset);
	Point pSize = getExtent();
	pSize.y += HAH + 1;
	pos.x -= HAO;
	pos.y += textWidget.getLineHeight(widgetOffset);
	Point dPos = textWidget.toDisplay(pos);
	Rectangle displayBounds = textWidget.getDisplay().getClientArea();
	Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize);
	Geometry.moveInside(dPopupRect, displayBounds);
	return new Point(dPopupRect.x, dPopupRect.y);
}
 
示例5
/**
 * Returns the monitor whose client area contains the given point. If no
 * monitor contains the point, returns the monitor that is closest to the
 * point.
 * <p>
 * Copied from
 * <code>org.eclipse.jface.window.Window.getClosestMonitor(Display, Point)</code>
 * </p>
 * 
 * @param display the display showing the monitors
 * @param point point to find (display coordinates)
 * @return the monitor closest to the given point
 */
private static Monitor getClosestMonitor(Display display, Point point) {
  int closest = Integer.MAX_VALUE;

  Monitor[] monitors = display.getMonitors();
  Monitor result = monitors[0];

  for (int i = 0; i < monitors.length; i++) {
    Monitor current = monitors[i];

    Rectangle clientArea = current.getClientArea();

    if (clientArea.contains(point))
      return current;

    int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea),
        point);
    if (distance < closest) {
      closest = distance;
      result = current;
    }
  }

  return result;
}
 
示例6
/**
 * This method was copy/pasted from JFace.
 */
private static Monitor getClosestMonitor(final Display toSearch, final Point toFind) {
	int closest = Integer.MAX_VALUE;

	final Monitor[] monitors = toSearch.getMonitors();
	Monitor result = monitors[0];

	for (final Monitor current : monitors) {
		final Rectangle clientArea = current.getClientArea();

		if (clientArea.contains(toFind)) { return current; }

		final int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind);
		if (distance < closest) {
			closest = distance;
			result = current;
		}
	}

	return result;
}
 
示例7
/**
 * Returns the monitor whose client area contains the given point. If no monitor contains the
 * point, returns the monitor that is closest to the point.
 * <p>
 * Copied from <code>org.eclipse.jface.window.Window.getClosestMonitor(Display, Point)</code>
 * </p>
 *
 * @param display the display showing the monitors
 * @param point point to find (display coordinates)
 * @return the monitor closest to the given point
 */
private static Monitor getClosestMonitor(Display display, Point point) {
	int closest= Integer.MAX_VALUE;

	Monitor[] monitors= display.getMonitors();
	Monitor result= monitors[0];

	for (int i= 0; i < monitors.length; i++) {
		Monitor current= monitors[i];

		Rectangle clientArea= current.getClientArea();

		if (clientArea.contains(point))
			return current;

		int distance= Geometry.distanceSquared(Geometry.centerPoint(clientArea), point);
		if (distance < closest) {
			closest= distance;
			result= current;
		}
	}

	return result;
}
 
示例8
/**
 * @param constrainee
 * @param container
 */
private void constrainRectangleToContainer( Rectangle constrainee, Rectangle container ) {
  Point originalSize = Geometry.getSize( constrainee );
  Point containerSize = Geometry.getSize( container );
  Point oversize = Geometry.subtract( originalSize, containerSize );
  if ( oversize.x > 0 ) {
    constrainee.width = originalSize.x - oversize.x;
  }
  if ( oversize.y > 0 ) {
    constrainee.height = originalSize.y - oversize.y;
  }
  // Detect if the dialog was positioned outside the container
  Geometry.moveInside( constrainee, container );
}
 
示例9
protected void updateVisibility() {
	if (popup != null && !popup.isDisposed() && delayJobFinished) {
		boolean visible = false;
		if (renameLinkedMode.isCaretInLinkedPosition()) {
			StyledText textWidget = editor.getInternalSourceViewer().getTextWidget();
			Rectangle eArea = Geometry.toDisplay(textWidget, textWidget.getClientArea());
			Rectangle pBounds = popup.getBounds();
			pBounds.x -= GAP;
			pBounds.y -= GAP;
			pBounds.width += 2 * GAP;
			pBounds.height += 2 * GAP;
			if (eArea.intersects(pBounds)) {
				visible = true;
			}
		}
		if (visible && !popup.isVisible()) {
			ISourceViewer viewer = editor.getInternalSourceViewer();
			if (viewer instanceof IWidgetTokenOwnerExtension) {
				IWidgetTokenOwnerExtension widgetTokenOwnerExtension = (IWidgetTokenOwnerExtension) viewer;
				widgetTokenOwnerExtension.requestWidgetToken(this, WIDGET_PRIORITY);
			}
		} else if (!visible && popup.isVisible()) {
			releaseWidgetToken();
		}
		popup.setVisible(visible);
	}
}
 
示例10
private void updateVisibility() {
	if (fPopup != null && !fPopup.isDisposed() && fDelayJobFinished) {
		boolean visible= false;
		//TODO: Check for visibility of linked position, not whether popup is outside of editor?
		if (fRenameLinkedMode.isCaretInLinkedPosition()) {
			StyledText textWidget= fEditor.getViewer().getTextWidget();
			Rectangle eArea= Geometry.toDisplay(textWidget, textWidget.getClientArea());
			Rectangle pBounds= fPopup.getBounds();
			pBounds.x-= GAP;
			pBounds.y-= GAP;
			pBounds.width+= 2 * GAP;
			pBounds.height+= 2 * GAP;
			if (eArea.intersects(pBounds)) {
				visible= true;
			}
		}
		if (visible && ! fPopup.isVisible()) {
			ISourceViewer viewer= fEditor.getViewer();
			if (viewer instanceof IWidgetTokenOwnerExtension) {
				IWidgetTokenOwnerExtension widgetTokenOwnerExtension= (IWidgetTokenOwnerExtension) viewer;
				visible= widgetTokenOwnerExtension.requestWidgetToken(this, WIDGET_PRIORITY);
			}
		} else if (! visible && fPopup.isVisible()) {
			releaseWidgetToken();
		}
		fPopup.setVisible(visible);
	}
}
 
示例11
private void updateVisibility() {
	if (fPopup != null && !fPopup.isDisposed() && fDelayJobFinished) {
		boolean visible= false;
		//TODO: Check for visibility of linked position, not whether popup is outside of editor?
		if (fRenameLinkedMode.isCaretInLinkedPosition()) {
			StyledText textWidget= fEditor.getViewer().getTextWidget();
			Rectangle eArea= Geometry.toDisplay(textWidget, textWidget.getClientArea());
			Rectangle pBounds= fPopup.getBounds();
			pBounds.x-= GAP;
			pBounds.y-= GAP;
			pBounds.width+= 2 * GAP;
			pBounds.height+= 2 * GAP;
			if (eArea.intersects(pBounds)) {
				visible= true;
			}
		}
		if (visible && ! fPopup.isVisible()) {
			ISourceViewer viewer= fEditor.getViewer();
			if (viewer instanceof IWidgetTokenOwnerExtension) {
				IWidgetTokenOwnerExtension widgetTokenOwnerExtension= (IWidgetTokenOwnerExtension) viewer;
				visible= widgetTokenOwnerExtension.requestWidgetToken(this, WIDGET_PRIORITY);
			}
		} else if (! visible && fPopup.isVisible()) {
			releaseWidgetToken();
		}
		fPopup.setVisible(visible);
	}
}
 
示例12
/**
 * Returns the monitor whose client area contains the given point. If no
 * monitor contains the point, returns the monitor that is closest to the
 * point.
 * <p>
 * Copied from
 * <code>org.eclipse.jface.window.Window.getClosestMonitor(Display, Point)</code>
 * </p>
 * 
 * @param display
 *            the display showing the monitors
 * @param point
 *            point to find (display coordinates)
 * @return the monitor closest to the given point
 */
private static Monitor getClosestMonitor( Display display, Point point )
{
	int closest = Integer.MAX_VALUE;

	Monitor[] monitors = display.getMonitors( );
	Monitor result = monitors[0];

	for ( int i = 0; i < monitors.length; i++ )
	{
		Monitor current = monitors[i];

		Rectangle clientArea = current.getClientArea( );

		if ( clientArea.contains( point ) )
			return current;

		int distance = Geometry.distanceSquared( Geometry.centerPoint( clientArea ),
				point );
		if ( distance < closest )
		{
			closest = distance;
			result = current;
		}
	}

	return result;
}
 
示例13
/**
 * Note that all parameters (x, y, shellTooltipArea) must be in display coordinates.
 * @param control 
 * @param display 
 */
private boolean inKeepUpZone(int x, int y, Control control, Display display) {
    if (display.isDisposed()) {
        return true; //received something from a dead display? Let's keep on showing it... (not sure if this actually happens)
    }
    Point point = display.map(control, null, x, y);

    int margin = 20;
    //the bounds are in display coordinates
    Rectangle bounds = Geometry.copy(fShellTooltipArea);

    //expand so that we have some tolerance to keep it open 
    Geometry.expand(bounds, margin, margin, margin, margin);
    return bounds.contains(point.x, point.y);
}
 
示例14
/**
 * @param constrainee
 * @param container
 */
private void constrainRectangleToContainer( Rectangle constrainee, Rectangle container ) {
  Point originalSize = Geometry.getSize( constrainee );
  Point containerSize = Geometry.getSize( container );
  Point oversize = Geometry.subtract( originalSize, containerSize );
  if ( oversize.x > 0 ) {
    constrainee.width = originalSize.x - oversize.x;
  }
  if ( oversize.y > 0 ) {
    constrainee.height = originalSize.y - oversize.y;
  }
  // Detect if the dialog was positioned outside the container
  Geometry.moveInside( constrainee, container );
}
 
示例15
/**
 * Performs calculations to size and position a dialog If the size passed in is too large for the primary monitor
 * client area, it is shrunk to fit. If the positioning leaves part of the dialog outside the client area, it is
 * centered instead.
 *
 * @param shell        The dialog to position and size
 * @param onlyPosition Unused argument. If the window is outside the viewable client are, it must be resized to prevent
 *                     inaccessibility.
 * @param minWidth
 * @param minHeight
 */
public void setShell( Shell shell, boolean onlyPosition, int minWidth, int minHeight ) {
  shell.setMaximized( maximized );
  shell.setBounds( new Rectangle(x, y, width, height) );

  if ( minWidth > 0 || minHeight > 0 ) {
    Rectangle bounds = shell.getBounds();
    if ( bounds.width < minWidth ) {
      bounds.width = minWidth;
    }
    if ( bounds.height < minHeight ) {
      bounds.height = minHeight;
    }
    shell.setSize( bounds.width, bounds.height );
  }

  // Just to double check: what is the preferred size of this dialog?
  // This computed is a minimum. If the minimum is smaller than the
  // size of the current shell, we make it larger.
  //
  Point computedSize = shell.computeSize( SWT.DEFAULT, SWT.DEFAULT );
  Rectangle shellSize = shell.getBounds();
  if ( shellSize.width < computedSize.x ) {
    shellSize.width = computedSize.x;
  }
  if ( shellSize.height < computedSize.y ) {
    shellSize.height = computedSize.y;
  }
  shell.setBounds( shellSize );

  Rectangle entireClientArea = shell.getDisplay().getClientArea();
  Rectangle resizedRect = Geometry.copy( shellSize );
  constrainRectangleToContainer( resizedRect, entireClientArea );

  // If the persisted size/location doesn't perfectly fit
  // into the entire client area, the persisted settings
  // likely were not meant for this configuration of monitors.
  // Relocate the shell into either the parent monitor or if
  // there is no parent, the primary monitor then center it.
  //
  if ( !resizedRect.equals( shellSize ) || isClippedByUnalignedMonitors( resizedRect, shell.getDisplay() ) ) {
    Monitor monitor = shell.getDisplay().getPrimaryMonitor();
    if ( shell.getParent() != null ) {
      monitor = shell.getParent().getMonitor();
    }
    Rectangle monitorClientArea = monitor.getClientArea();
    constrainRectangleToContainer( resizedRect, monitorClientArea );

    resizedRect.x = monitorClientArea.x + ( monitorClientArea.width - resizedRect.width ) / 2;
    resizedRect.y = monitorClientArea.y + ( monitorClientArea.height - resizedRect.height ) / 2;

    shell.setBounds( resizedRect );
  }
}
 
示例16
private void addMoveSupport(final Shell popupShell, final Control movedControl) {
	movedControl.addMouseListener(new MouseAdapter() {

		@Override
		public void mouseDown(final MouseEvent downEvent) {
			if (downEvent.button != 1) {
				return;
			}

			final Point POPUP_SOURCE= popupShell.getLocation();
			final StyledText textWidget= fEditor.getViewer().getTextWidget();
			Point pSize= getExtent();
			int originalSnapPosition= fSnapPosition;

			/*
			 * Feature in Tracker: it is not possible to directly control the feedback,
			 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=121300
			 * and https://bugs.eclipse.org/bugs/show_bug.cgi?id=121298#c1 .
			 *
			 * Workaround is to have an offscreen rectangle for tracking mouse movement
			 * and a manually updated rectangle for the actual drop target.
			 */
			final Tracker tracker= new Tracker(textWidget, SWT.NONE);

			final Point[] LOCATIONS= {
					textWidget.toControl(computePopupLocation(SNAP_POSITION_UNDER_RIGHT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_OVER_RIGHT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_UNDER_LEFT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_OVER_LEFT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_LOWER_RIGHT))
			};

			final Rectangle[] DROP_TARGETS= {
				Geometry.createRectangle(LOCATIONS[0], pSize),
				Geometry.createRectangle(LOCATIONS[1], pSize),
				new Rectangle(LOCATIONS[2].x, LOCATIONS[2].y + HAH, pSize.x, pSize.y),
				Geometry.createRectangle(LOCATIONS[3], pSize),
				Geometry.createRectangle(LOCATIONS[4], pSize)
			};
			final Rectangle MOUSE_MOVE_SOURCE= new Rectangle(1000000, 0, 0, 0);
			tracker.setRectangles(new Rectangle[] { MOUSE_MOVE_SOURCE, DROP_TARGETS[fSnapPosition] });
			tracker.setStippled(true);

			ControlListener moveListener= new ControlAdapter() {
				/*
				 * @see org.eclipse.swt.events.ControlAdapter#controlMoved(org.eclipse.swt.events.ControlEvent)
				 */
				@Override
				public void controlMoved(ControlEvent moveEvent) {
					Rectangle[] currentRects= tracker.getRectangles();
					final Rectangle mouseMoveCurrent= currentRects[0];
					Point popupLoc= new Point(
							POPUP_SOURCE.x + mouseMoveCurrent.x - MOUSE_MOVE_SOURCE.x,
							POPUP_SOURCE.y + mouseMoveCurrent.y - MOUSE_MOVE_SOURCE.y);

					popupShell.setLocation(popupLoc);

					Point ePopupLoc= textWidget.toControl(popupLoc);
					int minDist= Integer.MAX_VALUE;
					for (int snapPos= 0; snapPos < DROP_TARGETS.length; snapPos++) {
						int dist= Geometry.distanceSquared(ePopupLoc, LOCATIONS[snapPos]);
						if (dist < minDist) {
							minDist= dist;
							fSnapPosition= snapPos;
							fSnapPositionChanged= true;
							currentRects[1]= DROP_TARGETS[snapPos];
						}
					}
					tracker.setRectangles(currentRects);
				}
			};
			tracker.addControlListener(moveListener);
			boolean committed= tracker.open();
			tracker.close();
			tracker.dispose();
			if (committed) {
				getDialogSettings().put(SNAP_POSITION_KEY, fSnapPosition);
			} else {
				fSnapPosition= originalSnapPosition;
				fSnapPositionChanged= true;
			}
			updatePopupLocation(true);
			activateEditor();
		}
	});
}
 
示例17
private void addMoveSupport(final Shell popupShell, final Control movedControl) {
	movedControl.addMouseListener(new MouseAdapter() {

		@Override
		public void mouseDown(final MouseEvent downEvent) {
			if (downEvent.button != 1) {
				return;
			}

			final Point POPUP_SOURCE= popupShell.getLocation();
			final StyledText textWidget= fEditor.getViewer().getTextWidget();
			Point pSize= getExtent();
			int originalSnapPosition= fSnapPosition;

			/*
			 * Feature in Tracker: it is not possible to directly control the feedback,
			 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=121300
			 * and https://bugs.eclipse.org/bugs/show_bug.cgi?id=121298#c1 .
			 *
			 * Workaround is to have an offscreen rectangle for tracking mouse movement
			 * and a manually updated rectangle for the actual drop target.
			 */
			final Tracker tracker= new Tracker(textWidget, SWT.NONE);

			final Point[] LOCATIONS= {
					textWidget.toControl(computePopupLocation(SNAP_POSITION_UNDER_RIGHT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_OVER_RIGHT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_UNDER_LEFT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_OVER_LEFT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_LOWER_RIGHT))
			};

			final Rectangle[] DROP_TARGETS= {
				Geometry.createRectangle(LOCATIONS[0], pSize),
				Geometry.createRectangle(LOCATIONS[1], pSize),
				new Rectangle(LOCATIONS[2].x, LOCATIONS[2].y + HAH, pSize.x, pSize.y),
				Geometry.createRectangle(LOCATIONS[3], pSize),
				Geometry.createRectangle(LOCATIONS[4], pSize)
			};
			final Rectangle MOUSE_MOVE_SOURCE= new Rectangle(1000000, 0, 0, 0);
			tracker.setRectangles(new Rectangle[] { MOUSE_MOVE_SOURCE, DROP_TARGETS[fSnapPosition] });
			tracker.setStippled(true);

			ControlListener moveListener= new ControlAdapter() {
				/*
				 * @see org.eclipse.swt.events.ControlAdapter#controlMoved(org.eclipse.swt.events.ControlEvent)
				 */
				@Override
				public void controlMoved(ControlEvent moveEvent) {
					Rectangle[] currentRects= tracker.getRectangles();
					final Rectangle mouseMoveCurrent= currentRects[0];
					Point popupLoc= new Point(
							POPUP_SOURCE.x + mouseMoveCurrent.x - MOUSE_MOVE_SOURCE.x,
							POPUP_SOURCE.y + mouseMoveCurrent.y - MOUSE_MOVE_SOURCE.y);

					popupShell.setLocation(popupLoc);

					Point ePopupLoc= textWidget.toControl(popupLoc);
					int minDist= Integer.MAX_VALUE;
					for (int snapPos= 0; snapPos < DROP_TARGETS.length; snapPos++) {
						int dist= Geometry.distanceSquared(ePopupLoc, LOCATIONS[snapPos]);
						if (dist < minDist) {
							minDist= dist;
							fSnapPosition= snapPos;
							fSnapPositionChanged= true;
							currentRects[1]= DROP_TARGETS[snapPos];
						}
					}
					tracker.setRectangles(currentRects);
				}
			};
			tracker.addControlListener(moveListener);
			boolean committed= tracker.open();
			tracker.close();
			tracker.dispose();
			if (committed) {
				getDialogSettings().put(SNAP_POSITION_KEY, fSnapPosition);
			} else {
				fSnapPosition= originalSnapPosition;
				fSnapPositionChanged= true;
			}
			updatePopupLocation(true);
			activateEditor();
		}
	});
}
 
示例18
/**
 * Performs calculations to size and position a dialog If the size passed in is too large for the primary monitor
 * client area, it is shrunk to fit. If the positioning leaves part of the dialog outside the client area, it is
 * centered instead Note that currently, many of the defaults in org.pentaho.di.ui.core/default.properties have crazy
 * values. This causes the failsafe code in here to fire a lot more than is really necessary.
 *
 * @param shell
 *          The dialog to position and size
 * @param onlyPosition
 *          Unused argument. If the window is outside the viewable client are, it must be resized to prevent
 *          inaccessibility.
 * @param minWidth
 * @param minHeight
 */
public void setShell( Shell shell, boolean onlyPosition, int minWidth, int minHeight ) {
  shell.setMaximized( maximized );
  shell.setBounds( rectangle );

  if ( minWidth > 0 || minHeight > 0 ) {
    Rectangle bounds = shell.getBounds();
    if ( bounds.width < minWidth ) {
      bounds.width = minWidth;
    }
    if ( bounds.height < minHeight ) {
      bounds.height = minHeight;
    }
    shell.setSize( bounds.width, bounds.height );
  }

  // Just to double check: what is the preferred size of this dialog?
  // This computed is a minimum. If the minimum is smaller than the
  // size of the current shell, we make it larger.
  //
  Point computedSize = shell.computeSize( SWT.DEFAULT, SWT.DEFAULT );
  Rectangle shellSize = shell.getBounds();
  if ( shellSize.width < computedSize.x ) {
    shellSize.width = computedSize.x;
  }
  if ( shellSize.height < computedSize.y ) {
    shellSize.height = computedSize.y;
  }
  shell.setBounds( shellSize );

  Rectangle entireClientArea = shell.getDisplay().getClientArea();
  Rectangle resizedRect = Geometry.copy( shellSize );
  constrainRectangleToContainer( resizedRect, entireClientArea );

  // If the persisted size/location doesn't perfectly fit
  // into the entire client area, the persisted settings
  // likely were not meant for this configuration of monitors.
  // Relocate the shell into either the parent monitor or if
  // there is no parent, the primary monitor then center it.
  //
  if ( !resizedRect.equals( shellSize ) || isClippedByUnalignedMonitors( resizedRect, shell.getDisplay() ) ) {
    Monitor monitor = shell.getDisplay().getPrimaryMonitor();
    if ( shell.getParent() != null ) {
      monitor = shell.getParent().getMonitor();
    }
    Rectangle monitorClientArea = monitor.getClientArea();
    constrainRectangleToContainer( resizedRect, monitorClientArea );

    resizedRect.x = monitorClientArea.x + ( monitorClientArea.width - resizedRect.width ) / 2;
    resizedRect.y = monitorClientArea.y + ( monitorClientArea.height - resizedRect.height ) / 2;

    shell.setBounds( resizedRect );
  }
}
 
示例19
/**
 * Performs a DND operation to an arbitrary location. The drag start
 * location will be chosen depending on this widget's default
 * implementation.
 *
 * @param source
 *          the source widget to drag
 * @param target
 *          The target locations where the DND shall finish.
 * @see #before(AbstractSWTBot)
 * @see #on(AbstractSWTBot)
 * @see #after(AbstractSWTBot)
 */
public void dragAndDrop(final AbstractSWTBot<? extends Widget> source, final Point target) {
  final Rectangle sourceLocation = absoluteLocation(source);
  final Point slightOffset = Geometry.add(Geometry.getLocation(sourceLocation), new Point(DRAG_THRESHOLD, DRAG_THRESHOLD));
  doDragAndDrop(Geometry.min(Geometry.centerPoint(sourceLocation), slightOffset), target);
}
 
示例20
/**
 * Calculates a position which can be used to drop something <em>onto</em> the given widget by a DND operation. For tree structures, this will most
 * likely result in another child node being added. But how this is handled
 * in detail ultimately depends on the "drop action"'s implementation.
 *
 * @param targetItem
 *          On which to drop
 * @param <T>
 *          .
 * @return The {@code targetItem}'s center
 * @see #dragAndDrop(Point)
 * @see org.eclipse.swt.dnd.DND#FEEDBACK_SELECT
 */
@SuppressWarnings("PMD.ShortMethodName")
public static <T extends Widget> Point on(final AbstractSWTBot<T> targetItem) {
  return Geometry.centerPoint(absoluteLocation(targetItem));
}
 
示例21
/**
 * Creates a {@link Point} on the lower border of the given {@link Rectangle}.
 *
 * @param rect
 *          the {@link Rectangle} from which to get the lower border
 * @return a {@link Point} on the lower border of the given {@link Rectangle}
 */
private static Point pointOnLowerBorder(final Rectangle rect) {
  return new Point(Geometry.centerPoint(rect).x, rect.y + rect.height - 1);
}
 
示例22
/**
 * Creates a {@link Point} on the upper border of the given {@link Rectangle}.
 *
 * @param rect
 *          the {@link Rectangle} from which to get the upper border
 * @return a {@link Point} on the upper border of the given {@link Rectangle}
 */
private static Point pointOnUpperBorder(final Rectangle rect) {
  return new Point(Geometry.centerPoint(rect).x, rect.y + 1);
}
 
示例23
/**
 * Returns the size constraints.
 * 
 * @return the size constraints or <code>null</code> if not set
 * @see #setSizeConstraints(int, int)
 */
protected final Point getSizeConstraints()
{
	return fSizeConstraints != null ? Geometry.copy(fSizeConstraints) : null;
}