javax.swing.PopupFactory#getPopup ( )源码实例Demo

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

源代码1 项目: visualvm   文件: ProfilerTableHover.java
private void showPopup(Painter p, Rectangle rect) {
    mouse.deinstall();
    
    Point l = table.getLocationOnScreen();
    
    rect.translate(l.x, l.y);
    popupRect = rect;
    popupLocation = new Point(l.x + p.getX(), l.y + p.getY());
    
    PopupFactory popupFactory = PopupFactory.getSharedInstance();
    popup = popupFactory.getPopup(table, p, popupLocation.x, popupLocation.y);
    popup.show();
    
    paranoid = new Paranoid(p);
    paranoid.install();
    
    awt = new AWT();
    awt.install();
}
 
源代码2 项目: Logisim   文件: LayoutPopupManager.java
private void showPopup(Set<AppearancePort> portObjects) {
	dragStart = null;
	CircuitState circuitState = canvas.getCircuitState();
	if (circuitState == null)
		return;
	ArrayList<Instance> ports = new ArrayList<Instance>(portObjects.size());
	for (AppearancePort portObject : portObjects) {
		ports.add(portObject.getPin());
	}

	hideCurrentPopup();
	LayoutThumbnail layout = new LayoutThumbnail();
	layout.setCircuit(circuitState, ports);
	JViewport owner = canvasPane.getViewport();
	Point ownerLoc = owner.getLocationOnScreen();
	Dimension ownerDim = owner.getSize();
	Dimension layoutDim = layout.getPreferredSize();
	int x = ownerLoc.x + Math.max(0, ownerDim.width - layoutDim.width - 5);
	int y = ownerLoc.y + Math.max(0, ownerDim.height - layoutDim.height - 5);
	PopupFactory factory = PopupFactory.getSharedInstance();
	Popup popup = factory.getPopup(canvasPane.getViewport(), layout, x, y);
	popup.show();
	curPopup = popup;
	curPopupTime = System.currentTimeMillis();
}
 
源代码3 项目: netbeans   文件: VisualDesignerPopupMenuUI.java
@Override
public Popup getPopup(JPopupMenu popup, int x, int y) {
    PopupFactory popupFactory = layer.hackedPopupFactory;
    if(popupFactory == null) {
        return super.getPopup(popup, x, y);
    }
    return popupFactory.getPopup(popup.getInvoker(), popup, x, y);
}
 
源代码4 项目: netbeans   文件: CompletionLayoutPopup.java
/**
 * Create and display the popup at the given bounds.
 *
 * @param popupBounds location and size of the popup.
 * @param displayAboveCaret whether the popup is displayed above the anchor
 *  bounds or below them (it does not be right above them).
 */
private void show(Rectangle popupBounds, boolean displayAboveCaret) {
    // Hide the original popup if exists
    if (popup != null) {
        popup.hide();
        popup = null;
    }
    
    // Explicitly set the preferred size
    Dimension origPrefSize = getPreferredSize();
    Dimension newPrefSize = popupBounds.getSize();
    JComponent contComp = getContentComponent();
    if (contComp == null){
        return;
    }
    contComp.setPreferredSize(newPrefSize);
    showRetainedPreferredSize = newPrefSize.equals(origPrefSize);
    
    PopupFactory factory = PopupFactory.getSharedInstance();
    // Lightweight completion popups don't work well on the Mac - trying
    // to click on its scrollbars etc. will cause the window to be hidden,
    // so force a heavyweight parent by passing in owner==null. (#96717)
    
    JTextComponent owner = layout.getEditorComponent();
    if(owner != null && owner.getClientProperty("ForceHeavyweightCompletionPopup") != null) {
        owner = null;
    }
    
    // #76648: Autocomplete box is too close to text
    if(displayAboveCaret && Utilities.isMac()) {
        popupBounds.y -= 10;
    }
    
    popup = factory.getPopup(owner, contComp, popupBounds.x, popupBounds.y);
    popup.show();

    this.popupBounds = popupBounds;
    this.displayAboveCaret = displayAboveCaret;
}
 
源代码5 项目: netbeans   文件: CompletionLayoutPopup.java
/**
 * Create and display the popup at the given bounds.
 *
 * @param popupBounds location and size of the popup.
 * @param displayAboveCaret whether the popup is displayed above the anchor
 *  bounds or below them (it does not be right above them).
 */
private void show(Rectangle popupBounds, boolean displayAboveCaret) {
    // Hide the original popup if exists
    if (popup != null) {
        popup.hide();
        popup = null;
    }

    // Explicitly set the preferred size
    Dimension origPrefSize = getPreferredSize();
    Dimension newPrefSize = popupBounds.getSize();
    JComponent contComp = getContentComponent();
    if (contComp == null){
        return;
    }
    contComp.setPreferredSize(newPrefSize);
    showRetainedPreferredSize = newPrefSize.equals(origPrefSize);

    PopupFactory factory = PopupFactory.getSharedInstance();
    // Lightweight completion popups don't work well on the Mac - trying
    // to click on its scrollbars etc. will cause the window to be hidden,
    // so force a heavyweight parent by passing in owner==null. (#96717)

    JTextComponent owner = getEditorComponent();
    if(owner != null && owner.getClientProperty("ForceHeavyweightCompletionPopup") != null) { //NOI18N
        owner = null;
    }

    // #76648: Autocomplete box is too close to text
    if(displayAboveCaret && Utilities.isMac()) {
        popupBounds.y -= 10;
    }

    popup = factory.getPopup(owner, contComp, popupBounds.x, popupBounds.y);
    popup.show();

    this.popupBounds = popupBounds;
    this.displayAboveCaret = displayAboveCaret;
}
 
源代码6 项目: gate-core   文件: LuceneDataStoreSearchGUI.java
private void addStatistics(String kind, int count, int numRow,
        final MouseEvent e) {
  JLabel label = (JLabel)e.getComponent();
  if(!label.getToolTipText().contains(kind)) {
    // add the statistics to the tooltip
    String toolTip = label.getToolTipText();
    toolTip = toolTip.replaceAll("</?html>", "");
    toolTip = kind + " = " + count + "<br>" + toolTip;
    toolTip = "<html>" + toolTip + "</html>";
    label.setToolTipText(toolTip);
  }
  if(bottomSplitPane.getDividerLocation()
          / bottomSplitPane.getSize().getWidth() < 0.90) {
    // select the row in the statistics table
    statisticsTabbedPane.setSelectedIndex(1);
    oneRowStatisticsTable.setRowSelectionInterval(numRow, numRow);
    oneRowStatisticsTable.scrollRectToVisible(oneRowStatisticsTable
            .getCellRect(numRow, 0, true));
  } else {
    // display a tooltip
    JToolTip tip = label.createToolTip();
    tip.setTipText(kind + " = " + count);
    PopupFactory popupFactory = PopupFactory.getSharedInstance();
    final Popup tipWindow =
            popupFactory.getPopup(label, tip, e.getX()
                    + e.getComponent().getLocationOnScreen().x, e.getY()
                    + e.getComponent().getLocationOnScreen().y);
    tipWindow.show();
    Date timeToRun = new Date(System.currentTimeMillis() + 2000);
    Timer timer = new Timer("Annic statistics hide tooltip timer", true);
    timer.schedule(new TimerTask() {
      @Override
      public void run() {
        // hide the tooltip after 2 seconds
        tipWindow.hide();
      }
    }, timeToRun);
  }
}
 
源代码7 项目: gate-core   文件: LuceneDataStoreSearchGUI.java
private void addStatistics(String kind, int count, int numRow,
        final MouseEvent e) {
  JLabel label = (JLabel)e.getComponent();
  if(!label.getToolTipText().contains(kind)) {
    // add the statistics to the tooltip
    String toolTip = label.getToolTipText();
    toolTip = toolTip.replaceAll("</?html>", "");
    toolTip = kind + " = " + count + "<br>" + toolTip;
    toolTip = "<html>" + toolTip + "</html>";
    label.setToolTipText(toolTip);
  }
  if(bottomSplitPane.getDividerLocation()
          / bottomSplitPane.getSize().getWidth() < 0.90) {
    // select the row in the statistics table
    statisticsTabbedPane.setSelectedIndex(1);
    oneRowStatisticsTable.setRowSelectionInterval(numRow, numRow);
    oneRowStatisticsTable.scrollRectToVisible(oneRowStatisticsTable
            .getCellRect(numRow, 0, true));
  } else {
    // display a tooltip
    JToolTip tip = label.createToolTip();
    tip.setTipText(kind + " = " + count);
    PopupFactory popupFactory = PopupFactory.getSharedInstance();
    final Popup tipWindow =
            popupFactory.getPopup(label, tip, e.getX()
                    + e.getComponent().getLocationOnScreen().x, e.getY()
                    + e.getComponent().getLocationOnScreen().y);
    tipWindow.show();
    Date timeToRun = new Date(System.currentTimeMillis() + 2000);
    Timer timer = new Timer("Annic statistics hide tooltip timer", true);
    timer.schedule(new TimerTask() {
      @Override
      public void run() {
        // hide the tooltip after 2 seconds
        tipWindow.hide();
      }
    }, timeToRun);
  }
}
 
源代码8 项目: jdk8u_jdk   文件: Popup401.java
private void run() {
    JPanel panel = new JPanel();

    int count = 0;
    long diffTime, initialDiffTime = 0;
    while (count < ITERATION_NUMBER) {
        robot.delay(ROBOT_DELAY);

        PopupFactory factory = PopupFactory.getSharedInstance();
        Popup popup = factory.getPopup(panel, textArea, editorPane.getLocation().x + 20,
                editorPane.getLocation().y + 20);

        long startTime = System.currentTimeMillis();
        popup.show();
        long endTime = System.currentTimeMillis();
        diffTime = endTime - startTime;

        if (count > 1) {
            if (diffTime * HANG_TIME_FACTOR < (endTime - startTime)) {
                throw new RuntimeException("The test is near to be hang: iteration count = " + count
                        + " initial time = " + initialDiffTime
                        + " current time = " + diffTime);
            }
        } else {
            initialDiffTime = diffTime;
        }
        count++;
        robot.delay(ROBOT_DELAY);

        popup.hide();
    }
}
 
源代码9 项目: netbeans   文件: ToolTipManagerEx.java
protected void showTipWindow() {
       if(insideComponent == null || !insideComponent.isShowing())
           return;
       cancelled = false;
       LOG.fine("cancelled=false");    //NOI18N
for (Container p = insideComponent.getParent(); p != null; p = p.getParent()) {
           if (p instanceof JPopupMenu) break;
    if (p instanceof Window) {
	if (!((Window)p).isFocused()) {
	    return;
	}
	break;
    }
}
       if (enabled) {
           Dimension size;
           
           // Just to be paranoid
           hideTipWindow();

           tip = createToolTip();
           tip.setTipText(toolTipText);
           size = tip.getPreferredSize();

           Point location = provider.getToolTipLocation( mouseEvent.getPoint(), size );

    // we do not adjust x/y when using awt.Window tips
    if (popupRect == null){
	popupRect = new Rectangle();
    }
    popupRect.setBounds( location.x, location.y, size.width, size.height );
    
           PopupFactory popupFactory = PopupFactory.getSharedInstance();

    tipWindow = popupFactory.getPopup(insideComponent, tip,
				      location.x,
				      location.y);
    tipWindow.show();

           Window componentWindow = SwingUtilities.windowForComponent(
                                                   insideComponent);

           window = SwingUtilities.windowForComponent(tip);
           if (window != null && window != componentWindow) {
               window.addMouseListener(this);
           }
           else {
               window = null;
           }

           Toolkit.getDefaultToolkit().addAWTEventListener( getAWTListener(), AWTEvent.KEY_EVENT_MASK );
    tipShowing = true;
       }
   }
 
