Example usage for java.awt Point Point

List of usage examples for java.awt Point Point

Introduction

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

Prototype

public Point(int x, int y) 

Source Link

Document

Constructs and initializes a point at the specified (x,y) location in the coordinate space.

Usage

From source file:ded.model.SerializationTests.java

public void test1() throws Exception {
    // Build a simple diagram.
    Diagram d = new Diagram();
    d.windowSize = new Dimension(1000, 2000);

    Entity e1 = new Entity();
    e1.loc = new Point(5, 10);
    e1.size = new Dimension(30, 40);
    e1.shape = EntityShape.ES_ELLIPSE;//from  w  ww. j  a v  a 2  s . co m
    e1.name = "e1";
    e1.attributes = "attr1\nattr2\nattr3";
    d.entities.add(e1);

    Entity e2 = new Entity();
    e2.loc = new Point(15, 20);
    e2.size = new Dimension(130, 140);
    e2.shape = EntityShape.ES_NO_SHAPE;
    e2.name = "e2";
    e2.attributes = "funny\"characters\\in\'this,string!";
    d.entities.add(e2);

    // Relation from e1 to e2 with two control points.
    Relation r1 = new Relation(new RelationEndpoint(e1), new RelationEndpoint(e2));
    r1.controlPts.add(new Point(71, 72));
    r1.controlPts.add(new Point(73, 74));
    r1.routingAlg = RoutingAlgorithm.RA_DIRECT;
    r1.label = "r1";
    r1.end.arrowStyle = ArrowStyle.AS_FILLED_TRIANGLE;
    r1.start.arrowStyle = ArrowStyle.AS_DOUBLE_ANGLE;
    d.relations.add(r1);

    // Relation between two points.
    Relation r2 = new Relation(new RelationEndpoint(new Point(81, 82)),
            new RelationEndpoint(new Point(83, 84)));
    d.relations.add(r2);

    // Make e2 inherit from e1.
    Inheritance i1 = new Inheritance(e1, true /*open*/, new Point(31, 32));
    d.inheritances.add(i1);
    Relation r3 = new Relation(new RelationEndpoint(e2), new RelationEndpoint(i1));
    r3.routingAlg = RoutingAlgorithm.RA_MANHATTAN_VERT;
    d.relations.add(r3);

    // Make sure it is all consistent.
    d.selfCheck();

    // Serialize it.
    String serialized = d.toJSON().toString(2);
    System.out.println(serialized);

    // Parse it.
    JSONObject o = new JSONObject(new JSONTokener(serialized));
    Diagram d2 = new Diagram(o);
    d2.selfCheck();

    // Check for structural equality.
    assert (d2.equals(d));

    // Serialize and check that for equality too.
    String ser2 = d2.toJSON().toString(2);
    assert (ser2.equals(serialized));
}

From source file:MainClass.java

public void paint(Graphics g) {
    if (layouts == null)
        getLayouts(g);/*from  ww  w .j  a  va  2 s . c om*/

    Point pen = new Point(0, 0);
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(java.awt.Color.black); // or a property
    g2d.setFont(font);

    Iterator it = layouts.iterator();
    while (it.hasNext()) {
        TextLayout layout = (TextLayout) it.next();
        pen.y += (layout.getAscent());
        g2d.setFont(font);
        layout.draw(g2d, pen.x, pen.y);
        pen.y += layout.getDescent();
    }
}

From source file:laystream.SimpleGraphView.java

/**
 * Creates a new instance of SimpleGraphView
 */// w  ww . jav a 2s  . c om
public SimpleGraphView() {
    g = new DirectedSparseMultigraph<>();
    vertexFactory = new Factory<LayNode>() {

        @Override
        public LayNode create() {
            return new LayNode("asd", new Point(rnd.nextInt(90), rnd.nextInt(90)));
        }
    };
    edgeFactory = new Factory<LayEdge>() {
        @Override
        public LayEdge create() {
            return new LayEdge("asd", 10);
        }
    };
    for (int i = 0; i < Util.NUMBE_OF_NODES; i++) {
        g.addVertex(new LayNode("" + i, new Point(rnd.nextInt(90), rnd.nextInt(90))));
    }
}

From source file:Main.java

public static void swingDispatch(MouseEvent e, Point point, final Component component) {
    synchronized (component.getTreeLock()) {
        if (component instanceof Container) {
            Container container = (Container) component;
            for (int i = container.getComponentCount(); i-- != 0;) {
                Component child = container.getComponent(i);
                Rectangle r = child.getBounds();
                if (r.contains(point)) {
                    swingDispatch(e, new Point(point.x - r.x, point.y - r.y), child);
                    return;
                }//  w  w w .  j a  va  2 s  .  c o m
            }
        }
    }
    final MouseEvent adapted = convertMouseEvent(e, component, point);
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            component.dispatchEvent(adapted);
        }
    });
}

From source file:Main.java

/**
 * Create a custom cursor out of the specified image, with the specified hotspot.
 *///from   w ww . ja v a  2 s. c om
