Search in sources :

Example 81 with Color

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);
}
Also used : Window(java.awt.Window) JWindow(javax.swing.JWindow) Graphics(java.awt.Graphics) JFrame(javax.swing.JFrame) Frame(java.awt.Frame) JWindow(javax.swing.JWindow) Color(java.awt.Color) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 82 with Color

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);
}
Also used : Window(java.awt.Window) JWindow(javax.swing.JWindow) JFrame(javax.swing.JFrame) Frame(java.awt.Frame) Color(java.awt.Color) Dimension(java.awt.Dimension) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 83 with Color

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Color(java.awt.Color) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) Icon(javax.swing.Icon) IconLoader.getTransparentIcon(com.intellij.openapi.util.IconLoader.getTransparentIcon)

Example 84 with Color

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"));
}
Also used : Color(java.awt.Color)

Example 85 with Color

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);
    }
}
Also used : ConstraintHandle(com.android.tools.sherpa.interaction.ConstraintHandle) Color(java.awt.Color)

Aggregations

Color (java.awt.Color)2973 Graphics2D (java.awt.Graphics2D)396 Font (java.awt.Font)250 BufferedImage (java.awt.image.BufferedImage)236 Dimension (java.awt.Dimension)193 JPanel (javax.swing.JPanel)193 Point (java.awt.Point)188 BasicStroke (java.awt.BasicStroke)177 ArrayList (java.util.ArrayList)173 Test (org.junit.Test)156 JLabel (javax.swing.JLabel)148 Paint (java.awt.Paint)140 Rectangle (java.awt.Rectangle)109 GradientPaint (java.awt.GradientPaint)108 Insets (java.awt.Insets)103 GridBagConstraints (java.awt.GridBagConstraints)96 IOException (java.io.IOException)96 Stroke (java.awt.Stroke)94 JScrollPane (javax.swing.JScrollPane)93 File (java.io.File)89