コード例 #1
0
  void createRTFTransfer(Composite copyParent, Composite pasteParent) {
    //	RTF Transfer
    Label l = new Label(copyParent, SWT.NONE);
    l.setText("RTFTransfer:"); // $NON-NLS-1$
    copyRtfText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    copyRtfText.setText("some\nrtf\ntext");
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    copyRtfText.setLayoutData(data);
    Button b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            String data = copyRtfText.getText();
            if (data.length() > 0) {
              status.setText("");
              data = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;}\\uc1\\b\\i " + data + "}";
              clipboard.setContents(
                  new Object[] {data}, new Transfer[] {RTFTransfer.getInstance()});
            } else {
              status.setText("nothing to copy");
            }
          }
        });

    l = new Label(pasteParent, SWT.NONE);
    l.setText("RTFTransfer:"); // $NON-NLS-1$
    pasteRtfText =
        new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    pasteRtfText.setLayoutData(data);
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            String data = (String) clipboard.getContents(RTFTransfer.getInstance());
            if (data != null && data.length() > 0) {
              status.setText("");
              pasteRtfText.setText("start paste>" + data + "<end paste");
            } else {
              status.setText("nothing to paste");
            }
          }
        });
  }
コード例 #2
0
  /** Experimental. Switching themes at runtime does not yet work properly. */
  protected void createThemeSwitcher(final Composite parent) {
    final Button button = new Button(parent, SWT.PUSH);
    button.setText("Theme Switcher");
    button.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(final SelectionEvent e) {
            Shell shell = new Shell(parent.getShell(), SWT.DIALOG_TRIM);
            shell.setText("Theme Switcher");
            shell.setLayout(new GridLayout());
            Button themeButton = new Button(shell, SWT.PUSH);
            themeButton.setText("Switch Theme");
            themeButton.addSelectionListener(
                new SelectionAdapter() {
                  String[] availableThemeIds = ThemeUtil.getAvailableThemeIds();

                  public void widgetSelected(final SelectionEvent e) {
                    int index = 0;
                    String currThemeId = ThemeUtil.getCurrentThemeId();
                    for (int i = 0; i < availableThemeIds.length; i++) {
                      if (currThemeId.equals(availableThemeIds[i])) {
                        index = (i + 1) % availableThemeIds.length;
                      }
                    }
                    String newThemeId = availableThemeIds[index];
                    ThemeUtil.setCurrentThemeId(newThemeId);
                  }
                });
            shell.pack();
            shell.open();
          }
        });
  }
コード例 #3
0
  void createHTMLTransfer(Composite copyParent, Composite pasteParent) {
    //	HTML Transfer
    Label l = new Label(copyParent, SWT.NONE);
    l.setText("HTMLTransfer:"); // $NON-NLS-1$
    copyHtmlText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    copyHtmlText.setText("<b>Hello World</b>");
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    copyHtmlText.setLayoutData(data);
    Button b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            String data = copyHtmlText.getText();
            if (data.length() > 0) {
              status.setText("");
              clipboard.setContents(
                  new Object[] {data}, new Transfer[] {HTMLTransfer.getInstance()});
            } else {
              status.setText("nothing to copy");
            }
          }
        });

    l = new Label(pasteParent, SWT.NONE);
    l.setText("HTMLTransfer:"); // $NON-NLS-1$
    pasteHtmlText =
        new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    pasteHtmlText.setLayoutData(data);
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            String data = (String) clipboard.getContents(HTMLTransfer.getInstance());
            if (data != null && data.length() > 0) {
              status.setText("");
              pasteHtmlText.setText("start paste>" + data + "<end paste");
            } else {
              status.setText("nothing to paste");
            }
          }
        });
  }
コード例 #4
0
ファイル: CanvasTab.java プロジェクト: abego/java2script
  /** Creates the "Other" group. */
  void createOtherGroup() {
    super.createOtherGroup();

    /* Create display controls specific to this example */
    caretButton = new Button(otherGroup, SWT.CHECK);
    caretButton.setText(ControlExample.getResourceString("Caret"));
    fillDamageButton = new Button(otherGroup, SWT.CHECK);
    fillDamageButton.setText(ControlExample.getResourceString("FillDamage"));

    /* Add the listeners */
    caretButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
            setCaret();
          }
        });
  }
