예제 #1
0
 private JMenuItem getJMenuItem3() {
   if (jMenuItem3 == null) {
     jMenuItem3 = new JMenuItem();
     jMenuItem3.setText("Solution");
     jMenuItem3.setMnemonic(java.awt.event.KeyEvent.VK_S);
     jMenuItem3.setAccelerator(
         javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_S, java.awt.Event.CTRL_MASK, false));
     jMenuItem3.addActionListener(
         new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent e) {
             solution = true;
             current = new ArrayList<String>(correct);
             shuffle();
             getStatusLabel().setText("Correct solution.");
             // Change the buttons colors to green
             Iterator itr = buttons.iterator();
             while (itr.hasNext()) {
               ((JButton) itr.next()).setBackground(java.awt.Color.green);
             }
           }
         });
   }
   return jMenuItem3;
 }
예제 #2
0
  /**
   * Add a menu item to a named menu
   *
   * @param topMenu the name of the menu to add to
   * @param menuItem the entry text for the item itself
   * @param action the action associated with the menu item
   * @param accelerator the keystroke accelerator to associate with the item
   */
  protected void addMenuItemToMenu(
      String topMenu, String menuItem, final Action action, KeyStroke accelerator) {
    JMenuItem newItem = m_menuItemMap.get(menuItem);
    if (newItem != null) {
      throw new IllegalArgumentException("The menu item '" + menuItem + "' already exists!");
    }
    newItem = new JMenuItem(menuItem);
    if (accelerator != null) {
      newItem.setAccelerator(accelerator);
    }
    newItem.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            action.actionPerformed(e);
          }
        });

    JMenu topJ = m_menuMap.get(topMenu);
    if (topJ == null) {
      topJ = new JMenu();
      topJ.setText(topMenu);
      m_menuMap.put(topMenu, topJ);
    }

    topJ.add(newItem);
    m_menuItemMap.put(menuItem, newItem);
  }
예제 #3
0
 private JMenuItem createMenuItem(
     String name, KeyStroke accelerator, ActionListener actionListener) {
   JMenuItem item = new JMenuItem(name);
   item.setName(name);
   item.setAccelerator(accelerator);
   item.addActionListener(actionListener);
   return item;
 }
  private void initAccelerator(Class<? extends Action> actionClass, JMenuItem mnuItem) {
    Action action = _session.getApplication().getActionCollection().get(actionClass);

    String accel = (String) action.getValue(Resources.ACCELERATOR_STRING);
    if (null != accel && 0 != accel.trim().length()) {
      mnuItem.setAccelerator(KeyStroke.getKeyStroke(accel));
    }
  }
예제 #5
0
  /**
   * Define the main Circuit menu.
   *
   * @param al the action listener to associate to the menu.
   * @return the menu.
   */
  public JMenu defineCircuitMenu(ActionListener al) {
    JMenu circuitMenu = new JMenu(Globals.messages.getString("Circuit"));
    JMenuItem defineCircuit = new JMenuItem(Globals.messages.getString("Define"));

    defineCircuit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, Globals.shortcutKey));

    circuitMenu.add(defineCircuit);

    JMenuItem updateLibraries = new JMenuItem(Globals.messages.getString("LibraryUpdate"));

    updateLibraries.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, Globals.shortcutKey));

    circuitMenu.add(updateLibraries);
    defineCircuit.addActionListener(al);
    updateLibraries.addActionListener(al);

    return circuitMenu;
  }
예제 #6
0
  private void AddMenuItem(
      JMenu menu, ActionListener listener, String menutext, int commandID, int mnemonic) {
    JMenuItem menuitem;

    menuitem = new MyMenuItem(menutext, commandID, mnemonic);
    menuitem.setAccelerator(KeyStroke.getKeyStroke(mnemonic, primaryCommandKey));
    menuitem.addActionListener(listener);
    menu.add(menuitem);
  }
  JMenuItem item(String text, char accelerator) {

    JMenuItem menuItem = new JMenuItem(text);

    menuItem.setAccelerator(KeyStroke.getKeyStroke(accelerator, Event.CTRL_MASK));
    menuItem.addActionListener(menuListener);

    return menuItem;
  }
