Search in sources :

Example 6 with JBPanel

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

the class BaseSegment method initializeComponents.

public void initializeComponents() {
    setLayout(new BorderLayout());
    FontMetrics metrics = getFontMetrics(AdtUiUtils.DEFAULT_FONT);
    mLabelPanel = createSpacerPanel(metrics.getHeight() + LABEL_BORDER_WIDTH);
    mLabelPanel.setBorder(LABEL_BORDER);
    mLabel = new RotatedLabel();
    mLabel.setFont(AdtUiUtils.DEFAULT_FONT);
    mLabel.setText(myName);
    mLabel.setBorder(SEGMENT_BORDER);
    mLabelPanel.add(mLabel);
    this.add(mLabelPanel, BorderLayout.WEST);
    JBPanel panels = new JBPanel();
    panels.setBorder(SEGMENT_BORDER);
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    panels.setLayout(new GridBagLayout());
    gbc.weightx = 0;
    gbc.weighty = 0;
    //Setup the left panel
    if (hasLeftContent()) {
        mLeftPanel = createSpacerPanel(getSpacerWidth());
        gbc.gridx = 0;
        gbc.gridy = 1;
        panels.add(mLeftPanel, gbc);
        setLeftContent(mLeftPanel);
    }
    //Setup the top center panel.
    JBPanel topPanel = new JBPanel();
    topPanel.setLayout(new BorderLayout());
    gbc.gridx = 1;
    gbc.gridy = 0;
    panels.add(topPanel, gbc);
    setTopCenterContent(topPanel);
    //Setup the right panel
    if (hasRightContent()) {
        mRightPanel = createSpacerPanel(getSpacerWidth());
        gbc.gridx = 2;
        gbc.gridy = 1;
        panels.add(mRightPanel, gbc);
        setRightContent(mRightPanel);
    }
    //Setup the center panel, the primary component.
    //This component should consume all available space.
    JBPanel centerPanel = new JBPanel();
    centerPanel.setLayout(new BorderLayout());
    gbc.weightx = 1;
    gbc.weighty = 1;
    gbc.gridx = 1;
    gbc.gridy = 1;
    panels.add(centerPanel, gbc);
    setCenterContent(centerPanel);
    add(panels, BorderLayout.CENTER);
    // By default, starts in L1, this gives the Segment a chance to hide the right spacer panel and determine what it should rendered.
    toggleView(false);
}
Also used : JBPanel(com.intellij.ui.components.JBPanel) RotatedLabel(com.android.tools.adtui.common.RotatedLabel)

Example 7 with JBPanel

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

the class AccordionVisualTest method createComponentsList.

@Override
protected List<Animatable> createComponentsList() {
    mStartTimeUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime());
    Range timeGlobalRangeUs = new Range(0, 0);
    mAnimatedTimeRange = new AnimatedTimeRange(timeGlobalRangeUs, mStartTimeUs);
    mPanelX = new JBPanel();
    mPanelY = new JBPanel();
    mAccordionX = new AccordionLayout(mPanelX, AccordionLayout.Orientation.HORIZONTAL);
    mAccordionY = new AccordionLayout(mPanelY, AccordionLayout.Orientation.VERTICAL);
    mPanelX.setLayout(mAccordionX);
    mPanelY.setLayout(mAccordionY);
    List<Animatable> componentsList = new ArrayList<>();
    // Add the scene components to the list
    componentsList.add(mAccordionX);
    componentsList.add(mAccordionY);
    componentsList.add(mAnimatedTimeRange);
    mRangedData = new ArrayList<>();
    mData = new ArrayList<>();
    Range yRange = new Range(0.0, 100.0);
    for (int i = 0; i < 4; i++) {
        if (i % 2 == 0) {
            yRange = new Range(0.0, 100.0);
        }
        LongDataSeries series = new LongDataSeries();
        RangedContinuousSeries ranged = new RangedContinuousSeries("Widgets", timeGlobalRangeUs, yRange, series);
        mRangedData.add(ranged);
        mData.add(series);
    }
    return componentsList;
}
Also used : LongDataSeries(com.android.tools.adtui.model.LongDataSeries) ArrayList(java.util.ArrayList) Range(com.android.tools.adtui.model.Range) JBPanel(com.intellij.ui.components.JBPanel) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries)