コード例 #5
0
ファイル: UIUtils.java プロジェクト: ralic/dbeaver
  public static Button createCheckbox(Composite parent, String label, boolean checked) {
    final Button button = new Button(parent, SWT.CHECK);
    button.setText(label);
    if (checked) {
      button.setSelection(true);
    }

    return button;
  }
コード例 #6
0
ファイル: UIUtils.java プロジェクト: ralic/dbeaver
 public static Button createToolButton(
     Composite parent, String text, SelectionListener selectionListener) {
   Button button = new Button(parent, SWT.PUSH);
   button.setText(text);
   button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
   if (selectionListener != null) {
     button.addSelectionListener(selectionListener);
   }
   return button;
 }
コード例 #7
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);
          }
        });
  }
コード例 #8
0
 /**
  * Creates a checkbox that controls whether a background image is set on the registered controls.
  *
  * @return the created checkbox
  */
 protected Button createBgImageButton() {
   final Button button = new Button(styleComp, SWT.CHECK);
   button.setText("Background Image");
   button.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(final SelectionEvent event) {
           showBgImage = button.getSelection();
           updateBgImage();
         }
       });
   return button;
 }
コード例 #9
0
ファイル: UIUtils.java プロジェクト: ralic/dbeaver
 @NotNull
 public static Button createPushButton(
     @NotNull Composite parent, @Nullable String label, @Nullable Image image) {
   Button button = new Button(parent, SWT.PUSH);
   if (label != null) {
     button.setText(label);
   }
   if (image != null) {
     button.setImage(image);
   }
   return button;
 }
コード例 #10
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();
  }
コード例 #11
0
 /**
  * Creates a checkbutton to enable / disabled the registered controls.
  *
  * @return the created checkbutton.
  */
 protected Button createEnablementButton() {
   final Button button = new Button(styleComp, SWT.CHECK);
   button.setText("Enabled");
   button.setSelection(enabled);
   button.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(final SelectionEvent event) {
           enabled = button.getSelection();
           updateEnabled();
         }
       });
   return button;
 }
コード例 #12
0
 /**
  * Creates a checkbutton to show / hide the registered controls.
  *
  * @return the created checkbutton
  */
 protected Button createVisibilityButton() {
   final Button button = new Button(styleComp, SWT.CHECK);
   button.setText("Visible");
   button.setSelection(visible);
   button.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(final SelectionEvent event) {
           visible = button.getSelection();
           updateVisible();
         }
       });
   return button;
 }
コード例 #13
0
 protected Button createStyleButton(final String name, final int style, final boolean checked) {
   Button button = new Button(styleComp, SWT.CHECK);
   button.setText(name);
   button.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(final SelectionEvent event) {
           createNew();
         }
       });
   button.setData("style", new Integer(style));
   button.setSelection(checked);
   return button;
 }
コード例 #14
0
 /**
  * Creates a button to change the background color of all registered controls.
  *
  * @return the created button
  */
 protected Button createBgColorButton() {
   bgColorChooser = new ColorChooser();
   final Button button = new Button(styleComp, SWT.PUSH);
   button.setText("Background");
   button.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(final SelectionEvent event) {
           bgIndex = (bgIndex + 1) % fgColors.length;
           updateBgColor();
         }
       });
   return button;
 }
コード例 #15
0
 public static void directoryDialogTab() {
   TabItem tab = new TabItem(folder, SWT.CLOSE);
   tab.setText("Directory Dialog");
   tab.setToolTipText("Select a directory");
   final Button b = new Button(folder, SWT.PUSH);
   b.setText("Select a Directory");
   b.addListener(
       SWT.MouseDown,
       new Listener() {
         public void handleEvent(Event e) {
           DirectoryDialog dd = new DirectoryDialog(shell);
           String path = dd.open();
           if (path != null) b.setText(path);
         }
       });
   tab.setControl(b);
 }
コード例 #16
0
 protected Button createPropertyCheckbox(
     final String text, final String prop, final boolean checked) {
   final Button button = new Button(styleComp, SWT.CHECK);
   button.setText(text);
   button.setSelection(checked);
   button.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(final SelectionEvent e) {
           if (button.getSelection()) {
             properties.add(prop);
           } else {
             properties.remove(prop);
           }
           createNew();
         }
       });
   return button;
 }
コード例 #17
0
 void createAvailableTypes(Composite parent) {
   final List list = new List(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
   GridData data = new GridData(GridData.FILL_BOTH);
   data.heightHint = 100;
   list.setLayoutData(data);
   Button b = new Button(parent, SWT.PUSH);
   b.setText("Get Available Types");
   b.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           list.removeAll();
           String[] names = clipboard.getAvailableTypeNames();
           for (int i = 0; i < names.length; i++) {
             list.add(names[i]);
           }
         }
       });
 }
コード例 #18
0
  public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Widget");

    final Table table = new Table(shell, SWT.MULTI);
    table.setLinesVisible(true);
    table.setBounds(10, 10, 100, 100);
    for (int i = 0; i < 9; i++) {
      new TableItem(table, SWT.NONE).setText("item" + i);
    }

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Capture");
    button.pack();
    button.setLocation(10, 140);
    button.addListener(
        SWT.Selection,
        event -> {
          Point tableSize = table.getSize();
          GC gc = new GC(table);
          final Image image = new Image(display, tableSize.x, tableSize.y);
          gc.copyArea(image, 0, 0);
          gc.dispose();

          Shell popup = new Shell(shell);
          popup.setText("Image");
          popup.addListener(SWT.Close, e -> image.dispose());

          Canvas canvas = new Canvas(popup, SWT.NONE);
          canvas.setBounds(10, 10, tableSize.x + 10, tableSize.y + 10);
          canvas.addPaintListener(e -> e.gc.drawImage(image, 0, 0));
          popup.pack();
          popup.open();
        });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
コード例 #19
0
 protected Button createFontChooser() {
   final Button button = new Button(styleComp, SWT.PUSH);
   button.setText("Font");
   button.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(final SelectionEvent event) {
           fontChooser = new SimpleFontDialog(getShell());
           Control control = (Control) controls.get(0);
           fontChooser.setFont(control.getFont());
           fontChooser.open(
               new Runnable() {
                 public void run() {
                   font = fontChooser.getFont();
                   updateFont();
                 }
               });
         }
       });
   return button;
 }
コード例 #20
0
ファイル: CanvasTab.java プロジェクト: abego/java2script
  /** Creates the "Style" group. */
  void createStyleGroup() {
    super.createStyleGroup();

    /* Create the extra widgets */
    horizontalButton = new Button(styleGroup, SWT.CHECK);
    horizontalButton.setText("SWT.H_SCROLL");
    horizontalButton.setSelection(true);
    verticalButton = new Button(styleGroup, SWT.CHECK);
    verticalButton.setText("SWT.V_SCROLL");
    verticalButton.setSelection(true);
    borderButton = new Button(styleGroup, SWT.CHECK);
    borderButton.setText("SWT.BORDER");
    noBackgroundButton = new Button(styleGroup, SWT.CHECK);
    noBackgroundButton.setText("SWT.NO_BACKGROUND");
    noFocusButton = new Button(styleGroup, SWT.CHECK);
    noFocusButton.setText("SWT.NO_FOCUS");
    noMergePaintsButton = new Button(styleGroup, SWT.CHECK);
    noMergePaintsButton.setText("SWT.NO_MERGE_PAINTS");
    noRedrawResizeButton = new Button(styleGroup, SWT.CHECK);
    noRedrawResizeButton.setText("SWT.NO_REDRAW_RESIZE");
  }
コード例 #21
0
 private static void newButton(Composite composite, int type, String label) {
   Button b = new Button(composite, type);
   b.setText(label);
   b.addListener(SWT.MouseDown, listener);
 }
コード例 #22
0
 protected Button createPropertyButton(final String text, final int style) {
   Button button = new Button(styleComp, style);
   button.setText(text);
   return button;
 }
コード例 #23
0
  public static void main(String[] args) {
    final Display display = new Display();
    // Shell must be created with style SWT.NO_TRIM
    final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);
    shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
    // define a region that looks like a key hole
    Region region = new Region();
    region.add(circle(67, 67, 67));
    region.subtract(circle(20, 67, 50));
    region.subtract(new int[] {67, 50, 55, 105, 79, 105});
    // define the shape of the shell using setRegion
    shell.setRegion(region);
    Rectangle size = region.getBounds();
    shell.setSize(size.width, size.height);
    // add ability to move shell around
    Listener l =
        new Listener() {
          /** The x/y of the MouseDown, relative to top-left of the shell. */
          Point origin;

          @Override
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.MouseDown:
                Point point = shell.toDisplay(e.x, e.y);
                Point loc = shell.getLocation();
                origin = new Point(point.x - loc.x, point.y - loc.y);
                break;
              case SWT.MouseUp:
                origin = null;
                break;
              case SWT.MouseMove:
                if (origin != null) {
                  Point p = display.map(shell, null, e.x, e.y);
                  shell.setLocation(p.x - origin.x, p.y - origin.y);
                }
                break;
            }
          }
        };
    shell.addListener(SWT.MouseDown, l);
    shell.addListener(SWT.MouseUp, l);
    shell.addListener(SWT.MouseMove, l);
    // add ability to close shell
    Button b = new Button(shell, SWT.PUSH);
    b.setBackground(shell.getBackground());
    b.setText("close");
    b.pack();
    b.setLocation(10, 68);
    b.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event e) {
            shell.close();
          }
        });
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    region.dispose();
    display.dispose();
  }
