Ejemplo n.º 1
0
 private static JRadioButtonMenuItem createLookAndFeelItem(
     String lafName, String lafClassName, final ButtonGroup lookAndFeelRadioGroup) {
   JRadioButtonMenuItem lafItem = new JRadioButtonMenuItem();
   lafItem.setSelected(lafClassName.equals(lookAndFeel));
   lafItem.setHideActionText(true);
   lafItem.setAction(
       new AbstractAction() {
         @Override
         public void actionPerformed(ActionEvent e) {
           ButtonModel m = lookAndFeelRadioGroup.getSelection();
           try {
             setLookAndFeel(m.getActionCommand());
           } catch (ClassNotFoundException
               | InstantiationException
               | IllegalAccessException
               | UnsupportedLookAndFeelException ex) {
             ex.printStackTrace();
           }
         }
       });
   lafItem.setText(lafName);
   lafItem.setActionCommand(lafClassName);
   lookAndFeelRadioGroup.add(lafItem);
   return lafItem;
 }
Ejemplo n.º 2
0
  /**
   * Loads the menu with the available look and feels for the application
   *
   * @return l and f menu
   */
  JMenu buildLookAndFeelMenu() {
    String activeLookAndFeelName = UIManager.getLookAndFeel().getName();

    // ButtonGroup buttonGroup = new ButtonGroup();
    JMenu lfMenu = new JMenu();

    lfMenu.setText(rb.getString("Menu.LookAndFeel.Name"));
    lfMenu.setMnemonic(jgnash.ui.util.Resource.getMnemonic("Menu.LookAndFeel.Mnemonic"));

    lfMenu.add(buildSubstanceMenu());

    List<String> lookAndFeels = new ArrayList<>();

    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
      if (isLookAndFeelAvailable(info.getClassName())) {
        lookAndFeels.add(info.getClassName());
      }
    }

    for (String lookAndFeel : KNOWN) {
      if (isLookAndFeelAvailable(lookAndFeel)) {
        lookAndFeels.add(lookAndFeel);
      }
    }

    Collections.sort(lookAndFeels);

    for (String lookAndFeel : lookAndFeels) {
      try {
        Class<?> lnfClass = Class.forName(lookAndFeel);
        LookAndFeel newLAF = (LookAndFeel) lnfClass.newInstance();

        JRadioButtonMenuItem button = new JRadioButtonMenuItem();

        button.setText(newLAF.getName());
        button.setActionCommand(lookAndFeel);
        button.setName(newLAF.getName());

        button.addActionListener(
            e -> {
              Preferences pref = Preferences.userNodeForPackage(ThemeManager.class);
              pref.put(LF, e.getActionCommand());

              restartUI();
            });

        lfButtonGroup.add(button);

        lfMenu.add(button);

        if (newLAF.getName().equals(activeLookAndFeelName)) {
          button.setSelected(true);
        }
      } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        Logger.getLogger(ThemeManager.class.getName()).log(Level.WARNING, null, e);
      }
    }

    return lfMenu;
  }
Ejemplo n.º 3
0
    public JComponent[] getMenuPresenters() {
      assert SwingUtilities.isEventDispatchThread() : "Must be called from AWT";
      removeAll();
      final TopComponent tc = WindowManager.getDefault().getRegistry().getActivated();
      if (tc != null) {
        setEnabled(true);
        MultiViewHandler handler = MultiViews.findMultiViewHandler(tc);
        if (handler != null) {
          ButtonGroup group = new ButtonGroup();
          MultiViewPerspective[] pers = handler.getPerspectives();
          final String[] names = new String[pers.length];
          for (int i = 0; i < pers.length; i++) {
            MultiViewPerspective thisPers = pers[i];

            JRadioButtonMenuItem item = new JRadioButtonMenuItem();
            names[i] = thisPers.getDisplayName();
            Mnemonics.setLocalizedText(item, thisPers.getDisplayName());
            item.setActionCommand(thisPers.getDisplayName());
            item.addActionListener(
                new ActionListener() {
                  public void actionPerformed(ActionEvent event) {
                    MultiViewHandler handler = MultiViews.findMultiViewHandler(tc);
                    if (handler == null) {
                      return;
                    }
                    MultiViewPerspective thisPers = null;
                    MultiViewPerspective[] pers = handler.getPerspectives();
                    assert pers.length == names.length : "Arrays must have the same length";
                    for (int i = 0; i < pers.length; i++) {
                      if (event.getActionCommand().equals(names[i])) {
                        thisPers = pers[i];
                        break;
                      }
                    }
                    if (thisPers != null) {
                      handler.requestActive(thisPers);
                    }
                  }
                });
            if (thisPers
                .getDisplayName()
                .equals(handler.getSelectedPerspective().getDisplayName())) {
              item.setSelected(true);
            }
            group.add(item);
            add(item);
          }
        } else { // handler == null
          // No reason to enable action on any TC because now it was enabled even for Welcome page
          setEnabled(false);
          /*JRadioButtonMenuItem but = new JRadioButtonMenuItem();
          Mnemonics.setLocalizedText(but, NbBundle.getMessage(EditorsAction.class, "EditorsAction.source"));
          but.setSelected(true);
          add(but);*/
        }
      } else { // tc == null
        setEnabled(false);
      }
      return new JComponent[] {this};
    }
