File Source: PopupMenuItem.java
/*
P/P * Method: com.dmdirc.commandparser.PopupMenuItem__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.commandparser;
24
25 /**
26 * Represents an abstract, UI-independent popup menu item.
27 *
28 * @author chris
29 */
30 public class PopupMenuItem {
31
32 /** Whether this item is a divider. */
33 private boolean divider = false;
34 /** The submenu for this item, if any. */
35 private PopupMenu submenu = null;
36 /** The name of this item, if any. */
37 private String name;
38 /** The command for this item, if any. */
39 private String command;
40
41 /**
42 * Creates a new PopupMenuItem that is used as a divider.
43 */
/*
P/P * Method: void com.dmdirc.commandparser.PopupMenuItem()
*
* Postconditions:
* this.divider == 1
* this.submenu == null
*/
44 public PopupMenuItem() {
45 divider = true;
46 }
47
48 /**
49 * Creates a new PopupMenuItem that is used as a submenu.
50 *
51 * @param name The name of the menu item
52 * @param submenu The submenu of this item
53 */
/*
P/P * Method: void com.dmdirc.commandparser.PopupMenuItem(String, PopupMenu)
*
* Postconditions:
* this.divider == 0
* this.name == name
* init'ed(this.name)
* this.submenu == submenu
* init'ed(this.submenu)
*/
54 public PopupMenuItem(final String name, final PopupMenu submenu) {
55 this.name = name;
56 this.submenu = submenu;
57 }
58
59 /**
60 * Creates a new PopupMenuItem that executes a command.
61 *
62 * @param name The name of the menu item
63 * @param command The command to be executed
64 */
/*
P/P * Method: void com.dmdirc.commandparser.PopupMenuItem(String, String)
*
* Postconditions:
* this.command == command
* init'ed(this.command)
* this.divider == 0
* this.name == name
* init'ed(this.name)
* this.submenu == null
*/
65 public PopupMenuItem(final String name, final String command) {
66 this.name = name;
67 this.command = command;
68 }
69
70 /**
71 * Determines if this menu item is a divider or not.
72 *
73 * @return True if this item is a divider, false otherwise.
74 */
75 public boolean isDivider() {
/*
P/P * Method: bool isDivider()
*
* Preconditions:
* init'ed(this.divider)
*
* Postconditions:
* return_value == this.divider
* init'ed(return_value)
*/
76 return divider;
77 }
78
79 /**
80 * Determines if this menu item contains a submenu or not.
81 *
82 * @return True if this item contains a submenu, false otherwise.
83 */
84 public boolean isSubMenu() {
/*
P/P * Method: bool isSubMenu()
*
* Preconditions:
* init'ed(this.submenu)
*
* Postconditions:
* init'ed(return_value)
*/
85 return submenu != null;
86 }
87
88 /**
89 * Retrieves the submenu associated with this item.
90 *
91 * @return This menu item's submenu.
92 */
93 public PopupMenu getSubMenu() {
/*
P/P * Method: PopupMenu getSubMenu()
*
* Preconditions:
* init'ed(this.submenu)
*
* Postconditions:
* return_value == this.submenu
* init'ed(return_value)
*/
94 return submenu;
95 }
96
97 /**
98 * Retrieves the name of this menu item.
99 *
100 * @return This menu item's name.
101 */
102 public String getName() {
/*
P/P * Method: String getName()
*
* Preconditions:
* init'ed(this.name)
*
* Postconditions:
* return_value == this.name
* init'ed(return_value)
*/
103 return name;
104 }
105
106 /**
107 * Retrieves the command for this menu item, with the specified argumenwits
108 * substituted in.
109 *
110 * @param arguments The arguments needed for this command
111 * @return The command to be passed to a command parser
112 */
113 public String getCommand(final Object... arguments) {
/*
P/P * Method: String getCommand(Object[])
*
* Preconditions:
* init'ed(com/dmdirc/commandparser/CommandManager.commandChar)
* init'ed(this.command)
*
* Postconditions:
* java.lang.StringBuilder:toString(...)._tainted == 0
* return_value == &java.lang.StringBuilder:toString(...)
*/
114 return CommandManager.getCommandChar() + String.format(command, arguments);
115 }
116
117 }
SofCheck Inspector Build Version : 2.17854
| PopupMenuItem.java |
2009-Jun-25 01:54:24 |
| PopupMenuItem.class |
2009-Sep-02 17:04:14 |