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:coolmap.canvas.action.PasteRowNodesAction.java

@Override
public void actionPerformed(ActionEvent e) {
    try {/*  w w  w .j  av a  2 s . c  om*/
        CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject();
        Transferable content = (Transferable) Toolkit.getDefaultToolkit().getSystemClipboard()
                .getContents(null);
        String data = (String) content.getTransferData(DataFlavor.stringFlavor);
        JSONObject json = new JSONObject(data);

        ArrayList<Range<Integer>> selectedRows = obj.getCoolMapView().getSelectedRows();
        //            System.out.println(selectedColumns);
        //if there are selections
        int insertionIndex = 0;
        if (selectedRows != null && !selectedRows.isEmpty()) {
            insertionIndex = selectedRows.get(0).lowerEndpoint();
            //System.out.println(lower);

        } //else
        else {
            //append at beginning

        }

        JSONArray terms = json.getJSONArray("Terms");
        String ontologyID = json.getString("OntologyID");

        COntology ontology = CoolMapMaster.getCOntologyByID(ontologyID);

        System.out.println("Ontology:" + ontology);

        if (ontology == null) {
            return;
        }

        ArrayList<VNode> newNodes = new ArrayList<VNode>();

        for (int i = 0; i < terms.length(); i++) {
            VNode node = new VNode(terms.getString(i), ontology);
            newNodes.add(node);
            System.out.println(node);
        }

        Rectangle centerTo = new Rectangle(0, insertionIndex, 1, 1);
        if (obj.getCoolMapView().getSelectedColumns() != null
                && !obj.getCoolMapView().getSelectedColumns().isEmpty()) {
            centerTo.x = ((Range<Integer>) (obj.getCoolMapView().getSelectedColumns().get(0))).lowerEndpoint();
        }

        CoolMapState state = CoolMapState.createStateRows("Insert Row Nodes", obj, null);
        obj.insertRowNodes(insertionIndex, newNodes, true);
        obj.getCoolMapView().centerToRegion(centerTo);
        StateStorageMaster.addState(state);

    } catch (Exception ex) {
        System.err.println("Exception in pasting rows:" + ex);
    }
}

From source file:SimpleDraw.java

public void mouseReleased(MouseEvent me) {
    x2 = me.getX();// www. j  av a2  s .  c o  m
    y2 = me.getY();
    Shape shape = null;
    if (shapeType.equals("Rectangle")) {
        // a Rectangle cannot have a zero width or height
        if (x1 != x2 || y1 != y2) {
            shape = new Rectangle(x1, y1, x2, y2);
        }
    }
    if (shape != null) {
        this.shapes.add(shape);
        this.repaint();
    }
}

From source file:de.dakror.villagedefense.game.entity.creature.Creature.java

public Creature(int x, int y, String img) {
    super(x, y, Game.getImage("creature/" + img + ".png").getWidth() / 4,
            Game.getImage("creature/" + img + ".png").getHeight() / 4);

    spawnPoint = new Point(x, y);

    image = Game.getImage("creature/" + img + ".png");

    setBump(new Rectangle((int) (width * 0.25f), (int) (height * 0.75f), (int) (width * 0.5f),
            (int) (height * 0.25f)));
    frozen = false;/*from w  ww . ja va  2s .c o m*/

    dir = 0;
    frame = 0;
}

From source file:org.osjava.reportrunner_plugins.renderers.jfreechart.creators.TexturedBarRenderer.java

