001: package org.dbbrowser.ui;
002:
003: import java.util.ArrayList;
004: import java.util.List;
005:
006: /**
007: * An instance of this class represents a key binding. A key binding object contains information
008: * about a key press which will lead to an action. A Key Binding is uniquely identified by its description.
009: * The method 'getAllActions' lists all the possible actions.
010: * @author amangat
011: *
012: */
013: public class KeyBinding {
014: public static String HELP = "Help -> Help";
015: public static String FILE_CONNECT = "File -> Connect";
016: public static String FILE_DROP_CONNECTION = "File -> Drop connection";
017: public static String FILE_OPEN_SQL_SCRIPT_FILE = "File -> Open SQL Script";
018: public static String FILE_EXIT = "File -> Exit";
019: public static String EDIT_PREFERENCES = "Edit -> Preferences";
020: public static String TOOLS_COMMIT = "Tools -> Commit";
021: public static String TOOLS_ROLLBACK = "Tools -> Rollback";
022:
023: private String description = null;
024: private Integer keyCode = null;
025: private Integer modifierCode = null;
026: private String action = null;
027:
028: /**
029: * Constructer
030: * @param description
031: * @param keyCode
032: * @param modifierCode
033: * @param action
034: */
035: public KeyBinding(String description, Integer keyCode,
036: Integer modifierCode, String action) {
037: this .description = description;
038: this .keyCode = keyCode;
039: this .modifierCode = modifierCode;
040: this .action = action;
041: }
042:
043: /**
044: * Returns all the possible actions
045: * @return - a list of strings
046: */
047: public static List getAllActions() {
048: List listOfActions = new ArrayList();
049: listOfActions.add(HELP);
050: listOfActions.add(FILE_CONNECT);
051: listOfActions.add(FILE_DROP_CONNECTION);
052: listOfActions.add(FILE_OPEN_SQL_SCRIPT_FILE);
053: listOfActions.add(FILE_EXIT);
054: listOfActions.add(EDIT_PREFERENCES);
055: listOfActions.add(TOOLS_COMMIT);
056: listOfActions.add(TOOLS_ROLLBACK);
057:
058: return listOfActions;
059: }
060:
061: /**
062: * Returns a descriptions which uniquely identifies this key binding
063: * @return
064: */
065: public String getDescription() {
066: return this .description;
067: }
068:
069: /**
070: * Returns the key code for the key
071: * @return
072: */
073: public Integer getKeyCode() {
074: return this .keyCode;
075: }
076:
077: /**
078: * Returns the modifier code - such as CTRL or ALT key
079: * @return
080: */
081: public Integer getModifierCode() {
082: return this .modifierCode;
083: }
084:
085: /**
086: * Returns the action to be performed when this key is pressed
087: * @return
088: */
089: public String getAction() {
090: return this .action;
091: }
092:
093: public int hashCode() {
094: return this .getDescription().hashCode();
095: }
096:
097: /**
098: * Two key bindings are equal if they have the same description
099: * @return - true of the otherObject is an instance of KeyBinding and it has the same description as this object
100: */
101: public boolean equals(Object otherObject) {
102: boolean equal = false;
103: if (otherObject instanceof KeyBinding) {
104: KeyBinding otherKeyBinding = (KeyBinding) otherObject;
105: String otherObjectsDescription = otherKeyBinding
106: .getDescription();
107:
108: //if the 2 descriptions are equal, then they are equal
109: if (otherObjectsDescription.equals(this .getDescription())) {
110: equal = true;
111: }
112: }
113: return equal;
114: }
115: }
|