List of usage examples for java.awt Color getRed
public int getRed()
From source file:org.jfree.eastwood.GXYPlot.java
/** * Draws the gridlines for the plot, if they are visible. * * @param g2 the graphics device./*from w ww . j ava2 s . c om*/ * @param dataArea the data area. * @param ticks the ticks. * * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List) */ protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) { // no renderer, no gridlines... if (getRenderer() == null) { return; } // draw the domain grid lines, if any... if (isDomainGridlinesVisible() && this.xAxisStepSize > 0) { Stroke gridStroke = getDomainGridlineStroke(); Paint gridPaint = getDomainGridlinePaint(); if ((gridStroke != null) && (gridPaint != null)) { ValueAxis axis = getDomainAxis(); if (axis != null) { double lower = axis.getRange().getLowerBound(); double upper = axis.getRange().getUpperBound(); double x = lower; while (x <= upper) { Paint paint = gridPaint; if ((x == lower || x == upper) && gridPaint instanceof Color) { Color c = (Color) gridPaint; paint = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha() / 3); } try { setDomainGridlinePaint(paint); getRenderer().drawDomainGridLine(g2, this, getDomainAxis(), dataArea, x); } finally { setDomainGridlinePaint(gridPaint); } x += this.xAxisStepSize; } } } } }
From source file:Main.java
public Main() { for (int i = 0; i < panels.length; i++) { final String[] labels = new String[] { "0", "1" }; final Random rand = new Random(); int index = rand.nextInt(labels.length); String randomTitle = labels[index]; final JLabel label = new JLabel(randomTitle, JLabel.CENTER); Timer lblt = new Timer(00, new ActionListener() { @Override//from w w w. j a va 2s . com public void actionPerformed(ActionEvent ae) { label.setText(labels[rand.nextInt(labels.length)]); } }); lblt.setRepeats(true); lblt.start(); label.setForeground(Color.green); label.setVerticalAlignment(JLabel.CENTER); panels[i] = new JPanel(); panels[i].setBackground(Color.BLACK); panels[i].add(label); frame.getContentPane().add(panels[i]); } frame.setLayout(new GridLayout(grid, grid)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH); frame.setVisible(true); ActionListener action = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (int i = 0; i < panels.length; i++) { Color mix = new Color(255, 255, 255); Random random = new Random(); int r = random.nextInt(255); int g = random.nextInt(255); int b = random.nextInt(255); if (mix != null) { r = (r + mix.getRed()) / 2; g = (g + mix.getGreen()) / 2; b = (b + mix.getBlue()) / 2; } Color color = new Color(r, g, b); panels[i].setBackground(color); } } }; t = new Timer(00, action); t.setRepeats(true); t.start(); }
From source file:io.github.minecraftgui.models.network.packets.PacketInitClient.java
@Override public JSONObject toJSON() { JSONObject jsonObject = new JSONObject(); JSONArray fonts = new JSONArray(); JSONArray images = new JSONArray(); JSONArray fontsToGenerate = new JSONArray(); for (String font : this.fonts) fonts.put(font);// w ww. j a va 2s .c o m for (Map.Entry pairs : this.images.entrySet()) images.put(new JSONObject().put(NetworkController.URL, pairs.getKey()).put(NetworkController.NAME, pairs.getValue())); for (Map.Entry pairs : this.fontsGenerate.entrySet()) { JSONObject font = new JSONObject(); JSONArray colorList = new JSONArray(); for (Map.Entry pairs1 : ((HashMap<Color, Integer>) pairs.getValue()).entrySet()) { JSONObject colorObj = new JSONObject(); JSONArray sizeList = new JSONArray(); Color color = (Color) pairs1.getKey(); ArrayList<Integer> sizes = (ArrayList) pairs1.getValue(); for (Integer size : sizes) sizeList.put(size); colorObj.put(NetworkController.R, color.getRed()); colorObj.put(NetworkController.G, color.getGreen()); colorObj.put(NetworkController.B, color.getBlue()); colorObj.put(NetworkController.A, color.getAlpha()); colorObj.put(NetworkController.LIST, sizeList); colorList.put(colorObj); } font.put(NetworkController.NAME, pairs.getKey()); font.put(NetworkController.LIST, colorList); fontsToGenerate.put(font); } jsonObject.put(NetworkController.FONTS, fonts); jsonObject.put(NetworkController.IMAGES, images); jsonObject.put(NetworkController.FONTS_TO_GENERATE, fontsToGenerate); return jsonObject; }
From source file:ColorGradient.java
/** * Draw a color gradient from the top of the specified component to the * bottom. Start with the start color and change smoothly to the end *//* ww w. j a v a2 s . co m*/ public void fillGradient(Component c, Graphics g, Color start, Color end) { Rectangle bounds = this.getBounds(); // How big is the component? // Get the red, green, and blue components of the start and end // colors as floats between 0.0 and 1.0. Note that the Color class // also works with int values between 0 and 255 float r1 = start.getRed() / 255.0f; float g1 = start.getGreen() / 255.0f; float b1 = start.getBlue() / 255.0f; float r2 = end.getRed() / 255.0f; float g2 = end.getGreen() / 255.0f; float b2 = end.getBlue() / 255.0f; // Figure out how much each component should change at each y value float dr = (r2 - r1) / bounds.height; float dg = (g2 - g1) / bounds.height; float db = (b2 - b1) / bounds.height; // Now loop once for each row of pixels in the component for (int y = 0; y < bounds.height; y++) { g.setColor(new Color(r1, g1, b1)); // Set the color of the row g.drawLine(0, y, bounds.width - 1, y); // Draw the row r1 += dr; g1 += dg; b1 += db; // Increment color components } }
From source file:org.geoserver.wms.wms_1_1_1.GetLegendGraphicTest.java
/** * Tests an custom legend graphic/*from w ww .j a v a2 s .com*/ */ @Test public void testCustomLegend() throws Exception { String base = "wms?service=WMS&version=1.1.1&request=GetLegendGraphic" + "&layer=sf:states&style=custom" + "&format=image/png&width=22&height=22"; BufferedImage image = getAsImage(base, "image/png"); Resource resource = getResourceLoader().get("styles/legend.png"); BufferedImage expected = ImageIO.read(resource.file()); assertEquals(getPixelColor(expected, 10, 2).getRGB(), getPixelColor(image, 10, 2).getRGB()); // test rescale base = "wms?service=WMS&version=1.1.1&request=GetLegendGraphic" + "&layer=sf:states&style=custom" + "&format=image/png&width=16&height=16"; image = getAsImage(base, "image/png"); Color expectedColor = getPixelColor(expected, 11, 11); Color actualColor = getPixelColor(image, 8, 8); assertEquals("red", expectedColor.getRed(), actualColor.getRed()); assertEquals("green", expectedColor.getGreen(), actualColor.getGreen()); assertEquals("blue", expectedColor.getBlue(), actualColor.getBlue()); assertEquals("alpha", expectedColor.getAlpha(), actualColor.getAlpha()); }
From source file:haven.Utils.java
public static Color contrast(Color col) { int max = Math.max(col.getRed(), Math.max(col.getGreen(), col.getBlue())); if (max > 128) { return (new Color(col.getRed() / 2, col.getGreen() / 2, col.getBlue() / 2, col.getAlpha())); } else if (max == 0) { return (Color.WHITE); } else {//from w w w. j a v a 2 s . c o m int f = 128 / max; return (new Color(col.getRed() * f, col.getGreen() * f, col.getBlue() * f, col.getAlpha())); } }
From source file:haven.Utils.java
public static float[] c2fa(Color c) { return (new float[] { ((float) c.getRed() / 255.0f), ((float) c.getGreen() / 255.0f), ((float) c.getBlue() / 255.0f), ((float) c.getAlpha() / 255.0f) }); }
From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java
private Color getTopLight(Color primary) { float hsbVals[] = new float[3]; Color.RGBtoHSB(primary.getRed(), primary.getGreen(), primary.getBlue(), hsbVals); hsbVals[1] = 0.3f;//w w w . j a va2 s.c om hsbVals[2] = 0.97f; return Color.getHSBColor(hsbVals[0], hsbVals[1], hsbVals[2]); }
From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java
private Color getTopDark(Color primary) { float hsbVals[] = new float[3]; Color.RGBtoHSB(primary.getRed(), primary.getGreen(), primary.getBlue(), hsbVals); hsbVals[1] = 0.9f;/*from w w w . j a v a2 s . com*/ hsbVals[2] = 0.6f; return Color.getHSBColor(hsbVals[0], hsbVals[1], hsbVals[2]); }
From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java
private Color getFrontDark(Color primary) { float hsbVals[] = new float[3]; Color.RGBtoHSB(primary.getRed(), primary.getGreen(), primary.getBlue(), hsbVals); hsbVals[1] = 1.0f;// w ww. jav a 2 s . co m hsbVals[2] = 0.5f; return Color.getHSBColor(hsbVals[0], hsbVals[1], hsbVals[2]); }