List of usage examples for java.awt.geom AffineTransform getScaleX
public double getScaleX()
From source file:org.uva.itast.blended.omr.OMRUtils.java
public static void logFrame(PageImage pageImage, PagePoint topleft, PagePoint topright, PagePoint bottomleft, PagePoint bottomright, Color color, String label) { if (topleft == null || topright == null || bottomleft == null || bottomright == null) return;//from w w w. ja v a 2 s.c om Graphics2D g = pageImage.getReportingGraphics(); AffineTransform t = g.getTransform(); g.setColor(color); g.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1, new float[] { (float) (3 / t.getScaleX()), (float) (6 / t.getScaleY()) }, 0)); // Point framePxUL=pageImage.toPixels(topleft.getX(), topleft.getY()); // Point framePxUR=pageImage.toPixels(topright.getX(), topright.getY()); // Point framePxBL=pageImage.toPixels(bottomleft.getX(), // bottomleft.getY()); // Point framePxBR=pageImage.toPixels(bottomright.getX(), // bottomright.getY()); g.drawLine(topleft.getXpx(), topleft.getYpx(), topright.getXpx(), topright.getYpx()); g.drawLine(topleft.getXpx(), topleft.getYpx(), bottomleft.getXpx(), bottomleft.getYpx()); g.drawLine(topright.getXpx(), topright.getYpx(), bottomright.getXpx(), bottomright.getYpx()); g.drawLine(bottomleft.getXpx(), bottomleft.getYpx(), bottomright.getXpx(), bottomright.getYpx()); if (label != null) { g.drawString(label, topleft.getXpx(), topleft.getYpx()); } }
From source file:org.uva.itast.blended.omr.scanners.BarcodeScanner.java
/** * @param campo/*from w w w . j a v a2s .c o m*/ */ public void markBarcode(Field campo) { try { //get bbox in pixels Rectangle rect = pageImage.toPixels(campo.getBBox()); // expand the area for some tolerance Rectangle2D expandedArea = getExpandedArea(campo.getBBox(), (float) BARCODE_AREA_PERCENT); Rectangle expandedRect = pageImage.toPixels(expandedArea); Graphics2D g = pageImage.getReportingGraphics(); AffineTransform t = g.getTransform(); g.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1, new float[] { (float) (3 / t.getScaleX()), (float) (6 / t.getScaleY()) }, 0)); if (lastResult != null) g.setColor(Color.BLUE); else g.setColor(Color.RED); g.drawRoundRect(rect.x, rect.y, rect.width, rect.height, 3, 3); g.drawRoundRect(expandedRect.x, expandedRect.y, expandedRect.width, expandedRect.height, 3, 3); g.setFont(new Font("Arial", Font.BOLD, (int) (12 / t.getScaleX()))); String message; if (lastResult != null) message = ((Result) lastResult.getResult()).getBarcodeFormat().toString() + "=" + getParsedCode(lastResult); else message = "UNRECOGNIZED!"; g.drawString(message, rect.x, rect.y); } catch (Exception e) { logger.error("Unexpected errr while logging the image:", e); } }
From source file:org.uva.itast.blended.omr.scanners.SolidSquareMarkScanner.java
/** * @param pageImage/*from w w w . j a v a2s .co 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:org.vfny.geoserver.global.xml.XMLConfigWriter.java
protected static void storeCoverage(CoverageInfoDTO cv, File dir) throws ConfigurationException { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("In method storeCoverage"); }// w w w . j a v a2 s .c om File f = WriterUtils.initWriteFile(new File(dir, "info.xml"), false); try { Writer fw = new OutputStreamWriter(new FileOutputStream(f), getDefaultEncoding()); WriterHelper cw = new WriterHelper(fw); Map m = new HashMap(); if ((cv.getFormatId() != null) && (cv.getFormatId() != "")) { m.put("format", cv.getFormatId()); } cw.openTag("coverage", m); if ((cv.getName() != null) && (cv.getName() != "")) { cw.textTag("name", cv.getName()); } if ((cv.getLabel() != null) && (cv.getLabel() != "")) { cw.textTag("label", cv.getLabel()); } if ((cv.getDescription() != null) && (cv.getDescription() != "")) { cw.textTag("description", cv.getDescription()); } if ((cv.getWmsPath() != null) && (cv.getWmsPath() != "")) { cw.textTag("wmspath", cv.getWmsPath()); } m = new HashMap(); if ((cv.getMetadataLink() != null)) { m.put("about", cv.getMetadataLink().getAbout()); m.put("type", cv.getMetadataLink().getType()); m.put("metadataType", cv.getMetadataLink().getMetadataType()); cw.openTag("metadataLink", m); cw.writeln(cv.getMetadataLink().getContent()); cw.closeTag("metadataLink"); } if ((cv.getKeywords() != null) && (cv.getKeywords().size() != 0)) { String s = ""; Iterator i = cv.getKeywords().iterator(); if (i.hasNext()) { s = i.next().toString(); while (i.hasNext()) { s = s + "," + i.next().toString(); } } cw.textTag("keywords", s); } if ((cv.getDefaultStyle() != null) && (cv.getDefaultStyle() != "")) { cw.comment("the default style this CoverageInfoDTO can be represented by.\n" + "at least must contain the \"default\" attribute "); m = new HashMap(); m.put("default", cv.getDefaultStyle()); final ArrayList styles = cv.getStyles(); if (styles.isEmpty()) { cw.attrTag("styles", m); } else { cw.openTag("styles", m); Iterator s_IT = styles.iterator(); while (s_IT.hasNext()) cw.textTag("style", (String) s_IT.next()); cw.closeTag("styles"); } } // // // storing the envelope. // The native crs wkt is stored as the crs attribute. The user defined srs identifier as // the srsName atribute // // if (cv.getEnvelope() != null) { GeneralEnvelope e = cv.getEnvelope(); m = new HashMap(); String userDefinedCrsIdentifier = cv.getUserDefinedCrsIdentifier(); if ((userDefinedCrsIdentifier != null) && (userDefinedCrsIdentifier != "")) { m.put("srsName", userDefinedCrsIdentifier); } String nativeCrsWkt = cv.getNativeCrsWKT(); m.put("crs", nativeCrsWkt.replaceAll("\"", "'").replaceAll("\r\n", "\n")); if (!e.isNull()) { cw.comment("crs: native CRS definition, srsName: user defined CRS identifier"); cw.openTag("envelope", m); cw.textTag("pos", e.getLowerCorner().getOrdinate(0) + " " + e.getLowerCorner().getOrdinate(1)); cw.textTag("pos", e.getUpperCorner().getOrdinate(0) + " " + e.getUpperCorner().getOrdinate(1)); cw.closeTag("envelope"); } } // // // AlFa: storing the grid-geometry // // if (cv.getGrid() != null) { GridGeometry g = cv.getGrid(); MathTransform tx = g.getGridToCRS(); InternationalString[] dimNames = cv.getDimensionNames(); m = new HashMap(); m.put("dimension", new Integer(g.getGridRange().getDimension())); String lowers = ""; String upers = ""; for (int r = 0; r < g.getGridRange().getDimension(); r++) { lowers += (g.getGridRange().getLow(r) + " "); upers += (g.getGridRange().getHigh(r) + " "); } cw.openTag("grid", m); cw.textTag("low", lowers); cw.textTag("high", upers); if (dimNames != null) { for (int dn = 0; dn < dimNames.length; dn++) cw.textTag("axisName", dimNames[dn].toString()); } // // // AlFa: storing geo-transform // // if (tx instanceof AffineTransform) { AffineTransform aTX = (AffineTransform) tx; cw.openTag("geoTransform"); cw.textTag("scaleX", String.valueOf(aTX.getScaleX())); cw.textTag("scaleY", String.valueOf(aTX.getScaleY())); cw.textTag("shearX", String.valueOf(aTX.getShearX())); cw.textTag("shearY", String.valueOf(aTX.getShearY())); cw.textTag("translateX", String.valueOf(aTX.getTranslateX())); cw.textTag("translateY", String.valueOf(aTX.getTranslateY())); cw.closeTag("geoTransform"); } cw.closeTag("grid"); } if (cv.getDimensions() != null) { CoverageDimension[] dims = cv.getDimensions(); for (int d = 0; d < dims.length; d++) { Double[] nulls = dims[d].getNullValues(); cw.openTag("CoverageDimension"); cw.textTag("name", dims[d].getName()); cw.textTag("description", dims[d].getDescription()); if (dims[d].getRange() != null) { cw.openTag("interval"); cw.textTag("min", Double.toString(dims[d].getRange().getMinimum(true))); cw.textTag("max", Double.toString(dims[d].getRange().getMaximum(true))); cw.closeTag("interval"); } else { cw.openTag("interval"); cw.textTag("min", Double.toString(Double.NEGATIVE_INFINITY)); cw.textTag("max", Double.toString(Double.POSITIVE_INFINITY)); cw.closeTag("interval"); } if (nulls != null) { cw.openTag("nullValues"); for (int n = 0; n < nulls.length; n++) { cw.textTag("value", nulls[n].toString()); } cw.closeTag("nullValues"); } cw.closeTag("CoverageDimension"); } } cw.openTag("supportedCRSs"); if ((cv.getRequestCRSs() != null) && (cv.getRequestCRSs().size() != 0)) { String s = ""; Iterator i = cv.getRequestCRSs().iterator(); if (i.hasNext()) { s = i.next().toString(); while (i.hasNext()) { s = s + "," + i.next().toString(); } } cw.textTag("requestCRSs", s); } if ((cv.getResponseCRSs() != null) && (cv.getResponseCRSs().size() != 0)) { String s = ""; Iterator i = cv.getResponseCRSs().iterator(); if (i.hasNext()) { s = i.next().toString(); while (i.hasNext()) { s = s + "," + i.next().toString(); } } cw.textTag("responseCRSs", s); } cw.closeTag("supportedCRSs"); m = new HashMap(); if ((cv.getNativeFormat() != null) && (cv.getNativeFormat() != "")) { m.put("nativeFormat", cv.getNativeFormat()); } cw.openTag("supportedFormats", m); if ((cv.getSupportedFormats() != null) && (cv.getSupportedFormats().size() != 0)) { String s = ""; Iterator i = cv.getSupportedFormats().iterator(); if (i.hasNext()) { s = i.next().toString(); while (i.hasNext()) { s = s + "," + i.next().toString(); } } cw.textTag("formats", s); } cw.closeTag("supportedFormats"); m = new HashMap(); if ((cv.getDefaultInterpolationMethod() != null) && (cv.getDefaultInterpolationMethod() != "")) { m.put("default", cv.getDefaultInterpolationMethod()); } cw.openTag("supportedInterpolations", m); if ((cv.getInterpolationMethods() != null) && (cv.getInterpolationMethods().size() != 0)) { String s = ""; Iterator i = cv.getInterpolationMethods().iterator(); if (i.hasNext()) { s = i.next().toString(); while (i.hasNext()) { s = s + "," + i.next().toString(); } } cw.textTag("interpolationMethods", s); } cw.closeTag("supportedInterpolations"); // /////////////////////////////////////////////////////////////////////// // // STORING READ PARAMETERS // // /////////////////////////////////////////////////////////////////////// if ((cv.getParameters() != null) && (cv.getParameters().size() != 0)) { cw.openTag("parameters"); final Iterator i = cv.getParameters().keySet().iterator(); final HashMap temp = new HashMap(); while (i.hasNext()) { String key = (String) i.next(); if (cv.getParameters().get(key) != null) { temp.put("name", key); temp.put("value", cv.getParameters().get(key).toString().replaceAll("\"", "'")); } cw.attrTag("parameter", temp); } cw.closeTag("parameters"); } cw.closeTag("coverage"); fw.close(); } catch (IOException e) { throw new ConfigurationException(e); } }
From source file:tufts.vue.LWComponent.java
/** @return our shape, full transformed into map coords and ultimate scale when drawn at 100% map zoom * this is used for portal clipping, and will be imperfect for some scaled shapes, such as RountRect's * This only works for raw shapes that are RectangularShapes -- other Shape types just return the bounding * box in map coordinates (e.g., a link shape) *///from w ww. j ava 2s. c o m public RectangularShape getMapShape() { // Will not work for shapes like RoundRect when scaled -- e..g, corner scaling will be off final Shape s = getZeroShape(); // if (getMapScale() != 1f && s instanceof RectangularShape) { // todo: do if any transform, not just scale if (s instanceof RectangularShape) { // todo: cache this: only need to updaate if location, size or scale changes // (Also, on the scale or location change of any parent!) RectangularShape rshape = (RectangularShape) s; rshape = (RectangularShape) rshape.clone(); AffineTransform a = getZeroTransform(); Point2D.Float loc = new Point2D.Float(); a.transform(loc, loc); rshape.setFrame(loc.x, loc.y, rshape.getWidth() * a.getScaleX(), rshape.getHeight() * a.getScaleY()); //System.out.println("TRANSFORMED SHAPE: " + rshape + " for " + this); return rshape; } else { return getMapBounds(); } }
From source file:uky.article.imageviewer.views.SWTImageCanvas.java
/** * Synchronize the scrollbar with the image. If the transform is out * of range, it will correct it. This function considers only following * factors :<b> transform, image size, client area</b>. */// ww w . j a v a 2s.c om public void syncScrollBars() { if (sourceImage == null) { redraw(); return; } AffineTransform af = transform; double sx = af.getScaleX(), sy = af.getScaleY(); double tx = af.getTranslateX(), ty = af.getTranslateY(); if (tx > 0) tx = 0; if (ty > 0) ty = 0; ScrollBar horizontal = getHorizontalBar(); horizontal.setIncrement(getClientArea().width / 100); horizontal.setPageIncrement(getClientArea().width); Rectangle imageBound = sourceImage.getBounds(); int cw = getClientArea().width, ch = getClientArea().height; if (imageBound.width * sx > cw) { /* image is wider than client area */ horizontal.setMaximum((int) (imageBound.width * sx)); horizontal.setEnabled(true); if (((int) -tx) > horizontal.getMaximum() - cw) tx = -horizontal.getMaximum() + cw; } else { /* image is narrower than client area */ horizontal.setEnabled(false); tx = (cw - imageBound.width * sx) / 2; //center if too small. } horizontal.setSelection((int) (-tx)); horizontal.setThumb((getClientArea().width)); ScrollBar vertical = getVerticalBar(); vertical.setIncrement(getClientArea().height / 100); vertical.setPageIncrement((getClientArea().height)); if (imageBound.height * sy > ch) { /* image is higher than client area */ vertical.setMaximum((int) (imageBound.height * sy)); vertical.setEnabled(true); if (((int) -ty) > vertical.getMaximum() - ch) ty = -vertical.getMaximum() + ch; } else { /* image is less higher than client area */ vertical.setEnabled(false); ty = (ch - imageBound.height * sy) / 2; //center if too small. } vertical.setSelection((int) (-ty)); vertical.setThumb((getClientArea().height)); /* update transform. */ af = AffineTransform.getScaleInstance(sx, sy); af.preConcatenate(AffineTransform.getTranslateInstance(tx, ty)); transform = af; redraw(); }