File Source: SubstitutionsPanel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionsPanel__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.substitutions;
    24  
    25  import com.dmdirc.addons.ui_swing.components.text.TextLabel;
    26  
    27  import java.util.List;
    28  
    29  import javax.swing.BorderFactory;
    30  import javax.swing.JLabel;
    31  import javax.swing.JPanel;
    32  import javax.swing.JSeparator;
    33  
    34  import net.miginfocom.swing.MigLayout;
    35  
    36  /**
    37   * Generic substitutions panel
    38   * 
    39   * @param <T> Type of substitution
    40   */
    41  public abstract class SubstitutionsPanel<T> extends JPanel {
    42  
    43      /**
    44       * A version number for this class. It should be changed whenever the class
    45       * structure is changed (or anything else that would prevent serialized
    46       * objects being unserialized with the new class).
    47       */
    48      private static final long serialVersionUID = 1;
    49      /** Substitions list. */
    50      protected List<SubstitutionLabel> substitutions;
    51      /** Description. */
    52      private String description;
    53      /** Seperator alignment. */
    54      private Alignment alignment;
    55  
    56      /** Separator alignment enum. */
             /* 
    P/P       *  Method: void com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionsPanel$Alignment(String, int)
              */
    57      public enum Alignment {
    58  
    59          /** Horizontal separator. */
                 /* 
    P/P           *  Method: com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionsPanel$Alignment__static_init
                  * 
                  *  Postconditions:
                  *    $VALUES == &amp;new SubstitutionsPanel$Alignment[](SubstitutionsPanel$Alignment__static_init#3)
                  *    HORIZONTAL == &amp;new SubstitutionsPanel$Alignment(SubstitutionsPanel$Alignment__static_init#1)
                  *    $VALUES[0] == &amp;new SubstitutionsPanel$Alignment(SubstitutionsPanel$Alignment__static_init#1)
                  *    VERTICAL == &amp;new SubstitutionsPanel$Alignment(SubstitutionsPanel$Alignment__static_init#2)
                  *    $VALUES[1] == &amp;new SubstitutionsPanel$Alignment(SubstitutionsPanel$Alignment__static_init#2)
                  *    new SubstitutionsPanel$Alignment(SubstitutionsPanel$Alignment__static_init#1) num objects == 1
                  *    new SubstitutionsPanel$Alignment(SubstitutionsPanel$Alignment__static_init#2) num objects == 1
                  *    new SubstitutionsPanel$Alignment[](SubstitutionsPanel$Alignment__static_init#3) num objects == 1
                  *    $VALUES.length == 2
                  */
    60          HORIZONTAL,
    61          /** Vertical separator. */
    62          VERTICAL;
    63      }
    64  
    65      /** 
    66       * Instantiates the panel.
    67       * 
    68       * @param description Description
    69       */
    70      public SubstitutionsPanel(final String description) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionsPanel(String)
                  * 
                  *  Postconditions:
                  *    this.alignment == &amp;com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionsPanel$Alignment__static_init.new SubstitutionsPanel$Alignment(SubstitutionsPanel$Alignment__static_init#2)
                  *    this.description == description
                  *    init'ed(this.description)
                  */
    71          this(description, Alignment.VERTICAL, null);
    72      }
    73  
    74      /** 
    75       * Instantiates the panel.
    76       * 
    77       * @param description Description
    78       * @param type Action type
    79       */
    80      public SubstitutionsPanel(final String description, final T type) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionsPanel(String, Object)
                  * 
                  *  Postconditions:
                  *    this.alignment == &amp;com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionsPanel$Alignment__static_init.new SubstitutionsPanel$Alignment(SubstitutionsPanel$Alignment__static_init#2)
                  *    this.description == description
                  *    init'ed(this.description)
                  */
    81          this(description, Alignment.VERTICAL, type);
    82      }
    83  
    84      /** 
    85       * Instantiates the panel.
    86       * 
    87       * @param description Description
    88       * @param alignment Alignment of the separator
    89       */
    90      public SubstitutionsPanel(final String description,
    91              final Alignment alignment) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionsPanel(String, SubstitutionsPanel$Alignment)
                  * 
                  *  Preconditions:
                  *    alignment != null
                  * 
                  *  Postconditions:
                  *    this.alignment == alignment
                  *    this.alignment != null
                  *    this.description == description
                  *    init'ed(this.description)
                  */
    92          this(description, alignment, null);
    93      }
    94  
    95      /** 
    96       * Instantiates the panel.
    97       * 
    98       * @param description Description
    99       * @param alignment Alignment of the separator
   100       * @param type Action type
   101       */
   102      public SubstitutionsPanel(final String description,
   103              final Alignment alignment, final T type) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionsPanel(String, SubstitutionsPanel$Alignment, Object)
                  * 
                  *  Preconditions:
                  *    alignment != null
                  * 
                  *  Postconditions:
                  *    this.alignment == alignment
                  *    this.alignment != null
                  *    this.description == description
                  *    init'ed(this.description)
                  */
   104          super();
   105  
   106          this.description = description;
   107          this.alignment = alignment;
   108  
   109          initComponents();
   110          addListeners();
   111          setType(type);
   112      }
   113  
   114      /** Initialises the components. */
   115      private void initComponents() {
                 /* 
    P/P           *  Method: void initComponents()
                  * 
                  *  Preconditions:
                  *    this.alignment != null
                  * 
                  *  Test Vectors:
                  *    com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionsPanel_Alignment:equals(...)@117: {0}, {1}
                  */
   116          setBorder(BorderFactory.createTitledBorder(getBorder(), "Substitutions"));
   117          if (alignment.equals(Alignment.VERTICAL)) {
   118              setLayout(new MigLayout("fill, wrap 4, pack"));
   119          } else {
   120              setLayout(new MigLayout("fill, wrap 3, pack"));
   121          }
   122      }
   123  
   124      /** Adds the listeners. */
   125      private void addListeners() {
             /* 
    P/P       *  Method: void addListeners()
              */
   126      }
   127  
   128      /** Lays out the components. */
   129      protected void layoutComponents() {
                 /* 
    P/P           *  Method: void layoutComponents()
                  * 
                  *  Preconditions:
                  *    this.alignment != null
                  *    init'ed(this.description)
                  *    this.substitutions != null
                  * 
                  *  Test Vectors:
                  *    com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionsPanel:getComponentCount(...)@149: {-231..1, 3..232-1}, {2}
                  *    com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionsPanel_Alignment:equals(...)@137: {0}, {1}
                  *    java.util.Iterator:hasNext(...)@145: {0}, {1}
                  */
   130          final boolean visible = isVisible();
   131          setVisible(false);
   132          removeAll();
   133  
   134          final TextLabel textLabel = new TextLabel(description +
   135                  ". Drag and drop, or click on an item when " +
   136                  "editing the field, to insert it.");
   137          if (alignment.equals(Alignment.VERTICAL)) {
   138              add(textLabel, "spany, aligny top, wmin 225, wmax 225");
   139              add(new JSeparator(JSeparator.VERTICAL), "growy, pushy, spany");
   140          } else {
   141              add(textLabel, "spanx, aligny top");
   142              add(new JSeparator(JSeparator.HORIZONTAL), "growy, pushy, spanx");
   143          }
   144  
   145          for (SubstitutionLabel label : substitutions) {
   146              add(label, "sgx subslabel, aligny top, growx, pushx");
   147          }
   148  
   149          if (getComponentCount() == 2) {
   150              add(new JLabel("No substitutions."),
   151                      "growx, pushx, aligny top, align center");
   152          }
   153  
   154          setVisible(visible);
   155      }
   156  
   157      /**
   158       * Sets the type for this substitution panel.
   159       * 
   160       * @param type New action type
   161       */
   162      public abstract void setType(final T type);
   163  }








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