private void showPopupAtMousePosition() {
	// StaticDebug.debug("DND POPUP: Show popup at Mouse position");
	// get mouse location
	Point screenLocation = MouseInfo.getPointerInfo().getLocation();
	screenLocation.x += 26;
	screenLocation.y += 10;

	// if tooltip is shown
	if (tipWindow != null) {
		// StaticDebug.debug("DND POPUP: Popup is already shown");

		// check if mouse has moved
		if (mouseX != screenLocation.x || mouseY != screenLocation.y) {
			// StaticDebug.debug("DND POPUP: old position x = "+mouseX);
			// StaticDebug.debug("DND POPUP: old position y = "+mouseY);
			// StaticDebug.debug("DND POPUP: new position x = "+screenLocation.x);
			// StaticDebug.debug("DND POPUP: new position y = "+screenLocation.y);
			// StaticDebug.debug("DND POPUP: Mouse position has changed.. hide popup first");
			// hide tooltip
			hideDropDeniedTooltip();
		} else {
			// StaticDebug.debug("DND POPUP: Restart hide timer to prevent popup from being hidden.");
			// otherwise restart hide timer
			hideTimer.restart();
			return;
		}
	}

	Point componentLocation = (Point) screenLocation.clone();
	SwingUtilities.convertPointFromScreen(componentLocation, popupSource);
	if (tipWindow == null && popupSource.contains(componentLocation)) {
		// StaticDebug.debug("DND POPUP: Mouse is inside popupSource and popup is not shown");
		JToolTip tip = popupSource.createToolTip();
		tip.setTipText(reason);
		PopupFactory popupFactory = PopupFactory.getSharedInstance();

		mouseX = screenLocation.x;
		mouseY = screenLocation.y;

		// StaticDebug.debug("DND POPUP: show popup at "+mouseX+","+mouseY+" and start hide timer");
		tipWindow = popupFactory.getPopup(popupSource, tip, mouseX, mouseY);
		tipWindow.show();
		hideTimer.restart();
	}
}
 
源代码11 项目: jdk1.8-source-analysis   文件: PopupMenuUI.java
/**
 * Returns the <code>Popup</code> that will be responsible for
 * displaying the <code>JPopupMenu</code>.
 *
 * @param popup JPopupMenu requesting Popup
 * @param x     Screen x location Popup is to be shown at
 * @param y     Screen y location Popup is to be shown at.
 * @return Popup that will show the JPopupMenu
 * @since 1.4
 */
public Popup getPopup(JPopupMenu popup, int x, int y) {
    PopupFactory popupFactory = PopupFactory.getSharedInstance();

    return popupFactory.getPopup(popup.getInvoker(), popup, x, y);
}
 
源代码12 项目: dragonwell8_jdk   文件: PopupMenuUI.java
/**
 * Returns the <code>Popup</code> that will be responsible for
 * displaying the <code>JPopupMenu</code>.
 *
 * @param popup JPopupMenu requesting Popup
 * @param x     Screen x location Popup is to be shown at
 * @param y     Screen y location Popup is to be shown at.
 * @return Popup that will show the JPopupMenu
 * @since 1.4
 */
public Popup getPopup(JPopupMenu popup, int x, int y) {
    PopupFactory popupFactory = PopupFactory.getSharedInstance();

    return popupFactory.getPopup(popup.getInvoker(), popup, x, y);
}
 
源代码13 项目: TencentKona-8   文件: PopupMenuUI.java
/**
 * Returns the <code>Popup</code> that will be responsible for
 * displaying the <code>JPopupMenu</code>.
 *
 * @param popup JPopupMenu requesting Popup
 * @param x     Screen x location Popup is to be shown at
 * @param y     Screen y location Popup is to be shown at.
 * @return Popup that will show the JPopupMenu
 * @since 1.4
 */
public Popup getPopup(JPopupMenu popup, int x, int y) {
    PopupFactory popupFactory = PopupFactory.getSharedInstance();

    return popupFactory.getPopup(popup.getInvoker(), popup, x, y);
}
 
源代码14 项目: jdk8u60   文件: PopupMenuUI.java
/**
 * Returns the <code>Popup</code> that will be responsible for
 * displaying the <code>JPopupMenu</code>.
 *
 * @param popup JPopupMenu requesting Popup
 * @param x     Screen x location Popup is to be shown at
 * @param y     Screen y location Popup is to be shown at.
 * @return Popup that will show the JPopupMenu
 * @since 1.4
 */
