Example usage for javax.swing JCheckBox isSelected

List of usage examples for javax.swing JCheckBox isSelected

Introduction

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

Prototype

public boolean isSelected() 

Source Link

Document

Returns the state of the button.

Usage

From source file:main.UIController.java

public void convertToGregorian() {
    UI window = this.getUi();

    String errorNoLoa = "Please insert a loa.";
    String errorLoaNotNumeric = "Please insert the loa as a numeric value.";
    String errorYearNotValid = "Please insert a valid loa (from 1 to 144).";
    String errorDayNotRead = "Sorry, the day could not be read.";

    JComboBox yen = window.getYen();
    JTextField loa = window.getLoa();
    JComboBox period = window.getPeriod();
    JComboBox day = window.getDayOfLoa();
    JCheckBox beforeMidnight = window.getBeforeMidnight();
    JTextPane result = window.getResGregorian();
    int yenNum = yen.getSelectedIndex() + 1;
    String value = loa.getText();
    if (!value.isEmpty()) {
        try {/*  w w  w  .jav  a2s .com*/
            int loaNum = Integer.parseInt(value);
            if (loaNum > 0 && loaNum <= 144) {
                int periodNum = period.getSelectedIndex() + 1;
                ImladrisCalendar cal = new ImladrisCalendar();
                boolean success = false;
                if (periodNum == ImladrisCalendar.YESTARE || periodNum == ImladrisCalendar.METTARE) {
                    success = true;
                    cal = new ImladrisCalendar(cal.intToRoman(yenNum), loaNum, periodNum);
                } else {
                    int dayNum = 0;
                    if (day.isEnabled()) {
                        success = true;
                        dayNum = day.getSelectedIndex() + 1;
                        cal = new ImladrisCalendar(cal.intToRoman(yenNum), loaNum, periodNum, dayNum);
                    } else {
                        result.setText(errorDayNotRead);
                    }
                }
                if (success) {
                    GregorianCalendar gcal = cal.getGregorian();
                    if (beforeMidnight.isSelected()) {
                        gcal.add(GregorianCalendar.DAY_OF_YEAR, -1);
                    }
                    String gstr = this.gregorianToString(gcal);
                    result.setText(gstr);
                }
            } else {
                result.setText(errorYearNotValid);
            }
        } catch (NumberFormatException e) {
            result.setText(errorLoaNotNumeric);
        }
    } else {
        result.setText(errorNoLoa);
    }
}

From source file:ffx.ui.ModelingPanel.java

/**
 * This handles conditional command option input.
 *
 * @param evt ActionEvent/*  ww  w  . j av a  2  s.c  o  m*/
 */
private void conditionalCommandEvent(ActionEvent evt) {
    Object source = evt.getSource();
    if (source instanceof JRadioButton) {
        JRadioButton jrb = (JRadioButton) source;
        String selection = jrb.getText().toLowerCase();
        for (JLabel label : conditionals) {
            JTextField jtf = (JTextField) label.getLabelFor();
            String cupon = label.getName().toLowerCase();
            if (cupon.contains(selection) && jrb.isSelected()) {
                label.setEnabled(true);
                jtf.setEnabled(true);
            } else {
                label.setEnabled(false);
                jtf.setEnabled(false);
            }
        }
    } else if (source instanceof JCheckBox) {
        JCheckBox jcb = (JCheckBox) source;
        String selection = jcb.getText().toLowerCase();
        for (JLabel label : conditionals) {
            String cupon = label.getName().toLowerCase();
            JTextField jtf = (JTextField) label.getLabelFor();
            if (cupon.contains(selection) && jcb.isSelected()) {
                label.setEnabled(true);
                jtf.setEnabled(true);
            } else {
                label.setEnabled(false);
                jtf.setEnabled(false);
            }
        }
    }
    statusLabel.setText("  " + createCommandInput());
}

From source file:io.github.jeremgamer.editor.panels.components.PanelsPanel.java

