List of usage examples for java.awt.geom AffineTransform AffineTransform
public AffineTransform()
From source file:GrafosTroleBus.java
public GrafosTroleBus() { setLayout(new BorderLayout()); //definir puntos de trolebus (latitude y longitude) @autor sa map.put("RECREO", new String[] { "-0.2516682", "-78.521524" }); //Recreo map.put("P14", new String[] { "-0.2445098", "-78.51902" }); //Villaflora map.put("P15", new String[] { "-0.2396436", "-78.51698" }); //Chimbacalle N-S map.put("P16", new String[] { "-0.2378458", "-78.515976" }); //Chimbacalle S-N map.put("P17", new String[] { "-0.2356805", "-78.514816" }); //Colina map.put("P18", new String[] { "-0.234052", "-78.514237" }); //Jefferson Perez map.put("P19", new String[] { "-0.2312856", "-78.513627" }); //Recoleta N-S map.put("P20", new String[] { "-0.2307005", "-78.513051" }); //Recoleta S-N map.put("P21", new String[] { "-0.2263919", "-78.513011" }); //P21 Cumanda N-S map.put("P22", new String[] { "-0.226424", "-78.512803" }); //P22 Cumanda S-N map.put("P23", new String[] { "-0.2234658", "-78.512542" }); //P23 Santo Domingo map.put("P24", new String[] { "-0.2185857", "-78.508601" }); //P24 Plaza del Teatro N-S map.put("P25", new String[] { "-0.219605", "-78.50813" }); //P25 Plaza del Teatro S-N map.put("P26", new String[] { "-0.2177808", "-78.505977" }); //P26 Hermano Miguel map.put("P27", new String[] { "-0.2169088", "-78.50521" }); //P27 Banco Central map.put("P28", new String[] { "-0.214267", "-78.502999" }); //P28 La Alameda S-N map.put("P29", new String[] { "-0.2137705", "-78.50293" }); //P29 La Alameda N-S map.put("P30", new String[] { "-0.2084939", "-78.500255" }); //P30 Ejido N-S map.put("P31", new String[] { "-0.2088076", "-78.500032" }); //P31 Ejido S-N map.put("P32", new String[] { "-0.2047989", "-78.4988" }); //P32 La Mariscal N-S map.put("P33", new String[] { "-0.2041972", "-78.498491" }); //P33 La Mariscal S-N map.put("P34", new String[] { "-0.2009718", "-78.49715" }); //P34 Santa Clara S-N map.put("P35", new String[] { "-0.201056", "-78.496979" }); //P35 Santa Clara N-S map.put("P36", new String[] { "-0.1986325", "-78.496141" }); //P36 La Colon S-N map.put("P37", new String[] { "-0.1978432", "-78.495563" }); //P37 La Colon N-S map.put("P38", new String[] { "-0.1921587", "-78.493445" }); //P38 Cuero y Caicedo S-N map.put("P39", new String[] { "-0.1915098", "-78.493001" }); //P39 Cuero y Caicedo N-S map.put("P40", new String[] { "-0.1889467", "-78.492149" }); //P40 Mariana de Jess S-N map.put("P41", new String[] { "-0.1875567", "-78.491303" }); //P41 Mariana de Jesus N-S map.put("P42", new String[] { "-0.1853693", "-78.490878" }); //P42 El Floron S-N map.put("P43", new String[] { "-0.1846687", "-78.490403" }); //P43 El Floron N-S map.put("P44", new String[] { "-0.1817679", "-78.489808" }); //P44 Carolina S-N map.put("P45", new String[] { "-0.1810849", "-78.489336" }); //P45 Carolina N-S map.put("P46", new String[] { "-0.1787274", "-78.488954" }); //P46 Estadio S-N map.put("P47", new String[] { "-0.1780172", "-78.488621" }); //P47 Estadio N-S map.put("P48", new String[] { "-0.172087", "-78.487589" }); //P48 La Y S-N map.put("P49", new String[] { "-0.1713146", "-78.487277" }); //P49 La Y N-S map.put("LA Y", new String[] { "-0.1635504", "-78.485374" }); //Estacin La Y nodoList = new ArrayList<String>(map.keySet()); // create a simple graph for the demo graph = new DirectedSparseMultigraph<String, Number>(); createVertices();//from w w w . ja v a 2 s . com createEdges(); ImageIcon mapIcon = null; String imageLocation = "/mapa_quito.png"; try { mapIcon = new ImageIcon(getClass().getResource(imageLocation)); ImageWidth = mapIcon.getIconWidth(); ImageHeight = mapIcon.getIconHeight(); } catch (Exception ex) { System.err.println("Can't load \"" + imageLocation + "\""); } final ImageIcon icon = mapIcon; Dimension layoutSize = new Dimension(ImageWidth, ImageHeight); Layout<String, Number> layout = new StaticLayout<String, Number>(graph, new ChainedTransformer<String, Point2D>(new Transformer[] { new CityTransformer(map), new LatLonPixelTransformer(new Dimension(ImageWidth, ImageHeight)) })); layout.setSize(layoutSize); vv = new VisualizationViewer<String, Number>(layout, new Dimension(MonitorWidth, MonitorHeight)); if (icon != null) { vv.addPreRenderPaintable(new VisualizationViewer.Paintable() { public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AffineTransform oldXform = g2d.getTransform(); AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.LAYOUT).getTransform(); AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.VIEW).getTransform(); AffineTransform at = new AffineTransform(); at.concatenate(g2d.getTransform()); at.concatenate(vat); at.concatenate(lat); g2d.setTransform(at); g.drawImage(icon.getImage(), 0, 0, icon.getIconWidth(), icon.getIconHeight(), vv); g2d.setTransform(oldXform); } public boolean useTransform() { return false; } }); } vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red, Color.white, Color.blue, vv.getPickedVertexState(), false)); // add my listeners for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<String>()); vv.setEdgeToolTipTransformer(new Transformer<Number, String>() { public String transform(Number edge) { return "E" + graph.getEndpoints(edge).toString(); } }); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>()); vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); add(panel); final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<Object, Object>(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode"); final ScalingControl scaler = new CrossoverScalingControl(); vv.scaleToLayout(scaler); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity(); vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity(); } }); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(reset); add(controls, BorderLayout.SOUTH); }
From source file:org.apache.fop.render.pdf.PDFBoxAdapterTestCase.java
private String writeText(FontInfo fi, String pdf) throws IOException { PDDocument doc = getResource(pdf);/* ww w .j ava 2s .co m*/ PDPage page = (PDPage) doc.getDocumentCatalog().getPages().get(0); AffineTransform at = new AffineTransform(); String c = getPDFBoxAdapter().createStreamFromPDFBoxPage(doc, page, pdf, at, fi, new Rectangle()); // PDResources sourcePageResources = page.findResources(); // COSDictionary fonts = (COSDictionary)sourcePageResources.getCOSDictionary().getDictionaryObject(COSName.FONT); // PDFBoxAdapter.PDFWriter w = adapter. new MergeFontsPDFWriter(fonts, fi, "", new ArrayList<COSName>()); // String c = w.writeText(page.getContents()); doc.close(); return c; }
From source file:IDlook.java
private void createThumbnail() { int maxDim = 350; try {//from w w w . j a v a 2 s . c o m Image inImage = icon.getImage(); double scale = (double) maxDim / (double) inImage.getHeight(null); if (inImage.getWidth(null) > inImage.getHeight(null)) { scale = (double) maxDim / (double) inImage.getWidth(null); } int scaledW = (int) (scale * inImage.getWidth(null)); int scaledH = (int) (scale * inImage.getHeight(null)); BufferedImage outImage = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_INT_RGB); AffineTransform tx = new AffineTransform(); if (scale < 1.0d) { tx.scale(scale, scale); } Graphics2D g2d = outImage.createGraphics(); g2d.drawImage(inImage, tx, null); g2d.dispose(); iconThumbnail = new ImageIcon(outImage); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jcurl.demo.tactics.TrajectoryScenarioBean.java
public TrajectoryScenarioBean() { setVisible(false);// w w w .j a v a 2 s . com broom.setModel(tt); panel = new JSGPanel(); setLayout(new BorderLayout()); add(panel, BorderLayout.CENTER); final SGGroup world = new SGGroup(); world.add(new SGIceFactory.Fancy().newInstance()); // rocks.setVisible(false); final SGGroup r0 = new SGGroup(); final SGGroup r1 = new SGGroup(); final SGGroup pa = new SGGroup(); // rocks.add(traj); final RockSet<Pos> home = RockSetUtils.allHome(); final RockSet<Pos> out = RockSetUtils.allOut(); for (int i16 = RockSet.ROCKS_PER_SET - 1; i16 >= 0; i16--) { Affine n = createSceneRock(home, i16, 255); n.setMouseBlocker(true); n.addMouseListener(mouse); n.setCursor(CURSOR); r0.add(initial[i16] = n); r1.add(current[i16] = n = createSceneRock(out, i16, 255)); n.putAttribute(ATTR_TRIGGER_CURVE_UPDATE, true); pa.add(path[i16] = new SGGroup()); } if (false) { rocks.add(pa); rocks.add(r0); rocks.add(r1); } else { opa_r0.setChild(r0); opa_r0.setOpacity(64.0F / 255.0F); opa_r0.setOverlapBehavior(OverlapBehavior.LAYER); opa_r1.setChild(r1); opa_r1.setOverlapBehavior(OverlapBehavior.LAYER); opa_t0.setChild(pa); opa_t0.setMouseBlocker(true); opa_t0.setOverlapBehavior(OverlapBehavior.LAYER); opa_t0.setOpacity(100.0F / 255.0F); rocks.add(opa_t0); rocks.add(opa_r0); rocks.add(opa_r1); } rocks.add(broom.getScene()); rocks.setVisible(false); world.add(rocks); // make world right-handed: final AffineTransform rightHand = AffineTransform.getScaleInstance(1, -1); zoom = SGTransform.createAffine(new AffineTransform(), dc2wc = SGTransform.createAffine(rightHand, world)); broom.setDc2wc(dc2wc); panel.setScene(zoom); setVisible(true); }
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * Get the label shape for the given tree node * @param treeNode/*from ww w .j a v a 2 s . c o m*/ * the tree node * @param frc * the font rendering context * @return * the label shape */ private Shape getLabelShape(VisualTreeNode treeNode, FontRenderContext frc) { // convert the strain list to a comma separated list then wrap it List<String> strainList = treeNode.getPhylogenyTreeNode().getStrains(); int strainCount = strainList.size(); StringBuffer commaSeparatedStrains = new StringBuffer(); for (int i = 0; i < strainCount; i++) { if (i >= 1) { commaSeparatedStrains.append(", "); } commaSeparatedStrains.append(strainList.get(i)); } String[] wrappedStrains = TextWrapper.wrapText(commaSeparatedStrains.toString(), NODE_LABEL_WRAP_LIMIT); Shape textShape = Java2DUtils.createCenteredMultilineTextShape(wrappedStrains, LABEL_FONT, frc); AffineTransform transform = new AffineTransform(); transform.translate(treeNode.getPosition().getX(), treeNode.getPosition().getY()); textShape = transform.createTransformedShape(textShape); return textShape; }
From source file:org.dishevelled.brainstorm.BrainStorm.java
/** * Calculate the text area size in rows and columns based on the current * window size and text area font size.//from w ww . j av a2s. c o m */ private void calculateTextAreaSize() { double width = (double) getWidth(); FontRenderContext frc = new FontRenderContext(new AffineTransform(), true, true); TextLayout textLayout = new TextLayout("W", textArea.getFont(), frc); Rectangle2D textBounds = textLayout.getBounds(); int columns = Math.min(45, (int) (width / textBounds.getWidth()) - 4); textArea.setColumns(columns); }
From source file:org.apache.jetspeed.security.mfa.impl.CaptchaImageResource.java
/** * Renders this image/*from ww w. java 2s .com*/ * * @return The image data */ private final byte[] render() throws IOException { Graphics2D gfx = (Graphics2D) this.image.getGraphics(); if (config.isFontAntialiasing()) gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int curWidth = config.getTextMarginLeft(); FontRenderContext ctx = new FontRenderContext(null, config.isFontAntialiasing(), false); for (int i = 0; i < charAttsList.size(); i++) { CharAttributes cf = (CharAttributes) charAttsList.get(i); TextLayout text = new TextLayout(cf.getChar() + "", getFont(cf.getName()), ctx); //gfx.getFontRenderContext()); AffineTransform textAt = new AffineTransform(); textAt.translate(curWidth, this.height - cf.getRise()); if (cf.getRotation() != 0) { textAt.rotate(cf.getRotation()); } if (cf.getShearX() > 0.0) textAt.shear(cf.getShearX(), cf.getShearY()); Shape shape = text.getOutline(textAt); curWidth += shape.getBounds().getWidth() + config.getTextSpacing(); if (config.isUseImageBackground()) gfx.setColor(Color.BLACK); else gfx.setXORMode(Color.BLACK); gfx.fill(shape); } if (config.isEffectsNoise()) { noiseEffects(gfx, image); } if (config.isUseTimestamp()) { if (config.isEffectsNoise()) gfx.setColor(Color.WHITE); else gfx.setColor(Color.BLACK); TimeZone tz = TimeZone.getTimeZone(config.getTimestampTZ()); Calendar cal = new GregorianCalendar(tz); SimpleDateFormat formatter; if (config.isUseTimestamp24hr()) formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z"); else formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a, z"); formatter.setTimeZone(tz); Font font = gfx.getFont(); Font newFont = new Font(font.getName(), font.getStyle(), config.getTimestampFontSize()); gfx.setFont(newFont); gfx.drawString(formatter.format(cal.getTime()), config.getTextMarginLeft() * 4, this.height - 1); } return toImageData(image); }
From source file:org.jcurl.core.base.CurveTransformedTest.java
public void testStill() { final PositionSet p = PositionSet.allOut(); final CurveTransformed[] c = new CurveTransformed[6]; final AffineTransform[] m = new AffineTransform[c.length]; int k = -1;/* w w w . j a v a 2 s . c om*/ // Plain & straight m[++k] = new AffineTransform(); c[k] = new CurveTransformed(SlideBase.still(0.25, 1, 0), m[k], 0); m[++k] = new AffineTransform(); m[k].translate(0.5, 1); c[k] = new CurveTransformed(SlideBase.still(0, 0, 0), m[k], 0); // Plain & looking left m[++k] = new AffineTransform(); c[k] = new CurveTransformed(SlideBase.still(0.25, 1.5, 0.25 * Math.PI), m[k], 0); m[++k] = new AffineTransform(); m[k].translate(0.5, 1.5); m[k].rotate(0.25 * Math.PI); c[k] = new CurveTransformed(SlideBase.still(0, 0, 0), m[k], 0); // createRc2Wc & looking left m[++k] = new AffineTransform(); c[k] = new CurveTransformed(SlideBase.still(0.25, 2, 0.25 * Math.PI), m[k], 0); m[++k] = CurveTransformed.createRc2Wc(null, new Point2D.Double(0.5, 2), new Point2D.Double(-1, 1)); c[k] = new CurveTransformed(SlideBase.still(0, 0, 0), m[k], 0); final double[] tmp = { 0, 0, 0 }; for (int i = c.length - 1; i >= 0; i--) p.getRock(i).setLocation(c[i].at(0, 0, tmp)); // Check if "sibling" rocks look alike: showPositionDisplay(p, Zoomer.C12, 5000, new TimeRunnable() { @Override public void run(final double t) throws InterruptedException { p.notifyChange(); Thread.sleep(1500); } }); assertEquals(0.25, 1, 0, p.getRock(0), 1e-6); assertEquals(0.5, 1, 0, p.getRock(1), 1e-6); assertEquals(0.25, 1.5, 0.25 * Math.PI, p.getRock(2), 1e-6); assertEquals(0.5, 1.5, 0.25 * Math.PI, p.getRock(3), 1e-6); assertEquals(0.25, 2, 0.25 * Math.PI, p.getRock(4), 1e-6); assertEquals(0.5, 2, 0.25 * Math.PI, p.getRock(5), 1e-6); }
From source file:org.geolatte.maprenderer.sld.graphics.ExternalGraphicsRepository.java
private BufferedImage rotate(BufferedImage img, float rotation) { AffineTransform tx = new AffineTransform(); //determine center point of image int sx = img.getMinX() + img.getWidth() / 2; int sy = img.getMinY() + img.getHeight() / 2; double theta = Math.toRadians(rotation); tx.rotate(theta, sx, sy);// w w w . j a v a 2 s. c o m AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); return op.filter(img, null); }
From source file:org.schemaspy.view.DotNode.java
private int getTextWidth(String text) { AffineTransform affinetransform = new AffineTransform(); FontRenderContext frc = new FontRenderContext(affinetransform, true, true); int fontSize = Config.getInstance().getFontSize() + 1; Font font = new Font(Config.getInstance().getFont(), Font.BOLD, fontSize); int fontWidth = (int) (font.getStringBounds(text, frc).getWidth()); return fontWidth; }