public java.awt.Paint getSeriesPaint(int row) {
    BufferedImage bufferedImage = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB);
    Graphics2D big = bufferedImage.createGraphics();
    TexturePaint texture = null;//w w  w  .j ava  2s  .  c  o  m
    int rowNum = row + 1;
    int patNum = 13;
    int formula = rowNum - ((rowNum / patNum) * patNum);

    if (formula == 0) {
        big.setColor(Color.orange);
        big.fillRect(0, 0, 5, 5);
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);

    } else if (formula == 1) {
        big.setColor(Color.red);
        big.fillRect(0, 0, 5, 5);
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 2) {
        Color color = Color.blue;
        big.setColor(Color.white);
        big.fillRect(0, 0, 5, 5);
        big.setColor(color);
        big.fillRect(0, 1, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);

        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 3) {
        Color color = Color.yellow;
        big.setColor(Color.orange);
        big.fillRect(0, 0, 5, 5);
        big.setColor(color);
        big.fillRect(1, 1, 4, 4);
        Rectangle r = new Rectangle(0, 0, 5, 5);

        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 4) {
        big.setColor(Color.green);
        big.fillRect(0, 0, 5, 5);
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 5) {
        big.setColor(Color.magenta);
        big.fillRect(0, 0, 5, 5);
        big.setColor(Color.pink);
        big.fillRect(0, 0, 4, 4);

        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 6) {
        float[] x = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f };
        float[] y = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f };
        GeneralPath path = new GeneralPath();
        path.moveTo(x[0], y[0]);
        for (int j = 1; j < x.length; j++) {
            path.lineTo(x[j], y[j]);
        }

        big.setColor(new Color(226, 199, 252));
        big.fillRect(0, 0, 5, 5);
        big.setColor(Color.blue);
        big.setStroke(new BasicStroke(1.0f));

        big.draw(path);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 7) {
        big.setColor(Color.lightGray);
        big.fillRect(0, 0, 5, 5);
        big.setColor(Color.red);
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 8) {
        float[] x = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f };
        float[] y = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f };
        GeneralPath path = new GeneralPath();
        path.moveTo(x[0], y[0]);
        for (int j = 1; j < x.length; j++) {
            path.lineTo(x[j], y[j]);

        }
        big.setColor(Color.blue);
        big.fillRect(0, 0, 5, 5);
        big.setColor(Color.cyan);
        big.setStroke(new BasicStroke(2.0f));
        big.draw(path);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 9) {
        Color color = new Color(0xBBBBDD);
        big.setColor(color);
        big.fillRect(0, 0, 5, 5);
        big.setColor(new Color(199, 201, 230));
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 10) {
        float[] x = { 1, 2, 3, 4, 5 };
        float[] y = { 1, 2, 3, 4, 5 };
        GeneralPath path = new GeneralPath();
        path.moveTo(x[0], y[1]);
        path.lineTo(x[1], y[0]);
        path.moveTo(x[0], y[2]);
        path.lineTo(x[2], y[0]);
        path.moveTo(x[0], y[3]);
        path.lineTo(x[3], y[0]);
        path.moveTo(x[0], y[4]);
        path.lineTo(x[4], y[0]);
        big.setColor(Color.red);
        big.fillRect(0, 0, 5, 5);
        big.setColor(new Color(242, 242, 193));
        big.setStroke(new BasicStroke(3.0f));
        big.draw(path);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 11) {
        big.setColor(new Color(252, 169, 171));
        big.fillOval(0, 0, 5, 6);
        big.setColor(new Color(252, 230, 230));
        big.fillOval(0, 0, 3, 3);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 12) {
        big.setColor(Color.green);
        big.fillRect(0, 0, 5, 5);
        big.setColor(new Color(20, 178, 38));
        big.fillRect(2, 2, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    }
    return texture;

}

From source file:com.adito.navigation.forms.FileDownloadForm.java

/**
 * Get the link show the temporary download directory for the current session/ 
 * /*w w  w .  j ava2s .  c  o m*/
 * @param request request
 * @return String
 */
public String getTempDownloadLink(HttpServletRequest request) {
    SessionInfo session = LogonControllerFactory.getInstance().getSessionInfo(request);
    WindowOpenJavascriptLink windowOpenJavascriptLink = new WindowOpenJavascriptLink(
            "fileSystem.do?actionTarget=list&path=" + Util.urlEncode(
                    "temp/" + session.getUser().getPrincipalName() + "." + session.getHttpSession().getId())
                    + "&resourceId=0",
            "vfs_" + "0" + "_" + System.currentTimeMillis(), new Rectangle(20, 20, WINDOW_WIDTH, WINDOW_HEIGHT),
            true, false, false, true, false);
    return "javascript: " + windowOpenJavascriptLink.toJavascript();
}

From source file:ClipArea.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    int w = getSize().width;
    int h = getSize().height;

    if (clip) {/* ww  w  .j  a  va 2s  .c  o  m*/
        Ellipse2D e = new Ellipse2D.Float(w / 4.0f, h / 4.0f, w / 2.0f, h / 2.0f);
        g2.setClip(e);

        g2.setColor(Color.yellow);
        g2.fillRect(0, 0, w, h);
    }

    if (clipFurther) {
        Rectangle r = new Rectangle(w / 2, h / 2, w / 2, h / 2);
        g2.clip(r);

        g2.setColor(Color.green);
        g2.fillRect(0, 0, w, h);
    }
}

From source file:coolmap.canvas.action.PasteColumnNodesAction.java

