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:ancat.visualizers.VertexTransformers.java

/**
 * Check some node specific rendering options so it will not be necessary to
 * do this directly at rendering time./*from  w w w .  ja v  a  2  s .  c om*/
 */
private void nodeConfig() {
    Map<String, String> nodeConfig = _renderConfig.nodeConfiguration();

    if (nodeConfig.containsKey("node:scaling")) {
        String value = _renderConfig.nodeConfiguration().get("node:scaling");

        if (value.equalsIgnoreCase("on"))
            _scaling = true;
        else
            _scaling = false;
    }

    if (nodeConfig.containsKey("node:shape:default")) {
        String value = _renderConfig.nodeConfiguration().get("node:shape:default");

        if (value.equalsIgnoreCase("rectangle")) {
            _defaultShape = new Rectangle(-5, -5, 10, 10);
            _defaultShape2 = new Rectangle(-10, -10, 20, 20);
            _defaultShape3 = new Rectangle(-15, -15, 30, 30);
            _defaultShape4 = new Rectangle(-20, -20, 40, 40);
        }

        else if (value.equalsIgnoreCase("bubble")) {
            _defaultShape = new Ellipse2D.Double(-5, -5, 10, 10);
            _defaultShape2 = new Ellipse2D.Double(-10, -10, 20, 20);
            _defaultShape3 = new Ellipse2D.Double(-15, -15, 30, 30);
            _defaultShape4 = new Ellipse2D.Double(-20, -20, 40, 40);
        }
    } else {
        _defaultShape = new Rectangle(-5, -5, 10, 10);
        _defaultShape2 = new Rectangle(-10, -10, 20, 20);
        _defaultShape3 = new Rectangle(-15, -15, 30, 30);
        _defaultShape4 = new Rectangle(-20, -20, 40, 40);
    }

    /**
     * This option is required when working with extremely dense graphs.
     * Rendering full labels must be turned off in this case.
     */
    if (nodeConfig.containsKey("node:label")) {
        _renderLabel = nodeConfig.get("node:label").equals("on") ? true : false;
    }

}

From source file:edu.uci.ics.jung.visualization.renderers.VertexLabelAsShapeRenderer.java

public Shape transform(V v) {
    Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(),
            rc.getVertexLabelTransformer().transform(v), rc.getPickedVertexState().isPicked(v), v);
    Dimension size = component.getPreferredSize();
    Rectangle bounds = new Rectangle(-size.width / 2 - 2, -size.height / 2 - 2, size.width + 4, size.height);
    return bounds;
    //      Shape shape = shapes.get(v);
    //      if(shape == null) {
    //         return new Rectangle(-20,-20,40,40);
    //      }/* w ww.j a v a 2 s  .c o m*/
    //      else return shape;
}

From source file:OptimalPrimitives.java

protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    long startTime, endTime, totalTime;

    g.setColor(Color.WHITE);/*w ww.  ja v a 2s .co m*/
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(Color.BLACK);

    g.drawString("Bad vs. Good Primitive Rendering", 50, 20);
    g.drawString("(" + ITERATIONS + " iterations)", 100, 35);
    g.drawString("Bad: ", 10, BAD_Y + 30);
    g.drawString("Good: ", 10, GOOD_Y + 30);

    // Bad line
    Shape line = new Line2D.Double(LINE_X, BAD_Y, LINE_X + 50, BAD_Y + 50);
    startTime = System.nanoTime();
    for (int i = 0; i < ITERATIONS; ++i) {
        g2d.draw(line);
    }
    endTime = System.nanoTime();
    totalTime = (endTime - startTime) / 1000000;
    System.out.println("bad line = " + totalTime);
    g.drawString(totalTime + " ms", LINE_X, BAD_Y + 70);

    // Good line
    startTime = System.nanoTime();
    for (int i = 0; i < ITERATIONS; ++i) {
        g.drawLine(LINE_X, GOOD_Y, LINE_X + 50, GOOD_Y + 50);
    }
    endTime = System.nanoTime();
    totalTime = (endTime - startTime) / 1000000;
    System.out.println("good line = " + totalTime);
    g.drawString(totalTime + " ms", LINE_X, GOOD_Y + 70);

    // Bad rect
    Shape rect = new Rectangle(RECT_X, BAD_Y, 50, 50);
    startTime = System.nanoTime();
    for (int i = 0; i < ITERATIONS; ++i) {
        g2d.fill(rect);
    }
    endTime = System.nanoTime();
    totalTime = (endTime - startTime) / 1000000;
    System.out.println("bad rect = " + totalTime);
    g.drawString(totalTime + " ms", RECT_X, BAD_Y + 70);

    // Good rect
    startTime = System.nanoTime();
    for (int i = 0; i < ITERATIONS; ++i) {
        g.fillRect(RECT_X, GOOD_Y, 50, 50);
    }
    endTime = System.nanoTime();
    totalTime = (endTime - startTime) / 1000000;
    System.out.println("good rect = " + totalTime);
    g.drawString(totalTime + " ms", RECT_X, GOOD_Y + 70);
}

