Esempio n. 1
0
 void drawRectangles(Rectangle[] rects, boolean stippled) {
   int xDisplay = display.xDisplay;
   int color = OS.XWhitePixel(xDisplay, 0);
   int xWindow = OS.XDefaultRootWindow(xDisplay);
   if (parent != null) {
     xWindow = OS.XtWindow(parent.handle);
     if (xWindow == 0) return;
     int foreground = parent.getForegroundPixel();
     Control control = parent.findBackgroundControl();
     if (control == null) control = parent;
     int background = control.getBackgroundPixel();
     color = foreground ^ background;
   }
   int gc = OS.XCreateGC(xDisplay, xWindow, 0, null);
   OS.XSetForeground(xDisplay, gc, color);
   OS.XSetSubwindowMode(xDisplay, gc, OS.IncludeInferiors);
   OS.XSetFunction(xDisplay, gc, OS.GXxor);
   int stipplePixmap = 0;
   if (stippled) {
     byte[] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0};
     stipplePixmap = OS.XCreateBitmapFromData(xDisplay, xWindow, bits, 8, 8);
     OS.XSetStipple(xDisplay, gc, stipplePixmap);
     OS.XSetFillStyle(xDisplay, gc, OS.FillStippled);
     OS.XSetLineAttributes(xDisplay, gc, 3, OS.LineSolid, OS.CapButt, OS.JoinMiter);
   }
   for (int i = 0; i < rects.length; i++) {
     Rectangle rect = rects[i];
     OS.XDrawRectangle(xDisplay, xWindow, gc, rect.x, rect.y, rect.width, rect.height);
   }
   if (stippled) {
     OS.XFreePixmap(xDisplay, stipplePixmap);
   }
   OS.XFreeGC(xDisplay, gc);
 }
  /**
   * Creates an instance of a ControlExample embedded inside the supplied parent Composite.
   *
   * @param parent the container of the example
   */
  public ControlExample(Composite parent) {
    initResources();
    tabFolder = new TabFolder(parent, SWT.NONE);
    tabs = createTabs();
    for (Tab tab : tabs) {
      TabItem item = new TabItem(tabFolder, SWT.NONE);
      item.setText(tab.getTabText());
      item.setControl(tab.createTabFolderPage(tabFolder));
      item.setData(tab);
    }

    /* Workaround: if the tab folder is wider than the screen,
     * Mac platforms clip instead of somehow scrolling the tab items.
     * We try to recover some width by using shorter tab names. */
    Point size = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = parent.getMonitor().getClientArea();
    boolean isMac = SWT.getPlatform().equals("cocoa");
    if (size.x > monitorArea.width && isMac) {
      TabItem[] tabItems = tabFolder.getItems();
      for (int i = 0; i < tabItems.length; i++) {
        tabItems[i].setText(tabs[i].getShortTabText());
      }
    }
    startup = false;
  }
Esempio n. 3
0
 void update() {
   if (parent != null) {
     if (parent.isDisposed()) return;
     parent.getShell().update();
   } else {
     display.update();
   }
 }
Esempio n. 4
0
 private void createRight(final Composite parent) {
   parent.setLayout(new FillLayout());
   Group styleGroup = new Group(parent, SWT.NONE);
   styleGroup.setText("Styles and Parameters");
   styleGroup.setLayout(new FillLayout());
   styleComp = new Composite(styleGroup, SWT.NONE);
   styleComp.setLayout(new RowLayout(SWT.VERTICAL));
 }
Esempio n. 5
0
 public static void enableWithChildren(Composite composite, boolean enable) {
   composite.setEnabled(enable);
   for (Control child : composite.getChildren()) {
     if (child instanceof Composite) {
       enableWithChildren((Composite) child, enable);
     } else {
       child.setEnabled(enable);
     }
   }
 }
Esempio n. 6
0
 public static Composite createPlaceholder(Composite parent, int columns, int spacing) {
   Composite ph = new Composite(parent, SWT.NONE);
   GridLayout gl = new GridLayout(columns, false);
   gl.verticalSpacing = spacing;
   gl.horizontalSpacing = spacing;
   gl.marginHeight = 0;
   gl.marginWidth = 0;
   ph.setLayout(gl);
   return ph;
 }
 public void createContents(Composite parent) {
   shell = parent.getShell();
   parent.setLayout(new FillLayout());
   folder = new TabFolder(shell, SWT.BORDER);
   labelTab();
   directoryDialogTab();
   buttonTab();
   sliderTab();
   scribbleTab();
   browserTab();
 }
