Example usage for javax.swing JComboBox setRenderer

List of usage examples for javax.swing JComboBox setRenderer

Introduction

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

Prototype

@BeanProperty(expert = true, description = "The renderer that paints the item selected in the list.")
public void setRenderer(ListCellRenderer<? super E> aRenderer) 

Source Link

Document

Sets the renderer that paints the list items and the item selected from the list in the JComboBox field.

Usage

From source file:com.declarativa.interprolog.gui.ListenerWindow.java

private void UpdategraphComponents2(Forest<String, Integer> graph) throws IOException {
    jLayeredPane5.removeAll();/*from  w  w w.j  a  v  a  2 s  . co  m*/

    /*     
             
     List<String> heads = new ArrayList<>();
     List<String> subgrph = new ArrayList<>();
     ArgBuildManager manag = new ArgBuildManager();
     Forest<String, Integer> graphGUI = new DelegateForest<>();
            
            
     graphGUI = manag.getGraphJung();
     */
    Forest<String, Integer> graphGUI = new DelegateForest<>();

    graphGUI = graph;

    System.out.println("\t \t NUM UF VERT:" + graphGUI.getVertexCount());

    //ObservableGraph g = new ObservableGraph(new BalloonLayoutDemo().createTree(forest));
    ObservableGraph g = new ObservableGraph(graphGUI);

    //Layout layout = new BalloonLayout(forest);
    Layout layout = new BalloonLayout(graphGUI);
    //Layout layout = new TreeLayout(forest, 70, 70);

    final BaseJungScene scene2 = new SceneImpl(g, layout);

    jLayeredPane5.setLayout(new BorderLayout());
    //jf.setLayout(new BorderLayout());

    jLayeredPane5.add(new JScrollPane(scene2.createView()), BorderLayout.CENTER);
    //jf.add(new JScrollPane(scene2.createView()), BorderLayout.CENTER);

    JToolBar bar = new JToolBar();
    bar.setMargin(new Insets(5, 5, 5, 5));
    bar.setLayout(new FlowLayout(5));
    DefaultComboBoxModel<Layout> mdl = new DefaultComboBoxModel<>();
    mdl.addElement(new KKLayout(g));
    mdl.addElement(layout);
    mdl.addElement(new BalloonLayout(forest));
    mdl.addElement(new RadialTreeLayout(forest));
    mdl.addElement(new CircleLayout(g));
    mdl.addElement(new FRLayout(g));
    mdl.addElement(new FRLayout2(g));
    mdl.addElement(new ISOMLayout(g));
    mdl.addElement(new edu.uci.ics.jung.algorithms.layout.SpringLayout(g));
    mdl.addElement(new SpringLayout2(g));
    mdl.addElement(new DAGLayout(g));
    mdl.addElement(new XLayout(g));
    mdl.setSelectedItem(layout);
    final JCheckBox checkbox = new JCheckBox("Animate iterative layouts");

    scene2.setLayoutAnimationFramesPerSecond(48);

    final JComboBox<Layout> layouts = new JComboBox(mdl);
    layouts.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> jlist, Object o, int i, boolean bln,
                boolean bln1) {
            o = o.getClass().getSimpleName();
            return super.getListCellRendererComponent(jlist, o, i, bln, bln1); //To change body of generated methods, choose Tools | Templates.
        }
    });
    bar.add(new JLabel(" Layout Type"));
    bar.add(layouts);
    layouts.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            Layout layout = (Layout) layouts.getSelectedItem();
            // These two layouts implement IterativeContext, but they do
            // not evolve toward anything, they just randomly rearrange
            // themselves.  So disable animation for these.
            if (layout instanceof ISOMLayout || layout instanceof DAGLayout) {
                checkbox.setSelected(false);
            }
            scene2.setGraphLayout(layout, true);
        }
    });

    bar.add(new JLabel(" Connection Shape"));
    DefaultComboBoxModel<Transformer<Context<Graph<String, Number>, Number>, Shape>> shapes = new DefaultComboBoxModel<>();
    shapes.addElement(new EdgeShape.QuadCurve<String, Number>());
    shapes.addElement(new EdgeShape.BentLine<String, Number>());
    shapes.addElement(new EdgeShape.CubicCurve<String, Number>());
    shapes.addElement(new EdgeShape.Line<String, Number>());
    shapes.addElement(new EdgeShape.Box<String, Number>());
    shapes.addElement(new EdgeShape.Orthogonal<String, Number>());
    shapes.addElement(new EdgeShape.Wedge<String, Number>(10));

    final JComboBox<Transformer<Context<Graph<String, Number>, Number>, Shape>> shapesBox = new JComboBox<>(
            shapes);
    shapesBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            Transformer<Context<Graph<String, Number>, Number>, Shape> xform = (Transformer<Context<Graph<String, Number>, Number>, Shape>) shapesBox
                    .getSelectedItem();
            scene2.setConnectionEdgeShape(xform);
        }
    });
    shapesBox.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> jlist, Object o, int i, boolean bln,
                boolean bln1) {
            o = o.getClass().getSimpleName();
            return super.getListCellRendererComponent(jlist, o, i, bln, bln1); //To change body of generated methods, choose Tools | Templates.
        }
    });
    shapesBox.setSelectedItem(new EdgeShape.QuadCurve<>());
    bar.add(shapesBox);

    //jf.add(bar, BorderLayout.NORTH);
    bar.add(new ListenerWindow.MinSizePanel(scene2.createSatelliteView()));
    bar.setFloatable(false);
    bar.setRollover(true);

    final JLabel selectionLabel = new JLabel("<html>&nbsp;</html>");
    System.out.println("LOOKUP IS " + scene2.getLookup());
    Lookup.Result<String> selectedNodes = scene2.getLookup().lookupResult(String.class);
    LookupListener listener = new LookupListener() {
        @Override
        public void resultChanged(LookupEvent le) {
            System.out.println("RES CHANGED");
            Lookup.Result<String> res = (Lookup.Result<String>) le.getSource();
            StringBuilder sb = new StringBuilder("<html>");
            List<String> l = new ArrayList<>(res.allInstances());
            Collections.sort(l);
            for (String s : l) {
                if (sb.length() != 0) {
                    sb.append(", ");
                }
                sb.append(s);
            }
            sb.append("</html>");
            selectionLabel.setText(sb.toString());
            System.out.println("LOOKUP EVENT " + sb);
        }
    };
    selectedNodes.addLookupListener(listener);
    selectedNodes.allInstances();

    bar.add(selectionLabel);

    checkbox.setSelected(true);
    checkbox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            scene2.setAnimateIterativeLayouts(checkbox.isSelected());
        }
    });
    bar.add(checkbox);
    jLayeredPane6.setLayout(new BorderLayout());

    jLayeredPane6.add(bar);
    //        jf.setSize(jf.getGraphicsConfiguration().getBounds().width - 120, 700);
    //        jf.setSize(new Dimension(1280, 720));
    //        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    // this.repaint();
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent we) {
            scene2.relayout(true);
            scene2.validate();
        }
    });

}

