Example usage for java.awt Color getRGB

List of usage examples for java.awt Color getRGB

Introduction

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

Prototype

public int getRGB() 

Source Link

Document

Returns the RGB value representing the color in the default sRGB ColorModel .

Usage

From source file:com.xuggle.xuggler.UtilsTest.java

@SuppressWarnings("deprecation")
@Test//from   w w  w.ja v a  2 s  .c o  m
public void testImageToImageRandomColor() {
    int w = 50;
    int h = 50;
    Random rnd = new Random();

    // construct an image of random colors

    BufferedImage image1 = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
    for (int x = 0; x < w; ++x)
        for (int y = 0; y < h; ++y) {
            Color c = new Color(rnd.nextInt(255), rnd.nextInt(255), rnd.nextInt(255));
            image1.setRGB(x, y, c.getRGB());
        }

    // convert image1 to a picture and then back to image2

    BufferedImage image2 = Utils.videoPictureToImage(Utils.imageToVideoPicture(image1, 0));

    // test that all the pixels in image2 are the same as image1

    for (int x = 0; x < w; ++x)
        for (int y = 0; y < h; ++y) {
            int pixel1 = image1.getRGB(x, y);
            int pixel2 = image2.getRGB(x, y);
            assertTrue("color value missmatch", pixel1 == pixel2);
        }
}

From source file:url.Domain.java

public String getColor() {

    Random random = new Random();
    final float hue = random.nextFloat() + 0.5f;
    final float saturation = 0.9f;//1.0 for brilliant, 0.0 for dull
    final float luminance = 1.0f; //1.0 for brighter, 0.0 for black*/
    Color color = Color.getHSBColor(hue, saturation, luminance);

    Formatter f = new Formatter(new StringBuffer("#"));
    f.format("%06x", color.getRGB());
    f.toString();//from   w w  w.  j a  va  2  s  .c  o  m
    return f.toString();
}

From source file:edworld.pdfreader4humans.PDFReader.java

private Color groupColor(Color inkColor) {
    return new Color(Color.CYAN.getRGB() ^ inkColor.getRGB());
}

From source file:edworld.pdfreader4humans.PDFReader.java

private Color marginColor(Color inkColor) {
    return new Color(Color.YELLOW.getRGB() ^ inkColor.getRGB());
}

From source file:umich.ms.batmass.gui.viewers.map2d.components.Map2DZoomLevel.java

/**
 * Returns a Jet colormap almost like the Jet map from MatLab.
 * to white./*  w  w w  .j  a  v a  2s. c  om*/
 * @param size the size of the color palette
 * @return the color palette
 */
public int[] getJetPalette(int size) {
    int[] cm = new int[size];

    List<Color> colorPivots = baseMap.getColorPalette();

    // High contrast
    //        colorPivots.add(Color.decode("#000000")); // black
    //        colorPivots.add(Color.decode("#00007F")); // dark blue
    //        colorPivots.add(Color.decode("#007FFF")); // azure
    //        colorPivots.add(Color.decode("#FFFF00")); // yellow
    //        colorPivots.add(Color.decode("#00FFFF")); // cyan
    //        colorPivots.add(Color.decode("#FF7F00")); // orange
    //        colorPivots.add(Color.decode("#0000FF")); // blue
    //        colorPivots.add(Color.decode("#FF0000")); // red
    //        colorPivots.add(Color.decode("#7FFF7F")); // light green
    //        colorPivots.add(Color.decode("#7F0000")); // dark red

    int transCount = colorPivots.size() - 1;
    int transSize = (int) Math.ceil((double) size / (double) transCount);
    int curTrans = 0;
    int curMapPoint = 0;
    Color c1, c2;
    int r1, r2, g1, g2, b1, b2;
    float[] comp1 = new float[3];
    float[] comp2 = new float[3];
    float[] comp3 = new float[3];
    float weight;

    for (int transNum = 0; transNum < transCount; transNum++) {
        int curTransSize = Math.min(transSize, size - curMapPoint);
        c1 = colorPivots.get(transNum);
        c2 = colorPivots.get(transNum + 1);
        c1.getColorComponents(comp1);
        c2.getColorComponents(comp2);
        for (int ptTransNum = 0; ptTransNum < curTransSize; ptTransNum++) {
            weight = ((float) ptTransNum) / curTransSize;
            for (int i = 0; i < comp1.length; i++) {
                comp3[i] = (1.0f - weight) * comp1[i] + weight * comp2[i];
            }
            Color c3 = new Color(comp3[0], comp3[1], comp3[2]);
            cm[curMapPoint] = c3.getRGB();
            curMapPoint++;
        }
    }

    return cm;
}

From source file:edworld.pdfreader4humans.PDFReader.java

private Color boxColor(Color backgroundColor) {
    return new Color(Color.GRAY.getRGB() ^ backgroundColor.getRGB());
}

From source file:net.dv8tion.jda.managers.RoleManager.java

/**
 * Sets the color of this Role./*from www . java  2s  .c o  m*/
 * This change will only be applied, if {@link #update()} is called.
 * So multiple changes can be made at once.
 *
 * @param color
 *      The new color of the Role, or null to keep current one
 * @return
 *      this
 */
public RoleManager setColor(Color color) {
    checkPermission(Permission.MANAGE_ROLES);
    checkPosition();
    return setColor(color == null ? -1 : color.getRGB() & 0xFFFFFF);
}

From source file:ca.sqlpower.architect.swingui.TestPlayPenComponent.java

/**
 * Returns a new value that is not equal to oldVal. The
 * returned object will be a new instance compatible with oldVal.  
 * //from ww w  . j a v  a2s  .  c  o m
 * @param property The property that should be modified.
 * @param oldVal The existing value of the property to modify.  The returned value
 * will not equal this one at the time this method was first called.
 */
private Object getNewDifferentValue(PropertyDescriptor property, Object oldVal) throws SQLObjectException {
    Object newVal; // don't init here so compiler can warn if the
    // following code doesn't always give it a value
    if (property.getPropertyType() == String.class) {
        newVal = "new " + oldVal;
    } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) {
        if (oldVal == null) {
            newVal = new Boolean(false);
        } else {
            newVal = new Boolean(!((Boolean) oldVal).booleanValue());
        }
    } else if (property.getPropertyType() == Integer.class || property.getPropertyType() == Integer.TYPE) {
        if (oldVal == null) {
            newVal = new Integer(0);
        } else {
            newVal = new Integer(((Integer) oldVal).intValue() + 1);
        }
    } else if (property.getPropertyType() == Double.class || property.getPropertyType() == Double.TYPE) {
        if (oldVal == null) {
            newVal = new Double(0);
        } else {
            newVal = new Double(((Double) oldVal).doubleValue() + 1);
        }
    } else if (property.getPropertyType() == Color.class) {
        if (oldVal == null) {
            newVal = new Color(0xFAC157);
        } else {
            Color oldColor = (Color) oldVal;
            newVal = new Color((oldColor.getRGB() + 0xF00) % 0x1000000);
        }
    } else if (property.getPropertyType() == Font.class) {
        if (oldVal == null) {
            newVal = FontManager.getDefaultPhysicalFont();
        } else {
            Font oldFont = (Font) oldVal;
            newVal = new Font(oldFont.getFontName(), oldFont.getSize() + 2, oldFont.getStyle());
        }
    } else if (property.getPropertyType() == Point.class) {
        if (oldVal == null) {
            newVal = new Point();
        } else {
            Point oldPoint = (Point) oldVal;
            newVal = new Point(oldPoint.x + 10, oldPoint.y + 10);
        }
    } else if (property.getPropertyType() == Insets.class) {
        if (oldVal == null) {
            newVal = new Insets(0, 0, 0, 0);
        } else {
            Insets oldInsets = (Insets) oldVal;
            newVal = new Insets(oldInsets.top + 10, oldInsets.left + 10, oldInsets.bottom + 10,
                    oldInsets.right + 10);
        }
    } else if (property.getPropertyType() == Set.class) {
        newVal = new HashSet();
        if (property.getName().equals("hiddenColumns")) {
            ((Set) newVal).add(new SQLColumn());
        } else {
            ((Set) newVal).add("Test");
        }
    } else if (property.getPropertyType() == List.class) {
        newVal = new ArrayList();
        if (property.getName().equals("selectedColumns")) {
            ((List) newVal).add(new SQLColumn());
        } else {
            ((List) newVal).add("Test");
        }
    } else if (property.getPropertyType() == TablePane.class) {
        SQLTable t = new SQLTable();
        t.initFolders(true);
        newVal = new TablePane(t, pp.getContentPane());
    } else if (property.getPropertyType() == SQLTable.class) {
        newVal = new SQLTable();
        ((SQLTable) newVal).initFolders(true);
    } else if (property.getPropertyType() == Dimension.class) {
        newVal = new Dimension();
        if (oldVal != null) {
            ((Dimension) newVal).width = ((Dimension) oldVal).width + 1;
        }
    } else {
        throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type "
                + property.getPropertyType().getName() + ") in getNewDifferentValue()");
    }

    return newVal;
}

From source file:org.geoserver.catalog.SLDHandler.java

@Override
public String getStyle(StyleType type, Color color, String colorName, String layerName) {
    String template = TEMPLATES.get(type);
    String colorCode = Integer.toHexString(color.getRGB());
    colorCode = colorCode.substring(2, colorCode.length());
    return template.replace("${colorName}", colorName).replace("${colorCode}", "#" + colorCode)
            .replace("${layerName}", layerName);

}

From source file:edu.umn.cs.spatialHadoop.osm.OSMEdge.java

@Override
public void draw(Graphics g, Rectangle fileMBR, int imageWidth, int imageHeight, double scale) {
    int x1 = (int) ((this.lon1 - fileMBR.x1) * imageWidth / fileMBR.getWidth());
    int y1 = (int) ((this.lat1 - fileMBR.y1) * imageHeight / fileMBR.getHeight());
    int x2 = (int) ((this.lon2 - fileMBR.x1) * imageWidth / fileMBR.getWidth());
    int y2 = (int) ((this.lat2 - fileMBR.y1) * imageHeight / fileMBR.getHeight());
    Color shape_color = g.getColor();

    // Compute alpha to use based on edge length and image scale
    double geom_alpha = this.getLength() * scale;
    int color_alpha = geom_alpha > 1.0 ? 255 : (int) Math.round(geom_alpha * 255);
    if (color_alpha == 0)
        return;//from w w w  .  ja va  2s  .  com

    g.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true));
    g.drawLine(x1, y1, x2, y2);
}