Example usage for java.awt Rectangle Rectangle

List of usage examples for java.awt Rectangle Rectangle

Introduction

In this page you can find the example usage for java.awt Rectangle Rectangle.

Prototype

public Rectangle(int x, int y, int width, int height) 

Source Link

Document

Constructs a new Rectangle whose upper-left corner is specified as (x,y) and whose width and height are specified by the arguments of the same name.

Usage

From source file:org.jfree.graphics2d.demo.BufferedImageDemo.java

/**
 * Starting point for the demo./*from w  w  w.j  av  a 2s  . com*/
 * 
 * @param args  ignored.
 * 
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    BufferedImage image = new BufferedImage(600, 400, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = image.createGraphics();
    ImageIcon icon = new ImageIcon(BufferedImageDemo.class.getResource("jfree_chart_1.jpg"));
    g2.rotate(Math.PI / 12);
    g2.setStroke(new BasicStroke(2.0f));
    g2.setPaint(Color.WHITE);
    g2.fill(new Rectangle(0, 0, 600, 400));
    g2.setPaint(Color.RED);
    g2.draw(new Rectangle(0, 0, 600, 400));
    g2.drawImage(icon.getImage(), 10, 20, null);
    ImageIO.write(image, "png", new File("image-test.png"));
}

From source file:org.jfree.graphics2d.demo.CanvasPieChartDemo1.java

/**
 * Starting point for the demo.//from w ww .j  a  v a 2  s. c  o m
 * 
 * @param args  ignored.
 * 
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    JFreeChart chart = createChart(createDataset());
    CanvasGraphics2D g2 = new CanvasGraphics2D("id");
    int width = 600;
    int height = 400;
    chart.draw(g2, new Rectangle(0, 0, width, height));
    File f = new File("CanvasPieChartDemo1.html");
    CanvasUtils.writeToHTML(f, "CanvasPieChartDemo1", g2.getCanvasID(), width, height, g2.getScript());
}

From source file:org.jfree.graphics2d.demo.SVGBarChartDemo1.java

/**
 * Starting point for the demo.//from  w w  w  .j  ava  2s  . c  o  m
 * 
 * @param args  ignored.
 * 
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    JFreeChart chart = createChart(createDataset());
    SVGGraphics2D g2 = new SVGGraphics2D(600, 400);
    Rectangle r = new Rectangle(0, 0, 600, 400);
    chart.draw(g2, r);
    File f = new File("SVGBarChartDemo1.svg");
    SVGUtils.writeToSVG(f, g2.getSVGElement());
}

From source file:org.jfree.graphics2d.demo.CanvasBarChartDemo1.java

/**
 * Starting point for the demo./*w w w .  j  a v a 2s. c om*/
 * 
 * @param args  ignored.
 * 
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    JFreeChart chart = createChart(createDataset());
    CanvasGraphics2D g2 = new CanvasGraphics2D("id");
    int width = 600;
    int height = 400;
    Rectangle r = new Rectangle(0, 0, width, height);
    chart.draw(g2, r);
    File f = new File("CanvasBarChartDemo1.html");
    CanvasUtils.writeToHTML(f, "CanvasBarChartDemo1", g2.getCanvasID(), width, height, g2.getScript());
}

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);/*from   w  w w .  j  av  a 2  s  . c om*/

    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:org.jfree.graphics2d.demo.SVGPieChartDemo1.java

/**
 * Starting point for the demo.//  w  w w  .ja  v  a 2  s  . c  om
 * 
 * @param args  ignored.
 * 
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    JFreeChart chart = createChart(createDataset());
    SVGGraphics2D g2 = new SVGGraphics2D(600, 400);
    g2.setRenderingHint(JFreeChart.KEY_SUPPRESS_SHADOW_GENERATION, true);
    Rectangle r = new Rectangle(0, 0, 600, 400);
    chart.draw(g2, r);
    File f = new File("SVGPieChartDemo1.svg");
    SVGUtils.writeToSVG(f, g2.getSVGElement());
}

From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java

/**
 * Starting point for the demo.//from   w w  w  .  j  av a 2s.c  om
 * 
 * @param args  ignored.
 * 
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
    JFreeChart chart = createChart(createDataset());
    SVGGraphics2D g2 = new SVGGraphics2D(500, 300);
    Rectangle r = new Rectangle(0, 0, 500, 300);
    chart.draw(g2, r);
    File f = new File("SVGChartWithAnnotationsDemo1.svg");
    SVGUtils.writeToSVG(f, g2.getSVGElement());
}

From source file:Main.java

public static void main() {

    Frame frame = new Frame();

    Rectangle bounds = new Rectangle(20, 20, 200, 200);

    frame.setMaximizedBounds(bounds);//from  ww  w  .  j ava  2s  .c  o  m
    frame.setVisible(true);
}

From source file:Main.java

public static Rectangle getRelativeBounds(Component component) {
    Rectangle bounds = new Rectangle(0, 0, component.getWidth(), component.getHeight());
    Container parent = component.getParent();

    while (parent != null) {
        bounds.x += component.getX();//from   w  ww.ja  v  a 2  s  .com
        bounds.y += component.getY();
        component = parent;
        parent = component.getParent();
    }

    return bounds;
}

From source file:Main.java

public static Rectangle getRectangle(Point p1, Point p2) {
    return new Rectangle(Math.min(p1.x, p2.x), Math.min(p1.y, p2.y), Math.abs(p1.x - p2.x),
            Math.abs(p1.y - p2.y));
}