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;
}
Aggregations