public static void main(String[] args) {
   final Display display = new Display();
   final Shell shell = new Shell(display);
   shell.setLayout(new FillLayout());
   final StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER);
   styledText.setText(text);
   FontData data = display.getSystemFont().getFontData()[0];
   Font font = new Font(display, data.getName(), 16, SWT.BOLD);
   styledText.setFont(font);
   styledText.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
   styledText.addListener(
       SWT.Resize,
       new Listener() {
         public void handleEvent(Event event) {
           Rectangle rect = styledText.getClientArea();
           Image newImage = new Image(display, 1, Math.max(1, rect.height));
           GC gc = new GC(newImage);
           gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
           gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
           gc.fillGradientRectangle(rect.x, rect.y, 1, rect.height, true);
           gc.dispose();
           styledText.setBackgroundImage(newImage);
           if (oldImage != null) oldImage.dispose();
           oldImage = newImage;
         }
       });
   shell.setSize(700, 400);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   if (oldImage != null) oldImage.dispose();
   font.dispose();
   display.dispose();
 }
예제 #2
0
  private boolean findEntry() {
    Cursor waitCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    boolean matchCase = searchDialog.getMatchCase();
    boolean matchWord = searchDialog.getMatchWord();
    String searchString = searchDialog.getSearchString();
    int column = searchDialog.getSelectedSearchArea();

    searchString = matchCase ? searchString : searchString.toLowerCase();

    boolean found = false;
    if (searchDialog.getSearchDown()) {
      for (int i = table.getSelectionIndex() + 1; i < table.getItemCount(); i++) {
        if (found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase)) {
          table.setSelection(i);
          break;
        }
      }
    } else {
      for (int i = table.getSelectionIndex() - 1; i > -1; i--) {
        if (found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase)) {
          table.setSelection(i);
          break;
        }
      }
    }

    shell.setCursor(null);

    return found;
  }
예제 #3
0
  public void positionWindow(boolean resetToDefault) {
    String mapWindow;

    mapShellBounds = mapShell.getBounds();
    mapWindow = prefs.get(RadarConsts.PREF_KEY_MAP_WINDOW, "");

    if (mapWindow.equals("") || resetToDefault) {
      Rectangle dispBounds, tableBounds;

      dispBounds = ((Display.getCurrent()).getPrimaryMonitor()).getClientArea();
      tableBounds = display.getShells()[1].getBounds();

      mapShellBounds.width = dispBounds.width - tableBounds.width;
      mapShellBounds.height = dispBounds.height;
      mapShellBounds.x = dispBounds.x + tableBounds.width;
      mapShellBounds.y = dispBounds.y;
    } else {
      String[] tokens = mapWindow.split(",");

      mapShellBounds =
          new Rectangle(
              new Integer(tokens[0]), // X value
              new Integer(tokens[1]), // Y value
              new Integer(tokens[2]), // Width
              new Integer(tokens[3]) // Height
              );
    }
    mapShell.setBounds(mapShellBounds);
  }
예제 #4
0
  public void paintReticle(final TableItem item) {
    if (cursor != null) {
      mapShell.removePaintListener(cursor);
    }
    cursor =
        new PaintListener() {
          public void paintControl(PaintEvent pe) {
            int x = 0, y = 0;
            float xF = 0.0F, yF = 0.0F;

            Entity entity = dp.entityList.get(new Integer(item.getText(0)));

            xF = RadarConsts.WINDOW_BUFFER + dp.maxX - entity.posXAxis;
            yF = entity.posYAxis - (dp.minY - RadarConsts.WINDOW_BUFFER);

            x = (int) (xF * boundsXScale);
            y = (int) (yF * boundsYScale);

            pe.gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));

            pe.gc.drawRectangle(
                x - (RadarConsts.POINT_RADIUS * 2),
                y - (RadarConsts.POINT_RADIUS * 2),
                (RadarConsts.POINT_RADIUS * 4) - 1,
                (RadarConsts.POINT_RADIUS * 4));

            pe.gc.drawLine(
                x - (RadarConsts.POINT_RADIUS * 3), y, x + (RadarConsts.POINT_RADIUS * 3) - 1, y);
            pe.gc.drawLine(
                x, y - (RadarConsts.POINT_RADIUS * 3), x, y + (RadarConsts.POINT_RADIUS * 3) - 1);
          }
        };
    mapShell.addPaintListener(cursor);
    mapShell.redraw();
  }
