List of usage examples for java.awt Graphics2D setColor
public abstract void setColor(Color c);
From source file:com.vitco.Main.java
public static void main(String[] args) throws Exception { // display version number on splash screen final SplashScreen splash = SplashScreen.getSplashScreen(); if (splash != null) { Graphics2D g = splash.createGraphics(); if (g != null) { g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); Font font = Font .createFont(Font.TRUETYPE_FONT, new SaveResourceLoader("resource/font/arcade.ttf").asInputStream()) .deriveFont(Font.PLAIN, 42f); g.setFont(font);//from w w w .ja v a 2s . c o m //g.setFont(g.getFont().deriveFont(9f)); g.setColor(VitcoSettings.SPLASH_SCREEN_OVERLAY_TEXT_COLOR); int width = g.getFontMetrics().stringWidth(VitcoSettings.VERSION_ID); g.drawString(VitcoSettings.VERSION_ID, 400 - 20 - width, 110); splash.update(); g.dispose(); } } // the JIDE license SaveResourceLoader saveResourceLoader = new SaveResourceLoader("resource/jidelicense.txt"); if (!saveResourceLoader.error) { String[] jidelicense = saveResourceLoader.asLines(); if (jidelicense.length == 3) { com.jidesoft.utils.Lm.verifyLicense(jidelicense[0], jidelicense[1], jidelicense[2]); } } // check if we are in debug mode if ((args.length > 0) && args[0].equals("debug")) { ErrorHandler.setDebugMode(); debug = true; } // build the application final ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( "com/vitco/glue/config.xml"); // for debugging if (debug) { ((ActionManager) context.getBean("ActionManager")).performValidityCheck(); ((ComplexActionManager) context.getBean("ComplexActionManager")).performValidityCheck(); } // open vsd file when program is started with "open with" MainMenuLogic mainMenuLogic = ((MainMenuLogic) context.getBean("MainMenuLogic")); for (String arg : args) { if (arg.endsWith(".vsd")) { File file = new File(arg); if (file.exists() && !file.isDirectory()) { mainMenuLogic.openFile(file); break; } } } // perform shortcut check ((ShortcutManager) context.getBean("ShortcutManager")).doSanityCheck(debug); // // test console // final Console console = ((Console) context.getBean("Console")); // new Thread() { // public void run() { // while (true) { // console.addLine("text"); // try { // sleep(2000); // } catch (InterruptedException e) { // //e.printStackTrace(); // } // } // } // }.start(); // add a shutdown hook Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { // make reference so Preferences object doesn't get destroyed Preferences pref = ((Preferences) context.getBean("Preferences")); // trigger @PreDestroy context.close(); // store the preferences (this needs to be done here, b/c // some PreDestroys are used to store preferences!) pref.save(); } }); }
From source file:Draw2DTest.java
public static void main(String[] args) { final Graphics2DRenderer renderer = new Graphics2DRenderer(); Shell shell = new Shell(); shell.setSize(350, 350);/*from w w w.ja v a 2 s. c o m*/ shell.open(); shell.setText("Draw2d Hello World"); LightweightSystem lws = new LightweightSystem(shell); IFigure figure = new Figure() { protected void paintClientArea(org.eclipse.draw2d.Graphics graphics) { Dimension controlSize = getSize(); renderer.prepareRendering(graphics); // prepares the Graphics2D renderer // gets the Graphics2D context and switch on the antialiasing Graphics2D g2d = renderer.getGraphics2D(); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // paints the background with a color gradient g2d.setPaint(new GradientPaint(0.0f, 0.0f, java.awt.Color.yellow, (float) controlSize.width, (float) controlSize.width, java.awt.Color.white)); g2d.fillRect(0, 0, controlSize.width, controlSize.width); // draws rotated text g2d.setFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 16)); g2d.setColor(java.awt.Color.blue); g2d.translate(controlSize.width / 2, controlSize.width / 2); int nbOfSlices = 18; for (int i = 0; i < nbOfSlices; i++) { g2d.drawString("Angle = " + (i * 360 / nbOfSlices) + "\u00B0", 30, 0); g2d.rotate(-2 * Math.PI / nbOfSlices); } // now that we are done with Java2D, renders Graphics2D // operation // on the SWT graphics context renderer.render(graphics); // now we can continue with pure SWT paint operations graphics.drawOval(0, 0, controlSize.width, controlSize.width); } }; lws.setContents(figure); Display display = Display.getDefault(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } renderer.dispose(); }
From source file:SWTTest.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setSize(350, 350);//from w w w. jav a2 s . c om shell.setLayout(new GridLayout()); Canvas canvas = new Canvas(shell, SWT.NO_BACKGROUND); GridData data = new GridData(GridData.FILL_BOTH); canvas.setLayoutData(data); final Graphics2DRenderer renderer = new Graphics2DRenderer(); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Point controlSize = ((Control) e.getSource()).getSize(); GC gc = e.gc; // gets the SWT graphics context from the event renderer.prepareRendering(gc); // prepares the Graphics2D // renderer // gets the Graphics2D context and switch on the antialiasing Graphics2D g2d = renderer.getGraphics2D(); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // paints the background with a color gradient g2d.setPaint(new GradientPaint(0.0f, 0.0f, java.awt.Color.yellow, (float) controlSize.x, (float) controlSize.y, java.awt.Color.white)); g2d.fillRect(0, 0, controlSize.x, controlSize.y); // draws rotated text g2d.setFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 16)); g2d.setColor(java.awt.Color.blue); g2d.translate(controlSize.x / 2, controlSize.y / 2); int nbOfSlices = 18; for (int i = 0; i < nbOfSlices; i++) { g2d.drawString("Angle = " + (i * 360 / nbOfSlices) + "\u00B0", 30, 0); g2d.rotate(-2 * Math.PI / nbOfSlices); } // now that we are done with Java2D, renders Graphics2D // operation // on the SWT graphics context renderer.render(gc); // now we can continue with pure SWT paint operations gc.drawOval(0, 0, controlSize.x, controlSize.y); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); renderer.dispose(); System.exit(0); }
From source file:Main.java
public static void main(String[] args) throws Exception { String text = "java2s.com"; BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); Font font = new Font("Arial", Font.PLAIN, 48); g2d.setFont(font);/*from w w w .j a va 2 s .c om*/ FontMetrics fm = g2d.getFontMetrics(); int width = fm.stringWidth(text); int height = fm.getHeight(); g2d.dispose(); img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); g2d = img.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); g2d.setFont(font); fm = g2d.getFontMetrics(); g2d.setColor(Color.BLACK); g2d.drawString(text, 0, fm.getAscent()); g2d.dispose(); ImageIO.write(img, "png", new File("Text.png")); }
From source file:akori.AKORI.java
public static void main(String[] args) throws IOException, InterruptedException { System.out.println("esto es AKORI"); URL = "http://www.mbauchile.cl"; PATH = "E:\\NetBeansProjects\\AKORI\\"; NAME = "mbauchile.png"; // Extrar DOM tree Document doc = Jsoup.connect(URL).timeout(0).get(); // The Firefox driver supports javascript WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); System.out.println(driver.manage().window().getSize().toString()); System.out.println(driver.manage().window().getPosition().toString()); int xmax = driver.manage().window().getSize().width; int ymax = driver.manage().window().getSize().height; // Go to the URL page driver.get(URL);/* w w w . j a v a 2 s. c o m*/ File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screen, new File(PATH + NAME)); BufferedImage img = ImageIO.read(new File(PATH + NAME)); //Graphics2D graph = img.createGraphics(); BufferedImage img1 = new BufferedImage(xmax, ymax, BufferedImage.TYPE_INT_ARGB); Graphics2D graph1 = img.createGraphics(); double[][] matrix = new double[ymax][xmax]; BufferedReader in = new BufferedReader(new FileReader("et.txt")); String linea; double max = 0; graph1.drawImage(img, 0, 0, null); HashMap<String, Integer> lista = new HashMap<String, Integer>(); int count = 0; for (int i = 0; (linea = in.readLine()) != null && i < 10000; ++i) { String[] datos = linea.split(","); int x = (int) Double.parseDouble(datos[0]); int y = (int) Double.parseDouble(datos[2]); long time = Double.valueOf(datos[4]).longValue(); if (x >= xmax || y >= ymax) continue; if (time < 691215) continue; if (time > 705648) break; if (lista.containsKey(x + "," + y)) lista.put(x + "," + y, lista.get(x + "," + y) + 1); else lista.put(x + "," + y, 1); ++count; } System.out.println(count); in.close(); Iterator iter = lista.entrySet().iterator(); Map.Entry e; for (String key : lista.keySet()) { Integer i = lista.get(key); if (max < i) max = i; } System.out.println(max); max = 0; while (iter.hasNext()) { e = (Map.Entry) iter.next(); String xy = (String) e.getKey(); String[] datos = xy.split(","); int x = Integer.parseInt(datos[0]); int y = Integer.parseInt(datos[1]); matrix[y][x] += (int) e.getValue(); double aux; if ((aux = normalMatrix(matrix, y, x, ((int) e.getValue()) * 4)) > max) { max = aux; } //normalMatrix(matrix,x,y,20); if (matrix[y][x] > max) max = matrix[y][x]; } int A, R, G, B, n; for (int i = 0; i < xmax; ++i) { for (int j = 0; j < ymax; ++j) { if (matrix[j][i] != 0) { n = (int) Math.round(matrix[j][i] * 100 / max); R = Math.round((255 * n) / 100); G = Math.round((255 * (100 - n)) / 100); B = 0; A = Math.round((255 * n) / 100); ; if (R > 255) R = 255; if (R < 0) R = 0; if (G > 255) G = 255; if (G < 0) G = 0; if (R < 50) A = 0; graph1.setColor(new Color(R, G, B, A)); graph1.fillOval(i, j, 1, 1); } } } //graph1.dispose(); ImageIO.write(img, "png", new File("example.png")); System.out.println(max); graph1.setColor(Color.RED); // Extraer elementos Elements e1 = doc.body().getAllElements(); int i = 1; ArrayList<String> tags = new ArrayList<String>(); for (Element temp : e1) { if (tags.indexOf(temp.tagName()) == -1) { tags.add(temp.tagName()); List<WebElement> query = driver.findElements(By.tagName(temp.tagName())); for (WebElement temp1 : query) { Point po = temp1.getLocation(); Dimension d = temp1.getSize(); if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) continue; System.out.println(i + " " + temp.nodeName()); System.out.println(" x: " + po.x + " y: " + po.y); System.out.println(" width: " + d.width + " height: " + d.height); graph1.draw(new Rectangle(po.x, po.y, d.width, d.height)); ++i; } } } graph1.dispose(); ImageIO.write(img, "png", new File(PATH + NAME)); driver.quit(); }
From source file:Main.java
public static Image createImage(int size, Color color) { BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); g.setColor(color); g.fillRect(0, 0, size, size);/*from w w w . j a va2 s . c om*/ g.dispose(); return image; }
From source file:Main.java
public static BufferedImage drawtrajectory(BufferedImage canvas, int parabola[][], Color bgColour) { Graphics2D g2d = canvas.createGraphics(); g2d.setColor(bgColour); g2d.drawPolyline(parabola[0], parabola[1], parabola[0].length); return canvas; }
From source file:Main.java
/** * Creates an outline of an image,/* w w w .j av a 2 s . c om*/ * with the default clipping rectangle. * @param src The source image. * @param c The color to outline the image * in. * @return */ public static BufferedImage imgUtilOutline(BufferedImage src, Color c) { if (src == null) return null; BufferedImage b = new BufferedImage(src.getWidth(), src.getHeight(), src.getType()); Graphics2D g = (Graphics2D) b.getGraphics(); g.setColor(c); g.drawRect(1, 1, src.getWidth() - 1, src.getHeight() - 1); g.drawImage(src, 0, 0, null); g.dispose(); return b; }
From source file:Main.java
private static BufferedImage renderRotatedObject(Object src, double angle, int width, int height, double tx, double ty) { BufferedImage dest = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = (Graphics2D) dest.getGraphics(); g2d.setColor(Color.black); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AffineTransform at = AffineTransform.getRotateInstance(angle); at.translate(tx, ty);/* w ww . j a va 2s . c om*/ g2d.setTransform(at); if (src instanceof TextLayout) { TextLayout tl = (TextLayout) src; tl.draw(g2d, 0, tl.getAscent()); } else if (src instanceof Image) { g2d.drawImage((Image) src, 0, 0, null); } g2d.dispose(); return dest; }
From source file:Main.java
/** * Creates and returns image from the given text. * @param text input text//from w w w .j av a 2 s.co m * @param font text font * @return image with input text */ public static BufferedImage createImageFromText(String text, Font font) { //You may want to change these setting, or make them parameters boolean isAntiAliased = true; boolean usesFractionalMetrics = false; FontRenderContext frc = new FontRenderContext(null, isAntiAliased, usesFractionalMetrics); TextLayout layout = new TextLayout(text, font, frc); Rectangle2D bounds = layout.getBounds(); int w = (int) Math.ceil(bounds.getWidth()); int h = (int) Math.ceil(bounds.getHeight()) + 2; BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); //for example; Graphics2D g = image.createGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, w, h); g.setColor(Color.BLACK); g.setFont(font); Object antiAliased = isAntiAliased ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF; g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, antiAliased); Object fractionalMetrics = usesFractionalMetrics ? RenderingHints.VALUE_FRACTIONALMETRICS_ON : RenderingHints.VALUE_FRACTIONALMETRICS_OFF; g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, fractionalMetrics); g.drawString(text, (float) -bounds.getX(), (float) -bounds.getY()); g.dispose(); return image; }