List of usage examples for javax.swing SwingUtilities convertPoint
public static Point convertPoint(Component source, Point aPoint, Component destination)
aPoint
in source
coordinate system to destination
coordinate system. From source file:Main.java
public static MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination) { Point p = SwingUtilities.convertPoint(source, new Point(sourceEvent.getX(), sourceEvent.getY()), destination);/* w ww .j a v a2s .c o m*/ Component newSource; if (destination != null) newSource = destination; else newSource = source; MouseEvent newEvent; if (sourceEvent instanceof MouseWheelEvent) { MouseWheelEvent sourceWheelEvent = (MouseWheelEvent) sourceEvent; newEvent = new MouseWheelEvent(newSource, sourceWheelEvent.getID(), sourceWheelEvent.getWhen(), sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y, sourceWheelEvent.getClickCount(), sourceWheelEvent.isPopupTrigger(), sourceWheelEvent.getScrollType(), sourceWheelEvent.getScrollAmount(), sourceWheelEvent.getWheelRotation()); } else if (sourceEvent instanceof MenuDragMouseEvent) { MenuDragMouseEvent sourceMenuDragEvent = (MenuDragMouseEvent) sourceEvent; newEvent = new MenuDragMouseEvent(newSource, sourceMenuDragEvent.getID(), sourceMenuDragEvent.getWhen(), sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y, sourceMenuDragEvent.getClickCount(), sourceMenuDragEvent.isPopupTrigger(), sourceMenuDragEvent.getPath(), sourceMenuDragEvent.getMenuSelectionManager()); } else { newEvent = new MouseEvent(newSource, sourceEvent.getID(), sourceEvent.getWhen(), sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y, sourceEvent.getClickCount(), sourceEvent.isPopupTrigger(), sourceEvent.getButton()); } return newEvent; }
From source file:Main.java
public static Point convertPoint(Component src, Point p, Component dst) { final Point result = new Point(p); SwingUtilities.convertPoint(src, result, dst); return result; }
From source file:Main.java
public static Component findComponentUnderGlassPaneAt(Point p, Component top) { Component c = null;// w w w. jav a2 s . co m if (top.isShowing()) { if (top instanceof RootPaneContainer) c = ((RootPaneContainer) top).getLayeredPane().findComponentAt( SwingUtilities.convertPoint(top, p, ((RootPaneContainer) top).getLayeredPane())); else c = ((Container) top).findComponentAt(p); } return c; }
From source file:Main.java
@Override public boolean isCellEditable(final EventObject event) { Object source = event.getSource(); if (!(source instanceof JTree) || !(event instanceof MouseEvent)) { return false; }//from www . ja v a 2s. c o m JTree tree = (JTree) source; MouseEvent mouseEvent = (MouseEvent) event; TreePath path = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY()); if (path == null) { return false; } Object node = path.getLastPathComponent(); if (node == null || !(node instanceof DefaultMutableTreeNode)) { return false; } Rectangle r = tree.getPathBounds(path); if (r == null) { return false; } Dimension d = panel.getPreferredSize(); r.setSize(new Dimension(d.width, r.height)); if (r.contains(mouseEvent.getX(), mouseEvent.getY())) { Point pt = SwingUtilities.convertPoint(tree, mouseEvent.getPoint(), panel); Object o = SwingUtilities.getDeepestComponentAt(panel, pt.x, pt.y); if (o instanceof JComboBox) { comboBox.showPopup(); } else if (o instanceof Component) { Object oo = SwingUtilities.getAncestorOfClass(JComboBox.class, (Component) o); if (oo instanceof JComboBox) { comboBox.showPopup(); } } return true; } return delegate.isCellEditable(event); }
From source file:Diva.java
@Override protected void processMouseMotionEvent(MouseEvent e, JLayer l) { Point p = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), l); mX = p.x;/*from w w w .ja va2 s . c om*/ mY = p.y; l.repaint(); }
From source file:it.unibas.spicygui.vista.listener.MyMouseEventListener.java
private void dispacciaEvento(Component com, MouseEvent e, Point point, boolean draggedEvent) { if (com == null) { com = SwingUtilities.getDeepestComponentAt(pannelloPrincipale, point.x, point.y); }//from w w w . j a v a2 s . c o m Point componentPoint = SwingUtilities.convertPoint(component, e.getPoint(), com); if (com != null) { if (com instanceof JTree) { TreePath treePath = ((JTree) com).getPathForLocation(componentPoint.x, componentPoint.y); if (treePath == null || draggedEvent) { jLayeredPane.moveToFront(component); component.updateUI(); if (e.getButton() == MouseEvent.BUTTON3) { return; } } } com.dispatchEvent(new MouseEvent(com, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); jLayeredPane.moveToFront(component); component.updateUI(); } jLayeredPane.moveToFront(component); component.updateUI(); }
From source file:it.unibas.spicygui.vista.listener.ScrollPaneAdjustmentListener.java
private Point findNewLocationForTree(ICaratteristicheWidget icaratteristicheWidget, JTree albero) { CaratteristicheWidgetTree caratteristicheWidget = (CaratteristicheWidgetTree) icaratteristicheWidget; Point oldPoint = caratteristicheWidget.getPosizione(); if (logger.isTraceEnabled()) logger.trace("oldPoint: " + oldPoint); TreePath treePath = caratteristicheWidget.getTreePath(); Rectangle rect = albero.getPathBounds(treePath); if (rect != null && this.type.equalsIgnoreCase(caratteristicheWidget.getTreeType())) { Point newPoint = albero.getPathBounds(treePath).getLocation(); Point convertedPoint = SwingUtilities.convertPoint(source, newPoint, glassPane); if (logger.isTraceEnabled()) logger.trace(" -- newPoint: " + convertedPoint); if (caratteristicheWidget.getTreeType().equalsIgnoreCase(Costanti.TREE_SOURCE)) { return new Point( convertedPoint.x + (albero.getPathBounds(treePath).width - Costanti.OFFSET_X_WIDGET_SOURCE), convertedPoint.y/*w w w .j av a 2 s . co m*/ + (albero.getPathBounds(treePath).height / Costanti.OFFSET_Y_WIDGET_SOURCE)); } return new Point(convertedPoint.x, convertedPoint.y + 5); } else if (this.type.equalsIgnoreCase(caratteristicheWidget.getTreeType())) { TreePath treePathInterno = treePath; Rectangle rectInterno = albero.getPathBounds(treePathInterno); while (rectInterno == null) { if (treePathInterno == null) { return null; } treePathInterno = treePathInterno.getParentPath(); rectInterno = albero.getPathBounds(treePathInterno); } Point newPoint = albero.getPathBounds(treePathInterno).getLocation(); Point convertedPoint = SwingUtilities.convertPoint(source, newPoint, glassPane); if (logger.isTraceEnabled()) logger.trace(" -- newPoint: " + convertedPoint); if (caratteristicheWidget.getTreeType().equalsIgnoreCase(Costanti.TREE_SOURCE)) { return new Point( convertedPoint.x + (albero.getPathBounds(treePathInterno).width - Costanti.OFFSET_X_WIDGET_SOURCE), convertedPoint.y + (albero.getPathBounds(treePathInterno).height / Costanti.OFFSET_Y_WIDGET_SOURCE)); } return new Point(convertedPoint.x, convertedPoint.y + 5); } return null; }
From source file:it.unibas.spicygui.vista.listener.WidgetMoveExpansionListener.java
private Point findNewLocationForTree(ICaratteristicheWidget icaratteristicheWidget, JTree albero) { CaratteristicheWidgetTree caratteristicheWidget = (CaratteristicheWidgetTree) icaratteristicheWidget; Point oldPoint = caratteristicheWidget.getPosizione(); if (logger.isTraceEnabled()) logger.trace("oldPoint: " + oldPoint); TreePath treePath = caratteristicheWidget.getTreePath(); Rectangle rect = albero.getPathBounds(treePath); if (rect != null && this.type.equalsIgnoreCase(caratteristicheWidget.getTreeType())) { Point newPoint = albero.getPathBounds(treePath).getLocation(); Point convertedPoint = SwingUtilities.convertPoint(source, newPoint, glassPane); if (logger.isTraceEnabled()) logger.trace(" -- newPoint: " + convertedPoint); if (caratteristicheWidget.getTreeType().equalsIgnoreCase(Costanti.TREE_SOURCE)) { return new Point( convertedPoint.x + (albero.getPathBounds(treePath).width - Costanti.OFFSET_X_WIDGET_SOURCE), convertedPoint.y/*from www . j a v a 2 s . co m*/ + (albero.getPathBounds(treePath).height / Costanti.OFFSET_Y_WIDGET_SOURCE)); } return new Point(convertedPoint.x, convertedPoint.y + 5); } else if (this.type.equalsIgnoreCase(caratteristicheWidget.getTreeType())) { TreePath treePathInterno = treePath; Rectangle rectInterno = albero.getPathBounds(treePathInterno); while (rectInterno == null) { if (treePathInterno == null) { return null; } treePathInterno = treePathInterno.getParentPath(); rectInterno = albero.getPathBounds(treePathInterno); } Point newPoint = albero.getPathBounds(treePathInterno).getLocation(); Point convertedPoint = SwingUtilities.convertPoint(source, newPoint, glassPane); if (logger.isTraceEnabled()) logger.trace(" -- newPoint: " + convertedPoint); if (caratteristicheWidget.getTreeType().equalsIgnoreCase(Costanti.TREE_SOURCE)) { return new Point( convertedPoint.x + (albero.getPathBounds(treePathInterno).width - Costanti.OFFSET_X_WIDGET_SOURCE), convertedPoint.y + (albero.getPathBounds(treePathInterno).height / Costanti.OFFSET_Y_WIDGET_SOURCE)); } return new Point(convertedPoint.x, convertedPoint.y + 5); } return null; }
From source file:cz.muni.fi.javaseminar.kafa.bookregister.gui.MainWindow.java
private void initBooksTable() { booksTable.getColumnModel().getColumn(2) .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy"))); booksTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() { @Override//from w ww. j a va 2 s . c o m public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected, boolean hasFocus, int row, int column) { if (value instanceof Date) { // You could use SimpleDateFormatter instead value = new SimpleDateFormat("dd. MM. yyyy").format(value); } return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column); } }); booksTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JPopupMenu booksPopupMenu = new JPopupMenu(); JMenuItem deleteBook = new JMenuItem("Delete"); booksPopupMenu.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { int rowAtPoint = booksTable.rowAtPoint( SwingUtilities.convertPoint(booksPopupMenu, new Point(0, 0), booksTable)); if (rowAtPoint > -1) { booksTable.setRowSelectionInterval(rowAtPoint, rowAtPoint); } } }); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // TODO Auto-generated method stub } @Override public void popupMenuCanceled(PopupMenuEvent e) { // TODO Auto-generated method stub } }); deleteBook.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (booksTable.getSelectedRow() == -1) { JOptionPane.showMessageDialog(MainWindow.this, "You haven't selected any book."); return; } Book book = booksTableModel.getBooks().get(booksTable.getSelectedRow()); new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { log.debug("Deleting book: " + book.getName() + " from database."); bookManager.deleteBook(book); return null; } @Override protected void done() { try { get(); } catch (Exception e) { log.error("There was an exception thrown while deleting a book.", e); return; } updateModel(); } }.execute(); } }); booksPopupMenu.add(deleteBook); booksTable.setComponentPopupMenu(booksPopupMenu); }
From source file:it.unibas.spicygui.vista.listener.MyMouseEventListener.java
private void dispacciaEventoDrag(Component com, MouseEvent e, Point point, boolean draggedEvent) { Point componentPoint = SwingUtilities.convertPoint(component, e.getPoint(), com); if (com != null) { if (com instanceof JTree) { TreePath treePath = ((JTree) com).getPathForLocation(componentPoint.x, componentPoint.y); if (treePath == null || draggedEvent) { component.updateUI();// w w w . j a v a2s. c o m return; } } if ((!(com instanceof JScrollBar) && (tmp12 instanceof JScrollBar))) { jLayeredPane.moveToFront(component); component.updateUI(); return; } com.dispatchEvent(new MouseEvent(component, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); jLayeredPane.moveToFront(component); component.updateUI(); } jLayeredPane.moveToFront(component); component.updateUI(); }