コード例 #24
0
  public static void main(String[] args) {
    Shell shell = new Shell();
    Display display = shell.getDisplay();
    shell.setLayout(new FillLayout());
    shell.setText("ExpandBar Example");

    Menu menubar = new Menu(shell, SWT.BAR);
    shell.setMenuBar(menubar);
    MenuItem fileItem = new MenuItem(menubar, SWT.CASCADE);
    fileItem.setText("&File");
    Menu submenu = new Menu(shell, SWT.DROP_DOWN);
    fileItem.setMenu(submenu);
    item = new MenuItem(submenu, SWT.PUSH);
    item.setText("New ExpandItem");

    bar = new ExpandBar(shell, SWT.V_SCROLL);
    image = display.getSystemImage(SWT.ICON_QUESTION);

    // First item
    Composite composite = new Composite(bar, SWT.NONE);
    Menu popupmenu = new Menu(shell, SWT.POP_UP);
    MenuItem popupItem = new MenuItem(popupmenu, SWT.PUSH);
    popupItem.setText("Popup");
    composite.setMenu(popupmenu);

    GridLayout layout = new GridLayout(2, false);
    layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
    layout.verticalSpacing = 10;
    composite.setLayout(layout);
    Label label = new Label(composite, SWT.NONE);
    label.setImage(display.getSystemImage(SWT.ICON_ERROR));
    label = new Label(composite, SWT.NONE);
    label.setText("SWT.ICON_ERROR");
    label = new Label(composite, SWT.NONE);
    label.setImage(display.getSystemImage(SWT.ICON_INFORMATION));
    label = new Label(composite, SWT.NONE);
    label.setText("SWT.ICON_INFORMATION");
    label = new Label(composite, SWT.NONE);
    label.setImage(display.getSystemImage(SWT.ICON_WARNING));
    label = new Label(composite, SWT.NONE);
    label.setText("SWT.ICON_WARNING");
    label = new Label(composite, SWT.NONE);
    label.setImage(display.getSystemImage(SWT.ICON_QUESTION));
    label = new Label(composite, SWT.NONE);
    label.setText("SWT.ICON_QUESTION");
    ExpandItem item1 = new ExpandItem(bar, SWT.NONE);
    item1.setText("What is your favorite icon");
    item1.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    item1.setControl(composite);
    item1.setImage(image);

    // Second item
    composite = new Composite(bar, SWT.NONE);
    layout = new GridLayout(2, true);
    layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
    layout.verticalSpacing = 10;
    composite.setLayout(layout);
    Button button1 = new Button(composite, SWT.PUSH);
    button1.setText("Button 1");
    Button button2 = new Button(composite, SWT.PUSH);
    button2.setText("Button 2");

    ExpandItem item0 = new ExpandItem(bar, SWT.NONE);
    item0.setText("What is your favorite button");
    item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    item0.setControl(composite);
    item0.setImage(image);
    item0.setExpanded(false);

    item.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event e) {
            ExpandItem item2 = new ExpandItem(bar, SWT.NONE);
            Composite composite = new Composite(bar, SWT.NONE);
            GridLayout layout = new GridLayout(2, false);
            composite.setLayout(layout);
            Label label = new Label(composite, SWT.NONE);
            label.setText("What is your name?");
            Composite pcomposite = new Composite(composite, SWT.NONE);
            Text text = new Text(pcomposite, SWT.NONE);
            item2.setText("New Question");
            text.pack();
            composite.pack();
            Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            item2.setHeight(size.y);
            item2.setControl(composite);
            item2.setImage(image);
            item2.setExpanded(true);
          }
        });

    bar.setSpacing(8);
    shell.setSize(400, 550);
    shell.open();
    System.out.println("------------------------------");
    System.out.println("getSize: " + button1.getSize());
    System.out.println("getBounds: " + button1.getBounds());
    System.out.println("computeSize: " + button1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    System.out.println("getLocation: " + button1.getLocation());

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    image.dispose();
    display.dispose();
  }