From source file:com.jcraft.weirdx.DummySHAPEExtension.java

@SuppressWarnings("unused")
void dispatch(Client c) throws IOException {
    XWindow window;/*from   ww  w .j a v  a  2 s  . c  o  m*/
    int kind, x, y, w, h, shaped, op;
    Rectangle[] rect;
    int foo;
    InputOutput io = c.client;

    switch (c.data) {
    case 0:
        synchronized (io) {
            io.writeByte(1);
            io.writePad(1);
            io.writeShort(c.seq);
            io.writeInt(0);
            io.writeShort(1);
            io.writeShort(0);
            io.writePad(20);
            io.flush();
        }
        break;
    case 1:
        op = io.readByte();
        kind = io.readByte();
        int oder = io.readByte();
        io.readPad(1);
        foo = io.readInt();
        c.length -= 3;
        window = c.lookupWindow(foo);
        if (window == null) {
            c.errorValue = foo;
            c.errorReason = 3; // BadWindow
            return;
        }
        x = (short) io.readShort();
        y = (short) io.readShort();
        c.length--;
        int len = (c.length) / 2;
        rect = new Rectangle[len]; {
        int xx, yy, ww, hh;
        while (len > 0) {
            xx = (short) io.readShort();
            yy = (short) io.readShort();
            ww = (short) io.readShort();
            hh = (short) io.readShort();
            rect[rect.length - len] = new Rectangle(xx, yy, ww, hh);
            len--;
        }
    }
        //   synchronized(DummySHAPEExtension.class){                    
        //     window.ddxwindow.setShapeRectangles(op, kind, oder, x, y, rect);
        //   }                                                      
        break;
    case 2:
        op = io.readByte();
        kind = io.readByte();
        io.readPad(2);
        foo = io.readInt();
        c.length -= 3;
        window = c.lookupWindow(foo);
        if (window == null) {
            c.errorValue = foo;
            c.errorReason = 3; // BadWindow
            return;
        }
        x = (short) io.readShort();
        y = (short) io.readShort();
        foo = io.readInt();
        c.length -= 2;
        if (foo == 0) {
            sendShapeNotify(kind, window, x, y, window.width, window.height, 0);
            return;
        }

        XDrawable d = c.lookupDrawable(foo);
        if (d == null || !(d instanceof XPixmap)) {
            c.errorValue = foo;
            c.errorReason = 4; // BadPixmap;
            return;
        }
        XPixmap pixmap = (XPixmap) d;
        if (pixmap.depth != 1) {
            c.errorValue = foo;
            c.errorReason = 8; // BadMatch
            return;
        }

        //   synchronized(DummySHAPEExtension.class){                        
        //     if(kind==1){                                             
        //       window.ddxwindow.setShapeMask(op, kind, x, y, pixmap); 
        //        }                                                   
        //   }
        w = pixmap.width;
        h = pixmap.height;
        shaped = 1;
        sendShapeNotify(kind, window, x, y, w, h, shaped);
        break;
    case 3:
        int dk, sk;
        op = io.readByte();
        dk = io.readByte();
        sk = io.readByte();
        io.readPad(1);
        foo = io.readInt();
        c.length -= 3;
        XWindow dwindow = c.lookupWindow(foo);
        if (dwindow == null) {
            c.errorValue = foo;
            c.errorReason = 3; // BadWindow
            return;
        }
        x = (short) io.readShort();
        y = (short) io.readShort();
        foo = io.readInt();
        c.length -= 2;
        XWindow swindow = c.lookupWindow(foo);
        if (swindow == null) {
            c.errorValue = foo;
            c.errorReason = 3; // BadWindow
            return;
        }
        //   synchronized(DummySHAPEExtension.class){                
        //     dwindow.ddxwindow.setCombineMask(op, sk, dk, x, y, swindow); 
        //   }                                                  
        break;
    case 4:
        foo = io.readByte();
        io.readPad(3);
        foo = io.readInt();
        foo = io.readShort();
        foo = io.readShort();
        break;
    case 5:
        foo = io.readInt();
        c.length -= 2;
        window = c.lookupWindow(foo);
        if (window == null) {
            c.errorValue = foo;
            c.errorReason = 3; // BadWindow
            return;
        }
        synchronized (io) {
            io.writeByte(1);
            io.writePad(1);
            io.writeShort(c.seq);
            io.writeInt(0);
            io.writeByte(0); // bouding shaped
            io.writeByte(0); // clip shaped
            io.writePad(2);
            io.writeShort(-window.borderWidth); // bounding x
            io.writeShort(-window.borderWidth);
            io.writeShort(window.width + 2 * window.borderWidth);
            io.writeShort(window.height + 2 * window.borderWidth);
            io.writeShort(0); // clip x
            io.writeShort(0);
            io.writeShort(window.width);
            io.writeShort(window.height);
            io.writePad(4);
            io.flush();
        }
        break;
    case 6:
        foo = io.readInt();
        c.length -= 2;
        window = c.lookupWindow(foo);
        if (window == null) {
            c.errorValue = foo;
            c.errorReason = 3; // BadWindow
            return;
        }
        foo = io.readByte();
        io.readPad(3);
        c.length--;
        if (foo != 0 && foo != 1) {
            c.errorValue = foo;
            c.errorReason = 2; // BadWindow
            return;
        }

    {
        Head head = (Head) XResource.lookupIDByType(window.id, DummySHAPEExtension.etyp);
        if (foo == 1) {
            if (head != null) {
                for (ShapeEvent se = head.next; se != null; se = se.next) {
                    if (se.client == c) {
                        return;
                    }
                }
            }
            ShapeEvent se = new ShapeEvent(XResource.fakeClientId(c), DummySHAPEExtension.ctyp, c, window);
            XResource.add(se);
            if (head == null) {
                head = new Head(window.id, DummySHAPEExtension.etyp);
                XResource.add(head);
            } else {
                se.next = head.next;
            }
            head.next = se;
            return;
        }
        // foo==0
        if (head != null) {
            ShapeEvent nse = null;
            ShapeEvent se = null;
            for (se = head.next; se != null; se = se.next) {
                if (se.client == c)
                    break;
                nse = se;
            }
            if (se != null) {
                XResource.freeResource(se.id, DummySHAPEExtension.ctyp);
                if (nse != null) {
                    nse.next = se.next;
                } else {
                    head.next = se.next;
                }
            }
        }
    }
        break;
    case 7:
        foo = io.readInt();
        c.length -= 2;
        window = c.lookupWindow(foo);
        if (window == null) {
            c.errorValue = foo;
            c.errorReason = 3; // BadWindow
            return;
        }
        byte result = 0; {
        Head head = (Head) XResource.lookupIDByType(window.id, DummySHAPEExtension.etyp);
        if (head != null) {
            for (ShapeEvent se = head.next; se != null; se = se.next) {
                if (se.client == c) {
                    result = 1;
                    break;
                }
            }
        }
    }

        synchronized (io) {
            io.writeByte(1);
            io.writeByte(result);
            io.writeShort(c.seq);
            io.writeInt(0);
            io.writePad(24);
            io.flush();
        }
        break;
    case 8:
        foo = io.readInt();
        c.length -= 2;
        window = c.lookupWindow(foo);
        if (window == null) {
            c.errorValue = foo;
            c.errorReason = 3; // BadWindow
            return;
        }

        kind = io.readByte();
        io.readPad(3);

        synchronized (io) {
            io.writeByte(1);
            io.writeByte(0);
            io.writeShort(c.seq);
            io.writeInt(2 * 1);
            io.writeInt(1);
            io.writePad(20);
            io.writeShort(0);
            io.writeShort(0);
            io.writeShort(window.width);
            io.writeShort(window.height);
            io.flush();
        }
        break;
    default:
        LOG.error("Shape: unknown code=" + c.data);
    }
}