Example 8 with JBPanel

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

the class AccordionVisualTest method populateUi.

@Override
protected void populateUi(@NotNull JPanel panel) {
    panel.setLayout(new GridLayout(0, 1));
    Thread mUpdateDataThread = new Thread() {

        @Override
        public void run() {
            try {
                while (true) {
                    long nowUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime()) - mStartTimeUs;
                    for (LongDataSeries series : mData) {
                        ImmutableList<SeriesData<Long>> data = series.getAllData();
                        long last = data.isEmpty() ? 0 : data.get(data.size() - 1).value;
                        float delta = 10 * ((float) Math.random() - 0.45f);
                        series.add(nowUs, last + (long) delta);
                    }
                    Thread.sleep(LINECHART_DATA_DELAY);
                }
            } catch (InterruptedException e) {
            }
        }
    };
    mUpdateDataThread.start();
    // Creates the vertical accordion at the top half.
    JBPanel yPanel = new JBPanel();
    panel.add(yPanel);
    yPanel.setBorder(BorderFactory.createLineBorder(AdtUiUtils.DEFAULT_BORDER_COLOR));
    final JPanel controlsY = VisualTest.createControlledPane(yPanel, mPanelY);
    controlsY.add(VisualTest.createButton("Reset Weights", listener -> {
        mAccordionY.resetComponents();
    }));
    controlsY.add(VisualTest.createButton("Add Chart", listener -> {
        final LineChart chart = generateChart(mAccordionY, AccordionLayout.Orientation.VERTICAL, 0, PREFERRED_SIZE, Integer.MAX_VALUE);
        mPanelY.add(chart);
        mChartCountY++;
    }));
    controlsY.add(VisualTest.createButton("Add Chart With Min", listener -> {
        final LineChart chart = generateChart(mAccordionY, AccordionLayout.Orientation.VERTICAL, MIN_SIZE, PREFERRED_SIZE, Integer.MAX_VALUE);
        mPanelY.add(chart);
        mChartCountY++;
    }));
    controlsY.add(VisualTest.createButton("Add Chart With Small Max", listener -> {
        final LineChart chart = generateChart(mAccordionY, AccordionLayout.Orientation.VERTICAL, 0, PREFERRED_SIZE, MAX_SIZE);
        mPanelY.add(chart);
        mChartCountY++;
    }));
    controlsY.add(VisualTest.createButton("Remove Last Chart", listener -> {
        mPanelY.remove(--mChartCountY);
    }));
    controlsY.add(new Box.Filler(new Dimension(0, 0), new Dimension(300, Integer.MAX_VALUE), new Dimension(300, Integer.MAX_VALUE)));
    // Creates the horizontal accordion at the bottom half.
    JBPanel xPanel = new JBPanel();
    panel.add(xPanel);
    xPanel.setBorder(BorderFactory.createLineBorder(AdtUiUtils.DEFAULT_BORDER_COLOR));
    final JPanel controlsX = VisualTest.createControlledPane(xPanel, mPanelX);
    controlsX.add(VisualTest.createButton("Reset Weights", listener -> {
        mAccordionX.resetComponents();
    }));
    controlsX.add(VisualTest.createButton("Add Chart", listener -> {
        final LineChart chart = generateChart(mAccordionX, AccordionLayout.Orientation.HORIZONTAL, 0, PREFERRED_SIZE, Integer.MAX_VALUE);
        mPanelX.add(chart);
        mChartCountX++;
    }));
    controlsX.add(VisualTest.createButton("Add Chart With Min", listener -> {
        final LineChart chart = generateChart(mAccordionX, AccordionLayout.Orientation.HORIZONTAL, MIN_SIZE, PREFERRED_SIZE, Integer.MAX_VALUE);
        mPanelX.add(chart);
        mChartCountX++;
    }));
    controlsX.add(VisualTest.createButton("Add Chart With Small Max", listener -> {
        final LineChart chart = generateChart(mAccordionX, AccordionLayout.Orientation.HORIZONTAL, 0, PREFERRED_SIZE, MAX_SIZE);
        mPanelX.add(chart);
        mChartCountX++;
    }));
    controlsX.add(VisualTest.createButton("Remove Last Chart", listener -> {
        mPanelX.remove(--mChartCountX);
    }));
    controlsX.add(new Box.Filler(new Dimension(0, 0), new Dimension(300, Integer.MAX_VALUE), new Dimension(300, Integer.MAX_VALUE)));
}
Also used : LongDataSeries(com.android.tools.adtui.model.LongDataSeries) Range(com.android.tools.adtui.model.Range) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LineChart(com.android.tools.adtui.chart.linechart.LineChart) ImmutableList(com.intellij.util.containers.ImmutableList) AdtUiUtils(com.android.tools.adtui.common.AdtUiUtils) MouseEvent(java.awt.event.MouseEvent) ArrayList(java.util.ArrayList) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) com.android.tools.adtui(com.android.tools.adtui) List(java.util.List) SeriesData(com.android.tools.adtui.model.SeriesData) JBPanel(com.intellij.ui.components.JBPanel) MouseAdapter(java.awt.event.MouseAdapter) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) LongDataSeries(com.android.tools.adtui.model.LongDataSeries) JBPanel(com.intellij.ui.components.JBPanel) SeriesData(com.android.tools.adtui.model.SeriesData) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Example 9 with JBPanel

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

