File Source: SwingRestartDialog.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.updater.SwingRestartDialog__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.updater;
    24  
    25  import com.dmdirc.addons.ui_swing.MainFrame;
    26  import com.dmdirc.addons.ui_swing.components.StandardDialog;
    27  import com.dmdirc.addons.ui_swing.components.text.TextLabel;
    28  
    29  import java.awt.Dialog.ModalityType;
    30  import java.awt.event.ActionEvent;
    31  import java.awt.event.ActionListener;
    32  
    33  import javax.swing.JButton;
    34  
    35  import net.miginfocom.swing.MigLayout;
    36  
    37  /**
    38   * Prompts the user to restart the client, and restarts the client.
    39   */
    40  public class SwingRestartDialog extends StandardDialog implements ActionListener {
    41      
    42      /**
    43       * A version number for this class. It should be changed whenever the class
    44       * structure is changed (or anything else that would prevent serialized
    45       * objects being unserialized with the new class).
    46       */
    47      private static final long serialVersionUID = -7446499281414990074L;
    48      /** Informational label. */
    49      private TextLabel info;
    50      /** Swing controller. */
    51      private MainFrame mainFrame;
    52      
    53  
    54      /**
    55       * Dialog to restart the client.
    56       * 
    57       * @param mainFrame Main Frame
    58       * @param modal Modality
    59       */
    60      public SwingRestartDialog(final MainFrame mainFrame, final ModalityType modal) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.updater.SwingRestartDialog(MainFrame, Dialog$ModalityType)
                  * 
                  *  Postconditions:
                  *    this.info == &new TextLabel(initComponents#3)
                  *    this.mainFrame == mainFrame
                  *    init'ed(this.mainFrame)
                  *    new TextLabel(initComponents#3) num objects == 1
                  */
    61          super(mainFrame, modal);
    62          this.mainFrame = mainFrame;
    63  
    64          setTitle("DMDirc: Restart needed");
    65          setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    66          
    67          initComponents();
    68          layoutComponents();
    69          
    70          pack();
    71          setLocationRelativeTo(mainFrame);
    72      }
    73      
    74      /** Initialise components. */
    75      private void initComponents() {
                 /* 
    P/P           *  Method: void initComponents()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.addons.ui_swing.dialogs.updater.SwingRestartDialog:getCancelButton(...)@79 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.updater.SwingRestartDialog:getCancelButton(...)@82 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.updater.SwingRestartDialog:getOkButton(...)@78 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.updater.SwingRestartDialog:getOkButton(...)@81 != null
                  * 
                  *  Postconditions:
                  *    this.info == &new TextLabel(initComponents#3)
                  *    new TextLabel(initComponents#3) num objects == 1
                  */
    76          orderButtons(new JButton(), new JButton());
    77          info = new TextLabel("Your client needs to be restarted to finish updating.");
    78          getOkButton().setText("Now");
    79          getCancelButton().setText("Later");
    80          
    81          getOkButton().addActionListener(this);  
    82          getCancelButton().addActionListener(this);
    83  
    84          setResizable(false);
    85      }
    86      
    87      /** Layout Components. */
    88      public void layoutComponents() {
                 /* 
    P/P           *  Method: void layoutComponents()
                  * 
                  *  Preconditions:
                  *    init'ed(this.info)
                  */
    89          setLayout(new MigLayout("fill, wrap 2"));
    90          
    91          add(info, "grow, pushy, span 2");
    92          add(getLeftButton(), "split, right");
    93          add(getRightButton(), "right");
    94      }
    95  
    96      /** 
    97       * {@inheritDoc}
    98       * 
    99       * @param e Action event
   100       */
   101      @Override
   102      public void actionPerformed(final ActionEvent e) {
                 /* 
    P/P           *  Method: void actionPerformed(ActionEvent)
                  * 
                  *  Preconditions:
                  *    e != null
                  *    (soft) this.mainFrame != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.addons.ui_swing.dialogs.updater.SwingRestartDialog:getOkButton(...)@103 != null
                  * 
                  *  Test Vectors:
                  *    java.lang.Object:equals(...)@103: {0}, {1}
                  */
   103          if (getOkButton().equals(e.getSource())) {
   104              mainFrame.quit(42);
   105          }
   106          dispose();
   107      }
   108      
   109  }








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