private static BufferedImage createTestImage() { int w = 1024; int h = 768; BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g = img.createGraphics(); Color[] colors = { Color.red, Color.green, Color.blue }; float[] dist = {0.0f, 0.5f, 1.0f }; Point2D center = new Point2D.Float(0.5f * w, 0.5f * h); RadialGradientPaint p = new RadialGradientPaint(center, 0.5f * w, dist, colors); g.setPaint(p); g.fillRect(0, 0, w, h); g.dispose(); return img; }
/** * Creates paint for a vertex with given bounds and (inner) colour. */ static public Paint createPaint(Rectangle b, Color c) { // only bother with special paint if the vertex is not too small to notice if (!GRADIENT_PAINT || b.width < 10 && b.height < 10) { return c; } else { int cx = b.x + b.width / 2; int cy = b.y + b.height / 2; int fx = b.x + b.width / 3; int fy = b.y + 2 * b.height / 3; int rx = b.width - fx; int ry = b.height - fy; float r = (float) Math.sqrt(rx * rx + ry * ry); Paint newPaint = new RadialGradientPaint(cx, cy, r, fx, fy, new float[] {0f, 1f}, getGradient(c), CycleMethod.NO_CYCLE); return newPaint; } }
private static BufferedImage createSrcImage() { BufferedImage img = createImage(); Graphics2D g = img.createGraphics(); Color[] colors = { Color.red, Color.green, Color.blue }; float[] dist = {0.0f, 0.5f, 1.0f }; Point2D center = new Point2D.Float(0.5f * w, 0.5f * h); RadialGradientPaint p = new RadialGradientPaint(center, 0.5f * w, dist, colors); g.setPaint(p); g.fillRect(0, 0, w, h); g.dispose(); return img; }
public RadialLight(final float x, final float y, final float radius, final float intensity) { super(x, y, intensity); this.radius = radius; /******** DRAW THE LIGHT IMAGE **********************************************************/ final Color[] color = { new Color(0, 0, 0, intensity), new Color(0, 0, 0, 0) }; lightImage = new BufferedImage((int)(radius*2), (int)(radius*2), BufferedImage.TYPE_INT_ARGB); final Graphics2D g2d = (Graphics2D) lightImage.getGraphics(); final float[] distance = { 0f, 1f }; g2d.setPaint(new RadialGradientPaint(new Point((int)radius, (int)radius), radius, distance, color)); g2d.fillOval(0, 0, (int)(radius*2), (int)(radius*2)); g2d.dispose(); /***************************************************************************************/ Handler.lights.add(this); }
private void paintButton(Graphics g, Color[] colors) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int width = this.getWidth(); int height = this.getHeight(); Point2D center = new Point2D.Float(width / 2, height / 2); float radius = width / 2; float[] dist = { 0.0f, 0.8f }; RadialGradientPaint paint = new RadialGradientPaint(center, radius, dist, colors); g2.setPaint(paint); shape = new RoundRectangle2D.Double(0, 0, width, height, height, height); g2.fill(shape); Font defaultFont = getFont(); g2.setFont(defaultFont); g2.setColor(Color.BLACK); Rectangle2D rect = defaultFont.getStringBounds(text, g2.getFontRenderContext()); LineMetrics lineMetrics = defaultFont.getLineMetrics(text, g2.getFontRenderContext()); g2.drawString(text, (float) (width / 2 - rect.getWidth() / 2), (float) ((height / 2) + ((lineMetrics.getAscent() + lineMetrics.getDescent()) / 2 - lineMetrics.getDescent()))); }
private void paintButton(Graphics g, Color[] colors) { Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int width = this.getWidth(); int height = this.getHeight(); Point2D center = new Point2D.Float(width / 2, height / 2); float radius = width / 2; float[] dist = {0.0f, 0.8f}; RadialGradientPaint paint = new RadialGradientPaint(center, radius, dist, colors); g2.setPaint(paint); shape = new RoundRectangle2D.Double(0, 0, width, height, height, height); g2.fill(shape); Font defaultFont = getFont(); g2.setFont(defaultFont); g2.setColor(Color.BLACK); Rectangle2D rect = defaultFont.getStringBounds(text, g2.getFontRenderContext()); LineMetrics lineMetrics = defaultFont.getLineMetrics(text, g2.getFontRenderContext()); g2.drawString(text, (float)(width / 2 - rect.getWidth() / 2), (float)((height / 2) + ((lineMetrics.getAscent() + lineMetrics.getDescent()) / 2 - lineMetrics.getDescent()))); }
/** * Returns a radial gradient paint that will be used as overlay for the track or area image * to achieve some kind of a 3d effect. * @param WIDTH * @param RADIUS_FACTOR * @return a radial gradient paint that will be used as overlay for the track or area image */ protected RadialGradientPaint createArea3DEffectGradient(final int WIDTH, final float RADIUS_FACTOR) { final float[] FRACTIONS; final Color[] COLORS; FRACTIONS = new float[]{ 0.0f, 0.6f, 1.0f }; COLORS = new Color[]{ new Color(1.0f, 1.0f, 1.0f, 0.75f), new Color(1.0f, 1.0f, 1.0f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 0.3f) }; final Point2D GRADIENT_CENTER = new Point2D.Double(WIDTH / 2.0, WIDTH / 2.0); return new RadialGradientPaint(GRADIENT_CENTER, WIDTH * RADIUS_FACTOR, FRACTIONS, COLORS); }
public RadialBargraph() { super(); barGraphColor = ColorDef.RED; CENTER = new Point2D.Double(); LED_CENTER = new Point2D.Double(); LED_FRACTIONS = new float[]{ 0.0f, 1.0f }; sectionGradients = new java.util.HashMap<Section, RadialGradientPaint>(4); sectionAngles = new java.util.HashMap<Section, Point2D>(4); ledTrackStartAngle = getGaugeType().ORIGIN_CORRECTION - (0 * (getGaugeType().APEX_ANGLE / (getMaxValue() - getMinValue()))); ledTrackAngleExtend = -(getMaxValue() - getMinValue()) * (getGaugeType().APEX_ANGLE / (getMaxValue() - getMinValue())); calcBargraphTrack(); prepareBargraph(getInnerBounds().width); setLcdVisible(true); }
public RadialBargraph(final Model MODEL) { super(); setModel(MODEL); barGraphColor = ColorDef.RED; CENTER = new Point2D.Double(); LED_CENTER = new Point2D.Double(); LED_FRACTIONS = new float[]{ 0.0f, 1.0f }; sectionGradients = new java.util.HashMap<Section, RadialGradientPaint>(4); sectionAngles = new java.util.HashMap<Section, Point2D>(4); ledTrackStartAngle = getGaugeType().ORIGIN_CORRECTION - (0 * (getGaugeType().APEX_ANGLE / (getMaxValue() - getMinValue()))); ledTrackAngleExtend = -(getMaxValue() - getMinValue()) * (getGaugeType().APEX_ANGLE / (getMaxValue() - getMinValue())); calcBargraphTrack(); prepareBargraph(getGaugeBounds().width); }
/** * Creates a new instance of HighlightedButton */ public HighlightedButton(String label) { super(label); // Get the Graphics for the image Graphics2D g2d = highlight.createGraphics(); // Erase the image with a transparent background g2d.setComposite(AlphaComposite.Clear); g2d.fillRect(0, 0, HIGHLIGHT_SIZE, HIGHLIGHT_SIZE); g2d.setComposite(AlphaComposite.SrcOver); // Draw the highlight Point2D center = new Point2D.Float((float)HIGHLIGHT_SIZE / 2.0f, (float)HIGHLIGHT_SIZE / 2.0f); float radius = (float)HIGHLIGHT_SIZE / 2.0f; float[] dist = {0.0f, .85f}; Color[] colors = {Color.white, new Color(255, 255, 255, 0)}; RadialGradientPaint paint = new RadialGradientPaint(center, radius, dist, colors); g2d.setPaint(paint); g2d.fillOval(0, 0, HIGHLIGHT_SIZE, HIGHLIGHT_SIZE); g2d.dispose(); }