예제 #8
0
  private void initFileMenu() {
    fileMenu = new JMenu("   File   ");

    fileNewItem = new JMenuItem(new NewWorkbookAction());
    fileNewItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));
    fileNewItem.setPreferredSize(new Dimension(200, 26));

    fileOpenItem = new JMenuItem(new OpenWorkbookAction());
    fileOpenItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
    fileOpenItem.setPreferredSize(new Dimension(200, 26));

    fileSaveItem = new JMenuItem(new SaveWorkbookAction());
    fileSaveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
    fileSaveItem.setEnabled(false);
    fileSaveItem.setPreferredSize(new Dimension(200, 26));

    fileSaveAsItem = new JMenuItem(new SaveWorkbookAsAction());
    fileSaveAsItem.setAccelerator(
        KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK));
    fileSaveAsItem.setEnabled(false);
    fileSaveAsItem.setPreferredSize(new Dimension(200, 26));

    fileImportItem = new JMenuItem(new ImportCSVAction());
    fileImportItem.setPreferredSize(new Dimension(200, 26));
    fileImportItem.setEnabled(false);

    fileExportItem = new JMenuItem(new ExportCSVAction());
    fileExportItem.setPreferredSize(new Dimension(200, 26));
    fileExportItem.setEnabled(false);

    fileExitItem = new JMenuItem(new ExitApplicationAction());
    fileExitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK));
    fileExitItem.setPreferredSize(new Dimension(200, 26));

    fileMenu.add(fileNewItem);
    fileMenu.add(fileOpenItem);
    fileMenu.add(fileSaveItem);
    fileMenu.add(fileSaveAsItem);
    fileMenu.add(new JSeparator());
    fileMenu.add(fileImportItem);
    fileMenu.add(fileExportItem);
    fileMenu.add(new JSeparator());
    fileMenu.add(fileExitItem);
  }
예제 #9
0
  public static JMenuItem createMenuItem(Action a, char m, int key, HotKey hotKey) {
    JMenuItem res = new JMenuItem(a);
    res.setMnemonic(m);

    int mask = getMask(hotKey);

    if (key != 0) res.setAccelerator(KeyStroke.getKeyStroke(key, mask));

    return res;
  }
예제 #10
0
  /**
   * Define the main View menu.
   *
   * @param al the action listener to associate to the menu.
   * @return the menu.
   */
  public JMenu defineViewMenu(ActionListener al) {
    JMenu viewMenu = new JMenu(Globals.messages.getString("View"));
    JMenuItem layerOptions = new JMenuItem(Globals.messages.getString("Layer_opt"));

    layerOptions.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, Globals.shortcutKey));

    viewMenu.add(layerOptions);

    layerOptions.addActionListener(al);
    return viewMenu;
  }
예제 #11
0
 private JMenuItem closeAction() {
   JMenuItem result = new JMenuItem("Close");
   result.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.META_MASK));
   result.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           LookSpike.this.dispose();
         }
       });
   return result;
 }
예제 #12
0
  public MyMenuBar(JFrame frame) {
    super();
    this.frame = frame;
    // Build the first menu.
    JMenu menu = new JMenu(HELP);
    menu.setMnemonic(KeyEvent.VK_H);
    /** First menu Item */
    menuItem = new JMenuItem(OPTIONS, KeyEvent.VK_C);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK));
    menuItem.addActionListener(this);
    menu.add(menuItem);
    this.add(menu);

    /** Second menu Item */
    menuItem = new JMenuItem(ABOUT, KeyEvent.VK_A);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.ALT_MASK));
    menuItem.addActionListener(this);
    menu.add(menuItem);
    this.add(menu);
  }
