@Override
 public void actionPerformed(ActionEvent e) {
   int tamanyo = 14;
   try {
     if ((JComboBox) (e.getSource()) == comboTamanyo) {
       tamanyo = (int) ((JComboBox) e.getSource()).getSelectedItem();
       if (tamanyo == 10) jrdm10pt.setSelected(true);
       else if (tamanyo == 14) jrdm14pt.setSelected(true);
       else if (tamanyo == 18) jrdm18pt.setSelected(true);
       else if (tamanyo == 22) jrdm22pt.setSelected(true);
     }
   } catch (Exception ex) {
   }
   try {
     if ((JRadioButtonMenuItem) (e.getSource()) == jrdm10pt
         || (JRadioButtonMenuItem) (e.getSource()) == jrdm14pt
         || (JRadioButtonMenuItem) (e.getSource()) == jrdm18pt
         || (JRadioButtonMenuItem) (e.getSource()) == jrdm22pt) {
       tamanyo = Integer.parseInt(((JRadioButtonMenuItem) e.getSource()).getText());
       comboTamanyo.setSelectedItem(tamanyo);
     }
   } catch (Exception ex) {
   }
   // Establecemos la acción que queremos que haga cuando se cambie
   Action accion = new StyledEditorKit.FontSizeAction("Tamaño", tamanyo);
   // Hacemos que la accion ejecute el actionPerformand
   accion.actionPerformed(e);
   jtaTexto.requestFocus();
 }
Пример #2
0
  @Override
  public void update() {
    super.update();

    restrictDoorOptions();

    north.setSelected(zone.hasDoor(ZoneModel.NORTH));
    east.setSelected(zone.hasDoor(ZoneModel.EAST));
    south.setSelected(zone.hasDoor(ZoneModel.SOUTH));
    west.setSelected(zone.hasDoor(ZoneModel.WEST));
  }
Пример #3
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;
 }
Пример #4
0
  /** Return a menu for DesktopWindow and add a special listener. */
  public static JMenu getCurrencyMenu(ActionListener listener) {
    JRadioButtonMenuItem menuItem;
    String defaultCurrency = Money.getCurrencyFor(Money.getDefaultCurrency());

    JMenu menu = new JMenu("Währung");
    ButtonGroup group = new ButtonGroup();

    JMenu europeanMenu = new JMenu("Europa");
    String europeanCurrencies[] = Money.getEuropeanCurrencyList();

    for (int i = 0; i < europeanCurrencies.length; i++) {
      menuItem = new RadioCurrencyMenuItem(europeanCurrencies[i]);
      menuItem.addActionListener(listener);
      europeanMenu.add(menuItem);

      group.add(menuItem);

      if (europeanCurrencies[i].startsWith(defaultCurrency)) {
        menuItem.setSelected(true);
      }

      if (i == 0) {
        europeanMenu.addSeparator();
      }
    }

    menu.add(europeanMenu);

    return menu;
  }
Пример #5
0
  public void changeDictionary(String strLanguage) {
    // Change dictionary
    MonitorDictionary.setCurrentLanguage(strLanguage);
    DefaultDictionary.setCurrentLanguage(strLanguage);
    ErrorDictionary.setCurrentLanguage(strLanguage);

    // Update UI
    updateLanguage();
    WindowManager.updateLanguage();
    int iIndex = mvtLanguage.indexOf(strLanguage);
    if (iIndex >= 0) {
      JRadioButtonMenuItem mnu = (JRadioButtonMenuItem) mvtLanguageItem.elementAt(iIndex);
      mnu.setSelected(true);
    }

    // Store config
    Hashtable prt = null;
    try {
      prt = Global.loadHashtable(Global.FILE_CONFIG);
    } catch (Exception e) {
      prt = new Hashtable();
    }
    prt.put("Language", strLanguage);
    try {
      Global.storeHashtable(prt, Global.FILE_CONFIG);
    } catch (Exception e) {
    }
  }
Пример #6
0
  /** Populate searchers. */
  private void populateSearchers() {
    JMenu searchersMenu = this.searchersMenu;
    searchersMenu.removeAll();
    final ToolsSettings settings = ToolsSettings.getInstance();
    Collection<SearchEngine> searchEngines = settings.getSearchEngines();
    SearchEngine selectedEngine = settings.getSelectedSearchEngine();
    if (searchEngines != null) {
      for (SearchEngine se : searchEngines) {
        final SearchEngine finalSe = se;
        JRadioButtonMenuItem item = new JRadioButtonMenuItem();
        item.setAction(
            new AbstractAction() {

              private static final long serialVersionUID = 1L;

              @Override
              public void actionPerformed(ActionEvent e) {
                settings.setSelectedSearchEngine(finalSe);
                settings.save();
                ComponentSource.this.updateSearchButtonTooltip();
              }
            });
        item.setSelected(se == selectedEngine);
        item.setText(se.getName());
        item.setToolTipText(se.getDescription());
        searchersMenu.add(item);
      }
    }
  }
Пример #7
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;
  }
Пример #8
0
  private void computeContents() {
    ButtonGroup bgroup = new ButtonGroup();
    bgroup.add(nullItem);

    removeAll();
    add(minimize);
    add(zoom);
    add(close);

    if (!persistentItems.isEmpty()) {
      addSeparator();
      for (JRadioButtonMenuItem item : persistentItems) {
        bgroup.add(item);
        add(item);
      }
    }

    if (!transientItems.isEmpty()) {
      addSeparator();
      for (JRadioButtonMenuItem item : transientItems) {
        bgroup.add(item);
        add(item);
      }
    }

    WindowMenuItemManager currentManager = WindowMenuManager.getCurrentManager();
    if (currentManager != null) {
      JRadioButtonMenuItem item = currentManager.getMenuItem(this);
      if (item != null) {
        item.setSelected(true);
      }
    }
  }
Пример #9
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};
    }
  /** Called when a choice was made in the numeric format combo box. */
  public void formatCombo_actionPerformed() {
    int selectedIndex = formatCombo.getSelectedIndex();
    switch (selectedIndex) {
      case HackController.DECIMAL_FORMAT:
        if (!decMenuItem.isSelected()) decMenuItem.setSelected(true);
        break;

      case HackController.HEXA_FORMAT:
        if (!hexaMenuItem.isSelected()) hexaMenuItem.setSelected(true);
        break;

      case HackController.BINARY_FORMAT:
        if (!binMenuItem.isSelected()) binMenuItem.setSelected(true);
        break;
    }

    notifyControllerListeners(ControllerEvent.NUMERIC_FORMAT_CHANGE, selectedIndex);
  }
  /** Called when a choice was made in the animation type combo box. */
  public void animationCombo_actionPerformed() {
    int selectedIndex = animationCombo.getSelectedIndex();
    switch (selectedIndex) {
      case HackController.DISPLAY_CHANGES:
        if (!partAnimMenuItem.isSelected()) partAnimMenuItem.setSelected(true);
        break;

      case HackController.ANIMATION:
        if (!fullAnimMenuItem.isSelected()) fullAnimMenuItem.setSelected(true);
        break;

      case HackController.NO_DISPLAY_CHANGES:
        if (!noAnimMenuItem.isSelected()) noAnimMenuItem.setSelected(true);
        break;
    }

    notifyControllerListeners(ControllerEvent.ANIMATION_MODE_CHANGE, new Integer(selectedIndex));
  }
Пример #12
0
 public void addRadioMenuItem(String name, String eventName, boolean isSelected) {
   JRadioButtonMenuItem newItem = new JRadioButtonMenuItem(name);
   newItem.addActionListener(this);
   if (isSelected == true) {
     newItem.setSelected(true);
   }
   this.currentButtonGroup.add(newItem);
   this.currentMenu.add(newItem);
   this.registerComponentEvent(newItem, eventName);
 }
  /*
   * Called before a popup menu is activated and is used to enable or
   * disable menu items according to the state of the activity.
   */
  public void preparePopupMenu() {
    super.preparePopupMenu();

    if (
    /*DataTypeUtils.getReferenceClass(getData()) != null
    && */ (((getActivity().getApplication() != null))
        || getActivity().getImplementationType().equals(ImplementationType.Manual))) {
      propertiesItem.setEnabled(true);
    } else {
      propertiesItem.setEnabled(false);
    }
    if (Direction.IN == direction) {
      inItem.setSelected(true);
    } else if (Direction.OUT == direction) {
      outItem.setSelected(true);
    } else if (Direction.IN_OUT == direction) {
      inoutItem.setSelected(true);
    }
  }
Пример #14
0
  public TreeMenu() {
    super("Tree");
    this.setMnemonic('t');

    JMenuItem expandAllNodesItem = new JMenuItem(expand);
    expandAllNodesItem.addActionListener(new TreeActionListener(TREE_EXPAND_ALL_NODES));
    this.add(expandAllNodesItem);

    collapseNonExpNodesItem = new JCheckBoxMenuItem(collapse);
    collapseNonExpNodesItem.setSelected(PaintConfig.inst().collapse_no_exp);
    collapseNonExpNodesItem.addActionListener(new TreeActionListener(TREE_COLLAPSE_NONEXP_NODES));
    this.add(collapseNonExpNodesItem);

    // Separator line
    this.addSeparator();

    JCheckBoxMenuItem useDistances = new JCheckBoxMenuItem(distance);
    useDistances.setSelected(PaintConfig.inst().use_distances);
    useDistances.addActionListener(new TreeActionListener(TREE_USE_DISTANCES));
    this.add(useDistances);

    JMenuItem scaleTree = new JMenuItem(scale);
    scaleTree.addActionListener(new ScaleTreeActionListener());
    this.add(scaleTree);

    // Separator line
    this.addSeparator();

    JMenu tree_ordering = new JMenu(order);
    species_order = new JRadioButtonMenuItem(species);
    JRadioButtonMenuItem top_order = new JRadioButtonMenuItem(ladder_top);
    JRadioButtonMenuItem bottom_order = new JRadioButtonMenuItem(ladder_bottom);

    species_order.setSelected(true);

    ButtonGroup group = new ButtonGroup();
    group.add(species_order);
    group.add(top_order);
    group.add(bottom_order);

    species_order.addItemListener(new TreeReorderListener(TREE_SPECIES));
    top_order.addItemListener(new TreeReorderListener(TREE_TOP));
    bottom_order.addItemListener(new TreeReorderListener(TREE_BOTTOM));

    tree_ordering.add(species_order);
    tree_ordering.add(top_order);
    tree_ordering.add(bottom_order);

    this.add(tree_ordering);

    EventManager.inst().registerFamilyListener(this);
    EventManager.inst().registerNodeReorderListener(this);
  }
