@@ -86,6 +86,10 @@ public class FlutterView implements PersistentStateComponent<FlutterViewState>,
86
86
@ NotNull
87
87
private final FlutterViewState state = new FlutterViewState ();
88
88
89
+ @ VisibleForTesting
90
+ @ NotNull
91
+ public final ViewUtils viewUtils ;
92
+
89
93
@ NotNull
90
94
private final Project myProject ;
91
95
@@ -97,15 +101,16 @@ public class FlutterView implements PersistentStateComponent<FlutterViewState>,
97
101
private final JxBrowserManager jxBrowserManager ;
98
102
99
103
public FlutterView (@ NotNull Project project ) {
100
- this (project , JxBrowserManager .getInstance (), new JxBrowserUtils ());
104
+ this (project , JxBrowserManager .getInstance (), new JxBrowserUtils (), new ViewUtils () );
101
105
}
102
106
103
107
@ VisibleForTesting
104
108
@ NonInjectable
105
- protected FlutterView (@ NotNull Project project , @ NotNull JxBrowserManager jxBrowserManager , JxBrowserUtils jxBrowserUtils ) {
109
+ protected FlutterView (@ NotNull Project project , @ NotNull JxBrowserManager jxBrowserManager , JxBrowserUtils jxBrowserUtils , ViewUtils viewUtils ) {
106
110
myProject = project ;
107
111
this .jxBrowserUtils = jxBrowserUtils ;
108
112
this .jxBrowserManager = jxBrowserManager ;
113
+ this .viewUtils = viewUtils != null ? viewUtils : new ViewUtils ();
109
114
110
115
shouldAutoHorizontalScroll .listen (state ::setShouldAutoScroll );
111
116
highlightNodesShownInBothTrees .listen (state ::setHighlightNodesShownInBothTrees );
@@ -194,7 +199,7 @@ private void addBrowserInspectorViewContent(FlutterApp app,
194
199
new LabelInput ("The embedded browser failed to load. Error: " + error ),
195
200
openDevToolsLabel (app , toolWindow , ideFeature )
196
201
);
197
- presentClickableLabel (toolWindow , inputs );
202
+ viewUtils . presentClickableLabel (toolWindow , inputs );
198
203
});
199
204
}));
200
205
};
@@ -217,7 +222,7 @@ private void addBrowserInspectorViewContent(FlutterApp app,
217
222
.getUrlString (),
218
223
null
219
224
);
220
- presentLabel (toolWindow , "DevTools inspector has been opened in the browser." );
225
+ viewUtils . presentLabel (toolWindow , "DevTools inspector has been opened in the browser." );
221
226
}
222
227
}
223
228
@@ -247,7 +252,7 @@ private void presentDevTools(FlutterApp app, ToolWindow toolWindow, boolean isEm
247
252
verifyEventDispatchThread ();
248
253
249
254
devToolsInstallCount += 1 ;
250
- presentLabel (toolWindow , getInstallingDevtoolsLabel ());
255
+ viewUtils . presentLabel (toolWindow , getInstallingDevtoolsLabel ());
251
256
252
257
openInspectorWithDevTools (app , toolWindow , isEmbedded , ideFeature );
253
258
@@ -266,7 +271,7 @@ protected void setUpToolWindowListener(FlutterApp app, ToolWindow toolWindow, bo
266
271
}
267
272
this .toolWindowListener .updateOnWindowOpen (() -> {
268
273
devToolsInstallCount += 1 ;
269
- presentLabel (toolWindow , getInstallingDevtoolsLabel ());
274
+ viewUtils . presentLabel (toolWindow , getInstallingDevtoolsLabel ());
270
275
openInspectorWithDevTools (app , toolWindow , isEmbedded , ideFeature , true );
271
276
});
272
277
}
@@ -299,12 +304,12 @@ private void openInspectorWithDevTools(FlutterApp app,
299
304
// TODO(helinx): Restart DevTools server if there's an error.
300
305
if (error != null ) {
301
306
LOG .error (error );
302
- presentLabel (toolWindow , DEVTOOLS_FAILED_LABEL );
307
+ viewUtils . presentLabel (toolWindow , DEVTOOLS_FAILED_LABEL );
303
308
return ;
304
309
}
305
310
306
311
if (instance == null ) {
307
- presentLabel (toolWindow , DEVTOOLS_FAILED_LABEL );
312
+ viewUtils . presentLabel (toolWindow , DEVTOOLS_FAILED_LABEL );
308
313
return ;
309
314
}
310
315
@@ -402,47 +407,16 @@ else if (latestFailureReason != null && Objects.equals(latestFailureReason.failu
402
407
inputs .add (openDevToolsLabel );
403
408
}
404
409
405
- presentClickableLabel (toolWindow , inputs );
406
- }
407
-
408
- protected void presentLabel (ToolWindow toolWindow , String text ) {
409
- final JBLabel label = new JBLabel (text , SwingConstants .CENTER );
410
- label .setForeground (UIUtil .getLabelDisabledForeground ());
411
- replacePanelLabel (toolWindow , label );
412
- }
413
-
414
- protected void presentClickableLabel (ToolWindow toolWindow , List <LabelInput > labels ) {
415
- final JPanel panel = new JPanel (new GridLayout (0 , 1 ));
416
-
417
- for (LabelInput input : labels ) {
418
- if (input .listener == null ) {
419
- final JLabel descriptionLabel = new JLabel ("<html>" + input .text + "</html>" );
420
- descriptionLabel .setBorder (JBUI .Borders .empty (5 ));
421
- descriptionLabel .setHorizontalAlignment (SwingConstants .CENTER );
422
- panel .add (descriptionLabel , BorderLayout .NORTH );
423
- }
424
- else {
425
- final LinkLabel <String > linkLabel = new LinkLabel <>("<html>" + input .text + "</html>" , null );
426
- linkLabel .setBorder (JBUI .Borders .empty (5 ));
427
- linkLabel .setListener (input .listener , null );
428
- linkLabel .setHorizontalAlignment (SwingConstants .CENTER );
429
- panel .add (linkLabel , BorderLayout .SOUTH );
430
- }
431
- }
432
-
433
- final JPanel center = new JPanel (new VerticalFlowLayout (VerticalFlowLayout .CENTER ));
434
- center .add (panel );
435
- replacePanelLabel (toolWindow , center );
410
+ viewUtils .presentClickableLabel (toolWindow , inputs );
436
411
}
437
-
438
412
protected void presentOpenDevToolsOptionWithMessage (FlutterApp app ,
439
413
ToolWindow toolWindow ,
440
414
String message ,
441
415
DevToolsIdeFeature ideFeature ) {
442
416
final List <LabelInput > inputs = new ArrayList <>();
443
417
inputs .add (new LabelInput (message ));
444
418
inputs .add (openDevToolsLabel (app , toolWindow , ideFeature ));
445
- presentClickableLabel (toolWindow , inputs );
419
+ viewUtils . presentClickableLabel (toolWindow , inputs );
446
420
}
447
421
448
422
private void replacePanelLabel (ToolWindow toolWindow , JComponent label ) {
0 commit comments