예제 #13
0
  public DBJMenuBar(JMenuListener listener) {
    aJMenuListener = listener;

    fileJMenu = new JMenu("Datei");

    fileJMenuItem = new JMenuItem("Drucken");
    fileJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK));
    fileJMenuItem.setMnemonic((int) 'p');
    fileJMenu.add(fileJMenuItem);
    fileJMenuItem.addActionListener(aJMenuListener);

    fileJMenu.addSeparator();

    fileJMenuItem = new JMenuItem("Schliessen");
    fileJMenu.add(fileJMenuItem);
    fileJMenuItem.addActionListener(aJMenuListener);

    add(fileJMenu);

    selectJMenu = new JMenu("Anzeigen");
    selectJMenuItem = new JMenuItem("Rangliste");
    selectJMenu.add(selectJMenuItem);
    selectJMenuItem.addActionListener(aJMenuListener);

    selectJMenuItem = new JMenuItem("Verein");
    selectJMenu.add(selectJMenuItem);
    selectJMenuItem.addActionListener(aJMenuListener);

    selectJMenuItem = new JMenuItem("Schiedsrichter");
    selectJMenu.add(selectJMenuItem);
    selectJMenuItem.addActionListener(aJMenuListener);

    selectJMenuItem = new JMenuItem("Turnierdaten");
    selectJMenu.add(selectJMenuItem);
    selectJMenuItem.addActionListener(aJMenuListener);

    add(selectJMenu);

    editJMenu = new JMenu("Erstellen&Suchen");
    editJMenuItem = new JMenuItem("Person erstellen/suchen");
    editJMenu.add(editJMenuItem);
    editJMenuItem.addActionListener(aJMenuListener);

    add(editJMenu);

    infoJMenu = new JMenu("Info");

    infoJMenuItem = new JMenuItem("Tabelleninfo");
    infoJMenu.add(infoJMenuItem);
    infoJMenuItem.addActionListener(aJMenuListener);

    add(infoJMenu);
  }
예제 #14
0
 // create the menu bar (changed to private)
 private static JMenuBar createMenuBar() {
   JMenuBar menuBar = new JMenuBar();
   JMenu menu = new JMenu("File");
   menuBar.add(menu);
   JMenuItem saveItem = new JMenuItem(" Save...   ");
   saveItem.addActionListener(std);
   saveItem.setAccelerator(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
   menu.add(saveItem);
   return menuBar;
 }
  /**
   * Create the main frame's menu bar.
   *
   * @param frame The frame that the menu bar should be added to.
   */
  private void makeMenuBar(JFrame frame) {
    final int SHORTCUT_MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

    JMenuBar menubar = new JMenuBar();
    frame.setJMenuBar(menubar);
    // create the File manu
    JMenu fileMenu = new JMenu("File");
    menubar.add(fileMenu);

    JMenuItem openItem = new JMenuItem("Open");
    openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, SHORTCUT_MASK));
    openItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            openFile();
          }
        });
    fileMenu.add(openItem);

    JMenuItem quitItem = new JMenuItem("Quit");
    quitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, SHORTCUT_MASK));
    quitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            quit();
          }
        });
    fileMenu.add(quitItem);

    JMenuItem helpItem = new JMenuItem("Help");
    helpItem.setAccelerator(KeyStroke.getKeyStroke(133, SHORTCUT_MASK));
    helpItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Launch();
          }
        });
    fileMenu.add(helpItem);
  }
예제 #16
0
  private JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();

    JMenu menu = new JMenu("Game");
    menuBar.add(menu);

    JMenuItem newGameItem = new JMenuItem("New Game");
    newGameItem.addActionListener(new NewGameButtonListener());
    newGameItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
    menu.add(newGameItem);

    JMenuItem viewScoreItem = new JMenuItem("View Highscore");
    viewScoreItem.addActionListener(new HighscoreButtonListener());
    menu.add(viewScoreItem);

    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(new ExitItemListener());
    exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
    menu.add(exitItem);

    return menuBar;
  }
예제 #17
0
  private void initEditMenu() {
    editMenu = new JMenu("   Edit   ");

    editCopyItem = new JMenuItem(new CopyCellAction());
    editCopyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));
    editCopyItem.setPreferredSize(new Dimension(200, 26));
    editCopyItem.setEnabled(false);

    editCutItem = new JMenuItem(new CutCellAction());
    editCutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
    editCutItem.setPreferredSize(new Dimension(200, 26));
    editCutItem.setEnabled(false);

    editPasteItem = new JMenuItem(new PasteCellAction());
    editPasteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK));
    editPasteItem.setPreferredSize(new Dimension(200, 26));
    editPasteItem.setEnabled(false);

    editMenu.add(editCopyItem);
    editMenu.add(editCutItem);
    editMenu.add(editPasteItem);
  }
예제 #18
0
  private void initViewMenu() {
    viewMenu = new JMenu("   View   ");

    viewMaximizeItem = new JMenuItem(new MaximizeWindowAction());
    viewMaximizeItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0));
    viewMaximizeItem.setPreferredSize(new Dimension(200, 26));

    viewMinimizeItem = new JMenuItem(new MinimizeWindowAction());
    viewMinimizeItem.setPreferredSize(new Dimension(200, 26));

    viewMenu.add(viewMaximizeItem);
    viewMenu.add(viewMinimizeItem);
  }
  // Private helper methods
  private void createMenuBar() {
    menuBar = new JMenuBar();
    fileMenu = new JMenu("File");

    miOpen = new JMenuItem("Open...");
    miOpen.setAccelerator(
        KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.Event.META_MASK));
    fileMenu.add(miOpen).setEnabled(false);
    miOpen.addActionListener(new MenuActionListener());

    miSave = new JMenuItem("Save Selected...");
    miSave.setAccelerator(
        KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.Event.META_MASK));
    fileMenu.add(miSave).setEnabled(false);
    miSave.addActionListener(new MenuActionListener());

    miSaveAll = new JMenuItem("Save All...");
    fileMenu.add(miSaveAll).setEnabled(false);
    miSaveAll.addActionListener(new MenuActionListener());

    menuBar.add(fileMenu);
  }
예제 #20
0
 protected JMenu buildEditMenu() {
   JMenu editMenu = original();
   if (editMenu.getItemCount() > 0) editMenu.addSeparator();
   JMenuItem findMenuItem =
       new JMenuItem("Find", new ImageIcon(this.getClass().getResource("images/find.gif")));
   findMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK));
   findMenuItem.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ae) {
           actions.find();
         }
       });
   editMenu.add(findMenuItem);
   JMenuItem findNextMenuItem = new JMenuItem("Find Next");
   findNextMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK));
   findNextMenuItem.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ae) {
           actions.findNext();
         }
       });
   editMenu.add(findNextMenuItem);
   return editMenu;
 }
예제 #21
0
 /**
  * This method initializes jMenuItem1
  *
  * @return JMenuItem
  */
 private JMenuItem getJMenuItem1() {
   if (jMenuItem1 == null) {
     jMenuItem1 = new JMenuItem();
     jMenuItem1.setText("Quit");
     jMenuItem1.setMnemonic(java.awt.event.KeyEvent.VK_X);
     jMenuItem1.setAccelerator(
         javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_X, java.awt.Event.CTRL_MASK, false));
     jMenuItem1.addActionListener(
         new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent e) {
             System.exit(0);
           }
         });
   }
   return jMenuItem1;
 }
예제 #22
0
 /**
  * This method initializes jMenuItem
  *
  * @return JMenuItem
  */
 private JMenuItem getJMenuItem() {
   if (jMenuItem == null) {
     jMenuItem = new JMenuItem();
     jMenuItem.setText("New Game");
     jMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_N);
     jMenuItem.setAccelerator(
         javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_N, java.awt.Event.CTRL_MASK, false));
     jMenuItem.addActionListener(
         new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent e) {
             shuffle();
           }
         });
   }
   return jMenuItem;
 }
예제 #23
0
  private void initHelpMenu() {
    helpMenu = new JMenu("   Help   ");

    helpDocumentationItem = new JMenuItem(new ViewDocumentationAction());
    helpDocumentationItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0));
    helpDocumentationItem.setPreferredSize(new Dimension(200, 26));

    helpOnlineDocumentationItem = new JMenuItem(new ViewOnlineDocumentationAction());
    helpOnlineDocumentationItem.setPreferredSize(new Dimension(200, 26));

    helpAboutItem = new JMenuItem(new ViewAboutAction());
    helpAboutItem.setPreferredSize(new Dimension(200, 26));

    helpMenu.add(helpDocumentationItem);
    helpMenu.add(helpOnlineDocumentationItem);
    helpMenu.add(new JSeparator());
    helpMenu.add(helpAboutItem);
  }
예제 #24
0
  /** Creates the menubar for the search editor. */
  protected JMenuBar menuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu file = new JMenu("File");
    menuBar.add(file);
    JMenu fileMenu = new GraphFileMenu(this, getWorkbench());
    file.add(fileMenu);
    //        file.add(new SaveGraph(this, "Save Graph..."));
    //        file.add(new SaveScreenshot(this, true, "Save Screenshot..."));
    file.add(new SaveComponentImage(workbench, "Save Graph Image..."));

    JMenu edit = new JMenu("Edit");
    JMenuItem copy = new JMenuItem(new CopySubgraphAction(this));
    copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
    edit.add(copy);

    menuBar.add(edit);

    addSpecialMenus(menuBar);

    return menuBar;
  }
