List of usage examples for java.awt Color getRGB
public int getRGB()
From source file:edu.umn.cs.spatialHadoop.nasa.HDFRasterLayer.java
protected Color calculateColor(float value, float minValue, float maxValue) { Color color; if (value < minValue) { color = colors[0];// w w w . ja va 2 s . c o m } else if (value > maxValue) { color = colors[1]; } else { // Interpolate between two colors according to gradient type float ratio = (value - minValue) / (maxValue - minValue); if (gradientType == GradientType.GT_HSB) { // Interpolate between two hues float hue = hues[0] * (1.0f - ratio) + hues[1] * ratio; float saturation = saturations[0] * (1.0f - ratio) + saturations[1] * ratio; float brightness = brightnesses[0] * (1.0f - ratio) + brightnesses[1] * ratio; color = Color.getHSBColor(hue, saturation, brightness); int alpha = (int) (colors[0].getAlpha() * (1.0f - ratio) + colors[1].getAlpha() * ratio); color = new Color(color.getRGB() & 0xffffff | (alpha << 24), true); } else if (gradientType == GradientType.GT_RGB) { // Interpolate between colors int red = (int) (colors[0].getRed() * (1.0f - ratio) + colors[1].getRed() * ratio); int green = (int) (colors[0].getGreen() * (1.0f - ratio) + colors[1].getGreen() * ratio); int blue = (int) (colors[0].getBlue() * (1.0f - ratio) + colors[1].getBlue() * ratio); int alpha = (int) (colors[0].getAlpha() * (1.0f - ratio) + colors[1].getAlpha() * ratio); color = new Color(red, green, blue, alpha); } else { throw new RuntimeException("Unsupported gradient type: " + gradientType); } } return color; }
From source file:org.tellervo.desktop.prefs.Prefs.java
/** * Set the value of a preference to the specified color * @param pref// w w w .j a v a 2s. c om * @param value */ public void setColorPref(PrefKey pref, Color value) { String encoded = "#" + Integer.toHexString(value.getRGB() & 0x00ffffff); setPref(pref, encoded); }
From source file:org.tellervo.desktop.prefs.Prefs.java
/** * Use setPref(PrefKey, ...) instead/* w w w . j a v a 2 s . c om*/ * @param pref * @param value */ @Deprecated public void setColorPref(String pref, Color value) { String encoded = "#" + Integer.toHexString(value.getRGB() & 0x00ffffff); setPref(pref, encoded); }
From source file:com.ricemap.spateDB.operations.Plot.java
/** * Plots a Geometry from the library JTS into the given image. * @param graphics//from w w w. j a v a2 s .c o m * @param geom * @param fileMbr * @param imageWidth * @param imageHeight * @param scale * @param shape_color */ private static void drawJTSShape(Graphics2D graphics, Geometry geom, Prism fileMbr, int imageWidth, int imageHeight, double scale, Color shape_color) { if (geom instanceof GeometryCollection) { GeometryCollection geom_coll = (GeometryCollection) geom; for (int i = 0; i < geom_coll.getNumGeometries(); i++) { Geometry sub_geom = geom_coll.getGeometryN(i); // Recursive call to draw each geometry drawJTSShape(graphics, sub_geom, fileMbr, imageWidth, imageHeight, scale, shape_color); } } else if (geom instanceof com.vividsolutions.jts.geom.Polygon) { com.vividsolutions.jts.geom.Polygon poly = (com.vividsolutions.jts.geom.Polygon) geom; for (int i = 0; i < poly.getNumInteriorRing(); i++) { LineString ring = poly.getInteriorRingN(i); drawJTSShape(graphics, ring, fileMbr, imageWidth, imageHeight, scale, shape_color); } drawJTSShape(graphics, poly.getExteriorRing(), fileMbr, imageWidth, imageHeight, scale, shape_color); } else if (geom instanceof LineString) { LineString line = (LineString) geom; double geom_alpha = line.getLength() * scale; int color_alpha = geom_alpha > 1.0 ? 255 : (int) Math.round(geom_alpha * 255); if (color_alpha == 0) return; int[] xpoints = new int[line.getNumPoints()]; int[] ypoints = new int[line.getNumPoints()]; for (int i = 0; i < xpoints.length; i++) { double px = line.getPointN(i).getX(); double py = line.getPointN(i).getY(); // Transform a point in the polygon to image coordinates xpoints[i] = (int) Math.round((px - fileMbr.x1) * imageWidth / (fileMbr.x2 - fileMbr.x1)); ypoints[i] = (int) Math.round((py - fileMbr.y1) * imageHeight / (fileMbr.y2 - fileMbr.y1)); } // Draw the polygon graphics.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true)); graphics.drawPolyline(xpoints, ypoints, xpoints.length); } }
From source file:com.t3.model.Token.java
public void setHaloColor(Color color) { if (color != null) { haloColorValue = color.getRGB(); } else {/*w w w . j av a 2 s . c om*/ haloColorValue = null; } haloColor = color; }
From source file:com.t3.model.Token.java
public void setVisionOverlayColor(Color color) { if (color != null) { visionOverlayColorValue = color.getRGB(); } else {//from w w w.j a v a2 s .co m visionOverlayColorValue = null; } visionOverlayColor = color; }
From source file:edu.umn.cs.spatialHadoop.operations.Plot.java
/** * Plots a Geometry from the library JTS into the given image. * @param graphics/* www. java2s . c om*/ * @param geom * @param fileMbr * @param imageWidth * @param imageHeight * @param scale * @param shape_color */ private static void drawJTSShape(Graphics2D graphics, Geometry geom, Rectangle fileMbr, int imageWidth, int imageHeight, double scale, Color shape_color) { if (geom instanceof GeometryCollection) { GeometryCollection geom_coll = (GeometryCollection) geom; for (int i = 0; i < geom_coll.getNumGeometries(); i++) { Geometry sub_geom = geom_coll.getGeometryN(i); // Recursive call to draw each geometry drawJTSShape(graphics, sub_geom, fileMbr, imageWidth, imageHeight, scale, shape_color); } } else if (geom instanceof com.vividsolutions.jts.geom.Polygon) { com.vividsolutions.jts.geom.Polygon poly = (com.vividsolutions.jts.geom.Polygon) geom; for (int i = 0; i < poly.getNumInteriorRing(); i++) { LineString ring = poly.getInteriorRingN(i); drawJTSShape(graphics, ring, fileMbr, imageWidth, imageHeight, scale, shape_color); } drawJTSShape(graphics, poly.getExteriorRing(), fileMbr, imageWidth, imageHeight, scale, shape_color); } else if (geom instanceof LineString) { LineString line = (LineString) geom; double geom_alpha = line.getLength() * scale; int color_alpha = geom_alpha > 1.0 ? 255 : (int) Math.round(geom_alpha * 255); if (color_alpha == 0) return; int[] xpoints = new int[line.getNumPoints()]; int[] ypoints = new int[line.getNumPoints()]; for (int i = 0; i < xpoints.length; i++) { double px = line.getPointN(i).getX(); double py = line.getPointN(i).getY(); // Transform a point in the polygon to image coordinates xpoints[i] = (int) Math.round((px - fileMbr.x1) * imageWidth / (fileMbr.x2 - fileMbr.x1)); ypoints[i] = (int) Math.round((py - fileMbr.y1) * imageHeight / (fileMbr.y2 - fileMbr.y1)); } // Draw the polygon graphics.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true)); graphics.drawPolyline(xpoints, ypoints, xpoints.length); } }
From source file:com.jcraft.weirdx.DDXWindowImp.java
public final Graphics getGraphics(GC gc, int mask) { if (!isVisible()) { return null; }// w w w . j a va2 s .c o m if (offg == null) allocImage(); Graphics graphics = offg; if ((mask & GC.GCSubwindowMode) != 0 && (gc.attr & GC.IncludeInferiors) != 0) { graphics = getGraphics(); window.currentGC = null; } else { if (gc == window.currentGC && gc.time == window.gctime && (mask & ~window.gmask) == 0) { //System.out.println("DDXWindow skip"); return graphics; } window.gctime = gc.time; window.currentGC = gc; window.gmask = mask; } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec != null) { graphics = offg; } if (rec == null || (rec.x == 0 && rec.y == 0 && rec.width == window.width && rec.height == window.height)) { // return graphics; } else { graphics.setClip(rec.x, rec.y, rec.width, rec.height); } } if ((mask & GC.GCFunction) != 0) { Color color = window.getColormap().getColor(gc.fgPixel); if (gc.function == GC.GXxor) { window.gmask &= ~GC.GCFunction; graphics.setXORMode(new Color((color.getRGB() ^ graphics.getColor().getRGB()) & 0xffffff)); } else if (gc.function == GC.GXinvert) { window.gmask &= ~GC.GCFunction; graphics.setXORMode(window.screen.defaultColormap.getColor(window.background.pixel)); } else { graphics.setColor(color); } } if ((mask & GC.GCFont) != 0) { XFont font = gc.font; graphics.setFont(font.getFont()); } if ((mask & GC.GCLineWidth) != 0 || (mask & GC.GCLineStyle) != 0 || (mask & GC.GCCapStyle) != 0 || (mask & GC.GCJoinStyle) != 0) { } return graphics; }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java
/** * Sets the font color//from w w w . j av a 2s. c o m * @param color the color */ public void setFontColor(Color color) { ActionEvent evt = new ActionEvent(editorPane, ActionEvent.ACTION_PERFORMED, ""); Action action = new HTMLEditorKit.ForegroundAction(Integer.toString(color.getRGB()), color); action.actionPerformed(evt); }
From source file:tufts.vue.RichTextBox.java
/** @return true if hue value of Color is black, ignoring any alpha */ private boolean isBlack(Color c) { return c != null && (c.getRGB() & 0xFFFFFF) == 0; }