Ejemplo n.º 4
0
 /**
  * @param text
  * @param cmdName
  * @param group
  * @param icon
  * @return
  */
 public static JRadioButtonMenuItem createRadioMenuItem(
     String text, String cmdName, ButtonGroup group, ImageIcon icon) {
   JRadioButtonMenuItem item = new JRadioButtonMenuItem(text);
   item.setActionCommand(cmdName);
   if (group != null) {
     group.add(item);
   }
   if (icon != null) {
     item.setIcon(icon);
   }
   return item;
 }
Ejemplo n.º 5
0
 private static JMenu getMenu_ThemeOptions() {
   final JMenu menu = new JMenu("Theme");
   JRadioButtonMenuItem menuItem;
   final ButtonGroup group = new ButtonGroup();
   final String currentSkin = prefs.getPref(FPref.UI_SKIN);
   for (final String skin : FSkin.getAllSkins()) {
     menuItem = new JRadioButtonMenuItem(skin);
     group.add(menuItem);
     if (skin.equals(currentSkin)) {
       menuItem.setSelected(true);
     }
     menuItem.setActionCommand(skin);
     menuItem.addActionListener(changeSkin);
     menu.add(menuItem);
   }
   return menu;
 }
Ejemplo n.º 6
0
  private JMenu buildSubstanceMenu() {
    LookAndFeel lf = UIManager.getLookAndFeel();

    JMenu substanceMenu = new JMenu(rb.getString("Menu.SubstanceThemes.Name"));

    for (SkinInfo info : SubstanceLookAndFeel.getAllSkins().values()) {
      JRadioButtonMenuItem button = new JRadioButtonMenuItem();
      button.setText(info.getDisplayName());
      button.setActionCommand(info.getClassName());

      // add the button to the global look and feel
      lfButtonGroup.add(button);

      button.addActionListener(
          e -> {
            Preferences pref = Preferences.userNodeForPackage(ThemeManager.class);
            pref.put(LF, e.getActionCommand());

            restartUI();
          });

      substanceMenu.add(button);

      // select the button as the active L&F if it is the current skin
      if (lf instanceof SubstanceLookAndFeel) {
        if (SubstanceLookAndFeel.getCurrentSkin()
            .getClass()
            .getName()
            .equals(info.getClassName())) {
          button.setSelected(true);
        }
      }
    }

    return substanceMenu;
  }
Ejemplo n.º 7
0
  JMenu buildThemeMenu() {

    Preferences pref = Preferences.userNodeForPackage(ThemeManager.class);
    String currentTheme = pref.get(THEME, DEFAULT_THEME);

    themesMenu = new JMenu();
    themesMenu.setText(rb.getString("Menu.Themes.Name"));
    themesMenu.setMnemonic(jgnash.ui.util.Resource.getMnemonic("Menu.Themes.Mnemonic"));

    ButtonGroup themeButtonGroup = new ButtonGroup();
    buildThemeList();

    JRadioButtonMenuItem button;

    for (Object aThemeList : themeList) {
      MetalTheme theme = (MetalTheme) aThemeList;
      button = new JRadioButtonMenuItem();
      button.setText(theme.getName());
      button.setActionCommand(theme.getClass().getName());
      button.addActionListener(
          e -> {
            Preferences pref1 = Preferences.userNodeForPackage(ThemeManager.class);
            pref1.put(THEME, e.getActionCommand());

            restartUI();
          });

      themeButtonGroup.add(button);
      themesMenu.add(button);
      if (aThemeList.getClass().getName().equals(currentTheme)) {
        button.setSelected(true);
      }
    }
    refreshThemesState();
    return themesMenu;
  }
