List of usage examples for java.awt BasicStroke CAP_SQUARE
int CAP_SQUARE
To view the source code for java.awt BasicStroke CAP_SQUARE.
Click Source Link
From source file:org.uva.itast.blended.omr.scanners.SolidSquareMarkScanner.java
/** * @param pageImage/*from w w w. j a va 2s. c o m*/ */ public void putEmphasisMarkOnImage(PageImage pageImage, Color color) { Graphics2D g = pageImage.getReportingGraphics(); // int centerColor=imagen.getRGB(maxsimX, maxsimY); // g.setXORMode(new Color(centerColor)); // g.setColor(Color.RED); // g.fillOval(maxsimX - markWidth/2, maxsimY - markHeight/2, markWidth, // markHeight); // g.setPaintMode(); Dimension2D markDimsPx = pageImage.sizeInPixels(new Size(markWidth, markHeight)); int markWidth = (int) markDimsPx.getWidth(); int markHeight = (int) markDimsPx.getHeight(); g.setColor(color); AffineTransform t = g.getTransform(); g.drawLine(maxsimX, maxsimY - markHeight / 2 - 1, maxsimX, maxsimY - markHeight / 2 - (int) (20 / t.getScaleY())); Polygon arrowHead = new Polygon(); arrowHead.addPoint(maxsimX, (int) (maxsimY - markHeight / 2 - 1 / t.getScaleY())); arrowHead.addPoint((int) (maxsimX - 6 / t.getScaleX()), (int) (maxsimY - markHeight / 2 - 6 / t.getScaleY())); arrowHead.addPoint((int) (maxsimX + 6 / t.getScaleX()), (int) (maxsimY - markHeight / 2 - 6 / t.getScaleY())); g.fillPolygon(arrowHead); g.setStroke(new BasicStroke(2, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1, new float[] { (float) (3 / t.getScaleX()), (float) (3 / t.getScaleY()) }, 0)); g.drawRect(maxsimX - markWidth / 2 - 1, maxsimY - markHeight / 2 - 1, markWidth + 1, markHeight + 1); }
From source file:se.ngm.ditaaeps.EpsRenderer.java
public static void renderToEps(Diagram diagram, PrintWriter out, RenderingOptions options) { //RenderedImage renderedImage = image; EpsGraphics2D g2 = new EpsGraphics2D(out, new Rectangle2D.Double(0, -diagram.getHeight(), diagram.getWidth(), diagram.getHeight())); g2.scale(1, -1); // g2 origo is top-left, eps is bottom-left Object antialiasSetting = antialiasSetting = RenderingHints.VALUE_ANTIALIAS_OFF; if (options.performAntialias()) antialiasSetting = RenderingHints.VALUE_ANTIALIAS_ON; //g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasSetting); g2.setColor(Color.white);/*from w w w . j ava2s .co m*/ //TODO: find out why the next line does not work //g2.fillRect(0, 0, image.getWidth()+10, image.getHeight()+10); /*for(int y = 0; y < diagram.getHeight(); y ++) g2.drawLine(0, y, diagram.getWidth(), y);*/ g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND)); ArrayList shapes = diagram.getAllDiagramShapes(); if (DEBUG) System.out.println("Rendering " + shapes.size() + " shapes (groups flattened)"); Iterator shapesIt; if (options.dropShadows()) { //render shadows shapesIt = shapes.iterator(); while (shapesIt.hasNext()) { DiagramShape shape = (DiagramShape) shapesIt.next(); if (shape.getPoints().isEmpty()) continue; //GeneralPath path = shape.makeIntoPath(); GeneralPath path; path = shape.makeIntoRenderPath(diagram); float offset = diagram.getMinimumOfCellDimension() / 3.333f; if (path != null && shape.dropsShadow()) { GeneralPath shadow = new GeneralPath(path); AffineTransform translate = new AffineTransform(); translate.setToTranslation(offset, offset); shadow.transform(translate); g2.setColor(new Color(150, 150, 150)); g2.fill(shadow); } } //blur shadows // if(true) { // int blurRadius = 6; // int blurRadius2 = blurRadius * blurRadius; // float blurRadius2F = blurRadius2; // float weight = 1.0f / blurRadius2F; // float[] elements = new float[blurRadius2]; // for (int k = 0; k < blurRadius2; k++) // elements[k] = weight; // Kernel myKernel = new Kernel(blurRadius, blurRadius, elements); // // //if EDGE_NO_OP is not selected, EDGE_ZERO_FILL is the default which creates a black border // ConvolveOp simpleBlur = // new ConvolveOp(myKernel, ConvolveOp.EDGE_NO_OP, null); // //BufferedImage destination = new BufferedImage(image.getWidth()+blurRadius, image.getHeight()+blurRadius, image.getType()); // BufferedImage destination = // new BufferedImage( // image.getWidth(), // image.getHeight(), // image.getType()); // simpleBlur.filter(image, destination); // //destination = destination.getSubimage(blurRadius/2, blurRadius/2, image.getWidth(), image.getHeight()); // g2 = destination.createGraphics(); // g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasSetting); // renderedImage = destination; // } } //fill and stroke float dashInterval = Math.min(diagram.getCellWidth(), diagram.getCellHeight()) / 2; //Stroke normalStroke = g2.getStroke(); float strokeWeight = diagram.getMinimumOfCellDimension() / 10; Stroke normalStroke = new BasicStroke(strokeWeight, //10, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); Stroke dashStroke = new BasicStroke(strokeWeight, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0, new float[] { dashInterval }, 0); //find storage shapes ArrayList storageShapes = new ArrayList(); shapesIt = shapes.iterator(); while (shapesIt.hasNext()) { DiagramShape shape = (DiagramShape) shapesIt.next(); if (shape.getType() == DiagramShape.TYPE_STORAGE) { storageShapes.add(shape); continue; } } //render storage shapes //special case since they are '3d' and should be //rendered bottom to top //TODO: known bug: if a storage object is within a bigger normal box, it will be overwritten in the main drawing loop //(BUT this is not possible since tags are applied to all shapes overlaping shapes) Collections.sort(storageShapes, new Shape3DOrderingComparator()); g2.setStroke(normalStroke); shapesIt = storageShapes.iterator(); while (shapesIt.hasNext()) { DiagramShape shape = (DiagramShape) shapesIt.next(); GeneralPath path; path = shape.makeIntoRenderPath(diagram); if (!shape.isStrokeDashed()) { if (shape.getFillColor() != null) g2.setColor(shape.getFillColor()); else g2.setColor(Color.white); g2.fill(path); } if (shape.isStrokeDashed()) g2.setStroke(dashStroke); else g2.setStroke(normalStroke); g2.setColor(shape.getStrokeColor()); g2.draw(path); } //render the rest of the shapes ArrayList pointMarkers = new ArrayList(); shapesIt = shapes.iterator(); while (shapesIt.hasNext()) { DiagramShape shape = (DiagramShape) shapesIt.next(); if (shape.getType() == DiagramShape.TYPE_POINT_MARKER) { pointMarkers.add(shape); continue; } if (shape.getType() == DiagramShape.TYPE_STORAGE) { continue; } if (shape.getPoints().isEmpty()) continue; int size = shape.getPoints().size(); GeneralPath path; path = shape.makeIntoRenderPath(diagram); if (path != null && shape.isClosed() && !shape.isStrokeDashed()) { if (shape.getFillColor() != null) g2.setColor(shape.getFillColor()); else g2.setColor(Color.white); g2.fill(path); } if (shape.getType() != DiagramShape.TYPE_ARROWHEAD) { g2.setColor(shape.getStrokeColor()); if (shape.isStrokeDashed()) g2.setStroke(dashStroke); else g2.setStroke(normalStroke); g2.draw(path); } } //render point markers g2.setStroke(normalStroke); shapesIt = pointMarkers.iterator(); while (shapesIt.hasNext()) { DiagramShape shape = (DiagramShape) shapesIt.next(); //if(shape.getType() != DiagramShape.TYPE_POINT_MARKER) continue; GeneralPath path; path = shape.makeIntoRenderPath(diagram); g2.setColor(Color.white); g2.fill(path); g2.setColor(shape.getStrokeColor()); g2.draw(path); } //handle text //g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); Iterator textIt = diagram.getTextObjects().iterator(); while (textIt.hasNext()) { DiagramText text = (DiagramText) textIt.next(); g2.setColor(text.getColor()); g2.setFont(text.getFont()); g2.drawString(text.getText(), text.getXPos(), text.getYPos()); } if (options.renderDebugLines() || DEBUG) { Stroke debugStroke = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); g2.setStroke(debugStroke); g2.setColor(new Color(170, 170, 170)); g2.setXORMode(Color.white); for (int x = 0; x < diagram.getWidth(); x += diagram.getCellWidth()) g2.drawLine(x, 0, x, diagram.getHeight()); for (int y = 0; y < diagram.getHeight(); y += diagram.getCellHeight()) g2.drawLine(0, y, diagram.getWidth(), y); } g2.dispose(); }