Search in sources :

Example 6 with BaseMultiResolutionImage

use of java.awt.image.BaseMultiResolutionImage in project jdk8u_jdk by JetBrains.

the class BaseMultiResolutionImageTest method testBaseMRImage.

static void testBaseMRImage() {
    int baseIndex = 1;
    int length = 3;
    BufferedImage[] resolutionVariants = new BufferedImage[length];
    for (int i = 0; i < length; i++) {
        resolutionVariants[i] = createRVImage(i);
    }
    BaseMultiResolutionImage mrImage = new BaseMultiResolutionImage(baseIndex, resolutionVariants);
    List<Image> rvImageList = mrImage.getResolutionVariants();
    if (rvImageList.size() != length) {
        throw new RuntimeException("Wrong size of resolution variants list!");
    }
    for (int i = 0; i < length; i++) {
        int imageSize = getSize(i);
        Image testRVImage = mrImage.getResolutionVariant(imageSize, imageSize);
        if (testRVImage != resolutionVariants[i]) {
            throw new RuntimeException("Wrong resolution variant!");
        }
        if (rvImageList.get(i) != resolutionVariants[i]) {
            throw new RuntimeException("Wrong resolution variant!");
        }
    }
    BufferedImage baseImage = resolutionVariants[baseIndex];
    if (baseImage.getWidth() != mrImage.getWidth(null) || baseImage.getHeight() != mrImage.getHeight(null)) {
        throw new RuntimeException("Base image is wrong!");
    }
    boolean passed = false;
    try {
        rvImageList.set(0, createRVImage(10));
    } catch (Exception e) {
        passed = true;
    }
    if (!passed) {
        throw new RuntimeException("Resolution variants list is modifiable!");
    }
    passed = false;
    try {
        rvImageList.remove(0);
    } catch (Exception e) {
        passed = true;
    }
    if (!passed) {
        throw new RuntimeException("Resolution variants list is modifiable!");
    }
    passed = false;
    try {
        rvImageList.add(0, createRVImage(10));
    } catch (Exception e) {
        passed = true;
    }
    if (!passed) {
        throw new RuntimeException("Resolution variants list is modifiable!");
    }
    passed = false;
    try {
        mrImage.getGraphics();
    } catch (UnsupportedOperationException e) {
        passed = true;
    }
    if (!passed) {
        throw new RuntimeException("getGraphics() method shouldn't be supported!");
    }
}
Also used : BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage) MultiResolutionImage(java.awt.image.MultiResolutionImage) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage) BufferedImage(java.awt.image.BufferedImage)

Example 7 with BaseMultiResolutionImage

use of java.awt.image.BaseMultiResolutionImage in project jdk8u_jdk by JetBrains.

the class MultiresolutionIconTest method UI.

private void UI() {
    setUndecorated(true);
    BufferedImage img1x = generateImage(SZ / 2, C1X);
    BufferedImage img2x = generateImage(SZ, C2X);
    BaseMultiResolutionImage mri = new BaseMultiResolutionImage(new BufferedImage[] { img1x, img2x });
    Icon icon = new ImageIcon(mri);
    // hardcoded icon size for OS X (Mac OS X L&F) - see JDK-8151060
    BufferedImage tab1x = generateImage(16, C1X);
    BufferedImage tab2x = generateImage(32, C2X);
    BaseMultiResolutionImage tabMRI = new BaseMultiResolutionImage(new BufferedImage[] { tab1x, tab2x });
    Icon tabIcon = new ImageIcon(tabMRI);
    setSize((N + 1) * SZ, SZ);
    setLocation(50, 50);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().setLayout(new GridLayout(1, 1));
    JPanel p = new JPanel();
    p.setLayout(new GridLayout(1, N));
    JButton btn = new JButton(icon);
    p.add(btn);
    JToggleButton tbn = new JToggleButton(icon);
    p.add(tbn);
    JRadioButton rbn = new JRadioButton(icon);
    rbn.setHorizontalAlignment(SwingConstants.CENTER);
    p.add(rbn);
    JCheckBox cbx = new JCheckBox(icon);
    cbx.setHorizontalAlignment(SwingConstants.CENTER);
    p.add(cbx);
    lbl = new JLabel(icon);
    p.add(lbl);
    tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
    tabbedPane.addTab("", tabIcon, p);
    getContentPane().add(tabbedPane);
    setResizable(false);
    setVisible(true);
}
Also used : BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage) BufferedImage(java.awt.image.BufferedImage)

Example 8 with BaseMultiResolutionImage

use of java.awt.image.BaseMultiResolutionImage in project jdk8u_jdk by JetBrains.

the class MultiResolutionDrawImageWithTransformTest method main.

public static void main(String[] args) throws Exception {
    int length = COLORS.length;
    BufferedImage[] resolutionVariants = new BufferedImage[length];
    for (int i = 0; i < length; i++) {
        resolutionVariants[i] = createRVImage(getSize(i), COLORS[i]);
    }
    BaseMultiResolutionImage mrImage = new BaseMultiResolutionImage(resolutionVariants);
    // scale 1, transform 1, resolution variant 1
    Color color = getImageColor(mrImage, 1, 1);
    if (!getColorForScale(1).equals(color)) {
        throw new RuntimeException("Wrong resolution variant!");
    }
    // scale 1, transform 2, resolution variant 2
    color = getImageColor(mrImage, 1, 2);
    if (!getColorForScale(2).equals(color)) {
        throw new RuntimeException("Wrong resolution variant!");
    }
    // scale 2, transform 1, resolution variant 2
    color = getImageColor(mrImage, 2, 1);
    if (!getColorForScale(2).equals(color)) {
        throw new RuntimeException("Wrong resolution variant!");
    }
    // scale 2, transform 2, resolution variant 4
    color = getImageColor(mrImage, 2, 2);
    if (!getColorForScale(4).equals(color)) {
        throw new RuntimeException("Wrong resolution variant!");
    }
}
Also used : BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage) Color(java.awt.Color) BufferedImage(java.awt.image.BufferedImage)

Aggregations

BaseMultiResolutionImage (java.awt.image.BaseMultiResolutionImage)8 BufferedImage (java.awt.image.BufferedImage)7 MultiResolutionImage (java.awt.image.MultiResolutionImage)4 Image (java.awt.Image)3 Color (java.awt.Color)2 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 ImageIcon (javax.swing.ImageIcon)1 JButton (javax.swing.JButton)1 JFrame (javax.swing.JFrame)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 Test (org.junit.Test)1