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);
}
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!");
}
}
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);
}
}
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]);
}
}
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();
}
});
}
});
}
Aggregations