11 package com.google.scrollview.events;
18 import org.piccolo2d.PCamera;
19 import org.piccolo2d.PNode;
20 import org.piccolo2d.event.PBasicInputEventHandler;
21 import org.piccolo2d.event.PInputEvent;
22 import org.piccolo2d.nodes.PPath;
24 import java.awt.Color;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.KeyEvent;
28 import java.awt.event.KeyListener;
29 import java.awt.event.WindowEvent;
30 import java.awt.event.WindowListener;
32 import javax.swing.Timer;
43 ActionListener, KeyListener, WindowListener {
52 private int lastX = 0;
53 private int lastY = 0;
59 private int lastXMove = 0;
60 private int lastYMove = 0;
63 private int startX = 0;
64 private int startY = 0;
65 private float rubberBandTransparency = 0.5f;
66 private PNode selection = null;
72 private String keyStr =
"!";
76 timer =
new Timer(1000,
this);
84 private void processEvent(
SVEvent e) {
92 private void showPopup(PInputEvent e) {
93 double x = e.getCanvasPosition().getX();
94 double y = e.getCanvasPosition().getY();
105 if (e.isPopupTrigger()) {
109 .getPosition().getX(), (int) e.getPosition().getY(), 0, 0, null));
121 if (e.isPopupTrigger()) {
124 lastX = (int) e.getPosition().getX();
125 lastY = (int) e.getPosition().getY();
134 .getPosition().getX(), (int) e.getPosition().getY(), (int) e
135 .getPosition().getX()
136 - lastX, (int) e.getPosition().getY() - lastY, null));
139 if (selection == null) {
140 startX = (int) e.getPosition().getX();
141 startY = (int) e.getPosition().getY();
142 selection = PPath.createRectangle(startX, startY, 1, 1);
143 selection.setTransparency(rubberBandTransparency);
144 svWindow.
canvas.getLayer().addChild(selection);
146 int right = Math.max(startX, (
int) e.getPosition().getX());
147 int left = Math.min(startX, (
int) e.getPosition().getX());
148 int bottom = Math.max(startY, (
int) e.getPosition().getY());
149 int top = Math.min(startY, (
int) e.getPosition().getY());
150 svWindow.
canvas.getLayer().removeChild(selection);
151 selection = PPath.createRectangle(left, top, right - left, bottom - top);
152 selection.setPaint(Color.YELLOW);
153 selection.setTransparency(rubberBandTransparency);
154 svWindow.
canvas.getLayer().addChild(selection);
166 if (e.isPopupTrigger()) {
170 .getPosition().getX(), (int) e.getPosition().getY(), (int) e
171 .getPosition().getX()
172 - lastX, (int) e.getPosition().getY() - lastY, null));
174 if (selection != null) {
175 svWindow.
canvas.getLayer().removeChild(selection);
186 PCamera lc = svWindow.
canvas.getCamera();
189 if (e.getWheelRotation() < 0) {
192 lc.scaleViewAboutPoint(lc.getScale() / sf, e.getPosition().getX(), e
193 .getPosition().getY());
204 .getPosition().getX(), (int) e.getPosition().getY(), 0, 0, null));
229 lastYMove, 0, 0, null));
243 char keyCh = e.getKeyChar();
244 if (keyCh ==
'\r' || keyCh ==
'\n' || keyCh ==
'\0' || keyCh ==
'?') {
246 lastYMove, 0, 0, keyStr));
252 lastYMove, 0, 0, String.valueOf(keyCh)));
264 lastYMove, 0, 0, null));
265 e.getWindow().dispose();
269 lastYMove, 0, 0, null));
void mouseExited(PInputEvent e)
void mouseEntered(PInputEvent e)
void windowClosed(WindowEvent e)
SVEventHandler(SVWindow wdw)
void windowDeactivated(WindowEvent e)
void keyReleased(KeyEvent e)
void keyTyped(KeyEvent e)
void actionPerformed(ActionEvent e)
void mouseMoved(PInputEvent e)
void windowOpened(WindowEvent e)
void windowActivated(WindowEvent e)
void windowDeiconified(WindowEvent e)
void mouseDragged(PInputEvent e)
static void addMessage(SVEvent e)
static final double SCALING_FACTOR
void show(Component Invoker, int x, int y)
void mouseReleased(PInputEvent e)
void mouseWheelRotated(PInputEvent e)
void mousePressed(PInputEvent e)
void windowIconified(WindowEvent e)
void windowClosing(WindowEvent e)
void mouseClicked(PInputEvent e)
void keyPressed(KeyEvent e)