Example usage for java.awt GridBagConstraints LAST_LINE_START

List of usage examples for java.awt GridBagConstraints LAST_LINE_START

Introduction

In this page you can find the example usage for java.awt GridBagConstraints LAST_LINE_START.

Prototype

int LAST_LINE_START

To view the source code for java.awt GridBagConstraints LAST_LINE_START.

Click Source Link

Document

Place the component in the corner of its display area where the last line of text on a page would normally start for the current ComponentOrientation .

Usage

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  va 2 s. c  om

    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:typoscript.TypoScriptPluginOptions.java

/**
 * This method is STATIC and will give you a GridBagConstraints with the required attributes
 * @param gridx Horizontal grid position of the element
 * @param gridy Vertical grid position of the element
 * @param gridwidth How many cells the element should span
 * @param gridheight How many rows the element should span
 * @param position either left, centre, right, top-left, top-right, bottom-left, bottom-right
 * @return a GridBagConstraints object with the desired attributes.
 *//* w w  w.jav  a 2  s.c om*/
public static GridBagConstraints getConstraint(int gridx, int gridy, int gridwidth, int gridheight,
        String position) {
    GridBagConstraints tempGbc = new GridBagConstraints();
    tempGbc.gridx = gridx;
    tempGbc.gridy = gridy;
    tempGbc.gridwidth = gridwidth;
    tempGbc.gridheight = gridheight;

    if (position.equals("left")) {
        tempGbc.anchor = GridBagConstraints.LINE_START;
    } else if (position.equals("centre")) {
        tempGbc.anchor = GridBagConstraints.CENTER;
    } else if (position.equals("right")) {
        tempGbc.anchor = GridBagConstraints.LINE_END;
    } else if (position.equals("top-left")) {
        tempGbc.anchor = GridBagConstraints.FIRST_LINE_START;
    } else if (position.equals("top-right")) {
        tempGbc.anchor = GridBagConstraints.FIRST_LINE_END;
    } else if (position.equals("bottom-left")) {
        tempGbc.anchor = GridBagConstraints.LAST_LINE_START;
    } else if (position.equals("bottom-right")) {
        tempGbc.anchor = GridBagConstraints.LAST_LINE_END;
    } else {
        // error
        System.out.println(
                "getConstraint was provided with an invalid position '" + position + "', returning null");
        return null;
    }

    return tempGbc;
}