Java Code Examples for java.awt.Graphics2D.getClip()

The following are Jave code examples for showing how to use getClip() of the java.awt.Graphics2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: VASSAL-src   File: Zone.java   View Source Code Vote up 6 votes
public void draw(Graphics g, Rectangle bounds, Rectangle visibleRect, double scale, boolean reversed) {
  if ((getGrid() != null && getGrid().isVisible()) || highlighter != null) {
    final Graphics2D g2d = (Graphics2D) g;
    final Shape oldClip = g2d.getClip();
    final Area newClip = new Area(visibleRect);
    final Shape s = getCachedShape(myPolygon, bounds.x, bounds.y, scale);
    newClip.intersect(new Area(s));
    g2d.setClip(newClip);
    if (getGrid() != null && getGrid().isVisible()) {
      getGrid().draw(g, bounds, visibleRect, scale, reversed);
    }
    if (highlighter != null) {
      highlighter.draw(g2d, s, scale);
    }
    g2d.setClip(oldClip);
  }
}
 
Example 2
Project: parabuild-ci   File: Plot.java   View Source Code Vote up 6 votes
/**
     * Draws a message to state that there is no data to plot.
     *
     * @param g2  the graphics device.
     * @param area  the area within which the plot should be drawn.
     */
    protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {

        Shape savedClip = g2.getClip();
        g2.clip(area);
        String message = this.noDataMessage;
        if (message != null) {
            g2.setFont(this.noDataMessageFont);
            g2.setPaint(this.noDataMessagePaint);
//            FontMetrics fm = g2.getFontMetrics(this.noDataMessageFont);
//            Rectangle2D bounds = TextUtilities.getTextBounds(message, g2, fm);
//            float x = (float) (area.getX() + area.getWidth() / 2 - bounds.getWidth() / 2);
//            float y = (float) (area.getMinY() + (area.getHeight() / 2) - (bounds.getHeight() / 2));
//            g2.drawString(message, x, y);
            TextBlock block = TextUtilities.createTextBlock(
                this.noDataMessage, this.noDataMessageFont, this.noDataMessagePaint, 
                0.9f * (float) area.getWidth(), new G2TextMeasurer(g2)
            );
            block.draw(
                g2, (float) area.getCenterX(), (float) area.getCenterY(), TextBlockAnchor.CENTER
            );
        }
        g2.setClip(savedClip);

    }
 
Example 3
Project: parabuild-ci   File: SymbolicAxis.java   View Source Code Vote up 6 votes
/**
 * Draws the symbolic grid lines.
 * <P>
 * The colors are consecutively the color specified by
 * <CODE>symbolicGridPaint<CODE>
 * (<CODE>DEFAULT_SYMBOLIC_GRID_LINE_PAINT</CODE> by default) and white.
 *
 * @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.
 */
public void drawSymbolicGridLines(Graphics2D g2,
                                  Rectangle2D plotArea, 
                                  Rectangle2D dataArea,
                                  RectangleEdge edge, 
                                  List ticks) {

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

}
 
Example 4
Project: parabuild-ci   File: Plot.java   View Source Code Vote up 6 votes
/**
 * Draws a message to state that there is no data to plot.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 */
protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
    Shape savedClip = g2.getClip();
    g2.clip(area);
    String message = this.noDataMessage;
    if (message != null) {
        g2.setFont(this.noDataMessageFont);
        g2.setPaint(this.noDataMessagePaint);
        TextBlock block = TextUtilities.createTextBlock(
                this.noDataMessage, this.noDataMessageFont, 
                this.noDataMessagePaint, 0.9f * (float) area.getWidth(), 
                new G2TextMeasurer(g2));
        block.draw(g2, (float) area.getCenterX(), (float) area.getCenterY(), 
                TextBlockAnchor.CENTER);
    }
    g2.setClip(savedClip);
}
 
Example 5
Project: parabuild-ci   File: SymbolAxis.java   View Source Code Vote up 6 votes
/**
 * 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 6
Project: litiengine   File: RenderEngine.java   View Source Code Vote up 5 votes
@Override
public void renderEntities(final Graphics2D g, final Collection<? extends IEntity> entities, final boolean sort, final IVision vision) {
  // set render shape according to the vision
  final Shape oldClip = g.getClip();

  if (vision != null) {
    g.setClip(vision.getRenderVisionShape());
  }

  this.renderEntities(g, entities, sort);

  g.setClip(oldClip);
}
 
Example 7
Project: What-Happened-to-Station-7   File: TStack.java   View Source Code Vote up 5 votes
public gInfo(Graphics2D g)
{
	transform = g.getTransform();
	paint = g.getPaint();
	stroke = g.getStroke();
	font = g.getFont();
	composite = g.getComposite();
	bgrnd = g.getBackground();
	shape = g.getClip();
	hints = g.getRenderingHints();
}
 
Example 8
Project: parabuild-ci   File: PiePlot.java   View Source Code Vote up 5 votes
/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a 
 * printer).
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing 
 *              (<code>null</code> permitted).
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor,
                 PlotState parentState, PlotRenderingInfo info) {

    // adjust for insets...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    if (info != null) {
        info.setPlotArea(area);
        info.setDataArea(area);
    }

    drawBackground(g2, area);
    drawOutline(g2, area);

    Shape savedClip = g2.getClip();
    g2.clip(area);

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 
            getForegroundAlpha()));

    if (!DatasetUtilities.isEmptyOrNull(this.dataset)) {
        drawPie(g2, area, info);
    }
    else {
        drawNoDataMessage(g2, area);
    }

    g2.setClip(savedClip);
    g2.setComposite(originalComposite);

    drawOutline(g2, area);

}
 
Example 9
Project: brModelo   File: PreEspecializacao.java   View Source Code Vote up 4 votes
@Override
public void DoPaint(Graphics2D g) {
    super.DoPaint(g);
    int h = getHeight() / 8;
    int w = getWidth() / 8;
    
    Font fbkp = getFont();
    g.setFont(getFont());
    
    int fh = g.getFontMetrics().getHeight() / 2;
    int fw = g.getFontMetrics().stringWidth("p");
    int x =0, y = 0;
    Rectangle r = getBounds();
    Shape bkp = g.getClip();
    g.setClip(Regiao);
    switch (getDirecao()) {
        case Up:
            g.fillRect(r.x, r.y, r.width, h);
            x =  r.x + r.width -fw;
            y =  r.y + r.height/2 + fh/2;
            break;
        case Right:
            g.fillRect(getLeftWidth() - w, r.y, w, r.height);
            x =  r.x + r.width/2 - fw/2;
            y =  r.y + fh;
            break;
        case Down:
            g.fillRect(r.x, getTopHeight() - h, r.width, h);
            x =  r.x + r.width - fw;
            y =  r.y + r.height/2 + fh/2;
            break;
        case Left:
            g.fillRect(r.x, r.y, w, r.height);
            x =  r.x + r.width/2 - fw/2;
            y =  r.y + fh;
            break;
    }
    g.setClip(bkp);
    PaintPDeParcial(g, x, y);
    g.setFont(fbkp);
}
 
Example 10
Project: incubator-netbeans   File: FoldView.java   View Source Code Vote up 4 votes
@Override
public void paint(Graphics2D g, Shape alloc, Rectangle clipBounds) {
    Rectangle2D.Double allocBounds = ViewUtils.shape2Bounds(alloc);
    if (allocBounds.intersects(clipBounds)) {
        Font origFont = g.getFont();
        Color origColor = g.getColor();
        Color origBkColor = g.getBackground();
        Shape origClip = g.getClip();
        try {
            // Leave component font
            
            g.setBackground(getBackgroundColor());

            int xInt = (int) allocBounds.getX();
            int yInt = (int) allocBounds.getY();
            int endXInt = (int) (allocBounds.getX() + allocBounds.getWidth() - 1);
            int endYInt = (int) (allocBounds.getY() + allocBounds.getHeight() - 1);
            g.setColor(getBorderColor());
            g.drawRect(xInt, yInt, endXInt - xInt, endYInt - yInt);
            
            g.setColor(getForegroundColor());
            g.clearRect(xInt + 1, yInt + 1, endXInt - xInt - 1, endYInt - yInt - 1);
            g.clip(alloc);
            TextLayout textLayout = getTextLayout();
            if (textLayout != null) {
                EditorView.Parent parent = (EditorView.Parent) getParent();
                float ascent = parent.getViewRenderContext().getDefaultAscent();
                String desc = fold.getDescription(); // For empty desc a single-space text layout is returned
                float x = (float) (allocBounds.getX() + EXTRA_MARGIN_WIDTH);
                float y = (float) allocBounds.getY();
                if (desc.length() > 0) {
                    
                    textLayout.draw(g, x, y + ascent);
                }
            }
        } finally {
            g.setClip(origClip);
            g.setBackground(origBkColor);
            g.setColor(origColor);
            g.setFont(origFont);
        }
    }
}
 
Example 11
Project: incubator-netbeans   File: HighlightsViewUtils.java   View Source Code Vote up 4 votes
static void paintNewline(Graphics2D g, Shape viewAlloc, Rectangle clipBounds,
        DocumentView docView, EditorView view, int viewStartOffset)
{
    Rectangle2D viewRectReadonly = ViewUtils.shape2Bounds(viewAlloc);
    PaintState paintState = PaintState.save(g);
    Shape origClip = g.getClip();
    try {
        JTextComponent textComponent = docView.getTextComponent();
        SplitOffsetHighlightsSequence highlights = docView.getPaintHighlights(view, 0);
        boolean showNonPrintingChars = docView.op.isNonPrintableCharactersVisible();
        float charWidth = docView.op.getDefaultCharWidth();
        boolean logFiner = ViewHierarchyImpl.PAINT_LOG.isLoggable(Level.FINER);
        if (logFiner) {
            ViewHierarchyImpl.PAINT_LOG.finer("      Newline-View-Id=" + view.getDumpId() + // NOI18N
                    ", startOffset=" + viewStartOffset + ", alloc=" + viewAlloc + '\n' // NOI18N
            );

        }
        while (highlights.moveNext()) {
            int hiStartOffset = highlights.getStartOffset();
            int hiStartSplitOffset = highlights.getStartSplitOffset();
            int hiEndOffset = Math.min(highlights.getEndOffset(), viewStartOffset + 1); // TBD
            int hiEndSplitOffset = highlights.getEndSplitOffset();
            AttributeSet attrs = highlights.getAttributes();
            if (hiStartOffset > viewStartOffset) { // HL above newline
                break;
            }

            double startX = viewRectReadonly.getX() + hiStartSplitOffset * charWidth;
            double endX = (hiEndOffset > viewStartOffset)
                    ? viewRectReadonly.getMaxX()
                    : Math.min(viewRectReadonly.getX() + hiEndSplitOffset * charWidth, viewRectReadonly.getMaxX());
            Rectangle2D.Double renderPartRect = new Rectangle2D.Double(startX, viewRectReadonly.getY(), endX - startX, viewRectReadonly.getHeight());
            fillBackground(g, renderPartRect, attrs, textComponent);
            boolean hitsClip = (clipBounds == null) || renderPartRect.intersects(clipBounds);
            if (hitsClip) {
                // First render background and background related highlights
                // Do not g.clip() before background is filled since otherwise there would be
                // painting artifacts for italic fonts (one-pixel slanting lines) at certain positions.
                // Clip to part's alloc since textLayout.draw() renders fully the whole text layout
                g.clip(renderPartRect);
                paintBackgroundHighlights(g, renderPartRect, attrs, docView);
                // Render foreground with proper color
                g.setColor(HighlightsViewUtils.validForeColor(attrs, textComponent));
                Object strikeThroughValue = (attrs != null)
                        ? attrs.getAttribute(StyleConstants.StrikeThrough)
                        : null;
                if (showNonPrintingChars && hiStartSplitOffset == 0) { // First part => render newline char visible representation
                    TextLayout textLayout = docView.op.getNewlineCharTextLayout();
                    if (textLayout != null) {
                        paintTextLayout(g, renderPartRect, textLayout, docView);
                    }
                }
                if (strikeThroughValue != null) {
                    paintStrikeThrough(g, viewRectReadonly, strikeThroughValue, attrs, docView);
                }
                g.setClip(origClip);
            }
            if (logFiner) {
                ViewHierarchyImpl.PAINT_LOG.finer("        Highlight <" + 
                        hiStartOffset + '_' + hiStartSplitOffset + "," + // NOI18N
                        hiEndOffset + '_' + hiEndSplitOffset + ">, Color=" + // NOI18N
                        ViewUtils.toString(g.getColor()) + '\n'); // NOI18N
            }
            if (clipBounds != null && (renderPartRect.getX() > clipBounds.getMaxX())) {
                break;
            }
        }
    } finally {
        g.setClip(origClip);
        paintState.restore();
    }
}
 
Example 12
Project: VASSAL-src   File: SquareGrid.java   View Source Code Vote up 4 votes
/** Draw the grid even if not marked visible */
public void forceDraw(Graphics g, Rectangle bounds, Rectangle visibleRect, double scale, boolean reversed) {
  if (!bounds.intersects(visibleRect) || color == null) {
    return;
  }

  Graphics2D g2d = (Graphics2D) g;
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                       RenderingHints.VALUE_ANTIALIAS_ON);

  Rectangle region = bounds.intersection(visibleRect);

  Shape oldClip = g2d.getClip();
  if (oldClip != null) {
    Area clipArea = new Area(oldClip);
    clipArea.intersect(new Area(region));
    g2d.setClip(clipArea);
  }

  double deltaX = scale * dx;
  double deltaY = scale * dy;

  double xmin = reversed ? bounds.x + scale * origin.x + bounds.width - deltaX * round((bounds.x + scale * origin.x + bounds.width - region.x) / deltaX) + deltaX / 2
      : bounds.x + scale * origin.x + deltaX * round((region.x - bounds.x - scale * origin.x) / deltaX) + deltaX / 2;
  double xmax = region.x + region.width;
  double ymin = reversed ? bounds.y + scale * origin.y + bounds.height - deltaY * round((bounds.y + scale * origin.y + bounds.height - region.y) / deltaY) + deltaY / 2
      : bounds.y + scale * origin.y + deltaY * round((region.y - bounds.y - scale * origin.y) / deltaY) + deltaY / 2;
  double ymax = region.y + region.height;

  Point p1 = new Point();
  Point p2 = new Point();
  g2d.setColor(color);
  // x is the location of a vertical line
  for (double x = xmin; x < xmax; x += deltaX) {
    p1.move((int) round(x), region.y);
    p2.move((int) round(x), region.y + region.height);
    g2d.drawLine(p1.x, p1.y, p2.x, p2.y);
  }
  for (double y = ymin; y < ymax; y += deltaY) {
    g2d.drawLine(region.x, (int) round(y), region.x + region.width, (int) round(y));
  }
  if (dotsVisible) {
    xmin = reversed ? bounds.x + scale * origin.x + bounds.width - deltaX * round((bounds.x + scale * origin.x + bounds.width - region.x) / deltaX)
        : bounds.x + scale * origin.x + deltaX * round((region.x - bounds.x - scale * origin.x) / deltaX);
    ymin = reversed ? bounds.y + scale * origin.y + bounds.height - deltaY * round((bounds.y + scale * origin.y + bounds.height - region.y) / deltaY)
        : bounds.y + scale * origin.y + deltaY * round((region.y - bounds.y - scale * origin.y) / deltaY);
    for (double x = xmin; x < xmax; x += deltaX) {
      for (double y = ymin; y < ymax; y += deltaY) {
        p1.move((int) round(x - 0.5), (int) round(y - 0.5));
        g2d.fillRect(p1.x, p1.y, 2, 2);
      }
    }
  }
  g2d.setClip(oldClip);
}
 
Example 13
Project: nativehtml   File: AbstractSwingComponentElement.java   View Source Code Vote up 4 votes
private void drawBackground(Graphics2D g2d, int x, int y, int w, int h) {
  CssStyleDeclaration style = getComputedStyle();
  if (style.isSet(CssProperty.BACKGROUND_COLOR)) {
    g2d.setColor(createColor(style.getColor(CssProperty.BACKGROUND_COLOR)));
    g2d.fillRect(x, y, w, h);
  }

  if (!style.isSet(CssProperty.BACKGROUND_IMAGE)) {
    return;
  }

  String bgImage = style.getString(CssProperty.BACKGROUND_IMAGE);
  Image image = ((SwingPlatform) getOwnerDocument().getPlatform()).getImage(this, getOwnerDocument().getUrl().resolve(bgImage));
  
  if (image == null) {
    return;
  }

  Shape savedClip = g2d.getClip(); 
  g2d.clipRect(x, y, w, h);
  CssEnum repeat = style.getEnum(CssProperty.BACKGROUND_REPEAT);
     int bgY = 0;
     int bgX = 0;
     if (repeat == CssEnum.REPEAT_Y || repeat == CssEnum.REPEAT) {
       do {
         if (repeat == CssEnum.REPEAT) {
           int currentBgX = bgX;
           do {
             g2d.drawImage(image, x + currentBgX, y + bgY, null);
             currentBgX += image.getWidth(null);
           } while (currentBgX < w);
         } else {
           g2d.drawImage(image, x + bgX, y + bgY, null);
         }
         bgY += image.getHeight(null);
       } while (bgY < h);
     } else if (repeat == CssEnum.REPEAT_X) {
       do {
         g2d.drawImage(image, x + bgX, y + bgY, null);
         bgX += image.getWidth(null);
       } while (bgX < w);
     } else {
       g2d.drawImage(image, x + bgX, y + bgY, null);
     }
     
     g2d.setClip(savedClip);
}
 
Example 14
Project: parabuild-ci   File: PolarPlot.java   View Source Code Vote up 4 votes
/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a printer).
 * <P>
 * This plot relies on an {@link org.jfree.chart.renderer.DefaultPolarItemRenderer} to draw 
 * each item in the plot.  This allows the visual representation of the data to be changed 
 * easily.
 * <P>
 * The optional info argument collects information about the rendering of
 * the plot (dimensions, tooltip information etc).  Just pass in <code>null</code> if
 * you do not need this information.
 *
 * @param g2  the graphics device.
 * @param plotArea  the area within which the plot (including axes and labels) should be drawn.
 * @param parentState  ignored.
 * @param info  collects chart drawing information (<code>null</code> permitted).
 */
public void draw(Graphics2D g2, 
                 Rectangle2D plotArea, 
                 PlotState parentState,
                 PlotRenderingInfo info) {
   
    // if the plot area is too small, just return...
    boolean b1 = (plotArea.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
    boolean b2 = (plotArea.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
    if (b1 || b2) {
        return;
    }
   
    // record the plot area...
    if (info != null) {
        info.setPlotArea(plotArea);
    }
   
    // adjust the drawing area for the plot insets (if any)...
    Insets insets = getInsets();
    if (insets != null) {
        plotArea.setRect(plotArea.getX() + insets.left,
                         plotArea.getY() + insets.top,
                         plotArea.getWidth() - insets.left - insets.right,
                         plotArea.getHeight() - insets.top - insets.bottom);
    }
  
    Rectangle2D dataArea = plotArea;
    if (info != null) {
        info.setDataArea(dataArea);
    }
   
    // draw the plot background and axes...
    drawBackground(g2, dataArea);
    double h = Math.min(dataArea.getWidth() / 2.0, dataArea.getHeight() / 2.0) - MARGIN;
    Rectangle2D quadrant = new Rectangle2D.Double(
        dataArea.getCenterX(), dataArea.getCenterY(), h, h
    );
    AxisState state = drawAxis(g2, plotArea, quadrant);
    if (this.renderer != null) {
        Shape originalClip = g2.getClip();
        Composite originalComposite = g2.getComposite();
      
        g2.clip(dataArea);
        g2.setComposite(
            AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())
        );
      
        drawGridlines(g2, dataArea, this.angleTicks, state.getTicks());
      
        // draw...
        render(g2, dataArea, info);
      
        g2.setClip(originalClip);
        g2.setComposite(originalComposite);
    }
    drawOutline(g2, dataArea);
    drawCornerTextItems(g2, dataArea);
}
 
Example 15
Project: parabuild-ci   File: FastScatterPlot.java   View Source Code Vote up 4 votes
/**
 * Draws the fast scatter plot on a Java 2D graphics device (such as the screen or
 * a printer).
 *
 * @param g2  the graphics device.
 * @param plotArea   the area within which the plot (including axis labels) should be drawn.
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects chart drawing information (<code>null</code> permitted).
 */
public void draw(Graphics2D g2, Rectangle2D plotArea, PlotState parentState, 
                 PlotRenderingInfo info) {

    // set up info collection...
    if (info != null) {
        info.setPlotArea(plotArea);

    }

    // adjust the drawing area for plot insets (if any)...
    Insets insets = getInsets();
    if (insets != null) {
        plotArea.setRect(plotArea.getX() + insets.left,
                         plotArea.getY() + insets.top,
                         plotArea.getWidth() - insets.left - insets.right,
                         plotArea.getHeight() - insets.top - insets.bottom);
    }

    AxisSpace space = new AxisSpace();
    space = this.domainAxis.reserveSpace(g2, this, plotArea, RectangleEdge.BOTTOM, space);
    space = this.rangeAxis.reserveSpace(g2, this, plotArea, RectangleEdge.LEFT, space);
    Rectangle2D dataArea = space.shrink(plotArea, null);

    if (info != null) {
        info.setDataArea(dataArea);
    }

    // draw the plot background and axes...
    drawBackground(g2, dataArea);

    AxisState domainAxisState = null;
    AxisState rangeAxisState = null;
    if (this.domainAxis != null) {
        domainAxisState = this.domainAxis.draw(
            g2, dataArea.getMaxY(), plotArea, dataArea, RectangleEdge.BOTTOM, info
        );
    }
    if (this.rangeAxis != null) {
        rangeAxisState = this.rangeAxis.draw(
            g2, dataArea.getMinX(), plotArea, dataArea, RectangleEdge.LEFT, info
        );
    }
    drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
    drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
    
    Shape originalClip = g2.getClip();
    Composite originalComposite = g2.getComposite();

    g2.clip(dataArea);
    g2.setComposite(
        AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())
    );

    render(g2, dataArea, info, null);

    g2.setClip(originalClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, dataArea);

}
 
Example 16
Project: parabuild-ci   File: PiePlot.java   View Source Code Vote up 4 votes
/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a printer).
 *
 * @param g2  the graphics device.
 * @param plotArea  the area within which the plot should be drawn.
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing (<code>null</code> permitted).
 */
public void draw(Graphics2D g2, Rectangle2D plotArea, PlotState parentState,
                 PlotRenderingInfo info) {

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Entering draw() method, plot area = " + plotArea.toString());   
    }

    // adjust for insets...
    Insets insets = getInsets();
    if (insets != null) {
        plotArea.setRect(plotArea.getX() + insets.left,
            plotArea.getY() + insets.top,
            plotArea.getWidth() - insets.left - insets.right,
            plotArea.getHeight() - insets.top - insets.bottom
        );
    }

    if (info != null) {
        info.setPlotArea(plotArea);
        info.setDataArea(plotArea);
    }

    drawBackground(g2, plotArea);
    drawOutline(g2, plotArea);

    Shape savedClip = g2.getClip();
    g2.clip(plotArea);

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));

    if (!DatasetUtilities.isEmptyOrNull(this.dataset)) {
        drawPie(g2, plotArea, info);
    }
    else {
        drawNoDataMessage(g2, plotArea);
    }

    g2.setClip(savedClip);
    g2.setComposite(originalComposite);

    drawOutline(g2, plotArea);

}
 
Example 17
Project: parabuild-ci   File: WaferMapPlot.java   View Source Code Vote up 4 votes
/**
 * Calculates and draws the chip locations on the wafer.
 * 
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 */
private void drawChipGrid(Graphics2D g2, Rectangle2D plotArea) {
    
    Shape savedClip = g2.getClip();
    g2.setClip(getWaferEdge(plotArea));
    Rectangle2D chip = new Rectangle2D.Double();
    int xchips = 35;
    int ychips = 20;
    double space = 1d;
    if (this.dataset != null) {
        xchips = this.dataset.getMaxChipX() + 2;
        ychips = this.dataset.getMaxChipY() + 2;
        space = this.dataset.getChipSpace();
    }
    double startX = plotArea.getX();
    double startY = plotArea.getY();
    double chipWidth = 1d;
    double chipHeight = 1d;
    if (plotArea.getWidth() != plotArea.getHeight()) {
        double major = 0d;
        double minor = 0d;
        if (plotArea.getWidth() > plotArea.getHeight()) {
            major = plotArea.getWidth();
            minor = plotArea.getHeight();
        } 
        else {
            major = plotArea.getHeight();
            minor = plotArea.getWidth();
        } 
        //set upperLeft point
        if (plotArea.getWidth() == minor) { // x is minor
            startY += (major - minor) / 2;
            chipWidth = (plotArea.getWidth() - (space * xchips - 1)) / xchips;
            chipHeight = (plotArea.getWidth() - (space * ychips - 1)) / ychips;
        }
        else { // y is minor
            startX += (major - minor) / 2;
            chipWidth = (plotArea.getHeight() - (space * xchips - 1)) / xchips;
            chipHeight = (plotArea.getHeight() - (space * ychips - 1)) / ychips;
        }
    }
    
    for (int x = 1; x <= xchips; x++) {
        double upperLeftX = (startX - chipWidth) + (chipWidth * x) + (space * (x - 1));
        for (int y = 1; y <= ychips; y++) {
            double upperLeftY = (startY - chipHeight) + (chipHeight * y) + (space * (y - 1));
            chip.setFrame(upperLeftX, upperLeftY, chipWidth, chipHeight);
            g2.setColor(Color.white);
            if (this.dataset.getChipValue(x - 1, ychips - y - 1) != null) {
                g2.setPaint(
                    this.renderer.getChipColor(this.dataset.getChipValue(x - 1, ychips - y - 1))
                );
            } 
            g2.fill(chip);
            g2.setColor(Color.lightGray);
            g2.draw(chip);
        }
    }
    g2.setClip(savedClip);
}
 
Example 18
Project: parabuild-ci   File: PolarPlot.java   View Source Code Vote up 4 votes
/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a 
 * printer).
 * <P>
 * This plot relies on a {@link PolarItemRenderer} to draw each 
 * item in the plot.  This allows the visual representation of the data to 
 * be changed easily.
 * <P>
 * The optional info argument collects information about the rendering of
 * the plot (dimensions, tooltip information etc).  Just pass in 
 * <code>null</code> if you do not need this information.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot (including axes and 
 *              labels) should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  ignored.
 * @param info  collects chart drawing information (<code>null</code> 
 *              permitted).
 */
public void draw(Graphics2D g2, 
                 Rectangle2D area, 
                 Point2D anchor,
                 PlotState parentState,
                 PlotRenderingInfo info) {
   
    // if the plot area is too small, just return...
    boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
    boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
    if (b1 || b2) {
        return;
    }
   
    // record the plot area...
    if (info != null) {
        info.setPlotArea(area);
    }
   
    // adjust the drawing area for the plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);
  
    Rectangle2D dataArea = area;
    if (info != null) {
        info.setDataArea(dataArea);
    }
   
    // draw the plot background and axes...
    drawBackground(g2, dataArea);
    double h = Math.min(dataArea.getWidth() / 2.0, 
            dataArea.getHeight() / 2.0) - MARGIN;
    Rectangle2D quadrant = new Rectangle2D.Double(dataArea.getCenterX(), 
            dataArea.getCenterY(), h, h);
    AxisState state = drawAxis(g2, area, quadrant);
    if (this.renderer != null) {
        Shape originalClip = g2.getClip();
        Composite originalComposite = g2.getComposite();
      
        g2.clip(dataArea);
        g2.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, getForegroundAlpha()));
      
        drawGridlines(g2, dataArea, this.angleTicks, state.getTicks());
      
        // draw...
        render(g2, dataArea, info);
      
        g2.setClip(originalClip);
        g2.setComposite(originalComposite);
    }
    drawOutline(g2, dataArea);
    drawCornerTextItems(g2, dataArea);
}
 
Example 19
Project: parabuild-ci   File: FastScatterPlot.java   View Source Code Vote up 4 votes
/**
 * Draws the fast scatter plot on a Java 2D graphics device (such as the 
 * screen or a printer).
 *
 * @param g2  the graphics device.
 * @param area   the area within which the plot (including axis labels)
 *                   should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  the state from the parent plot (ignored).
 * @param info  collects chart drawing information (<code>null</code> 
 *              permitted).
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor,
                 PlotState parentState,
                 PlotRenderingInfo info) {

    // set up info collection...
    if (info != null) {
        info.setPlotArea(area);
    }

    // adjust the drawing area for plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    AxisSpace space = new AxisSpace();
    space = this.domainAxis.reserveSpace(g2, this, area, 
            RectangleEdge.BOTTOM, space);
    space = this.rangeAxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, 
            space);
    Rectangle2D dataArea = space.shrink(area, null);

    if (info != null) {
        info.setDataArea(dataArea);
    }

    // draw the plot background and axes...
    drawBackground(g2, dataArea);

    AxisState domainAxisState = this.domainAxis.draw(g2, 
            dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info);
    AxisState rangeAxisState = this.rangeAxis.draw(g2, dataArea.getMinX(), 
            area, dataArea, RectangleEdge.LEFT, info);
    drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
    drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
    
    Shape originalClip = g2.getClip();
    Composite originalComposite = g2.getComposite();

    g2.clip(dataArea);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 
            getForegroundAlpha()));

    render(g2, dataArea, info, null);

    g2.setClip(originalClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, dataArea);

}
 
Example 20
Project: parabuild-ci   File: WaferMapPlot.java   View Source Code Vote up 4 votes
/**
 * Calculates and draws the chip locations on the wafer.
 * 
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 */
protected void drawChipGrid(Graphics2D g2, Rectangle2D plotArea) {
    
    Shape savedClip = g2.getClip();
    g2.setClip(getWaferEdge(plotArea));
    Rectangle2D chip = new Rectangle2D.Double();
    int xchips = 35;
    int ychips = 20;
    double space = 1d;
    if (this.dataset != null) {
        xchips = this.dataset.getMaxChipX() + 2;
        ychips = this.dataset.getMaxChipY() + 2;
        space = this.dataset.getChipSpace();
    }
    double startX = plotArea.getX();
    double startY = plotArea.getY();
    double chipWidth = 1d;
    double chipHeight = 1d;
    if (plotArea.getWidth() != plotArea.getHeight()) {
        double major = 0d;
        double minor = 0d;
        if (plotArea.getWidth() > plotArea.getHeight()) {
            major = plotArea.getWidth();
            minor = plotArea.getHeight();
        } 
        else {
            major = plotArea.getHeight();
            minor = plotArea.getWidth();
        } 
        //set upperLeft point
        if (plotArea.getWidth() == minor) { // x is minor
            startY += (major - minor) / 2;
            chipWidth = (plotArea.getWidth() - (space * xchips - 1)) 
                / xchips;
            chipHeight = (plotArea.getWidth() - (space * ychips - 1)) 
                / ychips;
        }
        else { // y is minor
            startX += (major - minor) / 2;
            chipWidth = (plotArea.getHeight() - (space * xchips - 1)) 
                / xchips;
            chipHeight = (plotArea.getHeight() - (space * ychips - 1)) 
                / ychips;
        }
    }
    
    for (int x = 1; x <= xchips; x++) {
        double upperLeftX = (startX - chipWidth) + (chipWidth * x) 
            + (space * (x - 1));
        for (int y = 1; y <= ychips; y++) {
            double upperLeftY = (startY - chipHeight) + (chipHeight * y) 
                + (space * (y - 1));
            chip.setFrame(upperLeftX, upperLeftY, chipWidth, chipHeight);
            g2.setColor(Color.white);
            if (this.dataset.getChipValue(x - 1, ychips - y - 1) != null) {
                g2.setPaint(
                    this.renderer.getChipColor(
                        this.dataset.getChipValue(x - 1, ychips - y - 1)
                    )
                );
            } 
            g2.fill(chip);
            g2.setColor(Color.lightGray);
            g2.draw(chip);
        }
    }
    g2.setClip(savedClip);
}