下面列出了javax.swing.SwingUtilities#convertPointToScreen ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** @return true when conditions for auto slide OUT were met, false otherwise */
private boolean isSlideOutGesture(MouseEvent evt) {
if (resizer.isDragging()) {
activeArea = null;
return false;
}
if (activeArea == null) {
activeArea = computeActiveArea();
// comps are not yet ready, so do nothing
if (activeArea == null) {
return false;
}
}
Point mouseLoc = evt.getPoint();
//#118828
if (! (evt.getSource() instanceof Component)) {
return false;
}
SwingUtilities.convertPointToScreen(mouseLoc, (Component)evt.getSource());
boolean isMouseOut = !activeArea.contains(mouseLoc);
return isMouseOut;
}
@Override
public void userUndockedTopComponent(TopComponent tc, ModeImpl mode) {
Point tcLoc = tc.getLocation();
Dimension tcSize = tc.getSize();
SwingUtilities.convertPointToScreen(tcLoc, tc);
Rectangle bounds = new Rectangle(tcLoc, tcSize);
// #89100: update mode kind when undocking view in sliding mode
int modeKind = mode.getKind();
if (modeKind == Constants.MODE_KIND_SLIDING) {
modeKind = Constants.MODE_KIND_VIEW;
}
// #81479: unmaximize only if desirable
if (getCurrentMaximizedMode() == mode &&
mode.getOpenedTopComponents().size() == 1 &&
mode.getOpenedTopComponents().get(0) == tc) {
switchMaximizedMode(null);
}
ModeImpl newMode = createFloatingMode( bounds, modeKind );
moveTopComponentIntoMode( newMode, tc );
updateViewAfterDnD(false);
WindowManagerImpl.getInstance().doFirePropertyChange(
WindowManager.PROP_MODES, null, null);
}
/**
* Shows popup with ESC and TAB keys
*/
private void moreButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moreButtonActionPerformed
if (searchPopup != null) {
return;
}
JComponent tf = (JComponent) evt.getSource();
Point p = new Point(tf.getX(), tf.getY());
SwingUtilities.convertPointToScreen(p, this);
Rectangle usableScreenBounds = Utilities.getUsableScreenBounds();
if (p.x + specialkeyList.getWidth() > usableScreenBounds.width) {
p.x = usableScreenBounds.width - specialkeyList.getWidth();
}
if (p.y + specialkeyList.getHeight() > usableScreenBounds.height) {
p.y = usableScreenBounds.height - specialkeyList.getHeight();
}
//show special key popup
searchPopup = PopupFactory.getSharedInstance().getPopup(this, specialkeyList, p.x, p.y);
searchPopup.show();
}
public boolean right() {
Fix f = (Fix) getSelectedValue();
Iterable<? extends Fix> subfixes = HintsControllerImpl.getSubfixes(f);
if (subfixes.iterator().hasNext()) {
Rectangle r = getCellBounds(getSelectedIndex(), getSelectedIndex());
Point p = new Point(r.getLocation());
SwingUtilities.convertPointToScreen(p, this);
p.x += r.width;
// p.y += r.height;
HintsUI.getDefault().openSubList(subfixes, p);
return true;
}
return false;
}
public void firstShowPopup() throws Exception {
Point point = this.panel.getLocation();
SwingUtilities.convertPointToScreen(point, this.panel);
robot = new Robot(); // initialize shared static field first time
robot.mouseMove(point.x + 1, point.y + 1);
robot.mousePress(InputEvent.BUTTON3_MASK);
Thread.currentThread().setUncaughtExceptionHandler(this);
robot.mouseRelease(InputEvent.BUTTON3_MASK); // causes first AssertionError on EDT
}
private static ProfilerPopup create(Component invoker, Component content, int x, int y, int popupAlign, int resizeMode, Listener listener) {
Point location = new Point(x, y);
Dimension size = new Dimension();
Window owner = null;
if (invoker != null) {
SwingUtilities.convertPointToScreen(location, invoker);
size.setSize(invoker.getSize());
owner = SwingUtilities.getWindowAncestor(invoker);
}
return new ProfilerPopup(content, new Rectangle(location, size), popupAlign, owner, resizeMode, listener);
}
@Override
public Rectangle getScreenBounds() {
if (!list.isShowing())
return null;
Rectangle r = list.getUI().getCellBounds(list, selectedIndex,
selectedIndex);
Point p = new Point(0, 0);
SwingUtilities.convertPointToScreen(p, list);
r.x += p.x;
r.y += p.y;
int insetX = 0;
if (r.width > 30) {
insetX = 10;
} else if (r.width > 15) {
insetX = 4;
} else if (r.width > 8) {
insetX = 1;
}
r.x += insetX;
r.width -= 2 * insetX;
int insetY = 0;
if (r.height > 30) {
insetY = 10;
} else if (r.height > 15) {
insetY = 4;
} else if (r.height > 8) {
insetY = 1;
}
r.y += insetY;
r.height -= 2 * insetY;
return r;
}
private void test() throws Exception {
Robot robot = new Robot();
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
UIManager.setLookAndFeel(info.getClassName());
SwingUtilities.invokeAndWait(this);
toolkit.realSync(); // after creation
Thread.sleep(1000);
Point point = this.bar.getLocation();
SwingUtilities.convertPointToScreen(point, this.bar);
point.x += this.bar.getWidth() >> 2;
point.y += this.bar.getHeight() >> 1;
robot.mouseMove(point.x, point.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
toolkit.realSync(); // before validation
Thread.sleep(1000);
SwingUtilities.invokeAndWait(this);
if (this.bar != null) {
this.bar = null; // allows to reuse the instance
if (AUTO) { // error reporting only for automatic testing
throw new Error("TEST FAILED");
}
}
}
}
public void secondHidePopup() {
Point point = this.panel.getLocation();
SwingUtilities.convertPointToScreen(point, this.panel);
robot.mouseMove(point.x - 1, point.y - 1);
Thread.currentThread().setUncaughtExceptionHandler(this);
robot.mousePress(InputEvent.BUTTON1_MASK); // causes second AssertionError on EDT
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
public void secondHidePopup() {
Point point = this.panel.getLocation();
SwingUtilities.convertPointToScreen(point, this.panel);
robot.mouseMove(point.x - 1, point.y - 1);
Thread.currentThread().setUncaughtExceptionHandler(this);
robot.mousePress(InputEvent.BUTTON1_MASK); // causes second AssertionError on EDT
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
@Override
public void mouseMoved(MouseEvent e) {
Point p = e.getPoint();
int col = listClasses.columnAtPoint(p);
int row = listClasses.rowAtPoint(p);
if (col < 0 || row < 0) {
hidePopup();
return;
}
if (col == currentCol && row == currentRow) {
// the tooltip is (probably) shown, do not create again
return;
}
Rectangle cellRect = listClasses.getCellRect(row, col, false);
Point pt = cellRect.getLocation();
SwingUtilities.convertPointToScreen(pt, listClasses);
RenderedImage ri = new RenderedImage();
if (!updateTooltipImage(ri, row, col)) {
return;
}
ri.addMouseListener(this);
Popup popup = PopupFactory.getSharedInstance().getPopup(listClasses, ri, pt.x, pt.y);
popupContents = ri;
currentPopup = popup;
currentCol = col;
currentRow = row;
popup.show();
System.err.println("Hello");
}
public void firstShowPopup() throws Exception {
Point point = this.panel.getLocation();
SwingUtilities.convertPointToScreen(point, this.panel);
robot = new Robot(); // initialize shared static field first time
robot.mouseMove(point.x + 1, point.y + 1);
robot.mousePress(InputEvent.BUTTON3_MASK);
Thread.currentThread().setUncaughtExceptionHandler(this);
robot.mouseRelease(InputEvent.BUTTON3_MASK); // causes first AssertionError on EDT
}
@Override
public void mouseDragged(MouseEvent e) {
Point point = e.getPoint();
SwingUtilities.convertPointToScreen(point, (Component) e.getSource());
int distance_x = point.x - startPoint.x;
int distance_y = point.y - startPoint.y;
VistaSearchDialog.this.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
Point location = VistaSearchDialog.this.getLocation();
Point oldLocation = (Point) location.clone();
location.x += distance_x;
location.y += distance_y;
VistaSearchDialog.this.setLocation(location);
Rectangle clip = new Rectangle(oldLocation.x, oldLocation.y,
VistaSearchDialog.this.getWidth(),
VistaSearchDialog.this.getHeight());
clip.intersects(new Rectangle(location.x, location.y,
VistaSearchDialog.this.getWidth(),
VistaSearchDialog.this.getHeight()));
VistaSearchDialog.this.getParent().repaint(clip.x, clip.y,
clip.width, clip.height);
startPoint = point;
}
public void press() throws AWTException {
Point point = this.table.getCellRect(1, 1, false).getLocation();
SwingUtilities.convertPointToScreen(point, this.table);
Robot robot = new Robot();
robot.setAutoDelay(50);
robot.mouseMove(point.x + 1, point.y + 1);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
static void mouseClicked(Map<String, List<ElementDescription>> caption2Descriptions, JTextComponent c, Point p) {
if (caption2Descriptions.size() == 1 && caption2Descriptions.values().iterator().next().size() == 1) {
ElementDescription desc = caption2Descriptions.values().iterator().next().get(0);
desc.open();
return ;
}
Point position = new Point(p);
SwingUtilities.convertPointToScreen(position, c);
StringBuilder caption = new StringBuilder();
List<ElementDescription> descriptions = new LinkedList<ElementDescription>();
boolean first = true;
for (Entry<String, List<ElementDescription>> e : caption2Descriptions.entrySet()) {
if (!first) {
caption.append("/");
}
first = false;
caption.append(e.getKey());
descriptions.addAll(e.getValue());
}
PopupUtil.showPopup(new IsOverriddenPopup(caption.toString(), descriptions), caption.toString(), position.x, position.y, true, 0);
}
/**
* Convert a rectangle from coordinate system of Component c to
* screen coordinate system.
* @param r a non-null Rectangle
* @param c a Component whose coordinate system is used for conversion
*/
public void convertRectToScreen(Rectangle r, Component c) {
Point p = new Point(r.x, r.y);
SwingUtilities.convertPointToScreen(p, c);
r.x = p.x;
r.y = p.y;
}
private static void mouseClicked(Map<String, List<OverrideDescription>> caption2Descriptions, JTextComponent c, Point p) {
if (caption2Descriptions.size() == 1 && caption2Descriptions.values().iterator().next().size() == 1) {
OverrideDescription desc = caption2Descriptions.values().iterator().next().get(0);
FileObject file = desc.location.getLocation().getFileObject();
if (file != null) {
UiUtils.open(file, desc.location.getLocation().getOffset());
} else {
Toolkit.getDefaultToolkit().beep();
}
return ;
}
Point position = new Point(p);
SwingUtilities.convertPointToScreen(position, c);
StringBuilder caption = new StringBuilder();
List<OverrideDescription> descriptions = new LinkedList<OverrideDescription>();
boolean first = true;
for (Entry<String, List<OverrideDescription>> e : caption2Descriptions.entrySet()) {
if (!first) {
caption.append("/");
}
first = false;
caption.append(e.getKey());
descriptions.addAll(e.getValue());
}
PopupUtil.showPopup(new IsOverriddenPopup(caption.toString(), descriptions), caption.toString(), position.x, position.y, true, 0);
}
private static void resizePopup() {
popupWindow.pack();
Point point = new Point(0, 0);
SwingUtilities.convertPointToScreen(point, getMainWindow());
popupWindow.setLocation(point.x + (getMainWindow().getWidth() - popupWindow.getWidth()) / 2,
point.y + (getMainWindow().getHeight() - popupWindow.getHeight()) / 3);
}
@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);
}
}
private JButton createDropDownButton() {
Icon icon = ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/evaluator/drop_down_arrow.png", false);
final JButton button = new DropDownButton();
button.setIcon(icon);
String tooltipText = NbBundle.getMessage(CodeEvaluatorUI.class, "CTL_Expressions_Dropdown_tooltip");
button.setToolTipText(tooltipText);
button.setEnabled(false);
Dimension size = new Dimension(icon.getIconWidth() + 3, icon.getIconHeight() + 2);
button.setPreferredSize(size);
button.setMargin(new Insets(0, 0, 0, 0));
button.setFocusable(false);
AbstractAction action = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if ("pressed".equals(e.getActionCommand())) {
JComponent jc = (JComponent) e.getSource();
Point p = new Point(0, 0);
SwingUtilities.convertPointToScreen(p, jc);
if (!ButtonPopupSwitcher.isShown()) {
SwitcherTableItem[] items = createSwitcherItems();
ButtonPopupSwitcher.selectItem(jc, items, p.x, p.y);
}
//Other portion of issue 37487, looks funny if the
//button becomes pressed
if (jc instanceof AbstractButton) {
AbstractButton jb = (AbstractButton) jc;
jb.getModel().setPressed(false);
jb.getModel().setRollover(false);
jb.getModel().setArmed(false);
jb.repaint();
}
}
} // actionPerformed
@Override
public boolean isEnabled() {
return !getEditItemsList().isEmpty();
}
};
action.putValue(Action.SMALL_ICON, icon);
action.putValue(Action.SHORT_DESCRIPTION, tooltipText);
button.setAction(action);
return button;
}