public PanelsPanel(JFrame frame, final PanelSave ps) {
    this.ps = ps;
    this.frame = frame;
    this.setSize(new Dimension(395, frame.getHeight() - 27 - 23));
    this.setLocation(300, 0);
    this.setBorder(BorderFactory.createTitledBorder("Edition du panneau"));

    JPanel content = new JPanel();
    JScrollPane scroll = new JScrollPane(content);
    scroll.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    scroll.setBorder(null);//from   ww w . j av a  2  s .c  o  m
    content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));
    scroll.setPreferredSize(new Dimension(382, frame.getHeight() - 27 - 46 - 20));

    JPanel namePanel = new JPanel();
    name.setPreferredSize(new Dimension(this.getWidth() - 280, 30));
    name.setEditable(false);
    namePanel.add(new JLabel("Nom :"));
    namePanel.add(name);
    namePanel.add(Box.createRigidArea(new Dimension(10, 1)));
    layout.addItem("Basique");
    layout.addItem("Bordures");
    layout.addItem("Ligne");
    layout.addItem("Colonne");
    layout.addItem("Grille");
    layout.addItem("Empil");
    layout.setPreferredSize(new Dimension(110, 30));
    layout.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            cl.show(advanced, listContent[combo.getSelectedIndex()]);
            ps.set("layout", combo.getSelectedIndex());
            ActionPanel.updateLists();
        }

    });
    namePanel.add(new JLabel("Disposition :"));
    namePanel.add(layout);
    namePanel.setPreferredSize(new Dimension(365, 50));
    namePanel.setMaximumSize(new Dimension(365, 50));
    content.add(namePanel);

    advanced.setPreferredSize(new Dimension(365, 300));
    advanced.setMaximumSize(new Dimension(365, 300));
    advanced.add(ble, listContent[0]);
    advanced.add(brdle, listContent[1]);
    advanced.add(lle, listContent[2]);
    advanced.add(rle, listContent[3]);
    advanced.add(gle, listContent[4]);
    advanced.add(cle, listContent[5]);

    content.add(advanced);

    topBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.top", combo.getSelectedItem());
        }

    });
    leftBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.left", combo.getSelectedItem());
        }

    });
    centerBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.center", combo.getSelectedItem());
        }

    });
    rightBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.right", combo.getSelectedItem());
        }

    });
    bottomBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.bottom", combo.getSelectedItem());
        }

    });

    JPanel prefSize = new JPanel();
    prefSize.setPreferredSize(new Dimension(365, 110));
    prefSize.setMaximumSize(new Dimension(365, 110));
    prefSize.setBorder(BorderFactory.createTitledBorder("Taille prfre"));
    JPanel prefSizePanel = new JPanel();
    prefSizePanel.setLayout(new GridLayout(2, 4));
    prefSizePanel.setPreferredSize(new Dimension(300, 55));
    prefSizePanel.setMaximumSize(new Dimension(300, 55));
    prefSizePanel.add(prefSizeEnabled);
    prefSizePanel.add(new JLabel(""));
    prefSizePanel.add(new JLabel(""));
    prefSizePanel.add(new JLabel("(en pixels)"));
    prefSizePanel.add(new JLabel("Largeur :"));
    prefSizePanel.add(prefWidth);
    prefSizePanel.add(new JLabel("Hauteur :"));
    prefSizePanel.add(prefHeight);
    prefWidth.setEnabled(false);
    prefHeight.setEnabled(false);
    prefSizeEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JCheckBox check = (JCheckBox) event.getSource();
            ps.set("preferredSize", check.isSelected());
            prefWidth.setEnabled(check.isSelected());
            prefHeight.setEnabled(check.isSelected());
        }
    });
    prefWidth.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("preferredWidth", spinner.getValue());
        }
    });
    prefHeight.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("preferredHeight", spinner.getValue());
        }
    });
    prefSize.add(prefSizePanel);

    content.add(prefSize);

    JPanel insetsPanel = new JPanel();
    insetsPanel.setBorder(BorderFactory.createTitledBorder("carts"));
    insetsPanel.setPreferredSize(new Dimension(365, 100));
    insetsPanel.setMaximumSize(new Dimension(365, 100));

    JPanel insetsContent = new JPanel();
    insetsContent.setLayout(new BoxLayout(insetsContent, BoxLayout.PAGE_AXIS));

    JPanel insetInput = new JPanel();
    insetInput.setLayout(new GridLayout(2, 4));
    insetInput.add(insetsEnabled);
    insetInput.add(new JLabel(""));
    insetInput.add(new JLabel(""));
    insetInput.add(new JLabel("(en pixels)"));
    insetInput.add(new JLabel("Horizontaux :"));
    insetInput.add(insetHz);
    insetInput.add(new JLabel("Verticaux :"));
    insetInput.add(insetVt);

    insetsEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JCheckBox check = (JCheckBox) event.getSource();
            if (check.isSelected()) {
                insetHz.setEnabled(true);
                insetVt.setEnabled(true);
                ps.set("insets", true);
            } else {
                insetHz.setEnabled(true);
                insetVt.setEnabled(true);
                ps.set("insets", false);
            }
        }

    });

    insetHz.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("insets.horizontal", spinner.getValue());
        }
    });
    insetVt.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("insets.vertical", spinner.getValue());
        }
    });

    insetsContent.add(insetInput);
    insetsPanel.add(insetsContent);

    content.add(insetsPanel);

    JPanel web = new JPanel();
    web.setPreferredSize(new Dimension(365, 100));
    web.setMaximumSize(new Dimension(365, 100));
    web.setBorder(BorderFactory.createTitledBorder("Page Web"));

    JPanel webContent = new JPanel();
    webContent.setLayout(new BorderLayout());
    webContent.add(webEnabled, BorderLayout.NORTH);
    webEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox check = (JCheckBox) e.getSource();
            ps.set("web", check.isSelected());
            if (check.isSelected() == true) {
                layout.setSelectedIndex(0);
                layout.setEnabled(false);
                ble.removeAllComponents();
                ble.disableComponents();
                adress.setEnabled(true);
            } else {
                ble.enableComponents();
                layout.setEnabled(true);
                adress.setEnabled(false);
            }
        }
    });
    JPanel webInput = new JPanel();
    webInput.add(new JLabel("Adresse :"));
    adress.setPreferredSize(new Dimension(250, 30));
    CaretListener caretUpdate = new CaretListener() {
        public void caretUpdate(javax.swing.event.CaretEvent e) {
            JTextField text = (JTextField) e.getSource();
            ps.set("web.adress", text.getText());
        }
    };
    adress.addCaretListener(caretUpdate);
    webInput.add(adress);
    webContent.add(webInput, BorderLayout.CENTER);

    web.add(webContent);

    JPanel background = new JPanel();
    BorderLayout bLayout = new BorderLayout();
    bLayout.setVgap(12);
    background.setLayout(bLayout);
    background.setBorder(BorderFactory.createTitledBorder("Couleur de fond"));
    background.setPreferredSize(new Dimension(365, 210));
    background.setMaximumSize(new Dimension(365, 210));
    cp.setPreferredSize(new Dimension(347, 145));
    cp.setMaximumSize(new Dimension(347, 145));
    opaque.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox check = (JCheckBox) e.getSource();
            ps.set("background.opaque", check.isSelected());
            cp.enableComponents(check.isSelected());
        }
    });
    background.add(opaque, BorderLayout.NORTH);
    background.add(cp, BorderLayout.CENTER);

    JPanel image = new JPanel();
    image.setBorder(BorderFactory.createTitledBorder("Image de fond"));
    image.setPreferredSize(new Dimension(365, 125));
    image.setMaximumSize(new Dimension(365, 125));
    image.setLayout(new BorderLayout());
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.setEnabled(false);
    remove.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            File img = new File(
                    "projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png");
            if (img.exists()) {
                img.delete();
            }
            browseImage.setEnabled(true);
        }

    });
    JPanel top = new JPanel();
    browseImage.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JButton button = (JButton) e.getSource();
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "background.png");
                nameBackground.setText(new File(path).getName());
                ps.set("background.image", new File(path).getName());
                button.setEnabled(false);
                size.setEnabled(true);
                size2.setEnabled(true);
                remove.setEnabled(true);
            }
        }

    });
    bg.add(size);
    bg.add(size2);
    JPanel sizePanel = new JPanel();
    sizePanel.setLayout(new BoxLayout(sizePanel, BoxLayout.PAGE_AXIS));
    size.setEnabled(false);
    size2.setEnabled(false);
    sizePanel.add(size);
    sizePanel.add(size2);
    size.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            ps.set("background.size", 0);
        }

    });
    size2.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            ps.set("background.size", 1);
        }

    });
    top.add(browseImage);
    top.add(sizePanel);

    remove.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JButton button = (JButton) event.getSource();
            new File("projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png")
                    .delete();
            nameBackground.setText("");
            ps.set("background.image", "");
            button.setEnabled(false);
        }

    });
    nameBackground.setFont(new Font("Sans Serif", Font.PLAIN, 15));
    JPanel center = new JPanel(new BorderLayout());
    center.add(nameBackground, BorderLayout.CENTER);
    center.add(remove, BorderLayout.EAST);

    image.add(top, BorderLayout.NORTH);
    image.add(center, BorderLayout.CENTER);

    content.add(web);
    content.add(background);
    content.add(image);

    this.add(scroll);
}