예제 #5
0
  public void readData(final Widget widget) {
    //    HttpServletRequest request = ContextProvider.getRequest();
    //    String parameter = request.getParameter( "JSON" );
    //    if( parameter != null ) {
    //      System.out.println( "#### BEGIN ####");
    //      System.out.println( parameter );
    //      System.out.println( "#### END ####");
    //    }

    Shell shell = (Shell) widget;
    // [if] Preserve the menu bounds before setting the new shell bounds.
    preserveMenuBounds(shell);
    // Important: Order matters, readMode() before readBounds()

    readBounds(shell);
    if (WidgetLCAUtil.wasEventSent(shell, JSConst.EVENT_SHELL_CLOSED)) {
      shell.close();
    }
    processActiveShell(shell);
    processActivate(shell);
    ControlLCAUtil.processMouseEvents(shell);
    ControlLCAUtil.processKeyEvents(shell);
    ControlLCAUtil.processMenuDetect(shell);
    WidgetLCAUtil.processHelp(shell);
  }
예제 #6
0
파일: View.java 프로젝트: shader/gdr
  public View(Controller controller) {
    this.controller = controller;
    display = new Display();
    shell = new Shell(display);
    shell.setText("Gallant Animation Viewer");

    shell.setLayout(new GridLayout());
  }
예제 #7
0
 public static void main(String[] args) {
   Display display = new Display();
   AddressBook application = new AddressBook();
   Shell shell = application.open(display);
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
예제 #8
0
파일: UIUtils.java 프로젝트: ralic/dbeaver
 public static void runInUI(@Nullable Shell shell, @NotNull Runnable runnable) {
   final Display display =
       shell == null || shell.isDisposed() ? Display.getDefault() : shell.getDisplay();
   if (display.getThread() != Thread.currentThread()) {
     display.syncExec(runnable);
   } else {
     runnable.run();
   }
 }
예제 #9
0
 private static String getMode(final Shell shell) {
   String result = null;
   if (shell.getMinimized()) {
     result = "minimized";
   } else if (shell.getMaximized() || shell.getFullScreen()) {
     result = "maximized";
   }
   return result;
 }
예제 #10
0
  public void clearMap(boolean performRedraw) {
    Listener[] painters;

    painters = mapShell.getListeners(SWT.Paint);

    for (int i = 0; i < painters.length; i++) mapShell.removeListener(SWT.Paint, painters[i]);

    if (performRedraw) mapShell.redraw();
  }
예제 #11
0
파일: View.java 프로젝트: shader/gdr
  /** Initialize all ui elements, and then display the window */
  public void Initialize() {
    initMenu();
    initToolbar();
    initCanvas();
    shell.open();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
  }
예제 #12
0
 @Override
 public void setToolTipText(String string) {
   checkWidget();
   super.setToolTipText(string);
   Shell shell = _getShell();
   ToolItem[] items = getItems();
   for (int i = 0; i < items.length; i++) {
     String newString = string != null ? null : items[i].toolTipText;
     shell.setToolTipText(items[i].handle, newString);
   }
 }
예제 #13
0
  public Shell open(Display display) {
    shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.addShellListener(
        new ShellAdapter() {
          @Override
          public void shellClosed(ShellEvent e) {
            e.doit = closeAddressBook();
          }
        });

    createMenuBar();

    searchDialog = new SearchDialog(shell);
    searchDialog.setSearchAreaNames(columnNames);
    searchDialog.setSearchAreaLabel(resAddressBook.getString("Column"));
    searchDialog.addFindListener(
        new FindListener() {
          public boolean find() {
            return findEntry();
          }
        });

    table = new Table(shell, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);
    table.setMenu(createPopUpMenu());
    table.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length > 0) editEntry(items[0]);
          }
        });
    for (int i = 0; i < columnNames.length; i++) {
      TableColumn column = new TableColumn(table, SWT.NONE);
      column.setText(columnNames[i]);
      column.setWidth(150);
      final int columnIndex = i;
      column.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              sort(columnIndex);
            }
          });
    }

    newAddressBook();

    shell.setSize(table.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300);
    shell.open();
    return shell;
  }