Ejemplo n.º 8
0
  private void constructPopup() {
    popup = new JPopupMenu();
    popup.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
    popup.setBackground(new Color(100, 100, 100));
    JMenuItem popupItemSaveImage = new JMenuItem("Save image");
    popupItemSaveImage.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            display.saveButtonPressed();
          }
        });
    popup.add(popupItemSaveImage);

    JMenuItem popupItemSaveNewick = new JMenuItem("Save newick");
    popupItemSaveNewick.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            display.saveNewickButtonPressed();
          }
        });
    popup.add(popupItemSaveNewick);

    JMenuItem popupItemRemove = new JMenuItem("Remove tree");
    popupItemRemove.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            display.removeButtonPressed();
          }
        });
    popup.add(popupItemRemove);

    JMenu orientMenu = new JMenu("Orientation");
    popup.add(orientMenu);

    ButtonGroup bg = new ButtonGroup();
    OrientationListener oListen = new OrientationListener();
    JRadioButtonMenuItem oRight = new JRadioButtonMenuItem("Right");
    oRight.addActionListener(oListen);
    oRight.setSelected(true);
    orientMenu.add(oRight);
    oRight.setActionCommand("Right");
    bg.add(oRight);
    JRadioButtonMenuItem oLeft = new JRadioButtonMenuItem("Left");
    oLeft.addActionListener(oListen);
    orientMenu.add(oLeft);
    oLeft.setActionCommand("Left");
    bg.add(oLeft);
    JRadioButtonMenuItem oUp = new JRadioButtonMenuItem("Up");
    oUp.addActionListener(oListen);
    oUp.setActionCommand("Up");
    orientMenu.add(oUp);
    bg.add(oUp);
    JRadioButtonMenuItem oDown = new JRadioButtonMenuItem("Down");
    oDown.addActionListener(oListen);
    oDown.setActionCommand("Down");
    orientMenu.add(oDown);
    bg.add(oDown);

    PopupListener popListener = new PopupListener();
    this.addMouseListener(popListener);
  }
Ejemplo n.º 9
0
  public PuzzelHA() {

    window = new JFrame("PuzzelHA");
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // window.setSize(800, 600);

    // -----------------Menü erstellen---------------------------------------
    JMenuBar menu = new JMenuBar();
    menu.setBorder(new LineBorder(Color.BLACK, 1));

    JMenu spiel = new JMenu("Spiel");
    JMenuItem reset = new JMenuItem("Reset");
    reset.addActionListener(this);
    reset.setActionCommand("reset");
    spiel.add(reset);

    JMenu ansicht = new JMenu("Ansicht");
    JMenu bild = new JMenu("BildNr.");
    ansicht.add(bild);
    ButtonGroup bg1 = new ButtonGroup();

    for (int j = 1; j <= bilder.size(); j++) {
      JRadioButtonMenuItem bn = new JRadioButtonMenuItem("" + j);
      bn.setName("" + j);
      bn.setActionCommand("b");
      bn.addActionListener(this);
      bg1.add(bn);
      bild.add(bn);
    }

    // --------------RadioButtons für Puzzelgröße----------------------------------
    JMenu pg = new JMenu("Puzzelgröße");
    ansicht.add(pg);
    ButtonGroup bg2 = new ButtonGroup();
    JRadioButtonMenuItem pgb1 = new JRadioButtonMenuItem("2x3");
    pgb1.setActionCommand("g1");
    pgb1.addActionListener(this);
    bg2.add(pgb1);
    pg.add(pgb1);

    for (int i = 2; i <= 4; i++) {
      JRadioButtonMenuItem pgb = new JRadioButtonMenuItem("" + (i * 2) + "x" + (i * 2 - 1));
      pgb.setActionCommand("g" + i);
      pgb.addActionListener(this);
      bg2.add(pgb);
      pg.add(pgb);
    }

    JMenu help = new JMenu("?");
    JMenuItem info = new JMenuItem("Info");
    info.addActionListener(this);
    info.setActionCommand("?");
    help.add(info);

    menu.add(spiel);
    menu.add(ansicht);
    menu.add(help);
    window.add(menu);
    window.setJMenuBar(menu);

    // ---------------- Menü END-------------------------------------

    baueButton();

    window.setResizable(false);
    window.setLocationRelativeTo(null);
    window.pack();
    window.setVisible(true);
  }
