예제 #1
0
 void releaseParent_pp() {
   super.releaseParent_pp();
   if (cascade != null) cascade.setMenu(null);
   if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
     parent.setMenuBar(null);
   }
 }
  /**
   * 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();
          }
        });
  }
  /**
   * 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();
          }
        });
  }
예제 #4
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();
          }
        });
  }
예제 #5
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;
  }
예제 #6
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();
          }
        });
  }
예제 #7
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();
    }
  }