use of java.awt.AWTEvent in project ffx by mjschnie.
the class MouseZoom method processStimulus.
/**
* {@inheritDoc}
*/
public void processStimulus(Enumeration criteria) {
AWTEvent[] event;
boolean done = false;
while (criteria.hasMoreElements()) {
WakeupCriterion wakeup = (WakeupCriterion) criteria.nextElement();
if (wakeup instanceof WakeupOnAWTEvent) {
event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
for (int i = 0; i < event.length; i++) {
processMouseEvent((MouseEvent) event[i]);
int id = event[i].getID();
MouseEvent mevent = (MouseEvent) event[i];
int mod = mevent.getModifiersEx();
boolean middleButton = ((mod & mouseButton) == mouseButton);
if (!middleButton) {
middleButton = ((mod & MouseEvent.ALT_DOWN_MASK) == MouseEvent.ALT_DOWN_MASK);
}
if ((id == MouseEvent.MOUSE_DRAGGED) && middleButton) {
y = ((MouseEvent) event[i]).getY();
int dy = y - y_last;
if (!reset) {
transformGroup.getTransform(currXform);
double z = (-1.0) * dy * z_factor;
double scale = currXform.getScale() + z;
if (scale > 0) {
currXform.setScale(scale);
transformGroup.setTransform(currXform);
transformChanged(currXform);
}
if (callback != null) {
callback.transformChanged(MouseBehaviorCallback.ZOOM, currXform);
}
} else {
reset = false;
}
x_last = x;
y_last = y;
}
if (id == MouseEvent.MOUSE_PRESSED) {
x_last = ((MouseEvent) event[i]).getX();
y_last = ((MouseEvent) event[i]).getY();
} else if (id == MouseEvent.MOUSE_RELEASED) {
done = true;
}
}
}
}
if (!done) {
wakeupOn(mouseCriterion);
} else {
reset = true;
mouseButton = MouseEvent.BUTTON2_DOWN_MASK;
postId(doneID);
wakeupOn(postCriterion);
}
}
use of java.awt.AWTEvent in project ffx by mjschnie.
the class MouseOrbit method processStimulus.
/**
* {@inheritDoc}
*/
public void processStimulus(Enumeration criteria) {
WakeupCriterion wakeup;
AWTEvent[] event;
int id;
int dx, dy;
while (criteria.hasMoreElements()) {
wakeup = (WakeupCriterion) criteria.nextElement();
if (wakeup instanceof WakeupOnAWTEvent) {
event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
for (int i = 0; i < event.length; i++) {
processMouseEvent((MouseEvent) event[i]);
if (((buttonPress) && ((flags & MANUAL_WAKEUP) == 0)) || ((wakeUp) && ((flags & MANUAL_WAKEUP) != 0))) {
id = event[i].getID();
if ((id == MouseEvent.MOUSE_DRAGGED)) {
x = ((MouseEvent) event[i]).getX();
y = ((MouseEvent) event[i]).getY();
dx = x - x_last;
dy = y - y_last;
if (!reset) {
Transform3D tempT3D = new Transform3D();
Transform3D orbitT3D = new Transform3D();
tempT3D.rotX(-dy * y_factor);
orbitT3D.mul(tempT3D);
tempT3D.rotY(-dx * x_factor);
orbitT3D.mul(tempT3D);
Transform3D tg_ghost_T3D = new Transform3D();
tg_ghost.getTransform(tg_ghost_T3D);
Vector3f tg_ghost_vec3f = new Vector3f();
tg_ghost_T3D.get(tg_ghost_vec3f);
Matrix4d tg_ghost_mat4d = new Matrix4d();
tg_ghost_T3D.get(tg_ghost_mat4d);
Transform3D VPTG_ghost_T3D_inverted = new Transform3D();
Transform3D VPTG_ghost_T3D_noninverted = new Transform3D();
// (super.ViewerTG).getTransform(VPTG_ghost_T3D_inverted);
ViewerTG.getTransform(VPTG_ghost_T3D_inverted);
// (super.ViewerTG).getTransform(VPTG_ghost_T3D_noninverted);
ViewerTG.getTransform(VPTG_ghost_T3D_noninverted);
VPTG_ghost_T3D_inverted.setTranslation(new Vector3d(0.0, 0.0, 0.0));
VPTG_ghost_T3D_noninverted.setTranslation(new Vector3d(0.0, 0.0, 0.0));
VPTG_ghost_T3D_inverted.invert();
tg_ghost_T3D.mul(VPTG_ghost_T3D_inverted, tg_ghost_T3D);
tg_ghost_T3D.setTranslation(new Vector3d(0.0, 0.0, 0.0));
if (invert) {
tg_ghost_T3D.mul(tg_ghost_T3D, orbitT3D);
} else {
tg_ghost_T3D.mul(orbitT3D, tg_ghost_T3D);
}
tg_ghost_T3D.mul(VPTG_ghost_T3D_noninverted, tg_ghost_T3D);
tg_ghost_T3D.setTranslation(tg_ghost_vec3f);
tg_ghost.setTransform(tg_ghost_T3D);
VPTG_ghost_T3D = new Transform3D();
// (super.ViewerTG).getTransform(VPTG_ghost_T3D);
ViewerTG.getTransform(VPTG_ghost_T3D);
Vector3f VPTG_ghost_vec3f = new Vector3f();
VPTG_ghost_T3D.get(VPTG_ghost_vec3f);
Vector3f temp_vec3f = new Vector3f();
temp_vec3f.x = VPTG_ghost_vec3f.x - tg_ghost_vec3f.x;
temp_vec3f.y = VPTG_ghost_vec3f.y - tg_ghost_vec3f.y;
temp_vec3f.z = VPTG_ghost_vec3f.z - tg_ghost_vec3f.z;
VPTG_ghost_T3D.setTranslation(temp_vec3f);
VPTG_ghost_T3D.mul(VPTG_ghost_T3D_inverted, VPTG_ghost_T3D);
if (invert) {
VPTG_ghost_T3D.mul(VPTG_ghost_T3D, orbitT3D);
} else {
VPTG_ghost_T3D.mul(orbitT3D, VPTG_ghost_T3D);
}
VPTG_ghost_T3D.mul(VPTG_ghost_T3D_noninverted, VPTG_ghost_T3D);
VPTG_ghost_T3D.get(temp_vec3f);
temp_vec3f.x = temp_vec3f.x + tg_ghost_vec3f.x;
temp_vec3f.y = temp_vec3f.y + tg_ghost_vec3f.y;
temp_vec3f.z = temp_vec3f.z + tg_ghost_vec3f.z;
VPTG_ghost_T3D.setTranslation(temp_vec3f);
// (super.ViewerTG).setTransform(VPTG_ghost_T3D);
ViewerTG.setTransform(VPTG_ghost_T3D);
transformChanged(currXform);
if (callback != null) {
callback.transformChanged(MouseBehaviorCallback.ORBIT, currXform);
}
} else {
reset = false;
}
x_last = x;
y_last = y;
} else if (id == MouseEvent.MOUSE_PRESSED) {
x_last = ((MouseEvent) event[i]).getX();
y_last = ((MouseEvent) event[i]).getY();
}
}
}
}
}
wakeupOn(mouseCriterion);
}
use of java.awt.AWTEvent in project ffx by mjschnie.
the class MouseTranslate method processStimulus.
/**
* {@inheritDoc}
*/
public void processStimulus(Enumeration criteria) {
while (criteria.hasMoreElements()) {
WakeupCriterion wakeup = (WakeupCriterion) criteria.nextElement();
if (wakeup instanceof WakeupOnAWTEvent) {
AWTEvent[] event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
for (int i = 0; i < event.length; i++) {
MouseEvent mevent = (MouseEvent) event[i];
processMouseEvent(mevent);
int id = event[i].getID();
int mod = mevent.getModifiersEx();
boolean rightButton = ((mod & mouseButton) == mouseButton);
if (!rightButton) {
rightButton = ((mod & MouseEvent.SHIFT_DOWN_MASK) == MouseEvent.SHIFT_DOWN_MASK);
}
if ((id == MouseEvent.MOUSE_DRAGGED) && rightButton && transformGroup != null) {
x = ((MouseEvent) event[i]).getX();
y = ((MouseEvent) event[i]).getY();
int dx = x - x_last;
int dy = y - y_last;
if ((!reset) && ((Math.abs(dy) < 50) && (Math.abs(dx) < 50))) {
transformGroup.getTransform(currXform);
Transform3D VPTG_T3D = new Transform3D();
ViewerTG.getTransform(VPTG_T3D);
VPTG_T3D.setTranslation(zero3d);
VPTG_T3D.invert();
currXform.mul(VPTG_T3D, currXform);
translation.x = dx * x_factor;
translation.y = -dy * y_factor;
transformX.set(translation);
if (invert) {
currXform.mul(currXform, transformX);
} else {
currXform.mul(transformX, currXform);
}
VPTG_T3D.invert();
currXform.mul(VPTG_T3D, currXform);
transformGroup.setTransform(currXform);
transformChanged(currXform);
if (callback != null) {
callback.transformChanged(MouseBehaviorCallback.TRANSLATE, currXform);
}
} else {
reset = false;
}
x_last = x;
y_last = y;
}
if (id == MouseEvent.MOUSE_PRESSED) {
x_last = ((MouseEvent) event[i]).getX();
y_last = ((MouseEvent) event[i]).getY();
} else if (id == MouseEvent.MOUSE_RELEASED) {
setTransformGroup(null);
}
}
}
}
if (transformGroup != null) {
wakeupOn(mouseCriterion);
} else {
mouseButton = MouseEvent.BUTTON3_DOWN_MASK;
postId(doneID);
wakeupOn(postCriterion);
}
}
use of java.awt.AWTEvent in project jmeter by apache.
the class TristateCheckBox method iterateState.
// Mostly delegates to model
@SuppressWarnings("deprecation")
private void iterateState() {
// Maybe do nothing at all?
if (!getModel().isEnabled()) {
return;
}
grabFocus();
// Iterate state
getTristateModel().iterateState();
// Fire ActionEvent
int modifiers = 0;
AWTEvent currentEvent = EventQueue.getCurrentEvent();
if (currentEvent instanceof InputEvent) {
modifiers = ((InputEvent) currentEvent).getModifiers();
} else if (currentEvent instanceof ActionEvent) {
modifiers = ((ActionEvent) currentEvent).getModifiers();
}
fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, getText(), System.currentTimeMillis(), modifiers));
}
use of java.awt.AWTEvent in project ats-framework by Axway.
the class SwingElementLocator method useComponentInspector.
/**
* Log the clicked element (its type, properties and index in the component hierarchy from the current container)
*
* @param driver {@link SwingDriverInternal} instance
*/
public static void useComponentInspector(final SwingDriverInternal driver) {
// long eventMask = AWTEvent.MOUSE_MOTION_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK;
long eventMask = AWTEvent.MOUSE_EVENT_MASK;
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent e) {
if (e.getID() == MouseEvent.MOUSE_PRESSED && e.getSource() instanceof Component) {
Component component = (Component) e.getSource();
Class<?> swingClass = findSwingClass(component.getClass());
if (swingClass == null) {
swingClass = component.getClass();
log.warn("Can't find swing class of type \"" + swingClass.getName() + "\"");
}
String logEntry = "\t[INSPECTOR] " + getProperties(component).replaceFirst("\\[", " [") + " index=" + calculateIndex(component, swingClass);
if (!component.getClass().getName().equals(swingClass.getName())) {
logEntry += "\t(extends " + swingClass.getName() + ")";
}
log.info(logEntry);
}
}
private String getProperties(Component c) {
String properties = Formatting.inEdtFormat(c);
if (c instanceof JButton) {
String tooltip = ((JButton) c).getToolTipText();
if (!StringUtils.isNullOrEmpty(tooltip)) {
int lastBrIndex = properties.lastIndexOf(']');
if (lastBrIndex > 0) {
properties = properties.substring(0, lastBrIndex) + ", tooltip='" + tooltip + "'" + properties.substring(lastBrIndex);
} else {
return c.getClass().getName() + " [tooltip='" + tooltip + "']";
}
}
}
return properties;
}
private Class<?> findSwingClass(Class<?> clazz) {
if (clazz == null) {
return null;
}
if (clazz.getName().startsWith("javax.swing")) {
return clazz;
}
return findSwingClass(clazz.getSuperclass());
}
@SuppressWarnings("unchecked")
private int calculateIndex(final Component component, Class<?> swingClass) {
ContainerFixture<?> containerFixture = driver.getActiveContainerFixture();
Robot robot;
if (containerFixture != null) {
// use the current robot instance
robot = containerFixture.robot;
} else {
robot = BasicRobot.robotWithCurrentAwtHierarchy();
}
List<Component> found = SwingElementFinder.find(robot.hierarchy(), ((containerFixture != null) ? containerFixture.component() : null), new GenericTypeMatcher<Component>((Class<Component>) swingClass, true) {
@Override
protected boolean isMatching(Component c) {
return true;
}
});
return found.indexOf(component);
}
}, eventMask);
}
Aggregations