コード例 #1
0
 private void testPreserveControlProperties(Scale scale) {
   // bound
   Rectangle rectangle = new Rectangle(10, 10, 10, 10);
   scale.setBounds(rectangle);
   Fixture.preserveWidgets();
   IWidgetAdapter adapter = WidgetUtil.getAdapter(scale);
   assertEquals(rectangle, adapter.getPreserved(Props.BOUNDS));
   Fixture.clearPreserved();
   // enabled
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(Boolean.TRUE, adapter.getPreserved(Props.ENABLED));
   Fixture.clearPreserved();
   scale.setEnabled(false);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(Boolean.FALSE, adapter.getPreserved(Props.ENABLED));
   Fixture.clearPreserved();
   scale.setEnabled(true);
   // visible
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(Boolean.TRUE, adapter.getPreserved(Props.VISIBLE));
   Fixture.clearPreserved();
   scale.setVisible(false);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(Boolean.FALSE, adapter.getPreserved(Props.VISIBLE));
   Fixture.clearPreserved();
   // menu
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(null, adapter.getPreserved(Props.MENU));
   Fixture.clearPreserved();
   Menu menu = new Menu(scale);
   MenuItem item = new MenuItem(menu, SWT.NONE);
   item.setText("1 Item");
   scale.setMenu(menu);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(menu, adapter.getPreserved(Props.MENU));
   Fixture.clearPreserved();
   // foreground background font
   Color background = Graphics.getColor(122, 33, 203);
   scale.setBackground(background);
   Color foreground = Graphics.getColor(211, 178, 211);
   scale.setForeground(foreground);
   Font font = Graphics.getFont("font", 12, SWT.BOLD);
   scale.setFont(font);
   Fixture.preserveWidgets();
   adapter = WidgetUtil.getAdapter(scale);
   assertEquals(background, adapter.getPreserved(Props.BACKGROUND));
   assertEquals(foreground, adapter.getPreserved(Props.FOREGROUND));
   assertEquals(font, adapter.getPreserved(Props.FONT));
   Fixture.clearPreserved();
 }
コード例 #2
0
 void releaseChildren_pp(boolean destroy) {
   MenuItem[] items = getItems();
   for (int i = 0; i < items.length; i++) {
     MenuItem item = items[i];
     if (item != null && !item.isDisposed()) {
       item.release(false);
     }
   }
   super.releaseChildren_pp(destroy);
 }
コード例 #3
0
  /**
   * Creates all the items located in the Search submenu and associate all the menu items with their
   * appropriate functions.
   *
   * @param menuBar Menu the <code>Menu</code> that file contain the Search submenu.
   */
  private void createSearchMenu(Menu menuBar) {
    // Search menu.
    MenuItem item = new MenuItem(menuBar, SWT.CASCADE);
    item.setText(resMessages.getString("Search_menu_title"));
    Menu searchMenu = new Menu(shell, SWT.DROP_DOWN);
    item.setMenu(searchMenu);

    // Search -> Find...
    item = new MenuItem(searchMenu, SWT.NULL);
    item.setText(resMessages.getString("Find"));
    item.setAccelerator(SWT.MOD1 + 'F');
    item.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            searchDialog.setMatchCase(false);
            searchDialog.setMatchWord(false);
            searchDialog.setSearchDown(true);
            searchDialog.setSearchString("");
            searchDialog.setSelectedSearchArea(0);
            searchDialog.open();
          }
        });

    // Search -> Find Next
    item = new MenuItem(searchMenu, SWT.NULL);
    item.setText(resMessages.getString("Find_next"));
    item.setAccelerator(SWT.F3);
    item.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            searchDialog.open();
          }
        });
  }
コード例 #4
0
 void releaseParent_pp() {
   super.releaseParent_pp();
   if (cascade != null) cascade.setMenu(null);
   if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
     parent.setMenuBar(null);
   }
 }
コード例 #5
0
  /**
   * Creates all the items located in the Sort cascading submenu and associate all the menu items
   * with their appropriate functions.
   *
   * @return Menu The cascading menu with all the sort menu items on it.
   */
  private Menu createSortMenu() {
    Menu submenu = new Menu(shell, SWT.DROP_DOWN);
    MenuItem subitem;
    for (int i = 0; i < columnNames.length; i++) {
      subitem = new MenuItem(submenu, SWT.NULL);
      subitem.setText(columnNames[i]);
      final int column = i;
      subitem.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
              sort(column);
            }
          });
    }

    return submenu;
  }
