List of usage examples for java.awt Color Color
public Color(float r, float g, float b, float a)
From source file:Main.java
@Override public void paintComponent(Graphics gr) { Color c = gr.getColor();/*from www. j ava 2 s.c om*/ setForeground(new Color(0, 0, 0, 0)); super.paintComponent(gr); setForeground(c); gr.setColor(c); Graphics2D g = (Graphics2D) gr; g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); double pw = this.getPreferredSize().width; double ph = this.getPreferredSize().height; double w = this.getSize().width; double h = this.getSize().height; g.setColor(this.getForeground()); AffineTransform stretch = AffineTransform.getScaleInstance(w / pw, h / ph); g.setTransform(stretch); g.drawString(getText(), 0, this.getFont().getSize()); }
From source file:Main.java
/** * Linear interpolation./*ww w. j av a2 s .co m*/ * @param color0 * @param color1 * @param amount * @return */ public static Color Lerp(Color color0, Color color1, double amount) { int r = (int) Lerp(color0.getRed(), color1.getRed(), amount); int g = (int) Lerp(color0.getGreen(), color1.getGreen(), amount); int b = (int) Lerp(color0.getBlue(), color1.getBlue(), amount); int a = (int) Lerp(color0.getAlpha(), color1.getAlpha(), amount); if (r > 255) r = 255; if (r < 0) r = 0; if (g > 255) g = 255; if (g < 0) g = 0; if (b > 255) b = 255; if (b < 0) b = 0; if (a > 255) a = 255; if (a < 0) a = 0; return new Color(r, g, b, a); }
From source file:ColorUtil.java
public static final Color add(Color c1, Color c2) { return c1 == null ? c2 : c2 == null ? c1//from ww w . j a va2s . c o m : new Color(Math.min(255, c1.getRed() + c2.getRed()), Math.min(255, c1.getGreen() + c2.getGreen()), Math.min(255, c1.getBlue() + c2.getBlue()), c1.getAlpha()); }
From source file:Test.java
public ApplicationWindow() { setBackground(new Color(0, 0, 0, 0)); this.setSize(200, 200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { @Override/*from ww w . j av a 2s. co m*/ protected void paintComponent(Graphics gradient) { if (gradient instanceof Graphics2D) { final int Red = 150; final int Green = 150; final int Blue = 150; Paint paint = new GradientPaint(0.0f, 0.0f, new Color(Red, Green, Blue, 0), getWidth(), getHeight(), new Color(Red, Green, Blue, 255)); Graphics2D gradient2d = (Graphics2D) gradient; gradient2d.setPaint(paint); gradient2d.fillRect(0, 0, getWidth(), getHeight()); } } }; this.setContentPane(panel); }
From source file:Main.java
/** * Returns color copy.//w w w .j a v a 2 s . c o m * * @param color * color to copy * @return color copy */ public static Color copy(final Color color) { return new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); }
From source file:PaintUtils.java
/** Paints 3 different strokes around a shape to indicate focus. * The widest stroke is the most transparent, so this achieves a nice * "glow" effect.//from w ww. j av a 2 s. com * <P>The catch is that you have to render this underneath the shape, * and the shape should be filled completely. * * @param g the graphics to paint to * @param shape the shape to outline * @param biggestStroke the widest stroke to use. */ public static void paintFocus(Graphics2D g, Shape shape, int biggestStroke) { Color focusColor = getFocusRingColor(); Color[] focusArray = new Color[] { new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 255), new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 170), new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 110) }; g.setStroke(new BasicStroke(biggestStroke)); g.setColor(focusArray[2]); g.draw(shape); g.setStroke(new BasicStroke(biggestStroke - 1)); g.setColor(focusArray[1]); g.draw(shape); g.setStroke(new BasicStroke(biggestStroke - 2)); g.setColor(focusArray[0]); g.draw(shape); g.setStroke(new BasicStroke(1)); }
From source file:org.quickserver.net.qsadmin.plugin.stats.ThermometerChart.java
public ThermometerChart(String title) { bgColor = new Color(238, 238, 230, 255); thermo1.setValue(value);//from w ww .j a v a 2 s. c o m thermo1.setBackground(bgColor); thermo1.setOutlinePaint(null); thermo1.setUnits(0); thermo1.setShowValueLines(true); thermo1.setFollowDataInSubranges(true); //thermo1.setForeground(Color.blue); thermo1.setValuePaint(Color.BLACK); setRange(0, 300); /* setSubrangeInfo(0, 0, 50, 0, 60); setSubrangeInfo(1, 50, 100, 40, 110); setSubrangeInfo(2, 110, 250, 100, 300); */ thermo1.addSubtitle(title, new Font("Dialog", Font.BOLD, 15)); thermo1.setToolTipText(title); setToolTipText(title); setLayout(new BorderLayout()); add(thermo1, BorderLayout.CENTER); }
From source file:com.github.fritaly.graphml4j.Utils.java
/** * Decodes the given hexadecimal string (like "#RRGGBBAA" or "#RRGGBB" * (whether the transparency is set to 0)) into an instance of {@link Color} * ./*from w w w . ja va 2 s.c o m*/ * * @param value * a string representing the encoded color.Can't be null. * @return a {@link Color}. */ static Color decode(String value) { Validate.notNull(value, "The given encoded value is null"); if (value.length() == 9) { final int i = Integer.decode(value).intValue(); return new Color((i >> 24) & 0xFF, (i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF); } return Color.decode(value); }
From source file:org.jfree.chart.demo.XYTitleAnnotationDemo1.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date", "Price Per Unit", xydataset, false, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); LegendTitle legendtitle = new LegendTitle(xyplot); legendtitle.setItemFont(new Font("Dialog", 0, 9)); legendtitle.setBackgroundPaint(new Color(200, 200, 255, 100)); legendtitle.setFrame(new BlockBorder(Color.white)); legendtitle.setPosition(RectangleEdge.BOTTOM); XYTitleAnnotation xytitleannotation = new XYTitleAnnotation(0.97999999999999998D, 0.02D, legendtitle, RectangleAnchor.BOTTOM_RIGHT); xytitleannotation.setMaxWidth(0.47999999999999998D); xyplot.addAnnotation(xytitleannotation); org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer(); if (xyitemrenderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseShapesFilled(true); }/* ww w . j ava 2s. c om*/ DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); ValueAxis valueaxis = xyplot.getRangeAxis(); valueaxis.setLowerMargin(0.34999999999999998D); return jfreechart; }
From source file:Utils.java
public static BufferedImage createGradientMask(int width, int height, int orientation) { // algorithm derived from Romain Guy's blog BufferedImage gradient = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = gradient.createGraphics(); GradientPaint paint = new GradientPaint(0.0f, 0.0f, new Color(1.0f, 1.0f, 1.0f, 1.0f), orientation == SwingConstants.HORIZONTAL ? width : 0.0f, orientation == SwingConstants.VERTICAL ? height : 0.0f, new Color(1.0f, 1.0f, 1.0f, 0.0f)); g.setPaint(paint);//from ww w .jav a 2 s . co m g.fill(new Rectangle2D.Double(0, 0, width, height)); g.dispose(); gradient.flush(); return gradient; }