Esempio n. 8
0
 public void createContents() {
   if (!contentCreated) {
     Control sashForm = createSashForm();
     item.setControl(sashForm);
     initColors();
     createExampleControls(exmplComp);
     createStyleControls(styleComp);
     exmplComp.layout();
     styleComp.layout();
     contentCreated = true;
   }
 }
Esempio n. 9
0
 private void updateFont() {
   Iterator iter = controls.iterator();
   while (iter.hasNext()) {
     Control control = (Control) iter.next();
     control.setFont(font);
   }
   // Force layout
   if (controls.size() > 0) {
     Composite parent = ((Control) controls.get(0)).getParent();
     parent.layout(true, true);
   }
 }
Esempio n. 10
0
  /** Creates a text that controls whether a border radius is set on the registered controls. */
  protected void cteateRoundedBorderGroup() {
    Group group = new Group(styleComp, SWT.NONE);
    group.setText("Rounded Border");
    group.setLayout(new GridLayout(2, false));
    new Label(group, SWT.NONE).setText("Width");
    final Text textWidth = new Text(group, SWT.SINGLE | SWT.BORDER);
    textWidth.setLayoutData(new GridData(20, SWT.DEFAULT));
    new Label(group, SWT.NONE).setText("Color");
    final Button buttonColor = new Button(group, SWT.PUSH);
    buttonColor.setLayoutData(new GridData(20, 20));
    buttonColor.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(final SelectionEvent event) {
            rbIndex = (rbIndex + 1) % bgColors.length;
            if (bgColors[rbIndex] == null) {
              buttonColor.setText("");
            } else {
              buttonColor.setText("\u2588");
            }
            buttonColor.setForeground(bgColors[rbIndex]);
          }
        });
    new Label(group, SWT.NONE).setText("Radius ");
    Composite radiusGroup = new Composite(group, SWT.NONE);
    radiusGroup.setLayout(new GridLayout(4, false));
    new Label(radiusGroup, SWT.NONE).setText("T-L");
    final Text textTopLeft = new Text(radiusGroup, SWT.SINGLE | SWT.BORDER);
    textTopLeft.setLayoutData(new GridData(20, SWT.DEFAULT));
    new Label(radiusGroup, SWT.NONE).setText("T-R");
    final Text textTopRight = new Text(radiusGroup, SWT.SINGLE | SWT.BORDER);
    textTopRight.setLayoutData(new GridData(20, SWT.DEFAULT));
    new Label(radiusGroup, SWT.NONE).setText("B-L");
    final Text textBottomLeft = new Text(radiusGroup, SWT.SINGLE | SWT.BORDER);
    textBottomLeft.setLayoutData(new GridData(20, SWT.DEFAULT));
    new Label(radiusGroup, SWT.NONE).setText("B-R");
    final Text textBottomRight = new Text(radiusGroup, SWT.SINGLE | SWT.BORDER);
    textBottomRight.setLayoutData(new GridData(20, SWT.DEFAULT));
    Button button = new Button(group, SWT.PUSH);
    button.setText("Set");
    button.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(final SelectionEvent e) {
            int width = parseInt(textWidth.getText());
            Color color = buttonColor.getBackground();
            int topLeft = parseInt(textTopLeft.getText());
            int topRight = parseInt(textTopRight.getText());
            int bottomRight = parseInt(textBottomRight.getText());
            int bottomLeft = parseInt(textBottomLeft.getText());
            updateRoundedBorder(width, color, topLeft, topRight, bottomRight, bottomLeft);
          }
        });
  }