コード例 #6
0
 /**
  * Sets the default menu item to the argument or removes the default emphasis when the argument is
  * <code>null</code>.
  *
  * @param item the default menu item or null
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the menu item has been disposed
  *     </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 setDefaultItem(MenuItem item) {
   checkWidget();
   if (item != null) {
     if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
     if (item.parent != this) return;
     OS.QMenu_setDefaultAction(handle, item.handle);
   } else {
     OS.QMenu_setDefaultAction(handle, 0);
   }
 }
コード例 #7
0
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   final Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
   Rectangle clientArea = shell.getClientArea();
   table.setBounds(clientArea.x, clientArea.y, 200, 200);
   for (int i = 0; i < 128; i++) {
     TableItem item = new TableItem(table, SWT.NONE);
     item.setText("Item " + i);
   }
   Menu menu = new Menu(shell, SWT.POP_UP);
   table.setMenu(menu);
   MenuItem item = new MenuItem(menu, SWT.PUSH);
   item.setText("Delete Selection");
   item.addListener(SWT.Selection, event -> table.remove(table.getSelectionIndices()));
   shell.pack();
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
コード例 #8
0
  /**
   * Creates all the items located in the Help submenu and associate all the menu items with their
   * appropriate functions.
   *
   * @param menuBar Menu the <code>Menu</code> that file contain the Help submenu.
   */
  private void createHelpMenu(Menu menuBar) {

    // Help Menu
    MenuItem item = new MenuItem(menuBar, SWT.CASCADE);
    item.setText(resMessages.getString("Help_menu_title"));
    Menu menu = new Menu(shell, SWT.DROP_DOWN);
    item.setMenu(menu);

    // Help -> About Text Editor
    MenuItem subItem = new MenuItem(menu, SWT.NULL);
    subItem.setText(resMessages.getString("About"));
    subItem.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            MessageBox box = new MessageBox(shell, SWT.NONE);
            box.setText(resMessages.getString("About_1") + shell.getText());
            box.setMessage(shell.getText() + resMessages.getString("About_2"));
            box.open();
          }
        });
  }
コード例 #9
0
ファイル: View.java プロジェクト: shader/gdr
  /** Initialize the drop-down menus in the appropriate area of the window */
  public void initMenu() {
    Menu menuBar = new Menu(shell, SWT.BAR);
    MenuItem cascadeFileMenu = new MenuItem(menuBar, SWT.CASCADE);
    cascadeFileMenu.setText("&File");
    MenuItem cascadeAnimMenu = new MenuItem(menuBar, SWT.CASCADE);
    cascadeAnimMenu.setText("&Animation");

    // file menu
    Menu fileMenu = new Menu(shell, SWT.DROP_DOWN);
    cascadeFileMenu.setMenu(fileMenu);

    MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
    exitItem.setText("&Exit");

    MenuItem openGraphItem = new MenuItem(fileMenu, SWT.PUSH);
    openGraphItem.setText("Open &Graph");

    MenuItem openAnimationItem = new MenuItem(fileMenu, SWT.PUSH);
    openAnimationItem.setText("Open &Animation");

    // temporary animation menu
    Menu animMenu = new Menu(shell, SWT.DROP_DOWN);
    cascadeAnimMenu.setMenu(animMenu);

    MenuItem DFSItem = new MenuItem(animMenu, SWT.PUSH);
    DFSItem.setText("Depth First Search");

    // add the menubar to the shell
    shell.setMenuBar(menuBar);

    // actions for the menu items

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

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

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

    DFSItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            controller.LoadDFSAnimation();
          }
        });
  }