From source file:com.declarativa.interprolog.gui.ListenerWindow.java

private void graphComponents() throws IOException {

    Forest<String, Integer> forest = new DelegateForest<>();
    Forest<String, Integer> forest2 = new DelegateForest<>();
    Forest<String, Integer> forest3 = new DelegateForest<>();
    //ObservableGraph g = new ObservableGraph(new BalloonLayoutDemo().createTree(forest));
    ObservableGraph g = new ObservableGraph(new GraphGenerator().createTree(forest));
    ObservableGraph g2 = new ObservableGraph(new GraphGenerator().createTree2(forest2));
    ObservableGraph g3 = new ObservableGraph(new GraphGenerator().createTree3(forest3));

    //Layout layout = new BalloonLayout(forest);
    Layout layout = new BalloonLayout(forest);
    Layout layout2 = new BalloonLayout(forest2);
    Layout layout3 = new TreeLayout(forest3, 70, 70);

    final BaseJungScene scene = new SceneImpl(g, layout);
    final BaseJungScene scene2 = new SceneImpl(g2, layout2);
    final BaseJungScene scene3 = new SceneImpl(g3, layout3);

    jLayeredPane1.setLayout(new BorderLayout());
    //jf.setLayout(new BorderLayout());

    jLayeredPane5.setLayout(new BorderLayout());
    jLayeredPane8.setLayout(new BorderLayout());

    jLayeredPane1.add(new JScrollPane(scene.createView()), BorderLayout.CENTER);
    //jf.add(new JScrollPane(scene2.createView()), BorderLayout.CENTER);

    jLayeredPane5.add(new JScrollPane(scene2.createView()), BorderLayout.CENTER);
    jLayeredPane8.add(new JScrollPane(scene3.createView()), BorderLayout.CENTER);

    JToolBar bar = new JToolBar();
    bar.setMargin(new Insets(5, 5, 5, 5));
    bar.setLayout(new FlowLayout(5));
    DefaultComboBoxModel<Layout> mdl = new DefaultComboBoxModel<>();
    mdl.addElement(new KKLayout(g));
    mdl.addElement(layout);/*from   w  w w. j  av  a 2  s  .c om*/
    mdl.addElement(new BalloonLayout(forest));
    mdl.addElement(new RadialTreeLayout(forest));
    mdl.addElement(new CircleLayout(g));
    mdl.addElement(new FRLayout(g));
    mdl.addElement(new FRLayout2(g));
    mdl.addElement(new ISOMLayout(g));
    mdl.addElement(new edu.uci.ics.jung.algorithms.layout.SpringLayout(g));
    mdl.addElement(new SpringLayout2(g));
    mdl.addElement(new DAGLayout(g));
    mdl.addElement(new XLayout(g));
    mdl.setSelectedItem(layout);
    final JCheckBox checkbox = new JCheckBox("Animate iterative layouts");

    scene.setLayoutAnimationFramesPerSecond(48);
    scene2.setLayoutAnimationFramesPerSecond(48);
    scene3.setLayoutAnimationFramesPerSecond(48);

    final JComboBox<Layout> layouts = new JComboBox(mdl);
    layouts.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> jlist, Object o, int i, boolean bln,
                boolean bln1) {
            o = o.getClass().getSimpleName();
            return super.getListCellRendererComponent(jlist, o, i, bln, bln1); //To change body of generated methods, choose Tools | Templates.
        }
    });
    bar.add(new JLabel(" Layout Type"));
    bar.add(layouts);
    layouts.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            Layout layout = (Layout) layouts.getSelectedItem();
            // These two layouts implement IterativeContext, but they do
            // not evolve toward anything, they just randomly rearrange
            // themselves.  So disable animation for these.
            if (layout instanceof ISOMLayout || layout instanceof DAGLayout) {
                checkbox.setSelected(false);
            }
            scene.setGraphLayout(layout, true);
        }
    });

    bar.add(new JLabel(" Connection Shape"));
    DefaultComboBoxModel<Transformer<Context<Graph<String, Number>, Number>, Shape>> shapes = new DefaultComboBoxModel<>();
    shapes.addElement(new EdgeShape.QuadCurve<String, Number>());
    shapes.addElement(new EdgeShape.BentLine<String, Number>());
    shapes.addElement(new EdgeShape.CubicCurve<String, Number>());
    shapes.addElement(new EdgeShape.Line<String, Number>());
    shapes.addElement(new EdgeShape.Box<String, Number>());
    shapes.addElement(new EdgeShape.Orthogonal<String, Number>());
    shapes.addElement(new EdgeShape.Wedge<String, Number>(10));

    final JComboBox<Transformer<Context<Graph<String, Number>, Number>, Shape>> shapesBox = new JComboBox<>(
            shapes);
    shapesBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            Transformer<Context<Graph<String, Number>, Number>, Shape> xform = (Transformer<Context<Graph<String, Number>, Number>, Shape>) shapesBox
                    .getSelectedItem();
            scene.setConnectionEdgeShape(xform);
        }
    });
    shapesBox.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> jlist, Object o, int i, boolean bln,
                boolean bln1) {
            o = o.getClass().getSimpleName();
            return super.getListCellRendererComponent(jlist, o, i, bln, bln1); //To change body of generated methods, choose Tools | Templates.
        }
    });
    shapesBox.setSelectedItem(new EdgeShape.QuadCurve<>());
    bar.add(shapesBox);

    //jf.add(bar, BorderLayout.NORTH);
    bar.add(new ListenerWindow.MinSizePanel(scene.createSatelliteView()));
    bar.setFloatable(false);
    bar.setRollover(true);

    final JLabel selectionLabel = new JLabel("<html>&nbsp;</html>");
    System.out.println("LOOKUP IS " + scene.getLookup());
    Lookup.Result<String> selectedNodes = scene.getLookup().lookupResult(String.class);
    LookupListener listener = new LookupListener() {
        @Override
        public void resultChanged(LookupEvent le) {
            System.out.println("RES CHANGED");
            Lookup.Result<String> res = (Lookup.Result<String>) le.getSource();
            StringBuilder sb = new StringBuilder("<html>");
            List<String> l = new ArrayList<>(res.allInstances());
            Collections.sort(l);
            for (String s : l) {
                if (sb.length() != 0) {
                    sb.append(", ");
                }
                sb.append(s);
            }
            sb.append("</html>");
            selectionLabel.setText(sb.toString());
            System.out.println("LOOKUP EVENT " + sb);
        }
    };
    selectedNodes.addLookupListener(listener);
    selectedNodes.allInstances();

    bar.add(selectionLabel);

    checkbox.setSelected(true);
    checkbox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            scene.setAnimateIterativeLayouts(checkbox.isSelected());
        }
    });
    bar.add(checkbox);
    jLayeredPane3.setLayout(new BorderLayout());

    jLayeredPane6.setLayout(new BorderLayout());

    jLayeredPane3.add(bar);

    jLayeredPane6.add(bar);

    //        jf.setSize(jf.getGraphicsConfiguration().getBounds().width - 120, 700);
    //        jf.setSize(new Dimension(1280, 720));
    //        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent we) {
            scene.relayout(true);
            scene.validate();
            scene2.relayout(true);
            scene2.validate();
            scene3.relayout(true);
            scene3.validate();
        }
    });

}

