Java Code Examples for org.eclipse.swt.widgets.Display#getMonitors()

The following examples show how to use org.eclipse.swt.widgets.Display#getMonitors() . 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: WindowProperty.java    From hop with Apache License 2.0 6 votes vote down vote up
/**
 * This method is needed in the case where the display has multiple monitors, but they do not form a uniform
 * rectangle. In this case, it is possible for Geometry.moveInside() to not detect that the window is partially or
 * completely clipped. We check to make sure at least the upper left portion of the rectangle is visible to give the
 * user the ability to reposition the dialog in this rare case.
 *
 * @param constrainee
 * @param display
 * @return
 */
private boolean isClippedByUnalignedMonitors( Rectangle constrainee, Display display ) {
  boolean isClipped;
  Monitor[] monitors = display.getMonitors();
  if ( monitors.length > 0 ) {
    // Loop searches for a monitor proving false
    isClipped = true;
    for ( Monitor monitor : monitors ) {
      if ( monitor.getClientArea().contains( constrainee.x + 10, constrainee.y + 10 ) ) {
        isClipped = false;
        break;
      }
    }
  } else {
    isClipped = false;
  }

  return isClipped;
}
 
Example 2
Source File: UIUtils.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: SWTUtil.java    From SWET with MIT License 6 votes vote down vote up
private static Rectangle getCurrentMonitorBounds(Display dsp) {
	Monitor monitor = dsp.getPrimaryMonitor();

	// Choose current Monitor
	Point cursor = dsp.getCursorLocation();
	Monitor[] monitors = dsp.getMonitors();
	for (Monitor mon : monitors) {
		Rectangle mbounds = mon.getBounds();
		if (mbounds.contains(cursor)) {
			monitor = mon;
			break;
		}
	}

	return monitor.getBounds();
}
 
Example 4
Source File: BreadcrumbItemDropDown.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: GamlSearchField.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: BreadcrumbItemDropDown.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: WindowProperty.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * This method is needed in the case where the display has multiple monitors, but they do not form a uniform
 * rectangle. In this case, it is possible for Geometry.moveInside() to not detect that the window is partially or
 * completely clipped. We check to make sure at least the upper left portion of the rectangle is visible to give the
 * user the ability to reposition the dialog in this rare case.
 *
 * @param constrainee
 * @param display
 * @return
 */
private boolean isClippedByUnalignedMonitors( Rectangle constrainee, Display display ) {
  boolean isClipped;
  Monitor[] monitors = display.getMonitors();
  if ( monitors.length > 0 ) {
    // Loop searches for a monitor proving false
    isClipped = true;
    for ( Monitor monitor : monitors ) {
      if ( monitor.getClientArea().contains( constrainee.x + 10, constrainee.y + 10 ) ) {
        isClipped = false;
        break;
      }
    }
  } else {
    isClipped = false;
  }

  return isClipped;
}
 
Example 8
Source File: MainView.java    From Universal-FE-Randomizer with MIT License 5 votes vote down vote up
public MainView(Display mainDisplay) {
	super();
	
	Shell shell = new Shell(mainDisplay, SWT.SHELL_TRIM & ~SWT.MAX); 
	 shell.setText("Yune: A Universal Fire Emblem Randomizer (v0.9.1)");
	 shell.setImage(new Image(mainDisplay, Main.class.getClassLoader().getResourceAsStream("YuneIcon.png")));
	 
	 screenHeight = mainDisplay.getBounds().height;
	 for (Monitor monitor : mainDisplay.getMonitors()) {
		 screenHeight = Math.max(screenHeight, monitor.getClientArea().height);
	 }
	 
	 screenHeight -= 20;
	 
	 mainShell = shell;
	 
	 setupMainShell();
	 
	 resize();
	 
	 /* Open shell window */
	  mainShell.open();
	  
	  mainDisplay.addFilter(SWT.KeyDown, new Listener() {
		@Override
		public void handleEvent(Event event) {
			if (((event.stateMask & SWT.CTRL) != 0) && ((event.stateMask & SWT.SHIFT) != 0) && (event.keyCode == 'c') && !consoleShellOpened) {
				openConsole();
			}
		}
	  });
}
 
Example 9
Source File: AbstractPopup.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
private Monitor selectMonitor(Display display) {
  Shell activeShell = display.getActiveShell();
  if (activeShell != null && activeShell.getMonitor() != null) {
    return activeShell.getMonitor();
  }

  // Fall-back
  Monitor[] monitors = display.getMonitors();
  if (monitors.length > 0) {
    return monitors[0];
  }

  // Worst case. What? Can this happen?
  return null;
}
 
Example 10
Source File: BreadcrumbItemDropDown.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 11
Source File: Main.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the monitor on which the application was launched.
 *
 * @param display
 * @return
 */
