use of java.awt.Color in project jdk8u_jdk by JetBrains.
the class ShortHistogramTest method createTestImage.
protected BufferedImage createTestImage(int numColors) {
IndexColorModel icm = createTestICM(numColors);
int w = numColors * 10;
int h = 20;
BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm);
Graphics2D g = img.createGraphics();
for (int i = 0; i < numColors; i++) {
int rgb = icm.getRGB(i);
//System.out.printf("pixel %d, rgb %x\n", i, rgb);
g.setColor(new Color(rgb));
g.fillRect(i * 10, 0, w - i * 10, h);
}
g.dispose();
return img;
}
use of java.awt.Color in project jdk8u_jdk by JetBrains.
the class bug8016356 method main.
public static void main(String[] args) throws Exception {
// Windows only test
if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
// Retrieving top edge of Desktop
GraphicsConfiguration grConf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
Rectangle scrRect = grConf.getBounds();
Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(grConf);
scrTop = scrRect.y + scrInsets.top;
color = new Color(0, 255, 0);
SwingUtilities.invokeAndWait(() -> {
createAndShowUI();
});
try {
Robot robot = new Robot();
robot.setAutoDelay(500);
robot.setAutoWaitForIdle(true);
robot.delay(1000);
// Resizing a window to invoke Windows Snap feature
readFrameInfo();
robot.mouseMove(frLoc.x + frSize.width / 2, frLoc.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseMove(frLoc.x + frSize.width / 2, scrTop);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
// Retrieving the color of window expanded area
readFrameInfo();
Insets insets = frame.getInsets();
Color bgColor = robot.getPixelColor(frLoc.x + frSize.width / 2, frLoc.y + frSize.height - insets.bottom - 1);
frame.dispose();
if (!bgColor.equals(color)) {
throw new RuntimeException("TEST FAILED: got " + bgColor + " instead of " + color);
}
System.out.println("TEST PASSED!");
} catch (AWTException ex) {
throw new RuntimeException("TEST FAILED!");
}
}
}
use of java.awt.Color in project jdk8u_jdk by JetBrains.
the class bug8057791 method main.
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(new NimbusLookAndFeel());
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
final int listWidth = 50;
final int listHeight = 50;
final int selCellIndex = 0;
JList<String> list = new JList<String>();
list.setSize(listWidth, listHeight);
DefaultListModel<String> listModel = new DefaultListModel<String>();
listModel.add(selCellIndex, "E");
list.setModel(listModel);
list.setSelectedIndex(selCellIndex);
BufferedImage img = new BufferedImage(listWidth, listHeight, BufferedImage.TYPE_INT_ARGB);
Graphics g = img.getGraphics();
list.paint(g);
g.dispose();
Rectangle cellRect = list.getCellBounds(selCellIndex, selCellIndex);
HashSet<Color> cellColors = new HashSet<Color>();
int uniqueColorIndex = 0;
for (int x = cellRect.x; x < (cellRect.x + cellRect.width); x++) {
for (int y = cellRect.y; y < (cellRect.y + cellRect.height); y++) {
Color cellColor = new Color(img.getRGB(x, y), true);
if (cellColors.add(cellColor)) {
System.err.println(String.format("Cell color #%d: %s", uniqueColorIndex++, cellColor));
}
}
}
Color selForegroundColor = list.getSelectionForeground();
Color selBackgroundColor = list.getSelectionBackground();
if (!cellColors.contains(new Color(selForegroundColor.getRGB(), true))) {
throw new RuntimeException(String.format("Selected cell is drawn without selection foreground color '%s'.", selForegroundColor));
}
if (!cellColors.contains(new Color(selBackgroundColor.getRGB(), true))) {
throw new RuntimeException(String.format("Selected cell is drawn without selection background color '%s'.", selBackgroundColor));
}
}
});
} catch (UnsupportedLookAndFeelException | InterruptedException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
use of java.awt.Color in project jdk8u_jdk by JetBrains.
the class bug7181438 method createBufferedImage.
private static BufferedImage createBufferedImage() {
final BufferedImage bi = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_RGB);
final Graphics bg = bi.getGraphics();
//Black color and alpha = 0
bg.setColor(new Color(0, 0, 0, 0));
bg.fillRect(0, 0, SIZE, SIZE);
bg.dispose();
return bi;
}
use of java.awt.Color in project jna by java-native-access.
the class WindowUtilsTest method xtestReveal.
public void xtestReveal() throws Exception {
final int SIZE = 200;
System.setProperty("sun.java2d.noddraw", "true");
GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
Window w;
Container content;
if (true) {
JFrame frame = new JFrame(getName(), gconfig);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
content = frame.getContentPane();
w = frame;
} else {
Frame frame = JOptionPane.getRootFrame();
JWindow window = new JWindow(frame, gconfig);
content = window.getContentPane();
w = window;
}
final Window f = w;
WindowUtils.setWindowTransparent(f, true);
content.add(new JButton("Quit") {
private static final long serialVersionUID = 1L;
{
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
}, BorderLayout.SOUTH);
content.add(new JComponent() {
private static final long serialVersionUID = 1L;
public Dimension getPreferredSize() {
return new Dimension(SIZE, SIZE);
}
protected void paintComponent(Graphics graphics) {
Graphics2D g = (Graphics2D) graphics.create();
g.setComposite(AlphaComposite.Clear);
g.fillRect(0, 0, SIZE, SIZE);
g.dispose();
g = (Graphics2D) graphics.create();
Color[] colors = { new Color(0, 0, 0), new Color(0, 0, 0, 128), new Color(128, 128, 128), new Color(128, 128, 128, 128), new Color(255, 255, 255), new Color(255, 255, 255, 128) };
for (int i = 0; i < colors.length; i++) {
g.setColor(colors[i]);
g.fillRect((SIZE * i) / colors.length, 0, (SIZE + colors.length - 1) / colors.length, SIZE);
}
g.setColor(Color.red);
g.drawRect(0, 0, SIZE - 1, SIZE - 1);
g.dispose();
SwingUtilities.getWindowAncestor(this).toFront();
}
});
f.pack();
f.addMouseListener(handler);
f.addMouseMotionListener(handler);
f.setLocation(100, 100);
f.setVisible(true);
while (f.isVisible()) {
Thread.sleep(1000);
//f.repaint();
}
}
Aggregations