use of java.awt.event.MouseListener in project android by JetBrains.
the class ManifestPanel method createPopupMenu.
private void createPopupMenu() {
myPopup = new JBPopupMenu();
JMenuItem gotoItem = new JBMenuItem("Go to Declaration");
gotoItem.addActionListener(e -> {
TreePath treePath = myTree.getSelectionPath();
final ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
if (node != null) {
goToDeclaration(node.getUserObject());
}
});
myPopup.add(gotoItem);
myRemoveItem = new JBMenuItem("Remove");
myRemoveItem.addActionListener(e -> {
TreePath treePath = myTree.getSelectionPath();
final ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
new WriteCommandAction.Simple(myFacet.getModule().getProject(), "Removing manifest tag", ManifestUtils.getMainManifest(myFacet)) {
@Override
protected void run() throws Throwable {
ManifestUtils.toolsRemove(ManifestUtils.getMainManifest(myFacet), node.getUserObject());
}
}.execute();
});
myPopup.add(myRemoveItem);
MouseListener ml = new MouseAdapter() {
@Override
public void mousePressed(@NotNull MouseEvent e) {
if (e.isPopupTrigger()) {
handlePopup(e);
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
handlePopup(e);
}
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
TreePath treePath = myTree.getPathForLocation(e.getX(), e.getY());
if (treePath != null) {
ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
Node attribute = node.getUserObject();
if (attribute instanceof Attr) {
goToDeclaration(attribute);
}
}
}
}
private void handlePopup(@NotNull MouseEvent e) {
TreePath treePath = myTree.getPathForLocation(e.getX(), e.getY());
if (treePath == null || e.getSource() == myDetails) {
// Use selection instead
treePath = myTree.getSelectionPath();
}
if (treePath != null) {
ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
myRemoveItem.setEnabled(canRemove(node.getUserObject()));
myPopup.show(e.getComponent(), e.getX(), e.getY());
}
}
};
myTree.addMouseListener(ml);
myDetails.addMouseListener(ml);
}
use of java.awt.event.MouseListener in project android by JetBrains.
the class LayoutTestUtilities method clickMouse.
public static void clickMouse(InteractionManager manager, int button, int count, int x, int y, int modifiers) {
JComponent layeredPane = manager.getSurface().getLayeredPane();
for (int i = 0; i < count; i++) {
pressMouse(manager, button, x, y, modifiers);
releaseMouse(manager, button, x, y, modifiers);
Object listener = manager.getListener();
assertTrue(listener instanceof MouseListener);
MouseListener mouseListener = (MouseListener) listener;
MouseEvent event = new MouseEventBuilder(x, y).withSource(layeredPane).withButton(button).withMask(modifiers).withClickCount(i).build();
mouseListener.mouseClicked(event);
}
}
use of java.awt.event.MouseListener in project android by JetBrains.
the class PTableTest method fireMousePressed.
private void fireMousePressed(int row, int column, int xOffset) {
Rectangle bounds = myTable.getCellRect(row, column, false);
int x = bounds.x + xOffset;
int y = bounds.y + 5;
MouseEvent event = mock(MouseEvent.class);
when(event.getX()).thenReturn(x);
when(event.getY()).thenReturn(y);
when(event.getPoint()).thenReturn(new Point(x, y));
when(event.getComponent()).thenReturn(myTable);
for (MouseListener listener : myTable.getMouseListeners()) {
listener.mousePressed(event);
}
}
use of java.awt.event.MouseListener in project android by JetBrains.
the class ColorPickerTest method testColorWheelResizeAndSelect.
public void testColorWheelResizeAndSelect() {
ColorPicker.SaturationBrightnessComponent saturationBrightnessComponent = new ColorPicker.SaturationBrightnessComponent();
saturationBrightnessComponent.setSize(new Dimension(1010, 710));
saturationBrightnessComponent.setHue(0.75f);
saturationBrightnessComponent.setOpacity(100);
MouseEvent event = new MouseEvent(saturationBrightnessComponent, MouseEvent.MOUSE_CLICKED, 1, MouseEvent.BUTTON1, 805, 505, 1, false);
for (MouseListener mouseListener : saturationBrightnessComponent.getMouseListeners()) {
mouseListener.mousePressed(event);
}
Color expectedColor = ColorUtil.toAlpha(Color.getHSBColor(0.75f, 0.8f, 1.0f - 5.0f / 7.0f), 100);
assertEquals(expectedColor, saturationBrightnessComponent.getColor());
saturationBrightnessComponent.setSize(new Dimension(1510, 1010));
saturationBrightnessComponent.setHue(0.0f);
saturationBrightnessComponent.setOpacity(100);
event = new MouseEvent(saturationBrightnessComponent, MouseEvent.MOUSE_CLICKED, 1, MouseEvent.BUTTON1, 1505, 1005, 1, false);
for (MouseListener mouseListener : saturationBrightnessComponent.getMouseListeners()) {
mouseListener.mousePressed(event);
}
expectedColor = ColorUtil.toAlpha(Color.BLACK, 100);
assertEquals(expectedColor, saturationBrightnessComponent.getColor());
saturationBrightnessComponent.setSize(new Dimension(1510, 1010));
saturationBrightnessComponent.setHue(0.0f);
saturationBrightnessComponent.setOpacity(100);
event = new MouseEvent(saturationBrightnessComponent, MouseEvent.MOUSE_CLICKED, 1, MouseEvent.BUTTON1, 1505, 5, 1, false);
for (MouseListener mouseListener : saturationBrightnessComponent.getMouseListeners()) {
mouseListener.mousePressed(event);
}
expectedColor = ColorUtil.toAlpha(Color.RED, 100);
assertEquals(expectedColor, saturationBrightnessComponent.getColor());
}
use of java.awt.event.MouseListener in project android by JetBrains.
the class NlPaletteTreeGridTest method clickOnItem.
private void clickOnItem(int listIndex, int itemIndex) {
TreeGrid<Palette.Item> tree = myPanel.getComponentTree();
JList<Palette.Item> list = tree.getLists().get(listIndex);
Rectangle bounds = list.getCellBounds(itemIndex, itemIndex);
int x = bounds.x + bounds.width / 2;
int y = bounds.y + bounds.height / 2;
List<MouseListener> listeners = Arrays.stream(list.getMouseListeners()).filter(this::isInnerClassOfPanel).collect(Collectors.toList());
list.setSelectedIndex(itemIndex);
MouseEvent event1 = new MouseEvent(list, MOUSE_PRESSED, System.currentTimeMillis(), BUTTON1_MASK | BUTTON1_DOWN_MASK, x, y, 1, false);
for (MouseListener listener : listeners) {
listener.mousePressed(event1);
}
MouseEvent event2 = new MouseEvent(list, MOUSE_RELEASED, System.currentTimeMillis(), BUTTON1_MASK | BUTTON1_DOWN_MASK, x, y, 1, false);
for (MouseListener listener : listeners) {
listener.mouseReleased(event2);
}
MouseEvent event3 = new MouseEvent(list, MOUSE_CLICKED, System.currentTimeMillis(), BUTTON1_MASK | BUTTON1_DOWN_MASK, x, y, 1, false);
for (MouseListener listener : listeners) {
listener.mouseClicked(event3);
}
}
Aggregations