Example usage for java.awt.event MouseEvent translatePoint

List of usage examples for java.awt.event MouseEvent translatePoint

Introduction

In this page you can find the example usage for java.awt.event MouseEvent translatePoint.

Prototype

public synchronized void translatePoint(int x, int y) 

Source Link

Document

Translates the event's coordinates to a new position by adding specified x (horizontal) and y (vertical) offsets.

Usage

From source file:Main.java

public Main() {
    setLayout(null);//from   www .  j  a  v  a 2s  . c om
    add(button);
    button.setSize(button.getPreferredSize());
    button.setLocation(20, 20);
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            System.out.println(event.getPoint());
            event.translatePoint(20, 20);
            System.out.println(event.getPoint());
        }
    });
}

From source file:grafix.telas.MolduraAreaDados.java

protected void descartarEvento(final java.awt.event.MouseEvent evt) {
    Rectangle2D areaDados = getAreaData();
    evt.translatePoint(arred(areaDados.getX()), arred(areaDados.getY()));
    //        this.getPanelMolduras().dispatchEvent(evt);
    Controle.getJanelaAtiva().getPanelGraficos().dispatchEvent(evt); // Em teste
}

From source file:de.dakror.villagedefense.game.entity.struct.Struct.java

@Override
public void mouseReleased(MouseEvent e) {
    if (guiPoint != null && guiSize != null)
        e.translatePoint(-(guiPoint.x - guiSize.width / 2), -(guiPoint.y - guiSize.height / 2));

    for (Component c : components)
        c.mouseReleased(e);//from ww w .j ava  2 s  .  co  m

    if (guiPoint != null && guiSize != null)
        e.translatePoint(guiPoint.x - guiSize.width / 2, guiPoint.y - guiSize.height / 2);
}

From source file:de.dakror.villagedefense.game.entity.struct.Struct.java

@Override
public boolean mouseMoved(MouseEvent e) {
    if (guiPoint != null && guiSize != null)
        e.translatePoint(-(guiPoint.x - guiSize.width / 2), -(guiPoint.y - guiSize.height / 2));

    for (Component c : components)
        c.mouseMoved(e);//from ww  w  .j  a  v a  2  s  .c  o  m

    if (guiPoint != null && guiSize != null)
        e.translatePoint(guiPoint.x - guiSize.width / 2, guiPoint.y - guiSize.height / 2);

    return super.mouseMoved(e);
}

From source file:de.dakror.villagedefense.game.entity.struct.Struct.java

@Override
public boolean mousePressed(MouseEvent e) {
    if (guiPoint != null && guiSize != null)
        e.translatePoint(-(guiPoint.x - guiSize.width / 2), -(guiPoint.y - guiSize.height / 2));

    for (Component c : components)
        c.mousePressed(e);/*  w w  w  .  j  a v a  2  s.  com*/

    if (guiPoint != null && guiSize != null)
        e.translatePoint(guiPoint.x - guiSize.width / 2, guiPoint.y - guiSize.height / 2);

    boolean pressed = super.mousePressed(e);

    if (pressed && guiPoint == null && guiSize != null) {
        guiPoint = e.getPoint();
        guiPoint.translate(Game.world.x, Game.world.y);
        if (guiPoint.x - guiSize.width / 2 < 0)
            guiPoint.x = guiSize.width / 2;
        if (guiPoint.y - guiSize.height / 2 < 0)
            guiPoint.y = guiSize.height / 2;
        if (guiPoint.x + guiSize.width / 2 > Game.getWidth())
            guiPoint.x = Game.getWidth() - guiSize.width / 2;
        if (guiPoint.y + guiSize.height / 2 > Game.getHeight())
            guiPoint.y = Game.getHeight() - guiSize.height / 2;
    } else {
        if (guiPoint != null && guiSize != null && !new Rectangle(guiPoint.x - guiSize.width / 2,
                guiPoint.y - guiSize.height / 2, guiSize.width, guiSize.height).contains(e.getPoint())) {
            destroyGUI();
        }
    }

    return pressed;
}