Example usage for javax.swing JToggleButton JToggleButton

List of usage examples for javax.swing JToggleButton JToggleButton

Introduction

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

Prototype

public JToggleButton() 

Source Link

Document

Creates an initially unselected toggle button without setting the text or image.

Usage

From source file:org.springframework.richclient.factory.DefaultComponentFactory.java

protected AbstractButton createNewToggleButton() {
    return new JToggleButton();
}

From source file:org.tellervo.desktop.io.ImportDialog.java

/**
 * Set up the button bar// ww  w.ja  v a2 s . c  o  m
 */
private void setupButtonBar() {
    bottombar = new JPanel();
    bottombar.setLayout(new BoxLayout(bottombar, BoxLayout.X_AXIS));

    editEntity = new JToggleButton();
    editEntity.setIcon(Builder.getIcon("lock.png", Builder.ICONS, 22));
    editEntity.setSelectedIcon(Builder.getIcon("unlock.png", Builder.ICONS, 22));
    editEntity.setBorderPainted(false);
    editEntity.setContentAreaFilled(false);
    editEntity.setFocusable(false);

    editEntity.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (!editEntity.isSelected() && hasChanged) {
                if (!warnLosingChanges()) {
                    editEntity.setSelected(true);
                    return;
                } else {
                    editEntity.setSelected(false);
                    hasChanged = false;
                }
            }
            //enableEditing(editEntity.isSelected());
        }
    });

    bottombar.add(editEntity);

    editEntityText = new JLabel(I18n.getText("general.initializing").toLowerCase());
    editEntityText.setLabelFor(editEntity);
    bottombar.add(editEntityText);

    editEntitySave = new JButton(I18n.getText("general.saveChanges"));
    editEntityCancel = new JButton(I18n.getText("general.cancel"));

    // don't let an errant enter key fire these buttons!
    editEntitySave.setDefaultCapable(false);
    editEntityCancel.setDefaultCapable(false);

    editEntitySave.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //doSave();
        }
    });

    editEntityCancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            hasChanged = false;
            editEntity.setSelected(false);
            //enableEditing(false);            
        }
    });

    bottombar.add(Box.createHorizontalGlue());
    bottombar.add(editEntitySave);
    bottombar.add(Box.createHorizontalStrut(6));
    bottombar.add(editEntityCancel);
    bottombar.add(Box.createHorizontalStrut(6));
}

