01: /*
02: * $Author$
03: * $Id$
04: * This is free software, as software should be; you can redistribute
05: * it and/or modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08:
09: * See LICENSE.txt for the full license covering this software/program/code.
10: */
11:
12: package isql.commands;
13:
14: import isql.Command;
15: import util.PerlWrapper;
16: import isql.*;
17: import util.*;
18: import javax.swing.*;
19: import javax.swing.table.*;
20: import java.awt.*;
21: import java.util.*;
22:
23: /**
24: * The command object associated with our metadata, such as links for
25: * tables, sort options etc.
26: * I am wondering whether they should be separate classes, however,
27: * would like them to be in one place.
28: * @author rahul kumar <rahul_kumar@yahoo.com>
29: * @see XXX
30: */
31:
32: public class BindCommand implements Command {
33:
34: /** ctor/constructor.
35: */
36: public BindCommand() {
37: }
38:
39: public String[] getCommandList() {
40: return commands;
41: }
42:
43: public void execute(SQLForm form, String fword, String SQLString) {
44: _form = form;
45: SQLTabbedPane tp = _form.tp;
46: //SQLJDBC myjdbc = _form.myjdbc;
47:
48: Bindings bindings = _form.getBindings();
49:
50: String ts = SQLString.substring(5);
51: if (bindings == null)
52: bindings = new Bindings();
53: String parts[] = ArrayUtil.split(ts, ' ');
54: String scope = parts[0], key = parts[1], action = parts[2];
55: key = key.replace('-', ' ');
56: // 0 - scope, 1-key, 2-action
57: try {
58: bindings.addBinding(parts[0], key, action);
59: } catch (InvalidBindingException exc) {
60: System.err.println(P + " L1353 EXC:" + exc.toString());
61: _form.popup(exc.toString());
62: return;
63: }
64: // at this point it is only added to bindings object. New jt
65: // objects will take from this, not existing ones.
66:
67: if (PerlWrapper.isMatching(scope, "table")) {
68: JTable jt = (JTable) tp.getActualComponent(4);
69: jt.getInputMap().put(KeyStroke.getKeyStroke(key), action);
70: }
71: if (PerlWrapper.isMatching(scope, "frame")) {
72: InternalWindowPanel iwp = tp.getWindowPanel();
73: iwp.addBinding(".", key, action);
74: }
75:
76: }
77:
78: public String getUsage(String s) {
79: return "bind scope key action";
80: }
81:
82: String commands[] = { "bind" };
83: SQLForm _form;
84:
85: ////// START INSTANCE VARIABLES //////
86:
87: ////// START CONSTANTS AND CLASS LEVEL VARIABLES //////
88: static final String P = "BindCommand"; // used in exception strings
89:
90: } // end of class
|