Search in sources :

Example 1 with FlutterFramesMonitor

use of io.flutter.perf.FlutterFramesMonitor in project flutter-intellij by flutter.

the class StackLayout method createJPanelView.

public static JPanel createJPanelView(Disposable parentDisposable, FlutterApp app) {
    final JPanel panel = new JPanel(new StackLayout());
    panel.setDoubleBuffered(true);
    panel.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
    panel.setPreferredSize(new Dimension(100, HeapDisplay.PANEL_HEIGHT));
    assert app.getPerfService() != null;
    final FlutterFramesMonitor flutterFramesMonitor = app.getPerfService().getFlutterFramesMonitor();
    final FPSPanel fpsPanel = new FPSPanel(flutterFramesMonitor);
    final JPanel labelsPanel = new JPanel();
    labelsPanel.setOpaque(false);
    labelsPanel.setLayout(new BoxLayout(labelsPanel, BoxLayout.X_AXIS));
    panel.add(fpsPanel);
    panel.add(labelsPanel);
    final JBLabel fpsLabel = new JBLabel();
    fpsLabel.setAlignmentY(Component.TOP_ALIGNMENT);
    fpsLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
    fpsLabel.setForeground(UIUtil.getLabelDisabledForeground());
    fpsLabel.setOpaque(false);
    fpsLabel.setBorder(JBUI.Borders.empty(4));
    final JBLabel elapsedLabel = new JBLabel("", SwingConstants.RIGHT);
    elapsedLabel.setAlignmentY(Component.TOP_ALIGNMENT);
    elapsedLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
    elapsedLabel.setForeground(UIUtil.getLabelDisabledForeground());
    elapsedLabel.setOpaque(false);
    elapsedLabel.setBorder(JBUI.Borders.empty(4));
    labelsPanel.add(fpsLabel);
    labelsPanel.add(Box.createHorizontalGlue());
    labelsPanel.add(elapsedLabel);
    final FlutterFramesMonitor.Listener listener = event -> {
        fpsPanel.update();
        final int ms = Math.round(event.elapsedMicros / 1000.0f);
        elapsedLabel.setText(ms + "ms");
        SwingUtilities.invokeLater(elapsedLabel::repaint);
        fpsLabel.setText(df.format(flutterFramesMonitor.getFPS()) + " FPS");
        SwingUtilities.invokeLater(fpsLabel::repaint);
    };
    flutterFramesMonitor.addListener(listener);
    Disposer.register(parentDisposable, () -> flutterFramesMonitor.removeListener(listener));
    return panel;
}
Also used : CustomComponentAction(com.intellij.openapi.actionSystem.ex.CustomComponentAction) UIUtil(com.intellij.util.ui.UIUtil) java.util(java.util) DecimalFormat(java.text.DecimalFormat) Presentation(com.intellij.openapi.actionSystem.Presentation) AnAction(com.intellij.openapi.actionSystem.AnAction) JBLabel(com.intellij.ui.components.JBLabel) Disposable(com.intellij.openapi.Disposable) Path2D(java.awt.geom.Path2D) java.awt(java.awt) SideBorder(com.intellij.ui.SideBorder) List(java.util.List) IdeBorderFactory(com.intellij.ui.IdeBorderFactory) JBUI(com.intellij.util.ui.JBUI) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Disposer(com.intellij.openapi.util.Disposer) FlutterFramesMonitor(io.flutter.perf.FlutterFramesMonitor) NotNull(org.jetbrains.annotations.NotNull) FlutterApp(io.flutter.run.daemon.FlutterApp) javax.swing(javax.swing) JBLabel(com.intellij.ui.components.JBLabel) FlutterFramesMonitor(io.flutter.perf.FlutterFramesMonitor)

Aggregations

Disposable (com.intellij.openapi.Disposable)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1 CustomComponentAction (com.intellij.openapi.actionSystem.ex.CustomComponentAction)1 Disposer (com.intellij.openapi.util.Disposer)1 IdeBorderFactory (com.intellij.ui.IdeBorderFactory)1 SideBorder (com.intellij.ui.SideBorder)1 JBLabel (com.intellij.ui.components.JBLabel)1 JBUI (com.intellij.util.ui.JBUI)1 UIUtil (com.intellij.util.ui.UIUtil)1 FlutterFramesMonitor (io.flutter.perf.FlutterFramesMonitor)1 FlutterApp (io.flutter.run.daemon.FlutterApp)1 java.awt (java.awt)1 Path2D (java.awt.geom.Path2D)1 DecimalFormat (java.text.DecimalFormat)1 java.util (java.util)1 List (java.util.List)1 javax.swing (javax.swing)1 NotNull (org.jetbrains.annotations.NotNull)1