private static void formatStyle( final StringBuilder builder, final SimpleTextAttributes attributes) { final Color fgColor = attributes.getFgColor(); final Color bgColor = attributes.getBgColor(); final int style = attributes.getStyle(); final int pos = builder.length(); if (fgColor != null) { builder .append("color:#") .append(Integer.toString(fgColor.getRGB() & 0xFFFFFF, 16)) .append(';'); } if (bgColor != null) { builder .append("background-color:#") .append(Integer.toString(bgColor.getRGB() & 0xFFFFFF, 16)) .append(';'); } if ((style & SimpleTextAttributes.STYLE_BOLD) != 0) { builder.append("font-weight:bold;"); } if ((style & SimpleTextAttributes.STYLE_ITALIC) != 0) { builder.append("font-style:italic;"); } if ((style & SimpleTextAttributes.STYLE_UNDERLINE) != 0) { builder.append("text-decoration:underline;"); } else if ((style & SimpleTextAttributes.STYLE_STRIKEOUT) != 0) { builder.append("text-decoration:line-through;"); } if (builder.length() > pos) { builder.insert(pos, " style=\""); builder.append('"'); } }
public static void main(String[] args) { System.out.println("enum as array:"); System.out.println(" " + Arrays.toString(Color.values()) + "\n"); System.out.println("All enum constants:"); for (Color c : Color.values()) { System.out.println(" " + c.name() + "=" + c.ordinal()); } System.out.println("\nenum from a String:"); String color = "YELLOW"; Color c = Color.valueOf(color); System.out.println( " " + c.name() + "=" + c.ordinal() + " RGB=0x" + Integer.toHexString(c.getRGB())); System.out.println("\nenum from unknown String:"); String color2 = "yellow"; try { Color c2 = Color.valueOf(color2); // throws "IllegalArgumentException" System.out.println( " " + c2.name() + "=" + c2.ordinal() + " RGB=0x" + Integer.toHexString(c2.getRGB())); } catch (IllegalArgumentException iae) { System.out.println(" \"" + color2 + "\" not found in enum."); } // Sample of mapping an int to an enum: EnumSample service = new EnumSample(); switch (Index.valueOf(service.getIndex())) { case ONE: System.out.println("ONE"); break; case TWO: System.out.println("TWO"); break; case INVALID: System.out.println("INVALID"); break; case REG: break; case THREE: break; case ZERO: break; default: break; } }
public static void addLabel(final TestFrameworkRunningModel model) { String label; int color; if (model.getRoot().isDefect()) { color = RED.getRGB(); label = ExecutionBundle.message("junit.runing.info.tests.failed.label"); } else { color = GREEN.getRGB(); label = ExecutionBundle.message("junit.runing.info.tests.passed.label"); } final TestConsoleProperties consoleProperties = model.getProperties(); String name = label + " " + consoleProperties.getConfiguration().getName(); LocalHistory.getInstance().putSystemLabel(consoleProperties.getProject(), name, color); }
public void run(ImageProcessor ip) { if (enlarge && gd.wasOKed()) synchronized (this) { if (!isEnlarged) { enlargeCanvas(); isEnlarged = true; } } if (isEnlarged) { // enlarging may have made the ImageProcessor invalid, also for the parallel // threads int slice = pfr.getSliceNumber(); if (imp.getStackSize() == 1) ip = imp.getProcessor(); else ip = imp.getStack().getProcessor(slice); } ip.setInterpolationMethod(interpolationMethod); if (fillWithBackground) { Color bgc = Toolbar.getBackgroundColor(); if (bitDepth == 8) ip.setBackgroundValue(ip.getBestIndex(bgc)); else if (bitDepth == 24) ip.setBackgroundValue(bgc.getRGB()); } else ip.setBackgroundValue(0); ip.rotate(angle); if (!gd.wasOKed()) drawGridLines(gridLines); if (isEnlarged && imp.getStackSize() == 1) { imp.changes = true; imp.updateAndDraw(); Undo.setup(Undo.COMPOUND_FILTER_DONE, imp); } }
@Override public int getColor(VisualItem item) { // get value for target attr in item if (item.canGetString(colorAttrName)) { String attrVal = item.getString(colorAttrName); Color attrValColor = catToColorMap.get(attrVal); if (attrValColor == null) { return Color.CYAN.getRGB(); } return attrValColor.getRGB(); } Color white = Color.WHITE; return white.getRGB(); }
/** * Draw labels for picking. * * @param dc Current draw context. * @param pickSupport the PickSupport instance to be used. */ protected void doPick(DrawContext dc, PickSupport pickSupport) { GL gl = dc.getGL(); Angle heading = this.rotation; double headingDegrees; if (heading != null) headingDegrees = heading.degrees; else headingDegrees = 0; int x = this.screenPoint.x; int y = this.screenPoint.y; boolean matrixPushed = false; try { if (headingDegrees != 0) { gl.glPushMatrix(); matrixPushed = true; gl.glTranslated(x, y, 0); gl.glRotated(headingDegrees, 0, 0, 1); gl.glTranslated(-x, -y, 0); } for (int i = 0; i < this.lines.length; i++) { Rectangle2D bounds = this.lineBounds[i]; double width = bounds.getWidth(); double height = bounds.getHeight(); x = this.screenPoint.x; if (this.textAlign.equals(AVKey.CENTER)) x = x - (int) (width / 2.0); else if (this.textAlign.equals(AVKey.RIGHT)) x = x - (int) width; y -= this.lineHeight; Color color = dc.getUniquePickColor(); int colorCode = color.getRGB(); PickedObject po = new PickedObject(colorCode, this.getPickedObject(), this.position, false); pickSupport.addPickableObject(po); // Draw line rectangle gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()); try { gl.glBegin(GL.GL_POLYGON); gl.glVertex3d(x, y, 0); gl.glVertex3d(x + width - 1, y, 0); gl.glVertex3d(x + width - 1, y + height - 1, 0); gl.glVertex3d(x, y + height - 1, 0); gl.glVertex3d(x, y, 0); } finally { gl.glEnd(); } y -= this.lineSpacing; } } finally { if (matrixPushed) { gl.glPopMatrix(); } } }
@Override public void writeExternal(Element element) throws WriteExternalException { List<HighlightSeverity> list = getOrderAsList(getOrderMap()); for (HighlightSeverity severity : list) { Element info = new Element(INFO_TAG); String severityName = severity.getName(); final SeverityBasedTextAttributes infoType = getAttributesBySeverity(severity); if (infoType != null) { infoType.writeExternal(info); final Color color = myRendererColors.get(severityName); if (color != null) { info.setAttribute(COLOR_ATTRIBUTE, Integer.toString(color.getRGB() & 0xFFFFFF, 16)); } element.addContent(info); } } if (myReadOrder != null && !myReadOrder.isEmpty()) { myReadOrder.writeExternal(element); } else if (!getDefaultOrder().equals(list)) { final JDOMExternalizableStringList ext = new JDOMExternalizableStringList(Collections.nCopies(getOrderMap().size(), "")); getOrderMap() .forEachEntry( new TObjectIntProcedure<HighlightSeverity>() { @Override public boolean execute(HighlightSeverity orderSeverity, int oIdx) { ext.set(oIdx, orderSeverity.getName()); return true; } }); ext.writeExternal(element); } }
private static void assertThemeUsed(ActionBarIconGenerator.Theme theme, @Nullable Color color) throws Exception { ArgumentCaptor<ActionBarIconGenerator.ActionBarOptions> argument = ArgumentCaptor.forClass(ActionBarIconGenerator.ActionBarOptions.class); ActionBarIconGenerator generator = mock(ActionBarIconGenerator.class); TemplateWizardState state = new TemplateWizardState(); AssetStudioAssetGenerator studioGenerator = new AssetStudioAssetGenerator( new TemplateWizardContextAdapter(state), generator, null, null); pickImage(state); state.put(ATTR_ASSET_TYPE, AssetType.ACTIONBAR.name()); state.put(ATTR_ASSET_THEME, theme.name()); state.put(ATTR_FOREGROUND_COLOR, color); studioGenerator.generateImages(true); verify(generator, times(1)) .generate( isNull(String.class), any(Map.class), eq(studioGenerator), argument.capture(), anyString()); assertEquals(theme, argument.getValue().theme); if (color != null && theme.equals(ActionBarIconGenerator.Theme.CUSTOM)) { assertEquals(color.getRGB(), argument.getValue().customThemeColor); } }
public static void main(String[] args) { int x = 500, y = 80; DrawingKit dk = new DrawingKit("Daffodils", 800, 800); BufferedImage pict = dk.loadPicture("daffodils.jpg"); // get pixel value at location (500, 80) int encodedPixelColor = pict.getRGB(x, y); Color pixelColor = new Color(encodedPixelColor); System.out.println(pixelColor); int red = pixelColor.getRed(); int green = pixelColor.getGreen(); int blue = pixelColor.getBlue(); // change the color of the pixel to be pure red red = 255; green = 0; blue = 0; // update the pixel color in picture Color newPixelColor = new Color(red, green, blue); int newRgbvalue = newPixelColor.getRGB(); pict.setRGB(x, y, newRgbvalue); // display the approximate location of the pixel dk.drawPicture(pict, 0, 0); BasicStroke s = new BasicStroke(3); dk.setStroke(s); Ellipse2D.Float e = new Ellipse2D.Float(x - 3, y - 3, 8, 8); dk.draw(e); dk.drawString("(600, 150)", x - 3, y - 5); }
private void setSubscriberDetails( String subscriberName, String subscriberAddress, String message) { this.name = subscriberName; this.address = subscriberAddress; Color color = messagePane.getForeground(); messagePane.setText( "<FONT COLOR=\"#" + Integer.toHexString(color.getRGB()).substring(2) + "\">" + messageString1 + "<p>" + namePrefix + name + nameSuffix + "<br>" + addressPrefix + address + addressSuffix + "<p>" + ((message != null && message.trim().length() > 0) ? messagePrefix + message + messageSuffix + "<p>" : "") + messageString2 + "</FONT>"); }
public static String getRandomHexColor() { float hue = random.nextFloat(); // sat between 0.1 and 0.3 float saturation = (random.nextInt(2000) + 1000) / 10000f; float luminance = 0.9f; Color color = Color.getHSBColor(hue, saturation, luminance); return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); }
/** * WhiteboardShapeLine constructor. * * @param id String that uniquely identifies this WhiteboardObject. * @param t number of pixels that this object (or its border) should be thick. * @param c WhiteboardShapeLine's color (or rather it's border) * @param startPoint the start coordinates of this line. * @param endPoint the end coordinates of this line. */ public WhiteboardShapeLine( String id, int t, Color c, WhiteboardPoint startPoint, WhiteboardPoint endPoint) { super(id); this.setThickness(t); setColor(c); setColor(c.getRGB()); this.endPoint = endPoint; this.startPoint = startPoint; }
public static BufferedImage render(List<Contour> contours, Color color, BufferedImage out) { for (Contour c : contours) { for (Point2D_I32 p : c.external) { out.setRGB(p.x, p.y, color.getRGB()); } } return out; }
public static void drawShapeOutline(BufferedImage img, SegmentedShape o, Color c) { int color = c.getRGB(); Vector<ShapePixel> edge = o.edgePixels; for (int i = 0; i < edge.size(); i++) { ShapePixel shapePixel = edge.elementAt(i); int x = shapePixel.x; int y = shapePixel.y; img.setRGB(x, y, color); } }
// ------------------------------------------------------------------------------------------------ // 描述: // 设计: Skyline(2001.12.29) // 实现: Skyline // 修改:setFontColor // ------------------------------------------------------------------------------------------------ void setFrontColor(Color clr) { CellFormat CF; try { CF = mBook.getCellFormat(); CF.setFontColor(clr.getRGB()); mBook.setCellFormat(CF); } catch (Exception e) { e.printStackTrace(); } }
// ------------------------------------------------------------------------------------------------ // 描述: // 设计: Skyline(2001.12.29) // 实现: Skyline // 修改: // ------------------------------------------------------------------------------------------------ void setBackColor(Color clr) { CellFormat CF; try { CF = mBook.getCellFormat(); CF.setPattern(CellFormat.ePatternSolid); CF.setPatternFG(clr.getRGB()); mBook.setCellFormat(CF); } catch (Exception e) { e.printStackTrace(); } }
public void drawTileNumC(int tileNum, int x, int y, Color c, Graphics g) { BufferedImage coloredTile = tiles[tileNum]; for (int i = 0; i < this.tW; i++) { for (int j = 0; j < this.tH; j++) { Color originalColor = new Color(coloredTile.getRGB(i, j), true); Color nc = new Color(c.getRed(), c.getGreen(), c.getBlue(), originalColor.getAlpha()); coloredTile.setRGB(i, j, nc.getRGB()); } } g.drawImage(tiles[tileNum], x, y, null); }
/** * Gets the stroke paint for the specified figure based on the attributes STROKE_GRADIENT, * STROKE_OPACITY, STROKE_PAINT and the bounds of the figure. Returns null if the figure is not * filled. */ public static Paint getStrokePaint(Figure f) { double opacity = STROKE_OPACITY.get(f); if (STROKE_GRADIENT.get(f) != null) { return STROKE_GRADIENT.get(f).getPaint(f, opacity); } Color color = STROKE_COLOR.get(f); if (color != null) { if (opacity != 1) { color = new Color((color.getRGB() & 0xffffff) | (int) (opacity * 255) << 24, true); } } return color; }
/** * Constructs a new GradientPaintcontext * * @param cm - not used * @param t - the fill transformation * @param point1 - the start fill point * @param color1 - color of the start point * @param point2 - the end fill point * @param color2 - color of the end point * @param cyclic - the indicator of cycle filling */ GradientPaintContext( ColorModel cm, AffineTransform t, Point2D point1, Color color1, Point2D point2, Color color2, boolean cyclic) { this.cyclic = cyclic; this.cm = ColorModel.getRGBdefault(); c1 = color1.getRGB(); c2 = color2.getRGB(); double px = point2.getX() - point1.getX(); double py = point2.getY() - point1.getY(); Point2D p = t.transform(point1, null); Point2D bx = new Point2D.Double(px, py); Point2D by = new Point2D.Double(py, -px); t.deltaTransform(bx, bx); t.deltaTransform(by, by); double vec = bx.getX() * by.getY() - bx.getY() * by.getX(); if (Math.abs(vec) < ZERO) { dx = dy = delta = 0; table = new int[1]; table[0] = c1; } else { double mult = LOOKUP_SIZE * 256 / vec; dx = (int) (by.getX() * mult); dy = (int) (by.getY() * mult); delta = (int) ((p.getX() * by.getY() - p.getY() * by.getX()) * mult); createTable(); } }
@Override public String toString(TextStyle ts) { StringBuilder obj = new StringBuilder(); // Store font info Font f = ts.getFont(); if (f != null) { obj.append(f.getFontName(Locale.ROOT)); if (f.getStyle() != Font.PLAIN) { obj.append('-'); if ((f.getStyle() & Font.BOLD) == Font.BOLD) { obj.append("bold"); } if ((f.getStyle() & Font.ITALIC) == Font.ITALIC) { obj.append("italic"); } } obj.append('-'); obj.append(f.getSize()); } obj.append(';'); // Store foreground Color fg = ts.getForeground(); if (fg != null) { obj.append(fg.getRGB()); } obj.append(';'); // Store background Color bg = ts.getBackground(); if (bg != null) { obj.append(bg.getRGB()); } return obj.toString(); }
@Override public BufferedImage convert(BufferedImage input) { BufferedImage output = new BufferedImage(input.getWidth(), input.getHeight(), input.getType()); for (int x = 0; x < input.getWidth(); x++) { for (int y = 0; y < input.getHeight(); y++) { Color color = new Color(input.getRGB(x, y)); int level = (color.getRed() + color.getBlue() + color.getGreen()) / 3; Color grey = new Color(level, level, level); output.setRGB(x, y, grey.getRGB()); } } return output; }
/** * Send State (content on WhiteBoard) to all members of Group * * @param copy */ protected void sendOwnState(final Map<Point, Color> copy) { if (copy == null) return; for (Point point : copy.keySet()) { // we don't need the color: it is our draw_color anyway DrawCommand comm = new DrawCommand(DrawCommand.DRAW, point.x, point.y, drawColor.getRGB()); try { byte[] buf = Util.streamableToByteBuffer(comm); if (use_unicasts) sendToAll(buf); else channel.send(new Message(null, buf)); } catch (Exception ex) { System.err.println(ex); } } }
public void updateColor(Color c, Object source) { // record colour for the object rgb = c.getRGB(); if (source != red && source != green && source != blue) { red.setIntValue((rgb & 0xff0000) >> 16); green.setIntValue((rgb & 0xff00) >> 8); blue.setIntValue((rgb & 0xff)); hexText.setText("0x" + String.format("%06x", rgb & 0xffffff)); } colorSample.setBackground(c); colorSample.repaint(); }
public void overlay() { for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { // System.out.println(nonMax.getRGB(x,y)); if (nonMax.getRGB(x, y) != -1) { int rgb = img.getRGB(x, y); Color color = new Color(rgb); Color res = new Color(255, color.getGreen(), color.getBlue()); img.setRGB(x, y, res.getRGB()); } } } ImageIcon icon1 = new ImageIcon(img); lbl1.setIcon(icon1); }
private void writeColors(Element colorElements) { List<ColorKey> list = new ArrayList<ColorKey>(myColorsMap.keySet()); Collections.sort(list); for (ColorKey key : list) { if (haveToWrite(key)) { Color value = myColorsMap.get(key); Element element = new Element(OPTION_ELEMENT); element.setAttribute(NAME_ATTR, key.getExternalName()); element.setAttribute( VALUE_ELEMENT, value != null ? Integer.toString(value.getRGB() & 0xFFFFFF, 16) : ""); colorElements.addContent(element); } } }
/** * \ Draw saved State (color dots on panel) on WhiteBoard * * @param outstream * @throws IOException */ public void writeState(OutputStream outstream) throws IOException { if (state == null) return; synchronized (state) { DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(outstream)); // DataOutputStream dos=new DataOutputStream(outstream); dos.writeInt(state.size()); for (Map.Entry<Point, Color> entry : state.entrySet()) { Point point = entry.getKey(); Color col = entry.getValue(); dos.writeInt(point.x); dos.writeInt(point.x); dos.writeInt(col.getRGB()); } dos.flush(); System.out.println("wrote " + state.size() + " elements"); } }
/** * Makes the Mandelbrot image. * * @param width the width * @parah height the height * @return the image */ public BufferedImage makeMandelbrot(int width, int height) { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); WritableRaster raster = image.getRaster(); ColorModel model = image.getColorModel(); Color fractalColor = Color.red; int argb = fractalColor.getRGB(); Object colorData = model.getDataElements(argb, null); for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { double a = XMIN + i * (XMAX - XMIN) / width; double b = YMIN + j * (YMAX - YMIN) / height; if (!escapesToInfinity(a, b)) raster.setDataElements(i, j, colorData); } return image; }
/** * Sets the current color. This results in a selection of a crayon, if a crayon with the same RGB * values exists. */ public void setColor(Color newValue) { Color oldValue = color; color = newValue; Crayon newSelectedCrayon = null; int newRGB = newValue.getRGB() & 0xffffff; for (int i = 0; i < crayons.length; i++) { if ((crayons[i].color.getRGB() & 0xffffff) == newRGB) { newSelectedCrayon = crayons[i]; } } if (newSelectedCrayon != selectedCrayon) { selectedCrayon = newSelectedCrayon; repaint(); } firePropertyChange("Color", oldValue, newValue); }
@Override public void setOpaque(boolean isOpaque) { CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque); boolean isTextured = (peer == null) ? false : peer.isTextured(); if (!isTextured) { if (!isOpaque) { CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), 0); } else if (peer != null) { Color color = peer.getBackground(); if (color != null) { int rgb = color.getRGB(); CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), rgb); } } } // This is a temporary workaround. Looks like after 7124236 will be fixed // the correct place for invalidateShadow() is CGLayer.drawInCGLContext. SwingUtilities.invokeLater(this::invalidateShadow); }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value != null && highlight(table, value, isSelected, hasFocus, row, column)) { if (isSelected) { comp.setBackground(new Color((HIGHLIGHT_COLOR.getRGB() ^ comp.getBackground().getRGB()))); comp.setForeground(new Color(Color.BLACK.getRGB() ^ comp.getForeground().getRGB())); } else { comp.setBackground(HIGHLIGHT_COLOR); comp.setForeground(Color.BLACK); } } else { if (!isSelected) { comp.setBackground(Color.WHITE); comp.setForeground(Color.BLACK); } } return comp; }