File Source: UpdaterLabel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.components.statusbar.UpdaterLabel__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2008 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.ui_swing.components.statusbar;
    24  
    25  import com.dmdirc.addons.ui_swing.MainFrame;
    26  import com.dmdirc.addons.ui_swing.dialogs.updater.SwingRestartDialog;
    27  import com.dmdirc.addons.ui_swing.dialogs.updater.SwingUpdaterDialog;
    28  import com.dmdirc.updater.UpdateCheckerListener;
    29  import com.dmdirc.ui.IconManager;
    30  import com.dmdirc.ui.interfaces.StatusBarComponent;
    31  import com.dmdirc.updater.UpdateChecker;
    32  import com.dmdirc.updater.UpdateChecker.STATE;
    33  
    34  import java.awt.Dialog.ModalityType;
    35  import java.awt.event.MouseEvent;
    36  import java.awt.event.MouseListener;
    37  
    38  import javax.swing.BorderFactory;
    39  import javax.swing.JLabel;
    40  
    41  /**
    42   * Updater label is responsible for handling the display of updates in the
    43   * status bar.
    44   */
    45  public class UpdaterLabel extends JLabel implements StatusBarComponent, 
    46          MouseListener, UpdateCheckerListener {
    47  
    48      /**
    49       * A version number for this class. It should be changed whenever the class
    50       * structure is changed (or anything else that would prevent serialized
    51       * objects being unserialized with the new class).
    52       */
    53      private static final long serialVersionUID = 1;
    54      /** Swing controller. */
    55      private MainFrame mainFrame;
    56  
    57      /**
    58       * Instantiates a new updater label, handles showing updates on the status bar.
    59       * 
    60       * @param mainFrame Main frame
    61       */
    62      public UpdaterLabel(final MainFrame mainFrame) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.components.statusbar.UpdaterLabel(MainFrame)
                  * 
                  *  Postconditions:
                  *    this.mainFrame == mainFrame
                  *    init'ed(this.mainFrame)
                  */
    63          super();
    64          
    65          this.mainFrame = mainFrame;
    66          setBorder(BorderFactory.createEtchedBorder());
    67          addMouseListener(this);
    68          UpdateChecker.addListener(this);
    69          setVisible(false);
    70      }
    71  
    72      /**
    73       * {@inheritDoc}
    74       *
    75       * @param mouseEvent Mouse event
    76       */
    77      @Override
    78      public void mousePressed(final MouseEvent mouseEvent) {
    79      //Ignore.
             /* 
    P/P       *  Method: void mousePressed(MouseEvent)
              */
    80      }
    81  
    82      /**
    83       * {@inheritDoc}
    84       *
    85       * @param mouseEvent Mouse event
    86       */
    87      @Override
    88      public void mouseReleased(final MouseEvent mouseEvent) {
    89      //Ignore.
             /* 
    P/P       *  Method: void mouseReleased(MouseEvent)
              */
    90      }
    91  
    92      /**
    93       * {@inheritDoc}
    94       *
    95       * @param mouseEvent Mouse event
    96       */
    97      @Override
    98      public void mouseEntered(final MouseEvent mouseEvent) {
    99      //Ignore.
             /* 
    P/P       *  Method: void mouseEntered(MouseEvent)
              */
   100      }
   101  
   102      /**
   103       * {@inheritDoc}
   104       *
   105       * @param mouseEvent Mouse event
   106       */
   107      @Override
   108      public void mouseExited(final MouseEvent mouseEvent) {
   109      //Ignore.
             /* 
    P/P       *  Method: void mouseExited(MouseEvent)
              */
   110      }
   111  
   112      /**
   113       * {@inheritDoc}
   114       *
   115       * @param mouseEvent Mouse event
   116       */
   117      @Override
   118      public void mouseClicked(final MouseEvent mouseEvent) {
                 /* 
    P/P           *  Method: void mouseClicked(MouseEvent)
                  * 
                  *  Preconditions:
                  *    mouseEvent != null
                  *    (soft) init'ed(this.mainFrame)
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.updater.UpdateChecker$STATE.CHECKING)
                  *    init'ed(com.dmdirc.updater.UpdateChecker$STATE.RESTART_REQUIRED)
                  *    com.dmdirc.updater.UpdateChecker:getStatus(...)@120 != null
                  *    com.dmdirc.updater.UpdateChecker:getStatus(...)@124 != null
                  *    init'ed(java.awt.Dialog$ModalityType.MODELESS)
                  * 
                  *  Test Vectors:
                  *    com.dmdirc.updater.UpdateChecker_STATE:equals(...)@120: {0}, {1}
                  *    com.dmdirc.updater.UpdateChecker_STATE:equals(...)@124: {1}, {0}
                  *    java.awt.event.MouseEvent:getButton(...)@119: {-231..0, 2..232-1}, {1}
                  */
   119          if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
   120              if (UpdateChecker.getStatus().equals(UpdateChecker.STATE.RESTART_REQUIRED)) {
   121                  SwingRestartDialog restartDialog = new SwingRestartDialog(
   122                          mainFrame, ModalityType.MODELESS);
   123                  restartDialog.setVisible(true);
   124              } else if (!UpdateChecker.getStatus().equals(UpdateChecker.STATE.CHECKING)) {
   125                  SwingUpdaterDialog.showSwingUpdaterDialog(
   126                          UpdateChecker.getAvailableUpdates(), mainFrame);
   127              }
   128          }
   129      }
   130  
   131      /** {@inheritDoc} */
   132      @Override
   133      public void statusChanged(final STATE newStatus) {
                 /* 
    P/P           *  Method: void statusChanged(UpdateChecker$STATE)
                  * 
                  *  Preconditions:
                  *    newStatus != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.ui.IconManager:getIconManager(...)@142 != null
                  *    com.dmdirc.ui.IconManager:getIconManager(...)@146 != null
                  *    com.dmdirc.ui.IconManager:getIconManager(...)@149 != null
                  *    init'ed(com.dmdirc.updater.UpdateChecker$STATE.CHECKING)
                  *    init'ed(com.dmdirc.updater.UpdateChecker$STATE.IDLE)
                  *    ...
                  * 
                  *  Test Vectors:
                  *    com.dmdirc.updater.UpdateChecker_STATE:equals(...)@134: {0}, {1}
                  *    com.dmdirc.updater.UpdateChecker_STATE:equals(...)@140: {0}, {1}
                  *    com.dmdirc.updater.UpdateChecker_STATE:equals(...)@144: {0}, {1}
                  *    com.dmdirc.updater.UpdateChecker_STATE:equals(...)@147: {0}, {1}
                  */
   134          if (newStatus.equals(STATE.IDLE)) {
   135              setVisible(false);
   136          } else {
   137              setVisible(true);
   138          }
   139  
   140          if (newStatus.equals(STATE.CHECKING)) {
   141              setToolTipText("Checking for updates...");
   142              setIcon(IconManager.getIconManager().
   143                      getIcon("hourglass"));
   144          } else if (newStatus.equals(STATE.UPDATES_AVAILABLE)) {
   145              setToolTipText("Updates available");
   146              setIcon(IconManager.getIconManager().getIcon("update"));
   147          } else if (newStatus.equals(STATE.RESTART_REQUIRED)) {
   148              setToolTipText("Client restart required to finish updating");
   149              setIcon(IconManager.getIconManager().getIcon("restart-needed"));
   150          }
   151      }
   152  }








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