/**
   * Refreshes the undo/redo icons with the last action performed.
   *
   * @param oUndoManager, the manager to use to check for undo/redo possibilities.
   */
  public void refreshUndoRedo(UndoManager oUndoManager) {

    // refresh undo
    pbUndo.setToolTipText(oUndoManager.getUndoPresentationName());
    pbUndo.setEnabled(oUndoManager.canUndo());

    // refresh redo
    pbRedo.setToolTipText(oUndoManager.getRedoPresentationName());
    pbRedo.setEnabled(oUndoManager.canRedo());
  }
Esempio n. 2
0
  /**
   * Create a button to go inside of the toolbar. By default this will load an image resource. The
   * image filename is relative to the classpath (including the '.' directory if its a part of the
   * classpath), and may either be in a JAR file or a separate file.
   *
   * @param key The key in the resource file to serve as the basis of lookups.
   */
  protected JButton createToolbarButton(String key) {
    URL url = getResource(key + imageSuffix);
    JButton b =
        new JButton(new ImageIcon(url)) {

          @Override
          public float getAlignmentY() {
            return 0.5f;
          }
        };
    b.setRequestFocusEnabled(false);
    b.setMargin(new Insets(1, 1, 1, 1));

    String astr = getProperty(key + actionSuffix);
    if (astr == null) {
      astr = key;
    }
    Action a = getAction(astr);
    if (a != null) {
      b.setActionCommand(astr);
      b.addActionListener(a);
    } else {
      b.setEnabled(false);
    }

    String tip = getResourceString(key + tipSuffix);
    if (tip != null) {
      b.setToolTipText(tip);
    }

    return b;
  }