List of usage examples for com.lowagie.text Rectangle Rectangle
public Rectangle(float llx, float lly, float urx, float ury)
Rectangle
-object. From source file:org.geomajas.plugin.print.component.impl.LegendIconComponentImpl.java
License:Open Source License
@Override public void render(PdfContext context) { @SuppressWarnings("deprecation") float w = getSize().getWidth(); @SuppressWarnings("deprecation") float h = getSize().getHeight(); Rectangle iconRect = new Rectangle(0, 0, w, h); Color fillColor = Color.white; Color strokeColor = Color.black; float[] dashArray = null; if (styleInfo != null) { fillColor = context.getColor(styleInfo.getFillColor(), styleInfo.getFillOpacity(), Color.white); strokeColor = context.getColor(styleInfo.getStrokeColor(), styleInfo.getStrokeOpacity(), Color.black); dashArray = context.getDashArray(styleInfo.getDashArray()); }//from w w w . j a v a 2 s . co m float baseWidth = iconRect.getWidth() / 10; // draw symbol switch (layerType) { case RASTER: Image img = context.getImage("/images/layer-raster.png"); context.drawImage(img, iconRect, null); break; case POINT: case MULTIPOINT: drawPoint(context, iconRect, fillColor, strokeColor); break; case LINESTRING: case MULTILINESTRING: drawLine(context, iconRect, strokeColor, dashArray); break; case POLYGON: case MULTIPOLYGON: context.fillRectangle(iconRect, fillColor); context.strokeRectangle(iconRect, strokeColor, baseWidth, dashArray); break; case GEOMETRY: drawPoint(context, iconRect, fillColor, strokeColor); drawLine(context, iconRect, strokeColor, dashArray); break; default: log.warn("Cannot draw unknown layerType " + layerType); } }
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);//from w ww . j a va2 s. 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
@Override public void layout(PdfContext context) { // top down layout float x = getBounds().getLeft(); float y = getBounds().getBottom(); float w = getBounds().getWidth(); float h = getBounds().getHeight(); if (getConstraint().getFlowDirection() == LayoutConstraint.FLOW_Y) { y = getBounds().getTop();/*from w ww . j av a 2 s . com*/ } for (PrintComponent<?> child : children) { float cw = child.getBounds().getWidth(); float ch = child.getBounds().getHeight(); float marginX = child.getConstraint().getMarginX(); float marginY = child.getConstraint().getMarginY(); switch (getConstraint().getFlowDirection()) { case LayoutConstraint.FLOW_NONE: layoutChild(child, getBounds()); break; case LayoutConstraint.FLOW_X: layoutChild(child, new Rectangle(x, y, x + cw + 2 * marginX, y + h)); x += cw + 2 * marginX; break; case LayoutConstraint.FLOW_Y: layoutChild(child, new Rectangle(x, y - ch - 2 * marginY, x + w, y)); y -= ch + 2 * marginY; break; default: throw new IllegalStateException("Unknown flow direction " + getConstraint().getFlowDirection()); } } for (PrintComponent<?> child : children) { child.layout(context); } }
From source file:org.geomajas.plugin.print.component.impl.PrintComponentImpl.java
License:Open Source License
/** * Calculates the size based constraint width and height if present, otherwise from children sizes. *///from ww w . jav a 2s.co m public void calculateSize(PdfContext context) { float width = 0; float height = 0; for (PrintComponent<?> child : children) { child.calculateSize(context); float cw = child.getBounds().getWidth() + 2 * child.getConstraint().getMarginX(); float ch = child.getBounds().getHeight() + 2 * child.getConstraint().getMarginY(); switch (getConstraint().getFlowDirection()) { case LayoutConstraint.FLOW_NONE: width = Math.max(width, cw); height = Math.max(height, ch); break; case LayoutConstraint.FLOW_X: width += cw; height = Math.max(height, ch); break; case LayoutConstraint.FLOW_Y: width = Math.max(width, cw); height += ch; break; default: throw new IllegalStateException("Unknown flow direction " + getConstraint().getFlowDirection()); } } if (getConstraint().getWidth() != 0) { width = getConstraint().getWidth(); } if (getConstraint().getHeight() != 0) { height = getConstraint().getHeight(); } setBounds(new Rectangle(0, 0, width, height)); }
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;/* w w w .j a v a2 s. c o m*/ 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.PrintComponentImpl.java
License:Open Source License
private Rectangle createRectangle(Bbox bounds) { return new Rectangle((float) bounds.getX(), (float) bounds.getY(), (float) bounds.getX() + (float) bounds.getWidth(), (float) bounds.getY() + (float) bounds.getHeight()); }
From source file:org.geomajas.plugin.print.component.impl.RasterLayerComponentImpl.java
License:Open Source License
/** * Add image in the document.//from w w w . j a v a2s . c o m * * @param context * PDF context * @param imageResult * image * @throws BadElementException * PDF construction problem * @throws IOException * PDF construction problem */ protected void addImage(PdfContext context, ImageResult imageResult) throws BadElementException, IOException { Bbox imageBounds = imageResult.getRasterImage().getBounds(); float scaleFactor = (float) (72 / getMap().getRasterResolution()); float width = (float) imageBounds.getWidth() * scaleFactor; float height = (float) imageBounds.getHeight() * scaleFactor; // subtract screen position of lower-left corner float x = (float) (imageBounds.getX() - rasterScale * bbox.getMinX()) * scaleFactor; // shift y to lowerleft corner, flip y to user space and subtract // screen position of lower-left // corner float y = (float) (-imageBounds.getY() - imageBounds.getHeight() - rasterScale * bbox.getMinY()) * scaleFactor; if (log.isDebugEnabled()) { log.debug("adding image, width=" + width + ",height=" + height + ",x=" + x + ",y=" + y); } // opacity log.debug("before drawImage"); context.drawImage(Image.getInstance(imageResult.getImage()), new Rectangle(x, y, x + width, y + height), getSize(), getOpacity()); log.debug("after drawImage"); }
From source file:org.geomajas.plugin.print.component.impl.RasterLayerComponentImpl.java
License:Open Source License
/** * Add image with a exception message in the PDF document. * /*from www. ja v a 2s. c om*/ * @param context * PDF context * @param e * exception to put in image */ protected void addLoadError(PdfContext context, ImageException e) { Bbox imageBounds = e.getRasterImage().getBounds(); float scaleFactor = (float) (72 / getMap().getRasterResolution()); float width = (float) imageBounds.getWidth() * scaleFactor; float height = (float) imageBounds.getHeight() * scaleFactor; // subtract screen position of lower-left corner float x = (float) (imageBounds.getX() - rasterScale * bbox.getMinX()) * scaleFactor; // shift y to lower left corner, flip y to user space and subtract // screen position of lower-left // corner float y = (float) (-imageBounds.getY() - imageBounds.getHeight() - rasterScale * bbox.getMinY()) * scaleFactor; if (log.isDebugEnabled()) { log.debug("adding failed message=" + width + ",height=" + height + ",x=" + x + ",y=" + y); } float textHeight = context.getTextSize("failed", ERROR_FONT).getHeight() * 3f; Rectangle rec = new Rectangle(x, y, x + width, y + height); context.strokeRectangle(rec, Color.RED, 0.5f); context.drawText(getNlsString("RasterLayerComponent.loaderror.line1"), ERROR_FONT, new Rectangle(x, y + textHeight, x + width, y + height), Color.RED); context.drawText(getNlsString("RasterLayerComponent.loaderror.line2"), ERROR_FONT, rec, Color.RED); context.drawText(getNlsString("RasterLayerComponent.loaderror.line3"), ERROR_FONT, new Rectangle(x, y - textHeight, x + width, y + height), Color.RED); }
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 ww. j a v a 2s. 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.ScaleBarComponentImpl.java
License:Open Source License
@Override public void render(PdfContext context) { // draw the tics float lowX = 0.5f * tickSizes.get(0).getWidth(); float lowY = 0; float highX = lowX; float highY = 0.333f * ticHeight; Rectangle baseRect = new Rectangle(0, 0, ticWidth, 0.333f * ticHeight); // fills/*from ww w .j ava2 s .c om*/ for (int i = 0; i < ticNumber; i++) { if (i % 2 == 0) { context.moveRectangleTo(baseRect, lowX, lowY); context.fillRectangle(baseRect, Color.white); context.strokeRectangle(baseRect, Color.black, 0.5f); context.moveRectangleTo(baseRect, highX, highY); context.fillRectangle(baseRect, Color.black); context.strokeRectangle(baseRect, Color.black, 0.5f); } else { context.moveRectangleTo(baseRect, highX, highY); context.fillRectangle(baseRect, Color.white); context.strokeRectangle(baseRect, Color.black, 0.5f); context.moveRectangleTo(baseRect, lowX, lowY); context.fillRectangle(baseRect, Color.black); context.strokeRectangle(baseRect, Color.black, 0.5f); } lowX += ticWidth; highX += ticWidth; } // tick extensions highX = 0.5f * tickSizes.get(0).getWidth(); highY = 0.6666f * ticHeight; for (int i = 0; i <= ticNumber; i++) { context.drawRelativePath(new float[] { 0, 0 }, new float[] { 0, 1 }, new Rectangle(highX, highY, highX, 0.75f * ticHeight), Color.black, 0.5f, null); highX += ticWidth; } // position and print the labels float labelX = 0.5f * tickSizes.get(0).getWidth(); float labelY = ticHeight; for (int i = 0; i < tickLabels.size(); i++) { Rectangle box = tickSizes.get(i); // center the label context.moveRectangleTo(box, labelX - 0.5f * box.getWidth(), labelY); context.drawText(tickLabels.get(i), font, box, Color.black); labelX += ticWidth; } }