コード例 #25
0
  void createControlTransfer(Composite parent) {
    Label l = new Label(parent, SWT.NONE);
    l.setText("Text:");
    Button b = new Button(parent, SWT.PUSH);
    b.setText("Cut");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            text.cut();
          }
        });
    b = new Button(parent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            text.copy();
          }
        });
    b = new Button(parent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            text.paste();
          }
        });
    text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    text.setLayoutData(data);

    l = new Label(parent, SWT.NONE);
    l.setText("Combo:");
    b = new Button(parent, SWT.PUSH);
    b.setText("Cut");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            combo.cut();
          }
        });
    b = new Button(parent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            combo.copy();
          }
        });
    b = new Button(parent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            combo.paste();
          }
        });
    combo = new Combo(parent, SWT.NONE);
    combo.setItems(new String[] {"Item 1", "Item 2", "Item 3", "A longer Item"});

    l = new Label(parent, SWT.NONE);
    l.setText("StyledText:");
    l = new Label(parent, SWT.NONE);
    l.setVisible(false);
    b = new Button(parent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            styledText.copy();
          }
        });
    b = new Button(parent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            styledText.paste();
          }
        });
    styledText = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    styledText.setLayoutData(data);
  }
コード例 #26
0
  void createFileTransfer(Composite copyParent, Composite pasteParent) {
    // File Transfer
    Label l = new Label(copyParent, SWT.NONE);
    l.setText("FileTransfer:"); // $NON-NLS-1$

    Composite c = new Composite(copyParent, SWT.NONE);
    c.setLayout(new GridLayout(2, false));
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    c.setLayoutData(data);

    copyFileTable = new Table(c, SWT.MULTI | SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    data.horizontalSpan = 2;
    copyFileTable.setLayoutData(data);

    Button b = new Button(c, SWT.PUSH);
    b.setText("Select file(s)");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
            String result = dialog.open();
            if (result != null && result.length() > 0) {
              // copyFileTable.removeAll();
              String separator = System.getProperty("file.separator");
              String path = dialog.getFilterPath();
              String[] names = dialog.getFileNames();
              for (int i = 0; i < names.length; i++) {
                TableItem item = new TableItem(copyFileTable, SWT.NONE);
                item.setText(path + separator + names[i]);
              }
            }
          }
        });
    b = new Button(c, SWT.PUSH);
    b.setText("Select directory");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN);
            String result = dialog.open();
            if (result != null && result.length() > 0) {
              // copyFileTable.removeAll();
              TableItem item = new TableItem(copyFileTable, SWT.NONE);
              item.setText(result);
            }
          }
        });

    b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            TableItem[] items = copyFileTable.getItems();
            if (items.length > 0) {
              status.setText("");
              String[] data = new String[items.length];
              for (int i = 0; i < data.length; i++) {
                data[i] = items[i].getText();
              }
              clipboard.setContents(
                  new Object[] {data}, new Transfer[] {FileTransfer.getInstance()});
            } else {
              status.setText("nothing to copy");
            }
          }
        });

    l = new Label(pasteParent, SWT.NONE);
    l.setText("FileTransfer:"); // $NON-NLS-1$
    pasteFileTable = new Table(pasteParent, SWT.MULTI | SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    pasteFileTable.setLayoutData(data);
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            String[] data = (String[]) clipboard.getContents(FileTransfer.getInstance());
            if (data != null && data.length > 0) {
              status.setText("");
              pasteFileTable.removeAll();
              for (int i = 0; i < data.length; i++) {
                TableItem item = new TableItem(pasteFileTable, SWT.NONE);
                item.setText(data[i]);
              }
            } else {
              status.setText("nothing to paste");
            }
          }
        });
  }
