Java Code Examples for org.eclipse.swt.widgets.Shell#getLocation()

The following examples show how to use org.eclipse.swt.widgets.Shell#getLocation() . 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: ContentAssistant.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * getStackedLocation
 * 
 * @param shell
 * @param parent
 * @return Point
 */
protected Point getStackedLocation(Shell shell, Shell parent)
{
	Point p = parent.getLocation();
	Point parentSize = parent.getSize();
	// p.x += parentSize.x / 4;
	p.y += parentSize.y + 5;

	// p= parent.toDisplay(p);

	Rectangle shellBounds = shell.getBounds();
	Rectangle displayBounds = shell.getDisplay().getClientArea();
	shiftHorizontalLocation(p, shellBounds, displayBounds);
	shiftVerticalLocation(p, shellBounds, displayBounds, true);

	return p;
}
 
Example 2
Source File: Dialog.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void center() {
	final Point preferredSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);

	if (preferredSize.x < minimumWidth) {
		preferredSize.x = minimumWidth;
	}

	if (preferredSize.y < minimumHeight) {
		preferredSize.y = minimumHeight;
	}
	
	final int centerX;
	final int centerY;

	if (centerPolicy == CenterOption.CENTER_ON_SCREEN || shell.getParent() == null) {
		Shell activeShell = shell.getDisplay().getActiveShell();
		final Rectangle monitorBounds = SWTGraphicUtil.getBoundsOfMonitorOnWhichShellIsDisplayed(activeShell);
		centerX = monitorBounds.x + (monitorBounds.width - preferredSize.x) / 2;
		centerY = monitorBounds.y + (monitorBounds.height - preferredSize.y) / 2;
	} else {
		final Shell parent = (Shell) shell.getParent();
		centerX = parent.getLocation().x + (parent.getSize().x - preferredSize.x) / 2;
		centerY = parent.getLocation().y + (parent.getSize().y - preferredSize.y) / 2;
	}

	shell.setBounds(centerX, centerY, preferredSize.x, preferredSize.y);		
}
 
Example 3
Source File: SwtUtil.java    From AppleCommander with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Center the child shell within the parent shell window.
 */
public static void center(Shell parent, Shell child) {
	int x = parent.getLocation().x + 
		(parent.getSize().x - child.getSize().x) / 2;
	int y = parent.getLocation().y +
		(parent.getSize().y - child.getSize().y) / 2;
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	child.setLocation(x,y);
}
 
Example 4
Source File: PopupDialog.java    From SWET with MIT License 5 votes vote down vote up
/**
 * Saves the bounds of the shell in the appropriate dialog settings. The
 * bounds are recorded relative to the parent shell, if there is one, or
 * display coordinates if there is no parent shell. Subclasses typically
 * need not override this method, but may extend it (calling
 * <code>super.saveDialogBounds</code> if additional bounds information
 * should be stored. Clients may also call this method to persist the bounds
 * at times other than closing the dialog.
 * 
 * @param shell
 *            The shell whose bounds are to be stored
 */
protected void saveDialogBounds(Shell shell) {
	IDialogSettings settings = getDialogSettings();
	if (settings != null) {
		Point shellLocation = shell.getLocation();
		Point shellSize = shell.getSize();
		Shell parent = getParentShell();
		if (parent != null) {
			Point parentLocation = parent.getLocation();
			shellLocation.x -= parentLocation.x;
			shellLocation.y -= parentLocation.y;
		}
		String prefix = getClass().getName();
		if (persistSize) {
			settings.put(prefix + DIALOG_WIDTH, shellSize.x);
			settings.put(prefix + DIALOG_HEIGHT, shellSize.y);
		}
		if (persistLocation) {
			settings.put(prefix + DIALOG_ORIGIN_X, shellLocation.x);
			settings.put(prefix + DIALOG_ORIGIN_Y, shellLocation.y);
		}
		if (showPersistActions && showDialogMenu) {
			settings.put(getClass().getName() + DIALOG_USE_PERSISTED_SIZE,
					persistSize);
			settings.put(getClass().getName() + DIALOG_USE_PERSISTED_LOCATION,
					persistLocation);

		}
	}
}
 