the class AxisLineChartVisualTest method populateUi.

@Override
protected void populateUi(@NotNull JPanel panel) {
    panel.setLayout(new BorderLayout());
    JLayeredPane mockTimelinePane = createMockTimeline();
    panel.add(mockTimelinePane, BorderLayout.CENTER);
    final JBPanel controls = new JBPanel();
    LayoutManager manager = new BoxLayout(controls, BoxLayout.Y_AXIS);
    controls.setLayout(manager);
    panel.add(controls, BorderLayout.WEST);
    final AtomicInteger variance = new AtomicInteger(10);
    final AtomicInteger delay = new AtomicInteger(10);
    Thread mUpdateDataThread = new Thread() {

        @Override
        public void run() {
            try {
                while (true) {
                    long nowUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime()) - mStartTimeUs;
                    for (LongDataSeries series : mData) {
                        ImmutableList<SeriesData<Long>> data = series.getAllData();
                        long last = data.isEmpty() ? 0 : data.get(data.size() - 1).value;
                        float delta = 10 * ((float) Math.random() - 0.45f);
                        series.add(nowUs, last + (long) delta);
                    }
                    Thread.sleep(delay.get());
                }
            } catch (InterruptedException e) {
            }
        }
    };
    mUpdateDataThread.start();
    controls.add(VisualTest.createVariableSlider("Delay", 10, 5000, new VisualTests.Value() {

        @Override
        public void set(int v) {
            delay.set(v);
        }

        @Override
        public int get() {
            return delay.get();
        }
    }));
    controls.add(VisualTest.createVariableSlider("Variance", 0, 50, new VisualTests.Value() {

        @Override
        public void set(int v) {
            variance.set(v);
        }

        @Override
        public int get() {
            return variance.get();
        }
    }));
    controls.add(VisualTest.createCheckbox("Stable Scroll", itemEvent -> mScrollbar.setStableScrolling(itemEvent.getStateChange() == ItemEvent.SELECTED)));
    controls.add(VisualTest.createCheckbox("Clamp To Major Ticks", itemEvent -> mMemoryAxis1.setClampToMajorTicks(itemEvent.getStateChange() == ItemEvent.SELECTED)));
    controls.add(VisualTest.createCheckbox("Sync Vertical Axes", itemEvent -> mMemoryAxis2.setParentAxis(itemEvent.getStateChange() == ItemEvent.SELECTED ? mMemoryAxis1 : null)));
    controls.add(new Box.Filler(new Dimension(0, 0), new Dimension(300, Integer.MAX_VALUE), new Dimension(300, Integer.MAX_VALUE)));
}
Also used : LongDataSeries(com.android.tools.adtui.model.LongDataSeries) ItemEvent(java.awt.event.ItemEvent) Range(com.android.tools.adtui.model.Range) Arrays(java.util.Arrays) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LineChart(com.android.tools.adtui.chart.linechart.LineChart) ImmutableList(com.intellij.util.containers.ImmutableList) ComponentEvent(java.awt.event.ComponentEvent) ArrayList(java.util.ArrayList) java.awt(java.awt) ComponentAdapter(java.awt.event.ComponentAdapter) TimeUnit(java.util.concurrent.TimeUnit) com.android.tools.adtui(com.android.tools.adtui) List(java.util.List) MemoryAxisFormatter(com.android.tools.adtui.common.formatter.MemoryAxisFormatter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SeriesData(com.android.tools.adtui.model.SeriesData) JBLayeredPane(com.intellij.ui.components.JBLayeredPane) JBPanel(com.intellij.ui.components.JBPanel) NotNull(org.jetbrains.annotations.NotNull) TimeAxisFormatter(com.android.tools.adtui.common.formatter.TimeAxisFormatter) javax.swing(javax.swing) LongDataSeries(com.android.tools.adtui.model.LongDataSeries) JBPanel(com.intellij.ui.components.JBPanel) SeriesData(com.android.tools.adtui.model.SeriesData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 10 with JBPanel

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

the class AxisLineChartVisualTest method createMockTimeline.

private JLayeredPane createMockTimeline() {
    JBLayeredPane timelinePane = new JBLayeredPane();
    timelinePane.add(mMemoryAxis1);
    timelinePane.add(mMemoryAxis2);
    timelinePane.add(mTimeAxis);
    timelinePane.add(mLineChart);
    timelinePane.add(mSelection);
    timelinePane.add(mGrid);
    timelinePane.add(mScrollbar);
    // TODO move to ProfilerOverviewVisualTest.
    JBPanel labelPanel = new JBPanel();
    labelPanel.setLayout(new FlowLayout());
    labelPanel.add(mLegendComponent);
    timelinePane.add(labelPanel);
    timelinePane.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            JLayeredPane host = (JLayeredPane) e.getComponent();
            if (host != null) {
                Dimension dim = host.getSize();
                for (Component c : host.getComponents()) {
                    if (c instanceof AxisComponent) {
                        AxisComponent axis = (AxisComponent) c;
                        switch(axis.getOrientation()) {
                            case LEFT:
                                axis.setBounds(0, 0, AXIS_SIZE, dim.height);
                                break;
                            case BOTTOM:
                                axis.setBounds(0, dim.height - AXIS_SIZE, dim.width, AXIS_SIZE);
                                break;
                            case RIGHT:
                                axis.setBounds(dim.width - AXIS_SIZE, 0, AXIS_SIZE, dim.height);
                                break;
                            case TOP:
                                axis.setBounds(0, 0, dim.width, AXIS_SIZE);
                                break;
                        }
                    } else if (c instanceof RangeScrollbar) {
                        int sbHeight = c.getPreferredSize().height;
                        c.setBounds(0, dim.height - sbHeight, dim.width, sbHeight);
                    } else {
                        c.setBounds(AXIS_SIZE, AXIS_SIZE, dim.width - AXIS_SIZE * 2, dim.height - AXIS_SIZE * 2);
                    }
                }
            }
        }
    });
    return timelinePane;
}
Also used : JBLayeredPane(com.intellij.ui.components.JBLayeredPane) ComponentEvent(java.awt.event.ComponentEvent) JBPanel(com.intellij.ui.components.JBPanel) ComponentAdapter(java.awt.event.ComponentAdapter)

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