Search in sources :

Example 11 with JBPanel

use of com.intellij.ui.components.JBPanel in project android by JetBrains.

the class VisualTest method initialize.

protected void initialize() {
    mPanel = new JBPanel();
    mChoreographer = new Choreographer(mPanel);
    mChoreographer.register(createComponentsList());
    populateUi(mPanel);
}
Also used : Choreographer(com.android.tools.adtui.Choreographer) JBPanel(com.intellij.ui.components.JBPanel)

Example 12 with JBPanel

use of com.intellij.ui.components.JBPanel 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 13 with JBPanel

use of com.intellij.ui.components.JBPanel in project android by JetBrains.

the class ProfilerOverviewVisualTest method createComponentsList.

@Override
protected List<Animatable> createComponentsList() {
    long startTimeUs = mDataStore.getLatestTimeUs();
    mTimeCurrentRange = new Range(0, 0);
    mTimeGlobalRange = new Range(startTimeUs - RangeScrollbar.DEFAULT_VIEW_LENGTH_US, startTimeUs);
    mTimeSelectionRange = new Range(0, 0);
    mScrollbar = new RangeScrollbar(mTimeGlobalRange, mTimeCurrentRange);
    // add horizontal time axis
    AxisComponent.Builder builder = new AxisComponent.Builder(mTimeCurrentRange, TimeAxisFormatter.DEFAULT, AxisComponent.AxisOrientation.BOTTOM).setGlobalRange(mTimeGlobalRange).setOffset(startTimeUs);
    mTimeAxis = builder.build();
    mSegmentsContainer = new JBPanel();
    mLayout = new AccordionLayout(mSegmentsContainer, AccordionLayout.Orientation.VERTICAL);
    // TODO animation is disabled at the moment as it causes visual artifacts on the SelectionComponent due to overlapping painting regions.
    mLayout.setLerpFraction(1f);
    mSegmentsContainer.setLayout(mLayout);
    mSelection = new SelectionComponent(mTimeSelectionRange, mTimeCurrentRange);
    List<Animatable> componentsList = new ArrayList<>();
    componentsList.add(mLayout);
    // Get latest data time from the data store.
    componentsList.add(frameLength -> mTimeGlobalRange.setMax(mDataStore.getLatestTimeUs()));
    // Update selection range immediate.
    componentsList.add(mSelection);
    // Update current range immediate.
    componentsList.add(mScrollbar);
    // Read ranges.
    componentsList.add(mTimeAxis);
    return componentsList;
}
Also used : ArrayList(java.util.ArrayList) Range(com.android.tools.adtui.model.Range) JBPanel(com.intellij.ui.components.JBPanel)

Example 14 with JBPanel

use of com.intellij.ui.components.JBPanel in project android by JetBrains.

the class ProfilerOverviewVisualTest method populateUi.

