Search in sources :

Example 1 with ImmutableList

use of com.intellij.util.containers.ImmutableList 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 2 with ImmutableList

use of com.intellij.util.containers.ImmutableList 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 3 with ImmutableList

use of com.intellij.util.containers.ImmutableList in project android by JetBrains.

the class LineChartVisualTest method populateUi.

@Override
protected void populateUi(@NotNull JPanel panel) {
    JPanel layered = new JPanel(new GridBagLayout());
    JPanel controls = VisualTest.createControlledPane(panel, layered);
    mLineChart.setBorder(BorderFactory.createLineBorder(AdtUiUtils.DEFAULT_BORDER_COLOR));
    layered.add(myOverlayComponent, GBC_FULL);
    layered.add(mySelectionComponent, GBC_FULL);
    layered.add(mLineChart, GBC_FULL);
    final AtomicInteger variance = new AtomicInteger(10);
    final AtomicInteger delay = new AtomicInteger(100);
    Thread updateDataThread = new Thread() {

        @Override
        public void run() {
            super.run();
            try {
                while (true) {
                    int v = variance.get();
                    long nowUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime());
                    for (DefaultDataSeries<Long> series : mData) {
                        ImmutableList<SeriesData<Long>> data = series.getAllData();
                        long last = data.isEmpty() ? 0 : data.get(data.size() - 1).value;
                        float delta = ((float) Math.random() - 0.45f) * v;
                        // Make sure not to add negative numbers.
                        long current = Math.max(last + (long) delta, 0);
                        series.add(nowUs, current);
                    }
                    Thread.sleep(delay.get());
                }
            } catch (InterruptedException e) {
            }
        }
    };
    updateDataThread.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.createVariableSlider("Line width", 1, 10, new VisualTests.Value() {

        @Override
        public void set(int v) {
            Stroke stroke = new BasicStroke(v);
            for (int i = 0; i < mRangedData.size(); i += 2) {
                RangedContinuousSeries series = mRangedData.get(i);
                mLineChart.getLineConfig(series).setStroke(stroke);
            }
        }

        @Override
        public int get() {
            // Returns the stroke width of the first line, in case there is one, or a default (1) value
            RangedContinuousSeries firstSeries = mRangedData.get(0);
            Stroke firstLineStroke = mLineChart.getLineConfig(firstSeries).getStroke();
            return firstLineStroke instanceof BasicStroke ? (int) ((BasicStroke) firstLineStroke).getLineWidth() : 1;
        }
    }));
    controls.add(VisualTest.createCheckbox("Shift xRange Min", itemEvent -> mAnimatedTimeRange.setShift(itemEvent.getStateChange() == ItemEvent.SELECTED)));
    controls.add(VisualTest.createCheckbox("Stepped chart", itemEvent -> {
        boolean isStepped = itemEvent.getStateChange() == ItemEvent.SELECTED;
        for (int i = 0; i < mRangedData.size(); i += 2) {
            RangedContinuousSeries series = mRangedData.get(i);
            mLineChart.getLineConfig(series).setStepped(isStepped);
        }
    }));
    controls.add(VisualTest.createCheckbox("Dashed lines", itemEvent -> {
        Stroke stroke = itemEvent.getStateChange() == ItemEvent.SELECTED ? LineConfig.DEFAULT_DASH_STROKE : LineConfig.DEFAULT_LINE_STROKE;
        for (int i = 0; i < mRangedData.size(); i += 2) {
            RangedContinuousSeries series = mRangedData.get(i);
            mLineChart.getLineConfig(series).setStroke(stroke);
        }
    }));
    controls.add(VisualTest.createCheckbox("Filled lines", itemEvent -> {
        boolean isFilled = itemEvent.getStateChange() == ItemEvent.SELECTED;
        for (int i = 0; i < mRangedData.size(); i += 2) {
            RangedContinuousSeries series = mRangedData.get(i);
            mLineChart.getLineConfig(series).setFilled(isFilled);
        }
    }));
    controls.add(VisualTest.createCheckbox("Stacked lines", itemEvent -> {
        boolean isStacked = itemEvent.getStateChange() == ItemEvent.SELECTED;
        for (int i = 0; i < mRangedData.size(); i += 2) {
            RangedContinuousSeries series = mRangedData.get(i);
            mLineChart.getLineConfig(series).setStacked(isStacked);
        }
    }));
    JButton tapButton = VisualTest.createButton("Generate Duration1 (Hold)");
    tapButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            // Starts a new test event and give it a max duration.
            long nowUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime());
            DefaultDurationData newEvent = new DefaultDurationData(UNSPECIFIED_DURATION);
            mDurationData1.add(nowUs, newEvent);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            // Wraps up the latest event by assigning it a duration value relative to where it was started.
            long nowUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime());
            ImmutableList<SeriesData<DefaultDurationData>> allEvents = mDurationData1.getAllData();
            SeriesData<DefaultDurationData> lastEvent = allEvents.get(allEvents.size() - 1);
            lastEvent.value.setDuration(nowUs - lastEvent.x);
        }
    });
    controls.add(tapButton);
    tapButton = VisualTest.createButton("Generate Duration2 (Hold)");
    tapButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            // Starts a new test event and give it a max duration.
            long nowUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime());
            DefaultDurationData newEvent = new DefaultDurationData(UNSPECIFIED_DURATION);
            mDurationData2.add(nowUs, newEvent);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            // Wraps up the latest event by assigning it a duration value relative to where it was started.
            long nowUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime());
            ImmutableList<SeriesData<DefaultDurationData>> allEvents = mDurationData2.getAllData();
            SeriesData<DefaultDurationData> lastEvent = allEvents.get(allEvents.size() - 1);
            lastEvent.value.setDuration(nowUs - lastEvent.x);
        }
    });
    controls.add(tapButton);
    controls.add(mClickDisplayLabel);
    controls.add(new Box.Filler(new Dimension(0, 0), new Dimension(300, Integer.MAX_VALUE), new Dimension(300, Integer.MAX_VALUE)));
}
Also used : ItemEvent(java.awt.event.ItemEvent) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) LineChart(com.android.tools.adtui.chart.linechart.LineChart) Animatable(com.android.tools.adtui.Animatable) AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange) ImmutableList(com.intellij.util.containers.ImmutableList) SelectionComponent(com.android.tools.adtui.SelectionComponent) GBC_FULL(com.android.tools.adtui.common.AdtUiUtils.GBC_FULL) AdtUiUtils(com.android.tools.adtui.common.AdtUiUtils) MouseEvent(java.awt.event.MouseEvent) UNSPECIFIED_DURATION(com.android.tools.adtui.model.DurationData.UNSPECIFIED_DURATION) com.android.tools.adtui.model(com.android.tools.adtui.model) ArrayList(java.util.ArrayList) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) AnimatedComponent(com.android.tools.adtui.AnimatedComponent) DurationDataRenderer(com.android.tools.adtui.chart.linechart.DurationDataRenderer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MouseAdapter(java.awt.event.MouseAdapter) OverlayComponent(com.android.tools.adtui.chart.linechart.OverlayComponent) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) javax.swing(javax.swing) ImmutableList(com.intellij.util.containers.ImmutableList) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

LineChart (com.android.tools.adtui.chart.linechart.LineChart)3 ImmutableList (com.intellij.util.containers.ImmutableList)3 java.awt (java.awt)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3 javax.swing (javax.swing)3 NotNull (org.jetbrains.annotations.NotNull)3 com.android.tools.adtui (com.android.tools.adtui)2 LineConfig (com.android.tools.adtui.chart.linechart.LineConfig)2 AdtUiUtils (com.android.tools.adtui.common.AdtUiUtils)2 LongDataSeries (com.android.tools.adtui.model.LongDataSeries)2 Range (com.android.tools.adtui.model.Range)2 RangedContinuousSeries (com.android.tools.adtui.model.RangedContinuousSeries)2 SeriesData (com.android.tools.adtui.model.SeriesData)2 JBPanel (com.intellij.ui.components.JBPanel)2 ItemEvent (java.awt.event.ItemEvent)2 MouseAdapter (java.awt.event.MouseAdapter)2 MouseEvent (java.awt.event.MouseEvent)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2