Esempio n. 11
0
  @NotNull
  public static Text createOutputFolderChooser(
      final Composite parent, @Nullable String label, @Nullable ModifyListener changeListener) {
    UIUtils.createControlLabel(
        parent, label != null ? label : CoreMessages.data_transfer_wizard_output_label_directory);
    Composite chooserPlaceholder = UIUtils.createPlaceholder(parent, 2);
    chooserPlaceholder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    final Text directoryText = new Text(chooserPlaceholder, SWT.BORDER);
    directoryText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (changeListener != null) {
      directoryText.addModifyListener(changeListener);
    }

    final Runnable folderChooser =
        new Runnable() {
          @Override
          public void run() {
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.NONE);
            dialog.setMessage(CoreMessages.data_transfer_wizard_output_dialog_directory_message);
            dialog.setText(CoreMessages.data_transfer_wizard_output_dialog_directory_text);
            String directory = directoryText.getText();
            if (!CommonUtils.isEmpty(directory)) {
              dialog.setFilterPath(directory);
            }
            directory = dialog.open();
            if (directory != null) {
              directoryText.setText(directory);
            }
          }
        };
    directoryText.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseUp(MouseEvent e) {
            folderChooser.run();
          }
        });

    Button openFolder = new Button(chooserPlaceholder, SWT.PUSH | SWT.FLAT);
    openFolder.setImage(DBeaverIcons.getImage(DBIcon.TREE_FOLDER));
    openFolder.setLayoutData(
        new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.HORIZONTAL_ALIGN_CENTER));
    openFolder.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            folderChooser.run();
          }
        });
    return directoryText;
  }
  private int QueryContinueDrag(int fEscapePressed, int grfKeyState) {
    if (topControl != null && topControl.isDisposed()) return COM.DRAGDROP_S_CANCEL;
    if (fEscapePressed != 0) {
      if (hwndDrag != 0) OS.ImageList_DragLeave(hwndDrag);
      return COM.DRAGDROP_S_CANCEL;
    }
    /*
     * Bug in Windows.  On some machines that do not have XBUTTONs,
     * the MK_XBUTTON1 and OS.MK_XBUTTON2 bits are sometimes set,
     * causing mouse capture to become stuck.  The fix is to test
     * for the extra buttons only when they exist.
     */
    int mask = OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON;
    //	if (display.xMouse) mask |= OS.MK_XBUTTON1 | OS.MK_XBUTTON2;
    if ((grfKeyState & mask) == 0) {
      if (hwndDrag != 0) OS.ImageList_DragLeave(hwndDrag);
      return COM.DRAGDROP_S_DROP;
    }

    if (hwndDrag != 0) {
      POINT pt = new POINT();
      OS.GetCursorPos(pt);
      RECT rect = new RECT();
      OS.GetWindowRect(hwndDrag, rect);
      OS.ImageList_DragMove(pt.x - rect.left, pt.y - rect.top);
    }
    return COM.S_OK;
  }
 public static void sliderTab() {
   TabItem tab = new TabItem(folder, SWT.CLOSE);
   tab.setText("Sliders and Progress bars");
   tab.setToolTipText("Tied Slider to ProgressBar");
   Composite composite = new Composite(folder, SWT.NONE);
   composite.setLayout(new GridLayout(2, true));
   final Slider slider = new Slider(composite, SWT.HORIZONTAL);
   final ProgressBar progress = new ProgressBar(composite, SWT.HORIZONTAL);
   slider.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent event) {
           progress.setSelection(slider.getSelection());
         }
       });
   tab.setControl(composite);
 }
 public static void buttonTab() {
   TabItem tab = new TabItem(folder, SWT.CLOSE);
   tab.setText("Buttons");
   tab.setToolTipText("Different kinds of Buttons");
   Composite composite = new Composite(folder, SWT.NONE);
   composite.setLayout(new GridLayout(4, true));
   for (int dir : new int[] {SWT.UP, SWT.RIGHT, SWT.LEFT, SWT.DOWN}) {
     Button b = new Button(composite, SWT.ARROW | dir);
     b.addListener(SWT.MouseDown, listener);
   }
   newButton(composite, SWT.CHECK, "Check button");
   newButton(composite, SWT.PUSH, "Push button");
   newButton(composite, SWT.RADIO, "Radio button");
   newButton(composite, SWT.TOGGLE, "Toggle button");
   newButton(composite, SWT.FLAT, "Flat button");
   tab.setControl(composite);
 }
Esempio n. 15
0
 void setOrientation(boolean create) {
   super.setOrientation(create);
   if (items != null) {
     for (int i = 0; i < items.length; i++) {
       if (items[i] != null) items[i].setOrientation(create);
     }
   }
 }
Esempio n. 16
0
 void removeControl(Control control) {
   super.removeControl(control);
   int count = getItemCount();
   for (int i = 0; i < count; i++) {
     TabItem item = items[i];
     if (item.control == control) item.setControl(null);
   }
 }