コード例 #27
0
ファイル: DialogTab.java プロジェクト: andreyvit/yoursway-swt
  /** Creates the "Control" widget children. */
  void createControlWidgets() {

    /* Create the combo */
    String[] strings = {
      ControlExample.getResourceString("ColorDialog"),
      ControlExample.getResourceString("DirectoryDialog"),
      ControlExample.getResourceString("FileDialog"),
      ControlExample.getResourceString("FontDialog"),
      ControlExample.getResourceString("PrintDialog"),
      ControlExample.getResourceString("MessageBox"),
    };
    dialogCombo = new Combo(dialogStyleGroup, SWT.READ_ONLY);
    dialogCombo.setItems(strings);
    dialogCombo.setText(strings[0]);
    dialogCombo.setVisibleItemCount(strings.length);

    /* Create the create dialog button */
    createButton = new Button(dialogStyleGroup, SWT.NONE);
    createButton.setText(ControlExample.getResourceString("Create_Dialog"));
    createButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));

    /* Create a group for the various dialog button style controls */
    Group buttonStyleGroup = new Group(controlGroup, SWT.NONE);
    buttonStyleGroup.setLayout(new GridLayout());
    buttonStyleGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    buttonStyleGroup.setText(ControlExample.getResourceString("Button_Styles"));

    /* Create the button style buttons */
    okButton = new Button(buttonStyleGroup, SWT.CHECK);
    okButton.setText("SWT.OK");
    cancelButton = new Button(buttonStyleGroup, SWT.CHECK);
    cancelButton.setText("SWT.CANCEL");
    yesButton = new Button(buttonStyleGroup, SWT.CHECK);
    yesButton.setText("SWT.YES");
    noButton = new Button(buttonStyleGroup, SWT.CHECK);
    noButton.setText("SWT.NO");
    retryButton = new Button(buttonStyleGroup, SWT.CHECK);
    retryButton.setText("SWT.RETRY");
    abortButton = new Button(buttonStyleGroup, SWT.CHECK);
    abortButton.setText("SWT.ABORT");
    ignoreButton = new Button(buttonStyleGroup, SWT.CHECK);
    ignoreButton.setText("SWT.IGNORE");

    /* Create a group for the icon style controls */
    Group iconStyleGroup = new Group(controlGroup, SWT.NONE);
    iconStyleGroup.setLayout(new GridLayout());
    iconStyleGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    iconStyleGroup.setText(ControlExample.getResourceString("Icon_Styles"));

    /* Create the icon style buttons */
    iconErrorButton = new Button(iconStyleGroup, SWT.RADIO);
    iconErrorButton.setText("SWT.ICON_ERROR");
    iconInformationButton = new Button(iconStyleGroup, SWT.RADIO);
    iconInformationButton.setText("SWT.ICON_INFORMATION");
    iconQuestionButton = new Button(iconStyleGroup, SWT.RADIO);
    iconQuestionButton.setText("SWT.ICON_QUESTION");
    iconWarningButton = new Button(iconStyleGroup, SWT.RADIO);
    iconWarningButton.setText("SWT.ICON_WARNING");
    iconWorkingButton = new Button(iconStyleGroup, SWT.RADIO);
    iconWorkingButton.setText("SWT.ICON_WORKING");
    noIconButton = new Button(iconStyleGroup, SWT.RADIO);
    noIconButton.setText(ControlExample.getResourceString("No_Icon"));

    /* Create a group for the modal style controls */
    Group modalStyleGroup = new Group(controlGroup, SWT.NONE);
    modalStyleGroup.setLayout(new GridLayout());
    modalStyleGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    modalStyleGroup.setText(ControlExample.getResourceString("Modal_Styles"));

    /* Create the modal style buttons */
    primaryModalButton = new Button(modalStyleGroup, SWT.RADIO);
    primaryModalButton.setText("SWT.PRIMARY_MODAL");
    applicationModalButton = new Button(modalStyleGroup, SWT.RADIO);
    applicationModalButton.setText("SWT.APPLICATION_MODAL");
    systemModalButton = new Button(modalStyleGroup, SWT.RADIO);
    systemModalButton.setText("SWT.SYSTEM_MODAL");

    /* Create a group for the file dialog style controls */
    Group fileDialogStyleGroup = new Group(controlGroup, SWT.NONE);
    fileDialogStyleGroup.setLayout(new GridLayout());
    fileDialogStyleGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    fileDialogStyleGroup.setText(ControlExample.getResourceString("File_Dialog_Styles"));

    /* Create the file dialog style buttons */
    openButton = new Button(fileDialogStyleGroup, SWT.RADIO);
    openButton.setText("SWT.OPEN");
    saveButton = new Button(fileDialogStyleGroup, SWT.RADIO);
    saveButton.setText("SWT.SAVE");
    multiButton = new Button(fileDialogStyleGroup, SWT.CHECK);
    multiButton.setText("SWT.MULTI");

    /* Create the orientation group */
    if (RTL_SUPPORT_ENABLE) {
      createOrientationGroup();
    }

    /* Add the listeners */
    dialogCombo.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
            dialogSelected(event);
          }
        });
    createButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
            createButtonSelected(event);
          }
        });
    SelectionListener buttonStyleListener =
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
            buttonStyleSelected(event);
          }
        };
    okButton.addSelectionListener(buttonStyleListener);
    cancelButton.addSelectionListener(buttonStyleListener);
    yesButton.addSelectionListener(buttonStyleListener);
    noButton.addSelectionListener(buttonStyleListener);
    retryButton.addSelectionListener(buttonStyleListener);
    abortButton.addSelectionListener(buttonStyleListener);
    ignoreButton.addSelectionListener(buttonStyleListener);

    /* Set default values for style buttons */
    okButton.setEnabled(false);
    cancelButton.setEnabled(false);
    yesButton.setEnabled(false);
    noButton.setEnabled(false);
    retryButton.setEnabled(false);
    abortButton.setEnabled(false);
    ignoreButton.setEnabled(false);
    iconErrorButton.setEnabled(false);
    iconInformationButton.setEnabled(false);
    iconQuestionButton.setEnabled(false);
    iconWarningButton.setEnabled(false);
    iconWorkingButton.setEnabled(false);
    noIconButton.setEnabled(false);
    saveButton.setEnabled(false);
    openButton.setEnabled(false);
    openButton.setSelection(true);
    multiButton.setEnabled(false);
    noIconButton.setSelection(true);
  }
