Search in sources :

Example 26 with Point2D

use of java.awt.geom.Point2D in project opennms by OpenNMS.

the class TopoFRLayout method calcRepulsion.

protected void calcRepulsion(V v1) {
    FRVertexData fvd1 = getFRData(v1);
    if (fvd1 == null)
        return;
    fvd1.setLocation(0, 0);
    try {
        for (V v2 : getGraph().getVertices()) {
            if (v1 != v2) {
                Point2D p1 = transform(v1);
                Point2D p2 = transform(v2);
                if (p1 == null || p2 == null)
                    continue;
                double xDelta = p1.getX() - p2.getX();
                double yDelta = p1.getY() - p2.getY();
                xDelta = Math.abs(xDelta) > EPSILON ? xDelta : xDelta == 0 ? epsilon() : Math.signum(xDelta) * EPSILON;
                yDelta = Math.abs(yDelta) > EPSILON ? yDelta : yDelta == 0 ? epsilon() : Math.signum(yDelta) * EPSILON;
                double deltaLength = Math.sqrt((xDelta * xDelta) + (yDelta * yDelta));
                double force = (repulsion_constant * repulsion_constant) / deltaLength;
                if (Double.isNaN(force)) {
                    throw new RuntimeException("Unexpected mathematical result in FRLayout:calcPositions [repulsion]");
                }
                fvd1.offset((xDelta / deltaLength) * force, (yDelta / deltaLength) * force);
            }
        }
    } catch (ConcurrentModificationException cme) {
        calcRepulsion(v1);
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) Point2D(java.awt.geom.Point2D)

Example 27 with Point2D

use of java.awt.geom.Point2D in project opennms by OpenNMS.

the class DblBoundingBox method computeWithAspectRatio.

public DblBoundingBox computeWithAspectRatio(double R) {
    double r = getAspectRatio();
    double width = r < R ? Math.round(getHeight() * R) : getWidth();
    double height = r < R ? getHeight() : Math.round(getWidth() / R);
    Point2D center = getCenter();
    return new DblBoundingBox(center, width, height);
}
Also used : Point2D(java.awt.geom.Point2D)

Example 28 with Point2D

use of java.awt.geom.Point2D in project spatial-portal by AtlasOfLivingAustralia.

the class AooEooComposer method aooProcess.

private int aooProcess(LegendObject legend, double gridSize) {
    Set set = new HashSet<Point2D>();
    for (String key : legend.getCategories().keySet()) {
        try {
            //key=latitude,longitude
            String[] ll = key.split(",");
            Point2D point = new Point2D.Float(round(Double.parseDouble(ll[1]), gridSize), round(Double.parseDouble(ll[0]), gridSize));
            set.add(point);
        } catch (Exception e) {
        }
    }
    return set.size();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Point2D(java.awt.geom.Point2D) HashSet(java.util.HashSet)

Example 29 with Point2D

use of java.awt.geom.Point2D in project adempiere by adempiere.

the class ImageElement method paint.

/**
	 * 	Paint Image
	 * 	@param g2D Graphics
	 *  @param pageStart top left Location of page
	 *  @param pageNo page number for multi page support (0 = header/footer) - ignored
	 *  @param ctx print context
	 *  @param isView true if online view (IDs are links)
	 */
public void paint(Graphics2D g2D, int pageNo, Point2D pageStart, Properties ctx, boolean isView) {
    if (m_image == null)
        return;
    //	Position
    Point2D.Double location = getAbsoluteLocation(pageStart);
    int x = (int) location.x;
    if (MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight.equals(p_FieldAlignmentType))
        x += p_maxWidth - p_width;
    else if (MPrintFormatItem.FIELDALIGNMENTTYPE_Center.equals(p_FieldAlignmentType))
        x += (p_maxWidth - p_width) / 2;
    int y = (int) location.y;
    // 	map a scaled and shifted version of the image to device space
    AffineTransform transform = new AffineTransform();
    transform.translate(x, y);
    transform.scale(m_scaleFactor, m_scaleFactor);
    g2D.drawImage(m_image, transform, this);
}
Also used : Point2D(java.awt.geom.Point2D) AffineTransform(java.awt.geom.AffineTransform)

Example 30 with Point2D

use of java.awt.geom.Point2D in project adempiere by adempiere.

the class StringElement method paint.

//	getDrillAcross
/**************************************************************************
	 * 	Paint/Print.
	 *  Calculate actual Size.
	 *  The text is printed in the topmost left position - i.e. the leading is below the line
	 * 	@param g2D Graphics
	 *  @param pageStart top left Location of page
	 *  @param pageNo page number for multi page support (0 = header/footer) - ignored
	 *  @param ctx print context
	 *  @param isView true if online view (IDs are links)
	 */
public void paint(Graphics2D g2D, int pageNo, Point2D pageStart, Properties ctx, boolean isView) {
    //	log.finest( "StringElement.paint", "<" + m_originalString + "> " + p_pageLocation.x + "/" + p_pageLocation.y
    //		+ ", Clip=" + g2D.getClip()
    //		+ ", Translate=" + g2D.getTransform().getTranslateX() + "/" + g2D.getTransform().getTranslateY()
    //		+ ", Scale=" + g2D.getTransform().getScaleX() + "/" + g2D.getTransform().getScaleY()
    //		+ ", Shear=" + g2D.getTransform().getShearX() + "/" + g2D.getTransform().getShearY());
    Point2D.Double location = getAbsoluteLocation(pageStart);
    //
    if (m_originalString != null)
        translate(ctx);
    AttributedString aString = null;
    AttributedCharacterIterator iter = null;
    AttributedCharacterIterator iter2 = null;
    float xPos = (float) location.x;
    float yPos = (float) location.y;
    float yPen = 0f;
    float height = 0f;
    float width = 0f;
    //	for all lines
    for (int i = 0; i < m_string_paper.length; i++) {
        //	Get Text
        if (isView) {
            if (m_string_view[i] == null)
                continue;
            aString = m_string_view[i];
        } else {
            if (m_string_paper[i] == null)
                continue;
            aString = m_string_paper[i];
        }
        iter = aString.getIterator();
        //	Zero Length
        if (iter.getBeginIndex() == iter.getEndIndex())
            continue;
        //	Check for Tab (just first) and 16 bit characters
        int tabPos = -1;
        boolean is8Bit = true;
        for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
            if (c == '\t' && tabPos == -1)
                tabPos = iter.getIndex();
            if (c > 255)
                is8Bit = false;
        }
        TextLayout layout = null;
        float xPen = xPos;
        //	No Limit
        if (p_maxWidth == 0f) {
            if (tabPos == -1) {
                layout = new TextLayout(iter, g2D.getFontRenderContext());
                yPen = yPos + layout.getAscent();
                //	layout.draw(g2D, xPen, yPen);
                g2D.setFont(m_font);
                g2D.setPaint(m_paint);
                g2D.drawString(iter, xPen, yPen);
                //
                yPos += layout.getAscent() + layout.getDescent() + layout.getLeading();
                if (width < layout.getAdvance())
                    width = layout.getAdvance();
            } else //	we have a tab
            {
                LineBreakMeasurer measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
                layout = measurer.nextLayout(9999, tabPos, false);
                float lineHeight_1 = layout.getAscent() + layout.getDescent() + layout.getLeading();
                yPen = yPos + layout.getAscent();
                //	first part before tab
                layout.draw(g2D, xPen, yPen);
                xPen = getTabPos(xPos, layout.getAdvance());
                float lineWidth = xPen - xPos;
                //, iter.getEndIndex(), true);
                layout = measurer.nextLayout(9999);
                float lineHeight_2 = layout.getAscent() + layout.getDescent() + layout.getLeading();
                //	second part after tab
                layout.draw(g2D, xPen, yPen);
                //
                yPos += Math.max(lineHeight_1, lineHeight_2);
                lineWidth += layout.getAdvance();
                if (width < lineWidth)
                    width = lineWidth;
            }
        //	log.finest( "StringElement.paint - No Limit - " + location.x + "/" + yPos
        //		+ " w=" + layout.getAdvance() + ",h=" + lineHeight + ", Bounds=" + layout.getBounds());
        } else //	Size Limits
        {
            boolean fastDraw = LayoutEngine.s_FASTDRAW;
            if (fastDraw && !isView && !is8Bit)
                fastDraw = false;
            LineBreakMeasurer measurer = new LineBreakMeasurer(iter, g2D.getFontRenderContext());
            while (measurer.getPosition() < iter.getEndIndex()) {
                if (tabPos == -1) {
                    layout = measurer.nextLayout(p_maxWidth);
                    if (measurer.getPosition() < iter.getEndIndex())
                        fastDraw = false;
                } else //	tab
                {
                    fastDraw = false;
                    layout = measurer.nextLayout(p_maxWidth, tabPos, false);
                }
                //	Line Height
                float lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
                if (//	one line only
                p_maxHeight == -1f && i == 0)
                    p_maxHeight = lineHeight;
                //	If we have hight left over
                if (p_maxHeight == 0f || (height + lineHeight) <= p_maxHeight) {
                    yPen = (float) location.y + height + layout.getAscent();
                    //	Tab in Text
                    if (tabPos != -1) {
                        //	first part before tab
                        layout.draw(g2D, xPen, yPen);
                        xPen = getTabPos(xPos, layout.getAdvance());
                        layout = measurer.nextLayout(p_width, iter.getEndIndex(), true);
                        //	reset (just one tab)
                        tabPos = -1;
                    } else if ((MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight.equals(p_FieldAlignmentType) && layout.isLeftToRight()) || (MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft.equals(p_FieldAlignmentType) && !layout.isLeftToRight()))
                        xPen += p_maxWidth - layout.getAdvance();
                    else if (MPrintFormatItem.FIELDALIGNMENTTYPE_Center.equals(p_FieldAlignmentType))
                        xPen += (p_maxWidth - layout.getAdvance()) / 2;
                    else if (MPrintFormatItem.FIELDALIGNMENTTYPE_Block.equals(p_FieldAlignmentType) && measurer.getPosition() < iter.getEndIndex()) {
                        layout = layout.getJustifiedLayout(p_maxWidth);
                        fastDraw = false;
                    }
                    if (fastDraw) {
                        g2D.setFont(m_font);
                        g2D.setPaint(m_paint);
                        g2D.drawString(iter, xPen, yPen);
                        height += lineHeight;
                        break;
                    } else {
                        layout.draw(g2D, xPen, yPen);
                    }
                    height += lineHeight;
                //	log.finest( "StringElement.paint - Limit - " + xPen + "/" + yPen
                //		+ " w=" + layout.getAdvance() + ",h=" + lineHeight + ", Align=" + p_FieldAlignmentType + ", Max w=" + p_maxWidth + ",h=" + p_maxHeight + ", Bounds=" + layout.getBounds());
                }
            }
            width = p_maxWidth;
        }
    //	size limits
    }
    //	for all strings
    if (m_check != null) {
        int x = (int) (location.x + width + 1);
        int y = (int) (location.y);
        g2D.drawImage(m_check.booleanValue() ? LayoutEngine.IMAGE_TRUE : LayoutEngine.IMAGE_FALSE, x, y, this);
    }
}
Also used : AttributedString(java.text.AttributedString) Point2D(java.awt.geom.Point2D) LineBreakMeasurer(java.awt.font.LineBreakMeasurer) Point(java.awt.Point) Paint(java.awt.Paint) AttributedCharacterIterator(java.text.AttributedCharacterIterator) TextLayout(java.awt.font.TextLayout)

Aggregations

Point2D (java.awt.geom.Point2D)159 Rectangle2D (java.awt.geom.Rectangle2D)18 Color (java.awt.Color)12 RadialGradientPaint (java.awt.RadialGradientPaint)10 AffineTransform (java.awt.geom.AffineTransform)10 Line2D (java.awt.geom.Line2D)9 Paint (java.awt.Paint)8 Graphics2D (java.awt.Graphics2D)7 BufferedImage (java.awt.image.BufferedImage)7 Element (org.jdom2.Element)6 BasicStroke (java.awt.BasicStroke)5 IOException (java.io.IOException)5 LinearGradientPaint (java.awt.LinearGradientPaint)4 Point (java.awt.Point)4 Rectangle (java.awt.Rectangle)4 NodeRef (dr.evolution.tree.NodeRef)3 RenderableBlock (edu.mit.blocks.renderable.RenderableBlock)3 Arc2D (java.awt.geom.Arc2D)3 Test (org.junit.Test)3 AWSCredentials (com.amazonaws.auth.AWSCredentials)2