File Source: OldTextLabel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.components.text.OldTextLabel__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.components.text;
    24  
    25  import java.awt.Insets;
    26  
    27  import javax.swing.JTextPane;
    28  import javax.swing.plaf.basic.BasicTextPaneUI;
    29  import javax.swing.text.DefaultStyledDocument;
    30  import javax.swing.text.SimpleAttributeSet;
    31  import javax.swing.text.StyleConstants;
    32  import javax.swing.text.StyledDocument;
    33  
    34  /**
    35   * Dyamnic text label.
    36   */
         /* 
    P/P   *  Method: Document getDocument()
          * 
          *  Postconditions:
          *    init'ed(return_value)
          */
    37  public class OldTextLabel extends JTextPane {
    38  
    39      /**
    40       * A version number for this class. It should be changed whenever the
    41       * class structure is changed (or anything else that would prevent
    42       * serialized objects being unserialized with the new class).
    43       */
    44      private static final long serialVersionUID = 1;
    45      /** Simple attribute set. */
    46      private SimpleAttributeSet sas;
    47  
    48      /**
    49       * Creates a new instance of TextLabel.
    50       */
    51      public OldTextLabel() {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.components.text.OldTextLabel()
                  * 
                  *  Postconditions:
                  *    this.sas == &new SimpleAttributeSet(OldTextLabel#4)
                  *    new SimpleAttributeSet(OldTextLabel#4) num objects == 1
                  */
    52          this(null, true);
    53      }
    54  
    55      /**
    56       * Creates a new instance of TextLabel.
    57       *
    58       * @param text Text to display
    59       */
    60      public OldTextLabel(final String text) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.components.text.OldTextLabel(String)
                  * 
                  *  Postconditions:
                  *    this.sas == &new SimpleAttributeSet(OldTextLabel#4)
                  *    new SimpleAttributeSet(OldTextLabel#4) num objects == 1
                  */
    61          this(text, true);
    62      }
    63  
    64      /**
    65       * Creates a new instance of TextLabel.
    66       *
    67       * @param text Text to display
    68       * @param justified Justify the text?
    69       */
    70      public OldTextLabel(final String text, final boolean justified) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.components.text.OldTextLabel(String, bool)
                  * 
                  *  Presumptions:
                  *    com.dmdirc.addons.ui_swing.components.text.OldTextLabel:getFont(...)@84 != null
                  *    com.dmdirc.addons.ui_swing.components.text.OldTextLabel:getFont(...)@85 != null
                  *    com.dmdirc.addons.ui_swing.components.text.OldTextLabel:getFont(...)@86 != null
                  *    com.dmdirc.addons.ui_swing.components.text.OldTextLabel:getFont(...)@87 != null
                  * 
                  *  Postconditions:
                  *    this.sas == &new SimpleAttributeSet(OldTextLabel#4)
                  *    new SimpleAttributeSet(OldTextLabel#4) num objects == 1
                  * 
                  *  Test Vectors:
                  *    justified: {0}, {1}
                  */
    71          super(new DefaultStyledDocument());
    72          setUI(new BasicTextPaneUI());
    73  
    74          setOpaque(false);
    75          setEditable(false);
    76          setHighlighter(null);
    77          setMargin(new Insets(0, 0, 0, 0));
    78  
    79          sas = new SimpleAttributeSet();
    80          if (justified) {
    81              StyleConstants.setAlignment(sas, StyleConstants.ALIGN_JUSTIFIED);
    82          }
    83  
    84          StyleConstants.setFontFamily(sas, getFont().getFamily());
    85          StyleConstants.setFontSize(sas, getFont().getSize());
    86          StyleConstants.setBold(sas, getFont().isBold());
    87          StyleConstants.setItalic(sas, getFont().isItalic());
    88  
    89          setText(text);
    90      }
    91  
    92      /** {@inheritDoc} */
    93      @Override
    94      public StyledDocument getDocument() {
                 /* 
    P/P           *  Method: StyledDocument getDocument()
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    95          return (StyledDocument) super.getDocument();
    96      }
    97  
    98      /** {@inheritDoc} */
    99      @Override
   100      public void setText(final String t) {
                 /* 
    P/P           *  Method: void setText(String)
                  * 
                  *  Preconditions:
                  *    (soft) init'ed(this.sas)
                  * 
                  *  Presumptions:
                  *    javax.swing.JTextPane:getDocument(...)@95 != null
                  * 
                  *  Test Vectors:
                  *    t: Addr_Set{null}, Inverse{null}
                  *    java.lang.String:isEmpty(...)@102: {1}, {0}
                  */
   101          super.setText(t);
   102          if (t != null && !t.isEmpty()) {
   103              getDocument().setParagraphAttributes(0, t.length(), sas, true);
   104          }
   105      }
   106  }








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