From source file:op.controlling.PnlControlling.java

private JPanel createContentPanel4Nursing() {
    JPanel pnlContent = new JPanel(new VerticalLayout());

    /***/*from   ww  w .  j a  va2s.  c o  m*/
     *     __        __                    _
     *     \ \      / /__  _   _ _ __   __| |___
     *      \ \ /\ / / _ \| | | | '_ \ / _` / __|
     *       \ V  V / (_) | |_| | | | | (_| \__ \
     *        \_/\_/ \___/ \__,_|_| |_|\__,_|___/
     *
     */
    JPanel pnlWounds = new JPanel(new BorderLayout());
    final JButton btnWounds = GUITools.createHyperlinkButton("opde.controlling.nursing.wounds", null, null);
    int woundsMonthsBack;
    try {
        woundsMonthsBack = Integer.parseInt(OPDE.getProps().getProperty("opde.controlling::woundsMonthsBack"));
    } catch (NumberFormatException nfe) {
        woundsMonthsBack = 7;
    }
    final JTextField txtWoundsMonthsBack = GUITools.createIntegerTextField(1, 12, woundsMonthsBack);
    txtWoundsMonthsBack.setToolTipText(SYSTools.xx("misc.msg.monthsback"));

    btnWounds.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            OPDE.getMainframe().setBlocked(true);
            SwingWorker worker = new SwingWorker() {
                @Override
                protected Object doInBackground() throws Exception {
                    SYSPropsTools.storeProp("opde.controlling::woundsMonthsBack", txtWoundsMonthsBack.getText(),
                            OPDE.getLogin().getUser());
                    SYSFilesTools.print(
                            getWounds(Integer.parseInt(txtWoundsMonthsBack.getText()), progressClosure), false);
                    return null;
                }

                @Override
                protected void done() {
                    OPDE.getDisplayManager().setProgressBarMessage(null);
                    OPDE.getMainframe().setBlocked(false);
                }
            };
            worker.execute();
        }
    });
    pnlWounds.add(btnWounds, BorderLayout.WEST);
    pnlWounds.add(txtWoundsMonthsBack, BorderLayout.EAST);
    pnlContent.add(pnlWounds);

    /***
     *      ____             _       _   _____ _
     *     / ___|  ___   ___(_) __ _| | |_   _(_)_ __ ___   ___  ___
     *     \___ \ / _ \ / __| |/ _` | |   | | | | '_ ` _ \ / _ \/ __|
     *      ___) | (_) | (__| | (_| | |   | | | | | | | | |  __/\__ \
     *     |____/ \___/ \___|_|\__,_|_|   |_| |_|_| |_| |_|\___||___/
     *
     */
    JPanel pblSocialTimes = new JPanel(new BorderLayout());
    final JButton btnSocialTimes = GUITools.createHyperlinkButton("opde.controlling.nursing.social", null,
            null);
    final JComboBox cmbSocialTimes = new JComboBox(
            SYSCalendar.createMonthList(new LocalDate().minusYears(1), new LocalDate()));
    btnSocialTimes.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            OPDE.getMainframe().setBlocked(true);
            SwingWorker worker = new SwingWorker() {
                @Override
                protected Object doInBackground() throws Exception {
                    LocalDate month = (LocalDate) cmbSocialTimes.getSelectedItem();
                    SYSFilesTools.print(NReportTools.getTimes4SocialReports(month, progressClosure), false);
                    return null;
                }

                @Override
                protected void done() {
                    OPDE.getDisplayManager().setProgressBarMessage(null);
                    OPDE.getMainframe().setBlocked(false);
                }
            };
            worker.execute();
        }
    });
    cmbSocialTimes.setRenderer(new ListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            return new DefaultListCellRenderer().getListCellRendererComponent(list,
                    monthFormatter.format(((LocalDate) value).toDate()), index, isSelected, cellHasFocus);
        }
    });
    cmbSocialTimes.setSelectedIndex(cmbSocialTimes.getItemCount() - 2);
    pblSocialTimes.add(btnSocialTimes, BorderLayout.WEST);
    pblSocialTimes.add(cmbSocialTimes, BorderLayout.EAST);
    pnlContent.add(pblSocialTimes);

    return pnlContent;
}

From source file:op.controlling.PnlControlling.java

private JPanel createContentPanel4Nutrition() {
    JPanel pnlContent = new JPanel(new VerticalLayout());

    /***/*from   w ww. j  a va 2 s. c o m*/
     *      _ _             _     _   _           _
     *     | (_) __ _ _   _(_) __| | | |__   __ _| | __ _ _ __   ___ ___
     *     | | |/ _` | | | | |/ _` | | '_ \ / _` | |/ _` | '_ \ / __/ _ \
     *     | | | (_| | |_| | | (_| | | |_) | (_| | | (_| | | | | (_|  __/
     *     |_|_|\__, |\__,_|_|\__,_| |_.__/ \__,_|_|\__,_|_| |_|\___\___|
     *             |_|
     */
    JPanel pnlLiquidBalance = new JPanel(new BorderLayout());
    final JButton btnLiquidBalance = GUITools.createHyperlinkButton("opde.controlling.nutrition.liquidbalance",
            null, null);
    final JComboBox cmbLiquidBalanceMonth = new JComboBox(
            SYSCalendar.createMonthList(new LocalDate().minusYears(1), new LocalDate()));
    btnLiquidBalance.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            OPDE.getMainframe().setBlocked(true);
            SwingWorker worker = new SwingWorker() {
                @Override
                protected Object doInBackground() throws Exception {
                    LocalDate month = (LocalDate) cmbLiquidBalanceMonth.getSelectedItem();
                    SYSFilesTools.print(ResValueTools.getLiquidBalance(month, progressClosure), false);
                    return null;
                }

                @Override
                protected void done() {
                    OPDE.getDisplayManager().setProgressBarMessage(null);
                    OPDE.getMainframe().setBlocked(false);
                }
            };
            worker.execute();
        }
    });
    cmbLiquidBalanceMonth.setRenderer(new ListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            return new DefaultListCellRenderer().getListCellRendererComponent(list,
                    monthFormatter.format(((LocalDate) value).toDate()), index, isSelected, cellHasFocus);
        }
    });
    cmbLiquidBalanceMonth.setSelectedIndex(cmbLiquidBalanceMonth.getItemCount() - 2);
    pnlLiquidBalance.add(btnLiquidBalance, BorderLayout.WEST);
    pnlLiquidBalance.add(cmbLiquidBalanceMonth, BorderLayout.EAST);
    pnlContent.add(pnlLiquidBalance);

    /***
     *                   _       _     _         _        _   _     _   _
     *     __      _____(_) __ _| |__ | |_   ___| |_ __ _| |_(_)___| |_(_) ___ ___
     *     \ \ /\ / / _ \ |/ _` | '_ \| __| / __| __/ _` | __| / __| __| |/ __/ __|
     *      \ V  V /  __/ | (_| | | | | |_  \__ \ || (_| | |_| \__ \ |_| | (__\__ \
     *       \_/\_/ \___|_|\__, |_| |_|\__| |___/\__\__,_|\__|_|___/\__|_|\___|___/
     *                     |___/
     */
    JPanel pnlWeight = new JPanel(new BorderLayout());
    final JButton btnWeightStats = GUITools.createHyperlinkButton("opde.controlling.nutrition.weightstats",
            null, null);
    int wsMonthsBack;
    try {
        wsMonthsBack = Integer.parseInt(OPDE.getProps().getProperty("opde.controlling::wsMonthsBack"));
    } catch (NumberFormatException nfe) {
        wsMonthsBack = 7;
    }
    final JTextField txtWSMonthsBack = GUITools.createIntegerTextField(1, 24, wsMonthsBack);
    txtWSMonthsBack.setToolTipText(SYSTools.xx("misc.msg.monthsback"));
    btnWeightStats.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            OPDE.getMainframe().setBlocked(true);
            SwingWorker worker = new SwingWorker() {
                @Override
                protected Object doInBackground() throws Exception {
                    SYSPropsTools.storeProp("opde.controlling::wsMonthsBack", txtWSMonthsBack.getText(),
                            OPDE.getLogin().getUser());
                    SYSFilesTools.print(ResValueTools.getWeightStats(
                            Integer.parseInt(txtWSMonthsBack.getText()), progressClosure), false);
                    return null;
                }

                @Override
                protected void done() {
                    OPDE.getDisplayManager().setProgressBarMessage(null);
                    OPDE.getMainframe().setBlocked(false);
                }
            };
            worker.execute();
        }
    });
    pnlWeight.add(btnWeightStats, BorderLayout.WEST);
    pnlWeight.add(txtWSMonthsBack, BorderLayout.EAST);
    pnlContent.add(pnlWeight);

    return pnlContent;
}

