|
60 | 60 | public final class IssueDialog extends JDialog { |
61 | 61 | private static final Logger LOGGER = LoggerFactory.getLogger(IssueDialog.class); |
62 | 62 |
|
| 63 | + /** |
| 64 | + * Default text for critical issues (runtime exceptions). |
| 65 | + */ |
| 66 | + private static final String CRITICAL_ISSUE = "The following exception occurred:"; |
| 67 | + /** |
| 68 | + * Default text for non-critical issues (JML specification warnings). |
| 69 | + */ |
| 70 | + private static final String NON_CRITICAL_ISSUE = String.format( |
| 71 | + "The following non-fatal problems occurred when translating your %s specifications:", |
| 72 | + SLEnvInput.getLanguage()); |
| 73 | + |
63 | 74 | /** regex to find web urls in string messages */ |
64 | 75 | private static final Pattern HTTP_REGEX = Pattern.compile("https?://[^\\s]+"); |
65 | 76 |
|
@@ -129,7 +140,20 @@ public final class IssueDialog extends JDialog { |
129 | 140 |
|
130 | 141 | public IssueDialog(Window owner, String title, Set<PositionedIssueString> issues, |
131 | 142 | boolean critical) { |
132 | | - this(owner, title, issues, critical, null); |
| 143 | + this(owner, title, critical ? CRITICAL_ISSUE : NON_CRITICAL_ISSUE, issues, critical, null); |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * Create an issue dialog with the given title and description. |
| 148 | + * |
| 149 | + * @param owner parent window |
| 150 | + * @param title window title |
| 151 | + * @param description description to show |
| 152 | + * @param issues the issues |
| 153 | + */ |
| 154 | + public IssueDialog(Window owner, String title, String description, |
| 155 | + Set<PositionedIssueString> issues) { |
| 156 | + this(owner, title, description, issues, false, null); |
133 | 157 | } |
134 | 158 |
|
135 | 159 | /** |
@@ -166,8 +190,34 @@ private static List<PositionedIssueString> decorateHTML(Set<PositionedIssueStrin |
166 | 190 | }).collect(Collectors.toList()); |
167 | 191 | } |
168 | 192 |
|
| 193 | + /** |
| 194 | + * Construct a new issue dialog based on the title, the warnings to show and the exception to |
| 195 | + * show. |
| 196 | + * |
| 197 | + * @param owner parent window |
| 198 | + * @param title dialog title |
| 199 | + * @param warnings warnings to show |
| 200 | + * @param critical whether the issue is critical |
| 201 | + * @param throwable exception to show (may be null) |
| 202 | + */ |
169 | 203 | IssueDialog(Window owner, String title, Set<PositionedIssueString> warnings, |
170 | 204 | boolean critical, Throwable throwable) { |
| 205 | + this(owner, title, critical ? CRITICAL_ISSUE : NON_CRITICAL_ISSUE, warnings, critical, |
| 206 | + throwable); |
| 207 | + } |
| 208 | + |
| 209 | + /** |
| 210 | + * Construct a new issue dialog given the title, description, warnings and exception. |
| 211 | + * |
| 212 | + * @param owner parent window |
| 213 | + * @param title dialog title |
| 214 | + * @param head description |
| 215 | + * @param warnings warnings to show |
| 216 | + * @param critical criticality of the issue |
| 217 | + * @param throwable exception to show (may be null) |
| 218 | + */ |
| 219 | + IssueDialog(Window owner, String title, String head, Set<PositionedIssueString> warnings, |
| 220 | + boolean critical, Throwable throwable) { |
171 | 221 | super(owner, title, ModalityType.APPLICATION_MODAL); |
172 | 222 |
|
173 | 223 | this.throwable = throwable; |
@@ -195,14 +245,6 @@ private static List<PositionedIssueString> decorateHTML(Set<PositionedIssueStrin |
195 | 245 | // stTextArea |
196 | 246 |
|
197 | 247 | // set descriptive text in top label |
198 | | - final String head; |
199 | | - if (critical) { |
200 | | - head = "The following exception occurred:"; |
201 | | - } else { |
202 | | - head = String.format( |
203 | | - "The following non-fatal problems occurred when translating your %s specifications:", |
204 | | - SLEnvInput.getLanguage()); |
205 | | - } |
206 | 248 | JLabel label = new JLabel(head); |
207 | 249 | label.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); |
208 | 250 | add(label, BorderLayout.NORTH); |
@@ -719,8 +761,11 @@ public Component getListCellRendererComponent(JList<? extends PositionedString> |
719 | 761 | BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY), |
720 | 762 | BorderFactory.createEmptyBorder(5, 5, 5, 5))); |
721 | 763 | if (isSelected) { |
722 | | - textPane.setBackground(list.getSelectionBackground()); |
723 | | - textPane.setForeground(list.getSelectionForeground()); |
| 764 | + // for some reason, this copy is needed to get correct colors |
| 765 | + Color bg = new Color(list.getSelectionBackground().getRGB()); |
| 766 | + Color fg = new Color(list.getSelectionForeground().getRGB()); |
| 767 | + textPane.setBackground(bg); |
| 768 | + textPane.setForeground(fg); |
724 | 769 | } else { |
725 | 770 | textPane.setBackground(list.getBackground()); |
726 | 771 | textPane.setForeground(list.getForeground()); |
|
0 commit comments