File Source: NoUIDialog.java

         /* 
    P/P   *  Method: com.dmdirc.ui.NoUIDialog__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.ui;
    25  
    26  import java.awt.BorderLayout;
    27  import java.awt.Dimension;
    28  import java.awt.Font;
    29  import java.awt.Insets;
    30  import java.awt.event.ActionEvent;
    31  import java.awt.event.ActionListener;
    32  import java.awt.event.WindowAdapter;
    33  import java.awt.event.WindowEvent;
    34  import java.util.concurrent.Semaphore;
    35  
    36  import javax.swing.JButton;
    37  import javax.swing.JDialog;
    38  import javax.swing.JFrame;
    39  import javax.swing.JTextPane;
    40  import javax.swing.SwingUtilities;
    41  import javax.swing.UIManager;
    42  import javax.swing.text.html.HTMLDocument;
    43  import javax.swing.text.html.HTMLEditorKit;
    44  
    45  /**
    46   * Simple Dialog to inform the user there are no UI plugins.
    47   */
         /* 
    P/P   *  Method: void com.dmdirc.ui.NoUIDialog(NoUIDialog$1)
          */
    48  public class NoUIDialog extends JDialog {
    49  
    50      /**
    51       * A version number for this class. It should be changed whenever the class
    52       * structure is changed (or anything else that would prevent serialized
    53       * objects being unserialized with the new class).
    54       */
    55      private static final long serialVersionUID = -528603916540455178L;
    56      /** Dialog heading text. */
    57      private static final String TITLE = "<h1>No UIs Found</h1>";
    58      /** Dialog body text. */
    59      private static final String BODY = "DMDirc cannot find any UI plugins, " +
    60              "which are required for you to use DMDirc.  You can either " +
    61              "download a UI plugin or extract one from the jar. DMDirc will " +
    62              "now exit";
    63  
    64      /** Private constructor to prevent external instantiation. */
    65      private NoUIDialog() {
                 /* 
    P/P           *  Method: void com.dmdirc.ui.NoUIDialog()
                  * 
                  *  Presumptions:
                  *    javax.swing.JTextPane:getDocument(...)@88 != null
                  *    javax.swing.UIManager:getFont(...)@89 != null
                  *    javax.swing.text.html.HTMLDocument:getStyleSheet(...)@90 != null
                  *    javax.swing.text.html.HTMLDocument:getStyleSheet(...)@93 != null
                  *    javax.swing.text.html.HTMLDocument:getStyleSheet(...)@96 != null
                  */
    66          super((JFrame) null, "DMDirc: No UIs Found");
    67          setResizable(false);
    68          setLayout(new BorderLayout(5, 5));
    69          setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    70  
    71          final JButton button = new JButton("OK");
                 /* 
    P/P           *  Method: void com.dmdirc.ui.NoUIDialog$1(NoUIDialog)
                  */
    72          button.addActionListener(new ActionListener() {
    73  
    74              /** {@inheritDoc} */
    75              @Override
    76              public void actionPerformed(final ActionEvent e) {
                         /* 
    P/P                   *  Method: void actionPerformed(ActionEvent)
                          */
    77                  dispose();
    78              }
    79          });
    80  
    81          final JTextPane textArea = new JTextPane(new HTMLDocument());
    82          textArea.setEditorKit(new HTMLEditorKit());
    83          textArea.setOpaque(false);
    84          textArea.setEditable(false);
    85          textArea.setHighlighter(null);
    86          textArea.setMargin(new Insets(5, 5, 5, 5));
    87  
    88          final HTMLDocument doc = (HTMLDocument) textArea.getDocument();
    89          final Font font = UIManager.getFont("Label.font");
    90          doc.getStyleSheet().addRule("body " +
    91                  "{ font-family: " + font.getFamily() + "; " + "font-size: " +
    92                  font.getSize() + "pt; text-align: center; }");
    93          doc.getStyleSheet().addRule("h1 " +
    94                  "{ font-family: " + font.getFamily() + "; " +
    95                  "font-size: 1.5em; padding: 0; margin: 0}");
    96          doc.getStyleSheet().addRule("p { text-align: justify; }");
    97  
    98          textArea.setText(TITLE + "<p>" + BODY + "</p>");
    99  
   100          add(textArea, BorderLayout.CENTER);
   101          add(button, BorderLayout.SOUTH);
   102  
   103          setPreferredSize(new Dimension(250, 200));
   104      }
   105  
   106      /**
   107       * Static method to instantiate and display the dialog.
   108       */
   109      public static void display() {
                 /* 
    P/P           *  Method: void display()
                  */
   110          SwingUtilities.invokeLater(new Runnable() {
   111  
   112              /** {@inheritDoc} */
   113              @Override
   114              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          */
   115                  final NoUIDialog me = new NoUIDialog();
   116                  me.pack();
   117                  CoreUIUtils.centreWindow(me);
   118                  me.setVisible(true);
   119              }
   120          });
   121      }
   122  
   123      /**
   124       * Static method to instantiate and display the dialog, blocking until it
   125       * is closed.
   126       */
   127      public static void displayBlocking() {
                 /* 
    P/P           *  Method: void displayBlocking()
                  */
   128          final Semaphore semaphore = new Semaphore(0);
                 /* 
    P/P           *  Method: void com.dmdirc.ui.NoUIDialog$3(Semaphore)
                  * 
                  *  Postconditions:
                  *    this.val$semaphore == Param_1
                  *    init'ed(this.val$semaphore)
                  */
   129          SwingUtilities.invokeLater(new Runnable() {
   130  
   131              /** {@inheritDoc} */
   132              @Override
   133              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          */
   134                  final NoUIDialog me = new NoUIDialog();
                         /* 
    P/P                   *  Method: void com.dmdirc.ui.NoUIDialog$3$1(NoUIDialog$3)
                          */
   135                  me.addWindowListener(new WindowAdapter() {
   136  
   137                      @Override
   138                      public void windowClosed(final WindowEvent e) {
                                 /* 
    P/P                           *  Method: void windowClosed(WindowEvent)
                                  * 
                                  *  Preconditions:
                                  *    this.val$semaphore != null
                                  */
   139                          semaphore.release();
   140                      }
   141  
   142                  });
   143                  me.pack();
   144                  CoreUIUtils.centreWindow(me);
   145                  me.setVisible(true);
   146              }
   147          });
   148          semaphore.acquireUninterruptibly();
   149      }
   150  }








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