File Source: ActionNamePanel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionNamePanel__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.dialogs.actioneditor;
    24  
    25  import com.dmdirc.config.prefs.validator.FileNameValidator;
    26  import com.dmdirc.addons.ui_swing.components.validating.ValidatingJTextField;
    27  
    28  import java.beans.PropertyChangeEvent;
    29  import java.beans.PropertyChangeListener;
    30  
    31  import javax.swing.BorderFactory;
    32  import javax.swing.JLabel;
    33  import javax.swing.JPanel;
    34  import javax.swing.JTextField;
    35  
    36  import net.miginfocom.swing.MigLayout;
    37  
    38  /**
    39   * Action name panel.
    40   */
    41  public class ActionNamePanel extends JPanel implements PropertyChangeListener {
    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      /** Original name. */
    50      private final String originalName;
    51      /** Action name field. */
    52      private ValidatingJTextField name;
    53      
    54      /** Instantiates the panel. */
    55      public ActionNamePanel() {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionNamePanel()
                  * 
                  *  Postconditions:
                  *    this.name == &new ValidatingJTextField(initComponents#1)
                  *    this.originalName == &""
                  *    new FileNameValidator(initComponents#3) num objects == 1
                  *    new JLabel(ValidatingJTextField#1) num objects == 1
                  *    new JTextField(initComponents#2) num objects == 1
                  *    new ValidatingJTextField(initComponents#1) num objects == 1
                  *    new ValidatingJTextField(initComponents#1).errorIcon == &new JLabel(ValidatingJTextField#1)
                  *    new ValidatingJTextField(initComponents#1).textField == &new JTextField(initComponents#2)
                  *    new ValidatingJTextField(initComponents#1).validator == &new FileNameValidator(initComponents#3)
                  */
    56          this("");
    57      }
    58  
    59      /** 
    60       * Instantiates the panel.
    61       * 
    62       * @param name Initial name of the action
    63       */
    64      public ActionNamePanel(final String name) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionNamePanel(String)
                  * 
                  *  Postconditions:
                  *    this.name == &new ValidatingJTextField(initComponents#1)
                  *    this.originalName == One-of{&"", name}
                  *    this.originalName != null
                  *    new FileNameValidator(initComponents#3) num objects == 1
                  *    new JLabel(ValidatingJTextField#1) num objects == 1
                  *    new JTextField(initComponents#2) num objects == 1
                  *    new ValidatingJTextField(initComponents#1) num objects == 1
                  *    new ValidatingJTextField(initComponents#1).errorIcon == &new JLabel(ValidatingJTextField#1)
                  *    new ValidatingJTextField(initComponents#1).textField == &new JTextField(initComponents#2)
                  *    new ValidatingJTextField(initComponents#1).validator == &new FileNameValidator(initComponents#3)
                  * 
                  *  Test Vectors:
                  *    name: Inverse{null}, Addr_Set{null}
                  */
    65          super();
    66          
    67          if (name == null) {
    68              this.originalName = "";
    69          } else {
    70              this.originalName = name;
    71          }
    72          
    73          initComponents();
    74          addListeners();
    75          layoutComponents();
    76          this.name.checkError();
    77      }
    78  
    79      /**
    80       * Sets the action name.
    81       * 
    82       * @param name new name
    83       */
    84      void setActionName(final String name) {
                 /* 
    P/P           *  Method: void setActionName(String)
                  * 
                  *  Preconditions:
                  *    this.name != null
                  *    this.name.textField != null
                  */
    85          this.name.setText(name);
    86      }
    87  
    88      /** Validates the name. */
    89      public void validateName() {
                 /* 
    P/P           *  Method: void validateName()
                  * 
                  *  Preconditions:
                  *    this.name != null
                  *    this.name.errorIcon != null
                  *    this.name.textField != null
                  *    (soft) this.name.validator != null
                  */
    90          name.checkError();
    91      }
    92  
    93      /** Initialises the components. */
    94      private void initComponents() {
                 /* 
    P/P           *  Method: void initComponents()
                  * 
                  *  Postconditions:
                  *    this.name == &new ValidatingJTextField(initComponents#1)
                  *    new FileNameValidator(initComponents#3) num objects == 1
                  *    new JLabel(ValidatingJTextField#1) num objects == 1
                  *    new JTextField(initComponents#2) num objects == 1
                  *    new ValidatingJTextField(initComponents#1) num objects == 1
                  *    this.name.errorIcon == &new JLabel(ValidatingJTextField#1)
                  *    this.name.textField == &new JTextField(initComponents#2)
                  *    this.name.validator == &new FileNameValidator(initComponents#3)
                  */
    95          name = new ValidatingJTextField(new JTextField(originalName), new FileNameValidator());
    96      }
    97  
    98      /** Adds the listeners. */
    99      private void addListeners() {
                 /* 
    P/P           *  Method: void addListeners()
                  * 
                  *  Preconditions:
                  *    this.name != null
                  */
   100          name.addPropertyChangeListener("validationResult", this);
   101      }
   102  
   103      /** Lays out the components. */
   104      private void layoutComponents() {
                 /* 
    P/P           *  Method: void layoutComponents()
                  * 
                  *  Preconditions:
                  *    init'ed(this.name)
                  */
   105          setLayout(new MigLayout("wrap 1"));
   106          
   107          setBorder(BorderFactory.createTitledBorder(getBorder(), "Name"));
   108          
   109          add(new JLabel("This action's name:"));
   110          add(name, "growx, pushx");
   111      }
   112      
   113      /**
   114       * Has the action's name changed.
   115       * 
   116       * @return true if the action name has changed.
   117  
   118       */
   119      public boolean hasNameChanged() {
                 /* 
    P/P           *  Method: bool hasNameChanged()
                  * 
                  *  Preconditions:
                  *    this.name != null
                  *    this.name.textField != null
                  * 
                  *  Presumptions:
                  *    javax.swing.JTextField:getText(...)@272 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   120          return getActionName().equals(originalName);
   121      }
   122      
   123      /**
   124       * Returns the name represented by this component.
   125       * 
   126       * @return Current name of this action
   127       */
   128      public String getActionName() {
                 /* 
    P/P           *  Method: String getActionName()
                  * 
                  *  Preconditions:
                  *    this.name != null
                  *    this.name.textField != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   129          return name.getText();
   130      }
   131      
   132      /** {@inheritDoc} */
   133      @Override
   134      public void setEnabled(final boolean enabled) {
                 /* 
    P/P           *  Method: void setEnabled(bool)
                  * 
                  *  Preconditions:
                  *    this.name != null
                  *    this.name.errorIcon != null
                  *    this.name.textField != null
                  *    (soft) this.name.validator != null
                  */
   135          name.setEnabled(enabled);
   136      }
   137  
   138      /** {@inheritDoc} */
   139      @Override
   140      public void propertyChange(final PropertyChangeEvent evt) {
                 /* 
    P/P           *  Method: void propertyChange(PropertyChangeEvent)
                  * 
                  *  Preconditions:
                  *    evt != null
                  */
   141          firePropertyChange("validationResult", evt.getOldValue(), evt.getNewValue());
   142      }
   143  }








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