Пример #15
0
  /** Initialize and update the items. */
  @Override
  public void initItems() {
    if (!initialized) {
      return;
    }

    removeAll();
    JMenuItem mit = add(newWindowAction);
    setMenuShortCutAccelerator(mit, 'N');

    ArrayList<GeoGebraFrame> ggbInstances = GeoGebraFrame.getInstances();
    int size = ggbInstances.size();
    if (size == 1) return;

    addSeparator();
    StringBuilder sb = new StringBuilder();
    ButtonGroup bg = new ButtonGroup();
    JRadioButtonMenuItem mi;

    int current = -1;

    for (int i = 0; i < size; i++) {
      GeoGebraFrame ggb = ggbInstances.get(i);
      AppD application = ggb.getApplication();
      if (app == application) current = i;
    }

    for (int i = 0; i < size; i++) {
      GeoGebraFrame ggb = ggbInstances.get(i);
      AppD application = ggb.getApplication();

      sb.setLength(0);
      sb.append(i + 1);
      if (application != null) // Michael Borcherds 2008-03-03 bugfix
      if (application.getCurrentFile() != null) {
          sb.append(" ");
          sb.append(application.getCurrentFile().getName());
        }

      mi = new JRadioButtonMenuItem(sb.toString());
      if (application == this.app) mi.setSelected(true);
      ActionListener al = new RequestFocusListener(ggb);
      mi.addActionListener(al);
      if (i == ((current + 1) % size)) setMenuShortCutShiftAccelerator(mi, 'N');
      else if (i == ((current - 1 + size) % size)) setMenuShortCutShiftAltAccelerator(mi, 'N');
      bg.add(mi);
      add(mi);
    }

    // support for right-to-left languages
    app.setComponentOrientation(this);
  }
Пример #16
0
  private JMenuBar createMenuBar() {
    JMenu menu = new JMenu("Menu");

    disablingItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.ALT_MASK));

    menu.add(disablingItem);
    menu.addSeparator();

    blurItem.setSelected(true);
    blurItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, InputEvent.ALT_MASK));
    menu.add(blurItem);

    embossItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, InputEvent.ALT_MASK));
    menu.add(embossItem);

    busyPainterItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, InputEvent.ALT_MASK));
    menu.add(busyPainterItem);

    ButtonGroup group = new ButtonGroup();
    group.add(blurItem);
    group.add(embossItem);
    group.add(busyPainterItem);

    ItemListener menuListener =
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            if (blurItem.isSelected()) {
              //                    layer.setUI(blurUI);
            } else if (embossItem.isSelected()) {
              //                    layer.setUI(embossUI);
            } else if (busyPainterItem.isSelected()) {
              layer.setUI(busyPainterUI);
            }
          }
        };

    blurItem.addItemListener(menuListener);
    embossItem.addItemListener(menuListener);
    busyPainterItem.addItemListener(menuListener);

    //        embossUI.getUnlockButton().addActionListener(new ActionListener() {
    //            public void actionPerformed(ActionEvent e) {
    //                disablingItem.doClick();
    //            }
    //        });

    JMenuBar bar = new JMenuBar();
    bar.add(menu);

    bar.add(new LafMenu());
    return bar;
  }
Пример #17
0
  /**
   * create (if necessary) and return a menu that will change the mode
   *
   * @return the menu
   */
  @Override
  public JMenu getModeMenu() {
    if (modeMenu == null) {
      modeMenu = new JMenu(); // {
      Icon icon = BasicIconFactory.getMenuArrowIcon();
      modeMenu.setIcon(BasicIconFactory.getMenuArrowIcon());
      modeMenu.setPreferredSize(new Dimension(icon.getIconWidth() + 10, icon.getIconHeight() + 10));

      final JRadioButtonMenuItem transformingButton =
          new JRadioButtonMenuItem(Mode.TRANSFORMING.toString());
      transformingButton.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
              if (e.getStateChange() == ItemEvent.SELECTED) {
                setMode(Mode.TRANSFORMING);
              }
            }
          });

      final JRadioButtonMenuItem pickingButton = new JRadioButtonMenuItem(Mode.PICKING.toString());
      pickingButton.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
              if (e.getStateChange() == ItemEvent.SELECTED) {
                setMode(Mode.PICKING);
              }
            }
          });

      ButtonGroup radio = new ButtonGroup();
      radio.add(transformingButton);
      radio.add(pickingButton);
      transformingButton.setSelected(true);
      modeMenu.add(transformingButton);
      modeMenu.add(pickingButton);
      modeMenu.setToolTipText("Menu for setting Mouse Mode");
      addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
              if (e.getStateChange() == ItemEvent.SELECTED) {
                if (e.getItem() == Mode.TRANSFORMING) {
                  transformingButton.setSelected(true);
                } else if (e.getItem() == Mode.PICKING) {
                  pickingButton.setSelected(true);
                }
              }
            }
          });
    }
    return modeMenu;
  }
Пример #18
0
  /**
   * Creates and returns a new swing radio button menu item
   *
   * @param name the name of the menu item
   * @throws MissingResourceException if one of the keys that compose the menu item is missing. It
   *     is not thrown if the mnemonic, the accelerator and the action keys are missing
   * @throws ResourceFormatException if the mnemonic is not a single character.
   * @throws MissingListenerException if then item action is not found in the action map.
   */
  public JRadioButtonMenuItem createJRadioButtonMenuItem(String name)
      throws MissingResourceException, ResourceFormatException, MissingListenerException {
    JRadioButtonMenuItem result;
    result = new JRadioButtonMenuItem(getString(name + TEXT_SUFFIX));
    initializeJMenuItem(result, name);

    // is the item selected?
    try {
      result.setSelected(getBoolean(name + SELECTED_SUFFIX));
    } catch (MissingResourceException e) {
    }

    return result;
  }
  /** Called when a choice was made in the additional display combo box. */
  public void additionalDisplayCombo_actionPerformed() {
    int selectedIndex = additionalDisplayCombo.getSelectedIndex();
    switch (selectedIndex) {
      case HackController.SCRIPT_ADDITIONAL_DISPLAY:
        if (!scriptMenuItem.isSelected()) scriptMenuItem.setSelected(true);
        break;

      case HackController.OUTPUT_ADDITIONAL_DISPLAY:
        if (!outputMenuItem.isSelected()) outputMenuItem.setSelected(true);
        break;

      case HackController.COMPARISON_ADDITIONAL_DISPLAY:
        if (!compareMenuItem.isSelected()) compareMenuItem.setSelected(true);
        break;

      case HackController.NO_ADDITIONAL_DISPLAY:
        if (!noAdditionalDisplayMenuItem.isSelected())
          noAdditionalDisplayMenuItem.setSelected(true);
        break;
    }

    notifyControllerListeners(
        ControllerEvent.ADDITIONAL_DISPLAY_CHANGE, new Integer(selectedIndex));
  }
  protected JMenu buildSpeedMenu() {
    JMenu speed = new JMenu("Drag");

    JRadioButtonMenuItem live = new JRadioButtonMenuItem("Live");
    JRadioButtonMenuItem outline = new JRadioButtonMenuItem("Outline");

    JRadioButtonMenuItem slow = new JRadioButtonMenuItem("Old and Slow");

    ButtonGroup group = new ButtonGroup();

    group.add(live);
    group.add(outline);
    group.add(slow);

    live.setSelected(true);

    slow.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // for right now I'm saying if you set the mode
            // to something other than a specified mode
            // it will revert to the old way
            // This is mostly for comparison's sake
            desktop.setDragMode(-1);
          }
        });

    live.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            desktop.setDragMode(JDesktopPane.LIVE_DRAG_MODE);
          }
        });

    outline.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
          }
        });

    speed.add(live);
    speed.add(outline);
    speed.add(slow);
    return speed;
  }
Пример #21
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;
 }
Пример #22
0
 /**
  * This method initializes jRadioButtonMenuItem
  *
  * @return JRadioButtonMenuItem
  */
 private JRadioButtonMenuItem getJRadioButtonMenuItem() {
   if (jRadioButtonMenuItem == null) {
     jRadioButtonMenuItem = new JRadioButtonMenuItem();
     jRadioButtonMenuItem.setText("Default");
     jRadioButtonMenuItem.setSelected(true);
     jRadioButtonMenuItem.setAccelerator(
         javax.swing.KeyStroke.getKeyStroke(
             java.awt.event.KeyEvent.VK_D, java.awt.Event.ALT_MASK, false));
     jRadioButtonMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_D);
     jRadioButtonMenuItem.addActionListener(
         new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent e) {
             changeLnF(UIManager.getCrossPlatformLookAndFeelClassName());
           }
         });
   }
   return jRadioButtonMenuItem;
 }
Пример #23
0
  public void chargerLaf() {
    MD_Laf.removeAll();
    // Groupe
    SC_RadioLaf = new ButtonGroup();

    // Look And Feel
    for (int i = 0; i < UIManager.getInstalledLookAndFeels().length; i++) {
      // Création d'un bouton radio
      JRadioButtonMenuItem OO_LookAndFeel =
          new JRadioButtonMenuItem(UIManager.getInstalledLookAndFeels()[i].getName());
      // Ajout au groupe
      SC_RadioLaf.add(OO_LookAndFeel);
      // Ajout du listener
      OO_LookAndFeel.addActionListener(actionLaf);
      // Si le look and feel courant correspond à l'élément
      if (OO_LookAndFeel.getText().equals(UIManager.getLookAndFeel().getName()))
        OO_LookAndFeel.setSelected(true);
      // Ajout au panel
      MD_Laf.add(OO_LookAndFeel);
    }
  }
Пример #24
0
 public void chargerLangue() {
   MD_Langue.removeAll();
   // Groupe
   SC_Radios = new ButtonGroup();
   // Radios langue
   for (int i = 0; i < Bundle.getLanguesDisponibles().size(); i++) {
     // Récupération de la première des langues disponibles
     String langue = Bundle.getLanguesDisponibles().elementAt(i).toString();
     // Récupération de la langue courante
     String langueCourante = Bundle.getLangueCourante();
     // Création d'un bouton radio
     JRadioButtonMenuItem OO_Langue = new JRadioButtonMenuItem(langue);
     // Ajout au groupe
     SC_Radios.add(OO_Langue);
     // Ajout du listener
     OO_Langue.addActionListener(actionLangue);
     // Si la langue courante correspond à l'élément
     if (langueCourante.equals(langue)) OO_Langue.setSelected(true);
     // Ajout au panel
     MD_Langue.add(OO_Langue);
   }
 }
Пример #25
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;
  }
Пример #26
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;
  }
Пример #27
0
  private JMenuBar createJMenu() {
    System.out.println("Creating the JMenu...");

    JMenu algMenu = new JMenu("Algorithms");
    ButtonGroup g = new ButtonGroup();
    ricartAgrawala = new JRadioButtonMenuItem("Ricart-Agrawala Algorithm");
    modRicartAgrawala = new JRadioButtonMenuItem("Modified Ricart-Agrawala Algorithm");
    ricartAgrawala.setSelected(true);
    g.add(ricartAgrawala);
    g.add(modRicartAgrawala);

    ricartAgrawala.addActionListener(this);
    modRicartAgrawala.addActionListener(this);

    algMenu.add(ricartAgrawala);
    algMenu.add(modRicartAgrawala);

    JMenu demosMenu = new JMenu("Demos");
    demosMenu.add(algMenu);

    authorMenuItem = new JMenuItem("Authors");
    problemMenuItem = new JMenuItem("Problem Description");

    authorMenuItem.addActionListener(this);
    problemMenuItem.addActionListener(this);

    JMenu aboutMenu = new JMenu("About");
    aboutMenu.add(authorMenuItem);
    aboutMenu.add(problemMenuItem);

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(demosMenu);
    menuBar.add(aboutMenu);

    return menuBar;
  }
Пример #28
0
  private void jbInit() throws Exception {
    borderForProjectView = BorderFactory.createLineBorder(Color.black, 2);
    titleBoderForProjectView = new TitledBorder(borderForProjectView, "Project view");
    borderForEntitiesView = BorderFactory.createLineBorder(Color.black, 2);
    titledBorderForEntitiesView = new TitledBorder(borderForEntitiesView, "Entities view");
    titledBorderForMessagesPane =
        new TitledBorder(
            BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)), "Messages");
    this.getContentPane().setLayout(borderLayout2);
    file.setText("File");
    save.setEnabled(false);
    save.setText("Save");
    save.setName("Savefilemenu");
    save.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            save_actionPerformed(e);
          }
        });
    load.setText("Load");
    load.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            load_actionPerformed(e);
          }
        });
    this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    this.setJMenuBar(mainMenuBar);
    this.setTitle("INGENIAS Development Kit");
    this.setSize(625, 470);
    this.addWindowListener(
        new java.awt.event.WindowAdapter() {
          public void windowClosed(WindowEvent e) {
            this_windowClosed(e);
          }

          public void windowClosing(WindowEvent e) {
            this_windowClosing(e);
          }
        });
    splitPaneSeparatingProjectsAndEntitiesView.setOrientation(JSplitPane.VERTICAL_SPLIT);
    splitPaneSeparatingProjectsAndEntitiesView.setBottomComponent(scrollPaneForEntitiesView);
    splitPaneSeparatingProjectsAndEntitiesView.setTopComponent(scrollPaneForProyectView);
    jPanel1.setLayout(gridLayout1);
    arbolObjetos.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            arbolObjetos_mouseClicked(e);
          }
        });
    scrollPaneForProyectView.setAutoscrolls(true);
    scrollPaneForProyectView.setBorder(titleBoderForProjectView);
    scrollPaneForEntitiesView.setBorder(titledBorderForEntitiesView);
    edit.setText("Edit");
    copyImage.setText("Copy diagram as a file");
    copyImage.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            capture_actionPerformed(e);
          }
        });
    saveas.setText("Save as");
    saveas.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            saveas_actionPerformed(e);
          }
        });
    help.setText("Help");
    manual.setText("Tool manual");
    manual.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            manual_actionPerformed(e);
          }
        });
    about.setText("About");
    about.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            about_actionPerformed(e);
          }
        });
    project.setText("Project");
    copy.setText("Copy");
    copy.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            copy_actionPerformed(e);
          }
        });
    paste.setText("Paste");
    paste.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            paste_actionPerformed(e);
          }
        });
    exit.setText("Exit");
    exit.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            exit_actionPerformed(e);
          }
        });
    splitPanelDiagramMessagesPaneSeparator.setOrientation(JSplitPane.VERTICAL_SPLIT);
    splitPanelDiagramMessagesPaneSeparator.setLastDividerLocation(150);
    pprin.setLayout(new BorderLayout());
    pprin.setName("DiagramPane");
    pprin.setPreferredSize(new Dimension(400, 300));
    pprin.add(BorderLayout.SOUTH, pbar);
    pbar.setVisible(false);
    jSplitPane1.setOrientation(JSplitPane.HORIZONTAL_SPLIT);

    scrollLogs.setBorder(titledBorderForMessagesPane);
    scrollLogs.addKeyListener(
        new java.awt.event.KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            jScrollPane3_keyPressed(e);
          }
        });
    this.clearMessages.setText("Clear");
    clearMessages.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            clearMessages_actionPerformed(e, (JTextPane) messagesMenu.getInvoker());
          }
        });
    forcegc.setText("Force GC");
    forcegc.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            forcegc_actionPerformed(e);
          }
        });

    menuTools.setText("Tools");
    menuCodeGenerator.setText("Code Generator");
    profiles.setText("Profiles");

    menuModules.setText("Modules");
    this.properties.setText("Properties");
    properties.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            properties_actionPerformed(e);
          }
        });
    moutput.setEditable(false);
    moutput.setSelectionStart(0);
    moutput.setText("");
    moduleOutput.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            moduleOutput_mouseClicked(e);
          }
        });
    moduleOutput.setFont(new java.awt.Font("Monospaced", 0, 11));
    logs.setContentType("text/html");
    logs.setEditable(false);
    logs.setText("");
    logs.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            logs_mouseClicked(e);
          }
        });
    logs.addComponentListener(
        new java.awt.event.ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            logs_componentResized(e);
          }
        });
    newProject.setText("New");
    newProject.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            newProject_actionPerformed(e);
          }
        });
    undo.setText("Undo");
    undo.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            undo_actionPerformed(e);
          }
        });
    redo.setText("Redo");
    redo.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            redo_actionPerformed(e);
          }
        });
    delete.setText("Delete");
    delete.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            delete_actionPerformed(e);
          }
        });
    selectall.setText("Select all");
    selectall.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            selectall_actionPerformed(e);
          }
        });
    cpClipboard.setText("Copy diagram to clipboard");
    cpClipboard.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            cpClipboard_actionPerformed(e);
          }
        });
    preferences.setText("Preferences");

    enableUMLView.setToolTipText("UML view" + "instead of its type");
    enableUMLView.setText("Enable UML view from now on");
    enableUMLView.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            enableUMLView_actionPerformed(e);
          }
        });
    enableINGENIASView.setToolTipText("INGENIAS view");
    enableINGENIASView.setText("Enable INGENIAS view from now on");
    enableINGENIASView.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            enableINGENIASView_actionPerformed(e);
          }
        });

    switchINGENIASView.setToolTipText("Switch to INGENIAS view");
    switchINGENIASView.setText("Switch to INGENIAS view");
    switchINGENIASView.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            switchINGENIASView_actionPerformed(e);
          }
        });

    switchUMLView.setToolTipText("Switch to UML view");
    switchUMLView.setText("Switch to UML view");
    switchUMLView.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            switchUMLView_actionPerformed(e);
          }
        });

    resizeAll.setToolTipText("Resize all");
    resizeAll.setText("Resize all entities within current diagram");
    resizeAll.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            resizeAll_actionPerformed(e);
          }
        });

    resizeAllDiagrams.setToolTipText("Resize all diagrams");
    resizeAllDiagrams.setText("Resize all entities within all defined diagram");
    resizeAllDiagrams.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            resizeAllDiagrams_actionPerformed(e);
          }
        });

    JMenuItem workspaceEntry = new JMenuItem("Switch workspace");
    workspaceEntry.setToolTipText("Change current workspace");
    workspaceEntry.setText("Switch workspace");
    workspaceEntry.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            changeWorkspace(e);
          }
        });
    preferences.add(workspaceEntry);
    preferences.add(resizeAll);
    preferences.add(resizeAllDiagrams);
    {
      elimOverlap = new JMenuItem();
      preferences.add(elimOverlap);
      elimOverlap.setText("Eliminate overlap");
      elimOverlap.setAccelerator(KeyStroke.getKeyStroke("F3"));
      elimOverlap.addMenuKeyListener(
          new MenuKeyListener() {
            public void menuKeyPressed(MenuKeyEvent evt) {
              System.out.println("elimOverlap.menuKeyPressed, event=" + evt);
              // TODO add your code for elimOverlap.menuKeyPressed
            }

            public void menuKeyReleased(MenuKeyEvent evt) {
              System.out.println("elimOverlap.menuKeyReleased, event=" + evt);
              // TODO add your code for elimOverlap.menuKeyReleased
            }

            public void menuKeyTyped(MenuKeyEvent evt) {
              elimOverlapMenuKeyTyped(evt);
            }
          });
      elimOverlap.addKeyListener(
          new KeyAdapter() {
            public void keyPressed(KeyEvent evt) {
              elimOverlapKeyPressed(evt);
            }
          });
      elimOverlap.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              elimOverlapActionPerformed(evt);
            }
          });
    }
    {
      modelingLanguageNotationSwitchMenu = new JMenu();
      preferences.add(modelingLanguageNotationSwitchMenu);
      modelingLanguageNotationSwitchMenu.setText("Modelling language");
      modelingLanguageNotationSwitchMenu.add(enableINGENIASView);

      viewSelection.add(enableINGENIASView);
      modelingLanguageNotationSwitchMenu.add(enableUMLView);
      viewSelection.add(enableUMLView);

      enableINGENIASView.setSelected(true);
      modelingLanguageNotationSwitchMenu.add(switchUMLView);
      modelingLanguageNotationSwitchMenu.add(switchINGENIASView);
    }
    {
      propertiesModeMenu = new JMenu();
      preferences.add(propertiesModeMenu);
      propertiesModeMenu.setText("Edit Properties Mode");
      {
        editPopUpProperties = new JCheckBoxMenuItem();
        propertiesModeMenu.add(editPopUpProperties);
        editPopUpProperties.setText("Edit Properties in a PopUp Window");
        editPopUpProperties.setSelected(true);
        editPopUpProperties.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                editPopUpProperties_selected();
              }
            });
        propertiesEditModeSelection.add(editPopUpProperties);
      }
      {
        editOnMessages = new JCheckBoxMenuItem();
        propertiesModeMenu.add(editOnMessages);
        editOnMessages.setText("Edit Properties in Messages Panel");
        propertiesEditModeSelection.add(editOnMessages);
        editOnMessages.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                editOnMessages_selected();
              }
            });
      }
    }

    mainMenuBar.add(file);
    mainMenuBar.add(edit);
    mainMenuBar.add(project);
    mainMenuBar.add(menuModules);
    mainMenuBar.add(profiles);
    mainMenuBar.add(preferences);
    mainMenuBar.add(help);
    file.add(newProject);
    file.add(load);
    {
      importFile = new JMenuItem();
      file.add(importFile);
      importFile.setText("Import file");
      importFile.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              importFileActionPerformed(evt);
            }
          });
    }
    file.add(save);
    file.add(saveas);
    file.addSeparator();
    file.add(exit);
    file.addSeparator();
    rightPanel.setLayout(new BorderLayout());
    rightPanel.add(buttonModelPanel, BorderLayout.WEST);
    this.getContentPane().add(jSplitPane1, BorderLayout.CENTER);
    rightPanel.add(splitPanelDiagramMessagesPaneSeparator, BorderLayout.CENTER);
    jSplitPane1.add(splitPaneSeparatingProjectsAndEntitiesView, JSplitPane.LEFT);
    splitPaneSeparatingProjectsAndEntitiesView.add(scrollPaneForProyectView, JSplitPane.TOP);
    {
      jPanel2 = new JPanel();
      BorderLayout jPanel2Layout = new BorderLayout();
      jPanel2.setLayout(jPanel2Layout);
      splitPaneSeparatingProjectsAndEntitiesView.add(jPanel2, JSplitPane.BOTTOM);
      jPanel2.add(jPanel1, BorderLayout.SOUTH);
      jPanel2.add(scrollPaneForEntitiesView, BorderLayout.CENTER);
    }
    jSplitPane1.add(rightPanel, JSplitPane.RIGHT);
    splitPanelDiagramMessagesPaneSeparator.add(pprin, JSplitPane.TOP);
    splitPanelDiagramMessagesPaneSeparator.add(messagespane, JSplitPane.BOTTOM);
    JScrollPane scrollSearchDiagram = new JScrollPane();
    scrollSearchDiagram.getViewport().add(searchDiagramPanel, null);
    searchDiagramPanel.setContentType("text/html");
    searchDiagramPanel.setEditable(false);

    messagespane.addConventionalTab(scrollLogs, "Logs");
    scrollLogs.getViewport().add(logs, null);
    scrolloutput.getViewport().add(this.moduleOutput, null);
    messagespane.addConventionalTab(scrolloutput, "Module Output");
    messagespane.addConventionalTab(scrollSearchDiagram, "Search");
    scrolloutput.getViewport().add(moduleOutput, null);
    {
      searchPanel = new JPanel();
      FlowLayout searchPanelLayout = new FlowLayout();
      searchPanelLayout.setVgap(1);
      searchPanel.setLayout(searchPanelLayout);
      jPanel1.add(searchPanel, BorderLayout.SOUTH);
      searchPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
      {
        searchField = new JTextField();
        searchPanel.add(searchField);
        searchField.setColumns(15);

        searchField.addKeyListener(
            new KeyAdapter() {
              public void keyTyped(KeyEvent evt) {
                searchFieldKeyTyped(evt);
              }
            });
      }
      {
        Search = new JButton();
        scrollPaneForProyectView.setViewportView(arbolProyectos);
        scrollPaneForEntitiesView.setViewportView(arbolObjetos);
        searchPanel.add(Search);

        Search.setIcon(new ImageIcon(ImageLoader.getImage(("images/lense.png"))));
        //	Search.setPreferredSize(new java.awt.Dimension(20, 20));
        Search.setIconTextGap(0);
        Search.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                SearchActionPerformed(evt);
              }
            });
      }
    }
    edit.add(undo);
    edit.add(redo);
    edit.addSeparator();
    edit.add(copy);
    edit.add(paste);
    edit.add(delete);
    edit.add(selectall);
    edit.addSeparator();
    edit.add(copyImage);
    edit.add(cpClipboard);
    help.add(manual);
    help.add(about);
    help.add(forcegc);

    menuModules.add(menuTools);
    menuModules.add(menuCodeGenerator);
    messagesMenu.add(this.clearMessages);
    project.add(this.properties);

    project.addSeparator();
    jSplitPane1.setDividerLocation(250);
    splitPaneSeparatingProjectsAndEntitiesView.setDividerLocation(250);
    arbolProyectos.addMouseListener(
        new java.awt.event.MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            arbolProyectos_mouseClicked(e);
          }
        });
    splitPanelDiagramMessagesPaneSeparator.setDividerLocation(400);
  }
Пример #29
0
  public void buildMenuPanel() {
    // Menu
    menuBar = new JMenuBar();

    menuPanel = new JPanel();
    menuPanel.setLayout(new BorderLayout());
    menuPanel.add(menuBar, BorderLayout.NORTH);
    menuPanel.setVisible(true);
    menuPanel.setSize(400, 20);
    mainPanel.add(menuPanel);

    // File
    mFile = new JMenu("File");
    mFile.setMnemonic(KeyEvent.VK_F);
    menuBar.add(mFile);

    nextGame = new JMenuItem("New Game");
    nextGame.addActionListener(this);
    mFile.add(nextGame);

    reset = new JMenuItem("Reset Score");
    reset.addActionListener(this);
    mFile.add(reset);

    exit = new JMenuItem("Exit");
    exit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });
    mFile.add(exit);

    // Options
    mOptions = new JMenu("Game Options");
    mOptions.setMnemonic(KeyEvent.VK_O);
    menuBar.add(mOptions);

    // 1P 2P Selection RADIO--------------------
    pCount = new ButtonGroup();

    p1 = new JRadioButtonMenuItem("1 Player - Play against the computer");
    p1.addActionListener(this);
    p1.setSelected(true);
    pCount.add(p1);
    mOptions.add(p1);

    p2 = new JRadioButtonMenuItem("2 Player - Play with a friend");
    p2.addActionListener(this);
    pCount.add(p2);
    mOptions.add(p2);

    mOptions.addSeparator();
    // Player X O Selection RADIO--------------------
    xoSelect = new ButtonGroup();

    hx = new JRadioButtonMenuItem("Player 1 : X   - -   Player 2 : O");
    hx.addActionListener(this);
    hx.setSelected(true);
    xoSelect.add(hx);
    mOptions.add(hx);

    ho = new JRadioButtonMenuItem("Player 1 : O   - -   Player 2 : X");
    ho.addActionListener(this);

    xoSelect.add(ho);
    mOptions.add(ho);

    mOptions.addSeparator();

    // Player Skin Selection RADIO--------------------
    xoSkin = new ButtonGroup();

    plain = new JRadioButtonMenuItem("Traditional");
    plain.addActionListener(this);
    plain.setSelected(true);
    xoSkin.add(plain);
    mOptions.add(plain);

    fsu = new JRadioButtonMenuItem("FSU vs UF");
    fsu.addActionListener(this);
    xoSkin.add(fsu);
    mOptions.add(fsu);

    // Difficulty Selection
    mDiff = new JMenu("Difficulty");
    mDiff.setMnemonic(KeyEvent.VK_D);
    menuBar.add(mDiff);

    // Difficulty Selection Items
    diffSel = new ButtonGroup();

    easy = new JRadioButtonMenuItem("Easy");
    easy.setSelected(true);
    easy.addActionListener(this);
    diffSel.add(easy);
    mDiff.add(easy);

    hard = new JRadioButtonMenuItem("Hard");
    hard.addActionListener(this);
    diffSel.add(hard);
    mDiff.add(hard);

    impossible = new JRadioButtonMenuItem("Impossible");
    impossible.addActionListener(this);
    diffSel.add(impossible);
    mDiff.add(impossible);

    // About
    mAbout = new JMenu("About");
    mAbout.setMnemonic(KeyEvent.VK_A);
    menuBar.add(mAbout);

    info = new JMenuItem("About Me");
    info.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            printMessage("Tic Tac Toe\nCOP3252 Project 1\nJames Bach");
          }
        });
    mAbout.add(info);
  }
Пример #30
0
  /**
   * Creates the menu bar
   *
   * @return Description of the Return Value
   */
  public JMenuBar createMenuBar() {
    // Create the menu bar
    final JMenuBar menuBar = new JMenuBar();

    // Menu for all beans to demo
    JMenu componentsMenu = new JMenu("Components");
    componentsMenu.setMnemonic('C');

    menuBar.add(componentsMenu);

    for (int i = 0; i < beans.length; i++) {
      Icon icon;
      JMenuItem menuItem;

      try {
        URL iconURL =
            beans[i].getClass().getResource("images/" + beans[i].getName() + "Color16.gif");
        icon = new ImageIcon(iconURL);
        menuItem = new JMenuItem(beans[i].getName(), icon);
      } catch (Exception e) {
        System.out.println(
            "JCalendarDemo.createMenuBar(): "
                + e
                + " for URL: "
                + "images/"
                + beans[i].getName()
                + "Color16.gif");
        menuItem = new JMenuItem(beans[i].getName());
      }

      componentsMenu.add(menuItem);

      final JComponent bean = beans[i];
      ActionListener actionListener =
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              installBean(bean);
            }
          };

      menuItem.addActionListener(actionListener);
    }

    // Menu for the look and feels (lnfs).
    UIManager.LookAndFeelInfo[] lnfs = UIManager.getInstalledLookAndFeels();

    ButtonGroup lnfGroup = new ButtonGroup();
    JMenu lnfMenu = new JMenu("Look&Feel");
    lnfMenu.setMnemonic('L');

    menuBar.add(lnfMenu);

    for (int i = 0; i < lnfs.length; i++) {
      if (!lnfs[i].getName().equals("CDE/Motif")) {
        JRadioButtonMenuItem rbmi = new JRadioButtonMenuItem(lnfs[i].getName());
        lnfMenu.add(rbmi);

        // preselect the current Look & feel
        rbmi.setSelected(UIManager.getLookAndFeel().getName().equals(lnfs[i].getName()));

        // store lool & feel info as client property
        rbmi.putClientProperty("lnf name", lnfs[i]);

        // create and add the item listener
        rbmi.addItemListener(
            // inlining
            new ItemListener() {
              public void itemStateChanged(ItemEvent ie) {
                JRadioButtonMenuItem rbmi2 = (JRadioButtonMenuItem) ie.getSource();

                if (rbmi2.isSelected()) {
                  // get the stored look & feel info
                  UIManager.LookAndFeelInfo info =
                      (UIManager.LookAndFeelInfo) rbmi2.getClientProperty("lnf name");

                  try {
                    menuBar.putClientProperty("jgoodies.headerStyle", "Both");
                    UIManager.setLookAndFeel(info.getClassName());

                    // update the complete application's
                    // look & feel
                    SwingUtilities.updateComponentTreeUI(JCalendarDemo.this);
                    for (int i = 0; i < beans.length; i++) {
                      SwingUtilities.updateComponentTreeUI(beans[i]);
                    }
                    // set the split pane devider border to
                    // null
                    BasicSplitPaneDivider divider =
                        ((BasicSplitPaneUI) splitPane.getUI()).getDivider();

                    if (divider != null) {
                      divider.setBorder(null);
                    }
                  } catch (Exception e) {
                    e.printStackTrace();

                    System.err.println("Unable to set UI " + e.getMessage());
                  }
                }
              }
            });
        lnfGroup.add(rbmi);
      }
    }

    // the help menu
    JMenu helpMenu = new JMenu("Help");
    helpMenu.setMnemonic('H');

    JMenuItem aboutItem = helpMenu.add(new AboutAction(this));
    aboutItem.setMnemonic('A');
    aboutItem.setAccelerator(KeyStroke.getKeyStroke('A', java.awt.Event.CTRL_MASK));

    menuBar.add(helpMenu);

    return menuBar;
  }