From source file:edu.umd.cfar.lamp.viper.geometry.BoundingBox.java

/**
 * Creates a bounding box in double coordinates. Just casts the parameters
 * to ints, for now.//from   www.ja va 2 s. c o m
 * 
 * @param leftEdge
 *            the left edge
 * @param bottomEdge
 *            the bottom edge (top in screen coordinates)
 * @param width
 *            the width of the box
 * @param height
 *            the height of the box
 */
public BoundingBox(double leftEdge, double bottomEdge, double width, double height) {
    rect = new Rectangle((int) leftEdge, (int) bottomEdge, (int) Math.ceil(width), (int) Math.ceil(height));
}

From source file:ca.ubc.cs.ferret.cg.VertexLabelAsShapeRenderer.java

public Shape transform(V v) {
    Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(),
            rc.getVertexLabelTransformer().transform(v), rc.getPickedVertexState().isPicked(v), v);
    Dimension size = component.getPreferredSize();
    Rectangle bounds = new Rectangle(-size.width / 2 - 2, -size.height / 2 - 4, size.width + 4,
            size.height + 6);//  w  ww.  ja v  a 2  s.c  o m
    return bounds;
    //      Shape shape = shapes.get(v);
    //      if(shape == null) {
    //         return new Rectangle(-20,-20,40,40);
    //      }
    //      else return shape;
}