From source file:org.apache.cayenne.modeler.editor.ObjEntityRelationshipPanel.java

/**
 * Refresh the list of ObjEntity targets. Also refresh the table in case some
 * ObjRelationships were deleted.// ww w  . j  av  a  2s  .  com
 */
private void reloadEntityList(EntityEvent e) {
    if (e.getSource() != this) {
        return;
    }

    // If current model added/removed, do nothing.
    ObjEntity entity = mediator.getCurrentObjEntity();
    if (entity == e.getEntity() || entity == null) {
        return;
    }

    TableColumn col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_TARGET);
    DefaultCellEditor editor = (DefaultCellEditor) col.getCellEditor();

    JComboBox combo = (JComboBox) editor.getComponent();
    combo.setRenderer(CellRenderers.entityListRendererWithIcons(entity.getDataMap()));

    ObjRelationshipTableModel model = (ObjRelationshipTableModel) table.getModel();
    model.fireTableDataChanged();
}

From source file:org.apache.cayenne.modeler.editor.ObjEntityRelationshipTab.java

/**
 * Refresh the list of ObjEntity targets. Also refresh the table in case some
 * ObjRelationships were deleted.//  ww  w  .j a v a2s  .  co  m
 */
private void reloadEntityList(EntityEvent e) {
    if (e.getSource() != this) {
        return;
    }

    // If current model added/removed, do nothing.
    ObjEntity entity = mediator.getCurrentObjEntity();
    if (entity == e.getEntity() || entity == null) {
        return;
    }

    TableColumn col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_TARGET);
    DefaultCellEditor editor = (DefaultCellEditor) col.getCellEditor();

    JComboBox combo = (JComboBox) editor.getComponent();
    combo.setRenderer(CellRenderers.entityListRendererWithIcons(entity.getDataMap()));
    combo.setModel(new DefaultComboBoxModel(createObjEntityComboModel()));

    ObjRelationshipTableModel model = (ObjRelationshipTableModel) table.getModel();
    model.fireTableDataChanged();
}

