Search in sources :

Example 56 with ItemEvent

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);
}
Also used : JCheckBox(javax.swing.JCheckBox) ItemEvent(java.awt.event.ItemEvent) GuiLafPreferencesManager(apps.gui.GuiLafPreferencesManager) FlowLayout(java.awt.FlowLayout)

Example 57 with ItemEvent

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)));
}
Also used : ItemEvent(java.awt.event.ItemEvent) Range(com.android.tools.adtui.model.Range) Arrays(java.util.Arrays) AxisComponent(com.android.tools.adtui.AxisComponent) DefaultDataSeries(com.android.tools.adtui.model.DefaultDataSeries) StateChart(com.android.tools.adtui.chart.StateChart) EnumMap(java.util.EnumMap) RangedSeries(com.android.tools.adtui.model.RangedSeries) Animatable(com.android.tools.adtui.Animatable) AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange) ComponentEvent(java.awt.event.ComponentEvent) ArrayList(java.util.ArrayList) java.awt(java.awt) ComponentAdapter(java.awt.event.ComponentAdapter) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) AnimatedComponent(com.android.tools.adtui.AnimatedComponent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NotNull(org.jetbrains.annotations.NotNull) TIntArrayList(gnu.trove.TIntArrayList) JBColor(com.intellij.ui.JBColor) javax.swing(javax.swing) RangedSeries(com.android.tools.adtui.model.RangedSeries) TIntArrayList(gnu.trove.TIntArrayList) DefaultDataSeries(com.android.tools.adtui.model.DefaultDataSeries) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 58 with ItemEvent

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()));
        }
    });
}
Also used : ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) SunburstChart(com.android.tools.adtui.chart.SunburstChart) ActionListener(java.awt.event.ActionListener) ValuedTreeNode(com.android.tools.adtui.ValuedTreeNode) ItemListener(java.awt.event.ItemListener) Accessible(javax.accessibility.Accessible)

Example 59 with ItemEvent

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)));
}
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 60 with ItemEvent

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;
}
Also used : JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) BoxLayout(javax.swing.BoxLayout) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) ItemListener(java.awt.event.ItemListener)

Aggregations

ItemEvent (java.awt.event.ItemEvent)339 ItemListener (java.awt.event.ItemListener)313 ActionEvent (java.awt.event.ActionEvent)120 ActionListener (java.awt.event.ActionListener)110 JPanel (javax.swing.JPanel)106 JLabel (javax.swing.JLabel)84 JCheckBox (javax.swing.JCheckBox)72 JComboBox (javax.swing.JComboBox)65 Dimension (java.awt.Dimension)59 JButton (javax.swing.JButton)53 BorderLayout (java.awt.BorderLayout)48 JTextField (javax.swing.JTextField)46 ButtonGroup (javax.swing.ButtonGroup)35 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)33 GridLayout (java.awt.GridLayout)30 ChangeEvent (javax.swing.event.ChangeEvent)30 GridBagConstraints (java.awt.GridBagConstraints)29 JMenu (javax.swing.JMenu)29 ChangeListener (javax.swing.event.ChangeListener)29 GridBagLayout (java.awt.GridBagLayout)28