Example usage for javax.swing JCheckBox addActionListener

List of usage examples for javax.swing JCheckBox addActionListener

Introduction

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

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

From source file:storybook.model.EntityUtil.java

public static List<JCheckBox> createCountryCheckBoxes(MainFrame mainFrame, ActionListener comp) {
    List<JCheckBox> list = new ArrayList<>();
    BookModel model = mainFrame.getBookModel();
    Session session = model.beginTransaction();
    LocationDAOImpl dao = new LocationDAOImpl(session);
    List<String> countries = dao.findCountries();
    model.commit();//from w w w  . jav a2s.c om
    for (String country : countries) {
        JCheckBox chb = new JCheckBox(country);
        chb.setOpaque(false);
        chb.addActionListener(comp);
        chb.setSelected(true);
        list.add(chb);
    }
    return list;
}

From source file:storybook.model.EntityUtil.java

public static List<JCheckBox> createPersonCheckBoxes(MainFrame mainFrame, List<JCheckBox> cbl,
        ActionListener comp) {//from w  w  w  .j  av  a2  s .  c om
    List<JCheckBox> list = new ArrayList<>();
    BookModel model = mainFrame.getBookModel();
    Session session = model.beginTransaction();
    PersonDAOImpl dao = new PersonDAOImpl(session);
    for (JCheckBox cb : cbl) {
        if (cb.isSelected()) {
            Category category = (Category) cb.getClientProperty(SbConstants.ComponentName.CB_CATEGORY);
            List<Person> persons = dao.findByCategory(category);
            for (Person person : persons) {
                JCheckBox cbPerson = new JCheckBox(person.getFullNameAbbr());
                cbPerson.setOpaque(false);
                cbPerson.putClientProperty(SbConstants.ComponentName.CB_PERSON, person);
                cbPerson.addActionListener(comp);
                list.add(cbPerson);
            }
        }
    }
    model.commit();
    return list;
}

From source file:storybook.model.EntityUtil.java

public static List<JCheckBox> createItemCheckBoxes(MainFrame m, ActionListener comp) {
    List<JCheckBox> list = new ArrayList<>();
    BookModel model = m.getBookModel();/*  w w w.ja  va2s.  c  om*/
    Session session = model.beginTransaction();
    ItemDAOImpl dao = new ItemDAOImpl(session);
    List<Item> items = dao.findAll();
    for (Item item : items) {
        JCheckBox cbItem = new JCheckBox(item.getName());
        cbItem.setOpaque(false);
        cbItem.putClientProperty(SbConstants.ComponentName.CB_ITEM, item);
        cbItem.addActionListener(comp);
        list.add(cbItem);
    }
    model.commit();
    return list;
}

From source file:unikn.dbis.univis.navigation.tree.VTree.java

/**
 * TODO: document me!!!// ww  w . j  a v a  2s .  c o  m
 *
 * @param p
 */
public void showPopupMenu(Point p) {

    // Remove all items from popup menu.
    popupMenu.removeAll();

    Object o = getLastSelectedPathComponent();

    if (o instanceof DefaultMutableTreeNode) {

        DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;

        Object userObject = node.getUserObject();

        if (userObject instanceof VDimension) {

            VDimension dimension = (VDimension) userObject;

            try {
                Point p2 = new Point(p);
                SwingUtilities.convertPointToScreen(p2, this);

                final FilterItemContainer container = createFilterContainer(dimension, p2);

                if (!container.isEmpty()) {
                    /*
                    JLabel header = new JLabel(MessageResolver.getMessage("data_reference." + dimension.getI18nKey()));
                    Font font = header.getFont();
                    header.setFont(new Font(font.getFontName(), Font.BOLD, font.getSize() + 2));
                    popupMenu.add(header);
                    popupMenu.add(new JPopupMenu.Separator());
                    */

                    popupMenu = new FilterPopupMenu(
                            MessageResolver.getMessage("data_reference." + dimension.getI18nKey()));

                    final JCheckBox button = new JCheckBox("Check/Uncheck all");

                    button.setSelected(container.isAllChecked());

                    button.addActionListener(new ActionListener() {
                        /**
                         * Invoked when an action occurs.
                         */
                        public void actionPerformed(ActionEvent e) {

                            for (Component c : container.getComponents()) {
                                if (c instanceof VBidirectionalBrowsingItem) {
                                    ((VBidirectionalBrowsingItem) c).getCheckBox()
                                            .setChecked(button.isSelected());
                                }
                            }
                        }
                    });

                    popupMenu.add(button);

                    popupMenu.add(new JPopupMenu.Separator());

                    popupMenu.add(container);

                    JButton view = new JButton(MessageResolver.getMessage("filtering"), VIcons.FILTER);
                    view.addActionListener(new ActionListener() {

                        /**
                         * Invoked when an action occurs.
                         */
                        public void actionPerformed(ActionEvent e) {
                            popupMenu.setVisible(false);
                        }
                    });

                    popupMenu.add(new JPopupMenu.Separator());

                    popupMenu.add(view);

                    popupMenu.show(VTree.this, (int) p.getX(), (int) p.getY());
                } else {
                    JOptionPane.showMessageDialog(VTree.this.getParent().getParent().getParent(),
                            MessageResolver.getMessage("no_items_found"),
                            MessageResolver.getMessage("error_message"), JOptionPane.ERROR_MESSAGE);
                }
            } catch (SQLException sqle) {
                VExplorer.publishException(sqle);

                if (LOG.isErrorEnabled()) {
                    LOG.error(sqle.getMessage(), sqle);
                }
            }
        }
    }
}

