javax.swing.SwingUtilities#convertPoint ( )源码实例Demo

下面列出了javax.swing.SwingUtilities#convertPoint ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: stendhal   文件: InternalManagedWindow.java
/**
 * 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);
		}
	}
}
 
源代码2 项目: runelite   文件: DragAndDropReorderPane.java
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();
	}
}
 
源代码3 项目: netbeans   文件: QuickSearchPopup.java
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);
}
 
源代码4 项目: netbeans   文件: SimpleTestStepLocation.java
private Component getDeepestComponent(MouseEvent e) {
    Point contentPanePoint
            = SwingUtilities.convertPoint(glassPane,
                                          e.getPoint(),
                                          contentPane);
    return SwingUtilities.getDeepestComponentAt(
                    contentPane,
                    contentPanePoint.x,
                    contentPanePoint.y);
}
 
源代码5 项目: netbeans   文件: PSheet.java
public void mousePressed(MouseEvent e) {
    if (e.isPopupTrigger()) {
        Point p = SwingUtilities.convertPoint((Component) e.getSource(), e.getPoint(), this);
        updateSheetTableSelection(e);
        popupRequested(p);
    }
}
 
源代码6 项目: netbeans   文件: PSheet.java
public void mouseReleased(MouseEvent e) {
    if (e.isPopupTrigger()) {
        Point p = SwingUtilities.convertPoint((Component) e.getSource(), e.getPoint(), this);
        updateSheetTableSelection(e);
        popupRequested(p);
    }
}
 
源代码7 项目: blog-codes   文件: mxGraphHandler.java
/**
 * 
 */
public Point convertPoint(Point pt)
{
	pt = SwingUtilities.convertPoint(graphComponent, pt,
			graphComponent.getGraphControl());

	pt.x -= graphComponent.getHorizontalScrollBar().getValue();
	pt.y -= graphComponent.getVerticalScrollBar().getValue();

	return pt;
}
 
源代码8 项目: pumpernickel   文件: FakeSheetWindowListener.java
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);
}
 
源代码9 项目: FlatLaf   文件: FlatTitlePane.java
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() ) );
}
 
源代码10 项目: ramus   文件: Handler.java
@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);
    }

}
 
源代码11 项目: pumpernickel   文件: CustomizedToolbar.java
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);
	}
}
 
源代码12 项目: chipster   文件: EditableHeaderUI.java
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);
}
 
源代码13 项目: netbeans   文件: DefaultTabbedContainerUI.java
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);
}
 
源代码14 项目: pumpernickel   文件: PaletteUI.java
@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);
	}
}
 
源代码15 项目: netbeans   文件: ButtonPopupSwitcher.java
/**
 * 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);
}
 
源代码16 项目: netbeans   文件: NBTabbedPaneController.java
@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 );
    }
}
 
源代码17 项目: gcs   文件: MouseCapture.java
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()));
    }
}
 
源代码18 项目: jdk8u_jdk   文件: JLightweightFrame.java
/**
 * 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);
}
 
源代码19 项目: blog-codes   文件: mxGraphHandler.java
/**
 * 
 * @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();
	}
}
 
源代码20 项目: dragonwell8_jdk   文件: JLightweightFrame.java
/**
 * 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);
}