File Source: CategoryPanel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.prefs.CategoryPanel__static_init
          */
     1  /*
     2   * 
     3   * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
     4   * 
     5   * Permission is hereby granted, free of charge, to any person obtaining a copy
     6   * of this software and associated documentation files (the "Software"), to deal
     7   * in the Software without restriction, including without limitation the rights
     8   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     9   * copies of the Software, and to permit persons to whom the Software is
    10   * furnished to do so, subject to the following conditions:
    11   * 
    12   * The above copyright notice and this permission notice shall be included in
    13   * all copies or substantial portions of the Software.
    14   * 
    15   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    16   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    17   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    18   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    19   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    20   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    21   * SOFTWARE.
    22   */
    23  
    24  package com.dmdirc.addons.ui_swing.dialogs.prefs;
    25  
    26  import com.dmdirc.addons.ui_swing.UIUtilities;
    27  import com.dmdirc.addons.ui_swing.components.text.TextLabel;
    28  import com.dmdirc.addons.ui_swing.components.TitlePanel;
    29  import com.dmdirc.addons.ui_swing.components.ToolTipPanel;
    30  import com.dmdirc.config.prefs.PreferencesCategory;
    31  
    32  import java.awt.Window;
    33  import java.util.Collections;
    34  import java.util.HashMap;
    35  import java.util.Map;
    36  
    37  import javax.swing.BorderFactory;
    38  import javax.swing.JPanel;
    39  import javax.swing.JScrollPane;
    40  import javax.swing.ScrollPaneConstants;
    41  import javax.swing.SwingWorker;
    42  
    43  import net.miginfocom.layout.PlatformDefaults;
    44  import net.miginfocom.swing.MigLayout;
    45  
    46  /**
    47   * Panel representing a preferences category.
    48   */
         /* 
    P/P   *  Method: JPanel access$300(CategoryPanel)
          * 
          *  Preconditions:
          *    x0 != null
          *    init'ed(x0.loading)
          * 
          *  Postconditions:
          *    return_value == x0.loading
          *    init'ed(return_value)
          */
    49  public class CategoryPanel extends JPanel {
    50  
    51      /**
    52       * A version number for this class. It should be changed whenever the
    53       * class structure is changed (or anything else that would prevent
    54       * serialized objects being unserialized with the new class).
    55       */
    56      private static final long serialVersionUID = -3268284364607758509L;
    57      /** Panel gap. */
    58      private final int padding = (int) PlatformDefaults.getUnitValueX("related").
    59              getValue();
    60      /** Panel left padding. */
    61      private final int leftPadding = (int) PlatformDefaults.getPanelInsets(1).
    62              getValue();
    63      /** Panel right padding. */
    64      private final int rightPadding = (int) PlatformDefaults.getPanelInsets(3).
    65              getValue();
    66      /** Active preferences category. */
    67      private PreferencesCategory category;
    68      /** Parent window. */
    69      private Window parent;
    70      /** Title label. */
    71      private TitlePanel title;
    72      /** Tooltip display area. */
    73      private ToolTipPanel tooltip;
    74      /** Contents Panel. */
    75      private JScrollPane scrollPane;
    76      /** Loading panel. */
    77      private JPanel loading;
    78      /** Loading panel. */
    79      private JPanel nullCategory;
    80      /** Loading panel. */
    81      private JPanel waitingCategory;
    82      /** Category panel map. */
    83      private Map<PreferencesCategory, JPanel> panels;
    84      /** Category loading swing worker. */
    85      private SwingWorker worker;
    86      /** Waiting. */
    87      private boolean waiting;
    88  
    89      /**
    90       * Instantiates a new category panel.
    91       *
    92       * @param parent Parent window
    93       */
    94      public CategoryPanel(final Window parent) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.prefs.CategoryPanel(Window)
                  * 
                  *  Presumptions:
                  *    (int) (net.miginfocom.layout.UnitValue:getValue(...)@58) in {-231..232-1}
                  *    (int) (net.miginfocom.layout.UnitValue:getValue(...)@61) in {-231..232-1}
                  *    (int) (net.miginfocom.layout.UnitValue:getValue(...)@64) in {-231..232-1}
                  *    java.util.Collections:synchronizedMap(...)@109 != null
                  * 
                  *  Postconditions:
                  *    this.category == null
                  *    init'ed(this.leftPadding)
                  *    this.loading == &amp;new JPanel(CategoryPanel#3)
                  *    this.nullCategory == &amp;new JPanel(CategoryPanel#6)
                  *    init'ed(this.padding)
                  *    this.panels != null
                  *    this.parent == parent
                  *    init'ed(this.parent)
                  *    init'ed(this.rightPadding)
                  *    this.scrollPane == &amp;new JScrollPane(CategoryPanel#12)
                  *    ...
                  */
    95          this(parent, null);
    96      }
    97  
    98      /**
    99       * Instantiates a new category panel.
   100       *
   101       * @param parent Parent window
   102       * @param category Initial category
   103       */
   104      public CategoryPanel(final Window parent,
   105              final PreferencesCategory category) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.prefs.CategoryPanel(Window, PreferencesCategory)
                  * 
                  *  Presumptions:
                  *    (int) (net.miginfocom.layout.UnitValue:getValue(...)@58) in {-231..232-1}
                  *    (int) (net.miginfocom.layout.UnitValue:getValue(...)@61) in {-231..232-1}
                  *    (int) (net.miginfocom.layout.UnitValue:getValue(...)@64) in {-231..232-1}
                  *    java.util.Collections:synchronizedMap(...)@109 != null
                  *    net.miginfocom.layout.PlatformDefaults:getPanelInsets(...)@61 != null
                  *    ...
                  * 
                  *  Postconditions:
                  *    this.category == category
                  *    init'ed(this.category)
                  *    init'ed(this.leftPadding)
                  *    this.loading == &amp;new JPanel(CategoryPanel#3)
                  *    this.nullCategory == &amp;new JPanel(CategoryPanel#6)
                  *    init'ed(this.padding)
                  *    this.panels != null
                  *    this.parent == parent
                  *    init'ed(this.parent)
                  *    init'ed(this.rightPadding)
                  *    ...
                  */
   106          super(new MigLayout("fillx, wrap, ins 0"));
   107          this.parent = parent;
   108  
   109          panels = Collections.synchronizedMap(
   110                  new HashMap<PreferencesCategory, JPanel>());
   111  
   112          loading = new JPanel(new MigLayout("fillx"));
   113          loading.add(new TextLabel("Loading..."));
   114  
   115          nullCategory = new JPanel(new MigLayout("fillx"));
   116          nullCategory.add(new TextLabel("Please select a category."));
   117  
   118          waitingCategory = new JPanel(new MigLayout("fillx"));
   119          waitingCategory.add(new TextLabel("Please wait, loading..."));
   120  
   121          scrollPane = new JScrollPane(loading);
   122          scrollPane.setHorizontalScrollBarPolicy(
   123                  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
   124  
   125          title = new TitlePanel(BorderFactory.createEtchedBorder(),
   126                  "Preferences");
   127          tooltip = new ToolTipPanel("Hover over a setting to see a " +
   128                  "description, if available.");
   129  
   130          add(title, "pushx, growx, h 45!");
   131          add(scrollPane, "grow, push, h 425!");
   132          add(tooltip, "pushx, growx, h 65!");
   133  
   134          panels.put(null, loading);
   135          setCategory(category);
   136      }
   137  
   138      /**
   139       * Returns this categrory panel's parent window.
   140       *
   141       * @return Parent window
   142       */
   143      protected Window getParentWindow() {
                 /* 
    P/P           *  Method: Window getParentWindow()
                  * 
                  *  Preconditions:
                  *    init'ed(this.parent)
                  * 
                  *  Postconditions:
                  *    return_value == this.parent
                  *    init'ed(return_value)
                  */
   144          return parent;
   145      }
   146  
   147      /**
   148       * Returns the tooltip panel for this category panel.
   149       *
   150       * @return Tooltip panel
   151       */
   152      protected ToolTipPanel getToolTipPanel() {
                 /* 
    P/P           *  Method: ToolTipPanel getToolTipPanel()
                  * 
                  *  Preconditions:
                  *    init'ed(this.tooltip)
                  * 
                  *  Postconditions:
                  *    return_value == this.tooltip
                  *    init'ed(return_value)
                  */
   153          return tooltip;
   154      }
   155  
   156      /**
   157       * Informs the category panel a category has been loaded.
   158       *
   159       * @param loader Category loader
   160       * @param category Loaded category
   161       */
   162      protected void categoryLoaded(final PrefsCategoryLoader loader,
   163              final PreferencesCategory category) {
                 /* 
    P/P           *  Method: void categoryLoaded(PrefsCategoryLoader, PreferencesCategory)
                  * 
                  *  Preconditions:
                  *    loader != null
                  *    init'ed(this.category)
                  *    this.panels != null
                  *    (soft) init'ed(loader.errorCategory)
                  */
   164          panels.put(category, loader.getPanel());
   165          categoryLoaded(category);
   166      }
   167  
   168      private void categoryLoaded(final PreferencesCategory category) {
                 /* 
    P/P           *  Method: void categoryLoaded(PreferencesCategory)
                  * 
                  *  Preconditions:
                  *    init'ed(this.category)
                  * 
                  *  Test Vectors:
                  *    category == this.category: {0}, {1}
                  */
   169          if (this.category == category) {
                     /* 
    P/P               *  Method: void com.dmdirc.addons.ui_swing.dialogs.prefs.CategoryPanel$1(CategoryPanel, PreferencesCategory)
                      * 
                      *  Postconditions:
                      *    this.val$category == Param_2
                      *    init'ed(this.val$category)
                      */
   170              UIUtilities.invokeAndWait(new Runnable() {
   171  
   172                  /** {@inheritDoc} */
   173                  @Override
   174                  public void run() {
                             /* 
    P/P                       *  Method: void run()
                              * 
                              *  Preconditions:
                              *    this.panels != null
                              *    this.scrollPane != null
                              *    this.title != null
                              * 
                              *  Test Vectors:
                              *    this.val$category: Inverse{null}, Addr_Set{null}
                              */
   175                      scrollPane.setViewportView(panels.get(category));
   176                      if (category == null) {
   177                          title.setText("Preferences");
   178                      } else {
   179                          title.setText(category.getPath());
   180                      }
   181                  }
   182              });
   183          }        
   184      }
   185  
   186      /**
   187       * Sets the new active category for this panel and relays out.
   188       *
   189       * @param category New Category
   190       */
   191      public void setCategory(final PreferencesCategory category) {
                 /* 
    P/P           *  Method: void setCategory(PreferencesCategory)
                  * 
                  *  Preconditions:
                  *    this.panels != null
                  * 
                  *  Postconditions:
                  *    this.category == category
                  *    init'ed(this.category)
                  *    this.worker == One-of{&amp;new PrefsCategoryLoader(setCategory#2), old this.worker}
                  *    new JPanel(PrefsCategoryLoader#1) num objects <= 1
                  *    new PrefsCategoryLoader(setCategory#2) num objects <= 1
                  *    init'ed(new PrefsCategoryLoader(setCategory#2).category)
                  *    init'ed(new PrefsCategoryLoader(setCategory#2).categoryPanel)
                  *    init'ed(new PrefsCategoryLoader(setCategory#2).errorCategory)
                  *    init'ed(new PrefsCategoryLoader(setCategory#2).leftPadding)
                  *    init'ed(new PrefsCategoryLoader(setCategory#2).padding)
                  *    ...
                  * 
                  *  Test Vectors:
                  *    java.util.Map:containsKey(...)@194: {1}, {0}
                  */
   192          this.category = category;
   193  
   194          if (!panels.containsKey(category)) {
                     /* 
    P/P               *  Method: void com.dmdirc.addons.ui_swing.dialogs.prefs.CategoryPanel$2(CategoryPanel)
                      */
   195              UIUtilities.invokeAndWait(new Runnable() {
   196  
   197                  @Override
   198                  public void run() {
                             /* 
    P/P                       *  Method: void run()
                              * 
                              *  Preconditions:
                              *    init'ed(this.loading)
                              *    this.scrollPane != null
                              */
   199                      scrollPane.setViewportView(loading);
   200                  }
   201              });
   202  
   203              worker = new PrefsCategoryLoader(this, category);
   204              worker.execute();
   205          } else {
   206              categoryLoaded(category);
   207          }
   208      }
   209  
   210      /** 
   211       * Sets this panel to a waiting to load state.
   212       * 
   213       * @param b
   214       */
   215      public void setWaiting(boolean b) {
                 /* 
    P/P           *  Method: void setWaiting(bool)
                  * 
                  *  Preconditions:
                  *    this.scrollPane != null
                  *    init'ed(this.waitingCategory)
                  * 
                  *  Postconditions:
                  *    this.waiting == b
                  *    init'ed(this.waiting)
                  */
   216          waiting = b;
   217          scrollPane.setViewportView(waitingCategory);
   218      }
   219  }








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