예제 #14
0
 private static void writeOpen(final Shell shell) throws IOException {
   // TODO [rst] workaround: qx window should be opened only once.
   Boolean defValue = Boolean.FALSE;
   Boolean actValue = Boolean.valueOf(shell.getVisible());
   if (WidgetLCAUtil.hasChanged(shell, Props.VISIBLE, actValue, defValue) && shell.getVisible()) {
     //      JSWriter writer = JSWriter.getWriterFor( shell );
     //      writer.call( "open", null );
     IWidgetSynchronizer synchronizer = WidgetSynchronizerFactory.getSynchronizerForWidget(shell);
     synchronizer.call("open");
   }
 }
예제 #15
0
 private static void readMode(final Shell shell, final String mode) {
   if (mode != null) {
     if ("maximized".equals(mode)) {
       shell.setMaximized(true);
     } else if ("minimized".equals(mode)) {
       shell.setMinimized(true);
     } else {
       shell.setMinimized(false);
       shell.setMaximized(false);
     }
   }
 }
 public static void main(String[] args) {
   Display display = new Display();
   MessageWindow application = new MessageWindow();
   Shell shell = application.open(display);
   if (args.length != 0) {
     application.openAddressBook(args[0]);
   }
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
예제 #17
0
  public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    final Button button = new Button(shell, SWT.NONE);
    button.setSize(100, 100);
    button.setText("Click");
    shell.pack();
    shell.open();
    button.addListener(
        SWT.MouseDown,
        new Listener() {
          @Override
          public void handleEvent(Event e) {
            System.out.println(
                "Mouse Down (button: " + e.button + " x: " + e.x + " y: " + e.y + ")");
          }
        });
    final Point pt = display.map(shell, null, 50, 50);
    new Thread() {
      Event event;

      @Override
      public void run() {
        try {
          Thread.sleep(300);
        } catch (InterruptedException e) {
        }
        event = new Event();
        event.type = SWT.MouseMove;
        event.x = pt.x;
        event.y = pt.y;
        display.post(event);
        try {
          Thread.sleep(300);
        } catch (InterruptedException e) {
        }
        event.type = SWT.MouseDown;
        event.button = 1;
        display.post(event);
        try {
          Thread.sleep(300);
        } catch (InterruptedException e) {
        }
        event.type = SWT.MouseUp;
        display.post(event);
      }
    }.start();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
 /** Invokes as a standalone program. */
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display, SWT.SHELL_TRIM);
   shell.setLayout(new FillLayout());
   ControlExample instance = new ControlExample(shell);
   shell.setText(getResourceString("window.title"));
   setShellSize(instance, shell);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   instance.dispose();
   display.dispose();
 }
예제 #19
0
 private static void setActiveControl(final Shell shell, final Widget widget) {
   if (EventUtil.isAccessible(widget)) {
     Object adapter = shell.getAdapter(IShellAdapter.class);
     IShellAdapter shellAdapter = (IShellAdapter) adapter;
     shellAdapter.setActiveControl((Control) widget);
   }
 }
 static boolean runLoopTimer(final Display display, final Shell shell, final int seconds) {
   final boolean[] timeout = {false};
   new Thread() {
     public void run() {
       try {
         for (int i = 0; i < seconds; i++) {
           Thread.sleep(1000);
           if (display.isDisposed() || shell.isDisposed()) return;
         }
       } catch (Exception e) {
       }
       timeout[0] = true;
       /* wake up the event loop */
       if (!display.isDisposed()) {
         display.asyncExec(
             new Runnable() {
               public void run() {
                 if (!shell.isDisposed()) shell.redraw();
               }
             });
       }
     }
   }.start();
   while (!timeout[0] && !shell.isDisposed()) if (!display.readAndDispatch()) display.sleep();
   return timeout[0];
 }
