Java Code Examples for org.eclipse.swt.graphics.Rectangle#equals()

The following examples show how to use org.eclipse.swt.graphics.Rectangle#equals() . 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: SelectionModel.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
private void addSelectionIntoList(Rectangle selection) {
	selectionsLock.writeLock().lock();
	try {
		ArrayList<Rectangle> itemsToRemove = null;
		for (Rectangle r : selections) {
			if (selection.intersects(r)) {
				if (r.equals(selection)) {
					break;
				}

				Rectangle intersection = selection.intersection(r);
				if (intersection.equals(r)) {
					// r is a subset of intersection
					if (itemsToRemove == null)
						itemsToRemove = new ArrayList<Rectangle>();

					itemsToRemove.add(r);
				} else if (intersection.equals(selection)) {
					// selection is a subset of r
					break;
				}
			}
		}

		if (itemsToRemove != null) {
			selections.removeAll(itemsToRemove);
		}

		selections.add(selection);
	} finally {
		selectionsLock.writeLock().unlock();
	}

}
 
Example 2
Source File: SelectionModel.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private void addSelectionIntoList(Rectangle selection) {
	selectionsLock.writeLock().lock();
	try {
		ArrayList<Rectangle> itemsToRemove = null;
		for (Rectangle r : selections) {
			if (selection.intersects(r)) {
				if (r.equals(selection)) {
					break;
				}

				Rectangle intersection = selection.intersection(r);
				if (intersection.equals(r)) {
					// r is a subset of intersection
					if (itemsToRemove == null)
						itemsToRemove = new ArrayList<Rectangle>();

					itemsToRemove.add(r);
				} else if (intersection.equals(selection)) {
					// selection is a subset of r
					break;
				}
			}
		}

		if (itemsToRemove != null) {
			selections.removeAll(itemsToRemove);
		}

		selections.add(selection);
	} finally {
		selectionsLock.writeLock().unlock();
	}

}
 
Example 3
Source File: WindowProperty.java    From hop with Apache License 2.0 4 votes vote down vote up
/**
 * 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 );
  }
}
 
Example 4
Source File: SelectionModel.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @return TRUE if <i>rectangle</i> is completely contained inside <i>containerRectangle</i>
 */
protected boolean contains(Rectangle containerRectangle, Rectangle rectangle) {
	Rectangle union = containerRectangle.union(rectangle);
	return union.equals(containerRectangle); 
}
 
Example 5
Source File: SelectionModel.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @return TRUE if <i>rectangle</i> is completely contained inside <i>containerRectangle</i>
 */
protected boolean contains(Rectangle containerRectangle, Rectangle rectangle) {
	Rectangle union = containerRectangle.union(rectangle);
	return union.equals(containerRectangle); 
}
 
Example 6
Source File: WindowProperty.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * 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 );
  }
}