public Popup getPopup(JPopupMenu popup, int x, int y) {
    PopupFactory popupFactory = PopupFactory.getSharedInstance();

    return popupFactory.getPopup(popup.getInvoker(), popup, x, y);
}
 
源代码15 项目: JDKSourceCode1.8   文件: PopupMenuUI.java
/**
 * Returns the <code>Popup</code> that will be responsible for
 * displaying the <code>JPopupMenu</code>.
 *
 * @param popup JPopupMenu requesting Popup
 * @param x     Screen x location Popup is to be shown at
 * @param y     Screen y location Popup is to be shown at.
 * @return Popup that will show the JPopupMenu
 * @since 1.4
 */
public Popup getPopup(JPopupMenu popup, int x, int y) {
    PopupFactory popupFactory = PopupFactory.getSharedInstance();

    return popupFactory.getPopup(popup.getInvoker(), popup, x, y);
}
 
源代码16 项目: openjdk-8-source   文件: PopupMenuUI.java
/**
 * Returns the <code>Popup</code> that will be responsible for
 * displaying the <code>JPopupMenu</code>.
 *
 * @param popup JPopupMenu requesting Popup
 * @param x     Screen x location Popup is to be shown at
 * @param y     Screen y location Popup is to be shown at.
 * @return Popup that will show the JPopupMenu
 * @since 1.4
 */
public Popup getPopup(JPopupMenu popup, int x, int y) {
    PopupFactory popupFactory = PopupFactory.getSharedInstance();

    return popupFactory.getPopup(popup.getInvoker(), popup, x, y);
}
 
源代码17 项目: jdk8u-jdk   文件: PopupMenuUI.java
/**
 * Returns the <code>Popup</code> that will be responsible for
 * displaying the <code>JPopupMenu</code>.
 *
 * @param popup JPopupMenu requesting Popup
 * @param x     Screen x location Popup is to be shown at
 * @param y     Screen y location Popup is to be shown at.
 * @return Popup that will show the JPopupMenu
 * @since 1.4
 */
public Popup getPopup(JPopupMenu popup, int x, int y) {
    PopupFactory popupFactory = PopupFactory.getSharedInstance();

    return popupFactory.getPopup(popup.getInvoker(), popup, x, y);
}
 
源代码18 项目: jdk8u_jdk   文件: PopupMenuUI.java
/**
 * Returns the <code>Popup</code> that will be responsible for
 * displaying the <code>JPopupMenu</code>.
 *
 * @param popup JPopupMenu requesting Popup
 * @param x     Screen x location Popup is to be shown at
 * @param y     Screen y location Popup is to be shown at.
 * @return Popup that will show the JPopupMenu
 * @since 1.4
 */
public Popup getPopup(JPopupMenu popup, int x, int y) {
    PopupFactory popupFactory = PopupFactory.getSharedInstance();

    return popupFactory.getPopup(popup.getInvoker(), popup, x, y);
}
 
源代码19 项目: openjdk-jdk9   文件: PopupMenuUI.java
/**
 * Returns the <code>Popup</code> that will be responsible for
 * displaying the <code>JPopupMenu</code>.
 *
 * @param popup JPopupMenu requesting Popup
 * @param x     Screen x location Popup is to be shown at
 * @param y     Screen y location Popup is to be shown at.
 * @return Popup that will show the JPopupMenu
 * @since 1.4
 */
public Popup getPopup(JPopupMenu popup, int x, int y) {
    PopupFactory popupFactory = PopupFactory.getSharedInstance();

    return popupFactory.getPopup(popup.getInvoker(), popup, x, y);
}
 
源代码20 项目: jdk8u-jdk   文件: PopupMenuUI.java
/**
 * Returns the <code>Popup</code> that will be responsible for
 * displaying the <code>JPopupMenu</code>.
 *
 * @param popup JPopupMenu requesting Popup
 * @param x     Screen x location Popup is to be shown at
 * @param y     Screen y location Popup is to be shown at.
 * @return Popup that will show the JPopupMenu
 * @since 1.4
 */
public Popup getPopup(JPopupMenu popup, int x, int y) {
    PopupFactory popupFactory = PopupFactory.getSharedInstance();

    return popupFactory.getPopup(popup.getInvoker(), popup, x, y);
}