From source file:at.becast.youploader.gui.FrmMain.java

protected void startUploads() {
    UploadMgr.setSpeed_limit(speed);//from   w  ww  . java2s  . c  o  m
    if ("0".equals(Main.s.setting.get("tos_agreed")) && !this.tos) {
        if (Main.debug)
            LOG.debug("Asking about ToS Agreement");

        //Dummy JFrame to keep Dialog on top
        JFrame frmOpt = new JFrame();
        frmOpt.setAlwaysOnTop(true);
        JCheckBox checkbox = new JCheckBox(LANG.getString("frmMain.tos.Remember"));
        String message = LANG.getString("frmMain.tos.Message");
        Object[] params = { message, checkbox };
        int n;
        do {
            n = JOptionPane.showConfirmDialog(frmOpt, params, LANG.getString("frmMain.tos.Title"),
                    JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE);
        } while (n == JOptionPane.CLOSED_OPTION);
        if (n == JOptionPane.OK_OPTION) {
            if (Main.debug)
                LOG.debug("Agreed to ToS");

            if (checkbox.isSelected()) {
                Main.s.setting.put("tos_agreed", "1");
                Main.s.save("tos_agreed");
            }
            this.tos = true;
            UploadMgr.start();
        }
        frmOpt.dispose();
    } else {
        if (Main.debug)
            LOG.debug("Previously agreed to ToS");

        UploadMgr.start();
    }
}