From source file:org.apache.cayenne.modeler.editor.ObjEntityRelationshipTab.java

protected void rebuildTable(ObjEntity entity) {
    final ObjRelationshipTableModel model = new ObjRelationshipTableModel(entity, mediator, this);

    model.addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            if (table.getSelectedRow() >= 0) {
                ObjRelationship rel = model.getRelationship(table.getSelectedRow());
                if (((ObjEntity) rel.getSourceEntity()).getDbEntity() != null) {
                    resolve.setEnabled(true);
                } else
                    resolve.setEnabled(false);

                resolveMenu.setEnabled(resolve.isEnabled());
            }/* www .j a  v  a  2s. co  m*/
        }
    });

    table.setModel(model);
    table.setRowHeight(25);
    table.setRowMargin(3);

    TableColumn col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_TARGET);
    JComboBox targetCombo = Application.getWidgetFactory().createComboBox(createObjEntityComboModel(), false);
    AutoCompletion.enable(targetCombo);

    targetCombo.setRenderer(CellRenderers.entityListRendererWithIcons(entity.getDataMap()));
    targetCombo.setSelectedIndex(-1);
    col.setCellEditor(Application.getWidgetFactory().createCellEditor(targetCombo));

    col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_DELETERULE);
    JComboBox deleteRulesCombo = Application.getWidgetFactory().createComboBox(deleteRules, false);
    deleteRulesCombo.setEditable(false);
    deleteRulesCombo.setSelectedIndex(0); // Default to the first value
    col.setCellEditor(Application.getWidgetFactory().createCellEditor(deleteRulesCombo));

    tablePreferences.bind(table, null, null, null, ObjRelationshipTableModel.REL_NAME, true);
}

