File Source: LicensePanel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.about.LicensePanel__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.about;
    24  
    25  import com.dmdirc.addons.ui_swing.UIUtilities;
    26  import com.dmdirc.util.resourcemanager.ResourceManager;
    27  
    28  import java.awt.Font;
    29  import java.io.BufferedReader;
    30  import java.io.IOException;
    31  import java.io.InputStream;
    32  import java.io.InputStreamReader;
    33  import java.util.Map;
    34  import java.util.Map.Entry;
    35  import java.util.TreeMap;
    36  
    37  import javax.swing.JEditorPane;
    38  import javax.swing.JPanel;
    39  import javax.swing.JScrollPane;
    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  import net.miginfocom.swing.MigLayout;
    46  
    47  /**
    48   * License panel.
    49   */
         /* 
    P/P   *  Method: JScrollPane access$000(LicensePanel)
          * 
          *  Preconditions:
          *    x0 != null
          *    init'ed(x0.scrollPane)
          * 
          *  Postconditions:
          *    return_value == x0.scrollPane
          *    init'ed(return_value)
          */
    50  public final class LicensePanel extends JPanel {
    51  
    52      /**
    53       * A version number for this class. It should be changed whenever the class
    54       * structure is changed (or anything else that would prevent serialized
    55       * objects being unserialized with the new class).
    56       */
    57      private static final long serialVersionUID = 3;
    58      /** License scroll pane. */
    59      private JScrollPane scrollPane;
    60  
    61      /** Creates a new instance of LicensePanel. */
    62      public LicensePanel() {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.about.LicensePanel()
                  * 
                  *  Postconditions:
                  *    this.scrollPane == &new JScrollPane(initComponents#6)
                  *    new JScrollPane(initComponents#6) num objects == 1
                  */
    63          super();
    64  
    65          this.setOpaque(UIUtilities.getTabbedPaneOpaque());
    66          initComponents();
    67      }
    68  
    69      /** Initialises the components. */
    70      private void initComponents() {
    71          final JEditorPane license;
                 /* 
    P/P           *  Method: void initComponents()
                  * 
                  *  Presumptions:
                  *    java.lang.String:lastIndexOf(...)@105 <= 232-2
                  *    java.lang.String:lastIndexOf(...)@94 <= 232-2
                  *    java.util.Iterator:next(...)@104 != null
                  *    java.util.Iterator:next(...)@93 != null
                  *    java.util.Map:entrySet(...)@104 != null
                  *    ...
                  * 
                  *  Postconditions:
                  *    this.scrollPane == &amp;new JScrollPane(initComponents#6)
                  *    new JScrollPane(initComponents#6) num objects == 1
                  * 
                  *  Test Vectors:
                  *    com.dmdirc.util.resourcemanager.ResourceManager:getResourceManager(...)@72: Inverse{null}, Addr_Set{null}
                  *    java.lang.String:length(...)@108: {0,1}, {2..232-1}
                  *    java.lang.String:length(...)@97: {0,1}, {2..232-1}
                  *    java.util.Iterator:hasNext(...)@104: {0}, {1}
                  *    java.util.Iterator:hasNext(...)@93: {0}, {1}
                  */
    72          final ResourceManager rm = ResourceManager.getResourceManager();
    73  
    74          license = new JEditorPane();
    75          license.setEditorKit(new HTMLEditorKit());
    76          final Font font = UIManager.getFont("Label.font");
    77          ((HTMLDocument) license.getDocument()).getStyleSheet().addRule("body " +
    78                  "{ font-family: " + font.getFamily() + "; " + "font-size: " +
    79                  font.getSize() + "pt; }");
    80  
    81          final StringBuilder licenseText = new StringBuilder();
    82          licenseText.append("<html>");
    83  
    84          if (rm == null) {
    85              licenseText.append("Error loading licenses.");
    86          } else {
    87              final Map<String, InputStream> licenses =
    88                      new TreeMap<String, InputStream>(rm.
    89                      getResourcesStartingWithAsInputStreams(
    90                      "com/dmdirc/licenses/"));
    91              licenseText.append("Below are the licenses used in various " +
    92                      "components of DMDirc: <br><ul>");
    93              for (Entry<String, InputStream> entry : licenses.entrySet()) {
    94                  final String licenseString = entry.getKey().substring(entry.
    95                          getKey().
    96                          lastIndexOf('/') + 1);
    97                  if (licenseString.length() > 1) {
    98                      licenseText.append("<li>");
    99                      licenseText.append(licenseString);
   100                      licenseText.append("</li>");
   101                  }
   102              }
   103              licenseText.append("</ul>");
   104              for (Entry<String, InputStream> entry : licenses.entrySet()) {
   105                  final String licenseString = entry.getKey().substring(entry.
   106                          getKey().
   107                          lastIndexOf('/') + 1);
   108                  if (licenseString.length() > 1) {
   109                      licenseText.append("<h1>");
   110                      licenseText.append(licenseString.substring(0,
   111                              licenseString.lastIndexOf(" - ")));
   112                      licenseText.append("</h1>");
   113                      licenseText.append(
   114                              readInputStream(entry.getValue()).replaceAll("\n",
   115                              "<br>"));
   116                  }
   117              }
   118          }
   119          licenseText.append("</html>");
   120          license.setText(licenseText.toString());
   121          license.setEditable(false);
   122  
   123          scrollPane = new JScrollPane(license);
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.about.LicensePanel$1(LicensePanel)
                  */
   124          SwingUtilities.invokeLater(new Runnable() {
   125  
   126              /** {@inheritDoc} */
   127              @Override
   128              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          * 
                          *  Preconditions:
                          *    this.scrollPane != null
                          * 
                          *  Presumptions:
                          *    javax.swing.JScrollPane:getVerticalScrollBar(...)@129 != null
                          */
   129                  scrollPane.getVerticalScrollBar().setValue(0);
   130              }
   131          });
   132  
   133          setLayout(new MigLayout("ins rel, fill"));
   134          add(scrollPane, "grow, push");
   135      }
   136  
   137      /**
   138       * Converts an input stream into a string.
   139       * 
   140       * @param stream Stream to convert
   141       * 
   142       * @return Contents of the input stream
   143       */
   144      private String readInputStream(final InputStream stream) {
   145  
   146          String line;
                 /* 
    P/P           *  Method: String readInputStream(InputStream)
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == 0
                  *    return_value == &amp;java.lang.StringBuilder:toString(...)
                  */
   147          final BufferedReader input =
   148                  new BufferedReader(new InputStreamReader(stream));
   149          final StringBuilder text = new StringBuilder();
   150  
   151          try {
   152              line = input.readLine();
   153              while (line != null) {
   154                  text.append(line);
   155                  text.append("<br>");
   156                  line = input.readLine();
   157              }
   158          } catch (IOException ex) {
   159              //Ignore
   160          }
   161  
   162          return text.toString();
   163  
   164      }
   165  }








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