From source file:org.tinymediamanager.ui.dialogs.ImageChooserDialog.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private void addImage(BufferedImage originalImage, final MediaArtwork artwork) {
    Point size = null;/*  w  w w. j a v  a 2  s .com*/

    GridBagLayout gbl = new GridBagLayout();

    switch (type) {
    case FANART:
    case CLEARART:
    case THUMB:
    case DISC:
        gbl.columnWidths = new int[] { 130 };
        gbl.rowHeights = new int[] { 180 };
        size = ImageCache.calculateSize(300, 150, originalImage.getWidth(), originalImage.getHeight(), true);
        break;

    case BANNER:
    case LOGO:
    case CLEARLOGO:
        gbl.columnWidths = new int[] { 130 };
        gbl.rowHeights = new int[] { 120 };
        size = ImageCache.calculateSize(300, 100, originalImage.getWidth(), originalImage.getHeight(), true);
        break;

    case POSTER:
    default:
        gbl.columnWidths = new int[] { 180 };
        gbl.rowHeights = new int[] { 270 };
        size = ImageCache.calculateSize(150, 250, originalImage.getWidth(), originalImage.getHeight(), true);
        break;

    }

    gbl.columnWeights = new double[] { Double.MIN_VALUE };
    gbl.rowWeights = new double[] { Double.MIN_VALUE };
    JPanel imagePanel = new JPanel();
    imagePanel.setLayout(gbl);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 3;
    gbc.insets = new Insets(5, 5, 5, 5);

    JToggleButton button = new JToggleButton();
    button.setBackground(Color.white);
    button.setUI(toggleButtonUI);
    button.setMargin(new Insets(10, 10, 10, 10));
    ImageIcon imageIcon = new ImageIcon(Scalr.resize(originalImage, Scalr.Method.BALANCED, Scalr.Mode.AUTOMATIC,
            size.x, size.y, Scalr.OP_ANTIALIAS));
    button.setIcon(imageIcon);
    button.putClientProperty("MediaArtwork", artwork);

    buttonGroup.add(button);
    buttons.add(button);
    imagePanel.add(button, gbc);

    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.anchor = GridBagConstraints.LAST_LINE_START;
    gbc.insets = new Insets(0, 5, 0, 0);

    JComboBox cb = null;
    if (artwork.getImageSizes().size() > 0) {
        cb = new JComboBox(artwork.getImageSizes().toArray());
    } else {
        cb = new JComboBox(new String[] { originalImage.getWidth() + "x" + originalImage.getHeight() });
    }
    button.putClientProperty("MediaArtworkSize", cb);
    imagePanel.add(cb, gbc);

    // should we provide an option for extrathumbs
    if (mediaType == MediaType.MOVIE && type == ImageType.FANART
            && MovieModuleManager.MOVIE_SETTINGS.isImageExtraThumbs()) {
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.anchor = GridBagConstraints.LINE_END;
        JLabel label = new JLabel("Extrathumb");
        imagePanel.add(label, gbc);

        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = 1;
        gbc.anchor = GridBagConstraints.LINE_END;
        JCheckBox chkbx = new JCheckBox();
        button.putClientProperty("MediaArtworkExtrathumb", chkbx);
        imagePanel.add(chkbx, gbc);
    }

    // should we provide an option for extrafanart
    if (mediaType == MediaType.MOVIE && type == ImageType.FANART
            && MovieModuleManager.MOVIE_SETTINGS.isImageExtraFanart()) {
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = MovieModuleManager.MOVIE_SETTINGS.isImageExtraThumbs() ? 2 : 1;
        gbc.anchor = GridBagConstraints.LINE_END;
        JLabel label = new JLabel("Extrafanart");
        imagePanel.add(label, gbc);

        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = MovieModuleManager.MOVIE_SETTINGS.isImageExtraThumbs() ? 2 : 1;
        gbc.anchor = GridBagConstraints.LINE_END;
        JCheckBox chkbx = new JCheckBox();
        button.putClientProperty("MediaArtworkExtrafanart", chkbx);
        imagePanel.add(chkbx, gbc);
    }

    /* show image button */
    gbc.gridx = 0;
    gbc.gridy++;
    gbc.anchor = GridBagConstraints.LAST_LINE_START;
    gbc.gridwidth = 3;
    gbc.insets = new Insets(0, 0, 0, 0);
    JButton btnShowImage = new JButton("<html><font color=\"#0000CF\"><u>"
            + BUNDLE.getString("image.showoriginal") + "</u></font></html>");
    btnShowImage.setBorderPainted(false);
    btnShowImage.setFocusPainted(false);
    btnShowImage.setContentAreaFilled(false);
    btnShowImage.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            ImagePreviewDialog dialog = new ImagePreviewDialog(artwork.getDefaultUrl());
            dialog.setVisible(true);
        }
    });
    imagePanel.add(btnShowImage, gbc);

    panelImages.add(imagePanel);
    panelImages.validate();
    panelImages.getParent().validate();
}

From source file:org.zaproxy.zap.extension.auth.ExtensionAuth.java

private JToggleButton getReauthenticateButton() {
    if (reauthenticateButton == null) {
        reauthenticateButton = new JToggleButton();
        reauthenticateButton.setIcon(new ImageIcon(ExtensionAuth.class.getResource(REAUTH_OFF_ICON_RESOURCE)));
        reauthenticateButton.setToolTipText(Constant.messages.getString("auth.toolbar.button.reauth.disabled"));
        reauthenticateButton.setEnabled(false); // Disable until login and one indicator flagged

        reauthenticateButton.addActionListener(new java.awt.event.ActionListener() {
            @Override//from   w w w .jav  a  2s  . c  om
            public void actionPerformed(ActionEvent e) {
                setReauthenticate(getReauthenticateButton().isSelected());
            }
        });
    }
    return reauthenticateButton;
}