예제 #25
0
  /**
   * Creates a new JMenuItem or JCheckBoxMenuItem and adds it to the given JMenu.
   *
   * @param menu menu to add the menu item to.
   * @param text text used by the menu item.
   * @param mnemonicHelper an optional (can be null) mnemonic helper which will be used along with
   *     the item's text to set a mnemonic to the menu.
   * @param accelerator an optional (can be null) keyboard shortcut used by the menu item.
   * @param actionListener an optional (can be null) action listener which will listen to the events
   *     triggered by the menu item.
   * @param createCheckBoxMenuItem specifies whether the menu item to be created is a
   *     JCheckBoxMenuItem or just a regular JMenuItem.
   */
  private static JMenuItem addMenuItem(
      JMenu menu,
      String text,
      MnemonicHelper mnemonicHelper,
      KeyStroke accelerator,
      ActionListener actionListener,
      boolean createCheckBoxMenuItem) {
    JMenuItem menuItem =
        createCheckBoxMenuItem ? new JCheckBoxMenuItem(text, false) : new JMenuItem(text);

    if (mnemonicHelper != null) {
      char mnemonic = mnemonicHelper.getMnemonic(text);
      if (mnemonic != 0) menuItem.setMnemonic(mnemonic);
    }

    if (accelerator != null) menuItem.setAccelerator(accelerator);

    if (actionListener != null) menuItem.addActionListener(actionListener);

    menu.add(menuItem);

    return menuItem;
  }
예제 #26
0
 private JMenuItem getJMenuItem2() {
   if (jMenuItem2 == null) {
     jMenuItem2 = new JMenuItem();
     jMenuItem2.setText("Image Path");
     jMenuItem2.setMnemonic(java.awt.event.KeyEvent.VK_O);
     jMenuItem2.setAccelerator(
         javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_O, java.awt.Event.CTRL_MASK, false));
     jMenuItem2.addActionListener(
         new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent e) {
             // System.exit(0);
             jFileChooser = new JFileChooser();
             jFileChooser.setDialogTitle("Select image directory.");
             jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
             jFileChooser.setAcceptAllFileFilterUsed(false);
             if (jFileChooser.showOpenDialog(jPanel) == JFileChooser.APPROVE_OPTION) {
               path = jFileChooser.getSelectedFile() + "/";
               solution = true;
               current = new ArrayList<String>(correct);
               for (int i = 1; i <= 16; i++) {
                 // Add the icons in correct order
                 icons[i - 1] = new ImageIcon(path + i + ".jpg");
               }
               shuffle();
               getStatusLabel().setText("New game started.");
               // Change the buttons colors to green
               Iterator itr = buttons.iterator();
               while (itr.hasNext()) {
                 ((JButton) itr.next()).setBackground(java.awt.Color.green);
               }
             }
           }
         });
   }
   return jMenuItem2;
 }
