List of usage examples for java.awt.geom AffineTransform AffineTransform
public AffineTransform()
From source file:Main.java
public static void main(String[] argv) throws Exception { BufferedImage bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED); AffineTransform tx = new AffineTransform(); tx.scale(1, 2);/*w ww . j a v a 2 s .c o m*/ AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); bufferedImage = op.filter(bufferedImage, null); }
From source file:Main.java
public static void main(String[] argv) throws Exception { BufferedImage bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED); AffineTransform tx = new AffineTransform(); tx.rotate(0.5, bufferedImage.getWidth() / 2, bufferedImage.getHeight() / 2); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); bufferedImage = op.filter(bufferedImage, null); }
From source file:org.eclipse.swt.snippets.Snippet361.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 361"); shell.setText("Translate and Rotate an AWT Image in an SWT GUI"); shell.setLayout(new GridLayout(8, false)); Button fileButton = new Button(shell, SWT.PUSH); fileButton.setText("&Open Image File"); fileButton.addSelectionListener(widgetSelectedAdapter(e -> { String filename = new FileDialog(shell).open(); if (filename != null) { image = Toolkit.getDefaultToolkit().getImage(filename); canvas.repaint();/*from w w w.j av a 2s .c o m*/ } })); new Label(shell, SWT.NONE).setText("Translate &X by:"); final Combo translateXCombo = new Combo(shell, SWT.NONE); translateXCombo.setItems("0", "image width", "image height", "100", "200"); translateXCombo.select(0); translateXCombo.addModifyListener(e -> { translateX = numericValue(translateXCombo); canvas.repaint(); }); new Label(shell, SWT.NONE).setText("Translate &Y by:"); final Combo translateYCombo = new Combo(shell, SWT.NONE); translateYCombo.setItems("0", "image width", "image height", "100", "200"); translateYCombo.select(0); translateYCombo.addModifyListener(e -> { translateY = numericValue(translateYCombo); canvas.repaint(); }); new Label(shell, SWT.NONE).setText("&Rotate by:"); final Combo rotateCombo = new Combo(shell, SWT.NONE); rotateCombo.setItems("0", "Pi", "Pi/2", "Pi/4", "Pi/8"); rotateCombo.select(0); rotateCombo.addModifyListener(e -> { rotate = numericValue(rotateCombo); canvas.repaint(); }); Button printButton = new Button(shell, SWT.PUSH); printButton.setText("&Print Image"); printButton.addSelectionListener(widgetSelectedAdapter(e -> { performPrintAction(display, shell); })); composite = new Composite(shell, SWT.EMBEDDED | SWT.BORDER); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 8, 1); data.widthHint = 640; data.heightHint = 480; composite.setLayoutData(data); Frame frame = SWT_AWT.new_Frame(composite); canvas = new Canvas() { @Override public void paint(Graphics g) { if (image != null) { g.setColor(Color.WHITE); g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight()); /* Use Java2D here to modify the image as desired. */ Graphics2D g2d = (Graphics2D) g; AffineTransform t = new AffineTransform(); t.translate(translateX, translateY); t.rotate(rotate); g2d.setTransform(t); /*------------*/ g.drawImage(image, 0, 0, this); } } }; frame.add(canvas); composite.getAccessible().addAccessibleListener(new AccessibleAdapter() { @Override public void getName(AccessibleEvent e) { e.result = "Image drawn in AWT Canvas"; } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:de.mendelson.comm.as2.AS2.java
/**Method to start the server on from the command line*/ public static void main(String args[]) { // TODO remove cleanup();// w w w. ja v a 2 s . c o m String language = null; boolean startHTTP = true; boolean allowAllClients = false; int optind; for (optind = 0; optind < args.length; optind++) { if (args[optind].toLowerCase().equals("-lang")) { language = args[++optind]; } else if (args[optind].toLowerCase().equals("-nohttpserver")) { startHTTP = false; } else if (args[optind].toLowerCase().equals("-allowallclients")) { allowAllClients = true; } else if (args[optind].toLowerCase().equals("-?")) { AS2.printUsage(); System.exit(1); } else if (args[optind].toLowerCase().equals("-h")) { AS2.printUsage(); System.exit(1); } else if (args[optind].toLowerCase().equals("-help")) { AS2.printUsage(); System.exit(1); } } //load language from preferences if (language == null) { PreferencesAS2 preferences = new PreferencesAS2(); language = preferences.get(PreferencesAS2.LANGUAGE); } if (language != null) { if (language.toLowerCase().equals("en")) { Locale.setDefault(Locale.ENGLISH); } else if (language.toLowerCase().equals("de")) { Locale.setDefault(Locale.GERMAN); } else if (language.toLowerCase().equals("fr")) { Locale.setDefault(Locale.FRENCH); } else { AS2.printUsage(); System.out.println(); System.out.println("Language " + language + " is not supported."); System.exit(1); } } Splash splash = new Splash("/de/mendelson/comm/as2/client/Splash.jpg"); AffineTransform transform = new AffineTransform(); splash.setTextAntiAliasing(false); transform.setToScale(1.0, 1.0); splash.addDisplayString(new Font("Verdana", Font.BOLD, 11), 7, 262, AS2ServerVersion.getFullProductName(), new Color(0x65, 0xB1, 0x80), transform); splash.setVisible(true); splash.toFront(); //start server try { //register the database drivers for the VM Class.forName("org.hsqldb.jdbcDriver"); //initialize the security provider BCCryptoHelper helper = new BCCryptoHelper(); helper.initialize(); AS2Server as2Server = new AS2Server(startHTTP, allowAllClients); AS2Agent agent = new AS2Agent(as2Server); } catch (UpgradeRequiredException e) { //an upgrade to HSQLDB 2.x is required, delete the lock file Logger.getLogger(AS2Server.SERVER_LOGGER_NAME).warning(e.getMessage()); JOptionPane.showMessageDialog(null, e.getClass().getName() + ": " + e.getMessage()); AS2Server.deleteLockFile(); System.exit(1); } catch (Throwable e) { if (splash != null) { splash.destroy(); } JOptionPane.showMessageDialog(null, e.getMessage()); System.exit(1); } //start client AS2Gui gui = new AS2Gui(splash, "localhost"); gui.setVisible(true); splash.destroy(); splash.dispose(); }
From source file:Main.java
public static int getFontSize(String text, boolean getWidth) { if (text != null && text.length() > 0) { Font defaultFont = new Font("Montserrat", Font.PLAIN, 13); AffineTransform affinetransform = new AffineTransform(); FontRenderContext frc = new FontRenderContext(affinetransform, true, true); int textWidth = (int) (defaultFont.getStringBounds(text, frc) != null ? defaultFont.getStringBounds(text, frc).getWidth() : 0) + 10;// w w w.j a v a 2s . c o m int textHeight = (int) (defaultFont.getStringBounds(text, frc) != null ? defaultFont.getStringBounds(text, frc).getHeight() : 0); return getWidth ? textWidth : textHeight; } return 0; }
From source file:Main.java
/** * Converts a {@link Shape} to TDL. //from w w w . j av a 2 s . c o m * @param s * @return a string containing a space separated list of the points * specifiying the shape */ public static String shapeToXML(Shape s) { StringBuilder sb = new StringBuilder(); PathIterator pi = s.getPathIterator(new AffineTransform()); float[] coords = new float[6]; while (!pi.isDone()) { pi.currentSegment(coords); sb.append(String.valueOf(coords[0]) + "," + String.valueOf(coords[1])); pi.next(); if (!pi.isDone()) { sb.append(" "); } } return sb.toString(); }
From source file:Main.java
public static int paintMultilineText(Graphics2D g2d, String text, int textX, int textWidth, int textY, int maxTextLineCount) { FontRenderContext frc = new FontRenderContext(new AffineTransform(), true, false); int fa = g2d.getFontMetrics().getAscent(); if (text.length() == 0) return textY; int currOffset = 0; AttributedString attributedDescription = new AttributedString(text); attributedDescription.addAttribute(TextAttribute.FONT, g2d.getFont()); LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(attributedDescription.getIterator(), frc); int lineCount = 0; while (true) { TextLayout tl = lineBreakMeasurer.nextLayout(textWidth); if (tl == null) break; int charCount = tl.getCharacterCount(); String line = text.substring(currOffset, currOffset + charCount); g2d.drawString(line, textX, textY); textY += fa;/* www. j av a2 s . c om*/ currOffset += charCount; lineCount++; if ((maxTextLineCount > 0) && (lineCount == maxTextLineCount)) break; } // textY += fh; return textY; }
From source file:Main.java
private static AffineTransform createRandomTransform(double angleRad) { AffineTransform at = new AffineTransform(); double scale = 1.0; at.translate(randomDouble(), randomDouble()); scale = Math.abs(randomDouble()); at.scale(scale, scale);//from ww w. j a v a 2s . c om at.rotate(angleRad); at.translate(randomDouble(), randomDouble()); scale = Math.abs(randomDouble()); at.scale(scale, scale); return at; }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AffineTransform at = new AffineTransform(); at.setToRotation(-Math.PI / 2.0, getWidth() / 2.0, getHeight() / 2.0); g2d.setTransform(at);/*from w ww. j a v a 2 s. c o m*/ g2d.drawString("Vertical text", 10, 10); }
From source file:Shear.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; AffineTransform tx1 = new AffineTransform(); tx1.translate(50, 90);/*from w ww . j av a2s . c o m*/ g2d.setTransform(tx1); g2d.setColor(Color.green); g2d.drawRect(0, 0, 80, 50); AffineTransform tx2 = new AffineTransform(); tx2.translate(50, 90); tx2.shear(0, 1); g2d.setTransform(tx2); g2d.setColor(Color.blue); g2d.draw(new Rectangle(0, 0, 80, 50)); }