List of usage examples for java.awt.event MouseMotionAdapter MouseMotionAdapter
MouseMotionAdapter
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Helper method to create the trees hosting the display. * /* w ww . j a v a2 s . co m*/ * @param exp The logged in experimenter. */ private void createTrees(ExperimenterData exp) { treeDisplay = new DnDTree(model.getUserID(), TreeViewerAgent.isAdministrator()); treeDisplay.addPropertyChangeListener(this); String key = "meta pressed A"; if (UIUtilities.isWindowsOS()) key = "ctrl pressed A"; KeyStroke ks = KeyStroke.getKeyStroke(key); treeDisplay.getInputMap().put(ks, "none"); treeDisplay.setVisible(true); treeDisplay.setRootVisible(false); ToolTipManager.sharedInstance().registerComponent(treeDisplay); treeDisplay.setCellRenderer(new TreeCellRenderer(model.getUserID())); treeDisplay.setShowsRootHandles(true); TreeImageSet root = new TreeImageSet(""); treeDisplay.setModel(new DefaultTreeModel(root)); if (model.getBrowserType() != Browser.ADMIN_EXPLORER) { TreeImageDisplay node = buildTreeNodes(exp); if (node != null) treeDisplay.collapsePath(new TreePath(node.getPath())); } //Add Listeners //treeDisplay.requestFocus(); treeDisplay.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { mousePressedTime = e.getWhen(); rightClickPad = UIUtilities.isMacOS() && SwingUtilities.isLeftMouseButton(e) && e.isControlDown(); rightClickButton = SwingUtilities.isRightMouseButton(e); ctrl = e.isControlDown(); if (UIUtilities.isMacOS()) ctrl = e.isMetaDown(); leftMouseButton = SwingUtilities.isLeftMouseButton(e); if (UIUtilities.isMacOS() || UIUtilities.isLinuxOS()) onClick(e, false); } public void mouseReleased(MouseEvent e) { leftMouseButton = SwingUtilities.isLeftMouseButton(e); if (UIUtilities.isWindowsOS()) onClick(e, true); } // public void mouseMoved(MouseEvent e) { rollOver(e); } }); treeDisplay.addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent e) { rollOver(e); } }); treeDisplay.addTreeExpansionListener(listener); selectionListener = new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { event = e; eventHandledTime = System.currentTimeMillis(); if (delayedHandlingTreeSelection) /* mouse click delayed handling until this event occurred */ handleTreeSelection(); switch (keyEvent) { case KeyEvent.VK_DOWN: case KeyEvent.VK_UP: TreePath[] paths = treeDisplay.getSelectionPaths(); if (paths != null) controller.onClick(Arrays.asList(paths)); else controller.onClick(new ArrayList<TreePath>()); break; } } }; treeDisplay.addTreeSelectionListener(selectionListener); //remove standard behaviour treeDisplay.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { ctrl = false; switch (e.getKeyCode()) { case KeyEvent.VK_ENTER: ViewCmd cmd = new ViewCmd(model.getParentModel(), true); cmd.execute(); break; case KeyEvent.VK_DELETE: switch (model.getState()) { case Browser.LOADING_DATA: case Browser.LOADING_LEAVES: //case Browser.COUNTING_ITEMS: break; default: model.delete(); } break; case KeyEvent.VK_CONTROL: if (!UIUtilities.isMacOS()) ctrl = true; break; case KeyEvent.VK_META: if (UIUtilities.isMacOS()) ctrl = true; break; case KeyEvent.VK_A: if (UIUtilities.isWindowsOS() && e.isControlDown() || !UIUtilities.isWindowsOS() && e.isMetaDown()) { handleMultiSelection(); } break; case KeyEvent.VK_DOWN: case KeyEvent.VK_UP: case KeyEvent.VK_RIGHT: keyEvent = e.getKeyCode(); break; case KeyEvent.VK_LEFT: TreePath[] paths = treeDisplay.getSelectionPaths(); TreeImageDisplay node; Object o; for (int i = 0; i < paths.length; i++) { o = paths[i].getLastPathComponent(); if (o instanceof TreeImageDisplay) { node = (TreeImageDisplay) o; if (node.isExpanded()) node.setExpanded(false); } } } } public void keyReleased(KeyEvent e) { ctrl = false; keyEvent = -1; } }); }
From source file:de.codesourcery.jasm16.ide.ui.views.SourceCodeView.java
private final JPanel createPanel() { disableDocumentListener(); // necessary because setting colors on editor pane triggers document change listeners (is considered a style change...) try {/*from w w w .ja v a2 s . com*/ editorPane.setEditable(editable); editorPane.getDocument().addUndoableEditListener(undoListener); editorPane.setCaretColor(Color.WHITE); setupKeyBindings(editorPane); setColors(editorPane); editorScrollPane = new JScrollPane(editorPane); setColors(editorScrollPane); editorPane.addCaretListener(listener); editorPane.addMouseListener(mouseListener); editorPane.addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { if ((e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) != 0) // ctrl pressed { final ASTNode node = getASTNodeForLocation(e.getPoint()); if (node instanceof SymbolReferenceNode) { maybeUnderlineIdentifierAt(e.getPoint()); } else { clearUnderlineHighlight(); } } else if (compilationUnit != null) { String tooltipText = null; if (compilationUnit != null) { final ASTNode node = getASTNodeForLocation(e.getPoint()); if (node instanceof InvokeMacroNode) { tooltipText = ExpandMacrosPhase.expandInvocation((InvokeMacroNode) node, compilationUnit); if (tooltipText != null) { tooltipText = "<html>" + tooltipText.replace("\n", "<br>") + "</html>"; } } } if (!StringUtils.equals(editorPane.getToolTipText(), tooltipText)) { editorPane.setToolTipText(tooltipText); } } } }); editorPane.addMouseListener(popupListener); } finally { enableDocumentListener(); } EditorContainer.addEditorCloseKeyListener(editorPane, this); editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); editorScrollPane.setPreferredSize(new Dimension(400, 600)); editorScrollPane.setMinimumSize(new Dimension(100, 100)); final AdjustmentListener adjustmentListener = new AdjustmentListener() { @Override public void adjustmentValueChanged(AdjustmentEvent e) { if (!e.getValueIsAdjusting()) { if (compilationUnit != null) { doHighlighting(compilationUnit, false); } } } }; editorScrollPane.getVerticalScrollBar().addAdjustmentListener(adjustmentListener); editorScrollPane.getHorizontalScrollBar().addAdjustmentListener(adjustmentListener); // button panel final JPanel topPanel = new JPanel(); final JToolBar toolbar = new JToolBar(); setColors(toolbar); cursorPosition.setSize(new Dimension(400, 15)); cursorPosition.setEditable(false); setColors(cursorPosition); /** * TOOLBAR * SOURCE * cursor position * status area */ topPanel.setLayout(new GridBagLayout()); GridBagConstraints cnstrs = constraints(0, 0, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = GridBagConstraints.REMAINDER; cnstrs.weighty = 0; topPanel.add(toolbar, cnstrs); cnstrs = constraints(0, 1, GridBagConstraints.BOTH); cnstrs.gridwidth = GridBagConstraints.REMAINDER; topPanel.add(editorScrollPane, cnstrs); cnstrs = constraints(0, 2, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = GridBagConstraints.REMAINDER; cnstrs.weighty = 0; topPanel.add(cursorPosition, cnstrs); cnstrs = constraints(0, 3, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = GridBagConstraints.REMAINDER; cnstrs.weighty = 0; // setup result panel final JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); setColors(panel); cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH); panel.add(topPanel, cnstrs); return panel; }