Example usage for javax.swing JToggleButton setEnabled

List of usage examples for javax.swing JToggleButton setEnabled

Introduction

In this page you can find the example usage for javax.swing JToggleButton setEnabled.

Prototype

public void setEnabled(boolean b) 

Source Link

Document

Enables (or disables) the button.

Usage

From source file:com.haulmont.cuba.desktop.gui.components.DesktopOptionsGroup.java

@Override
protected void setEditableToComponent(boolean editable) {
    for (JToggleButton button : items.values()) {
        button.setEnabled(enabled && editable);
    }/* w w  w .ja va 2s  . c  o  m*/
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopOptionsGroup.java

@Override
public void updateEnabled() {
    super.updateEnabled();

    for (JToggleButton button : items.values()) {
        button.setEnabled(enabled && editable && parentEnabled);
    }/*w  w w  .j av  a2  s. c  o  m*/
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopOptionsGroup.java

private void addItem(final ValueWrapper item) {
    JToggleButton button;
    if (multiselect) {
        button = new JCheckBox(item.toString());
    } else {//from w w  w.j  a  va 2 s .  c o  m
        if (buttonGroup == null)
            buttonGroup = new ButtonGroup();
        button = new JRadioButton(item.toString());
        buttonGroup.add(button);
    }
    button.setEnabled(enabled && editable);
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (!multiselect) {
                Object newValue = item.getValue();
                if (!Objects.equals(newValue, prevValue)) {
                    updateInstance(newValue);
                    fireChangeListeners(newValue);
                }
                updateMissingValueState();
            } else {
                Set<Object> newValue = new LinkedHashSet<>();
                for (Map.Entry<ValueWrapper, JToggleButton> item : items.entrySet()) {
                    if (item.getValue().isSelected()) {
                        newValue.add(item.getKey().getValue());
                    }
                }
                if ((prevValue != null && !CollectionUtils.isEqualCollection(newValue, (Collection) prevValue))
                        || (prevValue == null)) {
                    updateInstance(newValue);
                    fireChangeListeners(newValue);
                }
                updateMissingValueState();
            }
        }
    });

    impl.add(button);
    items.put(item, button);
}

From source file:edu.ku.brc.specify.plugins.latlon.LatLonUI.java

public void setEnabled(final boolean enabled) {
    super.setEnabled(enabled);

    formatSelector.setEnabled(enabled);//w ww  .  j  a v  a 2 s  . c o  m

    for (LatLonUIIFace ll : panels) {
        ll.setEnabled(enabled);
    }

    if (botBtns != null) {
        for (JToggleButton brb : botBtns) {
            brb.setEnabled(enabled);
        }
    }
}

From source file:edu.ku.brc.af.ui.forms.FormViewObj.java

/**
 * Shows a Dialog to setup Carry Forward. 
 * The hard part is figuring out which fields are candidates for Carry Forward.
 *///from  www  . j  ava  2 s. co  m
public void configureCarryForward() {
    CarryForwardInfo carryForwardInfo = getCarryForwardInfo();

    DBTableInfo tblInfo = DBTableIdMgr.getInstance().getByClassName(view.getClassName());
    Vector<FVOFieldInfo> itemLabels = new Vector<FVOFieldInfo>();
    Vector<FVOFieldInfo> selectedItems = new Vector<FVOFieldInfo>(carryForwardInfo.getFieldList());

    buildFieldInfoList(itemLabels, tblInfo);

    ToggleButtonChooserDlg<FVOFieldInfo> dlg = new ToggleButtonChooserDlg<FVOFieldInfo>(
            (Frame) UIRegistry.getTopWindow(), "CONFIG_CARRY_FORWARD_TITLE", itemLabels);
    dlg.setUseScrollPane(true);
    dlg.setAddSelectAll(true);
    dlg.createUI();

    HashMap<String, JToggleButton> tgBtnHash = new HashMap<String, JToggleButton>();
    Vector<JToggleButton> btns = dlg.getPanel().getButtons();
    for (JToggleButton tb : btns) {
        tgBtnHash.put(tb.getText(), tb);
    }

    for (FVOFieldInfo itm : itemLabels) {
        if (itm.isRequired()) {
            JToggleButton togBtn = tgBtnHash.get(itm.getLabel());
            if (togBtn != null) {
                togBtn.setEnabled(false);
                selectedItems.add(itm);
            }
        }
    }

    dlg.setSelectedObjects(selectedItems);
    UIHelper.centerAndShow(dlg);

    if (!dlg.isCancelled()) {
        carryForwardInfo.add(dlg.getSelectedObjects());
    }
    notifyUIPluginsOfChanges(true, null);
}

