Search in sources :

Example 1 with LegendComponent

use of com.android.tools.adtui.LegendComponent in project android by JetBrains.

the class CpuMonitorView method populateUi.

@Override
protected void populateUi(JPanel container, Choreographer choreographer) {
    container.setLayout(new TabularLayout("*", "*"));
    Range viewRange = getMonitor().getTimeline().getViewRange();
    Range dataRange = getMonitor().getTimeline().getDataRange();
    final JLabel label = new JLabel(getMonitor().getName());
    label.setBorder(MONITOR_LABEL_PADDING);
    label.setVerticalAlignment(JLabel.TOP);
    // Cpu usage is shown as percentages (e.g. 0 - 100) and no range animation is needed.
    Range leftYRange = new Range(0, 100);
    final JPanel axisPanel = new JBPanel(new BorderLayout());
    axisPanel.setOpaque(false);
    AxisComponent.Builder builder = new AxisComponent.Builder(leftYRange, CPU_USAGE_AXIS, AxisComponent.AxisOrientation.RIGHT).showAxisLine(false).showMax(true).showUnitAtMax(true).setMarkerLengths(MARKER_LENGTH, MARKER_LENGTH).clampToMajorTicks(true).setMargins(0, Y_AXIS_TOP_MARGIN);
    final AxisComponent leftAxis = builder.build();
    axisPanel.add(leftAxis, BorderLayout.WEST);
    final JPanel lineChartPanel = new JBPanel(new BorderLayout());
    lineChartPanel.setOpaque(false);
    lineChartPanel.setBorder(BorderFactory.createEmptyBorder(Y_AXIS_TOP_MARGIN, 0, 0, 0));
    final LineChart lineChart = new LineChart();
    RangedContinuousSeries cpuSeries = new RangedContinuousSeries("CPU", viewRange, leftYRange, getMonitor().getThisProcessCpuUsage());
    lineChart.addLine(cpuSeries, new LineConfig(ProfilerColors.CPU_USAGE).setFilled(true));
    lineChartPanel.add(lineChart, BorderLayout.CENTER);
    final LegendComponent legend = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, LEGEND_UPDATE_FREQUENCY_MS);
    legend.setLegendData(Collections.singletonList(lineChart.createLegendRenderData(cpuSeries, CPU_USAGE_AXIS, dataRange)));
    final JPanel legendPanel = new JBPanel(new BorderLayout());
    legendPanel.setOpaque(false);
    legendPanel.add(label, BorderLayout.WEST);
    legendPanel.add(legend, BorderLayout.EAST);
    choreographer.register(lineChart);
    choreographer.register(leftAxis);
    choreographer.register(legend);
    container.add(legendPanel, new TabularLayout.Constraint(0, 0));
    container.add(leftAxis, new TabularLayout.Constraint(0, 0));
    container.add(lineChartPanel, new TabularLayout.Constraint(0, 0));
    container.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            getMonitor().expand();
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) TabularLayout(com.android.tools.adtui.TabularLayout) MouseAdapter(java.awt.event.MouseAdapter) AxisComponent(com.android.tools.adtui.AxisComponent) Range(com.android.tools.adtui.model.Range) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) JBPanel(com.intellij.ui.components.JBPanel) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LegendComponent(com.android.tools.adtui.LegendComponent) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Example 2 with LegendComponent

use of com.android.tools.adtui.LegendComponent in project android by JetBrains.

the class MemoryMonitorView method populateUi.

