Examples of GradientPaint


Examples of java.awt.GradientPaint

            stream.writeObject(paint.getClass());
            if (paint instanceof Serializable) {
                stream.writeObject(paint);
            }
            else if (paint instanceof GradientPaint) {
                final GradientPaint gp = (GradientPaint) paint;
                stream.writeFloat((float) gp.getPoint1().getX());
                stream.writeFloat((float) gp.getPoint1().getY());
                stream.writeObject(gp.getColor1());
                stream.writeFloat((float) gp.getPoint2().getX());
                stream.writeFloat((float) gp.getPoint2().getY());
                stream.writeObject(gp.getColor2());
                stream.writeBoolean(gp.isCyclic());
            }
        }
        else {
            stream.writeBoolean(true);
        }
View Full Code Here

Examples of java.awt.GradientPaint

     * Serialize a <code>GradientPaint</code>, restore it, and check for
     * equality.
     */
    public void testGradientPaintSerialization() {

        final Paint p1 = new GradientPaint(0.0f, 0.0f, Color.blue,
                100.0f, 200.0f, Color.red);
        Paint p2 = null;

        try {
            final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            final ObjectOutputStream out = new ObjectOutputStream(buffer);
            SerialUtilities.writePaint(p1, out);
            out.close();

            final ByteArrayInputStream bias = new ByteArrayInputStream(
                    buffer.toByteArray());
            final ObjectInputStream in = new ObjectInputStream(bias);
            p2 = SerialUtilities.readPaint(in);
            in.close();
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        // we want to check that the two objects are equal, but can't rely on
        // GradientPaint's equals() method because it is just the default
        // method inherited from Object...
        final GradientPaint gp1 = (GradientPaint) p1;
        final GradientPaint gp2 = (GradientPaint) p2;
        assertEquals(gp1.getColor1(), gp2.getColor1());
        assertEquals(gp1.getPoint1(), gp2.getPoint1());
        assertEquals(gp1.getColor2(), gp2.getColor2());
        assertEquals(gp1.getPoint2(), gp2.getPoint2());
        assertEquals(gp1.isCyclic(), gp2.isCyclic());

    }
View Full Code Here

Examples of java.awt.GradientPaint

    Graphics2D g = (Graphics2D) graphics.create();
    try {
      g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
      Color startingColor = look.colors().shadow().brighter().brighter();
      Color endingColor = look.colors().shadow().darker();
      g.setPaint(new GradientPaint(0, 0, startingColor, 0, b.getHeight(), endingColor));
      g.fillRect(1, 1, b.getWidth()-2, b.getHeight()-2);
    } finally {
      g.dispose();
    }
  }
View Full Code Here

Examples of java.awt.GradientPaint

  }
 
  private void paintButton(Graphics g, Dimension size, Color startColor, Color endColor) {
    Graphics2D g2d = createGraphics(g);
    try {
      g2d.setPaint(new GradientPaint(0, 0, startColor, 0, size.height, endColor));
      g2d.fillRoundRect(0, 0, size.width-1, size.height-1, 9, 9);
    } finally {
      g2d.dispose();
    }
  }
View Full Code Here

Examples of java.awt.GradientPaint

    double y = ellipseHeight * -0.55;
    Ellipse2D shape = new Ellipse2D.Double(x, y, ellipseWidth, ellipseHeight);
    Graphics2D graphics = image.createGraphics();
    try {
      graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      graphics.setPaint(new GradientPaint(0f, 0f, bright.brighter(), 0f, (float)shape.getHeight(), dark.brighter()));
      graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f));
      graphics.fill(shape);
    } finally {
      graphics.dispose();
    }
View Full Code Here

Examples of java.awt.GradientPaint

  }

  private void paintGradient(Color start, Color end, int y1, int y2) {
    Graphics2D graphics = image.createGraphics();
    try {
      graphics.setPaint(new GradientPaint(0, y1, start, 0, y2, end));
      graphics.fillRect(0, y1, width, y2);
    } finally {
      graphics.dispose();
    }
  }
View Full Code Here

Examples of java.awt.GradientPaint

        int y = 0;
        int lineHeight = (int) ((value / max) * chartHeight);

        // paint the background
        if (bgPaint == null) {
            bgPaint = new GradientPaint(0, 0, bgGradientEndColor,
                    0, chartHeight, bgGradientStartColor);
        }
        g2.setPaint(bgPaint);
        g2.fillRect(0, 0, currentWidth, currentHeight);

        // draw the text label
        x += leftIndent;
        y += topIndent + labelHeight / 2;
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        g2.setColor(Color.WHITE);
        g2.setFont(font);
        g2.drawString(label, x, y);

        // draw the value
        y += topIndent + labelHeight;
        g2.drawString(floatFormat.format(value), x, y);

        Graphics2D cg2 = (Graphics2D) chartImage.getGraphics();

        if (lineX > chartWidth) {
            Graphics2D sg2 = (Graphics2D) copyImage.getGraphics();
            sg2.drawImage(chartImage, null, -1, 0);
            cg2.setPaint(bgPaint);
            cg2.fillRect(0, 0, chartWidth, chartHeight);
            cg2.drawImage(copyImage, null, 0, 0);
            sg2.dispose();
            lineX = chartWidth - 1;
        }

        // draw the current value as a line
        if (paint == null) {
            paint = new GradientPaint(0, 0, gradientEndColor,
                    0, chartHeight, gradientStartColor);
        }
        cg2.setPaint(paint);
        cg2.fillRect(lineX, chartHeight - lineHeight, 1, lineHeight);
        lineX++;
View Full Code Here

Examples of java.awt.GradientPaint

   
    @Override
    public void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
       
        GradientPaint paint = new GradientPaint(0, 0, gradientStartColor,
                0, getHeight(), gradientEndColor);
        g2.setPaint(paint);
        g2.fill(g2.getClip());
    }
View Full Code Here

Examples of java.awt.GradientPaint

        bar.setFrame(leftIndent + 5, h - bottomIndent - labelHeight - labelGap - barHeight,
                barWidth - 5, barHeight);
        g2.setClip(bar);

        // paint gradient clipped by the bar's clip rect
        paint = new GradientPaint(leftIndent, topIndent + valueHeight + labelGap, startColor,
                barWidth, availableHeight, endColor);
        g2.setPaint(paint);
        g2.fillRect(leftIndent, topIndent + valueHeight + labelGap, availableWidth, availableHeight);

        // reset clip rect
View Full Code Here

Examples of java.awt.GradientPaint

        // draw the bar
        int barWidth = (int) ((value / max) * availableWidth);
        bar.setRoundRect(leftIndent + labelWidth + labelGap, y, barWidth, barHeight, 5, 5);
        g2.setClip(bar);
        paint = new GradientPaint(0, 0, startColor,
                availableWidth, getHeight(), endColor);
        g2.setPaint(paint);
        g2.fillRect(0, 0, getWidth(), getHeight());
        g2.setClip(0, 0, w, h);

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.