Search in sources :

Example 11 with Monitor

use of org.eclipse.swt.widgets.Monitor in project pentaho-kettle by pentaho.

the class BaseStepDialog method setSize.

/**
 * Sets the size of this dialog with respect to the given parameters.
 *
 * @param shell     the shell
 * @param minWidth  the minimum width
 * @param minHeight the minimum height
 * @param packIt    true to pack the dialog components, false otherwise
 */
public static void setSize(Shell shell, int minWidth, int minHeight, boolean packIt) {
    PropsUI props = PropsUI.getInstance();
    WindowProperty winprop = props.getScreen(shell.getText());
    if (winprop != null) {
        winprop.setShell(shell, minWidth, minHeight);
    } else {
        if (packIt) {
            shell.pack();
        } else {
            shell.layout();
        }
        // OK, sometimes this produces dialogs that are waay too big.
        // Try to limit this a bit, m'kay?
        // Use the same algorithm by cheating :-)
        // 
        winprop = new WindowProperty(shell);
        winprop.setShell(shell, minWidth, minHeight);
        // Now, as this is the first time it gets opened, try to put it in the middle of the screen...
        Rectangle shellBounds = shell.getBounds();
        Monitor monitor = shell.getDisplay().getPrimaryMonitor();
        if (shell.getParent() != null) {
            monitor = shell.getParent().getMonitor();
        }
        Rectangle monitorClientArea = monitor.getClientArea();
        int middleX = monitorClientArea.x + (monitorClientArea.width - shellBounds.width) / 2;
        int middleY = monitorClientArea.y + (monitorClientArea.height - shellBounds.height) / 2;
        shell.setLocation(middleX, middleY);
    }
}
Also used : WindowProperty(org.pentaho.di.ui.core.gui.WindowProperty) Monitor(org.eclipse.swt.widgets.Monitor) Rectangle(org.eclipse.swt.graphics.Rectangle) PropsUI(org.pentaho.di.ui.core.PropsUI)

Example 12 with Monitor

use of org.eclipse.swt.widgets.Monitor in project pentaho-kettle by pentaho.

the class BaseStepXulDialog method setSize.

public static void setSize(Shell shell, int minWidth, int minHeight, boolean packIt) {
    PropsUI props = PropsUI.getInstance();
    WindowProperty winprop = props.getScreen(shell.getText());
    if (winprop != null) {
        winprop.setShell(shell, minWidth, minHeight);
    } else {
        if (packIt) {
            shell.pack();
        } else {
            shell.layout();
        }
        // OK, sometimes this produces dialogs that are waay too big.
        // Try to limit this a bit, m'kay?
        // Use the same algorithm by cheating :-)
        // 
        winprop = new WindowProperty(shell);
        winprop.setShell(shell, minWidth, minHeight);
        // Now, as this is the first time it gets opened, try to put it in the middle of the screen...
        Rectangle shellBounds = shell.getBounds();
        Monitor monitor = shell.getDisplay().getPrimaryMonitor();
        if (shell.getParent() != null) {
            monitor = shell.getParent().getMonitor();
        }
        Rectangle monitorClientArea = monitor.getClientArea();
        int middleX = monitorClientArea.x + (monitorClientArea.width - shellBounds.width) / 2;
        int middleY = monitorClientArea.y + (monitorClientArea.height - shellBounds.height) / 2;
        shell.setLocation(middleX, middleY);
    }
}
Also used : WindowProperty(org.pentaho.di.ui.core.gui.WindowProperty) Monitor(org.eclipse.swt.widgets.Monitor) Rectangle(org.eclipse.swt.graphics.Rectangle) PropsUI(org.pentaho.di.ui.core.PropsUI)

Example 13 with Monitor

use of org.eclipse.swt.widgets.Monitor in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_Control method test_getMonitor.

@Test
public void test_getMonitor() {
    Monitor monitor = control.getMonitor();
    assertNotNull(monitor);
    Display display = control.getDisplay();
    Monitor[] monitors = display.getMonitors();
    int i;
    /* monitor must be listed in Display.getMonitors */
    for (i = 0; i < monitors.length; i++) {
        if (monitor.equals(monitors[i]))
            break;
    }
    if (i == monitors.length) {
        fail("Control.getMonitor does not return a monitor listed in Display.getMonitors");
    }
}
Also used : Monitor(org.eclipse.swt.widgets.Monitor) Point(org.eclipse.swt.graphics.Point) Display(org.eclipse.swt.widgets.Display) Test(org.junit.Test)

Example 14 with Monitor

use of org.eclipse.swt.widgets.Monitor in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_Display method test_getPrimaryMonitor.

/**
 * Note, this is hard to test via unit tests as you might not have multiple monitors.
 * When altering this function, it is recommended to perform
 * the following tests manually:
 * - Dual monitors with:
 *   - Primary being on the left
 *   - Primary being on the right
 *   - Stacked displays, primary on top
 *   - Stack displays, primary on bottom
 * - Single display
 */
@Test
public void test_getPrimaryMonitor() {
    Display display = new Display();
    Monitor monitor = display.getPrimaryMonitor();
    assertNotNull(monitor);
    display.dispose();
}
Also used : Monitor(org.eclipse.swt.widgets.Monitor) Display(org.eclipse.swt.widgets.Display) Test(org.junit.Test)

Example 15 with Monitor

use of org.eclipse.swt.widgets.Monitor in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_Display method test_getMonitors.

@Test
public void test_getMonitors() {
    Display display = new Display();
    Monitor[] monitors = display.getMonitors();
    assertNotNull(monitors);
    assertTrue("at least one monitor should be returned", monitors.length >= 1);
    for (int i = 0; i < monitors.length; i++) assertNotNull("monitor at index " + i + " should not be null", monitors[i]);
    display.dispose();
}
Also used : Monitor(org.eclipse.swt.widgets.Monitor) Point(org.eclipse.swt.graphics.Point) Display(org.eclipse.swt.widgets.Display) Test(org.junit.Test)

Aggregations

Monitor (org.eclipse.swt.widgets.Monitor)20 Rectangle (org.eclipse.swt.graphics.Rectangle)15 Point (org.eclipse.swt.graphics.Point)12 Display (org.eclipse.swt.widgets.Display)6 Test (org.junit.Test)3 PropsUI (org.pentaho.di.ui.core.PropsUI)3 WindowProperty (org.pentaho.di.ui.core.gui.WindowProperty)3 AddReferenceWizard (net.servicestack.eclipse.wizard.AddReferenceWizard)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 Composite (org.eclipse.swt.widgets.Composite)1 Shell (org.eclipse.swt.widgets.Shell)1 ISelectionService (org.eclipse.ui.ISelectionService)1