File Source: IgnoreListPanel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.serversetting.IgnoreListPanel__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  package com.dmdirc.addons.ui_swing.dialogs.serversetting;
    23  
    24  import com.dmdirc.IgnoreList;
    25  import com.dmdirc.Server;
    26  import com.dmdirc.config.prefs.validator.NotEmptyValidator;
    27  import com.dmdirc.config.prefs.validator.RegexValidator;
    28  import com.dmdirc.config.prefs.validator.ValidatorChain;
    29  import com.dmdirc.addons.ui_swing.components.StandardInputDialog;
    30  import com.dmdirc.addons.ui_swing.UIUtilities;
    31  
    32  import java.awt.Dialog.ModalityType;
    33  import java.awt.Window;
    34  import java.awt.event.ActionEvent;
    35  import java.awt.event.ActionListener;
    36  
    37  import javax.swing.JButton;
    38  import javax.swing.JCheckBox;
    39  import javax.swing.JLabel;
    40  import javax.swing.JList;
    41  import javax.swing.JOptionPane;
    42  import javax.swing.JPanel;
    43  import javax.swing.JScrollPane;
    44  import javax.swing.ListSelectionModel;
    45  import javax.swing.event.ListSelectionEvent;
    46  import javax.swing.event.ListSelectionListener;
    47  
    48  import net.miginfocom.swing.MigLayout;
    49  
    50  /**
    51   * Ignore list panel.
    52   */
         /* 
    P/P   *  Method: void access$200(IgnoreListPanel)
          * 
          *  Preconditions:
          *    x0 != null
          *    x0.cachedIgnoreList != null
          *    x0.listModel != null
          *    x0.listModel.ignoreList != null
          *    x0.viewToggle != null
          */
    53  public final class IgnoreListPanel extends JPanel implements ActionListener,
    54          ListSelectionListener {
    55  
    56      /**
    57       * A version number for this class. It should be changed whenever the class
    58       * structure is changed (or anything else that would prevent serialized
    59       * objects being unserialized with the new class).
    60       */
    61      private static final long serialVersionUID = 2;
    62      /** Parent server. */
    63      private final Server server;
    64      /** Add button. */
    65      private JButton addButton;
    66      /** Remove button. */
    67      private JButton delButton;
    68      /** View toggle. */
    69      private JCheckBox viewToggle;
    70      /** Size label. */
    71      private JLabel sizeLabel;
    72      /** Ignore list. */
    73      private JList list;
    74      /** Cached ignore list. */
    75      private IgnoreList cachedIgnoreList;
    76      /** Ignore list model . */
    77      private IgnoreListModel listModel;
    78      /** Parent window. */
    79      private Window parentWindow;
    80  
    81      /**
    82       * Creates a new instance of IgnoreList.
    83       *
    84       * @param server Parent server
    85       * @param parentWindow Parent window
    86       */
    87      public IgnoreListPanel(final Server server, final Window parentWindow) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.serversetting.IgnoreListPanel(Server, Window)
                  * 
                  *  Preconditions:
                  *    server != null
                  * 
                  *  Postconditions:
                  *    this.addButton == &new JButton(initComponents#5)
                  *    this.cachedIgnoreList == &new IgnoreList(initComponents#1)
                  *    new IgnoreListModel(initComponents#2).ignoreList == &new IgnoreList(initComponents#1)
                  *    this.delButton == &new JButton(initComponents#6)
                  *    this.list == &new JList(initComponents#3)
                  *    this.listModel == &new IgnoreListModel(initComponents#2)
                  *    this.parentWindow == parentWindow
                  *    init'ed(this.parentWindow)
                  *    this.server == server
                  *    this.server != null
                  *    ...
                  */
    88          super();
    89  
    90          this.server = server;
    91          this.parentWindow = parentWindow;
    92  
    93          this.setOpaque(UIUtilities.getTabbedPaneOpaque());
    94          initComponents();
    95          addListeners();
    96          populateList();
    97      }
    98  
    99      /** Initialises teh components. */
   100      private void initComponents() {
                 /* 
    P/P           *  Method: void initComponents()
                  * 
                  *  Preconditions:
                  *    this.server != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.Server:getIgnoreList(...)@101 != null
                  * 
                  *  Postconditions:
                  *    this.addButton == &new JButton(initComponents#5)
                  *    this.cachedIgnoreList == &new IgnoreList(initComponents#1)
                  *    this.listModel.ignoreList == &new IgnoreList(initComponents#1)
                  *    this.delButton == &new JButton(initComponents#6)
                  *    this.list == &new JList(initComponents#3)
                  *    this.listModel == &new IgnoreListModel(initComponents#2)
                  *    this.sizeLabel == &new JLabel(initComponents#7)
                  *    this.viewToggle == &new JCheckBox(initComponents#8)
                  *    new IgnoreList(initComponents#1) num objects == 1
                  *    new IgnoreListModel(initComponents#2) num objects == 1
                  *    ...
                  */
   101          cachedIgnoreList = new IgnoreList(server.getIgnoreList().getRegexList());
   102  
   103          listModel = new IgnoreListModel(cachedIgnoreList);
   104          list = new JList(listModel);
   105  
   106          final JScrollPane scrollPane = new JScrollPane(list);
   107  
   108          list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   109  
   110          addButton = new JButton("Add");
   111          delButton = new JButton("Remove");
   112  
   113          sizeLabel = new JLabel("0 entries");
   114          viewToggle = new JCheckBox("Use advanced expressions");
   115          viewToggle.setOpaque(UIUtilities.getTabbedPaneOpaque());
   116          viewToggle.setSelected(!cachedIgnoreList.canConvert());
   117          viewToggle.setEnabled(cachedIgnoreList.canConvert());
   118  
   119          setLayout(new MigLayout("fill, wrap 1"));
   120          add(scrollPane, "grow, push");
   121          add(sizeLabel, "split 2, pushx, growx");
   122          add(viewToggle, "alignx center");
   123          add(addButton, "split 2, width 50%");
   124          add(delButton, "width 50%");
   125      }
   126  
   127      /** Updates the size label. */
   128      private void updateSizeLabel() {
                 /* 
    P/P           *  Method: void updateSizeLabel()
                  * 
                  *  Preconditions:
                  *    this.cachedIgnoreList != null
                  *    this.sizeLabel != null
                  */
   129          sizeLabel.setText(cachedIgnoreList.count() + " entr" + (cachedIgnoreList.count() == 1 ? "y" : "ies"));
   130      }
   131  
   132      /** Adds listeners to the components. */
   133      private void addListeners() {
                 /* 
    P/P           *  Method: void addListeners()
                  * 
                  *  Preconditions:
                  *    this.addButton != null
                  *    this.delButton != null
                  *    this.list != null
                  *    this.viewToggle != null
                  * 
                  *  Presumptions:
                  *    javax.swing.JList:getSelectionModel(...)@137 != null
                  */
   134          addButton.addActionListener(this);
   135          delButton.addActionListener(this);
   136          viewToggle.addActionListener(this);
   137          list.getSelectionModel().addListSelectionListener(this);
   138      }
   139  
   140      /** Populates the ignore list. */
   141      private void populateList() {
                 /* 
    P/P           *  Method: void populateList()
                  * 
                  *  Preconditions:
                  *    this.cachedIgnoreList != null
                  *    this.list != null
                  *    this.sizeLabel != null
                  *    (soft) this.delButton != null
                  * 
                  *  Test Vectors:
                  *    javax.swing.JList:getSelectedIndex(...)@142: {-231..-2, 0..232-1}, {-1}
                  */
   142          if (list.getSelectedIndex() == -1) {
   143              delButton.setEnabled(false);
   144          }
   145  
   146          updateSizeLabel();
   147      }
   148  
   149      /** Updates the list. */
   150      private void updateList() {
                 /* 
    P/P           *  Method: void updateList()
                  * 
                  *  Preconditions:
                  *    this.cachedIgnoreList != null
                  *    this.listModel != null
                  *    this.listModel.ignoreList != null
                  *    this.viewToggle != null
                  * 
                  *  Test Vectors:
                  *    com.dmdirc.IgnoreList:canConvert(...)@153: {0}, {1}
                  */
   151          listModel.notifyUpdated();
   152  
   153          if (cachedIgnoreList.canConvert()) {
   154              viewToggle.setEnabled(true);
   155          } else {
   156              viewToggle.setEnabled(false);
   157              viewToggle.setSelected(true);
   158          }
   159      }
   160  
   161      /** Saves the ignore list. */
   162      public void saveList() {
                 /* 
    P/P           *  Method: void saveList()
                  * 
                  *  Preconditions:
                  *    this.cachedIgnoreList != null
                  *    this.server != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.Server:getIgnoreList(...)@163 != null
                  *    com.dmdirc.Server:getIgnoreList(...)@164 != null
                  */
   163          server.getIgnoreList().clear();
   164          server.getIgnoreList().addAll(cachedIgnoreList.getRegexList());
   165          server.saveIgnoreList();
   166      }
   167  
   168      /** 
   169       * {@inheritDoc}
   170       * 
   171       * @param e Action event
   172       */
   173      @SuppressWarnings("unchecked")
   174      @Override
   175      public void actionPerformed(final ActionEvent e) {
                 /* 
    P/P           *  Method: void actionPerformed(ActionEvent)
                  * 
                  *  Preconditions:
                  *    e != null
                  *    init'ed(this.addButton)
                  *    (soft) this.cachedIgnoreList != null
                  *    (soft) init'ed(this.delButton)
                  *    (soft) this.list != null
                  *    (soft) this.listModel != null
                  *    (soft) this.listModel.ignoreList != null
                  *    (soft) init'ed(this.parentWindow)
                  *    (soft) this.viewToggle != null
                  * 
                  *  Presumptions:
                  *    init'ed(java.awt.Dialog$ModalityType.MODELESS)
                  * 
                  *  Postconditions:
                  *    possibly_updated(this.listModel.isSimple)
                  * 
                  *  Test Vectors:
                  *    javax.swing.JCheckBox:isSelected(...)@177: {0}, {1}
                  *    javax.swing.JList:getSelectedIndex(...)@210: {-1}, {-231..-2, 0..232-1}
                  *    javax.swing.JOptionPane:showConfirmDialog(...)@210: {-231..-1, 1..232-1}, {0}
                  */
   176          if (e.getSource() == addButton) {
   177              new StandardInputDialog(parentWindow, ModalityType.MODELESS, 
   178                      "New ignore list entry",
   179                      "Please enter the new ignore list entry",
   180                      viewToggle.isSelected() ? new ValidatorChain<String>(
   181                      new NotEmptyValidator(), new RegexValidator())
                             /* 
    P/P                       *  Method: void com.dmdirc.addons.ui_swing.dialogs.serversetting.IgnoreListPanel$1(IgnoreListPanel, Window, Dialog$ModalityType, String, String, Validator)
                              */
   182                      : new NotEmptyValidator()) {
   183  
   184                  /**
   185                   * A version number for this class. It should be changed whenever the class
   186                   * structure is changed (or anything else that would prevent serialized
   187                   * objects being unserialized with the new class).
   188                   */
   189                  private static final long serialVersionUID = 2;
   190  
   191                  /** {@inheritDoc} */
   192                  @Override
   193                  public boolean save() {
                             /* 
    P/P                       *  Method: bool save()
                              * 
                              *  Preconditions:
                              *    this.cachedIgnoreList != null
                              *    this.listModel != null
                              *    this.listModel.ignoreList != null
                              *    this.viewToggle != null
                              * 
                              *  Postconditions:
                              *    return_value == 1
                              * 
                              *  Test Vectors:
                              *    javax.swing.JCheckBox:isSelected(...)@194: {0}, {1}
                              */
   194                      if (viewToggle.isSelected()) {
   195                          cachedIgnoreList.add(getText());
   196                      } else {
   197                          cachedIgnoreList.addSimple(getText());
   198                      }
   199  
   200                      updateList();
   201                      return true;
   202                  }
   203  
   204                  /** {@inheritDoc} */
   205                  @Override
   206                  public void cancelled() {
   207                      //Ignore
                         /* 
    P/P                   *  Method: void cancelled()
                          */
   208                  }
   209              }.display();
   210          } else if (e.getSource() == delButton && list.getSelectedIndex() != -1 && JOptionPane.showConfirmDialog(this,
   211                  "Are you sure you want to delete this item?",
   212                  "Delete Confirmation", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
   213              cachedIgnoreList.remove(list.getSelectedIndex());
   214  
   215              updateList();
   216          } else if (e.getSource() == viewToggle) {
   217              listModel.setIsSimple(!viewToggle.isSelected());
   218          }
   219      }
   220  
   221      /** {@inheritDoc} */
   222      @Override
   223      public void valueChanged(final ListSelectionEvent e) {
                 /* 
    P/P           *  Method: void valueChanged(ListSelectionEvent)
                  * 
                  *  Preconditions:
                  *    this.delButton != null
                  *    this.list != null
                  * 
                  *  Test Vectors:
                  *    javax.swing.JList:getSelectedIndex(...)@224: {-231..-2, 0..232-1}, {-1}
                  */
   224          if (list.getSelectedIndex() == -1) {
   225              delButton.setEnabled(false);
   226          } else {
   227              delButton.setEnabled(true);
   228          }
   229      }
   230  }








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