Example 5
Source File: LayoutLogic.java    From logbook with MIT License 5 votes vote down vote up
/**
 * Shellのウインドウ位置とサイズを保存します
 * 
 * @param clazz ウインドウクラス
 * @param shell Shell
 */
public static void saveWindowLocation(Class<? extends Dialog> clazz, Shell shell) {
    Map<String, WindowLocationBean> map = AppConfig.get().getWindowLocationMap();
    Point location = shell.getLocation();
    Point size = shell.getSize();
    WindowLocationBean wlocation = new WindowLocationBean();
    wlocation.setX(location.x);
    wlocation.setY(location.y);
    wlocation.setWidth(size.x);
    wlocation.setHeight(size.y);
    synchronized (map) {
        map.put(clazz.getName(), wlocation);
    }
}
 
Example 6
Source File: BreadcrumbItemDropDown.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Set the size of the given shell such that more content can be shown. The
 * shell size does not exceed {@link #DROP_DOWN_HIGHT} and
 * {@link #DROP_DOWN_WIDTH}.
 * 
 * @param shell the shell to resize
 */
private void resizeShell(final Shell shell) {
  Point size = shell.getSize();
  int currentWidth = size.x;
  int currentHeight = size.y;

  if (currentHeight >= DROP_DOWN_HIGHT && currentWidth >= DROP_DOWN_WIDTH)
    return;

  Point preferedSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);

  int newWidth;
  if (currentWidth >= DROP_DOWN_WIDTH) {
    newWidth = currentWidth;
  } else {
    newWidth = Math.min(Math.max(preferedSize.x, currentWidth),
        DROP_DOWN_WIDTH);
  }
  int newHeight;
  if (currentHeight >= DROP_DOWN_HIGHT) {
    newHeight = currentHeight;
  } else {
    newHeight = Math.min(Math.max(preferedSize.y, currentHeight),
        DROP_DOWN_HIGHT);
  }

  if (newHeight != currentHeight || newWidth != currentWidth) {
    shell.setRedraw(false);
    try {
      shell.setSize(newWidth, newHeight);
      if (!isLTR()) {
        Point location = shell.getLocation();
        shell.setLocation(location.x - (newWidth - currentWidth), location.y);
      }
    } finally {
      shell.setRedraw(true);
    }
  }
}
 
Example 7
Source File: DialogMemento.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Stores it current configuration in the dialog store.
 */
public void writeSettings(Shell shell) {
    Point location = shell.getLocation();
    fSettings.put("x", location.x);
    fSettings.put("y", location.y);

    Point size = shell.getSize();
    fSettings.put("width", size.x);
    fSettings.put("height", size.y);
}
 
Example 8
Source File: VertexWindow.java    From ldparteditor with MIT License 4 votes vote down vote up
/**
 * Places the vertex window on the 3D editor
 */
public static void placeVertexWindow() {
    final Composite3D lastHoveredC3d = DatFile.getLastHoveredComposite();
    if (lastHoveredC3d == null || Display.getDefault().getActiveShell() == null) return;

    final VertexWindow vertexWindow = Editor3DWindow.getWindow().getVertexWindow();
    final DatFile df = lastHoveredC3d.getLockableDatFileReference();
    final Set<Vertex> selectedVertices = df.getVertexManager().getSelectedVertices();
    final boolean singleVertexSelected = !df.isReadOnly() && selectedVertices.size() == 1;
    final boolean addingSomething = Editor3DWindow.getWindow().isAddingSomething();

    final boolean windowShouldBeDisplayed = singleVertexSelected && !addingSomething;

    Vertex newSelectedVertex = new Vertex(0,0,0);

    if (singleVertexSelected) {
        try {
            newSelectedVertex = selectedVertices.iterator().next();
        } catch (NoSuchElementException consumed) {}
    }

    if (windowShouldBeDisplayed && vertexWindow.getShell() == null) {
        vertexWindow.run();
        lastHoveredC3d.setFocus();
        Editor3DWindow.getWindow().getShell().setActive();
    } else if (!windowShouldBeDisplayed && vertexWindow.getShell() != null) {
        vertexWindow.close();
    }

    final Shell vertexWindowShell = vertexWindow.getShell();
    if (vertexWindowShell == null || vertexWindowShell.isDisposed()) {
        return;
    }

    if (singleVertexSelected) {
        vertexWindow.updateVertex(newSelectedVertex);
    }

    final Point old = vertexWindowShell.getLocation();
    final Point a = ShellHelper.absolutePositionOnShell(lastHoveredC3d);
    final Point s = vertexWindowShell.getSize();

    final int xPos = a.x - s.x + lastHoveredC3d.getSize().x;
    final int yPos = a.y;

    if (old.x != xPos || old.y != yPos) {
        vertexWindowShell.setLocation(xPos, yPos);
    }
}
 
Example 9
Source File: BreadcrumbItemDropDown.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Set the size of the given shell such that more content can be shown. The shell size does not
 * exceed a user-configurable maximum.
 *
 * @param shell the shell to resize
 */
private void resizeShell(final Shell shell) {
	Point size= shell.getSize();
	int currentWidth= size.x;
	int currentHeight= size.y;

	int maxHeight= getMaxHeight();
	
	if (currentHeight >= maxHeight && currentWidth >= DROP_DOWN_MAX_WIDTH)
		return;

	Point preferedSize= shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);

	int newWidth;
	if (currentWidth >= DROP_DOWN_MAX_WIDTH) {
		newWidth= currentWidth;
	} else {
		newWidth= Math.min(Math.max(preferedSize.x, currentWidth), DROP_DOWN_MAX_WIDTH);
	}
	int newHeight;
	if (currentHeight >= maxHeight) {
		newHeight= currentHeight;
	} else {
		newHeight= Math.min(Math.max(preferedSize.y, currentHeight), maxHeight);
	}

	if (newHeight != currentHeight || newWidth != currentWidth) {
		shell.setRedraw(false);
		try {
			isResizingProgrammatically= true;
			shell.setSize(newWidth, newHeight);
			if (!isLTR()) {
				Point location= shell.getLocation();
				shell.setLocation(location.x - (newWidth - currentWidth), location.y);
			}
		} finally {
			isResizingProgrammatically= false;
			shell.setRedraw(true);
		}
	}
}
 