예제 #27
0
  // Constructor receives the filename
  Rolodex(String filename) throws FileNotFoundException {
    File file = new File(filename);
    Scanner scanner = new Scanner(file);

    // Split the line with ~
    while (scanner.hasNext()) {
      tokens = scanner.nextLine().split("~");
      name = tokens[0];
      email = tokens[1];
      pictures = tokens[tokens.length - 1];

      User user = new User();
      user.setUserName(name);
      user.setUserEmail(email);
      user.setPicture(pictures);
      userList.add(user);
    }

    frame = new JFrame("Rolodex");
    frame.setSize(700, 200);

    // Menu
    JMenuBar jmb = new JMenuBar();
    JMenu jmFile = new JMenu("File");
    JMenuItem jmiOpen = new JMenuItem("Open");
    jmiOpen.setEnabled(false);
    JMenuItem jmiExit = new JMenuItem("Exit");
    jmiExit.setMnemonic(KeyEvent.VK_X);
    jmFile.add(jmiOpen);
    jmFile.addSeparator();
    jmFile.add(jmiExit);
    jmb.add(jmFile);

    jmiOpen.addActionListener(this);
    jmiExit.addActionListener(this);

    JMenu jmTabs = new JMenu("Tabs");
    jmTabs.setMnemonic(KeyEvent.VK_T);

    JMenu jmiplacement = new JMenu("Placement");
    JMenuItem jmitop = new JMenuItem("Top");
    JMenuItem jmiright = new JMenuItem("Right");
    JMenuItem jmibottom = new JMenuItem("Bottom");
    JMenuItem jmileft = new JMenuItem("Left");
    jmiplacement.add(jmitop);
    jmiplacement.add(jmiright);
    jmiplacement.add(jmibottom);
    jmiplacement.add(jmileft);

    jmitop.addActionListener(this);
    jmiright.addActionListener(this);
    jmibottom.addActionListener(this);
    jmileft.addActionListener(this);

    JMenu jmilayoutpolicy = new JMenu("Layout policy");
    JMenuItem jmiscroll = new JMenuItem("Scroll");
    JMenuItem jmiwrap = new JMenuItem("Wrap");
    jmilayoutpolicy.add(jmiscroll);
    jmilayoutpolicy.add(jmiwrap);

    jmiscroll.addActionListener(this);
    jmiwrap.addActionListener(this);

    JMenuItem jmidefaults = new JMenuItem("Defaults");
    jmidefaults.setMnemonic(KeyEvent.VK_D);
    jmidefaults.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK));
    jmidefaults.addActionListener(this);
    jmTabs.add(jmiplacement);
    jmTabs.add(jmilayoutpolicy);
    jmTabs.addSeparator();
    jmTabs.add(jmidefaults);
    jmb.add(jmTabs);

    JMenu jmHelp = new JMenu("Help");
    JMenuItem jmiabout = new JMenuItem("About");
    jmiabout.addActionListener(this);
    jmHelp.add(jmiabout);
    jmb.add(jmHelp);

    frame.setJMenuBar(jmb);

    jtp = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());

    for (User user : userList) {
      image = new ImageIcon(user.getPicture());
      panel = new JPanel();
      labname = new JLabel("Name: ");
      txtname = new JTextField(20);
      txtname.setText(user.getUserName());
      labemail = new JLabel("Email: ");
      txtemail = new JTextField(20);
      txtemail.setText(user.getUserEmail());
      l = new JLabel(image);
      l.setHorizontalAlignment(SwingConstants.LEFT);
      panel.add(l);
      panel.add(labname);
      panel.add(txtname);
      panel.add(labemail);
      panel.add(txtemail);
      jtp.addTab(user.getUserName(), panel);
      topPanel.add(jtp);
    }

    frame.add(jtp);
    center(frame);
    frame.setVisible(true);
  }
예제 #28
0
 // AAARGGG !! :-(  the javax.swing.JMenuItem don't take other
 // properties then Icon and Name from the Action !,
 // so we must add the accelerator
 public JMenuItem getJMenuItem() {
   JMenuItem jm = new JMenuItem(this);
   Object o = getValue(Action.ACCELERATOR_KEY);
   if (o != null) jm.setAccelerator((KeyStroke) o);
   return jm;
 }
