Java Code Examples for java.awt.Graphics2D

The following examples show how to use java.awt.Graphics2D. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: workcraft   Source File: VisualCircuitConnection.java    License: MIT License 6 votes vote down vote up
@Override
public void draw(DrawRequest r) {
    // Draw a small pieces of line at the beginning and at the end of connection arc when the gate contacts are hidden.
    Graphics2D g = r.getGraphics();
    Decoration d = r.getDecoration();
    Color colorisation = d.getColorisation();
    g.setColor(ColorUtils.colorise(getColor(), colorisation));
    g.setStroke(new BasicStroke((float) CircuitSettings.getWireWidth()));

    boolean showContact = CircuitSettings.getShowContacts() || (d instanceof StateDecoration);

    if (!showContact && (getFirst().getParent() instanceof VisualCircuitComponent)) {
        double tStart = Geometry.getBorderPointParameter(getFirstShape(), getGraphic(), 0, 1);
        g.draw(new Line2D.Double(getFirstCenter(), getGraphic().getPointOnCurve(tStart)));
    }

    if (!showContact && (getSecond().getParent() instanceof VisualCircuitComponent)) {
        double tEnd = Geometry.getBorderPointParameter(getSecondShape(), getGraphic(), 1, 0);
        g.draw(new Line2D.Double(getGraphic().getPointOnCurve(tEnd), getSecondCenter()));
    }
}
 
Example 2
Source Project: opensim-gui   Source File: SymbolAxis.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Draws the grid bands.  Alternate bands are colored using 
 * <CODE>gridBandPaint<CODE> (<CODE>DEFAULT_GRID_BAND_PAINT</CODE> by 
 * default).
 *
 * @param g2  the graphics device.
 * @param plotArea  the area within which the chart should be drawn.
 * @param dataArea  the area within which the plot should be drawn (a 
 *                  subset of the drawArea).
 * @param edge  the axis location.
 * @param ticks  the ticks.
 */
protected void drawGridBands(Graphics2D g2,
                             Rectangle2D plotArea, 
                             Rectangle2D dataArea,
                             RectangleEdge edge, 
                             List ticks) {

    Shape savedClip = g2.getClip();
    g2.clip(dataArea);
    if (RectangleEdge.isTopOrBottom(edge)) {
        drawGridBandsHorizontal(g2, plotArea, dataArea, true, ticks);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        drawGridBandsVertical(g2, plotArea, dataArea, true, ticks);
    }
    g2.setClip(savedClip);

}
 
Example 3
Source Project: netbeans   Source File: ColorEditor.java    License: Apache License 2.0 6 votes vote down vote up
/** Paints the current value. Implements <code>ProepertyEditor</code> interface. */
public void paintValue(Graphics g, Rectangle rectangle) {
    int px;

    ((Graphics2D)g).setRenderingHints (getHints ());
    
    if (this.superColor != null) {
        Color color = g.getColor();
        g.drawRect(rectangle.x, rectangle.y + rectangle.height / 2 - 5 , 10, 10);
        g.setColor(this.superColor);
        g.fillRect(rectangle.x + 1, rectangle.y + rectangle.height / 2 - 4 , 9, 9);
        g.setColor(color);
        px = 18;
    }
    else px = 0;

    FontMetrics fm = g.getFontMetrics();
    g.drawString(getAsText(), rectangle.x + px, rectangle.y +
                  (rectangle.height - fm.getHeight()) / 2 + fm.getAscent());
}
 
Example 4
private static void testScale(double scaleX, double scaleY) {

        Dialog dialog = new Dialog((Frame) null, true) {

            @Override
            public void paint(Graphics g) {
                super.paint(g);
                AffineTransform tx = ((Graphics2D) g).getTransform();
                dispose();
                if (scaleX != tx.getScaleX() || scaleY != tx.getScaleY()) {
                    throw new RuntimeException(String.format("Wrong scale:"
                            + "[%f, %f] instead of [%f, %f].",
                            tx.getScaleX(), tx.getScaleY(), scaleX, scaleY));
                }
            }
        };
        dialog.setSize(200, 300);
        dialog.setVisible(true);
    }
 
Example 5
/**
 * Paints a single bar instance.
 *
 * @param g2  the graphics target.
 * @param renderer  the renderer.
 * @param row  the row index.
 * @param column  the column index.
 * @param bar  the bar
 * @param base  indicates which side of the rectangle is the base of the
 *              bar.
 * @param pegShadow  peg the shadow to the base of the bar?
 */
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row,
        int column, RectangularShape bar, RectangleEdge base,
        boolean pegShadow) {

    // handle a special case - if the bar colour has alpha == 0, it is
    // invisible so we shouldn't draw any shadow
    Paint itemPaint = renderer.getItemPaint(row, column);
    if (itemPaint instanceof Color) {
        Color c = (Color) itemPaint;
        if (c.getAlpha() == 0) {
            return;
        }
    }

    RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
            renderer.getShadowYOffset(), base, pegShadow);
    g2.setPaint(Color.gray);
    g2.fill(shadow);

}
 
Example 6
Source Project: SimFix   Source File: 1_CategoryPlot.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the domain markers (if any) for an axis and layer.  This method is 
 * typically called from within the draw() method.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param index  the renderer index.
 * @param layer  the layer (foreground or background).
 * 
 * @see #drawRangeMarkers(Graphics2D, Rectangle2D, int, Layer)
 */
protected void drawDomainMarkers(Graphics2D g2, Rectangle2D dataArea, 
                                 int index, Layer layer) {
                                             
    CategoryItemRenderer r = getRenderer(index);
    if (r == null) {
        return;
    }
    
    Collection markers = getDomainMarkers(index, layer);
    CategoryAxis axis = getDomainAxisForDataset(index);
    if (markers != null && axis != null) {
        Iterator iterator = markers.iterator();
        while (iterator.hasNext()) {
            CategoryMarker marker = (CategoryMarker) iterator.next();
            r.drawDomainMarker(g2, this, axis, marker, dataArea);
        }
    }
    
}
 
Example 7
Source Project: gpx-animator   Source File: Renderer.java    License: Apache License 2.0 6 votes vote down vote up
private void printText(final Graphics2D g2, final String text, final float x, final float y) {
    final FontRenderContext frc = g2.getFontRenderContext();
    g2.setStroke(new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    final int height = g2.getFontMetrics(font).getHeight();

    final String[] lines = text == null ? new String[0] : text.split("\n");
    float yy = y - (lines.length - 1) * height;
    for (final String line : lines) {
        if (!line.isEmpty()) {
            final TextLayout tl = new TextLayout(line, font, frc);
            final Shape sha = tl.getOutline(AffineTransform.getTranslateInstance(x, yy));
            g2.setColor(Color.white);
            g2.fill(sha);
            g2.draw(sha);

            g2.setFont(font);
            g2.setColor(Color.black);
            g2.drawString(line, x, yy);
        }

        yy += height;
    }
}
 
Example 8
Source Project: triplea   Source File: MapRouteDrawer.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a specified CursorImage if available.
 *
 * @param graphics The {@linkplain Graphics2D} Object being drawn on
 * @param routeDescription The RouteDescription object containing the CursorImage
 * @param lastRoutePoint The last {@linkplain Point2D} on the drawn Route as a center for the
 *     cursor icon.
 */
private void drawCustomCursor(
    final Graphics2D graphics,
    final RouteDescription routeDescription,
    final Point2D lastRoutePoint) {
  final BufferedImage cursorImage = (BufferedImage) routeDescription.getCursorImage();
  if (cursorImage != null) {
    for (final Point2D[] endPoint : routeCalculator.getAllPoints(lastRoutePoint)) {
      final AffineTransform imageTransform = getDrawingTransform();
      imageTransform.translate(endPoint[0].getX(), endPoint[0].getY());
      imageTransform.translate(cursorImage.getWidth() / 2.0, cursorImage.getHeight() / 2.0);
      imageTransform.scale(1 / mapPanel.getScale(), 1 / mapPanel.getScale());
      graphics.drawImage(cursorImage, imageTransform, null);
    }
  }
}
 
Example 9
Source Project: netbeans   Source File: SlidingTabDisplayerButtonUI.java    License: Apache License 2.0 6 votes vote down vote up
/** Provides the painting logic.  Note that this does not call any of the
 * painting methods of BasicToggleButtonUI */
@Override
public final void paint(Graphics g, JComponent c) {
    
    BasicSlidingTabDisplayerUI.IndexButton b = 
        (BasicSlidingTabDisplayerUI.IndexButton) c;
    
    Graphics2D g2d = (Graphics2D) g;
    
    paintBackground (g2d, b);
    
    Object orientation = b.getOrientation();
    
    AffineTransform tr = g2d.getTransform();
    if (orientation == TabDisplayer.ORIENTATION_EAST) {
         g2d.rotate( Math.PI / 2 ); 
         g2d.translate( 0, - c.getWidth() );
    } else if (orientation == TabDisplayer.ORIENTATION_WEST) {
         g2d.rotate(-Math.PI / 2); 
         g2d.translate(-c.getHeight(), 0);
    }

    paintIconAndText (g2d, b, orientation);
    g2d.setTransform (tr);
}
 
Example 10
@Override
protected void paintComponent (Graphics g)
{
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g.create();

    //shift the image for pressed buttons
    if (getModel().isPressed()) {
        g2.translate(1, 1);
    }

    g2.setStroke(new BasicStroke(2));

    if (getModel().isRollover()) {
        g2.setColor(Color.MAGENTA);
    } else {
        g2.setColor(Color.BLACK);
    }

    int delta = 4; // Margin around the cross
    g2.drawLine(delta, delta, getWidth() - delta - 1, getHeight() - delta - 1);
    g2.drawLine(getWidth() - delta - 1, delta, delta, getHeight() - delta - 1);
    g2.dispose();
}
 
Example 11
Source Project: opensim-gui   Source File: XYDifferenceRenderer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color 
 *              information etc).
 * @param domainAxis  the domain (horizontal) axis.
 * @param rangeAxis  the range (vertical) axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot 
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2,
                     XYItemRendererState state,
                     Rectangle2D dataArea,
                     PlotRenderingInfo info,
                     XYPlot plot,
                     ValueAxis domainAxis,
                     ValueAxis rangeAxis,
                     XYDataset dataset,
                     int series,
                     int item,
                     CrosshairState crosshairState,
                     int pass) {

    if (pass == 0) {
        drawItemPass0(g2, dataArea, info, plot, domainAxis, rangeAxis, 
                dataset, series, item, crosshairState);
    }
    else if (pass == 1) {
        drawItemPass1(g2, dataArea, info, plot, domainAxis, rangeAxis, 
                dataset, series, item, crosshairState);
    }

}
 
Example 12
/**
 * Utility method for drawing a line perpendicular to the range axis (used
 * for crosshairs).
 *
 * @param g2  the graphics device.
 * @param dataArea  the area defined by the axes.
 * @param value  the data value.
 * @param stroke  the line stroke (<code>null</code> not permitted).
 * @param paint  the line paint (<code>null</code> not permitted).
 */
protected void drawRangeLine(Graphics2D g2, Rectangle2D dataArea,
        double value, Stroke stroke, Paint paint) {

    double java2D = getRangeAxis().valueToJava2D(value, dataArea, 
            getRangeAxisEdge());
    Line2D line = null;
    if (this.orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(java2D, dataArea.getMinY(), java2D, 
                dataArea.getMaxY());
    }
    else if (this.orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), java2D, 
                dataArea.getMaxX(), java2D);
    }
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);

}
 
Example 13
Source Project: opensim-gui   Source File: IntervalBarRenderer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2,
                     CategoryItemRendererState state,
                     Rectangle2D dataArea,
                     CategoryPlot plot,
                     CategoryAxis domainAxis,
                     ValueAxis rangeAxis,
                     CategoryDataset dataset,
                     int row,
                     int column,
                     int pass) {

     if (dataset instanceof IntervalCategoryDataset) {
         IntervalCategoryDataset d = (IntervalCategoryDataset) dataset;
         drawInterval(g2, state, dataArea, plot, domainAxis, rangeAxis, 
                 d, row, column);
     }
     else {
         super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, 
                 dataset, row, column, pass);
     } 
     
 }
 
Example 14
Source Project: buffer_bci   Source File: CyclicNumberAxis.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Selects a tick unit when the axis is displayed horizontally.
 *
 * @param g2  the graphics device.
 * @param drawArea  the drawing area.
 * @param dataArea  the data area.
 * @param edge  the side of the rectangle on which the axis is displayed.
 */
protected void selectHorizontalAutoTickUnit(Graphics2D g2,
        Rectangle2D drawArea, Rectangle2D dataArea, RectangleEdge edge) {

    double tickLabelWidth
        = estimateMaximumTickLabelWidth(g2, getTickUnit());

    // Compute number of labels
    double n = getRange().getLength()
               * tickLabelWidth / dataArea.getWidth();

    setTickUnit(
            (NumberTickUnit) getStandardTickUnits().getCeilingTickUnit(n),
            false, false);

 }
 
Example 15
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
Example 16
Source Project: hprof-tools   Source File: ViewRenderer.java    License: MIT License 6 votes vote down vote up
private void renderView(View view, Graphics2D canvas) {
    Drawable background = view.getBackground();
    canvas.translate(view.left, view.top);
    if (renderBackgrounds && background != null) {
        if (forceAlpha) {
            background.setAlpha(120);
        }
        else {
            background.setAlpha(255);
        }
        background.draw(canvas, 0, 0, view.getWidth(), view.getHeight());
    }
    canvas.setColor(getViewOutlineColor(view));
    canvas.setColor(view.isSelected() ? Color.RED : Color.BLACK);
    canvas.setStroke(view.isSelected() ? THICK_LINE : THIN_LINE);
    if (showBounds) {
        canvas.drawRect(0, 0, view.getWidth(), view.getHeight());
    }
    canvas.translate(-view.left, -view.top);
}
 
Example 17
Source Project: ECG-Viewer   Source File: FlowArrangement.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Arranges the blocks without any constraints.  This puts all blocks
 * into a single row.
 *
 * @param container  the container.
 * @param g2  the graphics device.
 *
 * @return The size after the arrangement.
 */
protected Size2D arrangeNN(BlockContainer container, Graphics2D g2) {
    double x = 0.0;
    double width = 0.0;
    double maxHeight = 0.0;
    List blocks = container.getBlocks();
    int blockCount = blocks.size();
    if (blockCount > 0) {
        Size2D[] sizes = new Size2D[blocks.size()];
        for (int i = 0; i < blocks.size(); i++) {
            Block block = (Block) blocks.get(i);
            sizes[i] = block.arrange(g2, RectangleConstraint.NONE);
            width = width + sizes[i].getWidth();
            maxHeight = Math.max(sizes[i].height, maxHeight);
            block.setBounds(
                new Rectangle2D.Double(
                    x, 0.0, sizes[i].width, sizes[i].height
                )
            );
            x = x + sizes[i].width + this.horizontalGap;
        }
        if (blockCount > 1) {
            width = width + this.horizontalGap * (blockCount - 1);
        }
        if (this.verticalAlignment != VerticalAlignment.TOP) {
            for (int i = 0; i < blocks.size(); i++) {
                //Block b = (Block) blocks.get(i);
                if (this.verticalAlignment == VerticalAlignment.CENTER) {
                    //TODO: shift block down by half
                }
                else if (this.verticalAlignment
                        == VerticalAlignment.BOTTOM) {
                    //TODO: shift block down to bottom
                }
            }
        }
    }
    return new Size2D(width, maxHeight);
}
 
Example 18
Source Project: SIMVA-SoS   Source File: XYPlot.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Draws the annotations for the plot.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param info  the chart rendering info.
 */
public void drawAnnotations(Graphics2D g2, Rectangle2D dataArea,
                            PlotRenderingInfo info) {

    Iterator iterator = this.annotations.iterator();
    while (iterator.hasNext()) {
        XYAnnotation annotation = (XYAnnotation) iterator.next();
        ValueAxis xAxis = getDomainAxis();
        ValueAxis yAxis = getRangeAxis();
        annotation.draw(g2, this, dataArea, xAxis, yAxis, 0, info);
    }

}
 
Example 19
Source Project: Pixelitor   Source File: CloneBrush.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Recalculates the brush stamp image before each dab
 */
@Override
void setupBrushStamp(PPoint p) {
    Graphics2D g = brushImage.createGraphics();

    type.beforeDrawImage(g);

    // the current sampling coordinates relative to the source image
    double currSrcX = dx - p.getImX();
    double currSrcY = dy - p.getImY();

    // Now calculate the transformation from the source to the brush image.
    // Concatenated transformations have a last-specified-first-applied
    // order, so start with the last transformation
    // that works when there is no scaling/rotating
    var transform = AffineTransform.getTranslateInstance(
            currSrcX + radius, currSrcY + radius);

    if (scaleX != 1.0 || scaleY != 1.0 || rotate != 0.0) {
        g.setRenderingHint(KEY_INTERPOLATION, VALUE_INTERPOLATION_BILINEAR);
        // we need to scale/rotate the image
        // around the source point, so translate first
        transform.translate(origSrcX, origSrcY);
        transform.scale(scaleX, scaleY);
        transform.rotate(rotate);
        transform.translate(-origSrcX, -origSrcY);
    }

    g.drawImage(sourceImage, transform, null);
    type.afterDrawImage(g);

    g.dispose();

    debugImage();
}
 
Example 20
private void drawText(Graphics2D g, String text, Point2d c, Vector2d v, Vector2d nV) {
    AffineTransform originalTransform = g.getTransform();
    double angle = getAngle(v);

    Rectangle2D textBounds = getTextBounds(g, text);
    double distance = textBounds.getWidth() / 2;
    Point2d start = new Point2d(c.x, c.y);
    if (angle < toRadians(90) || angle > toRadians(270)) {
        start.scaleAdd(distance, nV, c);
    } else {
        start.scaleAdd(distance, v, c);
        double angDeg = (180 + toDegrees(angle)) % 360;
        angle = toRadians(angDeg);
    }

    g.translate(start.x, start.y);
    g.rotate(angle);

    Font font = g.getFont();
    FontRenderContext frc = g.getFontRenderContext();
    GlyphVector gv = font.createGlyphVector(frc, text);
    int length = gv.getNumGlyphs();
    for (int i = 0; i < length; i++) {
        g.fill(gv.getGlyphOutline(i));
    }

    g.rotate((2 * PI) - angle);
    g.setTransform(originalTransform);
}
 
Example 21
public static void main(String[] args) {

        /* Create an image to draw, filled in solid red. */
        BufferedImage srcImg =
             new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
        Graphics srcG = srcImg.createGraphics();
        srcG.setColor(Color.red);
        int w = srcImg.getWidth(null);
        int h = srcImg.getHeight(null);
        srcG.fillRect(0, 0, w, h);

        /* Create a destination image */
        BufferedImage dstImage =
           new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
        Graphics2D dstG = dstImage.createGraphics();
        /* draw image under a scaling transform that overflows int */
        AffineTransform tx = new AffineTransform(0.5, 0, 0, 0.5,
                                                  0, 5.8658460197478485E9);
        dstG.setTransform(tx);
        dstG.drawImage(srcImg, 0, 0, null );
        /* draw image under the same overflowing transform, cancelling
         * out the 0.5 scale on the graphics
         */
        dstG.drawImage(srcImg, 0, 0, 2*w, 2*h, null);
        if (Color.red.getRGB() == dstImage.getRGB(w/2, h/2)) {
             throw new RuntimeException("Unexpected color: clipping failed.");
        }
        System.out.println("Test Thread Completed");
    }
 
Example 22
Source Project: tess4j   Source File: ImageHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method that returns a scaled instance of the provided
 * {@code BufferedImage}.
 *
 * @param image the original image to be scaled
 * @param targetWidth the desired width of the scaled instance, in pixels
 * @param targetHeight the desired height of the scaled instance, in pixels
 * @return a scaled version of the original {@code BufferedImage}
 */
public static BufferedImage getScaledInstance(BufferedImage image, int targetWidth, int targetHeight) {
    int type = (image.getTransparency() == Transparency.OPAQUE)
            ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
    BufferedImage tmp = new BufferedImage(targetWidth, targetHeight, type);
    Graphics2D g2 = tmp.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.drawImage(image, 0, 0, targetWidth, targetHeight, null);
    g2.dispose();
    return tmp;
}
 
Example 23
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 24
Source Project: beautyeye   Source File: BEUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 图形绘制反走样设置.
 *
 * @param g2 the g2
 * @param antiAliasing 是否反走样
 */
public static void setAntiAliasing(Graphics2D g2 ,boolean antiAliasing)
{
	if(antiAliasing)
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING
				, RenderingHints.VALUE_ANTIALIAS_ON);
	else
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING
				, RenderingHints.VALUE_ANTIALIAS_OFF);
}
 
Example 25
Source Project: snap-desktop   Source File: DiagramCanvas.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void drawValueIndicator(Graphics2D g2d) {
    Diagram.RectTransform transform = diagram.getTransform();
    Point2D a = transform.transformB2A(dragPoint, null);
    double x = a.getX();
    if (x < selectedGraph.getXMin()) {
        x = selectedGraph.getXMin();
    }
    if (x > selectedGraph.getXMax()) {
        x = selectedGraph.getXMax();
    }
    final Stroke oldStroke = g2d.getStroke();
    final Color oldColor = g2d.getColor();

    double y = getY(selectedGraph, x);
    Point2D b = transform.transformA2B(new Point2D.Double(x, y), null);

    g2d.setStroke(new BasicStroke(1.0f));
    g2d.setColor(diagram.getForegroundColor());
    Ellipse2D.Double marker = new Ellipse2D.Double(b.getX() - 4.0, b.getY() - 4.0, 8.0, 8.0);
    g2d.draw(marker);

    g2d.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{6, 6}, 12));
    g2d.setColor(diagram.getForegroundColor());
    final Rectangle graphArea = diagram.getGraphArea();
    g2d.draw(new Line2D.Double(b.getX(), graphArea.y + graphArea.height, b.getX(), b.getY()));
    g2d.draw(new Line2D.Double(graphArea.x, b.getY(), b.getX(), b.getY()));

    DecimalFormat decimalFormat = new DecimalFormat("0.#####E0");
    String text = selectedGraph.getYName() + ": x = " + decimalFormat.format(x) + ", y = " + decimalFormat.format(y);

    g2d.setStroke(oldStroke);
    g2d.setColor(oldColor);

    drawTextBox(g2d, text, graphArea.x + 6, graphArea.y + 6 + 16, new Color(255, 255, 255, 128));
}
 
Example 26
Source Project: pumpernickel   Source File: CloseIcon.java    License: MIT License 5 votes vote down vote up
protected void paintBackground(Graphics2D g, int x, int y) {
	Ellipse2D fill = new Ellipse2D.Float(x, y, size, size);
	// draw the light shadow/bevel
	g.translate(0, 1);
	g.setColor(new Color(255, 255, 255, 120));
	g.fill(fill);
	g.translate(0, -1);

	g.setPaint(new GradientPaint(0, 0, bkgndTop, 0, size, bkgndBottom));
	g.fill(fill);
}
 
Example 27
Source Project: openjdk-jdk8u   Source File: GraphicsTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.translate(0.0, (h - (w*h)/(w + h*0.1)) / 2);
    at.shear(0.1, 0.0);
    g2d.transform(at);
    dim.setSize(scaleForTransform(at, dim));
}
 
Example 28
Source Project: SIMVA-SoS   Source File: XYPlot.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Draws the gridlines for the plot's primary range axis, if they are
 * visible.
 *
 * @param g2  the graphics device.
 * @param area  the data area.
 * @param ticks  the ticks.
 *
 * @see #drawDomainGridlines(Graphics2D, Rectangle2D, List)
 */
protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area,
                                  List ticks) {

    // no renderer, no gridlines...
    if (getRenderer() == null) {
        return;
    }

    // draw the range grid lines, if any...
    if (isRangeGridlinesVisible() || isRangeMinorGridlinesVisible()) {
        Stroke gridStroke = null;
        Paint gridPaint = null;
        ValueAxis axis = getRangeAxis();
        if (axis != null) {
            Iterator iterator = ticks.iterator();
            boolean paintLine;
            while (iterator.hasNext()) {
                paintLine = false;
                ValueTick tick = (ValueTick) iterator.next();
                if ((tick.getTickType() == TickType.MINOR)
                        && isRangeMinorGridlinesVisible()) {
                    gridStroke = getRangeMinorGridlineStroke();
                    gridPaint = getRangeMinorGridlinePaint();
                    paintLine = true;
                } else if ((tick.getTickType() == TickType.MAJOR)
                        && isRangeGridlinesVisible()) {
                    gridStroke = getRangeGridlineStroke();
                    gridPaint = getRangeGridlinePaint();
                    paintLine = true;
                }
                if ((tick.getValue() != 0.0
                        || !isRangeZeroBaselineVisible()) && paintLine) {
                    getRenderer().drawRangeLine(g2, this, getRangeAxis(),
                            area, tick.getValue(), gridPaint, gridStroke);
                }
            }
        }
    }
}
 
Example 29
Source Project: TencentKona-8   Source File: MyCursor.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override public void paint(Graphics gr) {
   gr.setColor(Color.GREEN);
   ((Graphics2D)gr).setStroke(new BasicStroke(3));
   //arrow
   gr.drawLine(0, 0, width/2, height/2);
   gr.drawLine(0, 0, width/2, 0);
   gr.drawLine(0, 0, 0, height/2);
   //plus
   gr.drawRect(width/2 - 1, height/2 -1, width/2 - 1, height/2 - 1);
   gr.drawLine(width*3/4 - 1, height/2 - 1, width*3/4 - 1, height);
   gr.drawLine(width/2 - 1, height*3/4 - 1, width, height*3/4 - 1);
}
 
Example 30
Source Project: pdfxtk   Source File: ProjectionProfile.java    License: Apache License 2.0 5 votes vote down vote up
protected void paintComponent(Graphics g) {
  Graphics2D g2 = (Graphics2D) g;

  Dimension size = getSize(null);

  g2.setColor(getBackground());
  g2.fillRect(0, 0, size.width, size.height);
  g2.setColor(Color.black);

  ProjectionProfile.this.paint(g2, direction, 0, 0);
}