File Source: URLDialog.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.url.URLDialog__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.url;
    24  
    25  import com.dmdirc.addons.ui_swing.components.text.TextLabel;
    26  import com.dmdirc.addons.ui_swing.components.StandardDialog;
    27  import com.dmdirc.addons.ui_swing.components.URLProtocolPanel;
    28  import com.dmdirc.util.URLHandler;
    29  
    30  import java.awt.Window;
    31  import java.awt.event.ActionEvent;
    32  import java.awt.event.ActionListener;
    33  import java.net.URI;
    34  
    35  import javax.swing.JButton;
    36  
    37  import net.miginfocom.swing.MigLayout;
    38  
    39  /** URL Protocol dialog. */
    40  public class URLDialog 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 = 1;
    48      /** A previously created instance of URLDialog. */
    49      private static volatile URLDialog me;
    50      /** URL protocol config panel. */
    51      private URLProtocolPanel panel;
    52      /** URL. */
    53      private URI url;
    54      /** Blurb label. */
    55      private TextLabel blurb;
    56      /** Swing controller. */
    57      private Window parentWindow;
    58  
    59      /**
    60       * Instantiates the URLDialog.
    61       *
    62       * @param url URL to open once added
    63       * @param parentWindow Parent window
    64       */
    65      private URLDialog(final URI url, final Window parentWindow) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.url.URLDialog(URI, Window)
                  * 
                  *  Preconditions:
                  *    url != null
                  * 
                  *  Presumptions:
                  *    init'ed(java.awt.Dialog$ModalityType.MODELESS)
                  * 
                  *  Postconditions:
                  *    this.blurb == &new TextLabel(initComponents#3)
                  *    this.panel == &new URLProtocolPanel(initComponents#5)
                  *    this.parentWindow == parentWindow
                  *    init'ed(this.parentWindow)
                  *    this.url == url
                  *    this.url != null
                  *    new TextLabel(initComponents#3) num objects == 1
                  *    new URLProtocolPanel(initComponents#5) num objects == 1
                  */
    66          super(parentWindow, ModalityType.MODELESS);
    67          
    68          this.url = url;
    69          this.parentWindow = parentWindow;
    70          
    71          initComponents();
    72          layoutComponents();
    73          addListeners();
    74  
    75          setTitle("DMDirc: Unknown URL Protocol");
    76  
    77          pack();
    78      }
    79  
    80      /**
    81       * Creates the new URLDialog if one doesn't exist, and displays it.
    82       *
    83       * @param url URL to open once added
    84       * @param parentWindow Parent window
    85       */
    86      public static void showURLDialog(final URI url, final Window parentWindow) {
                 /* 
    P/P           *  Method: void showURLDialog(URI, Window)
                  * 
                  *  Preconditions:
                  *    init'ed(me)
                  *    (soft) url != null
                  * 
                  *  Postconditions:
                  *    me == One-of{old me, &new URLDialog(getURLDialog#1)}
                  *    me != null
                  *    new TextLabel(initComponents#3) num objects <= 1
                  *    new URLDialog(getURLDialog#1) num objects == new TextLabel(initComponents#3) num objects
                  *    new URLProtocolPanel(initComponents#5) num objects == new TextLabel(initComponents#3) num objects
                  *    new URLDialog(getURLDialog#1).blurb == &amp;new TextLabel(initComponents#3)
                  *    new URLDialog(getURLDialog#1).panel == &amp;new URLProtocolPanel(initComponents#5)
                  *    new URLDialog(getURLDialog#1).parentWindow == parentWindow
                  *    init'ed(new URLDialog(getURLDialog#1).parentWindow)
                  *    new URLDialog(getURLDialog#1).url == url
                  *    ...
                  */
    87          me = getURLDialog(url, parentWindow);
    88  
    89          me.setLocationRelativeTo(parentWindow);
    90          me.setVisible(true);
    91          me.requestFocusInWindow();
    92      }
    93  
    94      /**
    95       * Returns the current instance of the URLDialog.
    96       *
    97       * @param url URL to open once added
    98       * @param parentWindow Parent window
    99       * 
   100       * @return The current URLDialog instance
   101       */
   102      public static URLDialog getURLDialog(final URI url, final Window parentWindow) {
                 /* 
    P/P           *  Method: URLDialog getURLDialog(URI, Window)
                  * 
                  *  Preconditions:
                  *    init'ed(me)
                  *    (soft) url != null
                  * 
                  *  Postconditions:
                  *    me == One-of{old me, &amp;new URLDialog(getURLDialog#1)}
                  *    me != null
                  *    return_value == One-of{old me, &amp;new URLDialog(getURLDialog#1)}
                  *    return_value != null
                  *    new TextLabel(initComponents#3) num objects <= 1
                  *    new URLDialog(getURLDialog#1) num objects <= 1
                  *    new URLDialog(getURLDialog#1).blurb == &amp;new TextLabel(initComponents#3)
                  *    new URLDialog(getURLDialog#1).panel == &amp;new URLProtocolPanel(initComponents#5)
                  *    new URLDialog(getURLDialog#1).parentWindow == parentWindow
                  *    init'ed(new URLDialog(getURLDialog#1).parentWindow)
                  *    ...
                  */
   103          synchronized (URLDialog.class) {
   104              if (me == null) {
   105                  me = new URLDialog(url, parentWindow);
   106              }
   107          }
   108  
   109          return me;
   110      }
   111  
   112      /** Initialises the components. */
   113      private void initComponents() {
                 /* 
    P/P           *  Method: void initComponents()
                  * 
                  *  Preconditions:
                  *    this.url != null
                  * 
                  *  Postconditions:
                  *    this.blurb == &amp;new TextLabel(initComponents#3)
                  *    this.panel == &amp;new URLProtocolPanel(initComponents#5)
                  *    new TextLabel(initComponents#3) num objects == 1
                  *    new URLProtocolPanel(initComponents#5) num objects == 1
                  */
   114          orderButtons(new JButton(), new JButton());
   115          blurb = new TextLabel("Please select the appropriate action to " +
   116                  "handle " + url.getScheme() + " URL protocols from the list " +
   117                  "below.");
   118          panel = new URLProtocolPanel(url, false);
   119      }
   120  
   121      /** Lays out the components. */
   122      private void layoutComponents() {
                 /* 
    P/P           *  Method: void layoutComponents()
                  * 
                  *  Preconditions:
                  *    init'ed(this.blurb)
                  *    init'ed(this.panel)
                  */
   123          setLayout(new MigLayout("fill, wrap 1, pack"));
   124  
   125          add(blurb, "");
   126          add(panel, "grow, push");
   127          add(getLeftButton(), "split 2, right");
   128          add(getRightButton(), "right");
   129      }
   130  
   131      /** Adds listeners to the components. */
   132      private void addListeners() {
                 /* 
    P/P           *  Method: void addListeners()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.addons.ui_swing.dialogs.url.URLDialog:getCancelButton(...)@134 != null
                  *    com.dmdirc.addons.ui_swing.dialogs.url.URLDialog:getOkButton(...)@133 != null
                  */
   133          getOkButton().addActionListener(this);
   134          getCancelButton().addActionListener(this);
   135      }
   136  
   137      /**
   138       * {@inheritDoc}
   139       *
   140       * @param e action event
   141       */
   142      @Override
   143      public void actionPerformed(final ActionEvent e) {
                 /* 
    P/P           *  Method: void actionPerformed(ActionEvent)
                  * 
                  *  Preconditions:
                  *    e != null
                  *    (soft) init'ed(me)
                  *    (soft) this.panel != null
                  *    (soft) init'ed(this.url)
                  * 
                  *  Presumptions:
                  *    com.dmdirc.util.URLHandler:getURLHander(...)@147 != null
                  * 
                  *  Postconditions:
                  *    me == One-of{old me, null}
                  *    init'ed(me)
                  */
   144          if (e.getSource() == getOkButton()) {
   145              panel.save();
   146              dispose();
   147              URLHandler.getURLHander().launchApp(url);
   148          } else if (e.getSource() == getCancelButton()) {
   149              dispose();
   150          }
   151      }
   152  
   153      /** {@inheritDoc} */
   154      @Override
   155      public void validate() {
                 /* 
    P/P           *  Method: void validate()
                  * 
                  *  Preconditions:
                  *    init'ed(this.parentWindow)
                  */
   156          super.validate();
   157  
   158          setLocationRelativeTo(parentWindow);
   159      }
   160  
   161      /** {@inheritDoc} */
   162      @Override
   163      public void dispose() {
                 /* 
    P/P           *  Method: void dispose()
                  * 
                  *  Preconditions:
                  *    init'ed(me)
                  * 
                  *  Postconditions:
                  *    me == null
                  * 
                  *  Test Vectors:
                  *    me: Inverse{null}, Addr_Set{null}
                  */
   164          if (me == null) {
   165              return;
   166          }
   167          synchronized (me) {
   168              super.dispose();
   169              me = null;
   170          }
   171      }
   172  }








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