Source code: org/mitre/cvw/CmdChoice.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 javax.swing.*;
10 import java.awt.*;
11 import java.awt.event.*;
12 import java.util.Vector;
13
14 /**
15 * This is the command pull down menu within the CmdEntryPanel.
16 * @version 1.0 8/11/99
17 * @author Deb Ercolini
18 */
19 public class CmdChoice extends JComboBox {
20 Vector commands;
21
22 /**
23 * Constructor
24 * @param insideOf the window which contains this command entry panel
25 */
26 CmdChoice(Vector v) {
27 super();
28 if (v == null) return;
29 CVWCmdMgr cmdMgr = CVWCoordinator.getInstance().getCmdMgr();
30 commands = new Vector(v.size());
31
32 Integer cmd;
33 String str;
34 for (int i= 0; i < v.size(); i++) {
35 cmd = (Integer)v.elementAt(i);
36 CVWCommand cvwCmd = cmdMgr.get(cmd);
37 commands.addElement(cvwCmd);
38 str = cvwCmd.menuString;
39 addItem(str);
40 }
41
42 }
43
44 /**
45 * Enables the combo box so that items can be selected. When the
46 * Look to remove with jdk1.3
47 * @param b a boolean value, where true enables the component
48 */
49 public void setEnabled(boolean b) {
50 super.setEnabled(b);
51 if (b)
52 setBackground(JCVWApplic.getEditColor());
53 }
54
55 /**
56 * Sets the selected string in the choice menu.
57 * @param menuStr the pulldown menu choice selected
58 */
59 public void setCmdGivenMenuStr(String menuStr) {
60 System.out.println("CmdChoice::in set given menu " + menuStr);
61 if (!getSelectedItem().equals(menuStr))
62 setSelectedItem(menuStr);
63 }
64
65 /**
66 * Sets the command pull down menu given a int representing a CVWCommand.
67 * @param cmdKey the int representing the CVWCommand
68 */
69 public void setSelectedCmd(int cmdKey) {
70 CVWCmdMgr cmdMgr = CVWCoordinator.getInstance().getCmdMgr();
71 CVWCommand cmd = cmdMgr.get(cmdKey);
72 if (cmd == null) return;
73 String sel = cmd.menuString;
74 if (sel != null)
75 setSelectedItem(sel);
76 }
77
78 /**
79 * Sets the command pull down menu given the index
80 * @param index the index
81 */
82 public void setSelectedIndex(int index) {
83 if (index >= getItemCount())
84 index = 0;
85 super.setSelectedIndex(index);
86 }
87
88
89 /**
90 * Returns the text of the person field.
91 * @return the text of the person field
92 */
93 public CVWCommand getSelectedCmd() {
94 return (CVWCommand)commands.elementAt(getSelectedIndex());
95 }
96
97 /**
98 * Returns the Vector of CVWCommands
99 * @return vector of CVWCommands
100 */
101 public Vector getCommands() {
102 return commands;
103 }
104
105 }