File Source: NodeLabel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.framemanager.tree.NodeLabel__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.ui_swing.framemanager.tree;
    24  
    25  import com.dmdirc.interfaces.IconChangeListener;
    26  import com.dmdirc.interfaces.NotificationListener;
    27  import com.dmdirc.interfaces.SelectionListener;
    28  import com.dmdirc.ui.interfaces.Window;
    29  
    30  import java.awt.Color;
    31  import java.awt.Dimension;
    32  import javax.swing.BorderFactory;
    33  import javax.swing.Icon;
    34  import javax.swing.JLabel;
    35  
    36  import net.miginfocom.layout.PlatformDefaults;
    37  
    38  /**
    39   * Node label.
    40   */
    41  public class NodeLabel extends JLabel implements SelectionListener,
    42          NotificationListener, IconChangeListener {
    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 = 1;
    50      /** Node window. */
    51      private final Window window;
    52      /** Rollover colours. */
    53      private boolean rollover;
    54      /** notification colour */
    55      private Color notificationColour;
    56      /** Selected. */
    57      private boolean selected;
    58  
    59      /** 
    60       * Instantiates a new node label.
    61       * 
    62       * @param window Window for this node
    63       */
    64      public NodeLabel(final Window window) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.framemanager.tree.NodeLabel(Window)
                  * 
                  *  Postconditions:
                  *    init'ed(this.notificationColour)
                  *    init'ed(this.selected)
                  *    this.window == window
                  *    init'ed(this.window)
                  */
    65          super();
    66  
    67          this.window = window;
    68          
    69          init();
    70      }
    71  
    72      /**
    73       * Initialises the label.
    74       */
    75      private void init() {
                 /* 
    P/P           *  Method: void init()
                  * 
                  *  Presumptions:
                  *    (int) (net.miginfocom.layout.UnitValue:getValue(...)@87) in {-6_442_450_943..6_442_450_943}
                  *    (int) (net.miginfocom.layout.UnitValue:getValue(...)@87) + java.awt.Font:getSize(...)@87 in {-231..232-1}
                  *    com.dmdirc.addons.ui_swing.framemanager.tree.NodeLabel:getFont(...)@87 != null
                  *    com.dmdirc.ui.interfaces.Window:getContainer(...)@80 != null
                  *    com.dmdirc.ui.interfaces.Window:getContainer(...)@84 != null
                  *    ...
                  * 
                  *  Postconditions:
                  *    this.notificationColour == One-of{old this.notificationColour, null}
                  *    possibly_updated(this.selected)
                  * 
                  *  Test Vectors:
                  *    this.window: Inverse{null}, Addr_Set{null}
                  */
    76          if (window == null) {
    77              return;
    78          }
    79  
    80          setText(window.getContainer().toString());
    81  
    82          setOpaque(true);
    83          setToolTipText(null);
    84          setIcon(window.getContainer().getIcon());
    85          setBorder(BorderFactory.createEmptyBorder(1, 0, 2, 0));
    86  
    87          setPreferredSize(new Dimension(100000, getFont().getSize() +
    88                  (int) PlatformDefaults.getUnitValueX("related").
    89                  getValue()));
    90          notificationColour = null;
    91          selected = false;
    92      }
    93  
    94      /** {@inheritDoc} */
    95      @Override
    96      public void selectionChanged(final Window window) {
                 /* 
    P/P           *  Method: void selectionChanged(Window)
                  * 
                  *  Postconditions:
                  *    init'ed(this.selected)
                  */
    97          if (equals(window)) {
    98              selected = true;
    99          } else {
   100              selected = false;
   101          }
   102      }
   103  
   104      /** {@inheritDoc} */
   105      @Override
   106      public void notificationSet(final Window window, final Color colour) {
                 /* 
    P/P           *  Method: void notificationSet(Window, Color)
                  * 
                  *  Postconditions:
                  *    this.notificationColour == One-of{old this.notificationColour, colour}
                  */
   107          if (equals(window)) {
   108              notificationColour = colour;
   109          }
   110      }
   111  
   112      /** {@inheritDoc} */
   113      @Override
   114      public void notificationCleared(final Window window) {
                 /* 
    P/P           *  Method: void notificationCleared(Window)
                  * 
                  *  Postconditions:
                  *    this.notificationColour == One-of{old this.notificationColour, null}
                  */
   115          if (equals(window)) {
   116              notificationColour = null;
   117          }
   118      }
   119  
   120      /** {@inheritDoc} */
   121      @Override
   122      public void iconChanged(final Window window, final Icon icon) {
                 /* 
    P/P           *  Method: void iconChanged(Window, Icon)
                  */
   123          if (equals(window)) {
   124              setIcon(icon);
   125          }
   126      }
   127  
   128      /** 
   129       * Sets the rollover state for the node.
   130       * 
   131       * @param rollover rollover state
   132       */
   133      public void setRollover(final boolean rollover) {
                 /* 
    P/P           *  Method: void setRollover(bool)
                  * 
                  *  Postconditions:
                  *    this.rollover == rollover
                  *    init'ed(this.rollover)
                  */
   134          this.rollover = rollover;
   135      }
   136      
   137      /**
   138       * Is this node a rollover node?
   139       * 
   140       * @return true iff this node is a rollover node
   141       */
   142      public boolean isRollover() {
                 /* 
    P/P           *  Method: bool isRollover()
                  * 
                  *  Preconditions:
                  *    init'ed(this.rollover)
                  * 
                  *  Postconditions:
                  *    return_value == this.rollover
                  *    init'ed(return_value)
                  */
   143          return rollover;
   144      }
   145      
   146      /**
   147       * Is this node a selected node?
   148       * 
   149       * @return true iff this node is a selected node
   150       */
   151      public boolean isSelected() {
                 /* 
    P/P           *  Method: bool isSelected()
                  * 
                  *  Preconditions:
                  *    init'ed(this.selected)
                  * 
                  *  Postconditions:
                  *    return_value == this.selected
                  *    init'ed(return_value)
                  */
   152          return selected;
   153      }
   154      
   155      /**
   156       * Returns the notification colour for this node.
   157       * 
   158       * @return notification colour or null if non set
   159       */
   160      public Color getNotificationColour() {
                 /* 
    P/P           *  Method: Color getNotificationColour()
                  * 
                  *  Preconditions:
                  *    init'ed(this.notificationColour)
                  * 
                  *  Postconditions:
                  *    return_value == this.notificationColour
                  *    init'ed(return_value)
                  */
   161          return notificationColour;
   162      }
   163      
   164      /** {@inheritDoc} */
   165      @Override
   166      public boolean equals(final Object obj) {
                 /* 
    P/P           *  Method: bool equals(Object)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    this.window: Inverse{null}, Addr_Set{null}
                  */
   167          if (window == null) {
   168              return false;
   169          }
   170          
   171          return window.equals(obj);
   172      }
   173  
   174      /** {@inheritDoc} */
   175      @Override
   176      public int hashCode() {
                 /* 
    P/P           *  Method: int hashCode()
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    this.window: Inverse{null}, Addr_Set{null}
                  */
   177          if (window == null) {
   178              return super.hashCode();
   179          }
   180          
   181          return window.hashCode();
   182      }
   183  }








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