Java Code Examples for javax.swing.SwingUtilities#convertPoint()
The following examples show how to use
javax.swing.SwingUtilities#convertPoint() .
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 File: QuickSearchPopup.java From netbeans with Apache License 2.0 | 6 votes |
private void computePopupBounds (Rectangle result, JLayeredPane lPane, int modelSize) { Dimension cSize = comboBar.getSize(); int width = getPopupWidth(); Point location = new Point(cSize.width - width - 1, comboBar.getBottomLineY() - 1); if (SwingUtilities.getWindowAncestor(comboBar) != null) { location = SwingUtilities.convertPoint(comboBar, location, lPane); } result.setLocation(location); // hack to make jList.getpreferredSize work correctly // JList is listening on ResultsModel same as us and order of listeners // is undefined, so we have to force update of JList's layout data jList1.setFixedCellHeight(15); jList1.setFixedCellHeight(-1); // end of hack jList1.setVisibleRowCount(modelSize); Dimension preferredSize = jList1.getPreferredSize(); preferredSize.width = width; preferredSize.height += statusPanel.getPreferredSize().height + 3; result.setSize(preferredSize); }
Example 2
Source File: InternalManagedWindow.java From stendhal with GNU General Public License v2.0 | 6 votes |
/** * Drag the window. * * @param point mouse location */ private void drag(Point point) { if (dragStart != null) { Component parent = getParent(); // calculate the total moved distance point = SwingUtilities.convertPoint(this, point, parent); point.x -= dragStart.x; point.y -= dragStart.y; relocate(point); for (WindowDragListener listener : dragListeners) { listener.windowDragged(this, point); } } }
Example 3
Source File: DragAndDropReorderPane.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
private void drag(Point point) { moveDraggingComponent(point); // reorder components overlapping with the dragging components mid-point Point draggingComponentMidPoint = SwingUtilities.convertPoint( draggingComponent, new Point(draggingComponent.getWidth() / 2, draggingComponent.getHeight() / 2), this ); Component component = getDefaultLayerComponentAt(draggingComponentMidPoint); if (component != null) { int index = getPosition(component); dragIndex = index < dragIndex ? index : index + 1; revalidate(); } }
Example 4
Source File: Handler.java From ramus with 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 5
Source File: MouseCapture.java From gcs with Mozilla Public License 2.0 | 5 votes |
private void redispatchMouseEvent(MouseEvent event) { Point glassPanePoint = event.getPoint(); Point containerPoint = SwingUtilities.convertPoint(mGlassPane, glassPanePoint, mCaptureComponent); Component component = SwingUtilities.getDeepestComponentAt(mCaptureComponent, containerPoint.x, containerPoint.y); if (component != null) { Point componentPoint = SwingUtilities.convertPoint(mGlassPane, glassPanePoint, component); component.dispatchEvent(new MouseEvent(component, event.getID(), event.getWhen(), event.getModifiersEx(), componentPoint.x, componentPoint.y, event.getClickCount(), event.isPopupTrigger())); } }
Example 6
Source File: NBTabbedPaneController.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void mouseReleased( MouseEvent e ) { // close button must not be active when selection change was // triggered by mouse press Point p = e.getPoint(); p = SwingUtilities.convertPoint( e.getComponent(), p, container ); int i = container.indexAtLocation( p.x, p.y ); if( e.isPopupTrigger() ) { if( i >= 0 ) i = container.indexOf( container.getComponentAt( i ) ); //Post a popup menu show request shouldPerformAction( TabDisplayer.COMMAND_POPUP_REQUEST, i, e ); } }
Example 7
Source File: ButtonPopupSwitcher.java From netbeans with Apache License 2.0 | 5 votes |
/** * Was mouse upon the popup table when mouse action had been taken. */ private boolean onSwitcherTable(MouseEvent e) { Point p = e.getPoint(); //#118828 if (! (e.getSource() instanceof Component)) { return false; } p = SwingUtilities.convertPoint((Component) e.getSource(), p, pTable); return pTable.contains(p); }
Example 8
Source File: PaletteUI.java From pumpernickel with MIT License | 5 votes |
@Override public void mousePressed(MouseEvent e) { Component c = e.getComponent(); JPalette palette; Point palettePoint = e.getPoint(); if (c instanceof JToggleButton) { palette = (JPalette) c.getParent(); palettePoint = SwingUtilities.convertPoint(c, palettePoint, palette); } else { palette = (JPalette) c; } if (!palette.isEnabled()) return; if (palette.isRequestFocusEnabled()) palette.requestFocus(); Insets i = palette.getInsets(); palettePoint.x = Math.max(i.left + 1, Math.min(palette.getWidth() - i.right - i.left - 1, palettePoint.x)); palettePoint.y = Math.max(i.top + 1, Math.min(palette.getHeight() - i.top - i.bottom - 1, palettePoint.y)); Component c2 = SwingUtilities.getDeepestComponentAt(palette, palettePoint.x, palettePoint.y); if (c2 != null && c2 instanceof JToggleButton) { Color f = c2.getForeground(); palette.getColorSelectionModel().setSelectedColor(f); } }
Example 9
Source File: DefaultTabbedContainerUI.java From netbeans with Apache License 2.0 | 5 votes |
public Polygon getInsertTabIndication(int idx) { Polygon result = tabDisplayer.getUI().getInsertTabIndication(idx); scratchPoint.setLocation(0,0); Point p = SwingUtilities.convertPoint(tabDisplayer, scratchPoint, container); result.translate (-p.x, -p.y); return appendContentBoundsTo(result); }
Example 10
Source File: EditableHeaderUI.java From chipster with MIT License | 5 votes |
private void setDispatchComponent(MouseEvent e) { Component editorComponent = header.getEditorComponent(); Point p = e.getPoint(); Point p2 = SwingUtilities.convertPoint(header, p, editorComponent); dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent, p2.x, p2.y); }
Example 11
Source File: CustomizedToolbar.java From pumpernickel with MIT License | 5 votes |
public void dragOver(DropTargetDragEvent dtde) { if (draggingComponent == null) { dtde.rejectDrag(); } else { Point p = dtde.getLocation(); p = SwingUtilities.convertPoint( ((DropTarget) dtde.getSource()).getComponent(), p, CustomizedToolbar.this); String[] contents = getContents(p); updateContents(contents); dtde.acceptDrag(DnDConstants.ACTION_MOVE); } }
Example 12
Source File: FlatTitlePane.java From FlatLaf with Apache License 2.0 | 5 votes |
protected Rectangle getMenuBarBounds() { Insets insets = rootPane.getInsets(); Rectangle bounds = new Rectangle( SwingUtilities.convertPoint( menuBarPlaceholder, -insets.left, -insets.top, rootPane ), menuBarPlaceholder.getSize() ); // add menu bar bottom border insets to bounds so that menu bar overlaps // title pane border (menu bar border is painted over title pane border) Insets borderInsets = getBorder().getBorderInsets( this ); bounds.height += borderInsets.bottom; return FlatUIUtils.subtractInsets( bounds, UIScale.scale( getMenuBarMargins() ) ); }
Example 13
Source File: FakeSheetWindowListener.java From pumpernickel with MIT License | 5 votes |
protected void repositionDialog() { Point topLeft = new Point(0, 0); topLeft = SwingUtilities.convertPoint(dialogAnchor, topLeft, window1); int x = window1.getX() - window2.getWidth() / 2 + dialogAnchor.getWidth() / 2 + topLeft.x; int y = topLeft.y + dialogAnchor.getHeight() + 1 + window1.getY(); Rectangle optionsBounds = new Rectangle(x, y, window2.getWidth(), window2.getHeight()); SwingUtilities.convertRectangle(dialogAnchor, optionsBounds, window1); window2.setBounds(optionsBounds); }
Example 14
Source File: mxGraphHandler.java From blog-codes with Apache License 2.0 | 5 votes |
/** * */ public Point convertPoint(Point pt) { pt = SwingUtilities.convertPoint(graphComponent, pt, graphComponent.getGraphControl()); pt.x -= graphComponent.getHorizontalScrollBar().getValue(); pt.y -= graphComponent.getVerticalScrollBar().getValue(); return pt; }
Example 15
Source File: PSheet.java From netbeans with Apache License 2.0 | 5 votes |
public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { Point p = SwingUtilities.convertPoint((Component) e.getSource(), e.getPoint(), this); updateSheetTableSelection(e); popupRequested(p); } }
Example 16
Source File: PSheet.java From netbeans with Apache License 2.0 | 5 votes |
public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { Point p = SwingUtilities.convertPoint((Component) e.getSource(), e.getPoint(), this); updateSheetTableSelection(e); popupRequested(p); } }
Example 17
Source File: SimpleTestStepLocation.java From netbeans with Apache License 2.0 | 5 votes |
private Component getDeepestComponent(MouseEvent e) { Point contentPanePoint = SwingUtilities.convertPoint(glassPane, e.getPoint(), contentPane); return SwingUtilities.getDeepestComponentAt( contentPane, contentPanePoint.x, contentPanePoint.y); }
Example 18
Source File: JLightweightFrame.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Constructs a new, initially invisible {@code JLightweightFrame} * instance. */ public JLightweightFrame() { super(); copyBufferEnabled = "true".equals(AccessController. doPrivileged(new GetPropertyAction("swing.jlf.copyBufferEnabled", "true"))); add(rootPane, BorderLayout.CENTER); setFocusTraversalPolicy(new LayoutFocusTraversalPolicy()); if (getGraphicsConfiguration().isTranslucencyCapable()) { setBackground(new Color(0, 0, 0, 0)); } layoutSizeListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent e) { Dimension d = (Dimension)e.getNewValue(); if ("preferredSize".equals(e.getPropertyName())) { content.preferredSizeChanged(d.width, d.height); } else if ("maximumSize".equals(e.getPropertyName())) { content.maximumSizeChanged(d.width, d.height); } else if ("minimumSize".equals(e.getPropertyName())) { content.minimumSizeChanged(d.width, d.height); } } }; repaintListener = (JComponent c, int x, int y, int w, int h) -> { Window jlf = SwingUtilities.getWindowAncestor(c); if (jlf != JLightweightFrame.this) { return; } Point p = SwingUtilities.convertPoint(c, x, y, jlf); Rectangle r = new Rectangle(p.x, p.y, w, h).intersection( new Rectangle(0, 0, bbImage.getWidth() / scaleFactor, bbImage.getHeight() / scaleFactor)); if (!r.isEmpty()) { notifyImageUpdated(r.x, r.y, r.width, r.height); } }; SwingAccessor.getRepaintManagerAccessor().addRepaintListener( RepaintManager.currentManager(this), repaintListener); }
Example 19
Source File: JLightweightFrame.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * Constructs a new, initially invisible {@code JLightweightFrame} * instance. */ public JLightweightFrame() { super(); copyBufferEnabled = "true".equals(AccessController. doPrivileged(new GetPropertyAction("swing.jlf.copyBufferEnabled", "true"))); add(rootPane, BorderLayout.CENTER); setFocusTraversalPolicy(new LayoutFocusTraversalPolicy()); if (getGraphicsConfiguration().isTranslucencyCapable()) { setBackground(new Color(0, 0, 0, 0)); } layoutSizeListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent e) { Dimension d = (Dimension)e.getNewValue(); if ("preferredSize".equals(e.getPropertyName())) { content.preferredSizeChanged(d.width, d.height); } else if ("maximumSize".equals(e.getPropertyName())) { content.maximumSizeChanged(d.width, d.height); } else if ("minimumSize".equals(e.getPropertyName())) { content.minimumSizeChanged(d.width, d.height); } } }; repaintListener = (JComponent c, int x, int y, int w, int h) -> { Window jlf = SwingUtilities.getWindowAncestor(c); if (jlf != JLightweightFrame.this) { return; } Point p = SwingUtilities.convertPoint(c, x, y, jlf); Rectangle r = new Rectangle(p.x, p.y, w, h).intersection( new Rectangle(0, 0, bbImage.getWidth() / scaleFactor, bbImage.getHeight() / scaleFactor)); if (!r.isEmpty()) { notifyImageUpdated(r.x, r.y, r.width, r.height); } }; SwingAccessor.getRepaintManagerAccessor().addRepaintListener( RepaintManager.currentManager(this), repaintListener); }
Example 20
Source File: mxGraphHandler.java From blog-codes with Apache License 2.0 | 4 votes |
/** * * @param e */ public void dragOver(DropTargetDragEvent e) { if (canImport) { mouseDragged(createEvent(e)); mxGraphTransferHandler handler = getGraphTransferHandler(e); if (handler != null) { mxGraph graph = graphComponent.getGraph(); double scale = graph.getView().getScale(); Point pt = SwingUtilities.convertPoint(graphComponent, e.getLocation(), graphComponent.getGraphControl()); pt = graphComponent.snapScaledPoint(new mxPoint(pt)).getPoint(); handler.setLocation(new Point(pt)); int dx = 0; int dy = 0; // Centers the preview image if (centerPreview && transferBounds != null) { dx -= Math.round(transferBounds.getWidth() * scale / 2); dy -= Math.round(transferBounds.getHeight() * scale / 2); } // Sets the drop offset so that the location in the transfer // handler reflects the actual mouse position handler.setOffset(new Point((int) graph.snap(dx / scale), (int) graph.snap(dy / scale))); pt.translate(dx, dy); // Shifts the preview so that overlapping parts do not // affect the centering if (transferBounds != null && dragImage != null) { dx = (int) Math .round((dragImage.getIconWidth() - 2 - transferBounds .getWidth() * scale) / 2); dy = (int) Math .round((dragImage.getIconHeight() - 2 - transferBounds .getHeight() * scale) / 2); pt.translate(-dx, -dy); } if (!handler.isLocalDrag() && previewBounds != null) { setPreviewBounds(new Rectangle(pt, previewBounds.getSize())); } } } else { e.rejectDrag(); } }