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:MyData.java

public Object getCellEditorValue() {
    JCheckBox editor = (JCheckBox) (super.getComponent());
    nodeData.setAnswer(editor.isSelected());
    return nodeData;
}

From source file:CheckBoxNodeTreeSample.java

public Object getCellEditorValue() {
    JCheckBox checkbox = renderer.getLeafRenderer();
    CheckBoxNode checkBoxNode = new CheckBoxNode(checkbox.getText(), checkbox.isSelected());
    return checkBoxNode;
}

From source file:de.mprengemann.intellij.plugin.androidicons.forms.AndroidIconsImporter.java

private ImageInformation getImageInformation(ImageInformation baseInformation, Resolution resolution,
        JCheckBox checkBox) {
    if (!checkBox.isSelected()) {
        return null;
    }//from w w w .  j  a v  a  2  s  . co m

    String fromName = "ic_action_" + assetName + ".png";
    File source = new File(assetRoot.getCanonicalPath() + "/" + assetColor.replace(" ", "_") + "/"
            + resolution.toString() + "/" + fromName);

    return ImageInformation.newBuilder(baseInformation).setImageFile(source).setResolution(resolution)
            .build(project);
}

From source file:CheckBoxList.java

@SuppressWarnings("unchecked")
public java.util.List getCheckedItems() {
    java.util.List list = new java.util.ArrayList();
    DefaultListModel dlm = (DefaultListModel) getModel();
    for (int i = 0; i < dlm.size(); ++i) {
        Object obj = getModel().getElementAt(i);
        if (obj instanceof JCheckBox) {
            JCheckBox checkbox = (JCheckBox) obj;
            if (checkbox.isSelected()) {
                list.add(checkbox);//from   w  w  w  .ja  va  2 s .com
            }
        }
    }
    return list;
}

From source file:CheckBoxList.java

@SuppressWarnings("unchecked")
public int[] getCheckedIdexes() {
    java.util.List list = new java.util.ArrayList();
    DefaultListModel dlm = (DefaultListModel) getModel();
    for (int i = 0; i < dlm.size(); ++i) {
        Object obj = getModel().getElementAt(i);
        if (obj instanceof JCheckBox) {
            JCheckBox checkbox = (JCheckBox) obj;
            if (checkbox.isSelected()) {
                list.add(new Integer(i));
            }//from   www . j  a v a 2s  .  c  o  m
        }
    }

    int[] indexes = new int[list.size()];

    for (int i = 0; i < list.size(); ++i) {
        indexes[i] = ((Integer) list.get(i)).intValue();
    }

    return indexes;
}

From source file:com.excilys.ebi.gatling.recorder.ui.component.ConfigurationValidatorListener.java

public void actionPerformed(ActionEvent e) {

    boolean hasError = false;
    Border defaultBorder = frame.txtProxyHost.getBorder();

    Configuration config = Configuration.getInstance();

    if (frame.txtProxyHost.getText().equals(frame.txtProxyHost.getName()))
        frame.txtProxyHost.setText(EMPTY);
    if (frame.txtProxyPort.getText().equals(frame.txtProxyPort.getName()))
        frame.txtProxyPort.setText(EMPTY);
    if (frame.txtProxySslPort.getText().equals(frame.txtProxySslPort.getName()))
        frame.txtProxySslPort.setText(EMPTY);

    frame.tblFilters.validateCells();/*  w  w w  .  j  a v a2 s.c om*/

    // Parse local proxy port
    try {
        config.setPort(Integer.parseInt(frame.txtPort.getText()));
        frame.txtPort.setBorder(defaultBorder);
    } catch (NumberFormatException nfe) {
        logger.error("Error, while parsing proxy port...");
        frame.txtPort.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.red));
        hasError = true;
    }

    config.getProxy().setHost(StringUtils.trimToNull(frame.txtProxyHost.getText()));

    // Parse local ssl proxy port
    try {
        config.setSslPort(Integer.parseInt(frame.txtSslPort.getText()));
        frame.txtSslPort.setBorder(defaultBorder);
    } catch (NumberFormatException nfe) {
        logger.error("Error, while parsing proxy SSL port...");
        frame.txtSslPort.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.red));
        hasError = true;
    }

    config.getProxy().setHost(StringUtils.trimToNull(frame.txtProxyHost.getText()));

    // Parse outgoing proxy port
    if (!StringUtils.isEmpty(config.getProxy().getHost())) {
        try {
            config.getProxy().setPort(Integer.parseInt(frame.txtProxyPort.getText()));
            frame.txtProxyPort.setBorder(defaultBorder);
        } catch (NumberFormatException nfe) {
            logger.error("Error, while parsing outgoing proxy port... !");
            frame.txtProxyPort.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.red));
            hasError = true;
        }
    }

    // Parse outgoing ssl proxy port
    if (!StringUtils.isEmpty(config.getProxy().getHost())) {
        try {
            config.getProxy().setSslPort(Integer.parseInt(frame.txtProxySslPort.getText()));
            frame.txtProxySslPort.setBorder(defaultBorder);
        } catch (NumberFormatException nfe) {
            logger.error("Error, while parsing outgoing proxy SSL port... !");
            frame.txtProxySslPort.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.red));
            hasError = true;
        }
    }

    config.setFilterStrategy((FilterStrategy) frame.cbFilterStrategies.getSelectedItem());
    // Set urls filters into a list
    config.setPatterns(new ArrayList<Pattern>());
    for (int i = 0; i < frame.tblFilters.getRowCount(); i++)
        config.getPatterns().add((Pattern) frame.tblFilters.getPattern(i));

    // Check if a directory was entered
    config.setOutputFolder(StringUtils.trimToNull(frame.txtOutputFolder.getText()));
    if (config.getOutputFolder() == null) {
        logger.error("Error, no directory selected for results.");
        frame.txtOutputFolder.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.red));
        hasError = true;
    } else
        frame.txtOutputFolder.setBorder(defaultBorder);

    // Set selected results type into a list
    config.setResultTypes(new ArrayList<ResultType>());
    boolean tmp = false;
    for (JCheckBox cb : frame.resultTypes) {
        if (cb.isSelected()) {
            tmp = true;
            config.getResultTypes().add(ResultType.getByLabel(cb.getText()));
        }
    }

    config.setSaveConfiguration(frame.chkSavePref.isSelected());

    // set selected encoding
    config.setEncoding(Charset.class.cast(frame.cbOutputEncoding.getSelectedItem()).name());

    // If nothing was selected we add by default 'text'
    if (!tmp)
        config.getResultTypes().add(ResultType.TEXT);

    if (hasError)
        return;

    if (frame.chkSavePref.isSelected())
        ConfigurationHelper.saveToDisk();

    logConfiguration();

    getEventBus().post(new ShowRunningFrameEvent());
}

