Search in sources :

Example 31 with MouseMotionAdapter

use of java.awt.event.MouseMotionAdapter in project gate-core by GateNLP.

the class AnnotationEditor method initListeners.

protected void initListeners() {
    // resize the window when the table changes.
    featuresEditor.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            // the table has changed size -> resize the window too!
            popupWindow.pack();
        }
    });
    KeyAdapter keyAdapter = new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            hideTimer.stop();
        }
    };
    typeCombo.getEditor().getEditorComponent().addKeyListener(keyAdapter);
    MouseListener windowMouseListener = new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent evt) {
            hideTimer.stop();
        }

        // allow a JWindow to be dragged with a mouse
        @Override
        public void mousePressed(MouseEvent me) {
            pressed = me;
        }
    };
    MouseMotionListener windowMouseMotionListener = new MouseMotionAdapter() {

        Point location;

        // allow a JWindow to be dragged with a mouse
        @Override
        public void mouseDragged(MouseEvent me) {
            location = popupWindow.getLocation(location);
            int x = location.x - pressed.getX() + me.getX();
            int y = location.y - pressed.getY() + me.getY();
            popupWindow.setLocation(x, y);
            pinnedButton.setSelected(true);
        }
    };
    popupWindow.getRootPane().addMouseListener(windowMouseListener);
    popupWindow.getRootPane().addMouseMotionListener(windowMouseMotionListener);
    InputMap inputMap = ((JComponent) popupWindow.getContentPane()).getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    actionMap = ((JComponent) popupWindow.getContentPane()).getActionMap();
    // add the key-action bindings of this Component to the parent window
    solAction = new StartOffsetLeftAction("", MainFrame.getIcon("extend-left"), SOL_DESC, KeyEvent.VK_LEFT);
    solButton.setAction(solAction);
    setShortCuts(inputMap, SOL_KEY_STROKES, "solAction");
    actionMap.put("solAction", solAction);
    sorAction = new StartOffsetRightAction("", MainFrame.getIcon("extend-right"), SOR_DESC, KeyEvent.VK_RIGHT);
    sorButton.setAction(sorAction);
    setShortCuts(inputMap, SOR_KEY_STROKES, "sorAction");
    actionMap.put("sorAction", sorAction);
    delAction = new DeleteAnnotationAction("", MainFrame.getIcon("remove-annotation"), "Delete the annotation", KeyEvent.VK_DELETE);
    delButton.setAction(delAction);
    inputMap.put(KeyStroke.getKeyStroke("alt DELETE"), "delAction");
    actionMap.put("delAction", delAction);
    eolAction = new EndOffsetLeftAction("", MainFrame.getIcon("extend-left"), EOL_DESC, KeyEvent.VK_LEFT);
    eolButton.setAction(eolAction);
    setShortCuts(inputMap, EOL_KEY_STROKES, "eolAction");
    actionMap.put("eolAction", eolAction);
    eorAction = new EndOffsetRightAction("", MainFrame.getIcon("extend-right"), EOR_DESC, KeyEvent.VK_RIGHT);
    eorButton.setAction(eorAction);
    setShortCuts(inputMap, EOR_KEY_STROKES, "eorAction");
    actionMap.put("eorAction", eorAction);
    pinnedButton.setToolTipText("<html>Press to pin window in place" + "&nbsp;&nbsp;<font color=#667799><small>Ctrl-P" + "&nbsp;&nbsp;</small></font></html>");
    inputMap.put(KeyStroke.getKeyStroke("control P"), "toggle pin");
    actionMap.put("toggle pin", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            pinnedButton.doClick();
        }
    });
    DismissAction dismissAction = new DismissAction("", null, "Close the window", KeyEvent.VK_ESCAPE);
    dismissButton.setAction(dismissAction);
    inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "dismissAction");
    inputMap.put(KeyStroke.getKeyStroke("alt ESCAPE"), "dismissAction");
    actionMap.put("dismissAction", dismissAction);
    ApplyAction applyAction = new ApplyAction("Apply", null, "", KeyEvent.VK_ENTER);
    inputMap.put(KeyStroke.getKeyStroke("alt ENTER"), "applyAction");
    actionMap.put("applyAction", applyAction);
    typeCombo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            String newType = typeCombo.getSelectedItem().toString();
            if (ann == null || ann.getType().equals(newType))
                return;
            // annotation editing
            Integer oldId = ann.getId();
            Annotation oldAnn = ann;
            set.remove(ann);
            try {
                set.add(oldId, oldAnn.getStartNode().getOffset(), oldAnn.getEndNode().getOffset(), newType, oldAnn.getFeatures());
                Annotation newAnn = set.get(oldId);
                // update the selection to the new annotation
                getOwner().selectAnnotation(new AnnotationDataImpl(set, newAnn));
                editAnnotation(newAnn, set);
                owner.annotationChanged(newAnn, set, oldAnn.getType());
            } catch (InvalidOffsetException ioe) {
                throw new GateRuntimeException(ioe);
            }
        }
    });
    hideTimer = new Timer(HIDE_DELAY, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            annotationEditorInstance.setVisible(false);
        }
    });
    hideTimer.setRepeats(false);
    AncestorListener textAncestorListener = new AncestorListener() {

        @Override
        public void ancestorAdded(AncestorEvent event) {
            if (wasShowing) {
                annotationEditorInstance.setVisible(true);
            }
            wasShowing = false;
        }

        @Override
        public void ancestorRemoved(AncestorEvent event) {
            if (isShowing()) {
                wasShowing = true;
                popupWindow.dispose();
            }
        }

        @Override
        public void ancestorMoved(AncestorEvent event) {
        }

        private boolean wasShowing = false;
    };
    owner.getTextComponent().addAncestorListener(textAncestorListener);
}
Also used : ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseMotionListener(java.awt.event.MouseMotionListener) AncestorEvent(javax.swing.event.AncestorEvent) KeyEvent(java.awt.event.KeyEvent) MouseListener(java.awt.event.MouseListener) GateRuntimeException(gate.util.GateRuntimeException) AnnotationDataImpl(gate.gui.annedit.AnnotationDataImpl) AncestorListener(javax.swing.event.AncestorListener) AbstractAction(javax.swing.AbstractAction) ComponentAdapter(java.awt.event.ComponentAdapter) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JComponent(javax.swing.JComponent) InvalidOffsetException(gate.util.InvalidOffsetException) Point(java.awt.Point) Point(java.awt.Point) Annotation(gate.Annotation) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) ActionListener(java.awt.event.ActionListener) Timer(javax.swing.Timer) InputMap(javax.swing.InputMap) ComponentEvent(java.awt.event.ComponentEvent)