コード例 #10
0
 /**
  * Returns the receiver's parent item, which must be a <code>Menu</code> or null when the receiver
  * is a root.
  *
  * @return the receiver's parent item
  * @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 Menu getParentMenu() {
   checkWidget();
   if (cascade == null) return null;
   return cascade.getParent();
 }
コード例 #11
0
  /**
   * Creates all items located in the popup menu and associates all the menu items with their
   * appropriate functions.
   *
   * @return Menu The created popup menu.
   */
  private Menu createPopUpMenu() {
    Menu popUpMenu = new Menu(shell, SWT.POP_UP);

    /** Adds a listener to handle enabling and disabling some items in the Edit submenu. */
    popUpMenu.addMenuListener(
        new MenuAdapter() {
          @Override
          public void menuShown(MenuEvent e) {
            Menu menu = (Menu) e.widget;
            MenuItem[] items = menu.getItems();
            int count = table.getSelectionCount();
            items[2].setEnabled(count != 0); // edit
            items[3].setEnabled(count != 0); // copy
            items[4].setEnabled(copyBuffer != null); // paste
            items[5].setEnabled(count != 0); // delete
            items[7].setEnabled(table.getItemCount() != 0); // find
          }
        });

    // New
    MenuItem item = new MenuItem(popUpMenu, SWT.PUSH);
    item.setText(resAddressBook.getString("Pop_up_new"));
    item.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            newEntry();
          }
        });

    new MenuItem(popUpMenu, SWT.SEPARATOR);

    // Edit
    item = new MenuItem(popUpMenu, SWT.PUSH);
    item.setText(resAddressBook.getString("Pop_up_edit"));
    item.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length == 0) return;
            editEntry(items[0]);
          }
        });

    // Copy
    item = new MenuItem(popUpMenu, SWT.PUSH);
    item.setText(resAddressBook.getString("Pop_up_copy"));
    item.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length == 0) return;
            copyBuffer = new String[table.getColumnCount()];
            for (int i = 0; i < copyBuffer.length; i++) {
              copyBuffer[i] = items[0].getText(i);
            }
          }
        });

    // Paste
    item = new MenuItem(popUpMenu, SWT.PUSH);
    item.setText(resAddressBook.getString("Pop_up_paste"));
    item.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (copyBuffer == null) return;
            TableItem item = new TableItem(table, SWT.NONE);
            item.setText(copyBuffer);
            isModified = true;
          }
        });

    // Delete
    item = new MenuItem(popUpMenu, SWT.PUSH);
    item.setText(resAddressBook.getString("Pop_up_delete"));
    item.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length == 0) return;
            items[0].dispose();
            isModified = true;
          }
        });

    new MenuItem(popUpMenu, SWT.SEPARATOR);

    // Find...
    item = new MenuItem(popUpMenu, SWT.PUSH);
    item.setText(resAddressBook.getString("Pop_up_find"));
    item.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            searchDialog.open();
          }
        });

    return popUpMenu;
  }
コード例 #12
0
  /**
   * Creates all the items located in the Edit submenu and associate all the menu items with their
   * appropriate functions.
   *
   * @param menuBar Menu the <code>Menu</code> that file contain the Edit submenu.
   * @see #createSortMenu()
   */
  private MenuItem createEditMenu(Menu menuBar) {
    // Edit menu.
    MenuItem item = new MenuItem(menuBar, SWT.CASCADE);
    item.setText(resAddressBook.getString("Edit_menu_title"));
    Menu menu = new Menu(shell, SWT.DROP_DOWN);
    item.setMenu(menu);

    /** Add a listener to handle enabling and disabling some items in the Edit submenu. */
    menu.addMenuListener(
        new MenuAdapter() {
          @Override
          public void menuShown(MenuEvent e) {
            Menu menu = (Menu) e.widget;
            MenuItem[] items = menu.getItems();
            int count = table.getSelectionCount();
            items[0].setEnabled(count != 0); // edit
            items[1].setEnabled(count != 0); // copy
            items[2].setEnabled(copyBuffer != null); // paste
            items[3].setEnabled(count != 0); // delete
            items[5].setEnabled(table.getItemCount() != 0); // sort
          }
        });

    // Edit -> Edit
    MenuItem subItem = new MenuItem(menu, SWT.PUSH);
    subItem.setText(resAddressBook.getString("Edit"));
    subItem.setAccelerator(SWT.MOD1 + 'E');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length == 0) return;
            editEntry(items[0]);
          }
        });

    // Edit -> Copy
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Copy"));
    subItem.setAccelerator(SWT.MOD1 + 'C');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length == 0) return;
            copyBuffer = new String[table.getColumnCount()];
            for (int i = 0; i < copyBuffer.length; i++) {
              copyBuffer[i] = items[0].getText(i);
            }
          }
        });

    // Edit -> Paste
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Paste"));
    subItem.setAccelerator(SWT.MOD1 + 'V');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (copyBuffer == null) return;
            TableItem item = new TableItem(table, SWT.NONE);
            item.setText(copyBuffer);
            isModified = true;
          }
        });

    // Edit -> Delete
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Delete"));
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length == 0) return;
            items[0].dispose();
            isModified = true;
          }
        });

    new MenuItem(menu, SWT.SEPARATOR);

    // Edit -> Sort(Cascade)
    subItem = new MenuItem(menu, SWT.CASCADE);
    subItem.setText(resAddressBook.getString("Sort"));
    Menu submenu = createSortMenu();
    subItem.setMenu(submenu);

    return item;
  }