@Override
protected void populateUi(JPanel container, Choreographer choreographer) {
    container.setLayout(new TabularLayout("*", "*"));
    Range viewRange = getMonitor().getTimeline().getViewRange();
    Range dataRange = getMonitor().getTimeline().getDataRange();
    final JLabel label = new JLabel(getMonitor().getName());
    label.setBorder(MONITOR_LABEL_PADDING);
    label.setVerticalAlignment(JLabel.TOP);
    Range leftYRange = new Range(0, 0);
    final JPanel axisPanel = new JBPanel(new BorderLayout());
    axisPanel.setOpaque(false);
    AxisComponent.Builder builder = new AxisComponent.Builder(leftYRange, MEMORY_AXIS_FORMATTER, AxisComponent.AxisOrientation.RIGHT).showAxisLine(false).showMax(true).showUnitAtMax(true).clampToMajorTicks(true).setMarkerLengths(MARKER_LENGTH, MARKER_LENGTH).setMargins(0, Y_AXIS_TOP_MARGIN);
    final AxisComponent leftAxis = builder.build();
    axisPanel.add(leftAxis, BorderLayout.WEST);
    final JPanel lineChartPanel = new JBPanel(new BorderLayout());
    lineChartPanel.setOpaque(false);
    lineChartPanel.setBorder(BorderFactory.createEmptyBorder(Y_AXIS_TOP_MARGIN, 0, 0, 0));
    final LineChart lineChart = new LineChart();
    RangedContinuousSeries memSeries = new RangedContinuousSeries("Memory", viewRange, leftYRange, getMonitor().getTotalMemory());
    lineChart.addLine(memSeries, new LineConfig(ProfilerColors.MEMORY_TOTAL).setFilled(true));
    lineChartPanel.add(lineChart, BorderLayout.CENTER);
    final LegendComponent legend = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, LEGEND_UPDATE_FREQUENCY_MS);
    legend.setLegendData(Collections.singletonList(lineChart.createLegendRenderData(memSeries, MEMORY_AXIS_FORMATTER, dataRange)));
    final JPanel legendPanel = new JBPanel(new BorderLayout());
    legendPanel.setOpaque(false);
    legendPanel.add(label, BorderLayout.WEST);
    legendPanel.add(legend, BorderLayout.EAST);
    choreographer.register(lineChart);
    choreographer.register(leftAxis);
    choreographer.register(legend);
    container.add(legendPanel, new TabularLayout.Constraint(0, 0));
    container.add(leftAxis, new TabularLayout.Constraint(0, 0));
    container.add(lineChartPanel, new TabularLayout.Constraint(0, 0));
    container.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            getMonitor().expand();
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) TabularLayout(com.android.tools.adtui.TabularLayout) MouseAdapter(java.awt.event.MouseAdapter) AxisComponent(com.android.tools.adtui.AxisComponent) Range(com.android.tools.adtui.model.Range) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) JBPanel(com.intellij.ui.components.JBPanel) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LegendComponent(com.android.tools.adtui.LegendComponent) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Example 3 with LegendComponent

use of com.android.tools.adtui.LegendComponent in project android by JetBrains.

the class NetworkRadioSegment method createComponentsList.

@Override
public void createComponentsList(@NotNull List<Animatable> animatables) {
    EnumMap<RadioState, Color> colorsMap = getRadioStateColor();
    EnumMap<RadioState, String> labelsMap = getRadioStateLabel();
    mRadioChart = new StateChart(colorsMap);
    mRadioChart.addSeries(new RangedSeries<>(myTimeCurrentRangeUs, new DataStoreSeries<>(mDataStore, SeriesDataType.NETWORK_RADIO)));
    mNetworkTypeChart = new StateChart<>(getNetworkTypeColor());
    mNetworkTypeChart.setRenderMode(StateChart.RenderMode.TEXT);
    mNetworkTypeChart.addSeries(new RangedSeries<>(myTimeCurrentRangeUs, new DataStoreSeries<>(mDataStore, SeriesDataType.NETWORK_TYPE)));
    List<LegendRenderData> legendRenderDataList = new ArrayList<>();
    for (RadioState state : RadioState.values()) {
        LegendRenderData renderData = new LegendRenderData(LegendRenderData.IconType.LINE, colorsMap.get(state), labelsMap.get(state));
        legendRenderDataList.add(renderData);
    }
    mLegendComponent = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, 100);
    mLegendComponent.setLegendData(legendRenderDataList);
    animatables.add(mNetworkTypeChart);
    animatables.add(mRadioChart);
    animatables.add(mLegendComponent);
}
Also used : LegendRenderData(com.android.tools.adtui.LegendRenderData) JBColor(com.intellij.ui.JBColor) ArrayList(java.util.ArrayList) DataStoreSeries(com.android.tools.datastore.DataStoreSeries) LegendComponent(com.android.tools.adtui.LegendComponent) StateChart(com.android.tools.adtui.chart.StateChart)

