File Source: OsdCommand.java
/*
P/P * Method: com.dmdirc.addons.osd.OsdCommand__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.addons.osd;
24
25 import com.dmdirc.commandparser.CommandArguments;
26 import com.dmdirc.commandparser.CommandManager;
27 import com.dmdirc.commandparser.commands.GlobalCommand;
28 import com.dmdirc.commandparser.commands.IntelligentCommand;
29 import com.dmdirc.ui.input.AdditionalTabTargets;
30 import com.dmdirc.ui.interfaces.InputWindow;
31 import com.dmdirc.ui.messages.Styliser;
32
33 import java.util.List;
34
35 /**
36 * The osd command shows an on screen message.
37 * @author chris
38 */
39 public final class OsdCommand extends GlobalCommand implements IntelligentCommand {
40
41 /** The plugin that owns this command. */
42 private final OsdPlugin plugin;
43
44 /**
45 * Creates a new instance of OsdCommand.
46 *
47 * @param plugin The plugin that owns this command
48 */
49 public OsdCommand(final OsdPlugin plugin) {
/*
P/P * Method: void com.dmdirc.addons.osd.OsdCommand(OsdPlugin)
*
* Postconditions:
* this.plugin == plugin
* init'ed(this.plugin)
*/
50 super();
51
52 this.plugin = plugin;
53
54 CommandManager.registerCommand(this);
55 }
56
57
58 /**
59 * Used to show a notification using this plugin.
60 *
61 * @param title Title of dialog if applicable
62 * @param message Message to show
63 * @return True if the notification was shown.
64 */
65 public boolean showOSD(final String title, final String message) {
/*
P/P * Method: bool showOSD(String, String)
*
* Preconditions:
* this.plugin != null
* (soft) com/dmdirc/addons/osd/OsdWindow.windows != null
*
* Postconditions:
* return_value == 1
*/
66 new OsdWindow(Styliser.stipControlCodes(message), false, plugin);
67 return true;
68 }
69
70 /** {@inheritDoc} */
71 @Override
72 public void execute(final InputWindow origin, final boolean isSilent,
73 final CommandArguments args) {
/*
P/P * Method: void execute(InputWindow, bool, CommandArguments)
*
* Preconditions:
* args != null
* (soft) com/dmdirc/addons/osd/OsdWindow.windows != null
* (soft) this.plugin != null
*
* Presumptions:
* com.dmdirc.commandparser.CommandArguments:getArguments(...).length@74 >= 1
* com.dmdirc.commandparser.CommandArguments:getArguments(...)@74 != null
*
* Test Vectors:
* com.dmdirc.commandparser.CommandArguments:getArguments(...).length@74: {0}, {1..+Inf}
* java.lang.String:equalsIgnoreCase(...)@74: {0}, {1}
*/
74 if (args.getArguments().length > 0
75 && "--close".equalsIgnoreCase(args.getArguments()[0])) {
76 OsdWindow.closeAll();
77 } else {
78 showOSD("", args.getArgumentsAsString());
79 }
80 }
81
82 /** {@inheritDoc}. */
83 @Override
84 public String getName() {
/*
P/P * Method: String getName()
*
* Postconditions:
* return_value == &"osd"
*/
85 return "osd";
86 }
87
88 /** {@inheritDoc}. */
89 @Override
90 public boolean showInHelp() {
/*
P/P * Method: bool showInHelp()
*
* Postconditions:
* return_value == 1
*/
91 return true;
92 }
93
94 /** {@inheritDoc}. */
95 @Override
96 public String getHelp() {
/*
P/P * Method: String getHelp()
*
* Postconditions:
* return_value == &"osd --close - closes all OSD windows&#10;osd <message> - show the specified message in an OSD window"
*/
97 return "osd --close - closes all OSD windows\n" +
98 "osd <message> - show the specified message in an OSD window";
99 }
100
101 /** {@inheritDoc} */
102 @Override
103 public AdditionalTabTargets getSuggestions(final int arg, final List<String> previousArgs) {
/*
P/P * Method: AdditionalTabTargets getSuggestions(int, List)
*
* Preconditions:
* (soft) previousArgs != null
*
* Presumptions:
* java.util.List:get(...)@108 != null
*
* Postconditions:
* return_value == &new AdditionalTabTargets(getSuggestions#1)
* new AdditionalTabTargets(getSuggestions#1) num objects == 1
*
* Test Vectors:
* arg: {-231..-1}, {0}, {1..232-1}
* java.lang.String:equals(...)@108: {0}, {1}
*/
104 final AdditionalTabTargets res = new AdditionalTabTargets();
105
106 if (arg == 0) {
107 res.add("--close");
108 } else if (arg > 0 && previousArgs.get(0).equals("--close")) {
109 res.excludeAll();
110 }
111
112 return res;
113 }
114
115 }
SofCheck Inspector Build Version : 2.17854
| OsdCommand.java |
2009-Jun-25 01:54:24 |
| OsdCommand.class |
2009-Sep-02 17:04:15 |