Ejemplo n.º 10
0
  /**
   * Get an instance of a {@link JPopupMenu} for a given {@link VPathwayElement}
   *
   * @param e The {@link VPathwayElement} to create the popup menu for. If e is an instance of
   *     {@link Handle}, the menu is based on the parent element.
   * @return The {@link JPopupMenu} for the given pathway element
   */
  private JPopupMenu getMenuInstance(SwingEngine swingEngine, VPathwayElement e) {
    if (e instanceof Citation) return null;

    JMenu pathLitRef = null;
    if (e instanceof Handle) {
      e = ((Handle) e).getParent();
      pathLitRef = new JMenu("Literature for pathway");
    }

    VPathway vp = e.getDrawing();
    VPathwaySwing component = (VPathwaySwing) vp.getWrapper();
    ViewActions vActions = vp.getViewActions();

    JPopupMenu menu = new JPopupMenu();

    // Don't show delete if the element cannot be deleted
    if (!(e instanceof InfoBox)) {
      menu.add(vActions.delete1);
    }

    JMenu selectMenu = new JMenu("Select");
    selectMenu.add(vActions.selectAll);
    selectMenu.add(vActions.selectDataNodes);
    selectMenu.add(vActions.selectInteractions);
    selectMenu.add(vActions.selectLines);
    selectMenu.add(vActions.selectShapes);
    selectMenu.add(vActions.selectLabels);
    menu.add(selectMenu);
    menu.addSeparator();

    // new feature to copy and paste with the right-click menu
    menu.add(vActions.copy);

    PositionPasteAction a = vActions.positionPaste;
    Point loc = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(loc, component);
    a.setPosition(loc);

    menu.add(a);
    menu.addSeparator();

    // Only show group/ungroup when multiple objects or a group are selected
    if ((e instanceof Group)) {
      GroupStyle s = ((Group) e).getPathwayElement().getGroupStyle();
      if (s == GroupStyle.GROUP) {
        menu.add(vActions.toggleGroup);
      } else {
        menu.add(vActions.toggleComplex);
      }
      menu.addSeparator();
    } else if (vp.getSelectedGraphics().size() > 1) {
      menu.add(vActions.toggleGroup);
      menu.add(vActions.toggleComplex);
    }

    if (e instanceof GeneProduct) {
      menu.add(vActions.addState);
    }
    if (e instanceof State) {
      menu.add(vActions.removeState);
    }

    if ((e instanceof Line)) {
      final Line line = (Line) e;

      menu.add(vActions.addAnchor);

      if (line.getPathwayElement().getConnectorType() == ConnectorType.SEGMENTED) {
        menu.add(vActions.addWaypoint);
        menu.add(vActions.removeWaypoint);
      }

      JMenu typeMenu = new JMenu("Line type");

      ButtonGroup buttons = new ButtonGroup();

      ActionListener listener =
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              line.getPathwayElement()
                  .setConnectorType(ConnectorType.fromName(e.getActionCommand()));
            }
          };
      for (ConnectorType t : ConnectorType.getValues()) {
        JRadioButtonMenuItem mi = new JRadioButtonMenuItem(t.getName());
        mi.setActionCommand(t.getName());
        mi.setSelected(t.equals(line.getPathwayElement().getConnectorType()));
        mi.addActionListener(listener);
        typeMenu.add(mi);
        buttons.add(mi);
      }
      menu.add(typeMenu);
    }

    if ((e instanceof VAnchor)) {
      final VAnchor anchor = ((VAnchor) e);

      JMenu anchorMenu = new JMenu("Anchor type");
      ButtonGroup buttons = new ButtonGroup();

      ActionListener listener =
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              anchor.getMAnchor().setShape(AnchorType.fromName(e.getActionCommand()));
            }
          };

      for (AnchorType at : AnchorType.getValues()) {
        JRadioButtonMenuItem mi = new JRadioButtonMenuItem(at.getName());
        mi.setActionCommand(at.getName());
        mi.setSelected(at.equals(anchor.getMAnchor().getShape()));
        mi.addActionListener(listener);
        anchorMenu.add(mi);
        buttons.add(mi);
      }

      menu.add(anchorMenu);
    }

    JMenu orderMenu = new JMenu("Order");
    orderMenu.add(vActions.orderBringToFront);
    orderMenu.add(vActions.orderSendToBack);
    orderMenu.add(vActions.orderUp);
    orderMenu.add(vActions.orderDown);
    menu.add(orderMenu);

    if (e instanceof Graphics) {
      JMenu litMenu = new JMenu("Literature");
      litMenu.add(new AddLiteratureAction(swingEngine, component, e));
      litMenu.add(new EditLiteratureAction(swingEngine, component, e));
      menu.add(litMenu);

      menu.addSeparator();
      menu.add(new PropertiesAction(swingEngine, component, e));
    }

    if (pathLitRef != null) {
      menu.addSeparator();
      pathLitRef.add(
          new AddLiteratureAction(
              swingEngine, component, swingEngine.getEngine().getActiveVPathway().getMappInfo()));
      pathLitRef.add(
          new EditLiteratureAction(
              swingEngine, component, swingEngine.getEngine().getActiveVPathway().getMappInfo()));
      menu.add(pathLitRef);
    }

    // give plug-ins a chance to add menu items.
    for (PathwayElementMenuHook hook : hooks) {
      hook.pathwayElementMenuHook(e, menu);
    }

    return menu;
  }