use of java.awt.Color in project jna by java-native-access.
the class WindowUtilsTest method xtestWindowTransparency.
// Expect failure on windows and x11, since transparent pixels are not
// properly captured by java.awt.Robot
public void xtestWindowTransparency() throws Exception {
if (GraphicsEnvironment.isHeadless())
return;
System.setProperty("sun.java2d.noddraw", "true");
GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
Frame root = JOptionPane.getRootFrame();
final Window background = new Window(root);
background.setBackground(Color.white);
background.setLocation(X, Y);
final JWindow transparent = new JWindow(root, gconfig);
transparent.setLocation(X, Y);
((JComponent) transparent.getContentPane()).setOpaque(false);
transparent.getContentPane().add(new JComponent() {
private static final long serialVersionUID = 1L;
public Dimension getPreferredSize() {
return new Dimension(W, H);
}
protected void paintComponent(Graphics g) {
g = g.create();
g.setColor(Color.red);
g.fillRect(getWidth() / 4, getHeight() / 4, getWidth() / 2, getHeight() / 2);
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
g.dispose();
}
});
transparent.addMouseListener(handler);
transparent.addMouseMotionListener(handler);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
background.pack();
background.setSize(new Dimension(W, H));
background.setVisible(true);
transparent.pack();
transparent.setSize(new Dimension(W, H));
transparent.setVisible(true);
transparent.toFront();
}
});
WindowUtils.setWindowTransparent(transparent, true);
//robot.delay(60000);
Color sample = robot.getPixelColor(X + W / 2, Y + H / 2);
assertEquals("Painted pixel should be opaque", Color.red, sample);
sample = robot.getPixelColor(X + 10, Y + 10);
assertEquals("Unpainted pixel should be transparent", Color.white, sample);
}
use of java.awt.Color in project jna by java-native-access.
the class WindowUtilsTest method xtestWindowAlpha.
// Expect failure on windows and x11, since transparent pixels are not
// properly captured by java.awt.Robot
public void xtestWindowAlpha() throws Exception {
if (GraphicsEnvironment.isHeadless())
return;
System.setProperty("sun.java2d.noddraw", "true");
GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
Frame root = JOptionPane.getRootFrame();
final Window background = new Window(root);
background.setBackground(Color.white);
background.setLocation(X, Y);
final Window transparent = new Window(root, gconfig);
transparent.setBackground(Color.black);
transparent.setLocation(X, Y);
WindowUtils.setWindowAlpha(transparent, .5f);
transparent.addMouseListener(handler);
transparent.addMouseMotionListener(handler);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
background.pack();
background.setSize(new Dimension(W, H));
background.setVisible(true);
transparent.pack();
transparent.setSize(new Dimension(W, H));
transparent.setVisible(true);
}
});
//robot.delay(60000);
Point where = new Point(transparent.getX() + W / 2, transparent.getY() + H / 2);
Color sample = robot.getPixelColor(where.x, where.y);
// NOTE: w32 won't sample non-opaque windows
if (System.getProperty("os.name").startsWith("Windows")) {
assertFalse("Sample not transparent (w32)", sample.equals(transparent.getBackground()));
} else {
assertEquals("Sample should be 50% fg/bg", new Color(128, 128, 128), sample);
}
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
WindowUtils.setWindowAlpha(transparent, 1f);
}
});
sample = robot.getPixelColor(where.x, where.y);
assertEquals("Window should be opaque with alpha=1f", transparent.getBackground(), sample);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
WindowUtils.setWindowAlpha(transparent, 0f);
}
});
sample = robot.getPixelColor(where.x, where.y);
assertEquals("Window should be transparent with alpha=0f", transparent.getBackground(), sample);
}
use of java.awt.Color in project intellij-community by JetBrains.
the class FileRenderer method customize.
protected void customize(SimpleColoredComponent renderer, Object value, boolean selected, boolean focused) {
int style = SimpleTextAttributes.STYLE_PLAIN;
Color color = null;
Icon icon = null;
String name = null;
String comment = null;
boolean hidden = false;
boolean valid = true;
if (value instanceof FileNode) {
FileNode node = (FileNode) value;
icon = node.getIcon();
name = node.getName();
comment = node.getComment();
hidden = node.isHidden();
valid = node.isValid();
} else if (value instanceof VirtualFile) {
VirtualFile file = (VirtualFile) value;
name = file.getName();
hidden = isFileHidden(file);
valid = file.isValid();
} else if (value != null) {
name = value.toString();
color = GRAYED;
}
if (!valid)
style |= SimpleTextAttributes.STYLE_STRIKEOUT;
if (hidden)
color = HIDDEN;
renderer.setIcon(!hidden || icon == null ? icon : getTransparentIcon(icon));
SimpleTextAttributes attributes = new SimpleTextAttributes(style, color);
if (name != null)
renderer.append(name, attributes);
if (comment != null)
renderer.append(comment, attributes);
}
use of java.awt.Color in project intellij-community by JetBrains.
the class ValueElementReaderTest method testColor.
public void testColor() throws Exception {
assertNull(read(Color.class));
assertNull(read(Color.class, null));
assertNull(read(Color.class, ""));
assertNull(read(Color.class, "Z"));
assertEquals(new Color(0x00CAFE), read(Color.class, "CAFE"));
assertEquals(new Color(0x123456), read(Color.class, "0x123456"));
assertEquals(new Color(0x345678), read(Color.class, "12345678"));
}
use of java.awt.Color in project android by JetBrains.
the class AnimatedConnection method onPaint.
@Override
public void onPaint(ViewTransform transform, Graphics2D g) {
double progress = getProgress();
int alpha = getPulsatingAlpha(progress);
Color highlight = new Color(mColor.getRed(), mColor.getGreen(), mColor.getBlue(), alpha);
g.setColor(highlight);
ConstraintHandle sourceHandle = WidgetInteractionTargets.constraintHandle(mAnchor);
ConstraintHandle targetHandle = WidgetInteractionTargets.constraintHandle(mAnchor.getTarget());
if (sourceHandle != null && targetHandle != null && progress >= 0.05) {
float p = (float) (progress * 2);
if (p > 1) {
p = 1;
}
sourceHandle.drawConnection(transform, g, mColorSet, true, false, mOriginalCreator, p);
}
}
Aggregations