File Source: PluginInfoToggle.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.components.pluginpanel.PluginInfoToggle__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 package com.dmdirc.addons.ui_swing.components.pluginpanel;
23
24 import com.dmdirc.plugins.PluginInfo;
25 import com.dmdirc.plugins.PluginManager;
26
27 /**
28 * Wraps a PluginInfo object with a boolean to indicate whether it should be
29 * toggled or not.
30 *
31 * @author chris
32 */
33 public class PluginInfoToggle {
34
35 /** The PluginInfo object we're wrapping. */
36 private final PluginInfo pi;
37
38 /** Whether or not to toggle it. */
39 private boolean toggle = false;
40
41 /**
42 * Creates a new instance of PluginInfoToggle to wrap the specified
43 * PluginInfo.
44 *
45 * @param pi The PluginInfo to be wrapped
46 */
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.pluginpanel.PluginInfoToggle(PluginInfo)
*
* Postconditions:
* this.pi == pi
* init'ed(this.pi)
* this.toggle == 0
*/
47 public PluginInfoToggle(final PluginInfo pi) {
48 this.pi = pi;
49 }
50
51 /**
52 * Toggles this PluginInfoToggle.
53 */
54 public void toggle() {
/*
P/P * Method: void toggle()
*
* Preconditions:
* init'ed(this.toggle)
*
* Postconditions:
* init'ed(this.toggle)
*/
55 toggle = !toggle;
56 }
57
58 /**
59 * Gets the state of this PluginInfo, taking into account the state
60 * of the toggle setting.
61 *
62 * @return True if the plugin is or should be loaded, false otherwise.
63 */
64 public boolean getState() {
/*
P/P * Method: bool getState()
*
* Preconditions:
* this.pi != null
* init'ed(this.toggle)
*
* Postconditions:
* init'ed(return_value)
*/
65 return toggle ^ pi.isLoaded();
66 }
67
68 /**
69 * Retrieves the PluginInfo object associated with this toggle.
70 *
71 * @return This toggle's PluginInfo object.
72 */
73 public PluginInfo getPluginInfo() {
/*
P/P * Method: PluginInfo getPluginInfo()
*
* Postconditions:
* return_value == this.pi
* init'ed(return_value)
*/
74 return pi;
75 }
76
77 /**
78 * Applies the changes to the PluginInfo, if any.
79 */
80 public void apply() {
/*
P/P * Method: void apply()
*
* Preconditions:
* init'ed(this.toggle)
* (soft) this.pi != null
*
* Presumptions:
* com.dmdirc.plugins.PluginManager:getPluginManager(...)@88 != null
*
* Test Vectors:
* this.toggle: {0}, {1}
* com.dmdirc.plugins.PluginInfo:isLoaded(...)@82: {0}, {1}
*/
81 if (toggle) {
82 if (pi.isLoaded()) {
83 pi.unloadPlugin();
84 } else {
85 pi.loadPlugin();
86 }
87
88 PluginManager.getPluginManager().updateAutoLoad(pi);
89 }
90 }
91
92 }
SofCheck Inspector Build Version : 2.17854
| PluginInfoToggle.java |
2009-Jun-25 01:54:24 |
| PluginInfoToggle.class |
2009-Sep-02 17:04:15 |