From source file:us.paulevans.basicxslt.TransformParametersFrame.java

/**
 * Rebuilds the parameters panel//from w  ww.ja v  a2 s . c  o  m
 *
 */
private void rebuildParametersPanel() {

    int loop, row, size;
    JTextField paramNameTf, paramValueTf, paramNamespaceURITf;
    JCheckBox removeCb;
    String paramNames[];
    ParameterTextFieldGroup paramTfGroup;

    row = 0;
    parametersPanel.removeAll();
    GUIUtils.add(parametersPanel, new JLabel(stringFactory.getString(LabelStringFactory.PARAMS_FRAME_NAME_LBL)),
            parametersPanelLayout, parametersPanelConstraints, row, 0, 1, 1, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, GUIUtils.SMALL_INSETS);
    GUIUtils.add(parametersPanel,
            new JLabel(stringFactory.getString(LabelStringFactory.PARAMS_FRAME_VALUE_LBL)),
            parametersPanelLayout, parametersPanelConstraints, row, 1, 1, 1, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, GUIUtils.SMALL_INSETS);
    GUIUtils.add(parametersPanel,
            new JLabel(stringFactory.getString(LabelStringFactory.PARAMS_FRAME_NAMESPACE_URI_LBL)),
            parametersPanelLayout, parametersPanelConstraints, row, 2, 1, 1, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, GUIUtils.SMALL_INSETS);
    GUIUtils.add(parametersPanel,
            new JLabel(stringFactory.getString(LabelStringFactory.PARAMS_FRAME_REMOVE_LBL)),
            parametersPanelLayout, parametersPanelConstraints, row++, 3, 1, 1, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, GUIUtils.SMALL_INSETS);
    paramNames = parameters.getParameterNames();
    size = parameterTextFieldGroups.size();
    for (loop = 0; loop < size; loop++) {
        paramTfGroup = (ParameterTextFieldGroup) parameterTextFieldGroups.get(loop);
        GUIUtils.add(parametersPanel, paramNameTf = paramTfGroup.getParamNameTf(), parametersPanelLayout,
                parametersPanelConstraints, row, 0, 1, 1, GridBagConstraints.WEST,
                GridBagConstraints.HORIZONTAL, GUIUtils.SMALL_INSETS);
        GUIUtils.add(parametersPanel, paramValueTf = paramTfGroup.getParamValueTf(), parametersPanelLayout,
                parametersPanelConstraints, row, 1, 1, 1, GridBagConstraints.WEST,
                GridBagConstraints.HORIZONTAL, GUIUtils.SMALL_INSETS);
        GUIUtils.add(parametersPanel, paramNamespaceURITf = paramTfGroup.getParamNamespaceURITf(),
                parametersPanelLayout, parametersPanelConstraints, row, 2, 1, 1, GridBagConstraints.WEST,
                GridBagConstraints.HORIZONTAL, GUIUtils.SMALL_INSETS);
        GUIUtils.add(parametersPanel, removeCb = paramTfGroup.getRemoveCb(), parametersPanelLayout,
                parametersPanelConstraints, row++, 3, 1, 1, GridBagConstraints.WEST, GridBagConstraints.NONE,
                GUIUtils.SMALL_INSETS);
        removeCb.addActionListener(this);
        if (loop < paramNames.length) {
            paramNameTf.setText(TransformParameters.getParameterName(paramNames[loop]));
            paramValueTf.setText(parameters.getParameter(paramNames[loop]).toString());
            paramNamespaceURITf.setText(TransformParameters.getNamespaceURI(paramNames[loop]));
        }
    }
}