From source file:HW3.java

private void finalAttributeDisplay(String subCatName) {
    for (HashMap hmap : AttrList) {
        if (hmap != null) {
            Iterator iter = hmap.keySet().iterator();
            boolean flag;
            while (iter.hasNext()) {
                JCheckBox jcheck = (JCheckBox) iter.next();
                String attr = jcheck.getText();
                flag = checkAlredyExists(attr, attrNames);
                if (hmap.get(jcheck) == subCatName && flag == false) {
                    attrNames.add(attr);
                    jcheck.setSelected(false);
                    attrPanel.add(jcheck);
                    jcheck.addItemListener(new ItemListener() {

                        @Override
                        public void itemStateChanged(ItemEvent e) {
                            String str = jcheck.getText();
                            if (jcheck.isSelected()) {
                                if (!checkAlredyExists(str, selectedAttrList)) {
                                    selectedAttrList.add(str);
                                }/*from   w w  w .ja  v  a2 s . c o m*/
                            } else {
                                clearBusinessTable();
                                selectedAttrList.remove(str);
                            }
                        }
                    });
                }
            }
        }
    }
    attrPanel.setLayout(new GridLayout(0, 1));
    attrPanel.revalidate();
    attrPanel.repaint();
    pack();
    attrPanel.setVisible(true);
    if (attrListCount == MAX_ATTR_LIST_COUNT - 1) {
        attrListCount = 0;
    } else {
        attrListCount++;
    }
}

From source file:HW3.java

