File Source: UpdateConfigPanel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.prefs.UpdateConfigPanel__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.prefs;
    24  
    25  import com.dmdirc.config.ConfigManager;
    26  import com.dmdirc.config.Identity;
    27  import com.dmdirc.config.IdentityManager;
    28  import com.dmdirc.config.prefs.PreferencesInterface;
    29  import com.dmdirc.addons.ui_swing.components.PackingTable;
    30  import com.dmdirc.updater.UpdateChecker;
    31  
    32  import java.awt.event.ActionEvent;
    33  import java.awt.event.ActionListener;
    34  
    35  import javax.swing.JButton;
    36  import javax.swing.JCheckBox;
    37  import javax.swing.JLabel;
    38  import javax.swing.JPanel;
    39  import javax.swing.JScrollPane;
    40  
    41  import net.miginfocom.swing.MigLayout;
    42  
    43  /**
    44   * Updates configuration UI.
    45   */
    46  public class UpdateConfigPanel extends JPanel implements ActionListener,
    47          PreferencesInterface {
    48  
    49      /**
    50       * A version number for this class. It should be changed whenever the class
    51       * structure is changed (or anything else that would prevent serialized
    52       * objects being unserialized with the new class).
    53       */
    54      private static final long serialVersionUID = 1;
    55      /** Global checkbox. */
    56      private JCheckBox enable;
    57      /** Table scroll pane, */
    58      private JScrollPane scrollPane;
    59      /** Component table model. */
    60      private UpdateTableModel tableModel;
    61      /** Component table. */
    62      private PackingTable table;
    63      /** Check now button. */
    64      private JButton checkNow;
    65  
    66      /**
    67       * Instantiates a new update config panel.
    68       */
             /* 
    P/P       *  Method: void com.dmdirc.addons.ui_swing.dialogs.prefs.UpdateConfigPanel()
              * 
              *  Preconditions:
              *    init'ed(com/dmdirc/addons/ui_swing/dialogs/prefs/SwingPreferencesDialog.CLIENT_HEIGHT)
              * 
              *  Postconditions:
              *    this.checkNow == &new JButton(initComponents#5)
              *    this.enable == &new JCheckBox(initComponents#1)
              *    this.scrollPane == &new JScrollPane(initComponents#2)
              *    this.table == &new PackingTable(initComponents#4)
              *    this.tableModel == &new UpdateTableModel(initComponents#3)
              *    new ArrayList(UpdateTableModel#1) num objects == 1
              *    new HashMap(UpdateTableModel#2) num objects == 1
              *    new JButton(initComponents#5) num objects == 1
              *    new JCheckBox(initComponents#1) num objects == 1
              *    new JScrollPane(initComponents#2) num objects == 1
              *    ...
              */
    69      public UpdateConfigPanel() {
    70          initComponents();
    71          addListeners();
    72          layoutComponents();
    73      }
    74  
    75      /** {@inheritDoc} */
    76      @Override
    77      public void save() {
                 /* 
    P/P           *  Method: void save()
                  * 
                  *  Preconditions:
                  *    this.enable != null
                  *    this.tableModel != null
                  *    this.tableModel.updates != null
                  *    (soft) this.tableModel.enabled != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.config.IdentityManager:getConfigIdentity(...)@78 != null
                  * 
                  *  Test Vectors:
                  *    java.lang.Boolean:booleanValue(...)@87: {0}, {1}
                  *    javax.swing.JCheckBox:isSelected(...)@79: {0}, {1}
                  */
    78          final Identity identity = IdentityManager.getConfigIdentity();
    79          if (enable.isSelected()) {
    80              identity.setOption("updater", "enable", true);
    81          } else {
    82              identity.setOption("updater", "enable", false);
    83          }
    84  
    85          for (int i = 0; i < tableModel.getRowCount(); i++) {
    86              final String componentName = (String) tableModel.getValueAt(i, 0);
    87              if ((Boolean) tableModel.getValueAt(i, 1)) {
    88                  identity.unsetOption("updater", "enable-" + componentName);
    89              } else {
    90                  identity.setOption("updater", "enable-" + componentName, false);
    91              }
    92          }
    93      }
    94  
    95      /**
    96       * Initialises the components.
    97       */
    98      private void initComponents() {
                 /* 
    P/P           *  Method: void initComponents()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.config.IdentityManager:getGlobalConfig(...)@99 != null
                  * 
                  *  Postconditions:
                  *    this.checkNow == &amp;new JButton(initComponents#5)
                  *    this.enable == &amp;new JCheckBox(initComponents#1)
                  *    this.scrollPane == &amp;new JScrollPane(initComponents#2)
                  *    this.table == &amp;new PackingTable(initComponents#4)
                  *    this.tableModel == &amp;new UpdateTableModel(initComponents#3)
                  *    new ArrayList(UpdateTableModel#1) num objects == 1
                  *    new HashMap(UpdateTableModel#2) num objects == 1
                  *    new JButton(initComponents#5) num objects == 1
                  *    new JCheckBox(initComponents#1) num objects == 1
                  *    new JScrollPane(initComponents#2) num objects == 1
                  *    ...
                  */
    99          final ConfigManager config = IdentityManager.getGlobalConfig();
   100          enable = new JCheckBox();
   101          scrollPane = new JScrollPane();
   102          tableModel = new UpdateTableModel(UpdateChecker.getComponents());
   103          table = new PackingTable(tableModel, false, scrollPane);
   104          checkNow = new JButton("Check now");
   105  
   106          enable.setSelected(config.getOptionBool("updater", "enable"));
   107          scrollPane.setViewportView(table);
   108      }
   109  
   110      /**
   111       * Adds the listeners.
   112       */
   113      private void addListeners() {
                 /* 
    P/P           *  Method: void addListeners()
                  * 
                  *  Preconditions:
                  *    this.checkNow != null
                  */
   114          checkNow.addActionListener(this);
   115      }
   116  
   117      /**
   118       * Lays out the components.
   119       */
   120      private void layoutComponents() {
                 /* 
    P/P           *  Method: void layoutComponents()
                  * 
                  *  Preconditions:
                  *    init'ed(com/dmdirc/addons/ui_swing/dialogs/prefs/SwingPreferencesDialog.CLIENT_HEIGHT)
                  *    init'ed(this.checkNow)
                  *    init'ed(this.enable)
                  *    init'ed(this.scrollPane)
                  */
   121          setLayout(new MigLayout("fillx, ins 0, hmax " +
   122                  SwingPreferencesDialog.CLIENT_HEIGHT));
   123  
   124          add(new JLabel("Update checking:"), "split");
   125          add(enable, "growx, pushx, wrap");
   126          add(scrollPane, "wrap");
   127          add(checkNow, "right");
   128      }
   129  
   130      /** 
   131       * {@inheritDoc}
   132       * 
   133       * @param e Action event
   134       */
   135      @Override
   136      public void actionPerformed(final ActionEvent e) {
                 /* 
    P/P           *  Method: void actionPerformed(ActionEvent)
                  */
   137          UpdateChecker.checkNow();
   138      }
   139  }








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