Example usage for javax.swing JToggleButton putClientProperty

List of usage examples for javax.swing JToggleButton putClientProperty

Introduction

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

Prototype

public final void putClientProperty(Object key, Object value) 

Source Link

Document

Adds an arbitrary key/value "client property" to this component.

Usage

From source file:ca.sqlpower.wabit.swingui.chart.ChartPanel.java

/**
 * Subroutine of {@link #buildUI()}. Makes a chart type toggle button and
 * adds it to the button group.//from   w  ww  .  jav a  2  s .co  m
 * 
 * @param caption
 *            The text to appear under the button
 * @param type
 *            The type of chart the buttons should select
 * @param icon
 *            The icon for the button
 * @param fontSize
 *            the font size for the toggle buttons. The default font size of
 *            the toggle buttons are different than the default font size of
 *            JButtons on some platforms. This value should be equal to the
 *            JButton font size. This is a float as deriving fonts with a size
 *            takes a float.
 * @return A button properly configured for the new-look Wabit toolbar.
 */
private JToggleButton makeChartTypeButton(String caption, ChartType type, Icon icon, float fontSize) {
    JToggleButton b = new JToggleButton(caption, icon);
    b.putClientProperty(CHART_TYPE_PROP_KEY, type);
    chartTypeButtonGroup.add(b);

    b.setVerticalTextPosition(SwingConstants.BOTTOM);
    b.setHorizontalTextPosition(SwingConstants.CENTER);

    // Removes button borders on OS X 10.5
    b.putClientProperty("JButton.buttonType", "toolbar");

    b.addActionListener(genericActionListener);

    b.setFont(b.getFont().deriveFont(fontSize));

    return b;
}

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