コード例 #28
0
  public static void main(String[] args) {
    final Display display = new Display();
    final Clipboard clipboard = new Clipboard(display);
    final Shell shell = new Shell(display, SWT.SHELL_TRIM);
    shell.setLayout(new GridLayout());
    shell.setText("Clipboard ImageTransfer");

    final Button imageButton = new Button(shell, SWT.NONE);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.minimumHeight = 400;
    gd.minimumWidth = 600;
    imageButton.setLayoutData(gd);

    final Text imageText = new Text(shell, SWT.BORDER);
    imageText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    Composite buttons = new Composite(shell, SWT.NONE);
    buttons.setLayout(new GridLayout(4, true));
    Button button = new Button(buttons, SWT.PUSH);
    button.setText("Open");
    button.addListener(
        SWT.Selection,
        event -> {
          FileDialog dialog = new FileDialog(shell, SWT.OPEN);
          dialog.setText("Open an image file or cancel");
          String string = dialog.open();
          if (string != null) {
            imageButton.setText("");
            Image image = imageButton.getImage();
            if (image != null) image.dispose();
            image = new Image(display, string);
            imageButton.setImage(image);
            imageText.setText(string);
          }
        });

    button = new Button(buttons, SWT.PUSH);
    button.setText("Copy");
    button.addListener(
        SWT.Selection,
        event -> {
          Image image = imageButton.getImage();
          if (image != null) {
            ImageTransfer imageTransfer = ImageTransfer.getInstance();
            TextTransfer textTransfer = TextTransfer.getInstance();
            clipboard.setContents(
                new Object[] {image.getImageData(), imageText.getText()},
                new Transfer[] {imageTransfer, textTransfer});
          }
        });

    button = new Button(buttons, SWT.PUSH);
    button.setText("Paste");
    button.addListener(
        SWT.Selection,
        event -> {
          ImageData imageData = (ImageData) clipboard.getContents(ImageTransfer.getInstance());
          if (imageData != null) {
            imageButton.setText("");
            Image image = imageButton.getImage();
            if (image != null) image.dispose();
            image = new Image(display, imageData);
            imageButton.setImage(image);
          } else {
            imageButton.setText("No image");
            imageButton.setImage(null);
          }
          String text = (String) clipboard.getContents(TextTransfer.getInstance());
          if (text != null) {
            imageText.setText(text);
          } else {
            imageText.setText("");
          }
        });

    button = new Button(buttons, SWT.PUSH);
    button.setText("Clear");
    button.addListener(
        SWT.Selection,
        event -> {
          imageButton.setText("");
          Image image = imageButton.getImage();
          if (image != null) image.dispose();
          imageButton.setImage(null);
          imageText.setText("");
        });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }