Example usage for javax.swing JComboBox addActionListener

List of usage examples for javax.swing JComboBox addActionListener

Introduction

In this page you can find the example usage for javax.swing JComboBox addActionListener.

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener.

Usage

From source file:UNUSED.JUNGsamples.ShowLayouts.java

private static JPanel getGraphPanel() {
    g_array = (Graph<? extends Object, ? extends Object>[]) new Graph<?, ?>[graph_names.length];

    Factory<Graph<Integer, Number>> graphFactory = new Factory<Graph<Integer, Number>>() {
        public Graph<Integer, Number> create() {
            return new SparseMultigraph<Integer, Number>();
        }/*from  ww  w.j a v a 2 s.com*/
    };

    Factory<Integer> vertexFactory = new Factory<Integer>() {
        int count;

        public Integer create() {
            return count++;
        }
    };
    Factory<Number> edgeFactory = new Factory<Number>() {
        int count;

        public Number create() {
            return count++;
        }
    };

    g_array[0] = TestGraphs.createTestGraph(false);
    g_array[1] = MixedRandomGraphGenerator.generateMixedRandomGraph(graphFactory, vertexFactory, edgeFactory,
            new HashMap<Number, Number>(), 20, true, new HashSet<Integer>());
    g_array[2] = TestGraphs.getDemoGraph();
    g_array[3] = TestGraphs.createDirectedAcyclicGraph(6, 40, 0.3);
    g_array[4] = TestGraphs.getOneComponentGraph();
    g_array[5] = TestGraphs.createChainPlusIsolates(60, 5);
    g_array[6] = TestGraphs.createChainPlusIsolates(0, 40);

    Graph<? extends Object, ? extends Object> g = g_array[4]; // initial graph

    final VisualizationViewer<Integer, Number> vv = new VisualizationViewer<Integer, Number>(new FRLayout(g));

    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.red, Color.yellow));

    final DefaultModalGraphMouse<Integer, Number> graphMouse = new DefaultModalGraphMouse<Integer, Number>();
    vv.setGraphMouse(graphMouse);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });
    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Layout<Integer, Number> layout = vv.getGraphLayout();
            layout.initialize();
            Relaxer relaxer = vv.getModel().getRelaxer();
            if (relaxer != null) {
                //            if(layout instanceof IterativeContext) {
                relaxer.stop();
                relaxer.prerelax();
                relaxer.relax();
            }
        }
    });

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(((DefaultModalGraphMouse<Integer, Number>) vv.getGraphMouse()).getModeListener());

    JPanel jp = new JPanel();
    jp.setBackground(Color.WHITE);
    jp.setLayout(new BorderLayout());
    jp.add(vv, BorderLayout.CENTER);
    Class[] combos = getCombos();
    final JComboBox jcb = new JComboBox(combos);
    // use a renderer to shorten the layout name presentation
    jcb.setRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            String valueString = value.toString();
            valueString = valueString.substring(valueString.lastIndexOf('.') + 1);
            return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus);
        }
    });
    jcb.addActionListener(new LayoutChooser(jcb, vv));
    jcb.setSelectedItem(FRLayout.class);

    JPanel control_panel = new JPanel(new GridLayout(2, 1));
    JPanel topControls = new JPanel();
    JPanel bottomControls = new JPanel();
    control_panel.add(topControls);
    control_panel.add(bottomControls);
    jp.add(control_panel, BorderLayout.NORTH);

    final JComboBox graph_chooser = new JComboBox(graph_names);

    graph_chooser.addActionListener(new GraphChooser(jcb));

    topControls.add(jcb);
    topControls.add(graph_chooser);
    bottomControls.add(plus);
    bottomControls.add(minus);
    bottomControls.add(modeBox);
    bottomControls.add(reset);
    return jp;
}

From source file:Widgets.Simulation.java

protected JPanel trajectoryTabb() {
    JPanel trajectoryPanel = new JPanel();

    //judge if converged
    //final JLabel convergePanel = new JLabel();   
    plot.removeAllPlots();/* www. j  av  a2  s  .  c  om*/

    plot.setAxisLabel(0, "t");
    plot.setAxisLabel(1, "Expression Level");
    plot.setPreferredSize(new Dimension(440, 390));

    //ArrayList<DoubleMatrix2D> timeSeries_ = grn.getTimeSeries();
    //ArrayList<DoubleMatrix1D> timeScale_ = grn.getTimeScale();

    //display multiple time series
    //combobox
    //generate time series List
    String[] timeSeriesList = new String[grn.getTimeSeries().size()];

    for (int i = 0; i < grn.getTimeSeries().size(); i++)
        timeSeriesList[i] = Integer.toString(i);

    JLabel selectPanelName = new JLabel("Select trajectory: ");
    JPanel selectPanel = new JPanel();
    //selectPanel.setPreferredSize(new Dimension(1000,10));
    final JComboBox<String> combo = new JComboBox<String>(timeSeriesList);

    //view window
    final JPanel trajectoryViewPanel = new JPanel();
    //trajectoryViewPanel.setPreferredSize(new Dimension(990,500));

    plot.setPreferredSize(new Dimension(440, 350));
    double[] t = grn.getTimeScale().get(0).toArray();
    for (int k = 0; k < grn.getTimeSeries().get(0).columns(); k++)
        plot.addLinePlot(grn.getNode(k).getLabel(), t, grn.getTimeSeries().get(0).viewColumn(k).toArray());
    plot.addLegend("SOUTH");
    plot.repaint();

    //combobox action             
    combo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int row = combo.getSelectedIndex();

            plot.removeAllPlots();

            double[] t = grn.getTimeScale().get(row).toArray();
            for (int k = 0; k < grn.getTimeSeries().get(row).columns(); k++) {
                plot.addLinePlot(grn.getNode(k).getLabel(), t,
                        grn.getTimeSeries().get(row).viewColumn(k).toArray());
            }

            trajectoryViewPanel.repaint();
            trajectoryViewPanel.setVisible(true);
        }
    });

    selectPanel.setLayout(new BoxLayout(selectPanel, BoxLayout.X_AXIS));
    selectPanel.add(selectPanelName);
    selectPanel.add(combo);
    trajectoryViewPanel.add(plot);

    //set layout
    trajectoryPanel.setLayout(new GridBagLayout());
    NetLand.addComponent(trajectoryPanel, trajectoryViewPanel, 0, 0, 1, 1, GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH, 0, 1);
    NetLand.addComponent(trajectoryPanel, selectPanel, 0, 1, 1, 1, GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH, 1, 0);
    //NetLand.addComponent(trajectoryPanel, convergePanel, 0, 2, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, 1, 0);

    return trajectoryPanel;
}

From source file:wigraph.ShortestPathRelation.java

private Component getSelectionBox(final boolean from) {

    Set<String> s = new TreeSet<String>();

    for (String v : mGraph.getVertices()) {
        s.add(v);/*from  w ww .j  a v a2  s .com*/
    }
    final JComboBox choices = new JComboBox(s.toArray());
    choices.setSelectedIndex(-1);
    choices.setBackground(Color.WHITE);
    choices.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String v = (String) choices.getSelectedItem();

            if (from) {
                mFrom = v;
            } else {
                mTo = v;
            }
            drawShortest();
            repaint();
        }
    });
    return choices;
}