Example usage for com.lowagie.text Rectangle getHeight

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

Introduction

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

Prototype

public float getHeight() 

Source Link

Document

Returns the height of the rectangle.

Usage

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

License:Open Source License

@SuppressWarnings("deprecation")
private void generateWarningMessage(PdfContext context) {
    warning = resourceBundle.getString("ErrorRetrievingLegend");

    Rectangle textSize = context.getTextSize(warning, getFont());
    float margin = 0.5f * getFont().getSize();

    setBounds(new Rectangle(textSize.getWidth() + 2.0f * margin, textSize.getHeight() + 2 * margin));
}

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

License:Open Source License

public void setSize(String size, boolean landscape) {
    Rectangle rect = null;
    if (landscape) {
        rect = PageSize.getRectangle(size).rotate();
    } else {//w w w  . j a  v a2s . c  om
        rect = PageSize.getRectangle(size);
    }
    setBounds(rect);
    getConstraint().setWidth(rect.getWidth());
    getConstraint().setHeight(rect.getHeight());
}

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;/* ww w  . j a  va2s  . 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.ScaleBarComponentImpl.java

License:Open Source License

@Override
public void calculateSize(PdfContext context) {
    // clear labels and sizes to make this method idempotent
    tickLabels.clear();/*from   w w  w  .  j  av a  2  s .  c  o m*/
    tickSizes.clear();

    // the width must be set !!
    float width = getConstraint().getWidth();

    ClientMapInfo map = configurationService.getMapInfo(getMap().getMapId(), getMap().getApplicationId());
    boolean isEnglishUnits = false;
    boolean isEnglishMiles = false;
    float pxPUnit = getMap().getPpUnit();
    String englishUnit = "ft";
    // Calculate the labels
    if (map != null) {
        UnitType displayUnitType = map.getDisplayUnitType();
        log.debug("calculateSize getMap.getId({}), res {}", getMap().getId(), map);
        Crs crs;
        try {
            crs = geoService.getCrs2(map.getCrs());
            unit = crs.getCoordinateSystem().getAxis(0).getUnit().toString();
            if (UnitType.ENGLISH == displayUnitType || UnitType.ENGLISH_FOOT == displayUnitType) {
                isEnglishUnits = true;
                if (!unit.toUpperCase().contains("F")) {
                    pxPUnit = pxPUnit / FEET_PER_METER;
                }

                // check for yards conversion
                if (UnitType.ENGLISH == displayUnitType && (width / pxPUnit) >= 3
                        && (width / pxPUnit) < FEET_PER_MILE) {
                    pxPUnit = pxPUnit * 3f;
                    englishUnit = "yd";
                }

                // check for miles conversion
                if ((width / pxPUnit) > FEET_PER_MILE) {
                    pxPUnit = pxPUnit * FEET_PER_MILE;
                    englishUnit = "mi";
                    isEnglishMiles = true;
                }
            }
        } catch (Exception e) { // NOSONAR
            throw new IllegalStateException("Could not calculate map unit", e);
        }
    }
    // Calculate width in map units and round.
    float widthInUnits = width / pxPUnit;

    // Calculate ideal tic width in units
    float ticWidthInUnits = widthInUnits / getTicNumber();

    // Calculate minimal tic width in units
    int ticLog;
    float minTicWidthInUnits;
    if (!isEnglishMiles) {
        ticLog = (int) Math.floor(Math.log10(ticWidthInUnits) / 3);
        minTicWidthInUnits = (float) Math.pow(10, ticLog * 3);
    } else {
        ticLog = (int) Math.floor(Math.log10(ticWidthInUnits));
        minTicWidthInUnits = (float) Math.pow(10, ticLog);
    }

    // Find the highest nice number
    float nicestNumber = 0;
    for (float allowTickNumber : ALLOW_TICK_NUMBERS) {
        if (minTicWidthInUnits * allowTickNumber > ticWidthInUnits) {
            break;
        } else {
            nicestNumber = allowTickNumber;
        }
    }
    ticWidthInUnits = minTicWidthInUnits * nicestNumber;
    ticWidth = ticWidthInUnits * pxPUnit;
    ticHeight = ticWidth * 0.3f;
    int ticCount = getTicNumber();

    // font = new Font("Dialog", Font.PLAIN, (int) (0.8 * ticHeight));
    // set the Unit Prefixes

    String units;
    if (!isEnglishUnits && !isEnglishMiles) {
        units = ((ticLog >= -2 && ticLog <= 2) ? UNIT_PREFIXES[ticLog + 2] : "*10^" + (ticLog * 3)) + unit;
    } else {
        units = englishUnit;
    }

    // First pass to check if all fractions can be ignored
    boolean ignoreAllFractions = true;
    for (int i = 0; i <= ticCount; i++) {
        double valueLabel;
        if (!isEnglishUnits && !isEnglishMiles) {
            valueLabel = i * ticWidthInUnits / Math.pow(10, 3 * ticLog);

        } else {
            valueLabel = i * ticWidthInUnits;
        }
        double rounded = Math.round(valueLabel);
        if (Math.abs(valueLabel - (double) rounded) > 0.001) {
            ignoreAllFractions = false;
            break; // Abort
        }
    }

    for (int i = 0; i <= ticCount; i++) {
        String label;

        if (!isEnglishUnits && !isEnglishMiles) {
            label = scaleLabelOnPrint(i * ticWidthInUnits / Math.pow(10, 3 * ticLog), ignoreAllFractions);

        } else {
            label = scaleLabelOnPrint(i * ticWidthInUnits, ignoreAllFractions);

        }

        if (i == ticCount) {
            label += " " + units;
        }
        tickLabels.add(label);
        tickSizes.add(context.getTextSize(label, font));
    }

    // Calculate size
    width = ticWidth * ticCount;
    Rectangle first = context.getTextSize(tickLabels.get(0), font);
    Rectangle last = context.getTextSize(tickLabels.get(ticCount), font);
    width += 0.5 * first.getWidth();
    width += 0.5 * last.getWidth();
    float height = ticHeight;
    height += first.getHeight();
    setBounds(new Rectangle(0, 0, width, height));
}

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 v a  2  s  .  com
    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

/**
 * Initializes context size./*from  w ww  .j  a  va  2s .  c  o  m*/
 *
 * @param rectangle rectangle
 */
public void initSize(Rectangle rectangle) {
    template = writer.getDirectContent().createTemplate(rectangle.getWidth(), rectangle.getHeight());
}

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/*from  w  w  w  .  j  a  v  a 2s .  c o  m*/
 * @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();// w ww  .  ja  v  a2 s  .  c o  m
    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  a  v a  2  s .  co  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 .ja  va  2  s.  com*/
 * @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();
}