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