You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ErrorPopup.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.addons.ui_swing.components.statusbar;
  18. import com.dmdirc.addons.ui_swing.components.IconManager;
  19. import com.dmdirc.interfaces.ui.ErrorsDialogModel;
  20. import com.dmdirc.logger.ErrorLevel;
  21. import com.dmdirc.logger.ErrorReportStatus;
  22. import com.dmdirc.ui.core.errors.DisplayableError;
  23. import com.google.common.collect.HashMultiset;
  24. import java.awt.Font;
  25. import java.awt.Window;
  26. import java.util.Set;
  27. import javax.swing.JLabel;
  28. import javax.swing.JPanel;
  29. import javax.swing.JSeparator;
  30. import javax.swing.SwingConstants;
  31. /**
  32. * Shows a breakdown of errors that have occurred.
  33. *
  34. * @since 0.6.3m1
  35. */
  36. public class ErrorPopup extends StatusbarPopupWindow {
  37. /** Serial version UID. */
  38. private static final long serialVersionUID = 1;
  39. /** Icon manager. */
  40. private final IconManager iconManager;
  41. /** Error manager to retrieve errors from. */
  42. private final ErrorsDialogModel model;
  43. /**
  44. * Creates a new error popup.
  45. *
  46. * @param model The error model to retrieve errors from
  47. * @param iconManager The manager to use to retrieve icons.
  48. * @param parent Parent panel
  49. * @param parentWindow Parent window
  50. */
  51. public ErrorPopup(
  52. final ErrorsDialogModel model,
  53. final IconManager iconManager,
  54. final JPanel parent,
  55. final Window parentWindow) {
  56. super(parent, parentWindow);
  57. this.model = model;
  58. this.iconManager = iconManager;
  59. }
  60. @Override
  61. protected void initContent(final JPanel panel) {
  62. final Set<DisplayableError> errors = model.getErrors();
  63. final HashMultiset<ErrorLevel> severities = HashMultiset.create();
  64. final HashMultiset<ErrorReportStatus> statuses = HashMultiset.create();
  65. errors.stream().map(DisplayableError::getSeverity).forEach(severities::add);
  66. errors.stream().map(DisplayableError::getReportStatus).forEach(statuses::add);
  67. panel.add(buildLabel("Severity", SwingConstants.LEFT));
  68. panel.add(buildLabel("#", SwingConstants.RIGHT), "growx, pushx, wrap");
  69. severities.elementSet().forEach(s -> {
  70. panel.add(new JLabel(s.toString(), iconManager.getIcon(s.getIcon()), SwingConstants.LEFT));
  71. panel.add(new JLabel(String.valueOf(severities.count(s)), SwingConstants.RIGHT),
  72. "growx, pushx, wrap");
  73. });
  74. panel.add(new JSeparator(), "span, growx, pushx, wrap");
  75. panel.add(buildLabel("Report status", SwingConstants.LEFT));
  76. panel.add(buildLabel("#", SwingConstants.RIGHT), "growx, pushx, wrap");
  77. statuses.elementSet().forEach(s -> {
  78. panel.add(new JLabel(s.toString(), SwingConstants.LEFT));
  79. panel.add(new JLabel(String.valueOf(statuses.count(s)), SwingConstants.RIGHT),
  80. "growx, pushx, wrap");
  81. });
  82. }
  83. private JLabel buildLabel(final String text, final int constant) {
  84. final JLabel header = new JLabel(text, constant);
  85. header.setFont(header.getFont().deriveFont(Font.BOLD));
  86. return header;
  87. }
  88. }