Example usage for com.lowagie.text Rectangle getLeft

List of usage examples for com.lowagie.text Rectangle getLeft

Introduction

In this page you can find the example usage for com.lowagie.text Rectangle getLeft.

Prototype

public float getLeft() 

Source Link

Document

Returns the lower left x-coordinate.

Usage

From source file:org.geomajas.plugin.print.component.impl.MapComponentImpl.java

License:Open Source License

private void renderViewPort(ViewPortComponentImpl viewPort, PdfContext context) {
    Coordinate portOrigin = viewPort.getLocation();
    float x = (float) (portOrigin.x - location.x) * getPpUnit();
    float y = (float) (portOrigin.y - location.y) * getPpUnit();
    Rectangle shadowRect = new Rectangle(x, y, x + viewPort.getBounds().getWidth() / viewPort.getZoomScale(),
            y + viewPort.getBounds().getHeight() / viewPort.getZoomScale());
    context.fillRectangle(shadowRect, context.makeTransparent(Color.lightGray, 0.5f));
    context.strokeRectangle(shadowRect, Color.white, 1);
    Rectangle rect = context.toRelative(viewPort.getBounds());
    // connection lines
    float deltaLeft = shadowRect.getLeft() - rect.getLeft();
    float deltaRight = shadowRect.getRight() - rect.getRight();

    float deltaBottom = shadowRect.getBottom() - rect.getBottom();
    float deltaTop = shadowRect.getTop() - rect.getTop();

    if ((deltaLeft <= 0 && deltaBottom >= 0) || (deltaLeft >= 0 && deltaBottom <= 0)) {
        context.drawLine(rect.getLeft(), rect.getBottom(), shadowRect.getLeft(), shadowRect.getBottom(),
                Color.white, 1);/* w w w.  j av a2s.  co  m*/
    }
    if ((deltaLeft >= 0 && deltaTop >= 0) || (deltaLeft <= 0 && deltaTop <= 0)) {
        context.drawLine(rect.getLeft(), rect.getTop(), shadowRect.getLeft(), shadowRect.getTop(), Color.white,
                1);
    }
    if ((deltaRight <= 0 && deltaBottom <= 0) || (deltaRight >= 0 && deltaBottom >= 0)) {
        context.drawLine(rect.getRight(), rect.getBottom(), shadowRect.getRight(), shadowRect.getBottom(),
                Color.white, 1);
    }
    if ((deltaRight >= 0 && deltaTop <= 0) || (deltaRight <= 0 && deltaTop >= 0)) {
        context.drawLine(rect.getRight(), rect.getTop(), shadowRect.getRight(), shadowRect.getTop(),
                Color.white, 1);
    }
}

From source file:org.geomajas.plugin.print.component.impl.PrintComponentImpl.java

License:Open Source License

private void layoutChild(PrintComponent<?> child, Rectangle box) {
    LayoutConstraint layoutConstraint = child.getConstraint();
    float bx = box.getLeft();
    float by = box.getBottom();
    float bw = box.getWidth();
    float bh = box.getHeight();
    float cw = child.getBounds().getWidth();
    float ch = child.getBounds().getHeight();
    float marginX = layoutConstraint.getMarginX();
    float marginY = layoutConstraint.getMarginY();
    float absw = layoutConstraint.getWidth();
    float absh = layoutConstraint.getHeight();
    float x = 0;/*from  ww w .  jav a2  s  .  c  om*/
    float y = 0;
    float w = cw;
    float h = ch;
    switch (layoutConstraint.getAlignmentX()) {
    case LayoutConstraint.LEFT:
        x = bx + marginX;
        break;
    case LayoutConstraint.CENTER:
        x = bx + (bw - cw) / 2;
        break;
    case LayoutConstraint.RIGHT:
        x = bx + bw - marginX - cw;
        break;
    case LayoutConstraint.JUSTIFIED:
        x = bx + marginX;
        w = bw - 2 * marginX;
        break;
    case LayoutConstraint.ABSOLUTE:
        x = marginX;
        w = absw;
        break;
    default:
        throw new IllegalStateException("Unknown X alignment " + layoutConstraint.getAlignmentX());
    }
    switch (layoutConstraint.getAlignmentY()) {
    case LayoutConstraint.BOTTOM:
        y = by + marginY;
        break;
    case LayoutConstraint.CENTER:
        y = by + (bh - ch) / 2;
        break;
    case LayoutConstraint.TOP:
        y = by + bh - marginY - ch;
        break;
    case LayoutConstraint.JUSTIFIED:
        y = by + marginY;
        h = bh - 2 * marginY;
        break;
    case LayoutConstraint.ABSOLUTE:
        y = marginY;
        h = absh;
        break;
    default:
        throw new IllegalStateException("Unknown Y alignment " + layoutConstraint.getAlignmentY());
    }
    child.setBounds(new Rectangle(x, y, x + w, y + h));
}

From source file:org.geomajas.plugin.print.component.impl.VectorLayerComponentImpl.java

License:Open Source License

private void drawLabel(PdfContext context, InternalFeature f) {
    LabelStyleInfo labelType = styleInfo.getLabelStyle();
    String label = f.getLabel();/*from ww  w.  jav  a  2  s  . c  o m*/
    if (label != null) {
        Font font = new Font("Helvetica", Font.ITALIC, 10);
        Color fontColor = Color.black;
        if (labelType.getFontStyle() != null) {
            fontColor = context.getColor(labelType.getFontStyle().getColor(),
                    labelType.getFontStyle().getOpacity());
        }
        Rectangle rect = calculateLabelRect(context, f, label, font);
        Color bgColor = Color.white;
        if (labelType.getBackgroundStyle() != null) {
            bgColor = context.getColor(labelType.getBackgroundStyle().getFillColor(),
                    labelType.getBackgroundStyle().getFillOpacity());
        }
        context.fillRoundRectangle(rect, bgColor, 3);
        Color borderColor = Color.black;
        if (labelType.getBackgroundStyle() != null) {
            borderColor = context.getColor(labelType.getBackgroundStyle().getStrokeColor(),
                    labelType.getBackgroundStyle().getStrokeOpacity());
        }
        float linewidth = 0.5f;
        if (labelType.getBackgroundStyle() != null) {
            linewidth = labelType.getBackgroundStyle().getStrokeWidth();
        }
        context.strokeRoundRectangle(rect, borderColor, linewidth, 3);
        context.drawText(label, font, rect, fontColor);
        if (f.getGeometry() instanceof Point) {
            context.drawLine(0.5f * (rect.getLeft() + rect.getRight()), rect.getBottom(),
                    0.5f * (rect.getLeft() + rect.getRight()), rect.getBottom() - SYMBOL_CONNECT_LENGTH,
                    borderColor, linewidth);
        }
    }
}

From source file:org.geomajas.plugin.print.component.impl.VectorLayerComponentImpl.java

License:Open Source License

private Rectangle calculateLabelRect(PdfContext context, InternalFeature f, String label, Font font) {
    Rectangle textSize = context.getTextSize(label, font);
    float margin = 0.25f * font.getSize();
    Rectangle rect = new Rectangle(textSize.getWidth() + 2 * margin, textSize.getHeight() + 2 * margin);
    Coordinate labelPosition = geoService.calcDefaultLabelPosition(f);
    // SPRINT-53 Labels should be rendered in Screen Space
    new MapToUserFilter().filter(labelPosition);

    context.moveRectangleTo(rect, (float) labelPosition.x - rect.getWidth() / 2f,
            (float) labelPosition.y - rect.getHeight() / 2f);
    if (f.getGeometry() instanceof Point) {
        float shiftHeight = 0.5f * (rect.getHeight() + getSymbolHeight(f));
        // move up 15 pixels to make the symbol visible
        context.moveRectangleTo(rect, rect.getLeft(), rect.getBottom() + shiftHeight + SYMBOL_CONNECT_LENGTH);
    }//  w w  w .  ja  va2 s  .  c om
    if (rect.getLeft() < 0) {
        context.moveRectangleTo(rect, 10, rect.getBottom());
    }
    if (rect.getBottom() < 0) {
        context.moveRectangleTo(rect, rect.getLeft(), 10);
    }
    if (rect.getTop() > getBounds().getHeight()) {
        context.moveRectangleTo(rect, rect.getLeft(), getBounds().getHeight() - rect.getHeight() - 10);
    }
    if (rect.getRight() > getBounds().getWidth()) {
        context.moveRectangleTo(rect, getBounds().getWidth() - rect.getWidth() - 10, rect.getBottom());
    }
    return rect;
}

From source file:org.geomajas.plugin.print.component.PdfContext.java

License:Open Source License

/**
 * Draw text in the center of the specified box.
 *
 * @param text text/*www.j  a  v a  2 s. c  om*/
 * @param font font
 * @param box box to put text int
 * @param fontColor colour
 */
public void drawText(String text, Font font, Rectangle box, Color fontColor) {
    template.saveState();
    // get the font
    DefaultFontMapper mapper = new DefaultFontMapper();
    BaseFont bf = mapper.awtToPdf(font);
    template.setFontAndSize(bf, font.getSize());

    // calculate descent
    float descent = 0;
    if (text != null) {
        descent = bf.getDescentPoint(text, font.getSize());
    }

    // calculate the fitting size
    Rectangle fit = getTextSize(text, font);

    // draw text if necessary
    template.setColorFill(fontColor);
    template.beginText();
    template.showTextAligned(PdfContentByte.ALIGN_LEFT, text,
            origX + box.getLeft() + 0.5f * (box.getWidth() - fit.getWidth()),
            origY + box.getBottom() + 0.5f * (box.getHeight() - fit.getHeight()) - descent, 0);
    template.endText();
    template.restoreState();
}

From source file:org.geomajas.plugin.print.component.PdfContext.java

License:Open Source License

public void strokeRectangle(Rectangle rect, Color color, float linewidth, float[] dashArray) {
    template.saveState();/*from ww  w  . ja  v a 2s.com*/
    setStroke(color, linewidth, dashArray);
    template.rectangle(origX + rect.getLeft(), origY + rect.getBottom(), rect.getWidth(), rect.getHeight());
    template.stroke();
    template.restoreState();
}

From source file:org.geomajas.plugin.print.component.PdfContext.java

License:Open Source License

/**
 * Draw a rounded rectangular boundary.//  w  w  w.j  av a  2s  . c o m
 *
 * @param rect rectangle
 * @param color colour
 * @param linewidth line width
 * @param r radius for rounded corners
 */
public void strokeRoundRectangle(Rectangle rect, Color color, float linewidth, float r) {
    template.saveState();
    setStroke(color, linewidth, null);
    template.roundRectangle(origX + rect.getLeft(), origY + rect.getBottom(), rect.getWidth(), rect.getHeight(),
            r);
    template.stroke();
    template.restoreState();
}

From source file:org.geomajas.plugin.print.component.PdfContext.java

License:Open Source License

/**
 * Draw a rectangle's interior with this color.
 *
 * @param rect rectangle/* w  w  w. j  a  va  2 s.c  om*/
 * @param color colour
 */
public void fillRectangle(Rectangle rect, Color color) {
    template.saveState();
    setFill(color);
    template.rectangle(origX + rect.getLeft(), origY + rect.getBottom(), rect.getWidth(), rect.getHeight());
    template.fill();
    template.restoreState();
}

From source file:org.geomajas.plugin.print.component.PdfContext.java

License:Open Source License

public void fillRoundRectangle(Rectangle rect, Color color, float r) {
    template.saveState();// w w  w .java2s  .  c  o  m
    setFill(color);
    template.roundRectangle(origX + rect.getLeft(), origY + rect.getBottom(), rect.getWidth(), rect.getHeight(),
            r);
    template.fill();
    template.restoreState();
}

From source file:org.geomajas.plugin.print.component.PdfContext.java

License:Open Source License

/**
 * Draw an elliptical exterior with this color.
 *
 * @param rect rectangle in which ellipse should fit
 * @param color colour to use for stroking
 * @param linewidth line width/*from   ww  w  .ja va2 s .  c o  m*/
 */
public void strokeEllipse(Rectangle rect, Color color, float linewidth) {
    template.saveState();
    setStroke(color, linewidth, null);
    template.ellipse(origX + rect.getLeft(), origY + rect.getBottom(), origX + rect.getRight(),
            origY + rect.getTop());
    template.stroke();
    template.restoreState();
}