Search in sources :

Example 1 with BaseMultiResolutionImage

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

the class MultiResolutionRenderingHintsTest 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);
    // base
    Color color = getImageColor(VALUE_RESOLUTION_VARIANT_BASE, mrImage, 2, 3);
    if (!getColorForScale(1).equals(color)) {
        throw new RuntimeException("Wrong base resolution variant!");
    }
    // dpi fit
    color = getImageColor(VALUE_RESOLUTION_VARIANT_DPI_FIT, mrImage, 2, 3);
    if (!getColorForScale(2).equals(color)) {
        throw new RuntimeException("Resolution variant is not based on dpi!");
    }
    // size fit
    color = getImageColor(VALUE_RESOLUTION_VARIANT_SIZE_FIT, mrImage, 2, 3);
    if (!getColorForScale(6).equals(color)) {
        throw new RuntimeException("Resolution variant is not based on" + " rendered size!");
    }
    // default
    // depends on the policies of the platform
    // just check that exception is not thrown
    getImageColor(VALUE_RESOLUTION_VARIANT_DEFAULT, mrImage, 2, 3);
}
Also used : BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage) Color(java.awt.Color) BufferedImage(java.awt.image.BufferedImage)

Example 2 with BaseMultiResolutionImage

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

the class BaseMultiResolutionImageTest method testRVSizes.

static void testRVSizes() {
    int imageSize = getSize(1);
    double[][] sizeArray = { { -imageSize, imageSize }, { 2 * imageSize, -2 * imageSize }, { Double.POSITIVE_INFINITY, imageSize }, { Double.POSITIVE_INFINITY, -imageSize }, { imageSize, Double.NEGATIVE_INFINITY }, { -imageSize, Double.NEGATIVE_INFINITY }, { Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY }, { Double.NaN, imageSize }, { imageSize, Double.NaN }, { Double.NaN, Double.NaN }, { Double.POSITIVE_INFINITY, Double.NaN } };
    for (double[] sizes : sizeArray) {
        try {
            MultiResolutionImage mrImage = new BaseMultiResolutionImage(0, createRVImage(0), createRVImage(1));
            mrImage.getResolutionVariant(sizes[0], sizes[1]);
        } catch (IllegalArgumentException ignored) {
            continue;
        }
        throw new RuntimeException("IllegalArgumentException is not thrown!");
    }
}
Also used : BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage) MultiResolutionImage(java.awt.image.MultiResolutionImage) BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage)

Example 3 with BaseMultiResolutionImage

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

the class MultiResolutionDisabledImageTest method main.

public static void main(String[] args) throws Exception {
    Image baseMRImage = new BaseMultiResolutionImage(createImage(1), createImage(2));
    testMRDisabledImage(baseMRImage);
    saveImages();
    Image toolkitMRImage = Toolkit.getDefaultToolkit().getImage(IMAGE_NAME_1X);
    if (toolkitMRImage instanceof MultiResolutionImage) {
        testMRDisabledImage(toolkitMRImage);
    }
}
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) MultiResolutionImage(java.awt.image.MultiResolutionImage) BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage)

Example 4 with BaseMultiResolutionImage

use of java.awt.image.BaseMultiResolutionImage in project tutorials by eugenp.

the class MultiResultionImageUnitTest method baseMultiResImageTest.

@Test
public void baseMultiResImageTest() {
    int baseIndex = 1;
    int length = 4;
    BufferedImage[] resolutionVariants = new BufferedImage[length];
    for (int i = 0; i < length; i++) {
        resolutionVariants[i] = createImage(i);
    }
    MultiResolutionImage bmrImage = new BaseMultiResolutionImage(baseIndex, resolutionVariants);
    List<Image> rvImageList = bmrImage.getResolutionVariants();
    assertEquals("MultiResoltion Image shoudl contain the same number of resolution variants!", rvImageList.size(), length);
    for (int i = 0; i < length; i++) {
        int imageSize = getSize(i);
        Image testRVImage = bmrImage.getResolutionVariant(imageSize, imageSize);
        assertSame("Images should be the same", testRVImage, resolutionVariants[i]);
    }
}
Also used : BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage) MultiResolutionImage(java.awt.image.MultiResolutionImage) Image(java.awt.Image) BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage) MultiResolutionImage(java.awt.image.MultiResolutionImage) BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage) Test(org.junit.Test)

Example 5 with BaseMultiResolutionImage

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

the class IconTest method createUI.

private static void createUI() throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            f = new JFrame("TrayIcon Test");
            final BaseMultiResolutionImage IMG = new BaseMultiResolutionImage(new BufferedImage[] { generateImage(1, Color.RED), generateImage(2, Color.BLUE) });
            layout = new GridBagLayout();
            mainControlPanel = new JPanel(layout);
            resultButtonPanel = new JPanel(layout);
            f.setIconImage(IMG);
            GridBagConstraints gbc = new GridBagConstraints();
            String instructions = "<html>INSTRUCTIONS:<br>" + "Check if test button icon and unity icon are both " + "blue with green border.<br><br>" + "If Icon color is blue press pass" + " else press fail.<br><br></html>";
            instructionText = new JLabel();
            instructionText.setText(instructions);
            gbc.gridx = 0;
            gbc.gridy = 0;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            mainControlPanel.add(instructionText, gbc);
            testButton = new JButton("Test");
            testButton.setActionCommand("Test");
            mainControlPanel.add(testButton, gbc);
            testButton.setIcon(new ImageIcon(IMG));
            gbc.gridx = 0;
            gbc.gridy = 0;
            resultButtonPanel.add(testButton, gbc);
            passButton = new JButton("Pass");
            passButton.setActionCommand("Pass");
            passButton.addActionListener((ActionEvent e) -> {
                latch.countDown();
                f.dispose();
            });
            failButton = new JButton("Fail");
            failButton.setActionCommand("Fail");
            failButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    latch.countDown();
                    f.dispose();
                    throw new RuntimeException("Test Failed");
                }
            });
            gbc.gridx = 1;
            gbc.gridy = 0;
            resultButtonPanel.add(passButton, gbc);
            gbc.gridx = 2;
            gbc.gridy = 0;
            resultButtonPanel.add(failButton, gbc);
            gbc.gridx = 0;
            gbc.gridy = 1;
            mainControlPanel.add(resultButtonPanel, gbc);
            f.add(mainControlPanel);
            f.setSize(400, 200);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            f.addWindowListener(new WindowAdapter() {

                @Override
                public void windowClosing(WindowEvent e) {
                    latch.countDown();
                    f.dispose();
                }
            });
        }
    });
}
Also used : JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) WindowAdapter(java.awt.event.WindowAdapter) BufferedImage(java.awt.image.BufferedImage) BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage) ActionListener(java.awt.event.ActionListener) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent)

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