コード例 #13
0
  /**
   * Creates all the items located in the File submenu and associate all the menu items with their
   * appropriate functions.
   *
   * @param menuBar Menu the <code>Menu</code> that file contain the File submenu.
   */
  private void createFileMenu(Menu menuBar) {
    // File menu.
    MenuItem item = new MenuItem(menuBar, SWT.CASCADE);
    item.setText(resAddressBook.getString("File_menu_title"));
    Menu menu = new Menu(shell, SWT.DROP_DOWN);
    item.setMenu(menu);
    /** Adds a listener to handle enabling and disabling some items in the Edit submenu. */
    menu.addMenuListener(
        new MenuAdapter() {
          @Override
          public void menuShown(MenuEvent e) {
            Menu menu = (Menu) e.widget;
            MenuItem[] items = menu.getItems();
            items[1].setEnabled(table.getSelectionCount() != 0); // edit contact
            items[5].setEnabled((file != null) && isModified); // save
            items[6].setEnabled(table.getItemCount() != 0); // save as
          }
        });

    // File -> New Contact
    MenuItem subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("New_contact"));
    subItem.setAccelerator(SWT.MOD1 + 'N');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            newEntry();
          }
        });
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Edit_contact"));
    subItem.setAccelerator(SWT.MOD1 + 'E');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length == 0) return;
            editEntry(items[0]);
          }
        });

    new MenuItem(menu, SWT.SEPARATOR);

    // File -> New Address Book
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("New_address_book"));
    subItem.setAccelerator(SWT.MOD1 + 'B');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (closeAddressBook()) {
              newAddressBook();
            }
          }
        });

    // File -> Open
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Open_address_book"));
    subItem.setAccelerator(SWT.MOD1 + 'O');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (closeAddressBook()) {
              openAddressBook();
            }
          }
        });

    // File -> Save.
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Save_address_book"));
    subItem.setAccelerator(SWT.MOD1 + 'S');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            save();
          }
        });

    // File -> Save As.
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Save_book_as"));
    subItem.setAccelerator(SWT.MOD1 + 'A');
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            saveAs();
          }
        });

    new MenuItem(menu, SWT.SEPARATOR);

    // File -> Exit.
    subItem = new MenuItem(menu, SWT.NONE);
    subItem.setText(resAddressBook.getString("Exit"));
    subItem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            shell.close();
          }
        });
  }
コード例 #14
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();
  }
