File Source: OsdPlugin.java

         /* 
    P/P   *  Method: com.dmdirc.addons.osd.OsdPlugin__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.CommandManager;
    26  import com.dmdirc.config.IdentityManager;
    27  import com.dmdirc.config.prefs.CategoryChangeListener;
    28  import com.dmdirc.config.prefs.PreferencesCategory;
    29  import com.dmdirc.config.prefs.PreferencesInterface;
    30  import com.dmdirc.config.prefs.PreferencesManager;
    31  import com.dmdirc.config.prefs.PreferencesSetting;
    32  import com.dmdirc.config.prefs.PreferencesType;
    33  import com.dmdirc.config.prefs.SettingChangeListener;
    34  import com.dmdirc.plugins.Plugin;
    35  import java.util.HashMap;
    36  import java.util.Map;
    37  
    38  /**
    39   * Allows the user to display on-screen-display messages.
    40   * @author chris
    41   */
    42  public final class OsdPlugin extends Plugin implements CategoryChangeListener,
    43          PreferencesInterface, SettingChangeListener {
    44      
    45      /** Config OSD Window. */
    46      private OsdWindow osdWindow;
    47      
    48      /** OSD Command. */
    49      private OsdCommand command;
    50      
    51      /** X-axis position of OSD. */
    52      private int x;
    53      
    54      /** Y-axis potion of OSD. */
    55      private int y;
    56      
    57      /** Setting objects with registered change listeners. */
    58      private PreferencesSetting fontSizeSetting, backgroundSetting, foregroundSetting;
    59      
    60      /**
    61       * Creates a new instance of OsdPlugin.
    62       */
    63      public OsdPlugin() {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.osd.OsdPlugin()
                  */
    64          super();
    65      }
    66      
    67      /** {@inheritDoc} */
    68      @Override
    69      public void onLoad() {
                 /* 
    P/P           *  Method: void onLoad()
                  * 
                  *  Postconditions:
                  *    this.command == &new OsdCommand(onLoad#1)
                  *    new OsdCommand(onLoad#1) num objects == 1
                  *    this.command.plugin == this
                  *    this.command.plugin != null
                  */
    70          command = new OsdCommand(this);
    71      }
    72      
    73      /** {@inheritDoc} */
    74      @Override
    75      public void onUnload() {
                 /* 
    P/P           *  Method: void onUnload()
                  * 
                  *  Preconditions:
                  *    init'ed(this.command)
                  */
    76          CommandManager.unregisterCommand(command);
    77      }
    78  
    79      /** {@inheritDoc} */
    80      @Override
    81      public void showConfig(final PreferencesManager manager) {
                 /* 
    P/P           *  Method: void showConfig(PreferencesManager)
                  * 
                  *  Preconditions:
                  *    manager != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.config.IdentityManager:getGlobalConfig(...)@82 != null
                  *    com.dmdirc.config.IdentityManager:getGlobalConfig(...)@83 != null
                  *    com.dmdirc.config.prefs.PreferencesManager:getCategory(...)@116 != null
                  *    init'ed(com.dmdirc.config.prefs.PreferencesType.COLOUR)
                  *    init'ed(com.dmdirc.config.prefs.PreferencesType.INTEGER)
                  * 
                  *  Postconditions:
                  *    init'ed(this.backgroundSetting)
                  *    init'ed(this.fontSizeSetting)
                  *    init'ed(this.foregroundSetting)
                  *    init'ed(this.x)
                  *    init'ed(this.y)
                  */
    82          x = IdentityManager.getGlobalConfig().getOptionInt(getDomain(), "locationX");
    83          y = IdentityManager.getGlobalConfig().getOptionInt(getDomain(), "locationY");
    84          
    85          final PreferencesCategory category = new PreferencesCategory("OSD",
    86                  "General configuration for OSD plugin.");
    87          
    88          fontSizeSetting = new PreferencesSetting(PreferencesType.INTEGER,
    89                  getDomain(), "fontSize", "Font size", "Changes the font " +
    90                  "size of the OSD").registerChangeListener(this);
    91          backgroundSetting = new PreferencesSetting(PreferencesType.COLOUR,
    92                  getDomain(), "bgcolour", "Background colour",
    93                  "Background colour for the OSD").registerChangeListener(this);
    94          foregroundSetting = new PreferencesSetting(PreferencesType.COLOUR,
    95                  getDomain(), "fgcolour", "Foreground colour",
    96                  "Foreground colour for the OSD").registerChangeListener(this);
    97                  
    98          category.addSetting(fontSizeSetting);
    99          category.addSetting(backgroundSetting);
   100          category.addSetting(foregroundSetting);
   101          category.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
   102                  getDomain(), "timeout", "Timeout", "Length of time in " +
   103                  "seconds before the OSD window closes"));
   104          
   105          final Map<String, String> posOptions = new HashMap<String, String>();
   106          posOptions.put("down", "Place new windows below old ones");
   107          posOptions.put("up", "Place new windows above old ones");
   108          posOptions.put("close", "Close existing windows");
   109          posOptions.put("ontop", "Place new windows on top of existing window");
   110          
   111          category.addSetting(new PreferencesSetting(getDomain(), "newbehaviour",
   112                  "New window policy", "What to do when an OSD Window "
   113                  + "is opened when there are other, existing windows open", posOptions));
   114  
   115          category.addChangeListener(this);
   116          manager.getCategory("Plugins").addSubCategory(category);
   117          manager.registerSaveListener(this);
   118      }
   119  
   120      /** {@inheritDoc} */
   121      @Override
   122      public void categorySelected(final PreferencesCategory category) {
                 /* 
    P/P           *  Method: void categorySelected(PreferencesCategory)
                  * 
                  *  Preconditions:
                  *    this.backgroundSetting != null
                  *    this.fontSizeSetting != null
                  *    this.foregroundSetting != null
                  *    init'ed(this.x)
                  *    init'ed(this.y)
                  *    (soft) com/dmdirc/addons/osd/OsdWindow.windows != null
                  * 
                  *  Postconditions:
                  *    this.osdWindow == &amp;new OsdWindow(categorySelected#1)
                  *    new JLabel(OsdWindow#5) num objects == 1
                  *    new JPanel(OsdWindow#1) num objects == 1
                  *    new OsdWindow(categorySelected#1) num objects == 1
                  *    this.osdWindow.config == 1
                  *    this.osdWindow.label == &amp;new JLabel(OsdWindow#5)
                  *    this.osdWindow.panel == &amp;new JPanel(OsdWindow#1)
                  *    this.osdWindow.plugin == this
                  *    this.osdWindow.plugin != null
                  */
   123          osdWindow = new OsdWindow("Please drag this OSD to position", true, x, y, this);
   124          osdWindow.setBackgroundColour(backgroundSetting.getValue());
   125          osdWindow.setForegroundColour(foregroundSetting.getValue());
   126          osdWindow.setFontSize(Integer.parseInt(fontSizeSetting.getValue()));
   127      }
   128  
   129      /** {@inheritDoc} */
   130      @Override
   131      public void categoryDeselected(final PreferencesCategory category) {
                 /* 
    P/P           *  Method: void categoryDeselected(PreferencesCategory)
                  * 
                  *  Preconditions:
                  *    com/dmdirc/addons/osd/OsdWindow.windows != null
                  *    this.osdWindow != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.addons.osd.OsdWindow:getLocationOnScreen(...)@132 != null
                  *    com.dmdirc.addons.osd.OsdWindow:getLocationOnScreen(...)@133 != null
                  * 
                  *  Postconditions:
                  *    this.osdWindow == null
                  *    init'ed(this.x)
                  *    init'ed(this.y)
                  */
   132          x = osdWindow.getLocationOnScreen().x;
   133          y = osdWindow.getLocationOnScreen().y;
   134          
   135          osdWindow.dispose();
   136          osdWindow = null;
   137      }
   138  
   139      /** {@inheritDoc} */
   140      @Override
   141      public void save() {
                 /* 
    P/P           *  Method: void save()
                  * 
                  *  Preconditions:
                  *    init'ed(this.x)
                  *    init'ed(this.y)
                  * 
                  *  Presumptions:
                  *    com.dmdirc.config.IdentityManager:getConfigIdentity(...)@142 != null
                  *    com.dmdirc.config.IdentityManager:getConfigIdentity(...)@143 != null
                  */
   142          IdentityManager.getConfigIdentity().setOption(getDomain(), "locationX", x);
   143          IdentityManager.getConfigIdentity().setOption(getDomain(), "locationY", y);
   144      }
   145  
   146      /** {@inheritDoc} */
   147      @Override
   148      public void settingChanged(final PreferencesSetting setting) {
                 /* 
    P/P           *  Method: void settingChanged(PreferencesSetting)
                  * 
                  *  Preconditions:
                  *    init'ed(this.osdWindow)
                  *    (soft) setting != null
                  *    (soft) init'ed(this.backgroundSetting)
                  *    (soft) init'ed(this.fontSizeSetting)
                  *    (soft) init'ed(this.foregroundSetting)
                  *    (soft) this.osdWindow.label != null
                  *    (soft) this.osdWindow.panel != null
                  * 
                  *  Test Vectors:
                  *    this.osdWindow: Inverse{null}, Addr_Set{null}
                  *    java.lang.Object:equals(...)@155: {0}, {1}
                  *    java.lang.Object:equals(...)@157: {0}, {1}
                  *    java.lang.Object:equals(...)@159: {0}, {1}
                  */
   149          if (osdWindow == null) {
   150              // They've changed categories but are somehow poking settings.
   151              // Ignore the request.
   152              return;
   153          }
   154          
   155          if (setting.equals(fontSizeSetting)) {
   156              osdWindow.setFontSize(Integer.parseInt(setting.getValue()));
   157          } else if (setting.equals(backgroundSetting)) {
   158              osdWindow.setBackgroundColour(setting.getValue());
   159          } else if (setting.equals(foregroundSetting)) {
   160              osdWindow.setForegroundColour(setting.getValue());
   161          }
   162      }
   163  
   164  }








SofCheck Inspector Build Version : 2.17854
OsdPlugin.java 2009-Jun-25 01:54:24
OsdPlugin.class 2009-Sep-02 17:04:15