public MyToolBar(final Hashtable<Integer, Action> actions) {
      super();

      add(new JButton(actions.get(SharedActions.ACTION1_KEY)));
      add(new JButton(actions.get(SharedActions.ACTION2_KEY)));

      JToggleButton btn = new JToggleButton(actions.get(SharedActions.ACTION3_KEY));
      SharedActions.registerToggleAction(btn, SharedActions.ACTION3_KEY);
      add(btn);

      btn = new JToggleButton(actions.get(SharedActions.ACTION4_KEY));
      SharedActions.registerToggleAction(btn, SharedActions.ACTION4_KEY);
      add(btn);
    }
 public void actionPerformed(final ActionEvent ae) {
   System.out.println("About performed.");
   JOptionPane.showMessageDialog(
       frame,
       "SharedActions illustrates one way of handling\n"
           + "AbstractActions in a Swing application.\n\n"
           + "The author can be reached at [email protected]\n\n",
       "About SharedActions",
       JOptionPane.INFORMATION_MESSAGE);
   SharedActions.setActionEnabled(SharedActions.ACTION1_KEY, true);
   SharedActions.setActionEnabled(SharedActions.ACTION2_KEY, true);
   SharedActions.setActionSelected(SharedActions.ACTION3_KEY, true);
   SharedActions.setActionSelected(SharedActions.ACTION4_KEY, true);
 }
  /** Build our JPopupMenu */
  public void buildPopupMenu() {
    this.popup.add(new JMenuItem(actionTable.get(SharedActions.ACTION1_KEY)));
    this.popup.add(new JMenuItem(actionTable.get(SharedActions.ACTION2_KEY)));

    JCheckBoxMenuItem item = new JCheckBoxMenuItem(actionTable.get(SharedActions.ACTION3_KEY));
    SharedActions.registerToggleAction(item, SharedActions.ACTION3_KEY);
    this.popup.add(item);

    item = new JCheckBoxMenuItem(actionTable.get(SharedActions.ACTION4_KEY));
    SharedActions.registerToggleAction(item, SharedActions.ACTION4_KEY);
    this.popup.add(item);

    this.popup.add(new JSeparator());
    this.popup.add(new JMenuItem(actionTable.get(SharedActions.EXIT_KEY)));
  }
    public MyMenuBar(final Hashtable<Integer, Action> actions) {
      JMenu menu = new JMenu("File");
      menu.setMnemonic('F');
      menu.add(new JMenuItem(actions.get(SharedActions.ACTION1_KEY)));
      menu.add(new JMenuItem(actions.get(SharedActions.ACTION2_KEY)));
      menu.add(new JSeparator());
      JCheckBoxMenuItem item = new JCheckBoxMenuItem(actions.get(SharedActions.ACTION3_KEY));
      SharedActions.registerToggleAction(item, SharedActions.ACTION3_KEY);
      menu.add(item);

      item = new JCheckBoxMenuItem(actions.get(SharedActions.ACTION4_KEY));
      SharedActions.registerToggleAction(item, SharedActions.ACTION4_KEY);
      menu.add(item);

      menu.add(new JMenuItem(actions.get(SharedActions.EXIT_KEY)));
      add(menu);

      menu = new JMenu("Help");
      menu.setMnemonic('H');
      menu.add(new JMenuItem((Action) actions.get(SharedActions.ABOUT_KEY)));
      add(menu);
    }
  /** Populate a map of actions. */
  private void buildActionTable() {
    actionTable.put(SharedActions.ABOUT_KEY, new AboutAction());
    actionTable.put(SharedActions.EXIT_KEY, new ExitAction());
    actionTable.put(SharedActions.ACTION1_KEY, new Action1());
    actionTable.put(SharedActions.ACTION2_KEY, new Action2());

    Action action = new Action3();
    toggleListTable.put(action, new ArrayList<AbstractButton>());
    actionTable.put(SharedActions.ACTION3_KEY, action);

    action = new Action4();
    toggleListTable.put(action, new ArrayList<AbstractButton>());
    actionTable.put(SharedActions.ACTION4_KEY, action);

    //	initialize the ACTION2_KEY components.
    SharedActions.setActionEnabled(SharedActions.ACTION2_KEY, false);
  }
    public void actionPerformed(final ActionEvent ae) {
      AbstractButton btn = (AbstractButton) ae.getSource();

      System.out.println("Action 3 performed.");
      SharedActions.setActionSelected(SharedActions.ACTION4_KEY, btn.isSelected());
    }
 public void actionPerformed(final ActionEvent ae) {
   System.out.println("Action 2 performed.");
   SharedActions.setActionEnabled(SharedActions.ACTION1_KEY, true);
   SharedActions.setActionEnabled(SharedActions.ACTION2_KEY, false);
 }