Ejemplo n.º 1
0
 private void addProfiles(JMenu menu, String[] profileNames, ActionListener listener) {
   for (int i = 0; i < profileNames.length; i++) {
     JMenuItem item = new JMenuItem(profileNames[i]);
     item.addActionListener(listener);
     menu.add(item);
   }
 }
Ejemplo n.º 2
0
    public Popup() {
      super();
      String[] profileNames = profiles.getNames();
      JMenuItem item;

      // Make the load menu
      JMenu loadMenu = new JMenu("Load profile");
      loadMenu.setEnabled(profiles.size() > 0);
      addProfiles(loadMenu, profileNames, profileLoader);
      this.add(loadMenu);
      this.addSeparator();

      // put in a dummy item
      item = new JMenuItem();
      item.setEnabled(false);
      this.add(item);
      this.addSeparator();

      // Make the save menu
      JMenu saveMenu = new JMenu("Save profile");
      item = new JMenuItem("New...");
      item.addActionListener(profileSaver);
      saveMenu.add(item);
      saveMenu.addSeparator();
      addProfiles(saveMenu, profileNames, profileSaver);
      this.add(saveMenu);
      this.addSeparator();

      // put in a dummy item
      item = new JMenuItem();
      item.setEnabled(false);
      this.add(item);
      this.addSeparator();

      // Make the delete menu
      JMenu deleteMenu = new JMenu("Delete profile");
      deleteMenu.setEnabled(profiles.size() > 0);
      addProfiles(deleteMenu, profileNames, profileDeleter);
      this.add(deleteMenu);
    }