@Override
public void populateUi(JPanel panel) {
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    JBPanel gridBagPanel = new JBPanel();
    gridBagPanel.setBorder(BorderFactory.createLineBorder(AdtUiUtils.DEFAULT_BORDER_COLOR, 1));
    gridBagPanel.setLayout(gbl);
    // TODO create some controls.
    final JPanel controls = VisualTest.createControlledPane(panel, gridBagPanel);
    // Add Mock Toolbar
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridy = 0;
    gbc.gridx = 0;
    gbc.gridwidth = 4;
    gbc.weightx = 0;
    gbc.weighty = 0;
    gridBagPanel.add(createToolbarPanel(), gbc);
    // Add Selection Overlay
    // TODO define sizes for x columns 0 and 1
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridy = 1;
    gbc.gridx = 2;
    gbc.gridwidth = 1;
    gbc.weightx = 1;
    gbc.weighty = 1;
    gridBagPanel.add(mSelection, gbc);
    // Add Accordion Control
    gbc.gridx = 0;
    gbc.gridwidth = 4;
    gbc.gridy = 1;
    gbc.weighty = 0;
    gbc.weightx = 0;
    gridBagPanel.add(mSegmentsContainer, gbc);
    // Add Scrollbar
    gbc.gridy = 2;
    gridBagPanel.add(mScrollbar, gbc);
    // TODO: fix me, currently it's throwing IllegalArgumentException, the reason is:
    // EventSegment is using {@code DeviceProfilerService} which doesn't exist in visual test concept.
    // Mock event segment
    //BaseSegment eventSegment = new EventSegment(mTimeCurrentRange, mDataStore, ICONS, mEventDispatcher);
    //setupAndRegisterSegment(eventSegment, EVENT_MIN_HEIGHT, MONITOR_PREFERRED_HEIGHT, MONITOR_MAX_HEIGHT);
    // Mock monitor segments
    BaseSegment networkSegment = new NetworkSegment(mTimeCurrentRange, mDataStore, mEventDispatcher);
    setupAndRegisterSegment(networkSegment, 0, MONITOR_PREFERRED_HEIGHT, MONITOR_MAX_HEIGHT);
    BaseSegment memorySegment = new MemorySegment(mTimeCurrentRange, mDataStore, mEventDispatcher);
    setupAndRegisterSegment(memorySegment, 0, MONITOR_PREFERRED_HEIGHT, MONITOR_MAX_HEIGHT);
    BaseSegment cpuSegment = new CpuUsageSegment(mTimeCurrentRange, mDataStore, mEventDispatcher);
    setupAndRegisterSegment(cpuSegment, 0, MONITOR_PREFERRED_HEIGHT, MONITOR_MAX_HEIGHT);
    // Timeline segment
    BaseSegment timeSegment = new TimeAxisSegment(mTimeCurrentRange, mTimeAxis, mEventDispatcher);
    setupAndRegisterSegment(timeSegment, TIME_AXIS_HEIGHT, TIME_AXIS_HEIGHT, TIME_AXIS_HEIGHT);
    // Add left spacer
    Dimension leftSpacer = new Dimension(BaseSegment.getSpacerWidth() + networkSegment.getLabelColumnWidth(), 0);
    gbc.gridy = 0;
    gbc.gridx = 0;
    gbc.gridwidth = 2;
    gbc.weightx = 0;
    gbc.weighty = 0;
    gridBagPanel.add(new Box.Filler(leftSpacer, leftSpacer, leftSpacer), gbc);
    // Add right spacer
    Dimension rightSpacerWidth = new Dimension(BaseSegment.getSpacerWidth(), 0);
    Box.Filler rightSpacer = new Box.Filler(rightSpacerWidth, rightSpacerWidth, rightSpacerWidth);
    gbc.gridy = 0;
    gbc.gridx = 3;
    gbc.gridwidth = 1;
    gbc.weightx = 0;
    gbc.weighty = 0;
    gridBagPanel.add(rightSpacer, gbc);
    // hide right space in L1 by default.
    rightSpacer.setVisible(false);
    // Resize the SelectionComponent based on whether we are in L1 or L2 view.
    // TODO construct/destroyed Level3 segment/elements as we expand/collapse segments
    mEventDispatcher.addListener(new ProfilerEventListener() {

        @Override
        public void profilerExpanded(@NotNull BaseProfilerUiManager.ProfilerType profilerType) {
            switch(profilerType) {
                case NETWORK:
                    maximizeSegment(networkSegment);
                    break;
                case CPU:
                    maximizeSegment(cpuSegment);
                    break;
                case MEMORY:
                    maximizeSegment(memorySegment);
                    break;
            }
            rightSpacer.setVisible(true);
            mResetProfilersButton.setEnabled(true);
        }

        @Override
        public void profilersReset() {
            // Sets all the components back to their preferred states.
            mLayout.resetComponents();
            rightSpacer.setVisible(false);
            mResetProfilersButton.setEnabled(false);
            backProfilersToL1();
        }

        private void maximizeSegment(BaseSegment segment) {
            mLayout.setState(segment, AccordionLayout.AccordionState.MAXIMIZE);
            segment.toggleView(true);
        }

        private void backProfilersToL1() {
            networkSegment.toggleView(false);
            cpuSegment.toggleView(false);
            memorySegment.toggleView(false);
        }
    });
}
Also used : CpuUsageSegment(com.android.tools.idea.monitor.ui.cpu.view.CpuUsageSegment) BaseProfilerUiManager(com.android.tools.idea.monitor.ui.BaseProfilerUiManager) JBPanel(com.intellij.ui.components.JBPanel) MemorySegment(com.android.tools.idea.monitor.ui.memory.view.MemorySegment) TimeAxisSegment(com.android.tools.idea.monitor.ui.TimeAxisSegment) BaseSegment(com.android.tools.idea.monitor.ui.BaseSegment) NetworkSegment(com.android.tools.idea.monitor.ui.network.view.NetworkSegment) ProfilerEventListener(com.android.tools.idea.monitor.tool.ProfilerEventListener)

Example 15 with JBPanel

use of com.intellij.ui.components.JBPanel 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)

Aggregations

JBPanel (com.intellij.ui.components.JBPanel)25 Range (com.android.tools.adtui.model.Range)12 RangedContinuousSeries (com.android.tools.adtui.model.RangedContinuousSeries)8 ArrayList (java.util.ArrayList)8 NotNull (org.jetbrains.annotations.NotNull)8 LineChart (com.android.tools.adtui.chart.linechart.LineChart)7 LineConfig (com.android.tools.adtui.chart.linechart.LineConfig)6 com.android.tools.adtui (com.android.tools.adtui)4 java.awt (java.awt)4 MouseEvent (java.awt.event.MouseEvent)4 javax.swing (javax.swing)4 TimeAxisFormatter (com.android.tools.adtui.common.formatter.TimeAxisFormatter)3 LongDataSeries (com.android.tools.adtui.model.LongDataSeries)3 MouseAdapter (java.awt.event.MouseAdapter)3 AxisComponent (com.android.tools.adtui.AxisComponent)2 LegendComponent (com.android.tools.adtui.LegendComponent)2 TabularLayout (com.android.tools.adtui.TabularLayout)2 AdtUiUtils (com.android.tools.adtui.common.AdtUiUtils)2 MemoryAxisFormatter (com.android.tools.adtui.common.formatter.MemoryAxisFormatter)2 SeriesData (com.android.tools.adtui.model.SeriesData)2