예제 #29
0
  private void initMenu() {

    JMenuBar menuBar = new JMenuBar();

    setJMenuBar(menuBar);

    // File Menu
    JMenu fileMenu = new JMenu("File");

    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);

    JMenuItem fileNewItem = new JMenuItem("New", KeyEvent.VK_N);
    fileNewItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
    fileMenu.add(fileNewItem);

    JMenuItem fileOpenItem = new JMenuItem("Open...", KeyEvent.VK_O);
    fileOpenItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    fileMenu.add(fileOpenItem);

    JMenuItem fileOpenAdjacencyItem = new JMenuItem("Open Adjacency File...");
    fileMenu.add(fileOpenAdjacencyItem);

    JMenuItem fileOpenWeightedAdjacencyItem = new JMenuItem("Open Weighted Adjacency File...");
    fileMenu.add(fileOpenWeightedAdjacencyItem);

    JMenuItem fileOpenXMLItem = new JMenuItem("Open XML File...");
    fileMenu.add(fileOpenXMLItem);

    JMenuItem fileSaveItem = new JMenuItem("Save", KeyEvent.VK_S);
    fileSaveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
    fileMenu.add(fileSaveItem);

    JMenuItem fileSaveAsItem = new JMenuItem("Save As...");
    fileMenu.add(fileSaveAsItem);

    JMenuItem fileSaveSimpleItem = new JMenuItem("Save Simple Graph...");
    fileMenu.add(fileSaveSimpleItem);

    JMenuItem fileSaveXMLItem = new JMenuItem("Save XML File...");
    fileMenu.add(fileSaveXMLItem);

    JMenuItem filePNGItem = new JMenuItem("Export to png");
    fileMenu.add(filePNGItem);

    JMenuItem fileExitItem = new JMenuItem("Exit", KeyEvent.VK_X);
    fileExitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
    fileMenu.add(fileExitItem);

    fileExitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileExit();
          }
        });

    fileNewItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileNew();
          }
        });

    fileOpenItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileOpen();
          }
        });

    fileOpenXMLItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileOpenXML();
          }
        });

    fileSaveItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileSave();
          }
        });

    fileSaveAsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileSaveAs();
          }
        });

    fileSaveSimpleItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileSaveSimple();
          }
        });

    fileSaveXMLItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            fileSaveXML();
          }
        });

    filePNGItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            filePNG();
          }
        });

    // Edit Menu
    JMenu editMenu = new JMenu("Edit");

    editMenu.setMnemonic(KeyEvent.VK_E);
    menuBar.add(editMenu);

    JMenuItem editNodesItem = new JMenuItem("Edit Selected Nodes...", KeyEvent.VK_N);
    editNodesItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.SHIFT_MASK));
    editMenu.add(editNodesItem);

    JMenuItem editEdgesItem = new JMenuItem("Edit Selected Edges...", KeyEvent.VK_E);
    editEdgesItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.SHIFT_MASK));
    editMenu.add(editEdgesItem);

    JMenuItem editEdgeTypesItem = new JMenuItem("Edit Edge Types...");
    editMenu.add(editEdgeTypesItem);

    JMenuItem editNodeTypesItem = new JMenuItem("Edit Node Types...");
    editMenu.add(editNodeTypesItem);

    JMenuItem editMoveGraphItem = new JMenuItem("Move Graph...");
    editMenu.add(editMoveGraphItem);

    JMenuItem editAddEdgeBendItem = new JMenuItem("Add Edge Bend");
    editMenu.add(editAddEdgeBendItem);

    JMenuItem editRemoveEdgeBendsItem = new JMenuItem("Remove Edge Bends");
    editMenu.add(editRemoveEdgeBendsItem);

    JMenuItem editSelectAllItem = new JMenuItem("Select All", KeyEvent.VK_A);
    editSelectAllItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
    editMenu.add(editSelectAllItem);

    editNodesItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            gp.editNodes(gp.getSelection().getNodes());
          }
        });

    editEdgesItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            gp.editEdges(gp.getSelection().getEdges());
          }
        });

    editEdgeTypesItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            gp.editEdgeTypes();
          }
        });

    editNodeTypesItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            gp.editNodeTypes();
          }
        });

    editMoveGraphItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            gp.moveGraph();
          }
        });

    editAddEdgeBendItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            gp.addEdgeBend();
          }
        });

    editRemoveEdgeBendsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            gp.removeEdgeBends();
          }
        });

    editSelectAllItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            editSelectAll();
          }
        });

    // View Menu
    JMenu viewMenu = new JMenu("View");
    viewMenu.setMnemonic(KeyEvent.VK_V);
    menuBar.add(viewMenu);

    for (GraphView v : gp.getGraphViewList()) {
      JMenuItem menuItem = new JMenuItem(v.getMenuText(), v.getMnemonicKey());
      menuItem.setAccelerator(KeyStroke.getKeyStroke(v.getAcceleratorKey(), 0));
      menuItem.addActionListener(this);
      viewMenu.add(menuItem);
    }

    // Experiment Menu
    JMenu experimentsMenu = new JMenu("Experiments");
    experimentsMenu.setMnemonic(KeyEvent.VK_E);
    menuBar.add(experimentsMenu);

    for (GraphExperiment ge : gp.getGraphExperimentList()) {
      JMenuItem menuItem = new JMenuItem(ge.getMenuText(), ge.getMnemonicKey());
      menuItem.setAccelerator(KeyStroke.getKeyStroke(ge.getAcceleratorKey(), 0));
      menuItem.addActionListener(this);
      experimentsMenu.add(menuItem);
    }

    // Utilities Menu
    JMenu utilitiesMenu = new JMenu("Utilities");
    utilitiesMenu.setMnemonic(KeyEvent.VK_U);
    menuBar.add(utilitiesMenu);

    for (GraphUtility u : gp.getGraphUtilityList()) {
      JMenuItem menuItem = new JMenuItem(u.getMenuText(), u.getMnemonicKey());
      menuItem.setAccelerator(KeyStroke.getKeyStroke(u.getAcceleratorKey(), 0));
      menuItem.addActionListener(this);
      utilitiesMenu.add(menuItem);
    }

    JMenu layoutMenu = new JMenu("Layout");
    layoutMenu.setMnemonic(KeyEvent.VK_L);
    menuBar.add(layoutMenu);

    for (GraphDrawer d : gp.getGraphDrawerList()) {
      JMenuItem menuItem = new JMenuItem(d.getMenuText(), d.getMnemonicKey());
      menuItem.setAccelerator(KeyStroke.getKeyStroke(d.getAcceleratorKey(), 0));
      menuItem.addActionListener(this);
      layoutMenu.add(menuItem);
    }
  }
