Java Code Examples for java.awt.event.MouseEvent#getModifiers()
The following examples show how to use
java.awt.event.MouseEvent#getModifiers() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: yawl File: TableSorter.java License: GNU Lesser General Public License v3.0 | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { System.out.println("Sorting ..."); int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK; boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 2
Source Project: astor File: JTreeTable.java License: GNU General Public License v2.0 | 6 votes |
/** * Overridden to return false, and if the event is a mouse event * it is forwarded to the tree.<p> * The behavior for this is debatable, and should really be offered * as a property. By returning false, all keyboard actions are * implemented in terms of the table. By returning true, the * tree would get a chance to do something with the keyboard * events. For the most part this is ok. But for certain keys, * such as left/right, the tree will expand/collapse where as * the table focus should really move to a different column. Page * up/down should also be implemented in terms of the table. * By returning false this also has the added benefit that clicking * outside of the bounds of the tree node, but still in the tree * column will select the row, whereas if this returned true * that wouldn't be the case. * <p>By returning false we are also enforcing the policy that * the tree will never be editable (at least by a key sequence). */ @Override public boolean isCellEditable(EventObject e) { if (e instanceof MouseEvent) { for (int counter = getColumnCount() - 1; counter >= 0; counter--) { if (getColumnClass(counter) == TreeTableModel.class) { MouseEvent me = (MouseEvent)e; MouseEvent newME = new MouseEvent(tree, me.getID(), me.getWhen(), me.getModifiers(), me.getX() - getCellRect(0, counter, true).x, me.getY(), me.getClickCount(), me.isPopupTrigger()); tree.dispatchEvent(newME); break; } } } return false; }
Example 3
Source Project: jdk8u_jdk File: TableSorter.java License: GNU General Public License v2.0 | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { System.out.println("Sorting ..."); int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK; boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 4
Source Project: bboxdb File: TreeJPanel.java License: Apache License 2.0 | 6 votes |
/** * Get the text for the tool tip */ @Override public String getToolTipText(final MouseEvent event) { final MouseEvent scaledEvent = new MouseEvent(event.getComponent(), event.getID(), event.getWhen(), event.getModifiers(), (int) (event.getX() / zoomFactor), (int) (event.getY() / zoomFactor), event.getClickCount(), event.isPopupTrigger()); for(final DistributionRegionComponent component : regions) { if(component.isMouseOver(scaledEvent)) { return component.getToolTipText(); } } setToolTipText(null); return super.getToolTipText(event); }
Example 5
Source Project: pdfxtk File: TextArea2.java License: Apache License 2.0 | 6 votes |
public boolean mouseClickedAction(MouseEvent event) { // System.out.println("mouse clicked action; event = " + event); if ((click1Handler != null) && (0 != (event.getModifiers() & MouseEvent.BUTTON1_MASK))) { context.actionFactory.handleAction(click1Handler, null, this, context); return true; } if ((click2Handler != null) && (0 != (event.getModifiers() & MouseEvent.BUTTON2_MASK))) { context.actionFactory.handleAction(click2Handler, null, this, context); return true; } if ((click3Handler != null) && (0 != (event.getModifiers() & MouseEvent.BUTTON3_MASK))) { context.actionFactory.handleAction(click3Handler, null, this, context); return true; } return super.mouseClickedAction(event); }
Example 6
Source Project: openjdk-jdk8u File: bug7170657.java License: GNU General Public License v2.0 | 5 votes |
private static void test(final Frame frame, final MouseEvent me) { MouseEvent newme = SwingUtilities.convertMouseEvent(frame, me, frame); if (me.getModifiersEx() != newme.getModifiersEx() || me.getModifiers() != newme.getModifiers()) { fail(me, newme); } }
Example 7
Source Project: ramus File: Handler.java License: GNU General Public License v3.0 | 5 votes |
@Override public void mouseReleased(final MouseEvent me) { if (!ourToolBarIsDragging) return; if ((me.getModifiers() & InputEvent.BUTTON1_MASK) != InputEvent.BUTTON1_MASK) { return; } hideDraggingWindow(); final Container target = ourDockLayout.getTargetContainer(); if (target == null) return; Point p = me.getPoint(); p = SwingUtilities.convertPoint(ourToolBar, p, target); DockBoundary dock = null; if (!me.isControlDown()) { dock = getDockableBoundary(p); if (dock != null) { setDockIndex(dock.getDockIndex(p)); setRowIndex(dock.getRowIndex(p)); setDockEdge(dock.getEdge()); } } if (dock != null) { dockToolBar(getDockEdge(), getRowIndex(), getDockIndex()); } else { SwingUtilities.convertPointToScreen(p, target); floatToolBar(p.x, p.y, true); } }
Example 8
Source Project: jdk8u-jdk File: bug7170657.java License: GNU General Public License v2.0 | 5 votes |
private static void test(final Frame frame, final MouseEvent me) { MouseEvent newme = SwingUtilities.convertMouseEvent(frame, me, frame); if (me.getModifiersEx() != newme.getModifiersEx() || me.getModifiers() != newme.getModifiers()) { fail(me, newme); } }
Example 9
Source Project: dragonwell8_jdk File: bug7170657.java License: GNU General Public License v2.0 | 5 votes |
private static void test(final Frame frame, final MouseEvent me) { MouseEvent newme = SwingUtilities.convertMouseEvent(frame, me, frame); if (me.getModifiersEx() != newme.getModifiersEx() || me.getModifiers() != newme.getModifiers()) { fail(me, newme); } }
Example 10
Source Project: netbeans File: JTitledPanel.java License: Apache License 2.0 | 5 votes |
public void mouseClicked(MouseEvent e) { if ((e.getModifiers() == InputEvent.BUTTON1_MASK) && (e.getClickCount() == 2)) { if (isMaximized()) { restore(); } else { maximize(); } } ; }
Example 11
Source Project: netbeans File: TimelinePanel.java License: Apache License 2.0 | 5 votes |
public void mouseDragged(MouseEvent e){ if (!SwingUtilities.isLeftMouseButton(e)) return; if (draggingRow != null) { boolean checkStep = (e.getModifiers() & Toolkit.getDefaultToolkit(). getMenuShortcutKeyMask()) == 0; chart.setRowHeight(draggingRow.getIndex(), baseHeight + e.getY() - baseY, checkStep); } }
Example 12
Source Project: ghidra File: VertexMouseInfo.java License: Apache License 2.0 | 5 votes |
private MouseEvent createMouseEventFromSource(Component source, MouseEvent progenitor, Point2D clickPoint) { return new MouseEvent(source, progenitor.getID(), progenitor.getWhen(), progenitor.getModifiers() | progenitor.getModifiersEx(), (int) clickPoint.getX(), (int) clickPoint.getY(), progenitor.getClickCount(), progenitor.isPopupTrigger(), progenitor.getButton()); }
Example 13
Source Project: netbeans File: CompletionPopup.java License: Apache License 2.0 | 5 votes |
private MouseEvent convertMouseEvent(MouseEvent e) { Point convertedPoint = SwingUtilities.convertPoint((Component) e.getSource(), e.getPoint(), list); MouseEvent newEvent = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), convertedPoint.x, convertedPoint.y, e.getClickCount(), e.isPopupTrigger()); return newEvent; }
Example 14
Source Project: megamek File: PMGenericHotArea.java License: GNU General Public License v2.0 | 5 votes |
public void onMouseOver(MouseEvent e) { int modifiers = e.getModifiers(); String command = PMHotArea.MOUSE_OVER; ActionEvent ae = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, command, modifiers); dispatchEvent(ae); }
Example 15
Source Project: ProtegeVOWL File: ControlListener.java License: MIT License | 5 votes |
/** * mouse-over event on a visual item (node item or edge item) */ @Override public void itemEntered(VisualItem item, MouseEvent e) { // if ctrl is pressed, user zooms -> ignore itemEntered if (e.getModifiers() == InputEvent.CTRL_MASK) { ctrlZoom(e); return; } // only mark items as highlighted if the layout process is active RunLayoutControl rlc = new RunLayoutControl(viewManagerID); if (rlc.isLayouting()) { if (item instanceof NodeItem) { /* set highlight attribute to true, NodeRenderer will change the color */ item.set(ColumnNames.IS_HIGHLIGHTED, true); } if (item instanceof EdgeItem) { /* set highlight attribute to true, EdgeRenderer will change the color */ item.set(ColumnNames.IS_HIGHLIGHTED, true); } if (item instanceof TableDecoratorItem) { /* set highlight attribute to true, EdgeRenderer will change the color */ item.set(ColumnNames.IS_HIGHLIGHTED, true); } } }
Example 16
Source Project: netbeans File: AbstractListUI.java License: Apache License 2.0 | 4 votes |
private boolean redispatchComponent(MouseEvent e) { Point p = e.getPoint(); int index = list.locationToIndex(p); if (index < 0 || index >= list.getModel().getSize()) { return false; } ListCellRenderer renderer = list.getCellRenderer(); if (null == renderer) { return false; } Component renComponent = renderer.getListCellRendererComponent(list, list.getModel().getElementAt(index), index, false, false); if (null == renComponent) { return false; } Rectangle rect = list.getCellBounds(index, index); if (null == rect) { return false; } renComponent.setBounds(0, 0, rect.width, rect.height); renComponent.doLayout(); Point p3 = rect.getLocation(); Point p2 = new Point(p.x - p3.x, p.y - p3.y); Component dispatchComponent = SwingUtilities.getDeepestComponentAt(renComponent, p2.x, p2.y); if ( e.isPopupTrigger() && dispatchComponent instanceof LinkButton && !((LinkButton)dispatchComponent).isHandlingPopupEvents() ) { return false; } if (dispatchComponent instanceof AbstractButton) { if (!((AbstractButton) dispatchComponent).isEnabled()) { return false; } Point p4 = SwingUtilities.convertPoint(renComponent, p2, dispatchComponent); MouseEvent newEvent = new MouseEvent(dispatchComponent, e.getID(), e.getWhen(), e.getModifiers(), p4.x, p4.y, e.getClickCount(), e.isPopupTrigger(), MouseEvent.NOBUTTON); dispatchComponent.dispatchEvent(newEvent); list.repaint(rect); e.consume(); return true; } return false; }
Example 17
Source Project: weblaf File: WebTree.java License: GNU General Public License v3.0 | 4 votes |
/** * Unlike {@link JTree#getToolTipText()} this implementation takes row selection style into account. * That means that tooltips for {@link TreeSelectionStyle#line} will be displayed at any point in the row, not just on the node. * * @param event {@link MouseEvent} * @return tooltip text */ @Nullable @Override public String getToolTipText ( @Nullable final MouseEvent event ) { String tip = null; if ( event != null ) { final Point point = event.getPoint (); final WTreeUI ui = getUI (); final int row = ui.getExactRowForLocation ( point ); final TreeCellRenderer cellRenderer = getCellRenderer (); if ( row != -1 && cellRenderer != null ) { final TreePath path = getPathForRow ( row ); final Object value = path.getLastPathComponent (); final boolean selected = isRowSelected ( row ); final boolean expanded = isExpanded ( row ); final boolean leaf = isLeaf ( ( N ) value ); final Component renderer = cellRenderer.getTreeCellRendererComponent ( this, value, selected, expanded, leaf, row, true ); if ( renderer instanceof JComponent ) { final Rectangle pathBounds = getPathBounds ( path ); if ( pathBounds != null ) { final MouseEvent newEvent = new MouseEvent ( renderer, event.getID (), event.getWhen (), event.getModifiers (), point.x - pathBounds.x, point.y - pathBounds.y, event.getXOnScreen (), event.getYOnScreen (), event.getClickCount (), event.isPopupTrigger (), MouseEvent.NOBUTTON ); final JComponent jComponent = ( JComponent ) renderer; tip = jComponent.getToolTipText ( newEvent ); } } } } if ( tip == null ) { tip = getToolTipText (); } return tip; }
Example 18
Source Project: opensim-gui File: FunctionPanel.java License: Apache License 2.0 | 4 votes |
public void mousePressed(MouseEvent e) { this.requestFocusInWindow(); updateCursorLocation(e); FunctionNode leftClickNode = null; int keyMods = e.getModifiers(); if ((keyMods & InputEvent.BUTTON1_MASK) > 0) { leftClickNode = findNodeAt(e.getX(), e.getY()); // Some code to handle double clicking on an object, but which does so in a way that the sequence // CTRL-Click and Click does not count as a double click. This avoids // treating as double click the case where the user selects an object // (CTRL-Click) and quickly starts dragging (Click & Drag) if (leftClickNode != null && picking == false) { if (e.getClickCount() == lastLeftButtonClickCount+1 && leftClickNode == lastLeftButtonClickNode) { //handleDoubleClick(leftClickNode); return; } else { lastLeftButtonClickCount = e.getClickCount(); lastLeftButtonClickNode = leftClickNode; } } else { lastLeftButtonClickCount = -1; lastLeftButtonClickNode = null; } } if ((keyMods & InputEvent.BUTTON3_MASK) > 0) { rightClickNode = findNodeAt(e.getX(), e.getY()); rightClickX = e.getX(); rightClickY = e.getY(); } else if (picking == true && (keyMods & InputEvent.BUTTON1_MASK) > 0) { if (leftClickNode == null) { // Picking mode is on, but the user clicked away from a control point. // So clear the selections (unless Shift is pressed) and prepare for a box select. if ((keyMods & InputEvent.SHIFT_MASK) <= 0) clearSelectedNodes(); startBoxSelect(e); } else { if ((keyMods & InputEvent.SHIFT_MASK) > 0) { toggleSelectedNode(leftClickNode.series, leftClickNode.node); } else { replaceSelectedNode(leftClickNode.series, leftClickNode.node); } } } else if ((leftClickNode != null) && listContainsNode(leftClickNode, selectedNodes) == true) { XYPlot xyPlot = getChart().getXYPlot(); dragNode = leftClickNode; dragScreenXOld = e.getX(); dragScreenYOld = e.getY(); RectangleEdge xAxisLocation = xyPlot.getDomainAxisEdge(); RectangleEdge yAxisLocation = xyPlot.getRangeAxisEdge(); Rectangle2D dataArea = getScreenDataArea(); dragDataXOld = xyPlot.getDomainAxis().java2DToValue((double)e.getX(), dataArea, xAxisLocation); dragDataYOld = xyPlot.getRangeAxis().java2DToValue((double)e.getY(), dataArea, yAxisLocation); setDragging(true); // During dragging, the crosshairs lock onto the center of the dragNode double crosshairX = xyPlot.getDataset().getXValue(dragNode.series, dragNode.node); double crosshairY = xyPlot.getDataset().getYValue(dragNode.series, dragNode.node); double crosshairScreenX = xyPlot.getDomainAxis().valueToJava2D(crosshairX, dataArea, xAxisLocation); double crosshairScreenY = xyPlot.getRangeAxis().valueToJava2D(crosshairY, dataArea, yAxisLocation); updateCrosshairs((int)crosshairScreenX, (int)crosshairScreenY); picking = false; } else { super.mousePressed(e); } }
Example 19
Source Project: TencentKona-8 File: bug7146377.java License: GNU General Public License v2.0 | 4 votes |
private static boolean oldIsLeftMouseButton(MouseEvent e) { return ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0); }
Example 20
Source Project: openjdk-8-source File: bug7146377.java License: GNU General Public License v2.0 | 4 votes |
private static boolean oldIsRightMouseButton(MouseEvent e) { return ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK); }