private void finalDisplaySubCategory(String catName) {
    for (HashMap map : mapList) {
        if (map != null) {
            Iterator it = map.keySet().iterator();
            while (it.hasNext()) {
                JCheckBox jcheck = (JCheckBox) it.next();
                String s = jcheck.getText();
                boolean flag = checkAlredyExists(s, subCatNames);
                if (map.get(jcheck).equals(catName) && flag == false) {
                    subCatNames.add(s);//from w  ww. j a v a  2 s  .  c  om
                    jcheck.setSelected(false);
                    subCategoryPanel.add(jcheck);
                    jcheck.addItemListener(new ItemListener() {
                        @Override
                        public void itemStateChanged(ItemEvent e) {
                            String subCatName = null;
                            HashMap<JCheckBox, String> returnList = new HashMap<JCheckBox, String>();
                            if (jcheck.isSelected()) {
                                subCatName = jcheck.getText();
                                //System.out.println(subCatName);
                                selectSubCat.add(subCatName);
                                displayAttr(subCatName, returnList);
                                AttrList[attrListCount] = returnList;
                                finalAttributeDisplay(subCatName);
                            } else {
                                subCatName = jcheck.getText();
                                selectSubCat.remove(subCatName);
                                clearBusinessTable();
                                finalAttributeRemove(subCatName);
                            }
                        }
                    });
                }
            }
        }
    }
    subCategoryPanel.setLayout(new GridLayout(0, 1));
    subCategoryPanel.revalidate();
    subCategoryPanel.repaint();
    pack();
    subCategoryPanel.setVisible(true);
    if (mapListCount == MAX_MAP_LIST_COUNT - 1) {
        mapListCount = 0;
    } else {
        mapListCount++;
    }
}

From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java

/**
 * //ww  w.  j  a  v a 2s.  c  o  m
 * @param parent
 * @param title
 * @param message
 * @return <code>true</code> if project should also be physically deleted,
 * <code>false</code> is project should be deleted but all files should be left alone,
 * <code>null</code> if user cancelled the dialog/project should not be deleted
 */
public static Boolean showDeleteProjectDialog(IAssemblyProject project) {
    final JDialog dialog = new JDialog((Window) null, "Delete project " + project.getName());

    dialog.setModal(true);

    final JTextArea message = createMultiLineLabel(
            "Do you really want to delete project '" + project.getName() + " ?");
    final JCheckBox checkbox = new JCheckBox("Delete project files");

    final DialogResult[] outcome = { DialogResult.CANCEL };

    final JButton yesButton = new JButton("Yes");
    yesButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            outcome[0] = DialogResult.YES;
            dialog.dispose();
        }
    });

    final JButton noButton = new JButton("No");
    noButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            outcome[0] = DialogResult.NO;
            dialog.dispose();
        }
    });
    final JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            outcome[0] = DialogResult.CANCEL;
            dialog.dispose();
        }
    });

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());
    buttonPanel.add(yesButton);
    buttonPanel.add(noButton);
    buttonPanel.add(cancelButton);

    final JPanel messagePanel = new JPanel();
    messagePanel.setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = constraints(0, 0, true, false, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.weighty = 0;
    cnstrs.gridheight = 1;
    messagePanel.add(message, cnstrs);

    cnstrs = constraints(0, 1, true, true, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    messagePanel.add(checkbox, cnstrs);

    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());

    cnstrs = constraints(0, 0, true, false, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(5, 2, 5, 2); // top,left,bottom,right         
    panel.add(messagePanel, cnstrs);

    cnstrs = constraints(0, 1, true, true, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(0, 2, 10, 2); // top,left,bottom,right      
    panel.add(buttonPanel, cnstrs);

    dialog.getContentPane().add(panel);
    dialog.pack();
    dialog.setVisible(true);

    if (outcome[0] != DialogResult.YES) {
        return null;
    }
    return checkbox.isSelected();
}

From source file:com.diversityarrays.kdxplore.trialmgr.trait.TraitExplorerPanel.java

private void changeEditable(boolean isLocked, boolean override) {

    if (isLocked) {
        editingLocked.setIcon(KDClientUtils.getIcon(ImageId.LOCKED));
        editingLocked.setForeground(Color.BLACK);
        editingLocked.setText(EDITABLE_LOCKED);
        traitsEditable = false;//from   ww w.  j a  v  a 2  s  . c om
    } else {
        TrialManagerPreferences prefs = TrialManagerPreferences.getInstance();

        if (!override && prefs.getShowEditTraitWarning()) {

            JPanel dialogPanel = new JPanel(new BorderLayout());
            JLabel dialogLabel = new JLabel(
                    "<html>Editing <b><i>Traits</i></b> may adversely affect the <b><i>Trials</i></b> using them.");
            JCheckBox checkBox = new JCheckBox("Don't show me this again.", false);
            dialogPanel.add(dialogLabel, BorderLayout.CENTER);
            dialogPanel.add(checkBox, BorderLayout.SOUTH);

            if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this, dialogPanel,
                    "Allow Trait Editing?", JOptionPane.YES_NO_OPTION)) {
                editingLocked.setIcon(KDClientUtils.getIcon(ImageId.UNLOCKED));
                editingLocked.setForeground(Color.RED);
                editingLocked.setText(EDITABLE_UNLOCKED);
                traitsEditable = true;
            }

            if (checkBox.isSelected()) {
                prefs.setShowEditTraitWarning(false);
            }
        } else {
            editingLocked.setIcon(KDClientUtils.getIcon(ImageId.UNLOCKED));
            editingLocked.setForeground(Color.RED);
            editingLocked.setText(EDITABLE_UNLOCKED);
            traitsEditable = true;
        }
    }
}

