File Source: SwingStatusBar.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar__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.SwingController;
    27  import com.dmdirc.logger.ErrorLevel;
    28  import com.dmdirc.logger.Logger;
    29  import com.dmdirc.ui.interfaces.StatusBar;
    30  import com.dmdirc.ui.interfaces.StatusBarComponent;
    31  import com.dmdirc.ui.interfaces.StatusMessageNotifier;
    32  
    33  import java.awt.Component;
    34  import java.util.Arrays;
    35  
    36  import javax.swing.JPanel;
    37  import javax.swing.SwingUtilities;
    38  
    39  import net.miginfocom.swing.MigLayout;
    40  
    41  /** Status bar, shows message and info on the gui. */
         /* 
    P/P   *  Method: InviteLabel access$200(SwingStatusBar)
          * 
          *  Preconditions:
          *    x0 != null
          * 
          *  Postconditions:
          *    return_value == x0.inviteLabel
          *    init'ed(return_value)
          */
    42  public final class SwingStatusBar extends JPanel implements StatusBar {
    43  
    44      /**
    45       * A version number for this class. It should be changed whenever the class
    46       * structure is changed (or anything else that would prevent serialized
    47       * objects being unserialized with the new class).
    48       */
    49      private static final long serialVersionUID = 5;
    50      /** message label. */
    51      private final MessageLabel messageLabel;
    52      /** error panel. */
    53      private final ErrorPanel errorPanel;
    54      /** update label. */
    55      private final UpdaterLabel updateLabel;
    56      /** Invite label. */
    57      private final InviteLabel inviteLabel;
    58      /** Swing controller. */
    59      private SwingController controller;
    60      /** Main frame. */
    61      private MainFrame mainFrame;
    62  
    63      /**
    64       * Creates a new instance of SwingStatusBar.
    65       * 
    66       * @param controller Swing controller
    67       * @param mainFrame Main frame
    68       */
    69      public SwingStatusBar(final SwingController controller, final MainFrame mainFrame) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar(SwingController, MainFrame)
                  * 
                  *  Presumptions:
                  *    com.dmdirc.logger.ErrorManager:getErrorManager(...)@71 != null
                  * 
                  *  Postconditions:
                  *    this.controller == controller
                  *    init'ed(this.controller)
                  *    this.errorPanel.controller == this.controller
                  *    this.errorPanel == &new ErrorPanel(SwingStatusBar#2)
                  *    this.inviteLabel == &new InviteLabel(SwingStatusBar#4)
                  *    this.mainFrame == mainFrame
                  *    init'ed(this.mainFrame)
                  *    this.errorPanel.mainFrame == this.mainFrame
                  *    this.inviteLabel.mainFrame == this.mainFrame
                  *    this.updateLabel.mainFrame == this.mainFrame
                  *    ...
                  */
    70          super();
    71          
    72          this.controller = controller;
    73          this.mainFrame = mainFrame;
    74  
    75          messageLabel = new MessageLabel();
    76          errorPanel = new ErrorPanel(controller, mainFrame, this);
    77          updateLabel = new UpdaterLabel(mainFrame);
    78          inviteLabel = new InviteLabel(mainFrame);
    79  
    80          setLayout(new MigLayout("fill, ins 0, hidemode 3"));
    81  
    82          add(messageLabel, "growx, pushx, sgy components, hmax 20, hmin 20");
    83          add(updateLabel, "sgy components, hmax 20, hmin 20, wmin 20, shrink 0");
    84          add(errorPanel, "sgy components, hmax 20, hmin 20, wmin 20, shrink 0");
    85          add(inviteLabel, "sgy components, hmax 20, hmin 20, wmin 20, shrink 0");
    86      }
    87  
    88      /** {@inheritDoc} */
    89      @Override
    90      public void setMessage(final String newMessage) {
                 /* 
    P/P           *  Method: void setMessage(String)
                  * 
                  *  Preconditions:
                  *    this.messageLabel != null
                  */
    91          messageLabel.setMessage(newMessage);
    92      }
    93  
    94      /** {@inheritDoc} */
    95      @Override
    96      public void setMessage(final String newMessage,
    97              final StatusMessageNotifier newNotifier) {
                 /* 
    P/P           *  Method: void setMessage(String, StatusMessageNotifier)
                  * 
                  *  Preconditions:
                  *    this.messageLabel != null
                  */
    98          messageLabel.setMessage(newMessage, newNotifier);
    99      }
   100  
   101      /** {@inheritDoc} */
   102      @Override
   103      public void setMessage(final String iconType, final String newMessage) {
                 /* 
    P/P           *  Method: void setMessage(String, String)
                  * 
                  *  Preconditions:
                  *    this.messageLabel != null
                  */
   104          messageLabel.setMessage(iconType, newMessage);
   105      }
   106  
   107      /** {@inheritDoc} */
   108      @Override
   109      public void setMessage(final String iconType, final String newMessage,
   110              final StatusMessageNotifier newNotifier) {
                 /* 
    P/P           *  Method: void setMessage(String, String, StatusMessageNotifier)
                  * 
                  *  Preconditions:
                  *    this.messageLabel != null
                  */
   111          messageLabel.setMessage(iconType, newMessage, newNotifier);
   112      }
   113  
   114      /** {@inheritDoc} */
   115      @Override
   116      public void setMessage(final String newMessage,
   117              final StatusMessageNotifier newNotifier, final int timeout) {
                 /* 
    P/P           *  Method: void setMessage(String, StatusMessageNotifier, int)
                  * 
                  *  Preconditions:
                  *    this.messageLabel != null
                  */
   118          messageLabel.setMessage(newMessage, newNotifier, timeout);
   119      }
   120  
   121      /** {@inheritDoc} */
   122      @Override
   123      public synchronized void setMessage(final String iconType, 
   124              final String newMessage,
   125              final StatusMessageNotifier newNotifier, final int timeout) {
                 /* 
    P/P           *  Method: void setMessage(String, String, StatusMessageNotifier, int)
                  * 
                  *  Preconditions:
                  *    this.messageLabel != null
                  */
   126          messageLabel.setMessage(iconType, newMessage, newNotifier, timeout);
   127      }
   128  
   129      /** {@inheritDoc} */
   130      @Override
   131      public void clearMessage() {
                 /* 
    P/P           *  Method: void clearMessage()
                  * 
                  *  Preconditions:
                  *    this.messageLabel != null
                  * 
                  *  Postconditions:
                  *    this.messageLabel.messageNotifier == null
                  */
   132          messageLabel.clearMessage();
   133      }
   134  
   135      /** {@inheritDoc} */
   136      @Override
   137      public void addComponent(final StatusBarComponent component) {
                 /* 
    P/P           *  Method: void addComponent(StatusBarComponent)
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.logger.ErrorLevel.HIGH)
                  *    java.util.Arrays:asList(...)@144 != null
                  * 
                  *  Test Vectors:
                  *    java.util.List:contains(...)@144: {1}, {0}
                  */
   138          if (!(component instanceof Component)) {
   139              Logger.appError(ErrorLevel.HIGH, "Error adding status bar component", 
   140                      new IllegalArgumentException("Component must be an " +
   141                      "instance of java.awt.component"));
   142              return;
   143          }
   144          if (!Arrays.asList(getComponents()).contains(component)) {
                     /* 
    P/P               *  Method: void com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar$1(SwingStatusBar, StatusBarComponent)
                      * 
                      *  Postconditions:
                      *    this.val$component == Param_2
                      *    init'ed(this.val$component)
                      */
   145              SwingUtilities.invokeLater(new Runnable() {
   146  
   147                  /** {@inheritDoc} */
   148                  @Override
   149                  public void run() {
                             /* 
    P/P                       *  Method: void run()
                              */
   150                      remove(updateLabel);
   151                      remove(errorPanel);
   152                      remove(inviteLabel);
   153                      add((Component) component,
   154                              "sgy components, hmax 20, hmin 20, wmin 20, shrink 0");
   155                      add(updateLabel,
   156                              "sgy components, hmax 20, hmin 20, wmin 20, shrink 0");
   157                      add(inviteLabel,
   158                              "sgy components, hmax 20, hmin 20, wmin 20, shrink 0");
   159                      add(errorPanel,
   160                              "sgy components, hmax 20, hmin 20, wmin 20, shrink 0");
   161                      validate();
   162                  }
   163              });
   164          }
   165      }
   166  
   167      /** {@inheritDoc} */
   168      @Override
   169      public void removeComponent(final StatusBarComponent component) {
                 /* 
    P/P           *  Method: void removeComponent(StatusBarComponent)
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.logger.ErrorLevel.HIGH)
                  */
   170          if (!(component instanceof Component)) {
   171              Logger.appError(ErrorLevel.HIGH, "Error adding status bar component", 
   172                      new IllegalArgumentException("Component must be an " +
   173                      "instance of java.awt.component"));
   174              return;
   175          }
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar$2(SwingStatusBar, StatusBarComponent)
                  * 
                  *  Postconditions:
                  *    this.val$component == Param_2
                  *    init'ed(this.val$component)
                  */
   176          SwingUtilities.invokeLater(new Runnable() {
   177  
   178              /** {@inheritDoc} */
   179              @Override
   180              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          */
   181                  remove((Component) component);
   182                  validate();
   183              }
   184              });
   185      }
   186  
   187      /**
   188       * Returns the message label for this status bar. This is intended to be used
   189       * for advanced plugins that wish to do compliated things with messages.
   190       *
   191       * @return Message label component
   192       */
   193      public MessageLabel getMessageComponent() {
                 /* 
    P/P           *  Method: MessageLabel getMessageComponent()
                  * 
                  *  Postconditions:
                  *    return_value == this.messageLabel
                  *    init'ed(return_value)
                  */
   194          return messageLabel;
   195      }
   196  }








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