Esempio n. 17
0
 public MainWindow(Composite parent, int style) {
   super(parent, style);
   initGUI();
   setPreferences();
   waitCursor = getDisplay().getSystemCursor(SWT.CURSOR_WAIT);
   defaultCursor = getDisplay().getSystemCursor(SWT.CURSOR_ARROW);
   clientArea.setFocus();
 }
Esempio n. 18
0
 @Override
 void setForegroundColor(GdkColor color) {
   super.setForegroundColor(color);
   ToolItem[] items = getItems();
   for (int i = 0; i < items.length; i++) {
     items[i].setForegroundColor(color);
   }
 }
Esempio n. 19
0
 @Override
 void setOrientation(boolean create) {
   super.setOrientation(create);
   ToolItem[] items = _getItems();
   for (int i = 0; i < items.length; i++) {
     items[i].setOrientation(create);
   }
 }
Esempio n. 20
0
 void setForegroundColor(GdkColor color) {
   super.setForegroundColor(color);
   TabItem[] items = getItems();
   for (int i = 0; i < items.length; i++) {
     if (items[i] != null) {
       items[i].setForegroundColor(color);
     }
   }
 }
Esempio n. 21
0
 void setFontDescription(long /*int*/ font) {
   super.setFontDescription(font);
   TabItem[] items = getItems();
   for (int i = 0; i < items.length; i++) {
     if (items[i] != null) {
       items[i].setFontDescription(font);
     }
   }
 }
Esempio n. 22
0
 @Override
 void setBackgroundColor(long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
   if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) {
     String css = "GtkToolbar {background-color: " + gtk_rgba_to_css_string(rgba) + "}";
     gtk_css_provider_load_from_css(context, css);
   } else {
     super.setBackgroundColor(context, handle, rgba);
   }
 }
Esempio n. 23
0
 @Override
 void setFontDescription(long /*int*/ font) {
   super.setFontDescription(font);
   ToolItem[] items = getItems();
   for (int i = 0; i < items.length; i++) {
     items[i].setFontDescription(font);
   }
   relayout();
 }
Esempio n. 24
0
 @Override
 void removeControl(Control control) {
   super.removeControl(control);
   ToolItem[] items = getItems();
   for (int i = 0; i < items.length; i++) {
     ToolItem item = items[i];
     if (item.control == control) item.setControl(null);
   }
 }
Esempio n. 25
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);
   }
 }
Esempio n. 26
0
 @Override
 void reskinChildren(int flags) {
   ToolItem[] items = _getItems();
   if (items != null) {
     for (int i = 0; i < items.length; i++) {
       ToolItem item = items[i];
       if (item != null) item.reskin(flags);
     }
   }
   super.reskinChildren(flags);
 }
Esempio n. 27
0
 @Override
 void releaseChildren(boolean destroy) {
   ToolItem[] items = getItems();
   for (int i = 0; i < items.length; i++) {
     ToolItem item = items[i];
     if (item != null && !item.isDisposed()) {
       item.release(false);
     }
   }
   super.releaseChildren(destroy);
 }
Esempio n. 28
0
 void releaseChildren(boolean destroy) {
   if (items != null) {
     for (int i = 0; i < items.length; i++) {
       TabItem item = items[i];
       if (item != null && !item.isDisposed()) {
         item.release(false);
       }
     }
     items = null;
   }
   super.releaseChildren(destroy);
 }
Esempio n. 29
0
 @Override
 void releaseChildren(boolean destroy) {
   if (caret != null) {
     caret.release(false);
     caret = null;
   }
   if (ime != null) {
     ime.release(false);
     ime = null;
   }
   super.releaseChildren(destroy);
 }
Esempio n. 30
0
  /**
   * Creates a combo that controls whether a cursor is set on the registered controls.
   *
   * @return the created combo
   */
  protected Combo createCursorCombo() {
    Composite group = new Composite(styleComp, SWT.NONE);
    group.setLayout(new GridLayout(2, false));
    new Label(group, SWT.NONE).setText("Cursor");
    final Combo combo = new Combo(group, SWT.READ_ONLY);
    combo.setItems(SWT_CURSORS);
    combo.select(0);
    combo.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(final SelectionEvent e) {
            String selection = null;
            int index = combo.getSelectionIndex();
            if (index > 0) {
              selection = combo.getItem(index);
            }
            updateCursor(selection);
          }
        });
    return combo;
  }