Example usage for java.awt Color Color

List of usage examples for java.awt Color Color

Introduction

In this page you can find the example usage for java.awt Color Color.

Prototype

public Color(float r, float g, float b, float a) 

Source Link

Document

Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0).

Usage

From source file:Main.java

/**
 * Make a color scaled using a defined factor.
 *
 * @param color//from   w  w w.  j a v a 2  s  .  c  om
 *          the color to scale.
 * @param factor
 *          the factor to use.
 * @return the scaled color.
 */
public static Color getScaledColor(Color color, double factor) {
    if (color == null) {
        return null;
    }
    if (factor <= 1) {
        return new Color(Math.max((int) (color.getRed() * factor), 0),
                Math.max((int) (color.getGreen() * factor), 0), Math.max((int) (color.getBlue() * factor), 0),
                color.getAlpha());
    }
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.getBlue();

    int i = (int) (1.0 / (factor - 1));
    if (r == 0 && g == 0 && b == 0) {
        return new Color(i, i, i);
    }
    if (r > 0 && r < i) {
        r = i;
    }
    if (g > 0 && g < i) {
        g = i;
    }
    if (b > 0 && b < i) {
        b = i;
    }

    return new Color(Math.min((int) (r / (2 - factor)), 255), Math.min((int) (g / (2 - factor)), 255),
            Math.min((int) (b / (2 - factor)), 255));

}

From source file:ColorUtil.java

public static final Color mult(Color c, double amount) {
    return c == null ? null
            : new Color(Math.min(255, (int) (c.getRed() * amount)),
                    Math.min(255, (int) (c.getGreen() * amount)), Math.min(255, (int) (c.getBlue() * amount)),
                    c.getAlpha());//from  w  w  w.  jav a  2 s.  c o  m
}

From source file:Main.java

private static ByteBuffer convertImageData(BufferedImage bufferedImage) {
    ByteBuffer imageBuffer;//w w w  .j a v  a2s  .  co m
    WritableRaster raster;
    BufferedImage texImage;

    // for a texture
    if (bufferedImage.getColorModel().hasAlpha()) {
        raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, bufferedImage.getWidth(),
                bufferedImage.getHeight(), 4, null);
        texImage = new BufferedImage(glAlphaColorModel, raster, false, new Hashtable<Object, Object>());
    } else {
        raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, bufferedImage.getWidth(),
                bufferedImage.getHeight(), 3, null);
        texImage = new BufferedImage(glColorModel, raster, false, new Hashtable<Object, Object>());
    }

    // copy the source image into the produced image
    Graphics g = texImage.getGraphics();
    g.setColor(new Color(0f, 0f, 0f, 0f));
    g.fillRect(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight());
    g.drawImage(bufferedImage, 0, 0, null);

    // build a byte buffer from the temporary image
    // that be used by OpenGL to produce a texture.
    byte[] data = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData();

    imageBuffer = ByteBuffer.allocateDirect(data.length);
    imageBuffer.order(ByteOrder.nativeOrder());
    imageBuffer.put(data, 0, data.length);
    imageBuffer.flip();

    return imageBuffer;
}

From source file:BasicShapes.java

public void paint(Graphics g) {
    BufferedImage bimage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED);
    Graphics2D g2d = bimage.createGraphics();

    Color transparent = new Color(0, 0, 0, 0);
    g2d.setColor(transparent);/* w  w w . j a va2 s. c  om*/
    g2d.setComposite(AlphaComposite.Src);
    g2d.fill(new Rectangle2D.Float(20, 20, 100, 20));
    g2d.dispose();

}

From source file:com.technofovea.packbsp.gui2.jung.DependencyVisualizer.java

static Color trans(Color c) {
    return new Color(c.getRed(), c.getGreen(), c.getBlue(), 128);

}

From source file:Main.java

public MyTextPane() {
    super();
    setText("Hello World");
    setOpaque(false);
    setBackground(new Color(0, 0, 0, 0));
}

From source file:Main.java

public Main() {
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    // Make sure the frame is undecorated
    this.setUndecorated(true);
    this.setBackground(new Color(0, 0, 0, 0));
    this.setSize(200, 200);
    // Center it on the screen
    this.setLocationRelativeTo(null);

    this.getContentPane().setLayout(new GridLayout(0, 1));
    this.add(new TranslucentJPanel(Color.RED));
    JButton closeButton = new JButton("Close");
    this.add(closeButton);
    closeButton.addActionListener(e -> System.exit(0));
}

From source file:Overlap.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    double x = 15, y = 50, w = 70, h = 70;
    Ellipse2D e = new Ellipse2D.Double(x, y, w, h);
    g2.setStroke(new BasicStroke(8));

    Color smokeyColor = new Color(128, 128, 128, 128);
    g2.setPaint(smokeyColor);/*from w  w  w  .ja  v a2  s .co m*/
    g2.fill(e);
    g2.draw(e);

    e.setFrame(x + 100, y, w, h);
    g2.setPaint(Color.black);
    g2.draw(e);
    g2.setPaint(Color.gray);
    g2.fill(e);

    e.setFrame(x + 200, y, w, h);
    g2.setPaint(Color.gray);
    g2.fill(e);
    g2.setPaint(Color.black);
    g2.draw(e);
}

From source file:ColorUtil.java

public static Color setAlpha(Color c, int alpha) {
    return c == null ? null : new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha);
}

From source file:SplashScreen.java

License:asdf

public SplashScreen(int d) {
    duration = d;//from w  ww .  j a  v a  2s.  c o m

    JPanel content = (JPanel) getContentPane();
    content.setBackground(Color.white);
    int width = 450;
    int height = 115;
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screen.width - width) / 2;
    int y = (screen.height - height) / 2;
    setBounds(x, y, width, height);

    content.add(new JLabel("asdf"), BorderLayout.CENTER);
    Color oraRed = new Color(156, 20, 20, 255);
    content.setBorder(BorderFactory.createLineBorder(oraRed, 10));

    setVisible(true);
    try {
        Thread.sleep(duration);
    } catch (Exception e) {
    }
    setVisible(false);
}