Пример #1
0
 private static ActionBuilder[] getBuildersForNames(final String[] builderNames) {
   final ActionBuilder[] builders = new ActionBuilder[builderNames.length];
   for (int i = 0; i < builderNames.length; i++) {
     builders[i] = ActionBuilderFactory.getInstance().getActionBuilder(builderNames[i]);
   }
   return builders;
 }
Пример #2
0
/**
 * Prefs implementation for configuring keystrokes of one or more {@link ActionBuilder
 * ActionBuilders}.
 *
 * @author <a href="mailto:[email protected]">Christian Hujer</a>
 * @since 0.1
 */
public class KeyStrokePrefs extends AbstractPrefs implements ListSelectionListener {

  /** Action Builder. */
  private static final ActionBuilder ACTION_BUILDER =
      ActionBuilderFactory.getInstance().getActionBuilder("net.sf.japi.swing.prefs.keys");

  /**
   * The ActionKeyDisplay.
   *
   * @serial include
   */
  private final ActionKeyDisplay actionKeyDisplay;

  /**
   * The table.
   *
   * @serial include
   */
  private final JTreeTable<KeyStrokeRootNode, AbstractSimpleNode<AbstractSimpleNode>> table;

  /**
   * Create KeyStrokePrefs for a list of ActionBuilders.
   *
   * @param actionBuilders ActionBuilders
   */
  public KeyStrokePrefs(final ActionBuilder... actionBuilders) {
    setListLabelText(ACTION_BUILDER.getString("prefs.listLabelText"));
    setLabelText(ACTION_BUILDER.getString("prefs.labelText"));
    final List<ActionBuilder> builders = asList(actionBuilders);
    setLayout(new BorderLayout());
    table =
        new JTreeTable<KeyStrokeRootNode, AbstractSimpleNode<AbstractSimpleNode>>(
            new KeyStrokeTreeTableModel(builders));
    add(new JScrollPane(table));
    table.getSelectionModel().addListSelectionListener(this);
    actionKeyDisplay = new ActionKeyDisplay();
    add(actionKeyDisplay, BorderLayout.SOUTH);
  }

  /**
   * Create KeyStrokePrefs for a list of named ActionBuilders.
   *
   * @param builderNames names of ActionBuilders
   */
  public KeyStrokePrefs(final String... builderNames) {
    this(getBuildersForNames(builderNames));
  }

  private static ActionBuilder[] getBuildersForNames(final String[] builderNames) {
    final ActionBuilder[] builders = new ActionBuilder[builderNames.length];
    for (int i = 0; i < builderNames.length; i++) {
      builders[i] = ActionBuilderFactory.getInstance().getActionBuilder(builderNames[i]);
    }
    return builders;
  }

  /** {@inheritDoc} */
  public boolean isChanged() {
    return false; // TODO:2009-02-23:christianhujer:Implement.
  }

  /** {@inheritDoc} */
  public void defaults() {
    // TODO:2009-02-23:christianhujer:Implement.
  }

  /** {@inheritDoc} */
  public void revert() {
    // TODO:2009-02-23:christianhujer:Implement.
  }

  /** {@inheritDoc} */
  public void apply() {
    // TODO:2009-02-23:christianhujer:Implement.
  }

  /** {@inheritDoc} */
  public void valueChanged(final ListSelectionEvent e) {
    if (table.getSelectedRow() == -1) {
      actionKeyDisplay.setAction(null);
    } else {
      System.err.println(table.getTreeTableModel().getValueAt(null, table.getSelectedRow()));
    }
  }
} // class KeyStrokePrefs