Exemple #1
0
  /** @param args */
  public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("CDateTime");
    shell.setLayout(new GridLayout(3, true));

    final CDateTime date = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
    date.setNullText("<day>");
    date.setPattern("dd");
    date.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

    final CDateTime month = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
    month.setNullText("<month>");
    month.setPattern("MMMM");
    month.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

    final CDateTime year = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
    year.setNullText("<year>");
    year.setPattern("yyyy");
    year.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

    shell.pack();
    Point size = shell.getSize();
    Rectangle screen = display.getMonitors()[0].getBounds();
    shell.setBounds((screen.width - size.x) / 2, (screen.height - size.y) / 2, size.x, size.y);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
Exemple #2
0
 /**
  * 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();
 }
 @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");
   }
 }
Exemple #4
0
  /** @param args */
  public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("CDateTime");
    shell.setLayout(new GridLayout());

    final CDateTime cdt = new CDateTime(shell, CDT.BORDER | CDT.COMPACT | CDT.SIMPLE);
    cdt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));

    shell.pack();
    Point size = shell.getSize();
    Rectangle screen = display.getMonitors()[0].getBounds();
    shell.setBounds((screen.width - size.x) / 2, (screen.height - size.y) / 2, size.x, size.y);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }