Java Code Examples for java.awt.geom.Rectangle2D#getHeight()

The following examples show how to use java.awt.geom.Rectangle2D#getHeight() . 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 check out the related API usage on the sidebar.
Example 1
Source File: ProcessDrawer.java    From rapidminer-studio with GNU Affero General Public License v3.0 7 votes vote down vote up
/**
 * Draws the given {@link Operator} if inside the graphics clip bounds.
 *
 * @param op
 * 		the operator to draw. Note that it must have a position attached, see
 * 		{@link GUIProcessXMLFilter}
 * @param drawPorts
 * 		if {@true} will also draw operator ports, otherwise will not draw ports
 * @param g2
 * 		the graphics context to draw upon
 * @param printing
 * 		if {@code true} we are printing instead of drawing to the screen
 *
 */
public void drawOperator(final Operator op, final boolean drawPorts, final Graphics2D g2, final boolean printing) {
	Rectangle2D frame = model.getOperatorRect(op);
	if (frame == null) {
		return;
	}

	// only draw operator if visible
	Rectangle2D opBounds = new Rectangle2D.Double(frame.getX() - 10, frame.getY(), frame.getWidth() + 20,
			frame.getHeight());
	if (g2.getClipBounds() != null && !g2.getClipBounds().intersects(opBounds)) {
		return;
	}

	renderOperator(op, g2);
	renderPorts(op.getInputPorts(), g2, op.isEnabled());
	renderPorts(op.getOutputPorts(), g2, op.isEnabled());

	// let operator decorators draw
	drawOperatorDecorators(op, g2, printing);
}
 
Example 2
Source File: AbstractXYItemRenderer.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Fills a band between two values on the axis.  This can be used to color
 * bands between the grid lines.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the domain axis.
 * @param dataArea  the data area.
 * @param start  the start value.
 * @param end  the end value.
 */
@Override
public void fillDomainGridBand(Graphics2D g2, XYPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double start, double end) {

    double x1 = axis.valueToJava2D(start, dataArea,
            plot.getDomainAxisEdge());
    double x2 = axis.valueToJava2D(end, dataArea,
            plot.getDomainAxisEdge());
    Rectangle2D band;
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        band = new Rectangle2D.Double(Math.min(x1, x2), dataArea.getMinY(),
                Math.abs(x2 - x1), dataArea.getHeight());
    }
    else {
        band = new Rectangle2D.Double(dataArea.getMinX(), Math.min(x1, x2),
                dataArea.getWidth(), Math.abs(x2 - x1));
    }
    Paint paint = plot.getDomainTickBandPaint();

    if (paint != null) {
        g2.setPaint(paint);
        g2.fill(band);
    }

}
 
Example 3
Source File: NamedProgressBarRegionPainter.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
private Paint decodeGradient8(Shape s) {
    Rectangle2D bounds = s.getBounds2D();
    float x = (float) bounds.getX();
    float y = (float) bounds.getY();
    float w = (float) bounds.getWidth();
    float h = (float) bounds.getHeight();
    return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y,
            new float[]{0.0f, 0.20645161f, 0.41290322f, 0.44193548f, 0.47096774f, 0.7354839f, 1.0f},
            new Color[]{color24,
                    decodeColor(color24, color25, 0.5f),
                    color25,
                    decodeColor(color25, color26, 0.5f),
                    color26,
                    decodeColor(color26, color30, 0.5f),
                    color30});
}
 
Example 4
Source File: SVGDrawable.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Draws the object.
 *
 * @param g    the graphics device.
 * @param area the area inside which the object should be drawn.
 */
public void draw( final Graphics2D g, final Rectangle2D area ) {
  if ( width == 0 || height == 0 ) {
    return;
  }
  final Graphics2D g2 = (Graphics2D) g.create();
  try {
    g2.translate( -area.getX(), -area.getY() );
    final double sx = area.getWidth() / width;
    final double sy = area.getHeight() / height;
    final double sm = Math.min( sx, sy );
    g2.scale( sm, sm );

    rootNode.paint( g2 );
  } finally {
    g2.dispose();
  }
}
 
Example 5
Source File: CategoryAxis.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the starting coordinate for the specified category.
 *
 * @param category  the category.
 * @param categoryCount  the number of categories.
 * @param area  the data area.
 * @param edge  the axis location.
 *
 * @return The coordinate.
 *
 * @see #getCategoryMiddle(int, int, Rectangle2D, RectangleEdge)
 * @see #getCategoryEnd(int, int, Rectangle2D, RectangleEdge)
 */
public double getCategoryStart(int category, int categoryCount, 
        Rectangle2D area, RectangleEdge edge) {

    double result = 0.0;
    if ((edge == RectangleEdge.TOP) || (edge == RectangleEdge.BOTTOM)) {
        result = area.getX() + area.getWidth() * getLowerMargin();
    }
    else if ((edge == RectangleEdge.LEFT)
            || (edge == RectangleEdge.RIGHT)) {
        result = area.getMinY() + area.getHeight() * getLowerMargin();
    }

    double categorySize = calculateCategorySize(categoryCount, area, edge);
    double categoryGapWidth = calculateCategoryGapSize(categoryCount, area,
            edge);

    result = result + category * (categorySize + categoryGapWidth);
    return result;
}
 
Example 6
Source File: AbstractXYItemRenderer.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Fills a band between two values on the range axis.  This can be used to
 * color bands between the grid lines.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the range axis.
 * @param dataArea  the data area.
 * @param start  the start value.
 * @param end  the end value.
 */
@Override
public void fillRangeGridBand(Graphics2D g2, XYPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double start, double end) {

    double y1 = axis.valueToJava2D(start, dataArea,
            plot.getRangeAxisEdge());
    double y2 = axis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge());
    Rectangle2D band;
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        band = new Rectangle2D.Double(dataArea.getMinX(), Math.min(y1, y2),
            dataArea.getWidth(), Math.abs(y2 - y1));
    }
    else {
        band = new Rectangle2D.Double(Math.min(y1, y2), dataArea.getMinY(),
                Math.abs(y2 - y1), dataArea.getHeight());
    }
    Paint paint = plot.getRangeTickBandPaint();

    if (paint != null) {
        g2.setPaint(paint);
        g2.fill(band);
    }

}
 
Example 7
Source File: ChartPanel.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
void onMousePressed(MouseEvent e) {
    mouseDownPoint.x = e.getX();
    mouseDownPoint.y = e.getY();
    mouseLastPos = (Point) mouseDownPoint.clone();
    switch (this.mouseMode) {
        case PAN:
            Plot plot = selPlot(e.getX(), e.getY());
            if (plot != null) {
                Rectangle2D mapRect = plot.getGraphArea();
                tempImage = new BufferedImage((int) mapRect.getWidth() - 2,
                        (int) mapRect.getHeight() - 2, BufferedImage.TYPE_INT_ARGB);
                Graphics2D tg = tempImage.createGraphics();
                tg.setColor(Color.white);
                tg.fill(mapRect);
                tg.drawImage(this.mapBitmap, -(int) mapRect.getX() - 1, -(int) mapRect.getY() - 1, this);
                tg.dispose();
            }
            break;
    }
}
 
Example 8
Source File: ChartLogicsFX.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * Domain and Range axes need to share the same unit (e.g. mm)
 * 
 * @param myChart
 * @return
 */
public static double calcWidthToHeight(ChartViewer myChart, double chartHeight) {
  makeChartResizable(myChart);

  myChart.getCanvas().draw();

  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  ChartRenderingInfo info = myChart.getRenderingInfo();
  Rectangle2D dataArea = info.getPlotInfo().getDataArea();
  Rectangle2D chartArea = info.getChartArea();


  // calc title space: will be added later to the right plot size
  double titleWidth = chartArea.getWidth() - dataArea.getWidth();
  double titleHeight = chartArea.getHeight() - dataArea.getHeight();

  // calc right plot size with axis dim.
  // real plot width is given by factor;
  double realPH = chartHeight - titleHeight;

  // ranges
  ValueAxis domainAxis = plot.getDomainAxis();
  org.jfree.data.Range x = domainAxis.getRange();
  ValueAxis rangeAxis = plot.getRangeAxis();
  org.jfree.data.Range y = rangeAxis.getRange();

  // real plot height can be calculated by
  double realPW = realPH / y.getLength() * x.getLength();

  double width = realPW + titleWidth;

  return width;
}
 
Example 9
Source File: LevelRenderer.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the coordinate of the first "side" of a bar.  This will be
 * the minimum x-coordinate for a vertical bar, and the minimum
 * y-coordinate for a horizontal bar.
 *
 * @param plot  the plot.
 * @param orientation  the plot orientation.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param state  the renderer state (has the bar width precalculated).
 * @param row  the row index.
 * @param column  the column index.
 *
 * @return The coordinate.
 */
protected double calculateBarW0(CategoryPlot plot, 
        PlotOrientation orientation, Rectangle2D dataArea,
        CategoryAxis domainAxis, CategoryItemRendererState state, int row,
        int column) {
    // calculate bar width...
    double space;
    if (orientation == PlotOrientation.HORIZONTAL) {
        space = dataArea.getHeight();
    }
    else {
        space = dataArea.getWidth();
    }
    double barW0 = domainAxis.getCategoryStart(column, getColumnCount(),
            dataArea, plot.getDomainAxisEdge());
    int seriesCount = state.getVisibleSeriesCount();
    if (seriesCount < 0) {
        seriesCount = getRowCount();
    }
    int categoryCount = getColumnCount();
    if (seriesCount > 1) {
        double seriesGap = space * getItemMargin()
                / (categoryCount * (seriesCount - 1));
        double seriesW = calculateSeriesWidth(space, domainAxis,
                categoryCount, seriesCount);
        barW0 = barW0 + row * (seriesW + seriesGap)
                      + (seriesW / 2.0) - (state.getBarWidth() / 2.0);
    }
    else {
        barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(),
                dataArea, plot.getDomainAxisEdge()) - state.getBarWidth()
                / 2.0;
    }
    return barW0;
}
 
Example 10
Source File: ChartPanel.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the data area for the chart (the area inside the axes) with the
 * current scaling applied (that is, the area as it appears on screen).
 *
 * @return The scaled data area.
 */
public Rectangle2D getScreenDataArea() {
    Rectangle2D dataArea = this.info.getPlotInfo().getDataArea();
    Insets insets = getInsets();
    double x = dataArea.getX() * this.scaleX + insets.left;
    double y = dataArea.getY() * this.scaleY + insets.top;
    double w = dataArea.getWidth() * this.scaleX;
    double h = dataArea.getHeight() * this.scaleY;
    return new Rectangle2D.Double(x, y, w, h);
}
 
Example 11
Source File: NamedComboBoxPainter.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private Paint decodeGradient5(Shape s) {
    Rectangle2D bounds = s.getBounds2D();
    float x = (float) bounds.getX();
    float y = (float) bounds.getY();
    float w = (float) bounds.getWidth();
    float h = (float) bounds.getHeight();
    return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y,
            new float[]{0.0f, 0.5f, 1.0f},
            new Color[]{color15,
                    decodeColor(color15, color16, 0.5f),
                    color16});
}
 
Example 12
Source File: SearchComboBoxPainter.java    From cuba with Apache License 2.0 5 votes vote down vote up
private Paint decodeGradient10(Shape s) {
    Rectangle2D bounds = s.getBounds2D();
    float x = (float) bounds.getX();
    float y = (float) bounds.getY();
    float w = (float) bounds.getWidth();
    float h = (float) bounds.getHeight();
    return decodeGradient((0.5f * w) + x, (0.0f * h) + y, (0.5f * w) + x, (1.0f * h) + y,
            new float[]{0.0f, 0.5f, 1.0f},
            new Color[]{color33,
                    decodeColor(color33, color34, 0.5f),
                    color34});
}
 
Example 13
Source File: XYTitleAnnotation.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the annotation.  This method is called by the drawing code in the
 * {@link XYPlot} class, you don't normally need to call this method
 * directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  if supplied, this info object will be populated with
 *              entity information.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis,
                 int rendererIndex, PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    AxisLocation domainAxisLocation = plot.getDomainAxisLocation();
    AxisLocation rangeAxisLocation = plot.getRangeAxisLocation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            domainAxisLocation, orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            rangeAxisLocation, orientation);
    Range xRange = domainAxis.getRange();
    Range yRange = rangeAxis.getRange();
    double anchorX, anchorY;
    if (this.coordinateType == XYCoordinateType.RELATIVE) {
        anchorX = xRange.getLowerBound() + (this.x * xRange.getLength());
        anchorY = yRange.getLowerBound() + (this.y * yRange.getLength());
    }
    else {
        anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
        anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
    }

    float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea,
            domainEdge);
    float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea,
            rangeEdge);
    float xx = 0.0f;
    float yy = 0.0f;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = j2DY;
        yy = j2DX;
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        xx = j2DX;
        yy = j2DY;
    }

    double maxW = dataArea.getWidth();
    double maxH = dataArea.getHeight();
    if (this.coordinateType == XYCoordinateType.RELATIVE) {
        if (this.maxWidth > 0.0) {
            maxW = maxW * this.maxWidth;
        }
        if (this.maxHeight > 0.0) {
            maxH = maxH * this.maxHeight;
        }
    }
    if (this.coordinateType == XYCoordinateType.DATA) {
        maxW = this.maxWidth;
        maxH = this.maxHeight;
    }
    RectangleConstraint rc = new RectangleConstraint(
            new Range(0, maxW), new Range(0, maxH));

    Size2D size = this.title.arrange(g2, rc);
    Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width,
            size.height);
    Point2D anchorPoint = RectangleAnchor.coordinates(titleRect,
            this.anchor);
    xx = xx - (float) anchorPoint.getX();
    yy = yy - (float) anchorPoint.getY();
    titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight());
    BlockParams p = new BlockParams();
    if (info != null) {
        if (info.getOwner().getEntityCollection() != null) {
            p.setGenerateEntities(true);
        }
    }
    Object result = this.title.draw(g2, titleRect, p);
    if (info != null) {
        if (result instanceof EntityBlockResult) {
            EntityBlockResult ebr = (EntityBlockResult) result;
            info.getOwner().getEntityCollection().addAll(
                    ebr.getEntityCollection());
        }
        String toolTip = getToolTipText();
        String url = getURL();
        if (toolTip != null || url != null) {
            addEntity(info, new Rectangle2D.Float(xx, yy,
                    (float) size.width, (float) size.height),
                    rendererIndex, toolTip, url);
        }
    }
}
 
Example 14
Source File: PSPathGraphics.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/** Redraw a rectanglular area using a proxy graphics
  * To do this we need to know the rectangular area to redraw and
  * the transform & clip in effect at the time of the original drawImage
  *
  */

public void redrawRegion(Rectangle2D region, double scaleX, double scaleY,
                         Shape savedClip, AffineTransform savedTransform)

        throws PrinterException {

    PSPrinterJob psPrinterJob = (PSPrinterJob)getPrinterJob();
    Printable painter = getPrintable();
    PageFormat pageFormat = getPageFormat();
    int pageIndex = getPageIndex();

    /* Create a buffered image big enough to hold the portion
     * of the source image being printed.
     */
    BufferedImage deepImage = new BufferedImage(
                                    (int) region.getWidth(),
                                    (int) region.getHeight(),
                                    BufferedImage.TYPE_3BYTE_BGR);

    /* Get a graphics for the application to render into.
     * We initialize the buffer to white in order to
     * match the paper and then we shift the BufferedImage
     * so that it covers the area on the page where the
     * caller's Image will be drawn.
     */
    Graphics2D g = deepImage.createGraphics();
    ProxyGraphics2D proxy = new ProxyGraphics2D(g, psPrinterJob);
    proxy.setColor(Color.white);
    proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
    proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());

    proxy.translate(-region.getX(), -region.getY());

    /* Calculate the resolution of the source image.
     */
    float sourceResX = (float)(psPrinterJob.getXRes() / scaleX);
    float sourceResY = (float)(psPrinterJob.getYRes() / scaleY);

    /* The application expects to see user space at 72 dpi.
     * so change user space from image source resolution to
     *  72 dpi.
     */
    proxy.scale(sourceResX / DEFAULT_USER_RES,
                sourceResY / DEFAULT_USER_RES);
   proxy.translate(
        -psPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
           / psPrinterJob.getXRes() * DEFAULT_USER_RES,
        -psPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
           / psPrinterJob.getYRes() * DEFAULT_USER_RES);
   /* NB User space now has to be at 72 dpi for this calc to be correct */
    proxy.transform(new AffineTransform(getPageFormat().getMatrix()));

    proxy.setPaint(Color.black);

    painter.print(proxy, pageFormat, pageIndex);

    g.dispose();

    /* In PSPrinterJob images are printed in device space
     * and therefore we need to set a device space clip.
     */
    psPrinterJob.setClip(savedTransform.createTransformedShape(savedClip));


    /* Scale the bounding rectangle by the scale transform.
     * Because the scaling transform has only x and y
     * scaling components it is equivalent to multiply
     * the x components of the bounding rectangle by
     * the x scaling factor and to multiply the y components
     * by the y scaling factor.
     */
    Rectangle2D.Float scaledBounds
            = new Rectangle2D.Float(
                    (float) (region.getX() * scaleX),
                    (float) (region.getY() * scaleY),
                    (float) (region.getWidth() * scaleX),
                    (float) (region.getHeight() * scaleY));


    /* Pull the raster data from the buffered image
     * and pass it along to PS.
     */
    ByteComponentRaster tile = (ByteComponentRaster)deepImage.getRaster();

    psPrinterJob.drawImageBGR(tile.getDataStorage(),
                        scaledBounds.x, scaledBounds.y,
                        scaledBounds.width,
                        scaledBounds.height,
                        0f, 0f,
                        deepImage.getWidth(), deepImage.getHeight(),
                        deepImage.getWidth(), deepImage.getHeight());


}
 
Example 15
Source File: JobInformation.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void drawImage( final Graphics2D g2d, final Rectangle2D rectangle2d, ReportSubjectLocation location,
  boolean pixelateImages ) throws KettleException {

  // Load the job
  //
  JobMeta jobMeta = loadJob( location );

  Point min = jobMeta.getMinimum();
  Point area = jobMeta.getMaximum();

  area.x -= min.x;
  area.y -= min.y;

  int iconsize = 32;

  ScrollBarInterface bar = new ScrollBarInterface() {
    public void setThumb( int thumb ) {
    }

    public int getSelection() {
      return 0;
    }
  };

  // Paint the transformation...
  //
  Rectangle rect = new java.awt.Rectangle( 0, 0, area.x, area.y );
  double magnificationX = rectangle2d.getWidth() / rect.getWidth();
  double magnificationY = rectangle2d.getHeight() / rect.getHeight();
  float magnification = (float) Math.min( 1, Math.min( magnificationX, magnificationY ) );

  SwingGC gc = new SwingGC( g2d, rect, iconsize, 0, 0 );
  gc.setDrawingPixelatedImages( pixelateImages );
  List<AreaOwner> areaOwners = new ArrayList<AreaOwner>();
  JobPainter painter =
      new JobPainter( gc, jobMeta, area, bar, bar, null, null, null, areaOwners, new ArrayList<JobEntryCopy>(),
          iconsize, 1, 0, 0, true, "FreeSans", 10 );

  painter.setMagnification( magnification );

  painter.setTranslationX( ( -min.x ) * magnification );
  painter.setTranslationY( ( -min.y ) * magnification );

  painter.drawJob();
}
 
Example 16
Source File: ValueAxis.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the space required to draw the axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot that the axis belongs to.
 * @param plotArea  the area within which the plot should be drawn.
 * @param edge  the axis location.
 * @param space  the space already reserved (for other axes).
 *
 * @return The space required to draw the axis (including pre-reserved
 *         space).
 */
@Override
public AxisSpace reserveSpace(Graphics2D g2, Plot plot, 
        Rectangle2D plotArea, RectangleEdge edge, AxisSpace space) {

    // create a new space object if one wasn't supplied...
    if (space == null) {
        space = new AxisSpace();
    }

    // if the axis is not visible, no additional space is required...
    if (!isVisible()) {
        return space;
    }

    // if the axis has a fixed dimension, return it...
    double dimension = getFixedDimension();
    if (dimension > 0.0) {
        space.add(dimension, edge);
        return space;
    }

    // calculate the max size of the tick labels (if visible)...
    double tickLabelHeight = 0.0;
    double tickLabelWidth = 0.0;
    if (isTickLabelsVisible()) {
        g2.setFont(getTickLabelFont());
        List ticks = refreshTicks(g2, new AxisState(), plotArea, edge);
        if (RectangleEdge.isTopOrBottom(edge)) {
            tickLabelHeight = findMaximumTickLabelHeight(ticks, g2,
                    plotArea, isVerticalTickLabels());
        }
        else if (RectangleEdge.isLeftOrRight(edge)) {
            tickLabelWidth = findMaximumTickLabelWidth(ticks, g2, plotArea,
                    isVerticalTickLabels());
        }
    }

    // get the axis label size and update the space object...
    Rectangle2D labelEnclosure = getLabelEnclosure(g2, edge);
    if (RectangleEdge.isTopOrBottom(edge)) {
        double labelHeight = labelEnclosure.getHeight();
        space.add(labelHeight + tickLabelHeight, edge);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        double labelWidth = labelEnclosure.getWidth();
        space.add(labelWidth + tickLabelWidth, edge);
    }

    return space;

}
 
Example 17
Source File: NumberAxis3D.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the axis on a Java 2D graphics device (such as the screen or a
 * printer).
 *
 * @param g2  the graphics device.
 * @param cursor  the cursor.
 * @param plotArea  the area for drawing the axes and data.
 * @param dataArea  the area for drawing the data (a subset of the
 *                  plotArea).
 * @param edge  the axis location.
 * @param plotState  collects information about the plot (<code>null</code>
 *                   permitted).
 *
 * @return The updated cursor value.
 */
@Override
public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea,
        Rectangle2D dataArea, RectangleEdge edge,
        PlotRenderingInfo plotState) {

    // if the axis is not visible, don't draw it...
    if (!isVisible()) {
        AxisState state = new AxisState(cursor);
        // even though the axis is not visible, we need ticks for the
        // gridlines...
        List ticks = refreshTicks(g2, state, dataArea, edge);
        state.setTicks(ticks);
        return state;
    }

    // calculate the adjusted data area taking into account the 3D effect...
    double xOffset = 0.0;
    double yOffset = 0.0;
    Plot plot = getPlot();
    if (plot instanceof CategoryPlot) {
        CategoryPlot cp = (CategoryPlot) plot;
        CategoryItemRenderer r = cp.getRenderer();
        if (r instanceof Effect3D) {
            Effect3D e3D = (Effect3D) r;
            xOffset = e3D.getXOffset();
            yOffset = e3D.getYOffset();
        }
    }

    double adjustedX = dataArea.getMinX();
    double adjustedY = dataArea.getMinY();
    double adjustedW = dataArea.getWidth() - xOffset;
    double adjustedH = dataArea.getHeight() - yOffset;

    if (edge == RectangleEdge.LEFT || edge == RectangleEdge.BOTTOM) {
        adjustedY += yOffset;
    }
    else if (edge == RectangleEdge.RIGHT || edge == RectangleEdge.TOP) {
        adjustedX += xOffset;
    }
    Rectangle2D adjustedDataArea = new Rectangle2D.Double(adjustedX,
            adjustedY, adjustedW, adjustedH);

    // draw the tick marks and labels...
    AxisState info = drawTickMarksAndLabels(g2, cursor, plotArea,
            adjustedDataArea, edge);

    if (getAttributedLabel() != null) {
        info = drawAttributedLabel(getAttributedLabel(), g2, plotArea, 
                dataArea, edge, info);
    } else {
        info = drawLabel(getLabel(), g2, plotArea, dataArea, edge, info);
    }
    return info;

}
 
Example 18
Source File: SpiderWebPlot.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 */
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)) {
        int seriesCount = 0, catCount = 0;

        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            seriesCount = this.dataset.getRowCount();
            catCount = this.dataset.getColumnCount();
        }
        else {
            seriesCount = this.dataset.getColumnCount();
            catCount = this.dataset.getRowCount();
        }

        // ensure we have a maximum value to use on the axes
        if (this.maxValue == DEFAULT_MAX_VALUE)
            calculateMaxValue(seriesCount, catCount);

        // Next, setup the plot area

        // adjust the plot area by the interior spacing value

        double gapHorizontal = area.getWidth() * getInteriorGap();
        double gapVertical = area.getHeight() * getInteriorGap();

        double X = area.getX() + gapHorizontal / 2;
        double Y = area.getY() + gapVertical / 2;
        double W = area.getWidth() - gapHorizontal;
        double H = area.getHeight() - gapVertical;

        double headW = area.getWidth() * this.headPercent;
        double headH = area.getHeight() * this.headPercent;

        // make the chart area a square
        double min = Math.min(W, H) / 2;
        X = (X + X + W) / 2 - min;
        Y = (Y + Y + H) / 2 - min;
        W = 2 * min;
        H = 2 * min;

        Point2D  centre = new Point2D.Double(X + W / 2, Y + H / 2);
        Rectangle2D radarArea = new Rectangle2D.Double(X, Y, W, H);

        // draw the axis and category label
        for (int cat = 0; cat < catCount; cat++) {
            double angle = getStartAngle()
                    + (getDirection().getFactor() * cat * 360 / catCount);

            Point2D endPoint = getWebPoint(radarArea, angle, 1);
                                                 // 1 = end of axis
            Line2D  line = new Line2D.Double(centre, endPoint);
            g2.setPaint(this.axisLinePaint);
            g2.setStroke(this.axisLineStroke);
            g2.draw(line);
            drawLabel(g2, radarArea, 0.0, cat, angle, 360.0 / catCount);
        }

        // Now actually plot each of the series polygons..
        for (int series = 0; series < seriesCount; series++) {
            drawRadarPoly(g2, radarArea, centre, info, series, catCount,
                    headH, headW);
        }
    }
    else {
        drawNoDataMessage(g2, area);
    }
    g2.setClip(savedClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, area);
}
 
Example 19
Source File: PointerNeedle.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
@Override
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea,
                          Point2D rotate, double angle) {

    GeneralPath shape1 = new GeneralPath();
    GeneralPath shape2 = new GeneralPath();
    float minX = (float) plotArea.getMinX();
    float minY = (float) plotArea.getMinY();
    float maxX = (float) plotArea.getMaxX();
    float maxY = (float) plotArea.getMaxY();
    float midX = (float) (minX + (plotArea.getWidth() / 2));
    float midY = (float) (minY + (plotArea.getHeight() / 2));

    shape1.moveTo(minX, midY);
    shape1.lineTo(midX, minY);
    shape1.lineTo(maxX, midY);
    shape1.closePath();

    shape2.moveTo(minX, midY);
    shape2.lineTo(midX, maxY);
    shape2.lineTo(maxX, midY);
    shape2.closePath();

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation huston, please spin me
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        shape1.transform(getTransform());
        shape2.transform(getTransform());
    }

    if (getFillPaint() != null) {
        g2.setPaint(getFillPaint());
        g2.fill(shape1);
    }

    if (getHighlightPaint() != null) {
        g2.setPaint(getHighlightPaint());
        g2.fill(shape2);
    }

    if (getOutlinePaint() != null) {
        g2.setStroke(getOutlineStroke());
        g2.setPaint(getOutlinePaint());
        g2.draw(shape1);
        g2.draw(shape2);
    }
}
 
Example 20
Source File: CategoryAxis3D.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the Java 2D coordinate for a category.
 *
 * @param anchor  the anchor point.
 * @param category  the category index.
 * @param categoryCount  the category count.
 * @param area  the data area.
 * @param edge  the location of the axis.
 *
 * @return The coordinate.
 */
@Override
public double getCategoryJava2DCoordinate(CategoryAnchor anchor, 
        int category, int categoryCount, Rectangle2D area, 
        RectangleEdge edge) {

    double result = 0.0;
    Rectangle2D adjustedArea = area;
    CategoryPlot plot = (CategoryPlot) getPlot();
    CategoryItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof Effect3D) {
        Effect3D e3D = (Effect3D) renderer;
        double adjustedX = area.getMinX();
        double adjustedY = area.getMinY();
        double adjustedW = area.getWidth() - e3D.getXOffset();
        double adjustedH = area.getHeight() - e3D.getYOffset();

        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.BOTTOM) {
            adjustedY += e3D.getYOffset();
        }
        else if (edge == RectangleEdge.RIGHT || edge == RectangleEdge.TOP) {
            adjustedX += e3D.getXOffset();
        }
        adjustedArea = new Rectangle2D.Double(adjustedX, adjustedY,
                adjustedW, adjustedH);
    }

    if (anchor == CategoryAnchor.START) {
        result = getCategoryStart(category, categoryCount, adjustedArea,
                edge);
    }
    else if (anchor == CategoryAnchor.MIDDLE) {
        result = getCategoryMiddle(category, categoryCount, adjustedArea,
                edge);
    }
    else if (anchor == CategoryAnchor.END) {
        result = getCategoryEnd(category, categoryCount, adjustedArea,
                edge);
    }
    return result;

}