@SuppressWarnings({ "unchecked", "rawtypes" })
private void addImage(BufferedImage originalImage, final MediaArtwork artwork) {
    Point size = null;// ww  w.  j a va2s. co m

    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.ut.biolab.medsavant.client.view.LoginView.java

/** This method is called from within the constructor to
 * initialize the form.//from   w w w  . j ava2 s.  c o m
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;

    titlePanel = new javax.swing.JPanel();
    userField = new javax.swing.JTextField();
    passwordField = new javax.swing.JPasswordField();
    spiralPanel = new javax.swing.JPanel();
    versionLabel = new javax.swing.JLabel();
    javax.swing.JLabel userLabel = new javax.swing.JLabel();
    javax.swing.JLabel passwordLabel = new javax.swing.JLabel();
    javax.swing.JToggleButton button_settings = new javax.swing.JToggleButton();
    detailsPanel = new javax.swing.JPanel();
    javax.swing.JLabel hostLabel = new javax.swing.JLabel();
    hostField = new javax.swing.JTextField();
    javax.swing.JLabel portLabel = new javax.swing.JLabel();
    portField = new javax.swing.JTextField();
    javax.swing.JButton dbCreateButton = new javax.swing.JButton();
    databaseField = new javax.swing.JTextField();
    javax.swing.JLabel databaseLabel = new javax.swing.JLabel();
    javax.swing.JButton dbRemoveButton = new javax.swing.JButton();
    loginButton = new javax.swing.JButton();
    progressSigningIn = new javax.swing.JProgressBar();

    setLayout(new java.awt.GridBagLayout());

    titlePanel.setBackground(new java.awt.Color(255, 255, 255));
    titlePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(6, 6, 6, 6));
    titlePanel.setMaximumSize(new java.awt.Dimension(400, 32767));
    titlePanel.setMinimumSize(new java.awt.Dimension(400, 800));
    titlePanel.setOpaque(false);

    userField.setColumns(25);
    userField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    userField.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            userFieldKeyPressed(evt);
        }
    });

    passwordField.setColumns(25);
    passwordField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    passwordField.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            passwordFieldKeyPressed(evt);
        }
    });

    spiralPanel.setPreferredSize(new java.awt.Dimension(150, 150));

    javax.swing.GroupLayout spiralPanelLayout = new javax.swing.GroupLayout(spiralPanel);
    spiralPanel.setLayout(spiralPanelLayout);
    spiralPanelLayout.setHorizontalGroup(spiralPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));
    spiralPanelLayout.setVerticalGroup(spiralPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 150, Short.MAX_VALUE));

    versionLabel.setFont(versionLabel.getFont());
    versionLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    versionLabel.setText("version information");

    userLabel.setFont(new java.awt.Font("Helvetica", 0, 12)); // NOI18N
    userLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    userLabel.setText("USERNAME");

    passwordLabel.setFont(new java.awt.Font("Helvetica", 0, 12)); // NOI18N
    passwordLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    passwordLabel.setText("PASSWORD");

    button_settings.setText("Connection Settings");
    button_settings.putClientProperty("JButton.buttonType", "textured");
    button_settings.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            button_settingsActionPerformed(evt);
        }
    });

    detailsPanel.setBackground(new java.awt.Color(204, 204, 204));
    detailsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Connection Settings",
            javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
    detailsPanel.setName("Connection Settings"); // NOI18N
    detailsPanel.setOpaque(false);

    hostLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    hostLabel.setText("SERVER ADDRESS");

    hostField.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
    hostField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    hostField.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            hostFieldKeyPressed(evt);
        }
    });

    portLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    portLabel.setText("SERVER PORT");

    portField.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
    portField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    portField.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            portFieldKeyPressed(evt);
        }
    });

    dbCreateButton.setText("Create Database");
    dbCreateButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            dbCreateButtonActionPerformed(evt);
        }
    });

    databaseField.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
    databaseField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    databaseField.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            databaseFieldKeyPressed(evt);
        }
    });

    databaseLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    databaseLabel.setText("DATABASE NAME");

    dbRemoveButton.setText("Remove Database");
    dbRemoveButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            dbRemoveButtonActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout detailsPanelLayout = new javax.swing.GroupLayout(detailsPanel);
    detailsPanel.setLayout(detailsPanelLayout);
    detailsPanelLayout.setHorizontalGroup(detailsPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(databaseLabel, javax.swing.GroupLayout.Alignment.TRAILING,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(detailsPanelLayout.createSequentialGroup().addContainerGap().addGroup(detailsPanelLayout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(hostLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(hostField).addComponent(portField)
                    .addComponent(portLabel, javax.swing.GroupLayout.Alignment.TRAILING,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                            Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                            detailsPanelLayout.createSequentialGroup().addComponent(dbRemoveButton)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(dbCreateButton))
                    .addComponent(databaseField, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addContainerGap()));
    detailsPanelLayout.setVerticalGroup(detailsPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(detailsPanelLayout.createSequentialGroup().addComponent(hostLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(hostField, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(portLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(portField, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(databaseLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(databaseField, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(dbCreateButton).addComponent(dbRemoveButton))));

    loginButton.setBackground(new java.awt.Color(0, 0, 0));
    loginButton.setText("Log In");
    loginButton.putClientProperty("JButton.buttonType", "textured");
    loginButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            loginButtonActionPerformed(evt);
        }
    });

    progressSigningIn.setIndeterminate(true);

    javax.swing.GroupLayout titlePanelLayout = new javax.swing.GroupLayout(titlePanel);
    titlePanel.setLayout(titlePanelLayout);
    titlePanelLayout.setHorizontalGroup(titlePanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(versionLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(spiralPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)
            .addComponent(detailsPanel, javax.swing.GroupLayout.Alignment.TRAILING,
                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(titlePanelLayout.createSequentialGroup()
                    .addGroup(titlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(userLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(titlePanelLayout.createSequentialGroup().addContainerGap()
                                    .addGroup(titlePanelLayout
                                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(button_settings).addComponent(userField,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE, 201,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(0, 0, Short.MAX_VALUE)))
                    .addGroup(titlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(titlePanelLayout.createSequentialGroup().addGap(6, 6, 6).addComponent(
                                    passwordLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 189,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, titlePanelLayout
                                    .createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(titlePanelLayout
                                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                    titlePanelLayout.createSequentialGroup()
                                                            .addComponent(progressSigningIn,
                                                                    javax.swing.GroupLayout.PREFERRED_SIZE, 26,
                                                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                                                            .addPreferredGap(
                                                                    javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                            .addComponent(loginButton))
                                            .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                    197, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addContainerGap()))));
    titlePanelLayout.setVerticalGroup(titlePanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, titlePanelLayout.createSequentialGroup()
                    .addComponent(spiralPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(versionLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(titlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(userLabel).addComponent(passwordLabel))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(titlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(userField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(titlePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(loginButton)
                            .addComponent(progressSigningIn, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(button_settings))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(detailsPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)));

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridwidth = 3;
    gridBagConstraints.gridheight = 3;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.insets = new java.awt.Insets(45, 45, 45, 45);
    add(titlePanel, gridBagConstraints);
}