From source file:com.igormaznitsa.mindmap.exporters.PNGImageExporter.java

@Override
public void doExport(final MindMapPanel panel, final JComponent options, final OutputStream out)
        throws IOException {
    for (final Component compo : ((JPanel) options).getComponents()) {
        if (compo instanceof JCheckBox) {
            final JCheckBox cb = (JCheckBox) compo;
            if ("unfold".equalsIgnoreCase(cb.getActionCommand())) {
                flagExpandAllNodes = cb.isSelected();
            } else if ("back".equalsIgnoreCase(cb.getActionCommand())) {
                flagSaveBackground = cb.isSelected();
            }/*from  w w w .  ja  va 2s .  c  o  m*/
        }
    }

    final MindMapPanelConfig newConfig = new MindMapPanelConfig(panel.getConfiguration(), false);
    newConfig.setDrawBackground(flagSaveBackground);
    newConfig.setScale(1.0f);

    final RenderedImage image = MindMapPanel.renderMindMapAsImage(panel.getModel(), newConfig,
            flagExpandAllNodes);

    if (image == null) {
        if (out == null) {
            LOGGER.error("Can't render map as image");
            panel.getController().getDialogProvider(panel)
                    .msgError(BUNDLE.getString("PNGImageExporter.msgErrorDuringRendering"));
            return;
        } else {
            throw new IOException("Can't render image");
        }
    }

    final ByteArrayOutputStream buff = new ByteArrayOutputStream(128000);
    ImageIO.write(image, "png", buff);//NOI18N

    final byte[] imageData = buff.toByteArray();

    File fileToSaveMap = null;
    OutputStream theOut = out;
    if (theOut == null) {
        fileToSaveMap = selectFileForFileFilter(panel, BUNDLE.getString("PNGImageExporter.saveDialogTitle"),
                ".png", BUNDLE.getString("PNGImageExporter.filterDescription"),
                BUNDLE.getString("PNGImageExporter.approveButtonText"));
        fileToSaveMap = checkFileAndExtension(panel, fileToSaveMap, ".png");//NOI18N
        theOut = fileToSaveMap == null ? null
                : new BufferedOutputStream(new FileOutputStream(fileToSaveMap, false));
    }
    if (theOut != null) {
        try {
            IOUtils.write(imageData, theOut);
        } finally {
            if (fileToSaveMap != null) {
                IOUtils.closeQuietly(theOut);
            }
        }
    }
}

From source file:CheckBoxList.java

