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