use of java.awt.event.ItemEvent in project JMRI by JMRI.
the class GuiLafConfigPane method doGraphicState.
void doGraphicState(JPanel panel) {
panel.setLayout(new FlowLayout());
graphicStateDisplay = new JCheckBox(ConfigBundle.getMessage("GUIGraphicTableState"));
graphicStateDisplay.setSelected(InstanceManager.getDefault(GuiLafPreferencesManager.class).isGraphicTableState());
graphicStateDisplay.addItemListener((ItemEvent e) -> {
InstanceManager.getDefault(GuiLafPreferencesManager.class).setGraphicTableState(graphicStateDisplay.isSelected());
});
panel.add(graphicStateDisplay);
}
use of java.awt.event.ItemEvent in project android by JetBrains.
the class StateChartVisualTest method populateUi.
@Override
protected void populateUi(@NotNull JPanel panel) {
panel.setLayout(new BorderLayout());
JLayeredPane timelinePane = createMockTimeline();
panel.add(timelinePane, BorderLayout.CENTER);
final JPanel controls = new JPanel();
LayoutManager manager = new BoxLayout(controls, BoxLayout.Y_AXIS);
controls.setLayout(manager);
panel.add(controls, BorderLayout.WEST);
final AtomicInteger networkVariance = new AtomicInteger(MockFruitState.values().length);
final AtomicInteger radioVariance = new AtomicInteger(MockStrengthState.values().length);
final AtomicInteger delay = new AtomicInteger(100);
//TODO Refactor this to come from the DataStore, in the mean time we will leak a thread every time reset is called on this test.
Thread updateDataThread = new Thread() {
@Override
public void run() {
super.run();
try {
// Store off the last state to simulate the same preprocessing the DataStore does on each series.
TIntArrayList lastNetworkData = new TIntArrayList();
TIntArrayList lastRadioVariance = new TIntArrayList();
while (true) {
long nowUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime());
int v = networkVariance.get();
for (int i = 0; i < mNetworkDataEntries.size(); i++) {
DefaultDataSeries<MockFruitState> series = mNetworkDataEntries.get(i);
if (Math.random() > 0.5f) {
int index = (int) (Math.random() * v);
if (lastNetworkData.size() <= i) {
lastNetworkData.add(-1);
}
if (lastNetworkData.get(i) != index) {
series.add(nowUs, MockFruitState.values()[index]);
lastNetworkData.set(i, index);
}
}
}
v = radioVariance.get();
for (int i = 0; i < mRadioDataEntries.size(); i++) {
DefaultDataSeries<MockStrengthState> series = mRadioDataEntries.get(i);
if (Math.random() > 0.5f) {
int index = (int) (Math.random() * v);
if (lastRadioVariance.size() <= i) {
lastRadioVariance.add(-1);
}
if (lastRadioVariance.get(i) != index) {
series.add(nowUs, MockStrengthState.values()[index]);
lastRadioVariance.set(i, index);
}
}
}
Thread.sleep(delay.get());
}
} catch (InterruptedException e) {
}
}
};
updateDataThread.start();
controls.add(VisualTest.createVariableSlider("ArcWidth", 0, 100, new VisualTests.Value() {
@Override
public void set(int v) {
mNetworkStatusChart.setArcWidth(v / 100f);
mRadioStateChart.setArcWidth(v / 100f);
}
@Override
public int get() {
// unused
return -1;
}
}));
controls.add(VisualTest.createVariableSlider("ArcHeight", 0, 100, new VisualTests.Value() {
@Override
public void set(int v) {
mNetworkStatusChart.setArcHeight(v / 100f);
mRadioStateChart.setArcHeight(v / 100f);
}
@Override
public int get() {
// unused
return -1;
}
}));
controls.add(VisualTest.createVariableSlider("Gap", 0, 100, new VisualTests.Value() {
@Override
public void set(int v) {
mNetworkStatusChart.setHeightGap(v / 100f);
mRadioStateChart.setHeightGap(v / 100f);
}
@Override
public int get() {
// unused
return -1;
}
}));
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("Fruit Variance", 1, MockFruitState.values().length, new VisualTests.Value() {
@Override
public void set(int v) {
networkVariance.set(v);
}
@Override
public int get() {
return networkVariance.get();
}
}));
controls.add(VisualTest.createVariableSlider("Strength Variance", 1, MockStrengthState.values().length, new VisualTests.Value() {
@Override
public void set(int v) {
radioVariance.set(v);
}
@Override
public int get() {
return radioVariance.get();
}
}));
controls.add(VisualTest.createButton("Add Fruit Series", e -> {
DefaultDataSeries<MockFruitState> networkSeries = new DefaultDataSeries<>();
RangedSeries<MockFruitState> networkData = new RangedSeries(mTimeGlobalRangeUs, networkSeries);
mNetworkStatusChart.addSeries(networkData);
mNetworkDataEntries.add(networkSeries);
}));
controls.add(VisualTest.createButton("Add Strength Series", e -> {
DefaultDataSeries<MockStrengthState> radioSeries = new DefaultDataSeries<>();
RangedSeries<MockStrengthState> radioData = new RangedSeries(mTimeGlobalRangeUs, radioSeries);
mRadioStateChart.addSeries(radioData);
mRadioDataEntries.add(radioSeries);
}));
controls.add(VisualTest.createCheckbox("Shift xRange Min", itemEvent -> mAnimatedTimeRange.setShift(itemEvent.getStateChange() == ItemEvent.SELECTED)));
controls.add(VisualTest.createCheckbox("Text Mode", itemEvent -> {
StateChart.RenderMode mode = itemEvent.getStateChange() == ItemEvent.SELECTED ? StateChart.RenderMode.TEXT : StateChart.RenderMode.BAR;
mNetworkStatusChart.setRenderMode(mode);
mRadioStateChart.setRenderMode(mode);
}));
controls.add(new Box.Filler(new Dimension(0, 0), new Dimension(300, Integer.MAX_VALUE), new Dimension(300, Integer.MAX_VALUE)));
}
use of java.awt.event.ItemEvent in project android by JetBrains.
the class SunburstVisualTest method populateUi.
@Override
protected void populateUi(@NotNull JPanel panel) {
JPanel controls = VisualTest.createControlledPane(panel, mSunburst);
final JLabel info = new JLabel("<No information yet>");
panel.add(info, BorderLayout.SOUTH);
controls.add(VisualTest.createVariableSlider("Gap", 0, 200, new VisualTests.Value() {
@Override
public void set(int v) {
mSunburst.setGap(v);
}
@Override
public int get() {
return (int) mSunburst.getGap();
}
}));
final JPanel sizeSlider = VisualTest.createVariableSlider("Size", 0, 200, new VisualTests.Value() {
@Override
public void set(int v) {
mSunburst.setSliceWidth(v);
}
@Override
public int get() {
return (int) mSunburst.getSliceWidth();
}
});
controls.add(sizeSlider);
controls.add(VisualTest.createVariableSlider("Angle", 0, 360, new VisualTests.Value() {
@Override
public void set(int v) {
mSunburst.setAngle(v);
}
@Override
public int get() {
return (int) mSunburst.getAngle();
}
}));
controls.add(VisualTest.createVariableSlider("Start", 0, 360, new VisualTests.Value() {
@Override
public void set(int v) {
mSunburst.setStart(v);
}
@Override
public int get() {
return (int) mSunburst.getStart();
}
}));
controls.add(VisualTest.createVariableSlider("Fixed", 1, 100, new VisualTests.Value() {
@Override
public void set(int v) {
mSunburst.setFixed(v);
}
@Override
public int get() {
return (int) mSunburst.getFixed();
}
}));
controls.add(VisualTest.createVariableSlider("Separator", 0, 100, new VisualTests.Value() {
@Override
public void set(int v) {
mSunburst.setSeparator(v);
}
@Override
public int get() {
return (int) mSunburst.getSeparator();
}
}));
controls.add(VisualTest.createButton("Generate", new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
generateLayoutData((DataNode) mSunburst.getData(), 5);
}
}));
controls.add(VisualTest.createButton("Tree A", new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
DataNode g = new DataNode();
g.addDataNode(createTree(1));
g.addDataNode(createValue());
g.addDataNode(createTree(1));
g.addDataNode(createValue());
g.addDataNode(createTree(0));
mSunburst.setData(g);
}
}));
controls.add(VisualTest.createButton("Tree B", new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
DataNode g = new DataNode();
g.addDataNode(createValue());
g.addDataNode(createValue());
g.addDataNode(createTree(0));
mSunburst.setData(g);
}
}));
controls.add(VisualTest.createButton("Value", new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
DataNode g = new DataNode();
g.addDataNode(new DataNode(1, (int) (Math.random() * 50)));
mSunburst.setData(g);
}
}));
controls.add(VisualTest.createCheckbox("Auto size", new ItemListener() {
@Override
public void itemStateChanged(ItemEvent itemEvent) {
final boolean enableAutoSize = itemEvent.getStateChange() == ItemEvent.SELECTED;
mSunburst.setAutoSize(enableAutoSize);
// If auto size is enabled, size shouldn't be controlled by slider
// sizeSlider is a JPanel and its first child is a JSlider
Accessible sliderAccessible = SwingUtilities.getAccessibleChild(sizeSlider, 0);
if (sliderAccessible instanceof JSlider) {
JSlider slider = (JSlider) sliderAccessible;
slider.setEnabled(!enableAutoSize);
// If disabling auto size, set slider width to current slice width
if (!enableAutoSize) {
slider.setValue((int) mSunburst.getSliceWidth());
}
}
}
}));
controls.add(new Box.Filler(new Dimension(0, 0), new Dimension(300, Integer.MAX_VALUE), new Dimension(300, Integer.MAX_VALUE)));
mSunburst.addSelectionListener(new SunburstChart.SliceSelectionListener() {
@Override
public void valueChanged(SunburstChart.SliceSelectionEvent e) {
ValuedTreeNode node = e.getNode();
info.setText(node == null ? "<No selection>" : String.format("Value %d Count %d", node.getValue(), node.getCount()));
}
});
}
use of java.awt.event.ItemEvent 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 java.awt.event.ItemEvent in project knime-core by knime.
the class DialogComponentCalendar method createDatePanel.
private JPanel createDatePanel() {
m_date = new DialogComponentDate((SettingsModelCalendar) getModel(), "Date:");
// add the check box on top of the horizontal date panel
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
Box useDateBox = Box.createHorizontalBox();
m_useDateUI = new JCheckBox("Use date", false);
m_useDateUI.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
boolean enable = m_useDateUI.isSelected();
// only dis-/enable UI since they all share one model
m_date.setEnabledComponents(enable);
((SettingsModelCalendar) getModel()).setUseDate(enable);
}
});
useDateBox.add(m_useDateUI);
useDateBox.add(Box.createHorizontalGlue());
panel.add(useDateBox);
panel.add(m_date.getComponentPanel());
return panel;
}
Aggregations