public static Cursor createImageCursor(Image img, Point hotspot) {
    Toolkit tk = Toolkit.getDefaultToolkit();

    // for now, just report the cursor restrictions, then blindly create
    int w = img.getWidth(null);
    int h = img.getHeight(null);
    Dimension d = tk.getBestCursorSize(w, h);
    //         int colors = tk.getMaximumCursorColors();
    //         Log.debug("Creating custom cursor [desiredSize=" + w + "x" + h +
    //                   ", bestSize=" + d.width + "x" + d.height +
    //                   ", maxcolors=" + colors + "].");

    // if the passed-in image is smaller, pad it with transparent pixels and use it anyway.
    if (((w < d.width) && (h <= d.height)) || ((w <= d.width) && (h < d.height))) {
        Image padder = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                .getDefaultConfiguration().createCompatibleImage(d.width, d.height, Transparency.BITMASK);
        Graphics g = padder.getGraphics();
        g.drawImage(img, 0, 0, null);
        g.dispose();

        // and reassign the image to the padded image
        img = padder;

        // and adjust the 'best' to cheat the hotspot checking code
        d.width = w;
        d.height = h;
    }

    // make sure the hotspot is valid
    if (hotspot == null) {
        hotspot = new Point(d.width / 2, d.height / 2);
    } else {
        hotspot.x = Math.min(d.width - 1, Math.max(0, hotspot.x));
        hotspot.y = Math.min(d.height - 1, Math.max(0, hotspot.y));
    }

    // and create the cursor
    return tk.createCustomCursor(img, hotspot, "samskivertDnDCursor");
}

From source file:Main.java

public Main() {
    DefaultListModel<String> model = new DefaultListModel<>();
    model.addElement("one");
    model.addElement("two");
    model.addElement("three");
    model.addElement("four");
    model.addElement("five");
    model.addElement("six");
    model.addElement("seven");
    model.addElement("eight");
    model.addElement("nine");
    model.addElement("ten");

    JList<String> list = new JList(model) {
        public String getToolTipText(MouseEvent e) {
            int row = locationToIndex(e.getPoint());
            Object o = getModel().getElementAt(row);
            return o.toString();
        }//from w ww . j ava  2 s . co m

        public Point getToolTipLocation(MouseEvent e) {
            int row = locationToIndex(e.getPoint());
            Rectangle r = getCellBounds(row, row);
            return new Point(r.width, r.y);
        }
    };

    JScrollPane scrollPane = new JScrollPane(list);
    getContentPane().add(scrollPane);
}

From source file:Main.java

private void shakeButton() {
    final Point point = button.getLocation();
    final int delay = 75;
    Runnable r = new Runnable() {
        @Override/*from ww w . ja v  a 2  s. c  o  m*/
        public void run() {
            for (int i = 0; i < 30; i++) {
                try {

                    moveButton(new Point(point.x + 5, point.y));
                    Thread.sleep(delay);
                    moveButton(point);
                    Thread.sleep(delay);
                    moveButton(new Point(point.x - 5, point.y));
                    Thread.sleep(delay);
                    moveButton(point);
                    Thread.sleep(delay);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }
    };
    Thread t = new Thread(r);
    t.start();
}

From source file:SparseTableModel.java

public void setValueAt(Object value, int row, int column) {
    if ((rows < 0) || (columns < 0)) {
        throw new IllegalArgumentException("Invalid row/column setting");
    }/*from www  . j  a v a  2 s  .  c o  m*/
    if ((row < rows) && (column < columns)) {
        lookup.put(new Point(row, column), value);
    }
}

From source file:Main.java

private void addComponents() {
    JEditorPane editorPane = new JEditorPane();
    editorPane.setContentType("text/html");
    editorPane.setEditable(false);/*w ww .j  a v a 2  s  .  c  o m*/
    editorPane.setText(TEXT);

    JScrollPane scrollpane = new JScrollPane(editorPane);

    editorPane.addHyperlinkListener(e -> {
        if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
            String description = e.getDescription();
            if (TOP.equals(description)) {
                JViewport viewport = scrollpane.getViewport();
                viewport.setViewPosition(new Point(0, 0));
            }
        }
    });
    super.add(scrollpane);
}

From source file:net.sf.nmedit.jtheme.JTCursor.java

private static Cursor createCursor(int id) {
    Toolkit tk = Toolkit.getDefaultToolkit();
    URL res = getResource(id);/*ww w.  j a  v a2 s  .  co  m*/

    if (res == null) {
        Log log = LogFactory.getLog(JTCursor.class);
        if (log.isWarnEnabled()) {
            log.warn("Could not find cursor: id=" + id + ", url=" + res);
        }
        return Cursor.getDefaultCursor();
    }

    Image img;
    try {
        img = ImageIO.read(res);
    } catch (IOException e) {
        Log log = LogFactory.getLog(JTCursor.class);
        if (log.isWarnEnabled()) {
            log.warn("Could not find cursor: id=" + id + ", url=" + res, e);
        }
        return Cursor.getDefaultCursor();
    }

    return tk.createCustomCursor(img, new Point(4, 16), names[id]);
}