Search in sources :

Example 66 with MouseListener

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);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) MouseEvent(java.awt.event.MouseEvent) XmlNode(com.android.manifmerger.XmlNode) MouseAdapter(java.awt.event.MouseAdapter) JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) NotNull(org.jetbrains.annotations.NotNull) MouseListener(java.awt.event.MouseListener) JBMenuItem(com.intellij.openapi.ui.JBMenuItem)

Example 67 with MouseListener

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);
    }
}
Also used : MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) MouseEventBuilder(com.android.tools.idea.uibuilder.fixtures.MouseEventBuilder)

Example 68 with MouseListener

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);
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseListener(java.awt.event.MouseListener)

Example 69 with MouseListener

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());
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseListener(java.awt.event.MouseListener) Color(java.awt.Color) Dimension(java.awt.Dimension)

Example 70 with MouseListener

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);
    }
}
Also used : PaletteTestCase.findItem(com.android.tools.idea.uibuilder.palette.PaletteTestCase.findItem) MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent)

Aggregations

MouseListener (java.awt.event.MouseListener)104 MouseEvent (java.awt.event.MouseEvent)67 Dimension (java.awt.Dimension)21 JLabel (javax.swing.JLabel)20 MouseAdapter (java.awt.event.MouseAdapter)19 JPanel (javax.swing.JPanel)16 Component (java.awt.Component)14 JComponent (javax.swing.JComponent)14 ActionEvent (java.awt.event.ActionEvent)13 ActionListener (java.awt.event.ActionListener)11 MouseMotionListener (java.awt.event.MouseMotionListener)11 JButton (javax.swing.JButton)11 JScrollPane (javax.swing.JScrollPane)11 Insets (java.awt.Insets)8 BorderLayout (java.awt.BorderLayout)7 Color (java.awt.Color)7 Point (java.awt.Point)7 File (java.io.File)7 ImageIcon (javax.swing.ImageIcon)6 JCheckBox (javax.swing.JCheckBox)6