Example 32 with MouseMotionAdapter

use of java.awt.event.MouseMotionAdapter in project opennars by opennars.

the class AWTPanelHelper method addHelpAndPanelListeners.

/**
 * Adds common help text and listeners for awt-based testbeds.
 */
public static void addHelpAndPanelListeners(Component panel, final TestbedState model, final PhysicsController controller, final int screenDragButton) {
    final Vec2 oldDragMouse = new Vec2();
    final Vec2 mouse = new Vec2();
    List<String> help = Lists.newArrayList();
    help.add("Click and drag the left mouse button to move objects.");
    help.add("Click and drag the right mouse button to move the view.");
    help.add("Shift-Click to aim a bullet, or press space.");
    help.add("Scroll to zoom in/out on the mouse position");
    help.add("Press '[' or ']' to change tests, and 'r' to restart.");
    model.setImplSpecificHelp(help);
    panel.addMouseWheelListener(new MouseWheelListener() {

        public void mouseWheelMoved(MouseWheelEvent e) {
            int notches = e.getWheelRotation();
            PhysicsModel currTest = model.getCurrTest();
            if (currTest == null) {
                return;
            }
            ZoomType zoom = notches < 0 ? ZoomType.ZOOM_IN : ZoomType.ZOOM_OUT;
            currTest.getCamera().zoomToPoint(mouse, zoom);
        }
    });
    panel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent arg0) {
            if (arg0.getButton() == screenDragButton) {
                screenDragButtonDown = false;
            } else if (model.getCodedKeys()[KeyEvent.VK_SHIFT] && !mouseJointButtonDown) {
                controller.queueMouseUp(new Vec2(arg0.getX(), arg0.getY()), PhysicsModel.BOMB_SPAWN_BUTTON);
            } else {
                if (arg0.getButton() == PhysicsModel.MOUSE_JOINT_BUTTON) {
                    mouseJointButtonDown = false;
                }
                controller.queueMouseUp(new Vec2(arg0.getX(), arg0.getY()), arg0.getButton());
            }
        }

        @Override
        public void mousePressed(MouseEvent arg0) {
            if (arg0.getButton() == screenDragButton) {
                screenDragButtonDown = true;
                oldDragMouse.set(arg0.getX(), arg0.getY());
                return;
            } else if (model.getCodedKeys()[KeyEvent.VK_SHIFT]) {
                controller.queueMouseDown(new Vec2(arg0.getX(), arg0.getY()), PhysicsModel.BOMB_SPAWN_BUTTON);
            } else {
                if (arg0.getButton() == PhysicsModel.MOUSE_JOINT_BUTTON) {
                    mouseJointButtonDown = true;
                }
                controller.queueMouseDown(new Vec2(arg0.getX(), arg0.getY()), arg0.getButton());
            }
        }
    });
    panel.addMouseMotionListener(new MouseMotionAdapter() {

        @Override
        public void mouseMoved(MouseEvent arg0) {
            mouse.set(arg0.getX(), arg0.getY());
            controller.queueMouseMove(new Vec2(mouse));
        }

        @Override
        public void mouseDragged(MouseEvent arg0) {
            mouse.set(arg0.getX(), arg0.getY());
            if (screenDragButtonDown) {
                PhysicsModel currTest = model.getCurrTest();
                if (currTest == null) {
                    return;
                }
                Vec2 diff = oldDragMouse.sub(mouse);
                currTest.getCamera().moveWorld(diff);
                oldDragMouse.set(mouse);
            } else if (mouseJointButtonDown) {
                controller.queueMouseDrag(new Vec2(mouse), PhysicsModel.MOUSE_JOINT_BUTTON);
            } else if (model.getCodedKeys()[KeyEvent.VK_SHIFT]) {
                controller.queueMouseDrag(new Vec2(arg0.getX(), arg0.getY()), PhysicsModel.BOMB_SPAWN_BUTTON);
            } else {
                controller.queueMouseDrag(new Vec2(mouse), arg0.getButton());
            }
        }
    });
    panel.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent arg0) {
            controller.queueKeyReleased(arg0.getKeyChar(), arg0.getKeyCode());
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
            char c = arg0.getKeyChar();
            controller.queueKeyPressed(c, arg0.getKeyCode());
            switch(c) {
                case '[':
                    controller.lastTest();
                    break;
                case ']':
                    controller.nextTest();
                    break;
                case 'r':
                    controller.reset();
                    break;
                case ' ':
                    controller.queueLaunchBomb();
                    break;
                case 'p':
                    controller.queuePause();
                    break;
            }
        }
    });
}
Also used : ZoomType(nars.lab.narclear.jbox2d.PhysicsCamera.ZoomType) MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) MouseWheelListener(java.awt.event.MouseWheelListener) KeyEvent(java.awt.event.KeyEvent) PhysicsModel(nars.lab.narclear.PhysicsModel) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseWheelEvent(java.awt.event.MouseWheelEvent) Vec2(org.jbox2d.common.Vec2)

