private static Color toSRGBColor(Color color) { float[] comps; ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB); comps = color.getRGBColorComponents(null); float[] allComps = color.getComponents(null); float alpha = allComps[allComps.length - 1]; // Alpha is on last component return new Color(sRGB, comps, alpha); }
public FlatColor(int rgb, double alpha) { Color c = new Color(rgb, false); float[] comps = c.getComponents(null); red = comps[0]; green = comps[1]; blue = comps[2]; this.alpha = alpha; }
public FlatColor(int argb, boolean hasAlpha) { Color c = new Color(argb, hasAlpha); float[] comps = c.getComponents(null); red = comps[0]; green = comps[1]; blue = comps[2]; alpha = comps[3]; }
public FlatColor(int rgb) { Color c = new Color(rgb, false); float[] comps = c.getComponents(null); red = comps[0]; green = comps[1]; blue = comps[2]; alpha = 1; }
/** * 指定した属性でJDGradientPaintを構築します. * * @param p1 ユーザー空間で最初に指定されたPoint<br> * p2 ユーザー空間で2番目に指定されたPoint<br> * ; c1 ポイントp1のカラー<br> * c2 ポイントp2のカラー<br> * cp p1からp2間の制御点 cols 制御点のカラー gTyp 塗りのタイプ */ public JDGradientPaint( Point2D p1, Point2D p2, Color c1, Color c2, float[] cp, Color[] cols, int gType) { this.p1 = p1; this.p2 = p2; this.c1 = c1; this.c2 = c2; this.controlPoints = cp; this.colors = cols; this.gType = gType; dx = (float) (p2.getX() - p1.getX()); dy = (float) (p2.getY() - p1.getY()); distance = (float) Math.sqrt(dx * dx + dy * dy); startC = new float[4]; endC = new float[4]; startC = c1.getComponents(startC); endC = c2.getComponents(endC); }
public static float[] getHSB(Color color) { float[] rgb = new float[4]; float[] hsb = new float[3]; color.getComponents(rgb); int r = (int) (rgb[0] * 256); int g = (int) (rgb[1] * 256); int b = (int) (rgb[2] * 256); Color.RGBtoHSB(r, g, b, hsb); return hsb; }
public static String getTextFromColor(java.awt.Color color) { String text = ""; if (color.equals(java.awt.Color.black)) { text = "black"; } else if (color.equals(java.awt.Color.blue)) { text = "blue"; } else if (color.equals(java.awt.Color.cyan)) { text = "cyan"; } else if (color.equals(java.awt.Color.darkGray)) { text = "darkGray"; } else if (color.equals(java.awt.Color.gray)) { text = "gray"; } else if (color.equals(java.awt.Color.green)) { text = "green"; } else if (color.equals(java.awt.Color.lightGray)) { text = "lightGray"; } else if (color.equals(java.awt.Color.magenta)) { text = "magenta"; } else if (color.equals(java.awt.Color.orange)) { text = "orange"; } else if (color.equals(java.awt.Color.pink)) { text = "pink"; } else if (color.equals(java.awt.Color.red)) { text = "red"; } else if (color.equals(java.awt.Color.white)) { text = "white"; } else if (color.equals(java.awt.Color.yellow)) { text = "yellow"; } else { float[] rgba = new float[4]; color.getComponents(rgba); text = "<red = " + rgba[0] + ", green = " + rgba[1] + ", blue = " + rgba[2] + ", alpha = " + rgba[3] + ">"; } return text; }
public FlatColor(String srgb) { if (srgb.startsWith("#")) { srgb = srgb.substring(1); } alpha = 1; if (srgb.length() == 8) { String alphaString = srgb.substring(0, 2); srgb = srgb.substring(2); alpha = ((double) (Integer.valueOf(alphaString, 16) + 1)) / 256; } int rgb = Integer.valueOf(srgb, 16); Color c = new Color(rgb, false); float[] comps = c.getComponents(null); red = comps[0]; green = comps[1]; blue = comps[2]; }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value == null) return null; RenderableObject mol_image = (RenderableObject) value; Indigo indigo = mol_image.getIndigo(); IndigoRenderer indigo_renderer = mol_image.getIndigoRenderer(); // To avoid parallel rendering (maybe will be fixed) synchronized (indigo) { indigo.setOption("render-output-format", "png"); if (mol_image == null) return null; IndigoObject indigo_obj = mol_image.getRenderableObject(); int cell_h = table.getRowHeight(row); int cell_w = table.getColumnModel().getColumn(column).getWidth(); if (isSelected) bg_color = table.getSelectionBackground(); else bg_color = table.getBackground(); float[] c = bg_color.getComponents(null); indigo.setOption("render-background-color", c[0], c[1], c[2]); if (indigo_obj == null) { image = new BufferedImage(cell_w, cell_h, BufferedImage.TYPE_INT_RGB); Graphics2D gc = image.createGraphics(); gc.setColor(bg_color); gc.fillRect(0, 0, cell_w, cell_h); gc.setColor(Color.black); gc.drawString("Cannot render", 40, (int) (cell_h / 2)); gc.drawImage(_exclamation_img.getImage(), 5, 10, null); } else { indigo.setOption("render-image-size", cell_w, cell_h); byte[] bytes = null; try { bytes = indigo_renderer.renderToBuffer(indigo_obj); // System.out.print("Render: " + call_count + "\n"); call_count++; ByteArrayInputStream bytes_is = new ByteArrayInputStream(bytes, 0, bytes.length); image = ImageIO.read(new MemoryCacheImageInputStream(bytes_is)); } catch (IOException ex) { System.err.println(">>>>" + ex.getMessage()); ex.printStackTrace(); } if (mol_image.getErrorMessageToRender() != null) { // Mark molecule somehow Graphics2D gc = image.createGraphics(); gc.setColor(Color.red); gc.drawImage(_exclamation_img.getImage(), 5, 10, null); gc.drawString( mol_image.getErrorMessageToRender(), 5 + _exclamation_img.getIconWidth() + 5, 10 + _exclamation_img.getIconHeight() / 2); } } if (hasFocus) setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); else setBorder(new EmptyBorder(1, 2, 1, 2)); return this; } }