public CheckBoxList() {
    super();/* ww w . j a v  a 2 s  . c o m*/

    setModel(new DefaultListModel());
    setCellRenderer(new CheckboxCellRenderer());

    addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            int index = locationToIndex(e.getPoint());

            if (index != -1) {
                Object obj = getModel().getElementAt(index);
                if (obj instanceof JCheckBox) {
                    JCheckBox checkbox = (JCheckBox) obj;

                    checkbox.setSelected(!checkbox.isSelected());
                    repaint();
                }
            }
        }
    }

    );

    setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}

From source file:com.igormaznitsa.mindmap.plugins.exporters.PNGImageExporter.java

@Override
public void doExport(@Nonnull final MindMapPanel panel, @Nullable final JComponent options,
        @Nullable final OutputStream out) throws IOException {
    for (final Component compo : Assertions.assertNotNull(options).getComponents()) {
        if (compo instanceof JCheckBox) {
            final JCheckBox cb = (JCheckBox) compo;
            if ("unfold".equalsIgnoreCase(cb.getActionCommand())) {
                flagExpandAllNodes = cb.isSelected();
            } else if ("back".equalsIgnoreCase(cb.getActionCommand())) {
                flagSaveBackground = cb.isSelected();
            }/*from w ww  . java 2  s .c o m*/
        }
    }

    final MindMapPanelConfig newConfig = new MindMapPanelConfig(panel.getConfiguration(), false);
    newConfig.setDrawBackground(flagSaveBackground);
    newConfig.setScale(1.0f);

    final RenderedImage image = MindMapPanel.renderMindMapAsImage(panel.getModel(), newConfig,
            flagExpandAllNodes);

    if (image == null) {
        if (out == null) {
            LOGGER.error("Can't render map as image");
            panel.getController().getDialogProvider(panel)
                    .msgError(Texts.getString("PNGImageExporter.msgErrorDuringRendering"));
            return;
        } else {
            throw new IOException("Can't render image");
        }
    }

    final ByteArrayOutputStream buff = new ByteArrayOutputStream(128000);
    ImageIO.write(image, "png", buff);//NOI18N

    final byte[] imageData = buff.toByteArray();

    File fileToSaveMap = null;
    OutputStream theOut = out;
    if (theOut == null) {
        fileToSaveMap = MindMapUtils.selectFileToSaveForFileFilter(panel,
                Texts.getString("PNGImageExporter.saveDialogTitle"), ".png",
                Texts.getString("PNGImageExporter.filterDescription"),
                Texts.getString("PNGImageExporter.approveButtonText"));
        fileToSaveMap = MindMapUtils.checkFileAndExtension(panel, fileToSaveMap, ".png");//NOI18N
        theOut = fileToSaveMap == null ? null
                : new BufferedOutputStream(new FileOutputStream(fileToSaveMap, false));
    }
    if (theOut != null) {
        try {
            IOUtils.write(imageData, theOut);
        } finally {
            if (fileToSaveMap != null) {
                IOUtils.closeQuietly(theOut);
            }
        }
    }
}

From source file:EditorPaneTest.java

public EditorPaneFrame() {
    setTitle("EditorPaneTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    final Stack<String> urlStack = new Stack<String>();
    final JEditorPane editorPane = new JEditorPane();
    final JTextField url = new JTextField(30);

    // set up hyperlink listener

    editorPane.setEditable(false);/*from ww w .j  a v  a 2 s .  co m*/
    editorPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    // remember URL for back button
                    urlStack.push(event.getURL().toString());
                    // show URL in text field
                    url.setText(event.getURL().toString());
                    editorPane.setPage(event.getURL());
                } catch (IOException e) {
                    editorPane.setText("Exception: " + e);
                }
            }
        }
    });

    // set up checkbox for toggling edit mode

    final JCheckBox editable = new JCheckBox();
    editable.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            editorPane.setEditable(editable.isSelected());
        }
    });

    // set up load button for loading URL

    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                // remember URL for back button
                urlStack.push(url.getText());
                editorPane.setPage(url.getText());
            } catch (IOException e) {
                editorPane.setText("Exception: " + e);
            }
        }
    };

    JButton loadButton = new JButton("Load");
    loadButton.addActionListener(listener);
    url.addActionListener(listener);

    // set up back button and button action

    JButton backButton = new JButton("Back");
    backButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (urlStack.size() <= 1)
                return;
            try {
                // get URL from back button
                urlStack.pop();
                // show URL in text field
                String urlString = urlStack.peek();
                url.setText(urlString);
                editorPane.setPage(urlString);
            } catch (IOException e) {
                editorPane.setText("Exception: " + e);
            }
        }
    });

    add(new JScrollPane(editorPane), BorderLayout.CENTER);

    // put all control components in a panel

    JPanel panel = new JPanel();
    panel.add(new JLabel("URL"));
    panel.add(url);
    panel.add(loadButton);
    panel.add(backButton);
    panel.add(new JLabel("Editable"));
    panel.add(editable);

    add(panel, BorderLayout.SOUTH);
}