Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ErrorDetailPanel.java 6.6KB

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