From source file:org.encog.workbench.tabs.visualize.bayesian.BayesianStructureTab.java

public BayesianStructureTab(BayesianNetwork method) {
    super(null);//  ww  w  .  j a v  a 2 s .c o m

    // Graph<V, E> where V is the type of the vertices
    // and E is the type of the edges
    this.graph = buildGraph(method);

    Layout<DrawnEvent, DrawnEventConnection> layout = new KKLayout(graph);

    vv = new VisualizationViewer<DrawnEvent, DrawnEventConnection>(layout);

    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<DrawnEvent>());
    vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.N);

    vv.setVertexToolTipTransformer(new Transformer<DrawnEvent, String>() {
        public String transform(DrawnEvent edge) {
            return edge.getToolTip();
        }
    });

    Transformer<DrawnEvent, Paint> vertexPaint = new Transformer<DrawnEvent, Paint>() {
        public Paint transform(DrawnEvent neuron) {
            return Color.white;
        }
    };

    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    this.setLayout(new BorderLayout());
    add(panel, BorderLayout.CENTER);
    final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse();
    vv.setGraphMouse(graphMouse);

    vv.addKeyListener(graphMouse.getModeKeyListener());
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);

    final ScalingControl scaler = new CrossoverScalingControl();

    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);

    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) {
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity();
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity();
        }
    });

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

    JPanel controls = new JPanel();
    controls.setLayout(new FlowLayout(FlowLayout.LEFT));
    controls.add(plus);
    controls.add(minus);
    controls.add(reset);
    controls.add(modeBox);
    controls.add(jcb);
    Border border = BorderFactory.createEtchedBorder();
    controls.setBorder(border);
    add(controls, BorderLayout.NORTH);

}

