22
22
import com .intellij .ide .BrowserUtil ;
23
23
import com .intellij .openapi .diagnostic .Logger ;
24
24
import com .intellij .openapi .util .SystemInfo ;
25
- import com .intellij .ui .JBColor ;
26
25
import com .intellij .ui .components .JBTabbedPane ;
27
- import com .intellij .util .ui .UIUtil ;
28
- import edu .umd .cs .findbugs .BugAnnotation ;
29
- import edu .umd .cs .findbugs .BugInstance ;
30
- import edu .umd .cs .findbugs .BugPattern ;
31
- import edu .umd .cs .findbugs .DetectorFactory ;
32
- import edu .umd .cs .findbugs .FieldAnnotation ;
33
- import edu .umd .cs .findbugs .MethodAnnotation ;
34
- import edu .umd .cs .findbugs .Plugin ;
35
- import edu .umd .cs .findbugs .SortedBugCollection ;
26
+ import com .intellij .util .ui .*;
27
+ import edu .umd .cs .findbugs .*;
36
28
import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
37
29
import icons .PluginIcons ;
38
30
import org .jetbrains .annotations .NotNull ;
39
31
import org .jetbrains .plugins .spotbugs .common .util .BugInstanceUtil ;
40
- import org .jetbrains .plugins .spotbugs .gui .common .CustomLineBorder ;
41
- import org .jetbrains .plugins .spotbugs .gui .common .MultiSplitLayout ;
42
- import org .jetbrains .plugins .spotbugs .gui .common .MultiSplitPane ;
43
- import org .jetbrains .plugins .spotbugs .gui .common .ScrollPaneFacade ;
44
- import org .jetbrains .plugins .spotbugs .gui .common .VerticalTextIcon ;
32
+ import org .jetbrains .plugins .spotbugs .gui .common .*;
45
33
import org .jetbrains .plugins .spotbugs .gui .tree .view .BugTree ;
46
34
import org .jetbrains .plugins .spotbugs .resources .GuiResources ;
47
35
48
- import javax .swing .BorderFactory ;
49
- import javax .swing .JEditorPane ;
50
- import javax .swing .JPanel ;
51
- import javax .swing .JScrollPane ;
52
- import javax .swing .JTabbedPane ;
53
- import javax .swing .ScrollPaneConstants ;
54
- import javax .swing .SwingConstants ;
55
- import javax .swing .SwingUtilities ;
56
- import javax .swing .border .EmptyBorder ;
36
+ import javax .swing .*;
57
37
import javax .swing .event .HyperlinkEvent ;
58
- import javax .swing .event .HyperlinkListener ;
59
38
import javax .swing .text .html .HTMLEditorKit ;
60
- import java .awt .BorderLayout ;
61
- import java .awt .Color ;
62
- import java .awt .Component ;
63
- import java .awt .Dimension ;
64
- import java .awt .Graphics ;
65
- import java .awt .Graphics2D ;
66
- import java .awt .Rectangle ;
67
- import java .awt .RenderingHints ;
39
+ import java .awt .*;
68
40
import java .awt .event .KeyEvent ;
69
- import java .io .IOException ;
70
- import java .io .StringReader ;
41
+ import java .io .*;
71
42
import java .net .URL ;
72
43
import java .util .Collection ;
73
- import java .util .HashSet ;
74
- import java .util .Iterator ;
75
- import java .util .LinkedHashSet ;
44
+ import java .util .stream .Collectors ;
76
45
77
46
@ SuppressWarnings ("MagicNumber" )
78
47
public final class BugDetailsComponents {
@@ -108,6 +77,7 @@ JTabbedPane getTabbedPane() {
108
77
_jTabbedPane = new JTabbedPane (SwingConstants .RIGHT );
109
78
} else {
110
79
_jTabbedPane = new JBTabbedPane (SwingConstants .RIGHT );
80
+ ((JBTabbedPane ) _jTabbedPane ).setTabComponentInsets (JBUI .insets (0 , 0 , 0 , 5 ));
111
81
}
112
82
113
83
_jTabbedPane .setFocusable (false );
@@ -144,7 +114,7 @@ private Component getBugDetailsSplitPane() {
144
114
final String layoutDef = "(ROW weight=1.0 (COLUMN weight=1.0 top bottom))" ;
145
115
final MultiSplitLayout .Node modelRoot = MultiSplitLayout .parseModel (layoutDef );
146
116
final MultiSplitLayout multiSplitLayout = _bugDetailsSplitPane .getMultiSplitLayout ();
147
- multiSplitLayout .setDividerSize (6 );
117
+ multiSplitLayout .setDividerSize (3 );
148
118
multiSplitLayout .setModel (modelRoot );
149
119
multiSplitLayout .setFloatingDividers (true );
150
120
_bugDetailsSplitPane .add (getBugDetailsPanel (), "top" );
@@ -155,17 +125,13 @@ private Component getBugDetailsSplitPane() {
155
125
return _bugDetailsSplitPane ;
156
126
}
157
127
158
- @ SuppressWarnings ("MagicNumber" )
159
128
private JPanel getBugDetailsPanel () {
160
129
if (_bugDetailsPanel == null ) {
161
130
final JScrollPane scrollPane = ScrollPaneFacade .createScrollPane (ScrollPaneConstants .VERTICAL_SCROLLBAR_ALWAYS , ScrollPaneConstants .HORIZONTAL_SCROLLBAR_AS_NEEDED );
162
131
scrollPane .setViewportView (getBugDetailsPane ());
163
- //scrollPane.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(0, 0, 0, 3), new CustomLineBorder(new Color(98, 95, 89), 0, 0, 1, 1)));
164
- scrollPane .setBorder (new CustomLineBorder (new JBColor (new Color (98 , 95 , 89 ), new Color (53 , 51 , 48 )), 0 , 0 , 1 , 0 ));
165
- //scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));
166
132
167
133
_bugDetailsPanel = new JPanel ();
168
- _bugDetailsPanel .setBorder (new EmptyBorder ( 3 , 2 , 0 , 3 ));
134
+ _bugDetailsPanel .setBorder (JBUI . Borders . empty ( ));
169
135
_bugDetailsPanel .setLayout (new BorderLayout ());
170
136
_bugDetailsPanel .add (scrollPane , BorderLayout .CENTER );
171
137
}
@@ -176,16 +142,13 @@ private JPanel getBugDetailsPanel() {
176
142
private JEditorPane getBugDetailsPane () {
177
143
if (_bugDetailsPane == null ) {
178
144
_bugDetailsPane = new BugDetailsEditorPane ();
179
- _bugDetailsPane .setBorder (new EmptyBorder ( 10 , 10 , 10 , 10 ));
145
+ _bugDetailsPane .setBorder (JBUI . Borders . empty ( 5 ));
180
146
_bugDetailsPane .setEditable (false );
181
147
_bugDetailsPane .setContentType (UIUtil .HTML_MIME );
182
148
_bugDetailsPane .setEditorKit (_htmlEditorKit );
183
- _bugDetailsPane .addHyperlinkListener (new HyperlinkListener () {
184
- @ Override
185
- public void hyperlinkUpdate (final HyperlinkEvent evt ) {
186
- if (_parent != null ) {
187
- handleDetailsClick (evt );
188
- }
149
+ _bugDetailsPane .addHyperlinkListener (evt -> {
150
+ if (_parent != null ) {
151
+ handleDetailsClick (evt );
189
152
}
190
153
});
191
154
}
@@ -197,10 +160,10 @@ private JPanel getBugExplanationPanel() {
197
160
if (_explanationPanel == null ) {
198
161
final JScrollPane scrollPane = ScrollPaneFacade .createScrollPane (ScrollPaneConstants .VERTICAL_SCROLLBAR_ALWAYS , ScrollPaneConstants .HORIZONTAL_SCROLLBAR_AS_NEEDED );
199
162
scrollPane .setViewportView (getExplanationPane ());
200
- scrollPane .setBorder (BorderFactory .createCompoundBorder (new CustomLineBorder (new JBColor (new Color (208 , 206 , 203 ), new Color (170 , 168 , 165 )), 1 , 0 , 0 , 0 ), new CustomLineBorder (new JBColor (new Color (98 , 95 , 89 ), new Color (71 , 68 , 62 )), 1 , 0 , 0 , 0 )));
163
+ // scrollPane.setBorder(BorderFactory.createCompoundBorder(new CustomLineBorder(new JBColor(new Color(208, 206, 203), new Color(170, 168, 165)), 1, 0, 0, 0), new CustomLineBorder(new JBColor(new Color(98, 95, 89), new Color(71, 68, 62)), 1, 0, 0, 0)));
201
164
202
165
_explanationPanel = new JPanel ();
203
- _explanationPanel .setBorder (new EmptyBorder ( 0 , 2 , 0 , 3 ));
166
+ _explanationPanel .setBorder (JBUI . Borders . empty ( ));
204
167
_explanationPanel .setLayout (new BorderLayout ());
205
168
_explanationPanel .add (scrollPane , BorderLayout .CENTER );
206
169
}
@@ -212,16 +175,11 @@ private JPanel getBugExplanationPanel() {
212
175
private JEditorPane getExplanationPane () {
213
176
if (_explanationPane == null ) {
214
177
_explanationPane = new ExplanationEditorPane ();
215
- _explanationPane .setBorder (new EmptyBorder ( 10 , 10 , 10 , 10 ));
178
+ _explanationPane .setBorder (JBUI . Borders . empty ( 10 ));
216
179
_explanationPane .setEditable (false );
217
180
_explanationPane .setContentType ("text/html" );
218
181
_explanationPane .setEditorKit (_htmlEditorKit );
219
- _explanationPane .addHyperlinkListener (new HyperlinkListener () {
220
- @ Override
221
- public void hyperlinkUpdate (final HyperlinkEvent evt ) {
222
- editorPaneHyperlinkUpdate (evt );
223
- }
224
- });
182
+ _explanationPane .addHyperlinkListener (this ::editorPaneHyperlinkUpdate );
225
183
}
226
184
227
185
return _explanationPane ;
@@ -389,27 +347,22 @@ void setBugExplanation(final SortedBugCollection bugCollection, final BugInstanc
389
347
390
348
private void refreshDetailsShown () {
391
349
final String html = BugInstanceUtil .getDetailHtml (_lastBugInstance );
392
- final StringReader reader = new StringReader (html ); // no need for BufferedReader
393
- try {
394
- _explanationPane .setToolTipText (edu .umd .cs .findbugs .L10N .getLocalString ("tooltip.longer_description" , "This gives a longer description of the detected bug pattern" ));
350
+ // no need for BufferedReader
351
+ try (StringReader reader = new StringReader (html )) {
352
+ _explanationPane .setToolTipText (edu .umd .cs .findbugs .L10N
353
+ .getLocalString ("tooltip.longer_description" , "This gives a longer description of the detected bug " +
354
+ "pattern" ));
395
355
_explanationPane .read (reader , "html bug description" );
396
356
} catch (final IOException e ) {
397
357
_explanationPane .setText ("Could not find bug description: " + e .getMessage ());
398
358
LOGGER .warn (e .getMessage (), e );
399
- } finally {
400
- reader .close (); // polite, but doesn't do much in StringReader
401
359
}
402
360
scrollRectToVisible (_bugDetailsPane );
403
361
}
404
362
405
363
@ SuppressWarnings ({"AnonymousInnerClass" })
406
364
private static void scrollRectToVisible (final JEditorPane pane ) {
407
- SwingUtilities .invokeLater (new Runnable () {
408
- @ Override
409
- public void run () {
410
- pane .scrollRectToVisible (new Rectangle (0 , 0 , 0 , 0 ));
411
- }
412
- });
365
+ SwingUtilities .invokeLater (() -> pane .scrollRectToVisible (new Rectangle (0 , 0 , 0 , 0 )));
413
366
}
414
367
415
368
void adaptSize (final int width , final int height ) {
@@ -460,22 +413,9 @@ public void clear() {
460
413
}
461
414
462
415
public static String createBugsAbbreviation (final DetectorFactory factory ) {
463
- final StringBuilder sb = new StringBuilder ();
464
416
final Collection <BugPattern > patterns = factory .getReportedBugPatterns ();
465
- final HashSet <String > abbrs = new LinkedHashSet <String >();
466
- for (final BugPattern pattern : patterns ) {
467
- final String abbr = pattern .getAbbrev ();
468
- abbrs .add (abbr );
469
- }
470
- //noinspection ForLoopWithMissingComponent
471
- for (final Iterator <String > iter = abbrs .iterator (); iter .hasNext (); ) {
472
- final String element = iter .next ();
473
- sb .append (element );
474
- if (iter .hasNext ()) {
475
- sb .append ('|' );
476
- }
477
- }
478
- return sb .toString ();
417
+ return patterns .stream ().map (BugPattern ::getAbbrev )
418
+ .distinct ().collect (Collectors .joining ("|" ));
479
419
}
480
420
481
421
private static class BugDetailsEditorPane extends JEditorPane {
0 commit comments