From source file:neembuu.uploader.NeembuuUploader.java

private void saveListOfSelectedHosts() {
    final List<String> l = new LinkedList<String>();
    for (Map.Entry<JCheckBox, SmallModuleEntry> entry : unsyncEntries_map()) {
        JCheckBox jCheckBox = entry.getKey();
        SmallModuleEntry smallModuleEntry = entry.getValue();
        if (jCheckBox.isSelected()) {
            l.add(smallModuleEntry.getName());
        }//w  w  w .  jav a  2 s.c  o m
    }

    try {
        Files.write(Application.getNeembuuHome().resolve("selectedhostslist"), l, Charset.forName("UTF-8"),
                StandardOpenOption.CREATE, StandardOpenOption.WRITE);
    } catch (IOException ex) {
        NULogger.getLogger().log(Level.SEVERE, null, ex);
    }
}

From source file:edu.ku.brc.specify.plugins.ipadexporter.ManageDataSetsDlg.java

/**
 * //from   w  ww.  j a  v a 2 s  .  co  m
 */
private void addUserToDS() {
    final Vector<String> wsList = new Vector<String>();
    final Vector<String> instItems = new Vector<String>();

    String addStr = getResourceString("ADD");
    instItems.add(addStr);
    wsList.add(addStr);
    for (String fullName : cloudHelper.getInstList()) {
        String[] toks = StringUtils.split(fullName, '\t');
        instItems.add(toks[0]);
        wsList.add(toks[1]);
    }

    final JTextField userNameTF = createTextField(20);
    final JTextField passwordTF = createTextField(20);
    final JLabel pwdLbl = createI18NFormLabel("Password");
    final JLabel statusLbl = createLabel("");
    final JCheckBox isNewUser = UIHelper.createCheckBox("Is New User");
    final JLabel instLbl = createI18NFormLabel("Insitution");
    final JComboBox instCmbx = UIHelper.createComboBox(instItems.toArray());

    if (instItems.size() == 2) {
        instCmbx.setSelectedIndex(1);
    }

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,4px,p,4px,p,4px,p,4px,p,8px,p"));

    pb.add(createI18NLabel("Add New or Existing User to DataSet"), cc.xyw(1, 1, 3));
    pb.add(createI18NFormLabel("Username"), cc.xy(1, 3));
    pb.add(userNameTF, cc.xy(3, 3));
    pb.add(pwdLbl, cc.xy(1, 5));
    pb.add(passwordTF, cc.xy(3, 5));
    pb.add(instLbl, cc.xy(1, 7));
    pb.add(instCmbx, cc.xy(3, 7));

    pb.add(isNewUser, cc.xy(3, 9));

    pb.add(statusLbl, cc.xyw(1, 11, 3));
    pb.setDefaultDialogBorder();

    pwdLbl.setVisible(false);
    passwordTF.setVisible(false);
    instLbl.setVisible(false);
    instCmbx.setVisible(false);

    final CustomDialog dlg = new CustomDialog(this, "Add User", true, OKCANCEL, pb.getPanel()) {
        @Override
        protected void okButtonPressed() {
            String usrName = userNameTF.getText();
            if (cloudHelper.isUserNameOK(usrName)) {
                String collGuid = datasetGUIDList.get(dataSetList.getSelectedIndex());
                if (cloudHelper.addUserAccessToDataSet(usrName, collGuid)) {
                    super.okButtonPressed();
                } else {
                    iPadDBExporterPlugin.setErrorMsg(statusLbl,
                            String.format("Unable to add usr: %s to the DataSet guid: %s", usrName, collGuid));
                }
            } else if (isNewUser.isSelected()) {
                String pwdStr = passwordTF.getText();
                String guid = null;
                if (instCmbx.getSelectedIndex() == 0) {
                    //                        InstDlg instDlg = new InstDlg(cloudHelper);
                    //                        if (!instDlg.isInstOK())
                    //                        {
                    //                            instDlg.createUI();
                    //                            instDlg.pack();
                    //                            centerAndShow(instDlg, 600, null);
                    //                            if (instDlg.isCancelled())
                    //                            {
                    //                                return;
                    //                            }
                    //                            //guid = instDlg.getGuid()();
                    //                        }
                } else {
                    //webSite = wsList.get(instCmbx.getSelectedIndex());

                }

                if (guid != null) {
                    String collGuid = datasetGUIDList.get(dataSetList.getSelectedIndex());
                    if (cloudHelper.addNewUser(usrName, pwdStr, guid)) {
                        if (cloudHelper.addUserAccessToDataSet(usrName, collGuid)) {
                            ManageDataSetsDlg.this.loadUsersForDataSetsIntoJList();
                            super.okButtonPressed();
                        } else {
                            iPadDBExporterPlugin.setErrorMsg(statusLbl,
                                    String.format("Unable to add%s to the DataSet %s", usrName, collGuid));
                        }
                    } else {
                        iPadDBExporterPlugin.setErrorMsg(statusLbl,
                                String.format("Unable to add%s to the DataSet %s", usrName, collGuid));
                    }
                } else {
                    // error
                }
            } else {
                iPadDBExporterPlugin.setErrorMsg(statusLbl, String.format("'%s' doesn't exist.", usrName));
            }
        }
    };

    KeyAdapter ka = new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            statusLbl.setText("");
            String usrNmStr = userNameTF.getText();
            boolean hasData = StringUtils.isNotEmpty(usrNmStr)
                    && (!isNewUser.isSelected() || StringUtils.isNotEmpty(passwordTF.getText()))
                    && UIHelper.isValidEmailAddress(usrNmStr);
            dlg.getOkBtn().setEnabled(hasData);
        }

    };
    userNameTF.addKeyListener(ka);
    passwordTF.addKeyListener(ka);

    final Color textColor = userNameTF.getForeground();

    FocusAdapter fa = new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            JTextField tf = (JTextField) e.getSource();
            if (!tf.getForeground().equals(textColor)) {
                tf.setText("");
                tf.setForeground(textColor);
            }
        }

        @Override
        public void focusLost(FocusEvent e) {
            JTextField tf = (JTextField) e.getSource();
            if (tf.getText().length() == 0) {
                tf.setText("Enter email address");
                tf.setForeground(Color.LIGHT_GRAY);
            }
        }
    };
    userNameTF.addFocusListener(fa);

    userNameTF.setText("Enter email address");
    userNameTF.setForeground(Color.LIGHT_GRAY);

    isNewUser.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean isSel = isNewUser.isSelected();
            pwdLbl.setVisible(isSel);
            passwordTF.setVisible(isSel);
            instLbl.setVisible(isSel);
            instCmbx.setVisible(isSel);

            Dimension s = dlg.getSize();
            int hgt = isNewUser.getSize().height + 4 + instCmbx.getSize().height;
            s.height += isSel ? hgt : -hgt;
            dlg.setSize(s);
        }
    });

    dlg.createUI();
    dlg.getOkBtn().setEnabled(false);

    centerAndShow(dlg);
    if (!dlg.isCancelled()) {
        loadUsersForDataSetsIntoJList();
    }
}