From source file:org.graphwalker.GUI.App.java

@SuppressWarnings("serial")
private void addButtons(JToolBar toolBar) {
    loadButton = makeNavigationButton("open", LOAD, "Load a model (graphml file)", "Load", true);
    toolBar.add(loadButton);/*from   w  w w . j a va  2 s.com*/

    reloadButton = makeNavigationButton("reload", RELOAD, "Reload/Restart already loaded Model", "Reload",
            false);
    toolBar.add(reloadButton);

    firstButton = makeNavigationButton("first", FIRST, "Start at the beginning", "First", false);
    toolBar.add(firstButton);

    backButton = makeNavigationButton("back", BACK, "Backs a step", "Back", false);
    toolBar.add(backButton);

    runButton = makeNavigationButton("run", RUN, "Starts the execution/Take a step forward in the log", "Run",
            false);
    toolBar.add(runButton);

    pauseButton = makeNavigationButton("pause", PAUSE, "Pauses the execution", "Pause", false);
    toolBar.add(pauseButton);

    nextButton = makeNavigationButton("next", NEXT, "Walk a step in the model/Go to the end of log", "Next",
            false);
    toolBar.add(nextButton);

    soapButton = makeNavigationCheckBoxButton("soap", SOAP, "Run MBT in SOAP(Web Services) mode", "Soap");
    soapButton.setSelected(Util.readSoapGuiStartupState());
    toolBar.add(soapButton);

    centerOnVertexButton = makeNavigationCheckBoxButton("centerOnVertex", CENTERONVERTEX,
            "Center the layout on the current vertex", "Center on current vertex");
    toolBar.add(centerOnVertexButton);

    @SuppressWarnings("rawtypes")
    Class[] combos = getCombos();
    final JComboBox jcb = new JComboBox(combos);
    // use a renderer to shorten the layout name presentation
    jcb.setRenderer(new DefaultListCellRenderer() {
        @Override
        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, getVv()));
    jcb.setSelectedItem(StaticLayout.class);

    toolBar.add(jcb);
}

From source file:org.netbeans.jcode.rest.controller.RESTPanel.java

private void setPackageType(JComboBox comboBox) {
    comboBox.setRenderer(PackageView.listRenderer());
    ComboBoxModel model = PackageView.createListView(sourceGroup);
    if (model.getSize() > 0) {
        model.setSelectedItem(model.getElementAt(0));
    }//w  w w.java  2  s.  c om
    comboBox.setModel(model);
    addChangeListener(comboBox);
}