Example 10
Source File: BreadcrumbItemDropDown.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Set the size of the given shell such that more content can be shown. The
 * shell size does not exceed {@link #DROP_DOWN_HIGHT} and
 * {@link #DROP_DOWN_WIDTH}.
 * 
 * @param shell
 *            the shell to resize
 */
private void resizeShell( final Shell shell )
{
	Point size = shell.getSize( );
	int currentWidth = size.x;
	int currentHeight = size.y;

	if ( currentHeight >= DROP_DOWN_HIGHT
			&& currentWidth >= DROP_DOWN_WIDTH )
		return;

	Point preferedSize = shell.computeSize( SWT.DEFAULT, SWT.DEFAULT, true );

	int newWidth;
	if ( currentWidth >= DROP_DOWN_WIDTH )
	{
		newWidth = currentWidth;
	}
	else
	{
		newWidth = Math.min( Math.max( preferedSize.x, currentWidth ),
				DROP_DOWN_WIDTH );
	}
	int newHeight;
	if ( currentHeight >= DROP_DOWN_HIGHT )
	{
		newHeight = currentHeight;
	}
	else
	{
		newHeight = Math.min( Math.max( preferedSize.y, currentHeight ),
				DROP_DOWN_HIGHT );
	}

	if ( newHeight != currentHeight || newWidth != currentWidth )
	{
		shell.setRedraw( false );
		try
		{
			shell.setSize( newWidth, newHeight );
			if ( !isLTR( ) )
			{
				Point location = shell.getLocation( );
				shell.setLocation( location.x - ( newWidth - currentWidth ),
						location.y );
			}
		}
		finally
		{
			shell.setRedraw( true );
		}
	}
}