File Source: ActionTriggersListPanel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionTriggersListPanel__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.actions.interfaces.ActionType;
    26  import com.dmdirc.ui.IconManager;
    27  import com.dmdirc.addons.ui_swing.components.ImageButton;
    28  import com.dmdirc.addons.ui_swing.components.text.TextLabel;
    29  import com.dmdirc.util.ListenerList;
    30  
    31  import java.awt.event.ActionEvent;
    32  import java.awt.event.ActionListener;
    33  import java.util.ArrayList;
    34  import java.util.List;
    35  
    36  import javax.swing.JLabel;
    37  import javax.swing.JPanel;
    38  import javax.swing.SwingUtilities;
    39  
    40  import net.miginfocom.swing.MigLayout;
    41  
    42  /**
    43   * Action triggers list panel.
    44   */
         /* 
    P/P   *  Method: void access$100(ActionTriggersListPanel)
          * 
          *  Preconditions:
          *    x0 != null
          *    x0.triggers != null
          */
    45  public class ActionTriggersListPanel extends JPanel {
    46  
    47      /**
    48       * A version number for this class. It should be changed whenever the class
    49       * structure is changed (or anything else that would prevent serialized
    50       * objects being unserialized with the new class).
    51       */
    52      private static final long serialVersionUID = 1;
    53      /** Trigger list. */
    54      private List<ActionType> triggers;
    55      /** Listeners. */
    56      private final ListenerList listeners = new ListenerList();
    57  
    58      /** Instantiates the panel. */
    59      public ActionTriggersListPanel() {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionTriggersListPanel()
                  * 
                  *  Postconditions:
                  *    this.listeners == &amp;new ListenerList(ActionTriggersListPanel#1)
                  *    this.triggers == &amp;new ArrayList(ActionTriggersListPanel#2)
                  *    new ArrayList(ActionTriggersListPanel#2) num objects == 1
                  *    new ListenerList(ActionTriggersListPanel#1) num objects == 1
                  */
    60          this(new ArrayList<ActionType>());
    61      }
    62  
    63      /**
    64       * Instantiates the panel.
    65       * 
    66       * @param triggers Trigger list
    67       */
    68      public ActionTriggersListPanel(final List<ActionType> triggers) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionTriggersListPanel(List)
                  * 
                  *  Postconditions:
                  *    this.listeners == &amp;new ListenerList(ActionTriggersListPanel#1)
                  *    this.triggers == &amp;new ArrayList(ActionTriggersListPanel#2)
                  *    new ArrayList(ActionTriggersListPanel#2) num objects == 1
                  *    new ListenerList(ActionTriggersListPanel#1) num objects == 1
                  */
    69          super();
    70  
    71          this.triggers = new ArrayList<ActionType>(triggers);
    72  
    73          initComponents();
    74          addListeners();
    75          layoutComponents();
    76      }
    77  
    78      /** Initialises the components. */
    79      private void initComponents() {
                 /* 
    P/P           *  Method: void initComponents()
                  */
    80          setLayout(new MigLayout("fillx, wrap 2"));
    81      }
    82  
    83      /** Adds the listeners. */
    84      private void addListeners() {
             /* 
    P/P       *  Method: void addListeners()
              */
    85      }
    86  
    87      /** Lays out the components. */
    88      private void layoutComponents() {
                 /* 
    P/P           *  Method: void layoutComponents()
                  * 
                  *  Preconditions:
                  *    this.triggers != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.ui.IconManager:getIconManager(...)@95 != null
                  *    java.util.Iterator:next(...)@94 != null
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@94: {0}, {1}
                  *    java.util.List:size(...)@113: {-231..-1, 1..232-1}, {0}
                  */
    89          synchronized (triggers) {
    90              setVisible(false);
    91  
    92              removeAll();
    93  
    94              for (final ActionType trigger : triggers) {
    95                  final ImageButton button = new ImageButton("delete",
    96                          IconManager.getIconManager().getIcon("close-inactive"),
    97                          IconManager.getIconManager().getIcon("close-active"));
                         /* 
    P/P                   *  Method: void com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionTriggersListPanel$1(ActionTriggersListPanel, ActionType)
                          * 
                          *  Postconditions:
                          *    this.val$trigger == Param_2
                          *    init'ed(this.val$trigger)
                          */
    98                  button.addActionListener(new ActionListener() {
    99  
   100                      /** {@inheritDoc} */
   101                      @Override
   102                      public void actionPerformed(ActionEvent e) {
                                 /* 
    P/P                           *  Method: void actionPerformed(ActionEvent)
                                  */
   103                          delTrigger(trigger);
   104                      }
   105                  });
   106                  
   107                  button.setEnabled(isEnabled());
   108                  
   109                  add(new JLabel(trigger.getName()), "growx, pushx");
   110                  add(button, "right");
   111              }
   112  
   113              if (triggers.size() == 0) {
   114                  add(new TextLabel("No triggers."));
   115              }
   116              setVisible(true);
   117          }
   118      }
   119  
   120      /**
   121       * Adds a trigger to the list.
   122       * 
   123       * @param trigger Trigger to add
   124       */
   125      public void addTrigger(final ActionType trigger) {
                 /* 
    P/P           *  Method: void addTrigger(ActionType)
                  */
   126          SwingUtilities.invokeLater(new Runnable() {
   127  
   128              /** {@inheritDoc} */
   129              @Override
   130              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    this.triggers != null
                          * 
                          *  Presumptions:
                          *    java.util.List:size(...)@133 >= -231+1
                          */
   131                  synchronized (triggers) {
   132                      triggers.add(trigger);
   133                      firePropertyChange("triggerCount", triggers.size() - 1,
   134                              triggers.size());
   135  
   136                      layoutComponents();
   137                  }
   138              }
   139          });
   140      }
   141  
   142      /**
   143       * Deletes a trigger from the list.
   144       * 
   145       * @param trigger Trigger to delete
   146       */
   147      public void delTrigger(final ActionType trigger) {
                 /* 
    P/P           *  Method: void delTrigger(ActionType)
                  */
   148          SwingUtilities.invokeLater(new Runnable() {
   149  
   150              /** {@inheritDoc} */
   151              @Override
   152              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    this.listeners != null
                          *    this.triggers != null
                          * 
                          *  Presumptions:
                          *    java.util.List:size(...)@156 <= 232-2
                          */
   153                  synchronized (triggers) {
   154                      triggers.remove(trigger);
   155                      fireTriggerRemoved(trigger);
   156                      firePropertyChange("triggerCount", triggers.size() + 1,
   157                              triggers.size());
   158  
   159                      layoutComponents();
   160                  }
   161              }
   162          });
   163      }
   164  
   165      /**
   166       * Clears the trigger list.
   167       */
   168      public void clearTriggers() {
                 /* 
    P/P           *  Method: void clearTriggers()
                  * 
                  *  Preconditions:
                  *    this.triggers != null
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@169: {0}, {1}
                  */
   169          for (ActionType trigger : triggers) {
   170              delTrigger(trigger);
   171          }
   172      }
   173  
   174      /**
   175       * Returns the current list of triggers.
   176       * 
   177       * @return Trigger list
   178       */
   179      public List<ActionType> getTriggers() {
                 /* 
    P/P           *  Method: List getTriggers()
                  * 
                  *  Preconditions:
                  *    init'ed(this.triggers)
                  * 
                  *  Postconditions:
                  *    return_value == this.triggers
                  *    init'ed(return_value)
                  */
   180          synchronized (triggers) {
   181              return triggers;
   182          }
   183      }
   184  
   185      /**
   186       * Gets the trigger at the specified index.
   187       * 
   188       * @param index Index to retrieve
   189       * 
   190       * @return Requested action trigger
   191       */
   192      public ActionType getTrigger(final int index) {
                 /* 
    P/P           *  Method: ActionType getTrigger(int)
                  * 
                  *  Preconditions:
                  *    this.triggers != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   193          return triggers.get(index);
   194      }
   195  
   196      /**
   197       * Returns the number of triggers.
   198       * 
   199       * @return Trigger count
   200       */
   201      public int getTriggerCount() {
                 /* 
    P/P           *  Method: int getTriggerCount()
                  * 
                  *  Preconditions:
                  *    this.triggers != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   202          synchronized (triggers) {
   203              return triggers.size();
   204          }
   205      }
   206  
   207      /**
   208       * Adds an ActionTriggerRemovalListener to the listener list.
   209       *
   210       * @param listener Listener to add
   211       */
   212      public void addTriggerListener(final ActionTriggerRemovalListener listener) {
                 /* 
    P/P           *  Method: void addTriggerListener(ActionTriggerRemovalListener)
                  * 
                  *  Preconditions:
                  *    (soft) this.listeners != null
                  * 
                  *  Test Vectors:
                  *    listener: Inverse{null}, Addr_Set{null}
                  */
   213          if (listener == null) {
   214              return;
   215          }
   216  
   217          listeners.add(ActionTriggerRemovalListener.class, listener);
   218      }
   219  
   220      /**
   221       * Removes an ActionTriggerRemovalListener from the listener list.
   222       *
   223       * @param listener Listener to remove
   224       */
   225      public void removeTriggerListener(final ActionTriggerRemovalListener listener) {
                 /* 
    P/P           *  Method: void removeTriggerListener(ActionTriggerRemovalListener)
                  * 
                  *  Preconditions:
                  *    this.listeners != null
                  */
   226          listeners.remove(ActionTriggerRemovalListener.class, listener);
   227      }
   228  
   229      /**
   230       * Fired when the an action trigger is removed.
   231       *
   232       * @param type Removed trigger
   233       */
   234      protected void fireTriggerRemoved(final ActionType type) {
                 /* 
    P/P           *  Method: void fireTriggerRemoved(ActionType)
                  * 
                  *  Preconditions:
                  *    this.listeners != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.util.ListenerList:get(...)@235 != null
                  *    java.util.Iterator:next(...)@235 != null
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@235: {0}, {1}
                  */
   235          for (ActionTriggerRemovalListener listener : listeners.get(ActionTriggerRemovalListener.class)) {
   236              listener.triggerRemoved(type);
   237          }
   238      }
   239  
   240      /** {@inheritDoc} */
   241      @Override
   242      public void setEnabled(final boolean enabled) {
                 /* 
    P/P           *  Method: void setEnabled(bool)
                  */
   243          super.setEnabled(enabled);
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.actioneditor.ActionTriggersListPanel$4(ActionTriggersListPanel)
                  */
   244          SwingUtilities.invokeLater(new Runnable() {
   245  
   246              /** {@inheritDoc} */
   247              @Override
   248              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    this.triggers != null
                          */
   249                  layoutComponents();
   250              }
   251          });
   252      }
   253      
   254      /** Validates the triggers. */
   255      public void validateTriggers() {
                 /* 
    P/P           *  Method: void validateTriggers()
                  * 
                  *  Preconditions:
                  *    this.triggers != null
                  */
   256          firePropertyChange("triggerCount", triggers.size(), triggers.size());
   257      }
   258  }








SofCheck Inspector Build Version : 2.17854
ActionTriggersListPanel.java 2009-Jun-25 01:54:24
ActionTriggersListPanel.class 2009-Sep-02 17:04:16
ActionTriggersListPanel$1.class 2009-Sep-02 17:04:16
ActionTriggersListPanel$2.class 2009-Sep-02 17:04:16
ActionTriggersListPanel$3.class 2009-Sep-02 17:04:16
ActionTriggersListPanel$4.class 2009-Sep-02 17:04:16