@Override
public void actionPerformed(ActionEvent e) {
    try {/*from   w  w w .j  av a2  s .c  o m*/
        CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject();
        Transferable content = (Transferable) Toolkit.getDefaultToolkit().getSystemClipboard()
                .getContents(null);
        String data = (String) content.getTransferData(DataFlavor.stringFlavor);
        JSONObject json = new JSONObject(data);

        System.out.println(json);

        //System.out.println(((JMenuItem)(e.getSource())).getParent());
        ArrayList<Range<Integer>> selectedColumns = obj.getCoolMapView().getSelectedColumns();
        //            System.out.println(selectedColumns);
        //if there are selections
        int insertionIndex = 0;
        if (selectedColumns != null && !selectedColumns.isEmpty()) {
            insertionIndex = selectedColumns.get(0).lowerEndpoint();

        } //else

        System.out.println(insertionIndex);

        JSONArray terms = json.getJSONArray("Terms");
        String ontologyID = json.getString("OntologyID");

        COntology ontology = CoolMapMaster.getCOntologyByID(ontologyID);

        System.out.println("Ontology:" + ontology);

        if (ontology == null) {
            return;
        }

        ArrayList<VNode> newNodes = new ArrayList<VNode>();

        for (int i = 0; i < terms.length(); i++) {
            VNode node = new VNode(terms.getString(i), ontology);
            newNodes.add(node);
            System.out.println(node);
        }

        Rectangle centerTo = new Rectangle(insertionIndex, 0, 1, 1);
        if (obj.getCoolMapView().getSelectedRows() != null
                && !obj.getCoolMapView().getSelectedRows().isEmpty()) {
            centerTo.y = ((Range<Integer>) (obj.getCoolMapView().getSelectedRows().get(0))).lowerEndpoint();
        }

        CoolMapState state = CoolMapState.createStateColumns("Insert Column Nodes", obj, null);
        obj.insertColumnNodes(insertionIndex, newNodes, true);
        //need to center to inserted
        obj.getCoolMapView().centerToRegion(centerTo);

        StateStorageMaster.addState(state);

    } catch (Exception ex) {
        //Return
        System.err.println("Exception in pasting columns:" + ex);
    }
}

From source file:components.ScrollablePicture.java

public void mouseDragged(MouseEvent e) {
    //The user is dragging us, so scroll!
    Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1);
    scrollRectToVisible(r);/*from   w w w.jav a  2 s  . co  m*/
}

From source file:amicity.graph.pc.gui.JungGraphViewer.java

public JungGraphViewer(JungGraph aGraph) {
    this.graph = aGraph;

    this.setLayout(new BorderLayout());
    layout = new StaticLayout<Node, Edge>(graph);
    vv = new VisualizationViewer<Node, Edge>(layout);

    vv.setBackground(Color.white);

    vv.getRenderContext().setVertexLabelTransformer(new NodeTransformer());
    vv.getRenderContext().setEdgeLabelTransformer(new EdgeTransformer());
    vv.getRenderContext().setVertexStrokeTransformer(new NodeStrokeTransformer(vv));
    vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.YELLOW));
    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);

    Transformer<Node, Shape> vertexSize = new Transformer<Node, Shape>() {
        public Shape transform(Node i) {
            int length = i.getLabel().length() * 10;
            length = length > 30 ? length : 30;
            return new Rectangle(-20, -10, length, 30);
        }//  w  w w.j  a v  a 2s .c o m
    };
    vv.getRenderContext().setVertexShapeTransformer(vertexSize);

    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    panel.setPreferredSize(new Dimension(400, 400));
    add(panel, BorderLayout.CENTER);
}

From source file:GraphPaperTest.java

public GraphPaperTest() {
    setLayout(new GraphPaperLayout(new Dimension(5, 5)));

    // Add a 1x1 Rect at (0,0)
    add(new JButton("1"), new Rectangle(0, 0, 1, 1));

    // Add a 2x1 Rect at (2,0)
    add(new JButton("2"), new Rectangle(2, 0, 2, 1));

    // Add a 1x2 Rect at (1,1)
    add(new JButton("3"), new Rectangle(1, 1, 1, 2));

    // Add a 2x2 Rect at (3,2)
    add(new JButton("4"), new Rectangle(3, 2, 2, 2));

    // Add a 1x1 Rect at (0,4)
    add(new JButton("5"), new Rectangle(0, 4, 1, 1));

    // Add a 1x2 Rect at (2,3)
    add(new JButton("6"), new Rectangle(2, 3, 1, 2));
}