Example 33 with MouseMotionAdapter

use of java.awt.event.MouseMotionAdapter in project azure-tools-for-java by Microsoft.

the class SurveyPopUpDialog method addDragListener.

private void addDragListener() {
    addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            dragPosition = new Point(e.getX(), e.getY());
        }
    });
    addMouseMotionListener(new MouseMotionAdapter() {

        public void mouseDragged(MouseEvent e) {
            SurveyPopUpDialog.this.setLocation(e.getX() + getX() - dragPosition.x, e.getY() + getY() - dragPosition.y);
        }
    });
}
Also used : MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter)

Example 34 with MouseMotionAdapter

use of java.awt.event.MouseMotionAdapter in project Botnak by Gocnak.

the class BaseTableHeaderUI method installListeners.

public void installListeners() {
    super.installListeners();
    myMouseAdapter = new MouseAdapter() {

        public void mouseReleased(MouseEvent e) {
            if ((header == null) || (header.getTable() == null)) {
                return;
            }
            boolean rolloverEnabled = Boolean.TRUE.equals(header.getClientProperty("rolloverEnabled"));
            boolean sortingAllowed = false;
            if (JTattooUtilities.getJavaVersion() >= 1.6) {
                sortingAllowed = header.getTable().getRowSorter() != null;
            }
            if (rolloverEnabled || sortingAllowed || header.getReorderingAllowed()) {
                if (header.getBounds().contains(e.getPoint())) {
                    int oldRolloverCol = rolloverCol;
                    rolloverCol = header.getColumnModel().getColumnIndexAtX(e.getX());
                    updateRolloverColumn(oldRolloverCol, rolloverCol);
                } else {
                    int oldRolloverCol = rolloverCol;
                    rolloverCol = -1;
                    updateRolloverColumn(oldRolloverCol, rolloverCol);
                }
            }
        }

        public void mouseEntered(MouseEvent e) {
            if ((header == null) || (header.getTable() == null)) {
                return;
            }
            boolean rolloverEnabled = Boolean.TRUE.equals(header.getClientProperty("rolloverEnabled"));
            boolean sortingAllowed = false;
            if (JTattooUtilities.getJavaVersion() >= 1.6) {
                sortingAllowed = header.getTable().getRowSorter() != null;
            }
            if (rolloverEnabled || sortingAllowed || header.getReorderingAllowed()) {
                int oldRolloverCol = rolloverCol;
                rolloverCol = header.getColumnModel().getColumnIndexAtX(e.getX());
                updateRolloverColumn(oldRolloverCol, rolloverCol);
            }
        }

        public void mouseExited(MouseEvent e) {
            if ((header == null) || (header.getTable() == null)) {
                return;
            }
            boolean rolloverEnabled = Boolean.TRUE.equals(header.getClientProperty("rolloverEnabled"));
            boolean sortingAllowed = false;
            if (JTattooUtilities.getJavaVersion() >= 1.6) {
                sortingAllowed = header.getTable().getRowSorter() != null;
            }
            if (rolloverEnabled || sortingAllowed || header.getReorderingAllowed()) {
                int oldRolloverCol = rolloverCol;
                rolloverCol = -1;
                updateRolloverColumn(oldRolloverCol, rolloverCol);
            }
        }
    };
    myMouseMotionAdapter = new MouseMotionAdapter() {

        public void mouseMoved(MouseEvent e) {
            if ((header == null) || (header.getTable() == null)) {
                return;
            }
            boolean rolloverEnabled = Boolean.TRUE.equals(header.getClientProperty("rolloverEnabled"));
            boolean sortingAllowed = false;
            if (JTattooUtilities.getJavaVersion() >= 1.6) {
                sortingAllowed = header.getTable().getRowSorter() != null;
            }
            if (rolloverEnabled || sortingAllowed || header.getReorderingAllowed()) {
                if (header.getDraggedColumn() == null) {
                    int oldRolloverCol = rolloverCol;
                    rolloverCol = header.getColumnModel().getColumnIndexAtX(e.getX());
                    updateRolloverColumn(oldRolloverCol, rolloverCol);
                }
            }
        }

        public void mouseDragged(MouseEvent e) {
            if ((header == null) || (header.getTable() == null)) {
                return;
            }
            boolean rolloverEnabled = Boolean.TRUE.equals(header.getClientProperty("rolloverEnabled"));
            boolean sortingAllowed = false;
            if (JTattooUtilities.getJavaVersion() >= 1.6) {
                sortingAllowed = header.getTable().getRowSorter() != null;
            }
            if (rolloverEnabled || sortingAllowed || header.getReorderingAllowed()) {
                if (header.getDraggedColumn() != null && header.getDraggedColumn().getIdentifier() != null) {
                    rolloverCol = header.getColumnModel().getColumnIndex(header.getDraggedColumn().getIdentifier());
                } else if (header.getResizingColumn() != null) {
                    rolloverCol = -1;
                }
            }
        }
    };
    header.addMouseListener(myMouseAdapter);
    header.addMouseMotionListener(myMouseMotionAdapter);
}
Also used : MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter)

Aggregations

MouseEvent (java.awt.event.MouseEvent)34 MouseMotionAdapter (java.awt.event.MouseMotionAdapter)34 MouseAdapter (java.awt.event.MouseAdapter)20 Point (java.awt.Point)15 BorderLayout (java.awt.BorderLayout)13 Dimension (java.awt.Dimension)12 JLabel (javax.swing.JLabel)12 JPanel (javax.swing.JPanel)12 JScrollPane (javax.swing.JScrollPane)12 GridBagConstraints (java.awt.GridBagConstraints)11 GridBagLayout (java.awt.GridBagLayout)11 Insets (java.awt.Insets)11 Graphics (java.awt.Graphics)9 Border (javax.swing.border.Border)6 PointLocationInShapeContext (cbit.vcell.graph.PointLocationInShapeContext)5 RuleAnalysisChanged (cbit.vcell.graph.ReactionCartoon.RuleAnalysisChanged)5 GroupingCriteria (cbit.vcell.model.GroupingCriteria)5 RuleParticipantSignature (cbit.vcell.model.RuleParticipantSignature)5 JTextField (javax.swing.JTextField)5 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)5