001 /* JAPI - (Yet another (hopefully) useful) Java API
002 *
003 * Copyright (C) 2004-2006 Christian Hujer
004 *
005 * This program is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU General Public License as
007 * published by the Free Software Foundation; either version 2 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful, but
011 * WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013 * General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program; if not, write to the Free Software
017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
018 * 02111-1307, USA.
019 */
020
021 package net.sf.japi.swing.prefs.keys;
022
023 import java.awt.BorderLayout;
024 import static java.util.Arrays.asList;
025 import java.util.List;
026 import javax.swing.JScrollPane;
027 import javax.swing.event.ListSelectionEvent;
028 import javax.swing.event.ListSelectionListener;
029 import net.sf.japi.swing.ActionFactory;
030 import net.sf.japi.swing.prefs.AbstractPrefs;
031 import net.sf.japi.swing.treetable.JTreeTable;
032
033 /** Prefs implementation for configuring keystrokes of one or more {@link ActionFactory ActionFactories}.
034 * TODO
035 * @author <a href="mailto:chris@riedquat.de">Christian Hujer</a>
036 */
037 public class KeyStrokePrefs extends AbstractPrefs implements ListSelectionListener {
038
039 /** Action Factory. */
040 private static final ActionFactory ACTION_FACOTRY = ActionFactory.getFactory("net.sf.japi.swing.prefs.keys");
041
042 /** The ActionKeyDisplay. */
043 private final ActionKeyDisplay actionKeyDisplay;
044
045 /** The table. */
046 private final JTreeTable<KeyStrokeRootNode, AbstractSimpleNode<AbstractSimpleNode>> table;
047
048 /** Create KeyStrokePrefs for a list of ActionFactories.
049 * @param actionFactories ActionFactories
050 */
051 public KeyStrokePrefs(final ActionFactory... actionFactories) {
052 setListLabelText(ACTION_FACOTRY.getString("prefs.listLabelText"));
053 setLabelText(ACTION_FACOTRY.getString("prefs.labelText"));
054 final List<ActionFactory> factories = asList(actionFactories);
055 setLayout(new BorderLayout());
056 table = new JTreeTable<KeyStrokeRootNode, AbstractSimpleNode<AbstractSimpleNode>>(new KeyStrokeTreeTableModel(factories));
057 add(new JScrollPane(table));
058 table.getSelectionModel().addListSelectionListener(this);
059 actionKeyDisplay = new ActionKeyDisplay();
060 add(actionKeyDisplay, BorderLayout.SOUTH);
061 }
062
063 /** Create KeyStrokePrefs for a list of named ActionFactories.
064 * @param factoryNames names of ActionFactories
065 */
066 public KeyStrokePrefs(final String... factoryNames) {
067 this(getFactoriesForNames(factoryNames));
068 }
069
070 private static ActionFactory[] getFactoriesForNames(final String[] factoryNames) {
071 final ActionFactory[] factories = new ActionFactory[factoryNames.length];
072 for (int i = 0; i < factoryNames.length; i++) {
073 factories[i] = ActionFactory.getFactory(factoryNames[i]);
074 }
075 return factories;
076 }
077
078 /** {@inheritDoc} */
079 public boolean isChanged() {
080 return false; //TODO
081 }
082
083 /** {@inheritDoc} */
084 public void defaults() {
085 //TODO
086 }
087
088 /** {@inheritDoc} */
089 public void revert() {
090 //TODO
091 }
092
093 /** {@inheritDoc} */
094 public void apply() {
095 //TODO
096 }
097
098 /** {@inheritDoc} */
099 public void valueChanged(final ListSelectionEvent e) {
100 if (table.getSelectedRow() == -1) {
101 actionKeyDisplay.setAction(null);
102 } else {
103 System.err.println(table.getTreeTableModel().getValueAt(null, table.getSelectedRow()));
104 }
105 }
106
107 } // class KeyStrokePrefs