From source file:op.care.med.inventory.PnlInventory.java

private CollapsiblePane createCP4(final MedInventory inventory) {
    /***//from   ww  w .j  a  v  a 2  s. co m
     *                          _        ____ ____  _  _    _____                      _                 __
     *       ___ _ __ ___  __ _| |_ ___ / ___|  _ \| || |  / /_ _|_ ____   _____ _ __ | |_ ___  _ __ _   \ \
     *      / __| '__/ _ \/ _` | __/ _ \ |   | |_) | || |_| | | || '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | | |
     *     | (__| | |  __/ (_| | ||  __/ |___|  __/|__   _| | | || | | \ V /  __/ | | | || (_) | |  | |_| | |
     *      \___|_|  \___|\__,_|\__\___|\____|_|      |_| | ||___|_| |_|\_/ \___|_| |_|\__\___/|_|   \__, | |
     *                                                     \_\                                       |___/_/
     */
    final String key = inventory.getID() + ".xinventory";
    synchronized (cpMap) {
        if (!cpMap.containsKey(key)) {
            cpMap.put(key, new CollapsiblePane());
            try {
                cpMap.get(key).setCollapsed(true);
            } catch (PropertyVetoException e) {
                e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
            }

        }

        cpMap.get(key).setName("inventory");

        //            final CollapsiblePane cpInventory = cpMap.get(key);

        BigDecimal sumInventory = BigDecimal.ZERO;
        try {
            EntityManager em = OPDE.createEM();
            sumInventory = MedInventoryTools.getSum(em, inventory);
            em.close();
        } catch (Exception e) {
            OPDE.fatal(e);
        }

        String title = "<html><table border=\"0\">" + "<tr>" +

                "<td width=\"520\" align=\"left\"><font size=+1>" + inventory.getText() + "</font></td>"
                + "<td width=\"200\" align=\"right\"><font size=+1>"
                + NumberFormat.getNumberInstance().format(sumInventory) + " "
                + DosageFormTools.getPackageText(MedInventoryTools.getForm(inventory)) + "</font></td>" +

                "</tr>" + "</table>" +

                "</html>";

        DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    cpMap.get(key).setCollapsed(!cpMap.get(key).isCollapsed());
                } catch (PropertyVetoException pve) {
                    // BAH!
                }
            }
        });
        cpMap.get(key).setTitleLabelComponent(cptitle.getMain());
        cpMap.get(key).setSlidingDirection(SwingConstants.SOUTH);
        cptitle.getButton().setIcon(inventory.isClosed() ? SYSConst.icon22stopSign : null);

        if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.MANAGER, "nursingrecords.inventory")) {
            /***
             *       ____ _                ___                      _
             *      / ___| | ___  ___  ___|_ _|_ ____   _____ _ __ | |_ ___  _ __ _   _
             *     | |   | |/ _ \/ __|/ _ \| || '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | |
             *     | |___| | (_) \__ \  __/| || | | \ V /  __/ | | | || (_) | |  | |_| |
             *      \____|_|\___/|___/\___|___|_| |_|\_/ \___|_| |_|\__\___/|_|   \__, |
             *                                                                    |___/
             */
            final JButton btnCloseInventory = new JButton(SYSConst.icon22playerStop);
            btnCloseInventory.setPressedIcon(SYSConst.icon22playerStopPressed);
            btnCloseInventory.setAlignmentX(Component.RIGHT_ALIGNMENT);
            btnCloseInventory.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            btnCloseInventory.setContentAreaFilled(false);
            btnCloseInventory.setBorder(null);
            btnCloseInventory.setToolTipText(SYSTools.xx("nursingrecords.inventory.btncloseinventory.tooltip"));
            btnCloseInventory.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent actionEvent) {
                    new DlgYesNo(
                            SYSTools.xx("nursingrecords.inventory.question.close1") + "<br/><b>"
                                    + inventory.getText() + "</b>" + "<br/>"
                                    + SYSTools.xx("nursingrecords.inventory.question.close2"),
                            SYSConst.icon48playerStop, new Closure() {
                                @Override
                                public void execute(Object answer) {
                                    if (answer.equals(JOptionPane.YES_OPTION)) {
                                        EntityManager em = OPDE.createEM();
                                        try {
                                            em.getTransaction().begin();

                                            MedInventory myInventory = em.merge(inventory);
                                            em.lock(myInventory, LockModeType.OPTIMISTIC);
                                            em.lock(myInventory.getResident(), LockModeType.OPTIMISTIC);

                                            // close all stocks
                                            for (MedStock stock : MedStockTools.getAll(myInventory)) {
                                                if (!stock.isClosed()) {
                                                    MedStock mystock = em.merge(stock);
                                                    em.lock(mystock, LockModeType.OPTIMISTIC);
                                                    mystock.setNextStock(null);
                                                    MedStockTools.close(em, mystock, SYSTools.xx(
                                                            "nursingrecords.inventory.stock.msg.inventory_closed"),
                                                            MedStockTransactionTools.STATE_EDIT_INVENTORY_CLOSED);
                                                }
                                            }
                                            // close inventory
                                            myInventory.setTo(new Date());

                                            em.getTransaction().commit();

                                            createCP4(myInventory);
                                            buildPanel();
                                        } catch (OptimisticLockException ole) {
                                            OPDE.warn(ole);
                                            if (em.getTransaction().isActive()) {
                                                em.getTransaction().rollback();
                                            }
                                            if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                                OPDE.getMainframe().emptyFrame();
                                                OPDE.getMainframe().afterLogin();
                                            }
                                            OPDE.getDisplayManager()
                                                    .addSubMessage(DisplayManager.getLockMessage());
                                        } catch (Exception e) {
                                            if (em.getTransaction().isActive()) {
                                                em.getTransaction().rollback();
                                            }
                                            OPDE.fatal(e);
                                        } finally {
                                            em.close();
                                        }
                                    }
                                }
                            });
                }
            });
            btnCloseInventory.setEnabled(!inventory.isClosed());
            cptitle.getRight().add(btnCloseInventory);
        }
        if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, "nursingrecords.inventory")) {
            /***
             *      ____       _ ___                      _
             *     |  _ \  ___| |_ _|_ ____   _____ _ __ | |_ ___  _ __ _   _
             *     | | | |/ _ \ || || '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | |
             *     | |_| |  __/ || || | | \ V /  __/ | | | || (_) | |  | |_| |
             *     |____/ \___|_|___|_| |_|\_/ \___|_| |_|\__\___/|_|   \__, |
             *                                                          |___/
             */
            final JButton btnDelInventory = new JButton(SYSConst.icon22delete);
            btnDelInventory.setPressedIcon(SYSConst.icon22deletePressed);
            btnDelInventory.setAlignmentX(Component.RIGHT_ALIGNMENT);
            btnDelInventory.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            btnDelInventory.setContentAreaFilled(false);
            btnDelInventory.setBorder(null);
            btnDelInventory.setToolTipText(SYSTools.xx("nursingrecords.inventory.btndelinventory.tooltip"));
            btnDelInventory.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent actionEvent) {
                    new DlgYesNo(
                            SYSTools.xx("nursingrecords.inventory.question.delete1") + "<br/><b>"
                                    + inventory.getText() + "</b>" + "<br/>"
                                    + SYSTools.xx("nursingrecords.inventory.question.delete2"),
                            SYSConst.icon48delete, new Closure() {
                                @Override
                                public void execute(Object answer) {
                                    if (answer.equals(JOptionPane.YES_OPTION)) {
                                        EntityManager em = OPDE.createEM();
                                        try {
                                            em.getTransaction().begin();

                                            MedInventory myInventory = em.merge(inventory);
                                            em.lock(myInventory, LockModeType.OPTIMISTIC);
                                            em.lock(myInventory.getResident(), LockModeType.OPTIMISTIC);

                                            em.remove(myInventory);

                                            em.getTransaction().commit();

                                            //                                        lstInventories.remove(inventory);
                                            buildPanel();
                                        } catch (OptimisticLockException ole) {
                                            OPDE.warn(ole);
                                            if (em.getTransaction().isActive()) {
                                                em.getTransaction().rollback();
                                            }
                                            if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                                OPDE.getMainframe().emptyFrame();
                                                OPDE.getMainframe().afterLogin();
                                            }
                                            OPDE.getDisplayManager()
                                                    .addSubMessage(DisplayManager.getLockMessage());
                                        } catch (Exception e) {
                                            if (em.getTransaction().isActive()) {
                                                em.getTransaction().rollback();
                                            }
                                            OPDE.fatal(e);
                                        } finally {
                                            em.close();
                                        }
                                    }
                                }
                            });
                }
            });
            cptitle.getRight().add(btnDelInventory);
        }

        final JToggleButton tbClosedStock = GUITools.getNiceToggleButton(null);
        tbClosedStock.setToolTipText(SYSTools.xx("nursingrecords.inventory.showclosedstocks"));
        if (!inventory.isClosed()) {
            tbClosedStock.addItemListener(new ItemListener() {
                @Override
                public void itemStateChanged(ItemEvent e) {
                    cpMap.get(key).setContentPane(createContentPanel4(inventory, tbClosedStock.isSelected()));
                }
            });
        }
        tbClosedStock.setSelected(inventory.isClosed());
        tbClosedStock.setEnabled(!inventory.isClosed());

        mapKey2ClosedToggleButton.put(key, tbClosedStock);

        cptitle.getRight().add(tbClosedStock);

        CollapsiblePaneAdapter adapter = new CollapsiblePaneAdapter() {
            @Override
            public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
                cpMap.get(key).setContentPane(createContentPanel4(inventory, tbClosedStock.isSelected()));
            }
        };
        synchronized (cpListener) {
            if (cpListener.containsKey(key)) {
                cpMap.get(key).removeCollapsiblePaneListener(cpListener.get(key));
            }
            cpListener.put(key, adapter);
            cpMap.get(key).addCollapsiblePaneListener(adapter);
        }

        if (!cpMap.get(key).isCollapsed()) {
            cpMap.get(key).setContentPane(createContentPanel4(inventory, tbClosedStock.isSelected()));
        }

        cpMap.get(key).setHorizontalAlignment(SwingConstants.LEADING);
        cpMap.get(key).setOpaque(false);
        cpMap.get(key).setBackground(getColor(SYSConst.medium2, lstInventories.indexOf(inventory) % 2 != 0));

        return cpMap.get(key);
    }
}

From source file:org.zaproxy.zap.extension.httppanel.HttpPanel.java

private void addComponent(HttpPanelComponentInterface component) {
    synchronized (components) {
        final String componentName = component.getName();
        if (components.containsKey(componentName)) {
            removeComponent(componentName);
        }/*w  w  w.  j a v  a  2s .co  m*/

        component.setEditable(isEditable);
        component.setEnableViewSelect(isEnableViewSelect);

        components.put(componentName, component);
        panelContent.add(component.getMainPanel(), componentName);

        final JToggleButton button = component.getButton();
        button.setActionCommand(componentName);

        button.addActionListener(getSwitchComponentItemListener());
        button.setEnabled(isEnableViewSelect);

        if (component.isEnabled(message)) {
            enableComponent(component);

            if (currentComponent == null) {
                switchComponent(componentName);
            } else if (savedLastSelectedComponentName != null
                    && savedLastSelectedComponentName.equals(componentName)) {
                switchComponent(componentName);
            } else if (savedLastSelectedComponentName == null
                    && currentComponent.getPosition() > component.getPosition()) {
                switchComponent(componentName);
            }
        }
    }
}