Exemplo n.º 1
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);
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
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;
  }
  /** Creates a menu bar. */
  protected JMenuBar createMenuBar() {
    JMenu fileMenu = new JMenu("File");
    JMenuItem menuItem;

    menuItem = new JMenuItem("Open");
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            JFileChooser fc = new JFileChooser(path);
            int result = fc.showOpenDialog(frame);

            if (result == JFileChooser.APPROVE_OPTION) {
              String newPath = fc.getSelectedFile().getPath();

              new ComponentTree(newPath);
            }
          }
        });
    fileMenu.add(menuItem);
    fileMenu.addSeparator();

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

    // Create a menu bar
    JMenuBar menuBar = new JMenuBar();

    menuBar.add(fileMenu);

    // Menu for the look and feels (lafs).
    UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();
    ButtonGroup lafGroup = new ButtonGroup();

    JMenu optionsMenu = new JMenu("Options");

    menuBar.add(optionsMenu);

    for (int i = 0; i < lafs.length; i++) {
      JRadioButtonMenuItem rb = new JRadioButtonMenuItem(lafs[i].getName());
      optionsMenu.add(rb);
      rb.setSelected(UIManager.getLookAndFeel().getName().equals(lafs[i].getName()));
      rb.putClientProperty("UIKey", lafs[i]);
      rb.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent ae) {
              JRadioButtonMenuItem rb2 = (JRadioButtonMenuItem) ae.getSource();
              if (rb2.isSelected()) {
                UIManager.LookAndFeelInfo info =
                    (UIManager.LookAndFeelInfo) rb2.getClientProperty("UIKey");
                try {
                  UIManager.setLookAndFeel(info.getClassName());
                  SwingUtilities.updateComponentTreeUI(frame);
                } catch (Exception e) {
                  System.err.println("unable to set UI " + e.getMessage());
                }
              }
            }
          });
      lafGroup.add(rb);
    }
    return menuBar;
  }