private static Monitor getMonitor(Display display) {
    Point mouse = display.getCursorLocation();
    for (Monitor monitor : display.getMonitors()) {
        if (monitor.getBounds().contains(mouse)) {
            return monitor;
        }
    }
    return display.getPrimaryMonitor();
}
 
Example 12
Source File: GanttTester.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public GanttTester() {
    final Display display = Display.getDefault(); //new Display();
    final Monitor m = display.getMonitors()[0];
    final Shell shell = new Shell(display);
    shell.setText("GanttChart Test Application");
    shell.setLayout(new FillLayout());

    final SashForm sfVSplit = new SashForm(shell, SWT.VERTICAL);
    final SashForm sfHSplit = new SashForm(sfVSplit, SWT.HORIZONTAL);

    final ViewForm vfBottom = new ViewForm(sfVSplit, SWT.NONE);
    _vfChart = new ViewForm(sfHSplit, SWT.NONE);
    final ViewForm rightForm = new ViewForm(sfHSplit, SWT.NONE);

    final ScrolledComposite sc = new ScrolledComposite(rightForm, SWT.V_SCROLL | SWT.H_SCROLL);
    rightForm.setContent(sc);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    sc.getVerticalBar().setPageIncrement(150);

    final Composite rightComposite = new Composite(sc, SWT.NONE);
    final GridLayout gl = new GridLayout();
    gl.marginLeft = 0;
    gl.marginTop = 0;
    gl.horizontalSpacing = 0;
    gl.verticalSpacing = 0;
    gl.marginBottom = 0;
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    rightComposite.setLayout(gl);

    sc.setContent(rightComposite);

    rightComposite.addListener(SWT.Resize, new Listener() {

        public void handleEvent(final Event event) {
            sc.setMinSize(rightComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
        }

    });

    sfVSplit.setWeights(new int[] { 91, 9 });
    sfHSplit.setWeights(new int[] { 70, 30 });

    // top left side
    _ganttChart = new GanttChart(_vfChart, SWT.MULTI);
    _vfChart.setContent(_ganttChart);
    _ganttComposite = _ganttChart.getGanttComposite();

    final TabFolder tfRight = new TabFolder(rightComposite, SWT.BORDER);
    final TabItem tiGeneral = new TabItem(tfRight, SWT.NONE);
    tiGeneral.setText("Creation");

    final TabItem tiAdvanced = new TabItem(tfRight, SWT.NONE);
    tiAdvanced.setText("Advanced");

    final TabItem tiEventLog = new TabItem(tfRight, SWT.NONE);
    tiEventLog.setText("Event Log");

    final Composite bottom = new Composite(rightComposite, SWT.NONE);
    bottom.setLayout(new GridLayout());
    createCreateButtons(bottom);

    vfBottom.setContent(createBottom(vfBottom));
    tiGeneral.setControl(createCreationTab(tfRight)); // NOPMD
    tiAdvanced.setControl(createAdvancedTab(tfRight));
    tiEventLog.setControl(createEventLogTab(tfRight));

    shell.setMaximized(true);
    // uncomment to put on right-hand-side monitor
    shell.setLocation(new Point(m.getClientArea().x, 0));

    sc.setMinSize(rightComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));

    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.removeListener(SWT.KeyDown, _undoRedoListener);

    shell.dispose();
}
 
Example 13
Source File: Editor.java    From Rel with Apache License 2.0 4 votes vote down vote up
private void registerMultiLineEditorColumn(IConfigRegistry configRegistry, String columnLabel) {
	// configure the multi line text editor
	configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
			new MultiLineTextCellEditor(false) {
				protected Control activateCell(Composite parent, Object originalCanonicalValue) {
					editorBeenOpened(getRowIndex(), getColumnIndex());
					return super.activateCell(parent, originalCanonicalValue);
				}

				public void close() {
					editorBeenClosed(getRowIndex(), getColumnIndex());
					super.close();
				}
			}, DisplayMode.NORMAL, columnLabel);

	Style cellStyle = new Style();
	cellStyle.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.LEFT);
	configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL,
			columnLabel);
	configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.EDIT,
			columnLabel);

	// configure custom dialog settings
	Display display = Display.getCurrent();
	Map<String, Object> editDialogSettings = new HashMap<String, Object>();
	editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_TITLE, "Edit");
	editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_ICON, display.getSystemImage(SWT.ICON_WARNING));
	editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_RESIZABLE, Boolean.TRUE);

	Point size = new Point(400, 300);
	editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_SIZE, size);

	int screenWidth = display.getBounds().width;
	int screenHeight = display.getBounds().height;
	Point location = new Point((screenWidth / (2 * display.getMonitors().length)) - (size.x / 2),
			(screenHeight / 2) - (size.y / 2));
	editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_LOCATION, location);

	configRegistry.registerConfigAttribute(EditConfigAttributes.EDIT_DIALOG_SETTINGS, editDialogSettings,
			DisplayMode.EDIT, columnLabel);
}