コード例 #15
0
  /** Initializes the GUI. */
  private void initGUI() {
    try {
      getShell()
          .addDisposeListener(
              new DisposeListener() {
                public void widgetDisposed(DisposeEvent evt) {
                  shellWidgetDisposed(evt);
                }
              });

      getShell()
          .addControlListener(
              new ControlAdapter() {
                public void controlResized(ControlEvent evt) {
                  shellControlResized(evt);
                }
              });

      getShell()
          .addControlListener(
              new ControlAdapter() {
                public void controlMoved(ControlEvent evt) {
                  shellControlMoved(evt);
                }
              });

      GridLayout thisLayout = new GridLayout();
      this.setLayout(thisLayout);
      {
        GridData toolBarLData = new GridData();
        toolBarLData.grabExcessHorizontalSpace = true;
        toolBarLData.horizontalAlignment = GridData.FILL;
        toolBar = new ToolBar(this, SWT.FLAT);
        toolBar.setLayoutData(toolBarLData);
        toolBar.setBackgroundImage(SWTResourceManager.getImage("images/ToolbarBackground.gif"));
        {
          newToolItem = new ToolItem(toolBar, SWT.NONE);
          newToolItem.setImage(SWTResourceManager.getImage("images/new.gif"));
          newToolItem.setToolTipText("New");
        }
        {
          openToolItem = new ToolItem(toolBar, SWT.NONE);
          openToolItem.setToolTipText("Open");
          openToolItem.setImage(SWTResourceManager.getImage("images/open.gif"));
          openToolItem.addSelectionListener(
              new SelectionAdapter() {
                public void widgetSelected(SelectionEvent evt) {
                  openToolItemWidgetSelected(evt);
                }
              });
        }
        {
          saveToolItem = new ToolItem(toolBar, SWT.NONE);
          saveToolItem.setToolTipText("Save");
          saveToolItem.setImage(SWTResourceManager.getImage("images/save.gif"));
        }
      }
      {
        clientArea = new Composite(this, SWT.NONE);
        GridData clientAreaLData = new GridData();
        clientAreaLData.grabExcessHorizontalSpace = true;
        clientAreaLData.grabExcessVerticalSpace = true;
        clientAreaLData.horizontalAlignment = GridData.FILL;
        clientAreaLData.verticalAlignment = GridData.FILL;
        clientArea.setLayoutData(clientAreaLData);
        clientArea.setLayout(null);
      }
      {
        statusArea = new Composite(this, SWT.NONE);
        GridLayout statusAreaLayout = new GridLayout();
        statusAreaLayout.makeColumnsEqualWidth = true;
        statusAreaLayout.horizontalSpacing = 0;
        statusAreaLayout.marginHeight = 0;
        statusAreaLayout.marginWidth = 0;
        statusAreaLayout.verticalSpacing = 0;
        statusAreaLayout.marginLeft = 3;
        statusAreaLayout.marginRight = 3;
        statusAreaLayout.marginTop = 3;
        statusAreaLayout.marginBottom = 3;
        statusArea.setLayout(statusAreaLayout);
        GridData statusAreaLData = new GridData();
        statusAreaLData.horizontalAlignment = GridData.FILL;
        statusAreaLData.grabExcessHorizontalSpace = true;
        statusArea.setLayoutData(statusAreaLData);
        statusArea.setBackground(SWTResourceManager.getColor(239, 237, 224));
        {
          statusText = new Label(statusArea, SWT.BORDER);
          statusText.setText(" Ready");
          GridData txtStatusLData = new GridData();
          txtStatusLData.horizontalAlignment = GridData.FILL;
          txtStatusLData.grabExcessHorizontalSpace = true;
          txtStatusLData.verticalIndent = 3;
          statusText.setLayoutData(txtStatusLData);
        }
      }
      thisLayout.verticalSpacing = 0;
      thisLayout.marginWidth = 0;
      thisLayout.marginHeight = 0;
      thisLayout.horizontalSpacing = 0;
      thisLayout.marginTop = 3;
      this.setSize(474, 312);
      {
        menu1 = new Menu(getShell(), SWT.BAR);
        getShell().setMenuBar(menu1);
        {
          fileMenuItem = new MenuItem(menu1, SWT.CASCADE);
          fileMenuItem.setText("&File");
          {
            fileMenu = new Menu(fileMenuItem);
            {
              newFileMenuItem = new MenuItem(fileMenu, SWT.PUSH);
              newFileMenuItem.setText("&New");
              newFileMenuItem.setImage(SWTResourceManager.getImage("images/new.gif"));
            }
            {
              openFileMenuItem = new MenuItem(fileMenu, SWT.PUSH);
              openFileMenuItem.setText("&Open");
              openFileMenuItem.setImage(SWTResourceManager.getImage("images/open.gif"));
              openFileMenuItem.addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent evt) {
                      openFileMenuItemWidgetSelected(evt);
                    }
                  });
            }
            {
              closeFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
              closeFileMenuItem.setText("Close");
            }
            {
              fileMenuSep1 = new MenuItem(fileMenu, SWT.SEPARATOR);
            }
            {
              saveFileMenuItem = new MenuItem(fileMenu, SWT.PUSH);
              saveFileMenuItem.setText("&Save");
              saveFileMenuItem.setImage(SWTResourceManager.getImage("images/save.gif"));
              saveFileMenuItem.addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent evt) {
                      saveFileMenuItemWidgetSelected(evt);
                    }
                  });
            }
            {
              fileMenuSep2 = new MenuItem(fileMenu, SWT.SEPARATOR);
            }
            {
              exitMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
              exitMenuItem.setText("E&xit");
              exitMenuItem.addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent evt) {
                      exitMenuItemWidgetSelected(evt);
                    }
                  });
            }
            fileMenuItem.setMenu(fileMenu);
          }
        }
        {
          helpMenuItem = new MenuItem(menu1, SWT.CASCADE);
          helpMenuItem.setText("&Help");
          {
            helpMenu = new Menu(helpMenuItem);
            {
              aboutMenuItem = new MenuItem(helpMenu, SWT.CASCADE);
              aboutMenuItem.setText("&About");
              aboutMenuItem.addSelectionListener(
                  new SelectionAdapter() {
                    public void widgetSelected(SelectionEvent evt) {
                      aboutMenuItemWidgetSelected(evt);
                    }
                  });
            }
            helpMenuItem.setMenu(helpMenu);
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }