Example #1
0
  private static void constructActions() {
    final Action lExitAction = new ExitAction();
    lExitAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_X);
    viewModel.put("action.exit", lExitAction);

    final Action lHelpAction = new HelpAction();
    lHelpAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_T);
    viewModel.put("action.help", lHelpAction);

    final Action lAboutAction = new AboutAction();
    lAboutAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
    viewModel.put("action.about", lAboutAction);
  }
Example #2
0
 @Override
 public void ioResult(IOServiceEvent e) {
   if (e.getState() == IOServiceEvent.MOUNT_SUCCESS
       || e.getState() == IOServiceEvent.MOUNT_FAILURE) {
     lumberjack.setFullModel(buildModel(e.getResolverBundle().getResolvers()));
     toggleAction.setEnabled(cpos != null);
     toggleAction.putValue(
         Action.SELECTED_KEY,
         (Boolean) toggleAction.getValue(Action.SELECTED_KEY) && cpos != null);
   }
 }
Example #3
0
  /**
   * Tests that the returned JButton of <code>createManualToolBarButton</code>: 1. Is disabled upon
   * return. 2. Inherits the tooltip of the Action parameter <code>a</code>.
   */
  public void testCreateManualToolBarButton() {
    final Action a =
        new AbstractAction("Test Action") {
          public void actionPerformed(ActionEvent ae) {}
        };

    a.putValue(Action.LONG_DESCRIPTION, "test tooltip");
    Utilities.invokeAndWait(
        new Runnable() {
          public void run() {
            _but = _frame._createManualToolBarButton(a);
          }
        });

    assertTrue("Returned JButton is enabled.", !_but.isEnabled());
    assertEquals("Tooltip text not set.", "test tooltip", _but.getToolTipText());
    _log.log("testCreateManualToobarButton completed");
  }
  // Add icons and friendly names to actions we care about.
  protected void makeActionsPretty() {
    Action a;
    a = textComp.getActionMap().get(DefaultEditorKit.cutAction);
    a.putValue(Action.SMALL_ICON, new ImageIcon("icons/cut.gif"));
    a.putValue(Action.NAME, "Cut");

    a = textComp.getActionMap().get(DefaultEditorKit.copyAction);
    a.putValue(Action.SMALL_ICON, new ImageIcon("icons/copy.gif"));
    a.putValue(Action.NAME, "Copy");

    a = textComp.getActionMap().get(DefaultEditorKit.pasteAction);
    a.putValue(Action.SMALL_ICON, new ImageIcon("icons/paste.gif"));
    a.putValue(Action.NAME, "Paste");

    a = textComp.getActionMap().get(DefaultEditorKit.selectAllAction);
    a.putValue(Action.NAME, "Select All");
  }
  public ToolBarFrame() {
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // add a panel for color change

    panel = new JPanel();
    add(panel, BorderLayout.CENTER);

    // set up actions

    Action blueAction = new ColorAction("Blue", new ImageIcon("blue-ball.gif"), Color.BLUE);
    Action yellowAction = new ColorAction("Yellow", new ImageIcon("yellow-ball.gif"), Color.YELLOW);
    Action redAction = new ColorAction("Red", new ImageIcon("red-ball.gif"), Color.RED);

    Action exitAction =
        new AbstractAction("Exit", new ImageIcon("exit.gif")) {
          public void actionPerformed(ActionEvent event) {
            System.exit(0);
          }
        };
    exitAction.putValue(Action.SHORT_DESCRIPTION, "Exit");

    // populate tool bar

    JToolBar bar = new JToolBar();
    bar.add(blueAction);
    bar.add(yellowAction);
    bar.add(redAction);
    bar.addSeparator();
    bar.add(exitAction);
    add(bar, BorderLayout.NORTH);

    // populate menu

    JMenu menu = new JMenu("Color");
    menu.add(yellowAction);
    menu.add(blueAction);
    menu.add(redAction);
    menu.add(exitAction);
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(menu);
    setJMenuBar(menuBar);
  }
Example #6
0
  /** 创建工具栏 */
  private void createToolBar() {
    panel = new JPanel(new BorderLayout());

    // 加入工具栏
    toolBar = new JToolBar();
    panel.add(toolBar, BorderLayout.NORTH);

    // 保存
    saveAction =
        new AbstractAction("保存", new ImageIcon(TMFrame.class.getResource("/images/TSave.gif"))) {

          public void actionPerformed(ActionEvent e) {
            save();
          }
        };

    // 打印
    printAction =
        new AbstractAction("打印", new ImageIcon(TMFrame.class.getResource("/images/TPrint.gif"))) {

          public void actionPerformed(ActionEvent e) {
            print();
          }
        };

    // 人员管理
    DMManageAction =
        new AbstractAction("人员管理", new ImageIcon(TMFrame.class.getResource("/images/TStaff.gif"))) {

          public void actionPerformed(ActionEvent e) {
            DMManage();
          }
        };

    // 备份数据库
    Action backupAction =
        new AbstractAction(
            "备份数据库", new ImageIcon(TMFrame.class.getResource("/images/TBackup.gif"))) {

          public void actionPerformed(ActionEvent e) {
            backup();
          }
        };

    // 恢复数据库
    Action restoreAction =
        new AbstractAction(
            "恢复数据库", new ImageIcon(TMFrame.class.getResource("/images/TRestore.gif"))) {

          public void actionPerformed(ActionEvent e) {
            restore();
          }
        };

    Action searchAction =
        new AbstractAction("查询", new ImageIcon(TMFrame.class.getResource("/images/TSearch.gif"))) {

          public void actionPerformed(ActionEvent e) {
            search();
          }
        };

    // 帮助文档
    Action helpAction =
        new AbstractAction("帮助", new ImageIcon(TMFrame.class.getResource("/images/THelp.gif"))) {

          public void actionPerformed(ActionEvent e) {
            help();
          }
        };

    // 关于我们
    Action aboutAction =
        new AbstractAction(
            "关于我们", new ImageIcon(TMFrame.class.getResource("/images/TAboutUS.gif"))) {

          public void actionPerformed(ActionEvent e) {
            about();
          }
        };

    Action exitAction =
        new AbstractAction("退出", new ImageIcon(TMFrame.class.getResource("/images/TExit.gif"))) {

          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        };

    // 为工具栏图标加入提示
    saveAction.putValue(Action.SHORT_DESCRIPTION, "保存");
    printAction.putValue(Action.SHORT_DESCRIPTION, "打印");
    DMManageAction.putValue(Action.SHORT_DESCRIPTION, "人员管理");
    backupAction.putValue(Action.SHORT_DESCRIPTION, "备份数据库");
    restoreAction.putValue(Action.SHORT_DESCRIPTION, "恢复数据库");
    searchAction.putValue(Action.SHORT_DESCRIPTION, "查询");
    helpAction.putValue(Action.SHORT_DESCRIPTION, "帮助文档");
    aboutAction.putValue(Action.SHORT_DESCRIPTION, "关于我们");
    exitAction.putValue(Action.SHORT_DESCRIPTION, "退出系统");

    toolBar.add(saveAction);
    toolBar.add(printAction);
    toolBar.add(DMManageAction);
    toolBar.add(backupAction);
    toolBar.add(restoreAction);
    toolBar.add(searchAction);
    toolBar.add(helpAction);
    toolBar.add(aboutAction);
    toolBar.add(exitAction);

    toolBar.setBorder(BorderFactory.createEtchedBorder());
    toolBar.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 2));
    add(panel);

    // 设置图标活动性
    saveAction.setEnabled(false);
    printAction.setEnabled(false);
    backupAction.setEnabled(false);
    restoreAction.setEnabled(false);
  }