예제 #30
0
    public static void makeMenuBar(JFrame frame, final AirspaceBuilderController controller) {
      JMenuBar menuBar = new JMenuBar();
      final JCheckBoxMenuItem resizeNewShapesItem;
      final JCheckBoxMenuItem enableEditItem;

      JMenu menu = new JMenu("File");
      {
        JMenuItem item = new JMenuItem("Open...");
        item.setAccelerator(
            KeyStroke.getKeyStroke(
                KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        item.setActionCommand(OPEN);
        item.addActionListener(controller);
        menu.add(item);

        item = new JMenuItem("Open URL...");
        item.setActionCommand(OPEN_URL);
        item.addActionListener(controller);
        menu.add(item);

        item = new JMenuItem("Save...");
        item.setAccelerator(
            KeyStroke.getKeyStroke(
                KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        item.setActionCommand(SAVE);
        item.addActionListener(controller);
        menu.add(item);

        menu.addSeparator();

        item = new JMenuItem("Load Demo Shapes");
        item.setActionCommand(OPEN_DEMO_AIRSPACES);
        item.addActionListener(controller);
        menu.add(item);
      }
      menuBar.add(menu);

      menu = new JMenu("Shape");
      {
        JMenu subMenu = new JMenu("New");
        for (final AirspaceFactory factory : defaultAirspaceFactories) {
          JMenuItem item = new JMenuItem(factory.toString());
          item.addActionListener(
              new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                  controller.createNewEntry(factory);
                }
              });
          subMenu.add(item);
        }
        menu.add(subMenu);

        resizeNewShapesItem = new JCheckBoxMenuItem("Fit new shapes to viewport");
        resizeNewShapesItem.setActionCommand(SIZE_NEW_SHAPES_TO_VIEWPORT);
        resizeNewShapesItem.addActionListener(controller);
        resizeNewShapesItem.setState(controller.isResizeNewShapesToViewport());
        menu.add(resizeNewShapesItem);

        enableEditItem = new JCheckBoxMenuItem("Enable shape editing");
        enableEditItem.setActionCommand(ENABLE_EDIT);
        enableEditItem.addActionListener(controller);
        enableEditItem.setState(controller.isEnableEdit());
        menu.add(enableEditItem);
      }
      menuBar.add(menu);

      menu = new JMenu("Selection");
      {
        JMenuItem item = new JMenuItem("Deselect");
        item.setAccelerator(
            KeyStroke.getKeyStroke(
                KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        item.setActionCommand(CLEAR_SELECTION);
        item.addActionListener(controller);
        menu.add(item);

        item = new JMenuItem("Delete");
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
        item.setActionCommand(REMOVE_SELECTED);
        item.addActionListener(controller);
        menu.add(item);
      }
      menuBar.add(menu);

      frame.setJMenuBar(menuBar);

      controller.addPropertyChangeListener(
          new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent e) {
              if (SIZE_NEW_SHAPES_TO_VIEWPORT.equals((e.getPropertyName()))) {
                resizeNewShapesItem.setSelected(controller.isResizeNewShapesToViewport());
              } else if (ENABLE_EDIT.equals(e.getPropertyName())) {
                enableEditItem.setSelected(controller.isEnableEdit());
              }
            }
          });
    }