@@ -86,6 +86,10 @@ public class FlutterView implements PersistentStateComponent<FlutterViewState>,
8686 @ NotNull
8787 private final FlutterViewState state = new FlutterViewState ();
8888
89+ @ VisibleForTesting
90+ @ NotNull
91+ public final ViewUtils viewUtils ;
92+
8993 @ NotNull
9094 private final Project myProject ;
9195
@@ -97,15 +101,16 @@ public class FlutterView implements PersistentStateComponent<FlutterViewState>,
97101 private final JxBrowserManager jxBrowserManager ;
98102
99103 public FlutterView (@ NotNull Project project ) {
100- this (project , JxBrowserManager .getInstance (), new JxBrowserUtils ());
104+ this (project , JxBrowserManager .getInstance (), new JxBrowserUtils (), new ViewUtils () );
101105 }
102106
103107 @ VisibleForTesting
104108 @ 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 ) {
106110 myProject = project ;
107111 this .jxBrowserUtils = jxBrowserUtils ;
108112 this .jxBrowserManager = jxBrowserManager ;
113+ this .viewUtils = viewUtils != null ? viewUtils : new ViewUtils ();
109114
110115 shouldAutoHorizontalScroll .listen (state ::setShouldAutoScroll );
111116 highlightNodesShownInBothTrees .listen (state ::setHighlightNodesShownInBothTrees );
@@ -194,7 +199,7 @@ private void addBrowserInspectorViewContent(FlutterApp app,
194199 new LabelInput ("The embedded browser failed to load. Error: " + error ),
195200 openDevToolsLabel (app , toolWindow , ideFeature )
196201 );
197- presentClickableLabel (toolWindow , inputs );
202+ viewUtils . presentClickableLabel (toolWindow , inputs );
198203 });
199204 }));
200205 };
@@ -217,7 +222,7 @@ private void addBrowserInspectorViewContent(FlutterApp app,
217222 .getUrlString (),
218223 null
219224 );
220- presentLabel (toolWindow , "DevTools inspector has been opened in the browser." );
225+ viewUtils . presentLabel (toolWindow , "DevTools inspector has been opened in the browser." );
221226 }
222227 }
223228
@@ -247,7 +252,7 @@ private void presentDevTools(FlutterApp app, ToolWindow toolWindow, boolean isEm
247252 verifyEventDispatchThread ();
248253
249254 devToolsInstallCount += 1 ;
250- presentLabel (toolWindow , getInstallingDevtoolsLabel ());
255+ viewUtils . presentLabel (toolWindow , getInstallingDevtoolsLabel ());
251256
252257 openInspectorWithDevTools (app , toolWindow , isEmbedded , ideFeature );
253258
@@ -266,7 +271,7 @@ protected void setUpToolWindowListener(FlutterApp app, ToolWindow toolWindow, bo
266271 }
267272 this .toolWindowListener .updateOnWindowOpen (() -> {
268273 devToolsInstallCount += 1 ;
269- presentLabel (toolWindow , getInstallingDevtoolsLabel ());
274+ viewUtils . presentLabel (toolWindow , getInstallingDevtoolsLabel ());
270275 openInspectorWithDevTools (app , toolWindow , isEmbedded , ideFeature , true );
271276 });
272277 }
@@ -299,12 +304,12 @@ private void openInspectorWithDevTools(FlutterApp app,
299304 // TODO(helinx): Restart DevTools server if there's an error.
300305 if (error != null ) {
301306 LOG .error (error );
302- presentLabel (toolWindow , DEVTOOLS_FAILED_LABEL );
307+ viewUtils . presentLabel (toolWindow , DEVTOOLS_FAILED_LABEL );
303308 return ;
304309 }
305310
306311 if (instance == null ) {
307- presentLabel (toolWindow , DEVTOOLS_FAILED_LABEL );
312+ viewUtils . presentLabel (toolWindow , DEVTOOLS_FAILED_LABEL );
308313 return ;
309314 }
310315
@@ -402,47 +407,16 @@ else if (latestFailureReason != null && Objects.equals(latestFailureReason.failu
402407 inputs .add (openDevToolsLabel );
403408 }
404409
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 );
436411 }
437-
438412 protected void presentOpenDevToolsOptionWithMessage (FlutterApp app ,
439413 ToolWindow toolWindow ,
440414 String message ,
441415 DevToolsIdeFeature ideFeature ) {
442416 final List <LabelInput > inputs = new ArrayList <>();
443417 inputs .add (new LabelInput (message ));
444418 inputs .add (openDevToolsLabel (app , toolWindow , ideFeature ));
445- presentClickableLabel (toolWindow , inputs );
419+ viewUtils . presentClickableLabel (toolWindow , inputs );
446420 }
447421
448422 private void replacePanelLabel (ToolWindow toolWindow , JComponent label ) {
0 commit comments