File Source: ErrorDetailPanel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.error.ErrorDetailPanel__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.error;
    24  
    25  import com.dmdirc.logger.ErrorListener;
    26  import com.dmdirc.logger.ErrorManager;
    27  import com.dmdirc.logger.ProgramError;
    28  
    29  import javax.swing.JLabel;
    30  import javax.swing.JPanel;
    31  import javax.swing.JScrollPane;
    32  import javax.swing.JTextArea;
    33  import javax.swing.JTextField;
    34  import javax.swing.SwingUtilities;
    35  import javax.swing.text.BadLocationException;
    36  
    37  import net.miginfocom.swing.MigLayout;
    38  
    39  /**
    40   * Shows information about an error.
    41   */
         /* 
    P/P   *  Method: JScrollPane access$700(ErrorDetailPanel)
          * 
          *  Preconditions:
          *    x0 != null
          *    init'ed(x0.scrollPane)
          * 
          *  Postconditions:
          *    return_value == x0.scrollPane
          *    init'ed(return_value)
          */
    42  public final class ErrorDetailPanel extends JPanel implements ErrorListener {
    43      
    44      /**
    45       * A version number for this class. It should be changed whenever the class
    46       * structure is changed (or anything else that would prevent serialized
    47       * objects being unserialized with the new class).
    48       */
    49      private static final long serialVersionUID = 3;
    50      
    51      /** Error to show. */
    52      private ProgramError error;
    53      
    54      /** ID field. */
    55      private JTextField id;
    56      
    57      /** Date field. */
    58      private JTextField date;
    59      
    60      /** Severity field. */
    61      private JTextField level;
    62      
    63      /** Report Status field. */
    64      private JTextField reportStatus;
    65      
    66      /** Error status field. */
    67      private JTextField errorStatus;
    68      
    69      /** Details field. */
    70      private JTextArea details;
    71      
    72      /** Details scrollpane. */
    73      private JScrollPane scrollPane;
    74      
    75      /** Creates a new instance of ErrorDetailPanel. */
    76      public ErrorDetailPanel() {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.error.ErrorDetailPanel()
                  * 
                  *  Postconditions:
                  *    this.date == &new JTextField(initComponents#2)
                  *    this.details == &new JTextArea(initComponents#6)
                  *    this.error == null
                  *    this.errorStatus == &new JTextField(initComponents#5)
                  *    this.id == &new JTextField(initComponents#1)
                  *    this.level == &new JTextField(initComponents#3)
                  *    this.reportStatus == &new JTextField(initComponents#4)
                  *    this.scrollPane == &new JScrollPane(initComponents#7)
                  *    new JScrollPane(initComponents#7) num objects == 1
                  *    new JTextArea(initComponents#6) num objects == 1
                  *    ...
                  */
    77          this(null);
    78      }
    79      
    80      /**
    81       * Creates a new instance of ErrorDetailPanel.
    82       *
    83       * @param error Error to be displayed
    84       */
    85      public ErrorDetailPanel(final ProgramError error) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.error.ErrorDetailPanel(ProgramError)
                  * 
                  *  Postconditions:
                  *    this.date == &new JTextField(initComponents#2)
                  *    this.details == &new JTextArea(initComponents#6)
                  *    this.error == error
                  *    init'ed(this.error)
                  *    this.errorStatus == &new JTextField(initComponents#5)
                  *    this.id == &new JTextField(initComponents#1)
                  *    this.level == &new JTextField(initComponents#3)
                  *    this.reportStatus == &new JTextField(initComponents#4)
                  *    this.scrollPane == &new JScrollPane(initComponents#7)
                  *    new JScrollPane(initComponents#7) num objects == 1
                  *    ...
                  */
    86          super();
    87          
    88          this.error = error;
    89          
    90          initComponents();
    91          
    92          updateDetails();
    93          
    94          layoutComponents();
    95      }
    96      
    97      /**
    98       * Sets the error used for this panel.
    99       *
   100       * @param newError New ProgramError
   101       */
   102      public void setError(final ProgramError newError) {
                 /* 
    P/P           *  Method: void setError(ProgramError)
                  * 
                  *  Postconditions:
                  *    this.error == newError
                  *    init'ed(this.error)
                  */
   103          error = newError;
   104          updateDetails();
   105      }
   106      
   107      /** Initialises the components. */
   108      private void initComponents() {
                 /* 
    P/P           *  Method: void initComponents()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.logger.ErrorManager:getErrorManager(...)@126 != null
                  * 
                  *  Postconditions:
                  *    this.date == &new JTextField(initComponents#2)
                  *    this.details == &new JTextArea(initComponents#6)
                  *    this.errorStatus == &new JTextField(initComponents#5)
                  *    this.id == &new JTextField(initComponents#1)
                  *    this.level == &new JTextField(initComponents#3)
                  *    this.reportStatus == &new JTextField(initComponents#4)
                  *    this.scrollPane == &new JScrollPane(initComponents#7)
                  *    new JScrollPane(initComponents#7) num objects == 1
                  *    new JTextArea(initComponents#6) num objects == 1
                  *    new JTextField(initComponents#1) num objects == 1
                  *    ...
                  */
   109          id = new JTextField();
   110          date = new JTextField();
   111          level = new JTextField();
   112          reportStatus = new JTextField();
   113          errorStatus = new JTextField();
   114          details = new JTextArea();
   115          scrollPane = new JScrollPane(details);
   116          
   117          id.setEditable(false);
   118          date.setEditable(false);
   119          level.setEditable(false);
   120          reportStatus.setEditable(false);
   121          errorStatus.setEditable(false);
   122          details.setEditable(false);
   123          details.setRows(5);
   124          details.setWrapStyleWord(true);
   125          
   126          ErrorManager.getErrorManager().addErrorListener(this);
   127      }
   128      
   129      /** Updates the panels details. */
   130      private void updateDetails() {
                 /* 
    P/P           *  Method: void updateDetails()
                  */
   131          SwingUtilities.invokeLater(new Runnable() {
   132              @Override
   133              public void run() {
                         /* 
    P/P                   *  Method: void run()
                          */
   134                  details.setText("");
   135                  if (error == null) {
   136                      id.setText("");
   137                      date.setText("");
   138                      level.setText("");
   139                      reportStatus.setText("");
   140                      errorStatus.setText("");
   141                      
   142                      return;
   143                  }
   144                  
   145                  id.setText(String.valueOf(error.getID()));
   146                  date.setText(error.getDate().toString());
   147                  level.setText(error.getLevel().toString());
   148                  reportStatus.setText(error.getReportStatus().toString());
   149                  errorStatus.setText(error.getFixedStatus().toString());
   150                  
   151                  details.append(error.getMessage() + '\n');
   152                  final String[] trace = error.getTrace();
   153                  if (trace.length > 0) {
   154                      details.append("\n");
   155                  }
   156                  for (String traceLine : trace) {
   157                      details.append(traceLine + '\n');
   158                  }
   159                  try {
   160                      details.getDocument().remove(details.getDocument().getLength() - 1, 1);
   161                  } catch (BadLocationException ex) {
   162                      //Ignore
   163                  }
   164                  
                         /* 
    P/P                   *  Method: void com.dmdirc.addons.ui_swing.dialogs.error.ErrorDetailPanel$1$1(ErrorDetailPanel$1)
                          */
   165                  SwingUtilities.invokeLater(new Runnable() {
   166                      @Override
   167                      public void run() {
                                 /* 
    P/P                           *  Method: void run()
                                  * 
                                  *  Preconditions:
                                  *    this.scrollPane != null
                                  * 
                                  *  Presumptions:
                                  *    javax.swing.JScrollPane:getVerticalScrollBar(...)@168 != null
                                  */
   168                          scrollPane.getVerticalScrollBar().setValue(0);
   169                      }
   170                  }
   171                  
   172                  );
   173              }
   174          });
   175      }
   176      
   177      /** Lays out the components. */
   178      private void layoutComponents() {
                 /* 
    P/P           *  Method: void layoutComponents()
                  * 
                  *  Preconditions:
                  *    init'ed(this.date)
                  *    init'ed(this.errorStatus)
                  *    init'ed(this.id)
                  *    init'ed(this.level)
                  *    init'ed(this.reportStatus)
                  *    init'ed(this.scrollPane)
                  */
   179          setLayout(new MigLayout("fill, wrap 2", "[right]rel[grow,fill]", ""));
   180          
   181          add(new JLabel("ID: "));
   182          add(id);
   183          
   184          add(new JLabel("Date: "));
   185          add(date);
   186          
   187          add(new JLabel("Severity: "));
   188          add(level);
   189          
   190          add(new JLabel("Report status: "));
   191          add(reportStatus);
   192          
   193          add(new JLabel("Error status: "));
   194          add(errorStatus);
   195          
   196          add(new JLabel("Details: "));
   197          add(scrollPane, "grow, push");
   198      }
   199  
   200      @Override
   201      public void errorAdded(final ProgramError error) {
   202          //Ignore
             /* 
    P/P       *  Method: void errorAdded(ProgramError)
              */
   203      }
   204  
   205      @Override
   206      public void errorDeleted(final ProgramError error) {
   207          //Ignore
             /* 
    P/P       *  Method: void errorDeleted(ProgramError)
              */
   208      }
   209  
   210      @Override
   211      public void errorStatusChanged(final ProgramError error) {
                 /* 
    P/P           *  Method: void errorStatusChanged(ProgramError)
                  * 
                  *  Preconditions:
                  *    init'ed(this.error)
                  *    (soft) error != null
                  *    (soft) this.errorStatus != null
                  *    (soft) this.reportStatus != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.logger.ProgramError:getFixedStatus(...)@214 != null
                  *    com.dmdirc.logger.ProgramError:getReportStatus(...)@213 != null
                  * 
                  *  Test Vectors:
                  *    this.error: Addr_Set{null}, Inverse{null}
                  *    com.dmdirc.logger.ProgramError:equals(...)@212: {0}, {1}
                  */
   212          if (this.error != null && this.error.equals(error)) {
   213              reportStatus.setText(error.getReportStatus().toString());
   214              errorStatus.setText(error.getFixedStatus().toString());
   215          }
   216      }
   217  
   218      /** {@inheritDoc} */
   219      @Override
   220      public boolean isReady() {
                 /* 
    P/P           *  Method: bool isReady()
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   221          return isVisible();
   222      }
   223      
   224  }








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