use of java.awt.event.AWTEventListener in project intellij-community by JetBrains.
the class DarculaTest method main.
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(new DarculaLaf());
} catch (UnsupportedLookAndFeelException ignored) {
}
final JFrame frame = new JFrame("Darcula Demo");
frame.setSize(900, 500);
final DarculaTest form = new DarculaTest();
final JPanel root = form.myRoot;
frame.setContentPane(root);
frame.getRootPane().setDefaultButton(form.myDefaultButton);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
@Override
public void eventDispatched(AWTEvent event) {
if (event instanceof KeyEvent && event.getID() == KeyEvent.KEY_PRESSED && ((KeyEvent) event).getKeyCode() == KeyEvent.VK_F1) {
new ShowUIDefaultsAction().actionPerformed(null);
}
}
}, AWTEvent.KEY_EVENT_MASK);
SwingUtilities.invokeLater(() -> frame.setVisible(true));
}
use of java.awt.event.AWTEventListener in project intellij-community by JetBrains.
the class WindowSystemPlaybackCall method waitForDialog.
public static AsyncResult<String> waitForDialog(final PlaybackContext context, final String title) {
final AsyncResult<String> result = new AsyncResult<>();
final Ref<AWTEventListener> listener = new Ref<>();
listener.set(new AWTEventListener() {
@Override
public void eventDispatched(AWTEvent event) {
if (event.getID() == WindowEvent.WINDOW_ACTIVATED) {
final Window wnd = ((WindowEvent) event).getWindow();
if (wnd instanceof JDialog) {
if (title.equals(((JDialog) wnd).getTitle())) {
Toolkit.getDefaultToolkit().removeAWTEventListener(listener.get());
SwingUtilities.invokeLater(() -> getUiReady(context).notify(result));
}
}
}
}
});
Toolkit.getDefaultToolkit().addAWTEventListener(listener.get(), WindowEvent.WINDOW_EVENT_MASK);
SimpleTimer.getInstance().setUp(() -> {
Toolkit.getDefaultToolkit().removeAWTEventListener(listener.get());
if (!result.isProcessed()) {
result.setRejected("Timed out waiting for window: " + title);
}
}, Registry.intValue("actionSystem.commandProcessingTimeout"));
return result;
}
use of java.awt.event.AWTEventListener 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() + ")";
}
System.out.println(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 = null;
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);
}
use of java.awt.event.AWTEventListener in project intellij-community by JetBrains.
the class FocusTracesAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
final IdeFocusManager manager = IdeFocusManager.getGlobalInstance();
if (!(manager instanceof FocusManagerImpl))
return;
final FocusManagerImpl focusManager = (FocusManagerImpl) manager;
myActive = !myActive;
if (myActive) {
myFocusTracker = new AWTEventListener() {
@Override
public void eventDispatched(AWTEvent event) {
if (event instanceof FocusEvent && event.getID() == FocusEvent.FOCUS_GAINED) {
focusManager.recordFocusRequest(((FocusEvent) event).getComponent(), false);
}
}
};
Toolkit.getDefaultToolkit().addAWTEventListener(myFocusTracker, AWTEvent.FOCUS_EVENT_MASK);
}
if (!myActive) {
final List<FocusRequestInfo> requests = focusManager.getRequests();
new FocusTracesDialog(project, new ArrayList<>(requests)).show();
Toolkit.getDefaultToolkit().removeAWTEventListener(myFocusTracker);
myFocusTracker = null;
requests.clear();
}
}
use of java.awt.event.AWTEventListener in project intellij-plugins by JetBrains.
the class UserActivityMonitor method initComponent.
@Override
public void initComponent() {
if (ApplicationManager.getApplication().isUnitTestMode())
return;
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(e -> {
activity();
return false;
});
AWTEventListener listener = new AWTEventListener() {
@Override
public void eventDispatched(AWTEvent event) {
activity();
}
};
Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);
activity();
ProjectUtil.runWhenProjectOpened(project -> {
Thread t = new Thread(this, getComponentName() + " thread");
t.setDaemon(true);
t.start();
});
}
Aggregations