Example 4 with LegendComponent

use of com.android.tools.adtui.LegendComponent in project android by JetBrains.

the class ThreadsSegment method initializeLegendComponent.

private void initializeLegendComponent() {
    List<LegendRenderData> legendRenderDataList = new ArrayList<>();
    // Running state
    legendRenderDataList.add(new LegendRenderData(LegendRenderData.IconType.BOX, getThreadStateColor().get(CpuProfiler.ThreadActivity.State.RUNNING), RUNNING_LABEL));
    // Sleeping state
    legendRenderDataList.add(new LegendRenderData(LegendRenderData.IconType.BOX, getThreadStateColor().get(CpuProfiler.ThreadActivity.State.SLEEPING), SLEEPING_LABEL));
    // Blocked state. TODO: support this state later if we actually should do so
    legendRenderDataList.add(new LegendRenderData(LegendRenderData.IconType.BOX, new JBColor(new Color(199, 65, 101), new Color(199, 65, 101)), BLOCKED_LABEL));
    mLegendComponent = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, Integer.MAX_VALUE);
    mLegendComponent.setLegendData(legendRenderDataList);
}
Also used : LegendRenderData(com.android.tools.adtui.LegendRenderData) JBColor(com.intellij.ui.JBColor) LegendComponent(com.android.tools.adtui.LegendComponent) JBColor(com.intellij.ui.JBColor)

Example 5 with LegendComponent

use of com.android.tools.adtui.LegendComponent in project android by JetBrains.

the class NetworkRadioView method populateUI.

private void populateUI(@NotNull JComponent panel) {
    JLabel label = new JLabel(LABEL);
    label.setVerticalAlignment(SwingConstants.TOP);
    LegendComponent legend = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, Integer.MAX_VALUE);
    legend.setLegendData(getLegendData());
    // As legend doesn't change over time, it doesn't need to be in {@code Choreographer}}, so draw it by animating once.
    legend.animate(1);
    JPanel topPane = new JPanel(new BorderLayout());
    topPane.setOpaque(false);
    topPane.add(label, BorderLayout.WEST);
    topPane.add(legend, BorderLayout.EAST);
    panel.setLayout(new VerticalFlowLayout(true, true));
    panel.add(topPane);
    panel.add(myRadioChart);
}
Also used : LegendComponent(com.android.tools.adtui.LegendComponent) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout)

Aggregations

LegendComponent (com.android.tools.adtui.LegendComponent)5 AxisComponent (com.android.tools.adtui.AxisComponent)2 LegendRenderData (com.android.tools.adtui.LegendRenderData)2 TabularLayout (com.android.tools.adtui.TabularLayout)2 LineChart (com.android.tools.adtui.chart.linechart.LineChart)2 LineConfig (com.android.tools.adtui.chart.linechart.LineConfig)2 Range (com.android.tools.adtui.model.Range)2 RangedContinuousSeries (com.android.tools.adtui.model.RangedContinuousSeries)2 JBColor (com.intellij.ui.JBColor)2 JBPanel (com.intellij.ui.components.JBPanel)2 MouseAdapter (java.awt.event.MouseAdapter)2 MouseEvent (java.awt.event.MouseEvent)2 StateChart (com.android.tools.adtui.chart.StateChart)1 DataStoreSeries (com.android.tools.datastore.DataStoreSeries)1 VerticalFlowLayout (com.intellij.openapi.ui.VerticalFlowLayout)1 ArrayList (java.util.ArrayList)1