[Jsxe-cvs] SF.net SVN: jsxe: [1004] trunk/jsxe
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-07-10 19:13:02
|
Revision: 1004 Author: ian_lewis Date: 2006-07-10 12:12:51 -0700 (Mon, 10 Jul 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=1004&view=rev Log Message: ----------- Added the shortcuts option pane to the global options Modified Paths: -------------- trunk/jsxe/Changelog trunk/jsxe/messages/messages trunk/jsxe/src/net/sourceforge/jsxe/options/ShortcutsOptionPane.java Modified: trunk/jsxe/Changelog =================================================================== --- trunk/jsxe/Changelog 2006-07-08 18:22:12 UTC (rev 1003) +++ trunk/jsxe/Changelog 2006-07-10 19:12:51 UTC (rev 1004) @@ -1,3 +1,8 @@ +07/10/2006 Ian Lewis <Ian...@me...> + + * Added the Shortcuts option pane. However, it currently it doesn't work. + It only displays the built in options and the combo box. + 07/06/2006 Ian Lewis <Ian...@me...> * Rewrote the Messages class. Now it loads messages on demand and only Modified: trunk/jsxe/messages/messages =================================================================== --- trunk/jsxe/messages/messages 2006-07-08 18:22:12 UTC (rev 1003) +++ trunk/jsxe/messages/messages 2006-07-10 19:12:51 UTC (rev 1004) @@ -68,8 +68,10 @@ Global.Options.network=DTD and schema downloading: Global.Options.Menu.Spill.Over=Number of items before menus spill over - Shortcuts.Options.Title=Shortcuts +Shortcuts.Options.Select.Label=Edit Shortcuts: +Shortcuts.Options.Shortcut=Shortcut +Shortcuts.Options.Command=Command #}}} #{{{ Document Options Modified: trunk/jsxe/src/net/sourceforge/jsxe/options/ShortcutsOptionPane.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/options/ShortcutsOptionPane.java 2006-07-08 18:22:12 UTC (rev 1003) +++ trunk/jsxe/src/net/sourceforge/jsxe/options/ShortcutsOptionPane.java 2006-07-10 19:12:51 UTC (rev 1004) @@ -31,14 +31,28 @@ import net.sourceforge.jsxe.ActionSet; import net.sourceforge.jsxe.ActionManager; import net.sourceforge.jsxe.gui.Messages; +import net.sourceforge.jsxe.gui.GrabKeyDialog; import net.sourceforge.jsxe.util.MiscUtilities; +import net.sourceforge.jsxe.util.Log; //}}} +//{{{ AWT classes +import java.awt.BorderLayout; +import java.awt.Dimension; +//}}} + //{{{ Swing classes +import javax.swing.Box; +import javax.swing.JLabel; +import javax.swing.JComboBox; +import javax.swing.JTable; +import javax.swing.JScrollPane; import javax.swing.table.*; //}}} //{{{ Java classses +import java.util.Comparator; +import java.util.Iterator; import java.util.Vector; //}}} @@ -67,7 +81,28 @@ //{{{ _init() protected void _init() { + setLayout(new BorderLayout(12,12)); + initModels(); + + JComboBox setsBox = new JComboBox(ActionManager.getActionSets().toArray()); + Box north = Box.createHorizontalBox(); + north.add(new JLabel(Messages.getMessage("Shortcuts.Options.Select.Label"))); + north.add(Box.createHorizontalStrut(6)); + north.add(setsBox); + + JTable keyTable = new JTable(m_currentModel); + keyTable.getTableHeader().setReorderingAllowed(false); + // keyTable.getTableHeader().addMouseListener(new HeaderMouseHandler()); + // keyTable.addMouseListener(new TableMouseHandler()); + Dimension d = keyTable.getPreferredSize(); + d.height = Math.min(d.height,200); + JScrollPane scroller = new JScrollPane(keyTable); + scroller.setPreferredSize(d); + + add(BorderLayout.NORTH,north); + add(BorderLayout.CENTER,scroller); + }//}}} //{{{ _save() @@ -82,20 +117,29 @@ //{{{ Private Members + private ActionSetTableModel m_currentModel; + private Vector m_models; + //{{{ ActionSetTableModel class private class ActionSetTableModel extends AbstractTableModel { //{{{ ActionSetTableModel constructor public ActionSetTableModel(ActionSet set) { - //TODO: need to use key bindings from the GrabKeyDialog String[] names = set.getActionNames(); m_set = new Vector(names.length); for (int i = 0; i < names.length; i++) { String label = ActionManager.getLocalizedAction(names[i]).getLabel(); - m_set.add(label); + if (label == null) { + Log.log(Log.WARNING, this, names[i]+" has a null label"); + } else { + String binding = jsXe.getProperty(names[i]+".shortcut"); + m_set.add(new GrabKeyDialog.KeyBinding(names[i], label, binding)); + } } - MiscUtilities.quicksort(m_set, new MiscUtilities.StringCompare()); + MiscUtilities.quicksort(m_set, new KeyCompare()); + + m_name = set.getLabel(); }//}}} //{{{ getColumnCount() @@ -103,6 +147,19 @@ return 2; }//}}} + //{{{ getColumnName() + + public String getColumnName(int columnIndex) { + switch (columnIndex) { + case(0): + return Messages.getMessage("Shortcuts.Options.Command"); + case(1): + return Messages.getMessage("Shortcuts.Options.Shortcut"); + default: + return null; + } + }//}}} + //{{{ getRowCount() public int getRowCount() { return m_set.size(); @@ -110,15 +167,72 @@ //{{{ getValueAt() public Object getValueAt(int row, int column) { - return null; + switch (column) { + case (0): + return ((GrabKeyDialog.KeyBinding)m_set.get(row)).label; + case (1): + return ((GrabKeyDialog.KeyBinding)m_set.get(row)).shortcut; + default: + return null; + } }//}}} + //{{{ setValueAt() + + public void setValueAt(Object value, int row, int col) { + if (col == 0) + return; + + ((GrabKeyDialog.KeyBinding)m_set.get(row)).shortcut = (String)value; + + // redraw the whole table because a second shortcut + // might have changed, too + fireTableDataChanged(); + }//}}} + + //{{{ toString() + + public String toString() { + // needed for sorting of the models in initModels() + return m_name; + }//}}} + //{{{ Private members + + //{{{ KeyCompare class + + private class KeyCompare implements Comparator { + + public int compare(Object obj1, Object obj2) { + String label1 = ((GrabKeyDialog.KeyBinding)obj1).label; + String label2 = ((GrabKeyDialog.KeyBinding)obj2).label; + return MiscUtilities.compareStrings(label1,label2,true); + } + + }//}}} + private Vector m_set; + private String m_name; //}}} }//}}} + //{{{ initModels() + + private void initModels() { + m_models = new Vector(); + Iterator itr = ActionManager.getActionSets().iterator(); + while(itr.hasNext()) { + ActionSet actionSet = (ActionSet)itr.next(); + if (actionSet.getActionCount() != 0) { + String modelLabel = actionSet.getLabel(); + m_models.addElement(new ActionSetTableModel(actionSet)); + } + } + MiscUtilities.quicksort(m_models,new MiscUtilities.StringICaseCompare()); + m_currentModel = (ActionSetTableModel)m_models.elementAt(0); + }//}}} + //}}} } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |