use of com.android.tools.adtui.model.DurationData.UNSPECIFIED_DURATION 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