protected void internalDoubleClick(MouseEvent e) { if (!(e.getComponent() instanceof JComponent)) return; JComponent inComponent = (JComponent) e.getComponent(); if (inComponent instanceof JTable) { JTable thisTable = (JTable) inComponent; int rowPoint = thisTable.rowAtPoint(new Point(e.getX(), e.getY())); Searcher whichSearch = (Searcher) thisTable.getValueAt(rowPoint, -1); whichSearch.execute(); } }
public void mousePressed(MouseEvent evt) { try { if (!neu && !wiedergeben && !verloren && !intro) { if (evt.getComponent() == rot) { if (farben[klick] != 1) verloren = true; else { klick++; rot.setIcon(new ImageIcon("files/Minigames/Senso/red_1.png")); soundAbspielen(soundR); } } else if (evt.getComponent() == gruen) { if (farben[klick] != 2) verloren = true; else { klick++; gruen.setIcon(new ImageIcon("files/Minigames/Senso/green_1.png")); soundAbspielen(soundG); } } else if (evt.getComponent() == blau) { if (farben[klick] != 3) verloren = true; else { klick++; blau.setIcon(new ImageIcon("files/Minigames/Senso/blue_1.png")); soundAbspielen(soundB); } } else if (evt.getComponent() == gelb) { if (farben[klick] != 4) verloren = true; else { klick++; gelb.setIcon(new ImageIcon("files/Minigames/Senso/yellow_1.png")); soundAbspielen(soundY); } } // else if (evt.getComponent() == beenden) // { // this.setVisible(false); // s.minispielEnde(null); // if (spiel != null) // spiel.interrupt(); // neustarten(false); // spiel = new Thread(this); // if (intro) // spiel.start(); // } } } catch (Exception e) { } }
/** Shows popup with forward history entries */ private void showForwardHistory(MouseEvent e) { JPopupMenu forwardMenu = new JPopupMenu("Forward History"); if (historyModel == null) { return; } Locale locale = ((JHelp) getControl()).getModel().getHelpSet().getLocale(); Enumeration items = historyModel.getForwardHistory().elements(); JMenuItem mi = null; int index = historyModel.getIndex() + 1; // while(items.hasMoreElements()){ for (int i = 0; items.hasMoreElements(); i++) { HelpModelEvent item = (HelpModelEvent) items.nextElement(); if (item != null) { String title = item.getHistoryName(); if (title == null) { title = HelpUtilities.getString(locale, "history.unknownTitle"); } mi = new JMenuItem(title); // mi.setToolTipText(item.getURL().getPath()); mi.addActionListener(new HistoryActionListener(i + index)); forwardMenu.add(mi); } } // if(e.isPopupTrigger()) forwardMenu.show(e.getComponent(), e.getX(), e.getY()); }
public void mousePressed(MouseEvent e) { if (e.getButton() == e.BUTTON3) { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); int index = list.locationToIndex(e.getPoint()); GetImageFile gif = new GetImageFile(files[index]); JTextArea area = new JTextArea( "File: " + gif.getImageString() + "\n" + "Score: " + nf.format(scores[index]) + "\n" + "Pairs: " + nrpairs[index]); area.setEditable(false); area.setBorder(BorderFactory.createLineBorder(Color.black)); area.setFont(new Font("times", Font.PLAIN, 12)); PopupFactory factory = PopupFactory.getSharedInstance(); popup = factory.getPopup( null, area, (int) e.getComponent().getLocationOnScreen().getX() + e.getX() + 25, (int) e.getComponent().getLocationOnScreen().getY() + e.getY()); popup.show(); } }
private void dispatchMouseEvent(MouseEvent event) { MouseListener[] mouseListeners = event.getComponent().getMouseListeners(); for (MouseListener listener : mouseListeners) { // skip all ToolTipManager's related listeners if (!listener.getClass().getName().startsWith("javax.swing.ToolTipManager")) { switch (event.getID()) { case MouseEvent.MOUSE_PRESSED: listener.mousePressed(event); break; case MouseEvent.MOUSE_RELEASED: listener.mouseReleased(event); break; case MouseEvent.MOUSE_CLICKED: listener.mouseClicked(event); break; case MouseEvent.MOUSE_EXITED: listener.mouseExited(event); break; case MouseEvent.MOUSE_ENTERED: listener.mouseEntered(event); break; default: throw new AssertionError(); } } } }
@Override public void mouseDragged(MouseEvent e) { if (!myDragging) return; MouseEvent event = SwingUtilities.convertMouseEvent(e.getComponent(), e, MyDivider.this); final ToolWindowAnchor anchor = myInfo.getAnchor(); final Point point = event.getPoint(); final Container windowPane = InternalDecorator.this.getParent(); myLastPoint = SwingUtilities.convertPoint(MyDivider.this, point, windowPane); myLastPoint.x = Math.min(Math.max(myLastPoint.x, 0), windowPane.getWidth()); myLastPoint.y = Math.min(Math.max(myLastPoint.y, 0), windowPane.getHeight()); final Rectangle bounds = InternalDecorator.this.getBounds(); if (anchor == ToolWindowAnchor.TOP) { InternalDecorator.this.setBounds(0, 0, bounds.width, myLastPoint.y); } else if (anchor == ToolWindowAnchor.LEFT) { InternalDecorator.this.setBounds(0, 0, myLastPoint.x, bounds.height); } else if (anchor == ToolWindowAnchor.BOTTOM) { InternalDecorator.this.setBounds( 0, myLastPoint.y, bounds.width, windowPane.getHeight() - myLastPoint.y); } else if (anchor == ToolWindowAnchor.RIGHT) { InternalDecorator.this.setBounds( myLastPoint.x, 0, windowPane.getWidth() - myLastPoint.x, bounds.height); } InternalDecorator.this.validate(); e.consume(); }
@Override public void mouseExited(MouseEvent e) { if (!resizing) { Component source = e.getComponent(); source.setCursor(sourceCursor); } }
public void mouseExited(MouseEvent e) { Component component = e.getComponent(); if (component instanceof AbstractButton) { AbstractButton button = (AbstractButton) component; button.setBorderPainted(false); } }
@Override public void mouseMoved(MouseEvent e) { Component source = e.getComponent(); Point location = e.getPoint(); direction = 0; if (location.x < dragInsets.left) direction += WEST; if (location.x > source.getWidth() - dragInsets.right - 1) direction += EAST; if (location.y < dragInsets.top) direction += NORTH; if (location.y > source.getHeight() - dragInsets.bottom - 1) direction += SOUTH; // Mouse is no longer over a resizable border if (direction == 0) { source.setCursor(sourceCursor); } else // use the appropriate resizable cursor { int cursorType = cursors.get(direction); Cursor cursor = Cursor.getPredefinedCursor(cursorType); source.setCursor(cursor); } }
private void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger()) { _mnuAllFilteredSelectedOrder.setEnabled(_modeManager.getMode().isQueryBuilder()); _popUp.show(e.getComponent(), e.getX(), e.getY()); } }
protected void processMouseEvent(final MouseEvent e) { if (e.isPopupTrigger() && e.getComponent().isShowing()) { super.processMouseEvent(e); return; } if (UIUtil.isCloseClick(e)) { myDecorator.fireHiddenSide(); return; } if (e.getButton() == MouseEvent.BUTTON1) { if (MouseEvent.MOUSE_PRESSED == e.getID()) { myPressedPoint = e.getPoint(); myPressedWhenSelected = isSelected(); myDragCancelled = false; } else if (MouseEvent.MOUSE_RELEASED == e.getID()) { finishDragging(); myPressedPoint = null; myDragButtonImage = null; } } super.processMouseEvent(e); }
@Override public void mousePressed(MouseEvent e) { // The mouseMoved event continually updates this variable if (direction == 0) return; // Setup for resizing. All future dragging calculations are done based // on the original bounds of the component and mouse pressed location. resizing = true; Component source = e.getComponent(); pressed = e.getPoint(); SwingUtilities.convertPointToScreen(pressed, source); bounds = source.getBounds(); // Making sure autoscrolls is false will allow for smoother resizing // of components if (source instanceof JComponent) { JComponent jc = (JComponent) source; autoscrolls = jc.getAutoscrolls(); jc.setAutoscrolls(false); } }
private boolean withinPopup(final AWTEvent event) { if (!myContent.isShowing()) return false; final MouseEvent mouse = (MouseEvent) event; final Point point = mouse.getPoint(); SwingUtilities.convertPointToScreen(point, mouse.getComponent()); return new Rectangle(myContent.getLocationOnScreen(), myContent.getSize()).contains(point); }
/** * Resize the component ensuring location and size is within the bounds of the parent container * and that the size is within the minimum and maximum constraints. * * <p>All calculations are done using the bounds of the component when the resizing started. */ @Override public void mouseDragged(MouseEvent e) { if (resizing == false) return; Component source = e.getComponent(); Point dragged = e.getPoint(); SwingUtilities.convertPointToScreen(dragged, source); changeBounds(source, direction, bounds, pressed, dragged); }
/** Restore the original state of the Component */ @Override public void mouseReleased(MouseEvent e) { resizing = false; Component source = e.getComponent(); source.setCursor(sourceCursor); if (source instanceof JComponent) { ((JComponent) source).setAutoscrolls(autoscrolls); } }
@Override public void mousePressed(MouseEvent e) { JList list = (JList) e.getComponent(); Point pt = e.getPoint(); int index = list.locationToIndex(pt); if (index >= 0) { JButton button = getButton(list, pt, index); if (Objects.nonNull(button)) { listRepaint(list, list.getCellBounds(index, index)); } } }
protected void processMouseMotionEvent(MouseEvent e) { MouseEvent transformedEvent = transformMouseEvent(e); if (mouseEnteredComponent == null) { mouseEnteredComponent = mouseCurrentComponent; } switch (e.getID()) { case MouseEvent.MOUSE_MOVED: if (mouseCurrentComponent != mouseEnteredComponent) { dispatchMouseEvent( createEnterExitEvent(mouseEnteredComponent, MouseEvent.MOUSE_EXITED, e)); dispatchMouseEvent( createEnterExitEvent(mouseCurrentComponent, MouseEvent.MOUSE_ENTERED, e)); } break; case MouseEvent.MOUSE_DRAGGED: if (mouseDraggedComponent == null) { mouseDraggedComponent = mouseEnteredComponent; } if (mouseEnteredComponent == mouseDraggedComponent && mouseCurrentComponent != mouseDraggedComponent) { dispatchMouseEvent( createEnterExitEvent(mouseDraggedComponent, MouseEvent.MOUSE_EXITED, e)); } else if (mouseEnteredComponent != mouseDraggedComponent && mouseCurrentComponent == mouseDraggedComponent) { dispatchMouseEvent( createEnterExitEvent(mouseDraggedComponent, MouseEvent.MOUSE_ENTERED, e)); } if (mouseDraggedComponent != null) { transformedEvent.setSource(mouseDraggedComponent); } break; } mouseEnteredComponent = mouseCurrentComponent; // dispatch MouseMotionEvent MouseMotionListener[] mouseMotionListeners = transformedEvent.getComponent().getMouseMotionListeners(); for (MouseMotionListener listener : mouseMotionListeners) { // skip all ToolTipManager's related listeners if (!listener.getClass().getName().startsWith("javax.swing.ToolTipManager")) { switch (transformedEvent.getID()) { case MouseEvent.MOUSE_MOVED: listener.mouseMoved(transformedEvent); break; case MouseEvent.MOUSE_DRAGGED: listener.mouseDragged(transformedEvent); break; default: throw new AssertionError(); } } } super.processMouseMotionEvent(e); }
/** * Determines whether or not the given mouse event is actually a popup trigger. * * @param aPoint the <em>corrected</em> mouse position, where the popup is to be shown, cannot be * <code>null</code>; * @param aEvent the mouse event that could be a popup trigger, cannot be <code>null</code>. */ private boolean handlePopupTrigger(final Point aPoint, final MouseEvent aEvent) { final boolean popupTrigger = isCursorPopupTrigger(aEvent); if (popupTrigger) { JPopupMenu contextMenu = createCursorPopup(aPoint, aEvent.getLocationOnScreen()); if (contextMenu != null) { contextMenu.show(aEvent.getComponent(), aEvent.getX(), aEvent.getY()); // Mark the event as consumed... aEvent.consume(); } } return popupTrigger; }
/** * Hook method which can be overriden by subclasses to provide specialised behaviour in the event * of a popup trigger. */ protected void handlePopupMenu(MouseEvent e, int x, int y) { Figure figure = drawing().findFigure(e.getX(), e.getY()); if (figure != null) { Object attribute = figure.getAttribute(Figure.POPUP_MENU); if (attribute == null) { figure = drawing().findFigureInside(e.getX(), e.getY()); } if (figure != null) { showPopupMenu(figure, e.getX(), e.getY(), e.getComponent()); } } }
private void processDrag(final MouseEvent e) { if (myDragCancelled) return; if (!isDraggingNow()) { if (myPressedPoint == null) return; if (isWithinDeadZone(e)) return; myDragPane = findLayeredPane(e); if (myDragPane == null) return; final BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); paint(image.getGraphics()); myDragButtonImage = new JLabel(new ImageIcon(image)) { public String toString() { return "Image for: " + StripeButton.this.toString(); } }; myDragPane.add(myDragButtonImage, JLayeredPane.POPUP_LAYER); myDragButtonImage.setSize(myDragButtonImage.getPreferredSize()); setVisible(false); myPane.startDrag(); myDragKeyEventDispatcher = new DragKeyEventDispatcher(); KeyboardFocusManager.getCurrentKeyboardFocusManager() .addKeyEventDispatcher(myDragKeyEventDispatcher); } if (!isDraggingNow()) return; Point xy = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), myDragPane); if (myPressedPoint != null) { xy.x -= myPressedPoint.x; xy.y -= myPressedPoint.y; } myDragButtonImage.setLocation(xy); SwingUtilities.convertPointToScreen(xy, myDragPane); final Stripe stripe = myPane.getStripeFor(new Rectangle(xy, myDragButtonImage.getSize()), (Stripe) getParent()); if (stripe == null) { if (myLastStripe != null) { myLastStripe.resetDrop(); } } else { if (myLastStripe != null && myLastStripe != stripe) { myLastStripe.resetDrop(); } stripe.processDropButton(this, myDragButtonImage, xy); } myLastStripe = stripe; }
@Override public void mousePressed(MouseEvent e) { Object o = e.getSource(); if (o instanceof TableCellEditor) { actionPerformed(null); } else if (o instanceof JButton) { // DEBUG: view button click -> control key down + edit button(same cell) press -> remain // selection color ButtonModel m = ((JButton) e.getComponent()).getModel(); if (m.isPressed() && table.isRowSelected(table.getEditingRow()) && e.isControlDown()) { setBackground(table.getBackground()); } } }
public void mouseClicked(MouseEvent evt) { if (evt.getComponent() == beenden) { this.setVisible(false); Game.Information[] infos = null; if (runde > 0) { infos = new Game.Information[2]; infos[0] = new Game.Information( Game.Information.AENDERN_BEWERBUNGSFAKTOR, Game.Information.ART_UM_WERT, runde); infos[1] = new Game.Information( Game.Information.AENDERN_SOZIALES, Game.Information.ART_UM_WERT, 2 * runde); } s.minispielEnde(infos); läuft = false; // if (spiel != null) // spiel.interrupt(); // neustarten(false); // spiel = new Thread(this); // if (intro) // spiel.start(); } else if (evt.getComponent() == neustart && verloren) neustarten(true); }
// Event forwarding. We need it if user does press-and-drag gesture for opening popup and // choosing item there. // It works in JComboBox, here we provide the same behavior private void dispatchEventToPopup(MouseEvent e) { if (myPopup != null && myPopup.isVisible()) { JComponent content = myPopup.getContent(); Rectangle rectangle = content.getBounds(); Point location = rectangle.getLocation(); SwingUtilities.convertPointToScreen(location, content); Point eventPoint = e.getLocationOnScreen(); rectangle.setLocation(location); if (rectangle.contains(eventPoint)) { MouseEvent event = SwingUtilities.convertMouseEvent(e.getComponent(), e, myPopup.getContent()); Component component = SwingUtilities.getDeepestComponentAt(content, event.getX(), event.getY()); if (component != null) component.dispatchEvent(event); } } }
/** * @param aEvent * @param aStartPoint */ protected void handleZoomRegion(final MouseEvent aEvent, final Point aStartPoint) { // For now, disabled by default as it isn't 100% working yet... if (Boolean.FALSE.equals(Boolean.valueOf(System.getProperty("zoomregionenabled", "false")))) { return; } final JComponent source = (JComponent) aEvent.getComponent(); final boolean dragging = (aEvent.getID() == MouseEvent.MOUSE_DRAGGED); final GhostGlassPane glassPane = (GhostGlassPane) SwingUtilities.getRootPane(source).getGlassPane(); Rectangle viewRect; final JScrollPane scrollPane = SwingComponentUtils.getAncestorOfClass(JScrollPane.class, source); if (scrollPane != null) { final JViewport viewport = scrollPane.getViewport(); viewRect = SwingUtilities.convertRectangle(viewport, viewport.getVisibleRect(), glassPane); } else { viewRect = SwingUtilities.convertRectangle(source, source.getVisibleRect(), glassPane); } final Point start = SwingUtilities.convertPoint(source, aStartPoint, glassPane); final Point current = SwingUtilities.convertPoint(source, aEvent.getPoint(), glassPane); if (dragging) { if (!glassPane.isVisible()) { glassPane.setVisible(true); glassPane.setRenderer(new RubberBandRenderer(), start, current, viewRect); } else { glassPane.updateRenderer(start, current, viewRect); } glassPane.repaintPartially(); } else /* if ( !dragging ) */ { // Fire off a signal to the zoom controller to do its job... this.controller.getZoomController().zoomRegion(aStartPoint, aEvent.getPoint()); glassPane.setVisible(false); } }
@Override public void mouseMoved(MouseEvent e) { JList list = (JList) e.getComponent(); Point pt = e.getPoint(); int index = list.locationToIndex(pt); if (!list.getCellBounds(index, index).contains(pt)) { if (prevIndex >= 0) { Rectangle r = list.getCellBounds(prevIndex, prevIndex); listRepaint(list, r); } index = -1; prevButton = null; return; } if (index >= 0) { JButton button = getButton(list, pt, index); ButtonsRenderer renderer = (ButtonsRenderer) list.getCellRenderer(); if (Objects.nonNull(button)) { renderer.rolloverIndex = index; if (!button.equals(prevButton)) { Rectangle r = list.getCellBounds(prevIndex, index); listRepaint(list, r); } } else { renderer.rolloverIndex = -1; Rectangle r = null; if (prevIndex == index) { if (prevIndex >= 0 && Objects.nonNull(prevButton)) { r = list.getCellBounds(prevIndex, prevIndex); } } else { r = list.getCellBounds(index, index); } listRepaint(list, r); prevIndex = -1; } prevButton = button; } prevIndex = index; }
// {{{ showPopupMenu method private void showPopupMenu(MouseEvent evt) { TreePath path = resultTree.getSelectionPath(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); popupMenu = new JPopupMenu(); Object userObj = node.getUserObject(); if (userObj instanceof HyperSearchFileNode || userObj instanceof HyperSearchResult) { popupMenu.add(new GoToNodeAction("hypersearch-results.open", M_OPEN)); popupMenu.add(new GoToNodeAction("hypersearch-results.open-view", M_OPEN_NEW_VIEW)); popupMenu.add( new GoToNodeAction("hypersearch-results.open-plain-view", M_OPEN_NEW_PLAIN_VIEW)); popupMenu.add(new GoToNodeAction("hypersearch-results.open-split", M_OPEN_NEW_SPLIT)); } if (!(userObj instanceof HyperSearchFolderNode)) popupMenu.add(new RemoveTreeNodeAction()); popupMenu.add(new ExpandChildTreeNodesAction()); if (userObj instanceof HyperSearchFolderNode || userObj instanceof HyperSearchOperationNode) { popupMenu.add(new CollapseChildTreeNodesAction()); if (userObj instanceof HyperSearchFolderNode) popupMenu.add(new NewSearchAction()); } if (userObj instanceof HyperSearchOperationNode) { popupMenu.add(new JPopupMenu.Separator()); HyperSearchOperationNode resultNode = (HyperSearchOperationNode) userObj; JCheckBoxMenuItem chkItem = new JCheckBoxMenuItem( jEdit.getProperty("hypersearch-results.tree-view"), resultNode.isTreeViewDisplayed()); chkItem.addActionListener(new TreeDisplayAction()); popupMenu.add(chkItem); popupMenu.add(new RedoSearchAction((HyperSearchOperationNode) userObj)); } popupMenu.add(new CopyToClipboardAction()); GUIUtilities.showPopupMenu(popupMenu, evt.getComponent(), evt.getX(), evt.getY()); evt.consume(); } // }}}
/** * Sets the current mouse cursor. * * @param aMouseCursor a mouse cursor, can be <code>null</code> to use the default cursor. */ protected final void setMouseCursor(final MouseEvent aEvent, final java.awt.Cursor aMouseCursor) { aEvent.getComponent().setCursor(aMouseCursor); }
/** * @param aEvent * @return */ protected final MouseEvent convertEvent(final MouseEvent aEvent) { JComponent view = SwingComponentUtils.getDeepestComponentAt(aEvent); return SwingUtilities.convertMouseEvent(aEvent.getComponent(), aEvent, view); }
private void nameContactNotesTableMouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { insertContactNotePopUpMenu.show(e.getComponent(), e.getX(), e.getY()); } }
@Override public void mouseExited(MouseEvent e) { JList list = (JList) e.getComponent(); ButtonsRenderer renderer = (ButtonsRenderer) list.getCellRenderer(); renderer.rolloverIndex = -1; }