Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/mitre/cvw/CVWCommand.java


1   /*
2    * Copyright (c) 1996-2000. The MITRE Corporation (http://www.mitre.org/).
3    * All rights reserved.
4    * CVW comes with ABSOLUTELY NO WARRANTY. See license for details.
5    */
6   
7   package org.mitre.cvw;
8   
9   import java.awt.event.KeyEvent;
10  
11  
12  /**************************************************************
13   ****************** CVW Command Object ************************
14   **************************************************************/
15  /**
16   * This class represents a cvw command to make communcation to
17   * the CVW server easier.  Each command also can have a hot key
18   * sequence.
19   * 
20   * @version 
21   * @author Deb Ercolini
22   */
23  class CVWCommand extends Object {
24   
25   public static final int GOHOME = 0;   //home or go to home
26   
27   public static final int SAY = 1;       //"user   or say text
28   public static final int PASTE = 2;     //@paste text
29   public static final int EMOTE = 3;     //:text   or emote text
30   
31   public static final int PAGE = 4;         //popup page 
32   public static final int SAYTO = 5;          //'user text   or sayto user text
33   public static final int PASTETO = 6;        //@pasteto text
34   public static final int EMOTE_PRIVATE = 7;      //+user text
35   public static final int WHISPER = 8;       //whisper text to user
36   
37   public static final int JOIN = 9;     //join user
38   public static final int IDLE = 10;   //idle [text] 
39   public static final int GOTO = 11;   //go to user
40   
41   public static final int EMOTETO = 12;      //(to user) user text
42   public static final int CVWCMD = 13;      //send text as cvw cmd
43   public static final int SENDURL = 14;    //@url
44  
45   public static final int FINDUSER = 15;    //@who
46   public static final int SAY_PRIVATE = 16;    //page user text
47   
48   public static final int PHONE = 17;    //page user text
49  
50   public static final int CMDCOUNT = 18;    //the number of cmds above
51  
52     Integer key;
53     String menuString;
54     String errString;
55     String cmdString;
56     String modifiers;
57     Character hotkey;
58     int virtualKey;
59     int modMask;
60  
61  /**
62   * Constructor
63   * @param k the static value of this key
64   * @param cmdStr the cvw textual command
65   * @param menuStr the display string
66   * @see CVWCmdMgr
67   */
68      CVWCommand (int k, String cmdStr, String menuStr) {
69          key = new Integer(k);
70          cmdString = cmdStr;
71          errString = cmdStr;
72          menuString = menuStr;
73    hotkey = null;
74       modifiers = null;
75    modMask = 0;
76    virtualKey = KeyEvent.VK_UNDEFINED;
77        }
78   
79  /**
80   * Constructor
81   * @param k the static value of this key
82   * @param cmdStr the cvw textual command
83   * @param menuStr the display string
84   * @param mod the modifiers needed for the hotkey to work
85   * @param hk the actual hot key
86   * @param vk the virtual key as defined by InputEvent
87   * @see CVWCmdMgr
88   */
89      CVWCommand (int k, String cmdStr, String menuStr, String mod, char hk, int vk) {
90          key = new Integer(k);
91          cmdString = cmdStr;
92          errString = menuStr;
93    hotkey = new Character(hk);
94       modifiers = mod;
95          menuString = buildCmdMenuItem(menuStr, new String(mod + "+" + hotkey));
96    virtualKey = vk;
97    modMask = KeyEvent.CTRL_MASK;
98    if (mod.indexOf("shift") > 0)
99      modMask |= KeyEvent.SHIFT_MASK;
100       }
101 
102   public int getVirtualKey() {
103      return virtualKey;
104     }
105       
106   public int getModMask() {
107      return modMask;
108     }
109       
110 /**
111  * Calculates the spaces between the
112  * command and the ctrl+x value.  Not perfect but good enough
113  * 9/11/96 dage
114  *
115  * @param menu the menu command string
116  * @param ctrlx the control char sequence
117  * @return  the formatted string
118  */
119   public String buildCmdMenuItem(String menu, String ctrlx) {
120     CVWCoordinator cvw = CVWCoordinator.getInstance();
121     java.awt.FontMetrics g = cvw.getFontMetrics(cvw.plainFont);
122     int mWidth = g.stringWidth(menu);
123     int sWidth = g.stringWidth(" ");
124     int cWidth = g.stringWidth(ctrlx);
125     int max = g.stringWidth("emote privately     ");
126     int len = max - mWidth;
127     int count = (int)Math.ceil(len/sWidth);  //crtl+shift+e
128     //System.err.println(menu + " " + ctrlx);
129     //System.err.println(mWidth + " " + sWidth + " " + cWidth);
130     //System.err.println(max + " " + len + " " + count);
131     String spaces = "                                             "; //40 spaces
132     StringBuffer sbuff = new StringBuffer(menu + spaces);
133     sbuff.setLength(40);
134     //sbuff.insert(0, menu);
135     sbuff.insert(menu.length() + count, ctrlx);
136     //System.err.println("build menu item: " + menuItem + ".");
137     return sbuff.toString().trim();
138   }
139 
140 /**
141  * Returns the integer value of the key for this command
142  * @return  the integer value of the key for this command
143  */
144   public int keyInt() { 
145     return key.intValue(); 
146    }
147  
148 /**
149  * Returns a string representation of this component and its values.
150  * @return    a string representation of this component.
151  */
152   public String toString() {
153         return getClass().getName() + "["
154                 + "key=" + key
155                 + "hotkey=" + hotkey
156                 + "modMask=" + modMask
157                 + "virtualKey=" + virtualKey
158                 + ",cmdString=" + cmdString
159                 + ",menuString=" + menuString
160                 + "]" ;
161     }
162  
163   }
164 /**************************************************************
165  **************** End CVW Command Object **********************
166  **************************************************************/
167