예제 #21
0
파일: View.java 프로젝트: shader/gdr
  /**
   * Initialize the toolbar with icons and selection listeners in the appropriate part of the window
   */
  public void initToolbar() {

    Device dev = shell.getDisplay();
    try {
      exitImg = new Image(dev, "img/exit.png");
      //            openImg = new Image(dev, "img/open.png");
      playImg = new Image(dev, "img/play.png");
      //            pauseImg = new Image(dev, "img/pause.png");

    } catch (Exception e) {
      System.out.println("Cannot load images");
      System.out.println(e.getMessage());
      System.exit(1);
    }

    ToolBar toolBar = new ToolBar(shell, SWT.BORDER);

    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    toolBar.setLayoutData(gridData);

    ToolItem exit = new ToolItem(toolBar, SWT.PUSH);
    exit.setImage(exitImg);

    // ToolItem open = new ToolItem(toolBar, SWT.PUSH);
    // exit.setImage(openImg);

    ToolItem play = new ToolItem(toolBar, SWT.PUSH);
    play.setImage(playImg);

    //        ToolItem pause = new ToolItem(toolBar, SWT.PUSH);
    //        pause.setImage(pauseImg);

    toolBar.pack();

    exit.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            System.exit(0);
          }
        });

    // open.addSelectionListener(new SelectionAdapter() {
    //     @Override
    //     public void widgetSelected(SelectionEvent e) {
    //         FileDialog dialog = new FileDialog(shell, SWT.NULL);
    //         String path = dialog.open();
    //     }
    // });

    play.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            controller.RunAnimation();
          }
        });
  }
예제 #22
0
 private static void preserveMenuBounds(final Shell shell) {
   Object adapter = shell.getAdapter(IShellAdapter.class);
   IShellAdapter shellAdapter = (IShellAdapter) adapter;
   Rectangle menuBounds = shellAdapter.getMenuBounds();
   IWidgetAdapter widgetAdapter = WidgetUtil.getAdapter(shell);
   widgetAdapter.preserve(PROP_SHELL_MENU_BOUNDS, menuBounds);
 }
예제 #23
0
 /**
  * Sets the control that is used to fill the bounds of the item when the item is a <code>SEPARATOR
  * </code>.
  *
  * @param control the new control
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the control has been disposed
  *       <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public void setControl(Control control) {
   checkWidget();
   if (control != null) {
     if (control.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
     if (control.parent != parent) error(SWT.ERROR_INVALID_PARENT);
   }
   if ((style & SWT.SEPARATOR) == 0) return;
   if (this.control == control) return;
   this.control = control;
   int[] argList = {
     OS.XmNseparatorType,
     control == null
         ? ((parent.style & SWT.FLAT) != 0 ? OS.XmSHADOW_ETCHED_IN : OS.XmSHADOW_ETCHED_OUT)
         : OS.XmNO_LINE,
   };
   OS.XtSetValues(handle, argList, argList.length / 2);
   if (control != null && !control.isDisposed()) {
     /*
      * It is possible that the control was created with a
      * z-order below that of the current tool item. In this
      * case, the control is not visible because it is
      * obscured by the tool item. The fix is to move the
      * control above this tool item in the z-order.
      * The code below is similar to the code found in
      * setZOrder.
      */
     int xDisplay = OS.XtDisplay(handle);
     if (xDisplay == 0) return;
     if (!OS.XtIsRealized(handle)) {
       Shell shell = parent.getShell();
       shell.realizeWidget();
     }
     int topHandle1 = control.topHandle();
     int window1 = OS.XtWindow(topHandle1);
     if (window1 == 0) return;
     int topHandle2 = this.topHandle();
     int window2 = OS.XtWindow(topHandle2);
     if (window2 == 0) return;
     XWindowChanges struct = new XWindowChanges();
     struct.sibling = window2;
     struct.stack_mode = OS.Above;
     int screen = OS.XDefaultScreen(xDisplay);
     int flags = OS.CWStackMode | OS.CWSibling;
     OS.XReconfigureWMWindow(xDisplay, window1, screen, flags, struct);
   }
   parent.relayout();
 }
  private boolean save() {
    if (file == null) return saveAs();

    Cursor waitCursor = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    TableItem[] items = table.getItems();
    String[] lines = new String[items.length];
    for (int i = 0; i < items.length; i++) {
      String[] itemText = new String[table.getColumnCount()];
      for (int j = 0; j < itemText.length; j++) {
        itemText[j] = items[i].getText(j);
      }
      lines[i] = encodeLine(itemText);
    }

    FileWriter fileWriter = null;
    try {
      fileWriter = new FileWriter(file.getAbsolutePath(), false);
      for (int i = 0; i < lines.length; i++) {
        fileWriter.write(lines[i]);
      }
    } catch (FileNotFoundException e) {
      displayError(resMessages.getString("File_not_found") + "\n" + file.getName());
      return false;
    } catch (IOException e) {
      displayError(resMessages.getString("IO_error_write") + "\n" + file.getName());
      return false;
    } finally {
      shell.setCursor(null);
      waitCursor.dispose();

      if (fileWriter != null) {
        try {
          fileWriter.close();
        } catch (IOException e) {
          displayError(resMessages.getString("IO_error_close") + "\n" + file.getName());
          return false;
        }
      }
    }

    shell.setText(resMessages.getString("Title_bar") + file.getName());
    isModified = false;
    return true;
  }
예제 #25
0
 private static void writeDefaultButton(final Shell shell) throws IOException {
   Button defaultButton = shell.getDefaultButton();
   if (defaultButton != null && defaultButton.isDisposed()) {
     //      JSWriter writer = JSWriter.getWriterFor( shell );
     //      writer.call( "setDefaultButton", NULL_PARAMETER );
     IWidgetSynchronizer synchronizer = WidgetSynchronizerFactory.getSynchronizerForWidget(shell);
     synchronizer.call("setDefaultButton");
   }
 }
예제 #26
0
 public void setTitle(String title, boolean append) {
   String text;
   if (append == true) {
     text = RadarConsts.PROGRAM_NAME + " " + RadarConsts.VERSION + " - " + title;
   } else {
     text = title;
   }
   mapShell.setText(text);
 }
예제 #27
0
 private static void writeFullScreen(final Shell shell) throws IOException {
   Object defValue = Boolean.FALSE;
   Boolean newValue = Boolean.valueOf(shell.getFullScreen());
   if (WidgetLCAUtil.hasChanged(shell, PROP_FULLSCREEN, newValue, defValue)) {
     //      JSWriter writer = JSWriter.getWriterFor( shell );
     //      writer.set( "fullScreen", newValue );
     IWidgetSynchronizer synchronizer = WidgetSynchronizerFactory.getSynchronizerForWidget(shell);
     synchronizer.setWidgetProperty("fullScreen", newValue);
   }
 }
예제 #28
0
 private void writeAlpha(final Shell shell) throws IOException {
   int alpha = shell.getAlpha();
   if (WidgetLCAUtil.hasChanged(shell, PROP_ALPHA, new Integer(alpha), new Integer(0xFF))) {
     //      JSWriter writer = JSWriter.getWriterFor( shell );
     float opacity = (alpha & 0xFF) * 1000 / 0xFF / 1000.0f;
     //      writer.set( "opacity", opacity );
     IWidgetSynchronizer synchronizer = WidgetSynchronizerFactory.getSynchronizerForWidget(shell);
     synchronizer.setWidgetProperty("opacity", opacity);
   }
 }
예제 #29
0
 private static void writeActiveShell(final Shell shell) throws IOException {
   Shell activeShell = shell.getDisplay().getActiveShell();
   boolean hasChanged = WidgetLCAUtil.hasChanged(shell, PROP_ACTIVE_SHELL, activeShell, null);
   if (shell == activeShell && hasChanged) {
     //      JSWriter writer = JSWriter.getWriterFor( shell );
     //      writer.set( "active", true );
     IWidgetSynchronizer synchronizer = WidgetSynchronizerFactory.getSynchronizerForWidget(shell);
     synchronizer.setWidgetProperty("active", true);
   }
 }
예제 #30
0
 private static void writeImage(final Shell shell) throws IOException {
   if ((shell.getStyle() & SWT.TITLE) != 0) {
     Image image = shell.getImage();
     if (image == null) {
       Image[] defaultImages = shell.getImages();
       if (defaultImages.length > 0) {
         image = defaultImages[0];
       }
     }
     if (WidgetLCAUtil.hasChanged(shell, PROP_IMAGE, image, null)) {
       //        JSWriter writer = JSWriter.getWriterFor( shell );
       //        writer.set( JSConst.QX_FIELD_ICON,
       //                    ResourceFactory.getImagePath( image ) );
       IWidgetSynchronizer synchronizer =
           WidgetSynchronizerFactory.getSynchronizerForWidget(shell);
       synchronizer.setWidgetProperty(JSConst.QX_FIELD_ICON, ResourceFactory.getImagePath(image));
     }
   }
 }