File Source: WizardPanel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.wizard.WizardPanel__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.wizard;
    24  
    25  import com.dmdirc.addons.ui_swing.components.EtchedLineBorder;
    26  import com.dmdirc.addons.ui_swing.components.EtchedLineBorder.BorderSide;
    27  import com.dmdirc.addons.ui_swing.components.TitlePanel;
    28  import com.dmdirc.util.ListenerList;
    29  
    30  import java.awt.Color;
    31  import java.awt.event.ActionEvent;
    32  import java.awt.event.ActionListener;
    33  import java.util.List;
    34  
    35  import javax.swing.BorderFactory;
    36  import javax.swing.JButton;
    37  import javax.swing.JLabel;
    38  import javax.swing.JPanel;
    39  import javax.swing.border.EtchedBorder;
    40  
    41  import net.miginfocom.swing.MigLayout;
    42  
    43  /**
    44   * Wizard panel.
    45   */
    46  public class WizardPanel extends JPanel implements ActionListener {
    47  
    48      /**
    49       * A version number for this class. It should be changed whenever the class
    50       * structure is changed (or anything else that would prevent serialized
    51       * objects being unserialized with the new class).
    52       */
    53      private static final long serialVersionUID = 2;
    54      /** Step panel list. */
    55      private final StepLayout steps;
    56      /** Wizard title. */
    57      private final String title;
    58      /** Wizard. */
    59      private final transient WizardListener wizard;
    60      /** Step panel. */
    61      private JPanel stepsPanel;
    62      /** Title panel. */
    63      private TitlePanel titleLabel;
    64      /** Current step. */
    65      private int currentStep;
    66      /** Prevous step button. */
    67      private JButton prev;
    68      /** Next step button. */
    69      private JButton next;
    70      /** Progress label. */
    71      private JLabel progressLabel;
    72      /** Step Listeners. */
    73      private final ListenerList stepListeners;
    74  
    75      /**
    76       * Creates a new instance of WizardPanel.
    77       *
    78       * @param title Title for the wizard
    79       * @param steps Steps for the wizard
    80       * @param wizard Wizard to inform of changes
    81       */
    82      public WizardPanel(final String title, final List<Step> steps,
    83              final WizardListener wizard) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.wizard.WizardPanel(String, List, WizardListener)
                  * 
                  *  Preconditions:
                  *    steps != null
                  * 
                  *  Presumptions:
                  *    java.util.Iterator:next(...)@95 != null
                  * 
                  *  Postconditions:
                  *    this.next == &amp;new JButton(initComponents#5)
                  *    this.prev == &amp;new JButton(initComponents#6)
                  *    this.progressLabel == &amp;new JLabel(initComponents#4)
                  *    this.stepListeners == &amp;new ListenerList(WizardPanel#1)
                  *    this.steps == &amp;new StepLayout(WizardPanel#2)
                  *    this.stepsPanel == &amp;new JPanel(initComponents#3)
                  *    this.title == title
                  *    init'ed(this.title)
                  *    this.titleLabel == &amp;new TitlePanel(initComponents#1)
                  *    this.wizard == wizard
                  *    ...
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@95: {0}, {1}
                  */
    84          super();
    85  
    86          stepListeners = new ListenerList();
    87  
    88          this.title = title;
    89          this.steps = new StepLayout();
    90          this.wizard = wizard;
    91  
    92          initComponents();
    93          layoutComponents();
    94  
    95          for (Step step : steps) {
    96              addStep(step);
    97          }
    98      }
    99  
   100      /** Initialises the components. */
   101      private void initComponents() {
                 /* 
    P/P           *  Method: void initComponents()
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.addons.ui_swing.components.EtchedLineBorder$BorderSide.BOTTOM)
                  * 
                  *  Postconditions:
                  *    this.next == &amp;new JButton(initComponents#5)
                  *    this.prev == &amp;new JButton(initComponents#6)
                  *    this.progressLabel == &amp;new JLabel(initComponents#4)
                  *    this.stepsPanel == &amp;new JPanel(initComponents#3)
                  *    this.titleLabel == &amp;new TitlePanel(initComponents#1)
                  *    new JButton(initComponents#5) num objects == 1
                  *    new JButton(initComponents#6) num objects == 1
                  *    new JLabel(initComponents#4) num objects == 1
                  *    new JPanel(initComponents#3) num objects == 1
                  *    new TitlePanel(initComponents#1) num objects == 1
                  */
   102          titleLabel = new TitlePanel(new EtchedLineBorder(EtchedBorder.LOWERED,
   103                  BorderSide.BOTTOM), title);
   104          stepsPanel = new JPanel(steps);
   105  
   106          progressLabel = new JLabel();
   107  
   108          next = new JButton();
   109  
   110          prev = new JButton("\u00AB Previous");
   111          next.setText("Next \u00BB");
   112  
   113          next.addActionListener(this);
   114          prev.addActionListener(this);
   115      }
   116  
   117      /** Lays out the components. */
   118      private void layoutComponents() {
                 /* 
    P/P           *  Method: void layoutComponents()
                  * 
                  *  Preconditions:
                  *    init'ed(this.next)
                  *    init'ed(this.prev)
                  *    init'ed(this.progressLabel)
                  *    init'ed(this.stepsPanel)
                  *    init'ed(this.titleLabel)
                  * 
                  *  Presumptions:
                  *    init'ed(com.dmdirc.addons.ui_swing.components.EtchedLineBorder$BorderSide.TOP)
                  *    init'ed(java.awt.Color.BLACK)
                  */
   119          final JPanel progressPanel = new JPanel(new MigLayout("fill"));
   120          progressPanel.add(progressLabel, "growx, pushx");
   121          progressPanel.add(prev, "sg button");
   122          progressPanel.add(next, "sg button");
   123          progressPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0,
   124                  Color.BLACK));
   125          progressPanel.setBorder(new EtchedLineBorder(EtchedBorder.LOWERED,
   126                  BorderSide.TOP));
   127  
   128          setLayout(new MigLayout("fill, wrap 1, ins 0"));
   129          add(titleLabel, "growx, pushx");
   130          add(stepsPanel, "grow, push");
   131          add(progressPanel, "growx, pushx");
   132      }
   133  
   134      /** Displays the wizard. */
   135      public void display() {
                 /* 
    P/P           *  Method: void display()
                  * 
                  *  Preconditions:
                  *    this.steps != null
                  *    this.steps.steps != null
                  *    (soft) this.next != null
                  *    (soft) this.prev != null
                  *    (soft) this.progressLabel != null
                  *    (soft) this.stepsPanel != null
                  *    (soft) this.titleLabel != null
                  * 
                  *  Presumptions:
                  *    java.util.List:get(...)@126 != null
                  * 
                  *  Postconditions:
                  *    this.currentStep == One-of{old this.currentStep, 0}
                  *    possibly_updated(this.steps.currentStep)
                  * 
                  *  Test Vectors:
                  *    java.util.List:isEmpty(...)@115: {1}, {0}
                  *    java.util.List:size(...)@106: {-231..0, 2..232-1}, {1}
                  */
   136          if (!steps.isEmpty()) {
   137              steps.first(stepsPanel);
   138              currentStep = 0;
   139              titleLabel.setText(steps.getStep(currentStep).getTitle());
   140  
   141              prev.setEnabled(false);
   142              if (steps.size() == 1) {
   143                  next.setText("Finish");
   144              }
   145  
   146              updateProgressLabel();
   147          }
   148      }
   149  
   150      /**
   151       * {@inheritDoc}
   152       *
   153       * @param e Action event
   154       */
   155      @Override
   156      public void actionPerformed(final ActionEvent e) {
                 /* 
    P/P           *  Method: void actionPerformed(ActionEvent)
                  * 
                  *  Preconditions:
                  *    e != null
                  *    (soft) this.currentStep >= -231+1
                  *    (soft) this.steps.currentStep >= -231+1
                  *    (soft) this.next != null
                  *    (soft) this.prev != null
                  *    (soft) this.progressLabel != null
                  *    (soft) this.stepListeners != null
                  *    (soft) this.steps != null
                  *    (soft) this.steps.steps != null
                  *    (soft) this.stepsPanel != null
                  *    ...
                  * 
                  *  Postconditions:
                  *    this.currentStep == One-of{old this.currentStep, old this.currentStep - 1}
                  *    init'ed(this.currentStep)
                  *    init'ed(this.steps.currentStep)
                  */
   157          if (e.getSource() == next) {
   158              nextStep();
   159          } else if (e.getSource() == prev) {
   160              prevStep();
   161          }
   162      }
   163  
   164      /**
   165       * Adds a step to the wizard.
   166       *
   167       * @param step Step to add
   168       */
   169      public void addStep(final Step step) {
                 /* 
    P/P           *  Method: void addStep(Step)
                  * 
                  *  Preconditions:
                  *    step != null
                  *    this.stepsPanel != null
                  */
   170          stepsPanel.add(step, step.toString());
   171      }
   172  
   173      /**
   174       * Enables or disables the "next step" button.
   175       *
   176       * @param newValue boolean true to make "next" button enabled, else false
   177       */
   178      public void enableNextStep(final boolean newValue) {
                 /* 
    P/P           *  Method: void enableNextStep(bool)
                  * 
                  *  Preconditions:
                  *    this.next != null
                  */
   179          next.setEnabled(newValue);
   180      }
   181  
   182      /**
   183       * Enables or disables the "previous step" button.
   184       *
   185       * @param newValue boolean true to make "previous" button enabled, else false
   186       */
   187      public void enablePreviousStep(final boolean newValue) {
                 /* 
    P/P           *  Method: void enablePreviousStep(bool)
                  * 
                  *  Preconditions:
                  *    this.prev != null
                  */
   188          prev.setEnabled(newValue);
   189      }
   190  
   191      /** Moves to the next step. */
   192      protected void nextStep() {
                 /* 
    P/P           *  Method: void nextStep()
                  * 
                  *  Preconditions:
                  *    this.next != null
                  *    (soft) init'ed(com/dmdirc/config/IdentityManager.config.globalConfig)
                  *    (soft) this.currentStep <= 232-3
                  *    (soft) this.steps.currentStep <= 232-2
                  *    (soft) this.prev != null
                  *    (soft) this.progressLabel != null
                  *    (soft) this.stepListeners != null
                  *    (soft) this.steps != null
                  *    (soft) this.steps.steps != null
                  *    (soft) this.stepsPanel != null
                  *    ...
                  * 
                  *  Presumptions:
                  *    java.util.List:get(...)@126 != null
                  * 
                  *  Postconditions:
                  *    com/dmdirc/config/IdentityManager.config.globalConfig == old com/dmdirc/config/IdentityManager.config.globalConfig
                  *    possibly_updated(com/dmdirc/config/IdentityManager.config.needSave)
                  *    java.lang.StringBuilder:toString(...)._tainted == 0
                  *    this.currentStep == One-of{old this.currentStep + 1, old this.currentStep}
                  *    this.currentStep <= 232-2
                  *    init'ed(this.steps.currentStep)
                  *    new ArrayList(getSources#1) num objects == 0, if init'ed
                  *    new ConfigManager(setOption#2*) num objects == 0, if init'ed
                  *    new ConfigManager(setOption#2*).channel == null
                  *    new ConfigManager(setOption#2*).ircd == null
                  *    ...
                  * 
                  *  Test Vectors:
                  *    java.lang.String:equals(...)@193: {0}, {1}
                  *    java.lang.String:equals(...)@204: {0}, {1}
                  */
   193          if ("Next \u00BB".equals(next.getText())) {
   194              prev.setEnabled(true);
   195              fireStepAboutToBeDisplayed(steps.getStep(currentStep + 1));
   196              steps.next(stepsPanel);
   197              fireStepHidden(steps.getStep(currentStep));
   198              currentStep++;
   199              if (currentStep == steps.size() - 1) {
   200                  next.setText("Finish");
   201              }
   202              titleLabel.setText(steps.getStep(currentStep).getTitle());
   203              updateProgressLabel();
   204          } else if ("Finish".equals(next.getText())) {
   205              fireWizardFinished();
   206          }
   207      }
   208  
   209      /** Moves to the previous step. */
   210      protected void prevStep() {
                 /* 
    P/P           *  Method: void prevStep()
                  * 
                  *  Preconditions:
                  *    this.currentStep >= -231+1
                  *    this.steps.currentStep >= -231+1
                  *    this.next != null
                  *    this.progressLabel != null
                  *    this.stepListeners != null
                  *    this.steps != null
                  *    this.steps.steps != null
                  *    this.stepsPanel != null
                  *    this.titleLabel != null
                  *    (soft) this.prev != null
                  * 
                  *  Presumptions:
                  *    java.util.List:get(...)@126 != null
                  * 
                  *  Postconditions:
                  *    this.currentStep == old this.currentStep - 1
                  *    this.currentStep <= 232-2
                  *    init'ed(this.steps.currentStep)
                  * 
                  *  Test Vectors:
                  *    this.currentStep: {-231+1..0, 2..232-1}, {1}
                  */
   211          fireStepAboutToBeDisplayed(steps.getStep(currentStep - 1));
   212          steps.previous(stepsPanel);
   213          fireStepHidden(steps.getStep(currentStep));
   214          currentStep--;
   215          if (currentStep == 0) {
   216              prev.setEnabled(false);
   217          }
   218          next.setText("Next \u00BB");
   219          titleLabel.setText(steps.getStep(currentStep).getTitle());
   220          updateProgressLabel();
   221      }
   222  
   223      /**
   224       * Returns the step at the specified index.
   225       *
   226       * @param stepNumber step number
   227       *
   228       * @return Specified step.
   229       */
   230      public Step getStep(final int stepNumber) {
                 /* 
    P/P           *  Method: Step getStep(int)
                  * 
                  *  Preconditions:
                  *    this.steps != null
                  *    this.steps.steps != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   231          return steps.getStep(stepNumber);
   232      }
   233  
   234      /**
   235       * Returns the current step.
   236       *
   237       * @return Current step number
   238       */
   239      public int getCurrentStep() {
                 /* 
    P/P           *  Method: int getCurrentStep()
                  * 
                  *  Preconditions:
                  *    init'ed(this.currentStep)
                  * 
                  *  Postconditions:
                  *    return_value == this.currentStep
                  *    init'ed(return_value)
                  */
   240          return currentStep;
   241      }
   242  
   243      /** Updates the progress label. */
   244      private void updateProgressLabel() {
                 /* 
    P/P           *  Method: void updateProgressLabel()
                  * 
                  *  Preconditions:
                  *    this.currentStep <= 232-2
                  *    this.progressLabel != null
                  *    this.steps != null
                  *    this.steps.steps != null
                  */
   245          progressLabel.setText("Step " + (currentStep + 1) + " of " +
   246                  steps.size());
   247      }
   248  
   249      /**
   250       * Adds a step listener to the list.
   251       *
   252       * @param listener
   253       */
   254      public void addStepListener(final StepListener listener) {
                 /* 
    P/P           *  Method: void addStepListener(StepListener)
                  * 
                  *  Preconditions:
                  *    this.stepListeners != null
                  */
   255          synchronized (stepListeners) {
   256              stepListeners.add(StepListener.class, listener);
   257          }
   258      }
   259  
   260      /**
   261       * Removes a step listener from the list.
   262       *
   263       * @param listener
   264       */
   265      public void removeStepListener(final StepListener listener) {
                 /* 
    P/P           *  Method: void removeStepListener(StepListener)
                  * 
                  *  Preconditions:
                  *    this.stepListeners != null
                  */
   266          synchronized (stepListeners) {
   267              stepListeners.remove(StepListener.class, listener);
   268          }
   269      }
   270  
   271      /**
   272       * Adds a wizard listener to the list.
   273       *
   274       * @param listener
   275       */
   276      public void addWizardListener(final WizardListener listener) {
                 /* 
    P/P           *  Method: void addWizardListener(WizardListener)
                  * 
                  *  Preconditions:
                  *    this.stepListeners != null
                  */
   277          synchronized (stepListeners) {
   278              stepListeners.add(WizardListener.class, listener);
   279          }
   280      }
   281  
   282      /**
   283       * Removes a wizard listener from the list.
   284       *
   285       * @param listener
   286       */
   287      public void removeWizardListener(final WizardListener listener) {
                 /* 
    P/P           *  Method: void removeWizardListener(WizardListener)
                  * 
                  *  Preconditions:
                  *    this.stepListeners != null
                  */
   288          synchronized (stepListeners) {
   289              stepListeners.remove(WizardListener.class, listener);
   290          }
   291      }
   292  
   293      /**
   294       * Fires step about to be displayed events.
   295       *
   296       * @param step Step to be displayed
   297       */
   298      private void fireStepAboutToBeDisplayed(final Step step) {
                 /* 
    P/P           *  Method: void fireStepAboutToBeDisplayed(Step)
                  * 
                  *  Preconditions:
                  *    this.stepListeners != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.util.ListenerList:get(...)@300 != null
                  *    java.util.Iterator:next(...)@302 != null
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@302: {1}, {0}
                  */
   299          synchronized (stepListeners) {
   300              List<StepListener> listeners =
   301                      stepListeners.get(StepListener.class);
   302              for (StepListener listener : listeners) {
   303                  listener.stepAboutToDisplay(step);
   304              }
   305          }
   306      }
   307  
   308      /**
   309       * Fires step hidden events.
   310       *
   311       * @param step step thats been hidden
   312       */
   313      private void fireStepHidden(final Step step) {
                 /* 
    P/P           *  Method: void fireStepHidden(Step)
                  * 
                  *  Preconditions:
                  *    this.stepListeners != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.util.ListenerList:get(...)@315 != null
                  *    java.util.Iterator:next(...)@317 != null
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@317: {1}, {0}
                  */
   314          synchronized (stepListeners) {
   315              List<StepListener> listeners =
   316                      stepListeners.get(StepListener.class);
   317              for (StepListener listener : listeners) {
   318                  listener.stepHidden(step);
   319              }
   320          }
   321      }
   322  
   323      /**
   324       * Fires wizard finished events.
   325       */
   326      private void fireWizardFinished() {
                 /* 
    P/P           *  Method: void fireWizardFinished()
                  * 
                  *  Preconditions:
                  *    this.stepListeners != null
                  *    (soft) init'ed(com/dmdirc/config/IdentityManager.config.globalConfig)
                  * 
                  *  Presumptions:
                  *    com.dmdirc.util.ListenerList:get(...)@328 != null
                  *    java.util.Iterator:next(...)@330 != null
                  * 
                  *  Postconditions:
                  *    com/dmdirc/config/IdentityManager.config.globalConfig == old com/dmdirc/config/IdentityManager.config.globalConfig
                  *    com/dmdirc/config/IdentityManager.config.needSave == old com/dmdirc/config/IdentityManager.config.needSave
                  *    java.lang.StringBuilder:toString(...)._tainted == 0
                  *    new ArrayList(getSources#1) num objects == undefined
                  *    new ArrayList(getSources#1) num objects == 0, if init'ed
                  *    new ConfigManager(setOption#2*) num objects == new ArrayList(getSources#1) num objects
                  *    new MapList(ConfigManager#1) num objects == new ArrayList(getSources#1) num objects
                  *    new ConfigManager(setOption#2*).channel == undefined
                  *    new ConfigManager(setOption#2*).channel == null
                  *    new ConfigManager(setOption#2*).ircd == new ConfigManager(setOption#2*).channel
                  *    ...
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@330: {1}, {0}
                  */
   327          synchronized (stepListeners) {
   328              List<WizardListener> listeners =
   329                      stepListeners.get(WizardListener.class);
   330              for (WizardListener listener : listeners) {
   331                  listener.wizardFinished();
   332              }
   333          }
   334      }
   335  
   336      /**
   337       * Fires wizard cancelled events.
   338       */
   339      protected void fireWizardCancelled() {
                 /* 
    P/P           *  Method: void fireWizardCancelled()
                  * 
                  *  Preconditions:
                  *    this.stepListeners != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.util.ListenerList:get(...)@341 != null
                  *    java.util.Iterator:next(...)@343 != null
                  *    listener.wizardDialog@343 != null
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@343: {1}, {0}
                  */
   340          synchronized (stepListeners) {
   341              List<WizardListener> listeners =
   342                      stepListeners.get(WizardListener.class);
   343              for (WizardListener listener : listeners) {
   344                  listener.wizardCancelled();
   345              }
   346          }
   347      }
   348  }








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