Search in sources :

Example 61 with MouseListener

use of java.awt.event.MouseListener in project lionengine by b3dgs.

the class MouseAwtTest method testClicked.

/**
 * Test clicked state.
 */
@Test
void testClicked() {
    final MouseAwt mouse = createMouse();
    final MouseListener clicker = mouse.getClicker();
    assertFalse(mouse.isPushed(MouseAwt.LEFT));
    clicker.mousePressed(createEvent(MouseAwt.LEFT, 0, 0));
    assertTrue(mouse.isPushed(MouseAwt.LEFT));
    clicker.mouseReleased(createEvent(MouseAwt.LEFT, 0, 0));
    assertFalse(mouse.isPushed(MouseAwt.LEFT));
    assertFalse(mouse.isPushed(MouseAwt.RIGHT));
    clicker.mousePressed(createEvent(MouseAwt.RIGHT, 0, 0));
    assertTrue(mouse.isPushed(MouseAwt.RIGHT));
    clicker.mouseReleased(createEvent(MouseAwt.RIGHT, 0, 0));
    assertFalse(mouse.isPushed(MouseAwt.RIGHT));
}
Also used : MouseListener(java.awt.event.MouseListener) Test(org.junit.jupiter.api.Test)

Example 62 with MouseListener

use of java.awt.event.MouseListener in project lionengine by b3dgs.

the class MouseAwtTest method testClick.

/**
 * Test click.
 */
@Test
void testClick() {
    final MouseAwt mouse = createMouse();
    final MouseListener clicker = mouse.getClicker();
    clicker.mousePressed(createEvent(MouseAwt.MIDDLE, 0, 0));
    assertEquals(MouseAwt.MIDDLE, mouse.getPushed());
    clicker.mouseReleased(createEvent(MouseAwt.MIDDLE, 0, 0));
    assertNotEquals(MouseAwt.MIDDLE, mouse.getPushed());
}
Also used : MouseListener(java.awt.event.MouseListener) Test(org.junit.jupiter.api.Test)

Example 63 with MouseListener

use of java.awt.event.MouseListener in project lionengine by b3dgs.

the class MouseAwtTest method testMouse.

/**
 * Test move.
 */
@Test
void testMouse() {
    final MouseAwt mouse = createMouse();
    final MouseListener clicker = mouse.getClicker();
    final MouseMotionListener mover = mouse.getMover();
    mover.mouseMoved(createEvent(MouseAwt.LEFT, 0, 0));
    mover.mouseDragged(createEvent(Integer.valueOf(0), 0, 0));
    mouse.update(1.0);
    assertEquals(0, mouse.getMoveX());
    assertEquals(0, mouse.getMoveY());
    clicker.mouseEntered(null);
    clicker.mouseExited(null);
    clicker.mouseClicked(null);
}
Also used : MouseListener(java.awt.event.MouseListener) MouseMotionListener(java.awt.event.MouseMotionListener) Test(org.junit.jupiter.api.Test)

Example 64 with MouseListener

use of java.awt.event.MouseListener in project lionengine by b3dgs.

the class MouseAwtTest method testEvent.

/**
 * Test event.
 */
@Test
void testEvent() {
    final MouseAwt mouse = createMouse();
    final AtomicBoolean left = new AtomicBoolean(false);
    mouse.addActionPressed(MouseAwt.LEFT, () -> left.set(true));
    mouse.addActionPressed(MouseAwt.LEFT, () -> left.set(true));
    mouse.addActionReleased(MouseAwt.LEFT, () -> left.set(false));
    mouse.addActionReleased(MouseAwt.LEFT, () -> left.set(false));
    assertFalse(left.get());
    final MouseListener clicker = mouse.getClicker();
    clicker.mousePressed(createEvent(MouseAwt.LEFT, 0, 0));
    assertTrue(left.get());
    clicker.mouseReleased(createEvent(MouseAwt.LEFT, 0, 0));
    assertFalse(left.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MouseListener(java.awt.event.MouseListener) Test(org.junit.jupiter.api.Test)

Example 65 with MouseListener

use of java.awt.event.MouseListener in project sldeditor by robward-scisys.

the class FileSystemExtension method initialise.

/**
 * Initialise.
 *
 * @param parent the parent
 * @param toolMgr the tool manager
 */
@Override
public void initialise(LoadSLDInterface parent, ToolSelectionInterface toolMgr) {
    this.toolMgr = toolMgr;
    this.parentObj = parent;
    if (toolMgr != null) {
        toolMgr.addRecursiveListener(this);
    }
    // Add extensions
    List<FileSystemInterface> extensionList = FileSystemExtensionFactory.getFileExtensionList(toolMgr);
    extensionPanel = new JPanel();
    extensionPanel.setLayout(new BorderLayout());
    extensionPanel.setPreferredSize(new Dimension(450, 400));
    JPanel toolPanel = null;
    if (toolMgr != null) {
        toolPanel = toolMgr.getPanel();
    }
    if (toolPanel != null) {
        extensionPanel.add(toolPanel, BorderLayout.NORTH);
    }
    tree = new FSTree();
    tree.setRootVisible(true);
    DefaultMutableTreeNode rootNode;
    try {
        rootNode = new DefaultMutableTreeNode(ROOT_NODE);
        model = new DefaultTreeModel(rootNode);
        FileSystemNodeManager.create(tree, model);
        for (FileSystemInterface extension : extensionList) {
            extension.populate(tree, model, rootNode);
        }
    } catch (SecurityException e1) {
        ConsoleManager.getInstance().exception(this, e1);
    }
    tree.setModel(model);
    tree.setDragEnabled(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            treeSelected(e);
        }

        @Override
        public void mousePressed(MouseEvent e) {
        // Do nothing
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        // Do nothing
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        // Do nothing
        }

        @Override
        public void mouseExited(MouseEvent e) {
        // Do nothing
        }
    });
    // Listen for Tree Selection Events
    tree.addTreeExpansionListener(new TreeExpansionListener() {

        /*
                     * (non-Javadoc)
                     *
                     * @see javax.swing.event.TreeExpansionListener#treeExpanded(javax.swing.event.
                     * TreeExpansionEvent)
                     */
        public void treeExpanded(TreeExpansionEvent evt) {
            TreePath path = evt.getPath();
            Object selectedItem = path.getLastPathComponent();
            for (FileSystemInterface extension : extensionList) {
                if (extension.treeExpanded(selectedItem)) {
                    ((DefaultTreeModel) tree.getModel()).nodeStructureChanged((TreeNode) selectedItem);
                }
            }
        }

        /*
                     * (non-Javadoc)
                     *
                     * @see javax.swing.event.TreeExpansionListener#treeCollapsed(javax.swing.event.
                     * TreeExpansionEvent)
                     */
        public void treeCollapsed(TreeExpansionEvent evt) {
        // Nothing to do
        }
    });
    // Tree selection listener
    tree.setTreeSelection(this);
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
    panel.add(new JScrollPane(tree));
    extensionPanel.add(panel, BorderLayout.CENTER);
    logger.debug("FileSystem initialise finished");
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) TreeExpansionListener(javax.swing.event.TreeExpansionListener) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) BoxLayout(javax.swing.BoxLayout) Dimension(java.awt.Dimension) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) FileSystemInterface(com.sldeditor.common.filesystem.FileSystemInterface) MouseListener(java.awt.event.MouseListener) BorderLayout(java.awt.BorderLayout) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent)

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