From source file:Main.java

@Override
protected void processMouseEvent(MouseEvent e, JLayer<? extends JTabbedPane> l) {
    if (e.getID() != MouseEvent.MOUSE_CLICKED) {
        return;/*from   w  ww  . j  a v  a  2 s  . c  om*/
    }
    pt.setLocation(e.getPoint());
    JTabbedPane tabbedPane = (JTabbedPane) l.getView();
    int index = tabbedPane.indexAtLocation(pt.x, pt.y);
    if (index >= 0) {
        Rectangle rect = tabbedPane.getBoundsAt(index);
        Dimension d = button.getPreferredSize();
        int x = rect.x + rect.width - d.width - 2;
        int y = rect.y + (rect.height - d.height) / 2;
        Rectangle r = new Rectangle(x, y, d.width, d.height);
        if (r.contains(pt)) {
            tabbedPane.removeTabAt(index);
        }
    }
    l.getView().repaint();
}

From source file:TexturedText.java

/** Construct the object */
public TexturedText() {
    super();//from  w w w  . ja  v a2  s . c o  m
    setBackground(Color.white);
    int width = 8, height = 8;
    bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = bim.createGraphics();
    for (int i = 0; i < width; i++) {
        g2.setPaint(colors[(i / 2) % colors.length]);
        g2.drawLine(0, i, i, 0);
        g2.drawLine(width - i, height, width, height - i);
    }
    Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight());
    tp = new TexturePaint(bim, r);
}

From source file:D20140128.ApacheXMLGraphicsTest.TilingPatternExample.java

private void paintShapes(Graphics2D g2d) {
    g2d.setPaint(paint);//w  ww. j a v  a  2 s . co  m
    Rectangle rect = new Rectangle(10, 50, 30, 30);
    g2d.fill(rect);
    rect = new Rectangle(10, 90, 40, 20);
    g2d.fill(rect);
    Polygon poly = new Polygon(new int[] { 50, 100, 150 }, new int[] { 100, 20, 100 }, 3);
    g2d.fill(poly);
}

From source file:ANNFileDetect.GraphingClass.java

public JFreeChart RenderFiles(TreeMap finalMap) {
    XYSeriesCollection ds = new XYSeriesCollection();
    Iterator entries = finalMap.entrySet().iterator();
    while (entries.hasNext()) {
        Entry thisentry = (Entry) entries.next();

        String key = (String) thisentry.getKey();
        TreeMap<Double, Integer> tm = (TreeMap) thisentry.getValue();
        XYSeries series = new XYSeries(key);
        //HashMap<Double, Integer> tmp = finalMap.get(key);
        for (Map.Entry<Double, Integer> entry : tm.entrySet()) {
            //ds.addValue(ht.get(tmp), "Times", tmp); 
            series.add(entry.getKey(), entry.getValue());
        }//from  w w w. j  a v a 2s  .  c o m
        ds.addSeries(series);
    }
    JFreeChart chart = ChartFactory.createXYLineChart("Test graph", "Value", "Times", ds,
            PlotOrientation.VERTICAL, true, true, false);

    XYLineAndShapeRenderer rend = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
    rend.setBaseShape(new Rectangle(-2, -2, 4, 4));
    rend.setBaseShapesVisible(true);
    rend.setBaseSeriesVisible(true);
    //rend.setSeriesVisible(i, true);
    chart.getXYPlot().setRenderer(rend);
    return chart;
}