Java Code Examples for javax.swing.PopupFactory

The following examples show how to use javax.swing.PopupFactory. These examples are extracted from open source projects. 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 Project: FlatLaf   Source File: FlatPopupFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * There is no API in Java 8 to force creation of heavy weight popups,
 * but it is possible with reflection. Java 9 provides a new method.
 *
 * When changing FlatLaf system requirements to Java 9+,
 * then this method can be replaced with:
 *    return getPopup( owner, contents, x, y, true );
 */
private Popup getHeavyWeightPopup( Component owner, Component contents, int x, int y )
	throws IllegalArgumentException
{
	try {
		if( SystemInfo.IS_JAVA_9_OR_LATER ) {
			if( java9getPopupMethod == null ) {
				java9getPopupMethod = PopupFactory.class.getDeclaredMethod(
					"getPopup", Component.class, Component.class, int.class, int.class, boolean.class );
			}
			return (Popup) java9getPopupMethod.invoke( this, owner, contents, x, y, true );
		} else {
			// Java 8
			if( java8getPopupMethod == null ) {
				java8getPopupMethod = PopupFactory.class.getDeclaredMethod(
					"getPopup", Component.class, Component.class, int.class, int.class, int.class );
				java8getPopupMethod.setAccessible( true );
			}
			return (Popup) java8getPopupMethod.invoke( this, owner, contents, x, y, /*HEAVY_WEIGHT_POPUP*/ 2 );
		}
	} catch( NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException ex ) {
		// ignore
		return null;
	}
}
 
Example 2
Source Project: netbeans   Source File: TextValueCompleter.java    License: Apache License 2.0 6 votes vote down vote up
private void showPopup() {
    hidePopup();
    if (completionListModel.getSize() == 0) {
        return;
    }
    // figure out where the text field is,
    // and where its bottom left is
    java.awt.Point los = field.getLocationOnScreen();
    int popX = los.x;
    int popY = los.y + field.getHeight();
    popup = PopupFactory.getSharedInstance().getPopup(field, listScroller, popX, popY);
    field.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),ACTION_HIDEPOPUP);
    field.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),ACTION_FILLIN);
    popup.show();
    if (completionList.getSelectedIndex() != -1) {
        completionList.ensureIndexIsVisible(completionList.getSelectedIndex());
    }
}
 
Example 3
Source Project: netbeans   Source File: KeymapPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
     * 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();
}
 
Example 4
Source Project: netbeans   Source File: ShortcutCellPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void changeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeButtonActionPerformed
    JComponent tf = changeButton;
    Point p = new Point(tf.getX(), tf.getY());
    SwingUtilities.convertPointToScreen(p, this);
    //show special key popup
    if (popup == null) {
        changeButton.setText(""); // NOI18N
        changeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/options/keymap/more_closed.png")));
        if (Utilities.isUnix()) {
            // #156869 workaround, force HW for Linux
            popup = PopupFactory.getSharedInstance().getPopup(null, specialkeyList, p.x, p.y + tf.getHeight());
        } else {
            popup = factory.getPopup(this, specialkeyList, p.x, p.y + tf.getHeight());
        }
        popup.show();
    } else {
        changeButton.setText(""); // NOI18N
        changeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/options/keymap/more_opened.png")));
        hidePopup();
    }
}
 
Example 5
Source Project: netbeans   Source File: ProfilerTableHover.java    License: Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 6
Source Project: netbeans   Source File: ButtonPopupSwitcher.java    License: Apache License 2.0 6 votes vote down vote up
private void doSelect(JComponent owner) {
    invokingComponent = owner;
    invokingComponent.addMouseListener(this);
    invokingComponent.addMouseMotionListener(this);
    pTable.addMouseListener(this);
    pTable.addMouseMotionListener(this);
    
    Toolkit.getDefaultToolkit().addAWTEventListener(this,
            AWTEvent.MOUSE_EVENT_MASK
            | AWTEvent.KEY_EVENT_MASK);
    popup = PopupFactory.getSharedInstance().getPopup(
            invokingComponent, pTable, x, y);
    popup.show();
    shown = true;
    invocationTime = System.currentTimeMillis();
}
 
Example 7
Source Project: Logisim   Source File: LayoutPopupManager.java    License: GNU General Public License v3.0 6 votes vote down vote up
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();
}
 
Example 8
Source Project: visualvm   Source File: ProfilerTableHover.java    License: GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example 9
private void enforceHeavyWeightComponents() {
	if (!couldEnforceHeavyWeightComponents) {
		return;
	}

	AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
		try {
			Method setPopupTypeMethod = PopupFactory.class.getDeclaredMethod("setPopupType", int.class);
			setPopupTypeMethod.setAccessible(true);
			// 2 is the heavyweight constant
			setPopupTypeMethod.invoke(this, 2);
		} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException aE) {
			// if it fails once, it will fail every time. Do not try again
			couldEnforceHeavyWeightComponents = false;
		}
		return null;
	});
}
 
Example 10
public static void setPopupFactory() {
	PopupFactory.setSharedInstance(new PopupFactory() {

		@Override
		public Popup getPopup(Component owner, Component contents, int x, int y) throws IllegalArgumentException {
			if (contents instanceof JToolTip) {
				JToolTip toolTip = (JToolTip)contents;
				int width = (int) toolTip.getPreferredSize().getWidth();
				
				GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
				int screenWidth = gd.getDisplayMode().getWidth();
				
				// if there is enough room, move tooltip to the right to have enough room
				// for large tooltips.
				// this way they don't hinder mouse movement and make it possible to easily
				// view multiple tooltips of items.
				if (x + width + TOOLTIP_X_OFFSET < screenWidth) {
					x += TOOLTIP_X_OFFSET;
				}
			}
			return super.getPopup(owner, contents, x, y);
		}
	});
}
 
Example 11
Source Project: xpra-client   Source File: SwingPopup.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onStart(NewWindow wnd) {
	Window window = null;
	int offsetX = 0;
	int offsetY = 0;
	if(owner != null) {
		window = owner.window;
		offsetX = owner.offsetX;
		offsetY = owner.offsetY;
	}
	canvas = new XpraCanvas(this);
	canvas.setCustomRoot(window);
	canvas.setPreferredSize(new Dimension(wnd.getWidth(), wnd.getHeight()));
	popup = PopupFactory.getSharedInstance().getPopup(window, canvas, wnd.getX() + offsetX, wnd.getY() + offsetY);
	popup.show();
}
 
Example 12
Source Project: FlatLaf   Source File: FlatLaf.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void uninitialize() {
	// remove desktop property listener
	if( desktopPropertyListener != null ) {
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		toolkit.removePropertyChangeListener( desktopPropertyName, desktopPropertyListener );
		if( desktopPropertyName2 != null )
			toolkit.removePropertyChangeListener( desktopPropertyName2, desktopPropertyListener );
		toolkit.removePropertyChangeListener( DESKTOPFONTHINTS, desktopPropertyListener );
		desktopPropertyName = null;
		desktopPropertyName2 = null;
		desktopPropertyListener = null;
	}

	// uninstall popup factory
	if( oldPopupFactory != null ) {
		PopupFactory.setSharedInstance( oldPopupFactory );
		oldPopupFactory = null;
	}

	// uninstall mnemonic handler
	if( mnemonicHandler != null ) {
		mnemonicHandler.uninstall();
		mnemonicHandler = null;
	}

	// restore default link color
	new HTMLEditorKit().getStyleSheet().addRule( "a { color: blue; }" );
	postInitialization = null;

	// restore enable/disable window decorations
	if( oldFrameWindowDecorated != null ) {
		JFrame.setDefaultLookAndFeelDecorated( oldFrameWindowDecorated );
		JDialog.setDefaultLookAndFeelDecorated( oldDialogWindowDecorated );
		oldFrameWindowDecorated = null;
		oldDialogWindowDecorated = null;
	}

	super.uninitialize();
}
 
Example 13
Source Project: arcusplatform   Source File: Toast.java    License: Apache License 2.0 5 votes vote down vote up
public Toast(Component comp, Point toastLocation, String msg, long forDuration) {
    this.component = comp;
    this.location = toastLocation;
    this.message = msg;
    this.duration = forDuration;

    if(this.component != null)
    {

        if(this.location == null)
        {
            this.location = component.getLocationOnScreen();
        }

        new Thread(new Runnable()
        {
            @Override
            public void run()
            {
                Popup view = null;
                try
                {
                    Label tip = new Label(message);
                    tip.setForeground(Color.black);
                    tip.setBackground(Color.white);
                    view = PopupFactory.getSharedInstance().getPopup(component, tip , location.x + 30, location.y + component.getHeight() + 5);
                    view.show();
                    Thread.sleep(duration);
                } catch (InterruptedException ex)
                {
                    Logger.getLogger(Toast.class.getName()).log(Level.SEVERE, null, ex);
                }
                finally
                {
                    view.hide();
                }
            }
        }).start();
    }
}
 
Example 14
Source Project: netbeans   Source File: VisualDesignerPopupMenuUI.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 15
Source Project: netbeans   Source File: CompletionLayoutPopup.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 16
Source Project: netbeans   Source File: InnerPanelSupport.java    License: Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example 17
Source Project: netbeans   Source File: CompletionLayoutPopup.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 18
Source Project: netbeans   Source File: CompletionLayoutPopup.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 19
Source Project: SimpleERP   Source File: Chooser.java    License: Apache License 2.0 5 votes vote down vote up
private void showPanel(Component owner) {
    if (pop != null) pop.hide();
    Point show = new Point(0, showDate.getHeight());
    SwingUtilities.convertPointToScreen(show, showDate);
    Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
    int x = show.x;
    int y = show.y;
    if (x < 0) x = 0;
    if (x > size.width - 212) x = size.width - 212;
    if (y > size.height - 167) y -= 165;
    pop = PopupFactory.getSharedInstance().getPopup(owner, calendarPanel, x, y);
    pop.show();
    isShow = true;
}
 
Example 20
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);
  }
}
 
Example 21
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);
  }
}
 
Example 22
Source Project: pumpernickel   Source File: JPopover.java    License: MIT License 5 votes vote down vote up
/**
 * Create a new QPopup to display this popover's {@link #getContents()}.
 */
protected QPopup createPopup() {
	PopupFactory pf = PopupFactory.getSharedInstance();
	QPopupFactory qpf = null;
	if (pf instanceof QPopupFactory) {
		qpf = (QPopupFactory) pf;
	} else {
		qpf = new QPopupFactory(pf);
	}
	return qpf.getQPopup(getOwner(), popupTarget, getContents());
}
 
Example 23
Source Project: jdk8u_jdk   Source File: Popup401.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example 24
Source Project: jdk8u_jdk   Source File: JDialog741.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void start() {

        System.setProperty("jbre.popupwindow.settype", "true");

        jFrame = new JFrame("Wrong popup z-order");
        jFrame.setSize(200, 200);
        jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        JPanel jPanel = new JPanel();
        jPanel.setPreferredSize(new Dimension(200, 200));

        Popup popup = PopupFactory.getSharedInstance().getPopup(jFrame, jPanel, 100, 100);
        windowAncestor = SwingUtilities.getWindowAncestor(jPanel);
        ((RootPaneContainer) windowAncestor).getRootPane().putClientProperty("SIMPLE_WINDOW", true);
        windowAncestor.setFocusable(true);
        windowAncestor.setFocusableWindowState(true);
        windowAncestor.setAutoRequestFocus(true);

        jFrame.setVisible(true);
        popup.show();


        modalBlocker = new JDialog(windowAncestor, "Modal Blocker");
        modalBlocker.setModal(true);
        modalBlocker.setSize(new Dimension(200, 200));
        modalBlocker.setLocation(200, 200);
        modalBlocker.addWindowListener(new JDialog741Listener());
        modalBlocker.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

        modalBlocker.setVisible(true);
    }
 
Example 25
Source Project: jdk8u_jdk   Source File: JDialog705.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        SwingUtilities.invokeAndWait(() -> {
            jFrame = new JFrame("Wrong popup z-order");
            jFrame.setSize(200, 200);

            JPanel jPanel = new JPanel();
            jPanel.setPreferredSize(new Dimension(200, 200));
            jPanel.setBackground(Color.BLACK);

            Popup popup = PopupFactory.getSharedInstance().getPopup(jFrame, jPanel, 100, 100);
            windowAncestor = SwingUtilities.getWindowAncestor(jPanel);
            ((RootPaneContainer) windowAncestor).getRootPane().putClientProperty("SIMPLE_WINDOW", true);
            windowAncestor.setFocusable(true);
            windowAncestor.setFocusableWindowState(true);
            windowAncestor.setAutoRequestFocus(true);

            jFrame.setVisible(true);
            popup.show();


            modalBlocker = new JDialog(windowAncestor, "Modal Blocker");
            modalBlocker.setModal(true);
            modalBlocker.setSize(new Dimension(200, 200));
            modalBlocker.setLocation(200, 200);
            modalBlocker.addWindowListener(new DialogListener());

            modalBlocker.setVisible(true);
        });
    }
 
Example 26
Source Project: littleluck   Source File: LuckPopupMenuUIBundle.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void installOther(UIDefaults table)
{
    // 使用自定义工厂, 设置Popup为透明, 否则无法使用阴影边框
    // Use a custom factory, set the Popup to be transparent.
    // otherwise you can not use the shadow border.
    PopupFactory.setSharedInstance(new LuckPopupFactory());
}
 
Example 27
public static void install() {
	PopupFactory factory = PopupFactory.getSharedInstance();
	if (factory instanceof RoundedPopupFactory) {
		return;
	}
	PopupFactory.setSharedInstance(new RoundedPopupFactory(factory));
}
 
Example 28
public static void uninstall() {
	PopupFactory factory = PopupFactory.getSharedInstance();
	if (!(factory instanceof RoundedPopupFactory)) {
		return;
	}
	PopupFactory stored = ((RoundedPopupFactory) factory).storedFactory;
	PopupFactory.setSharedInstance(stored);
}
 
Example 29
/**
 * This default implementation only setup the tool tip durations. Subclasses might override this
 * method.
 */
protected void setupGUI() throws Exception {
	System.setProperty(BookmarkIO.PROPERTY_BOOKMARKS_DIR, FileSystemService.getUserRapidMinerDir().getAbsolutePath());
	System.setProperty(BookmarkIO.PROPERTY_BOOKMARKS_FILE, ".bookmarks");

	try {
		if (SystemInfoUtilities.getOperatingSystem() == OperatingSystem.OSX) {
			// to support OS Xs menu bar shown in the OS X menu bar,
			// we have to load the default system look and feel
			// to exchange the MenuBarUI from RapidLookAndFeel with the
			// default OS X look and feel UI class.
			// See here for more information:
			// http://www.pushing-pixels.org/2008/07/13/swing-applications-and-mac-os-x-menu-bar.html
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			Map<String, Object> macUIDefaults = new HashMap<>();
			macUIDefaults.put("MenuBarUI", UIManager.get("MenuBarUI"));
			UIManager.setLookAndFeel(new RapidLookAndFeel(macUIDefaults));

			// tooltips are painted behind heavyweight windows (e.g. the native Chromium browser window) on OS X
			// despite the call above of ToolTipManager#setLightWeightPopupEnabled(false);
			// so we force a heavyweight popup factory for OS X
			PopupFactory.setSharedInstance(new HeavyweightOSXPopupFactory());
		} else {
			UIManager.setLookAndFeel(new RapidLookAndFeel());
		}
	} catch (Exception e) {
		LogService.getRoot().log(Level.WARNING, I18N.getMessage(LogService.getRoot().getResourceBundle(),
				"com.rapidminer.gui.RapidMinerGUI.setting_up_modern_look_and_feel_error"), e);
	}

	// needed because of native browser window which otherwise renders above all popup menus
	JPopupMenu.setDefaultLightWeightPopupEnabled(false);
}
 
Example 30
@Override
public void actionPerformed(final ActionEvent e) {
  if (text != null && text.length() > 0) {
    final Point currentPoint = MouseInfo.getPointerInfo().getLocation();
    if (isPointWithinParentBounds(currentPoint)) {
      final PopupFactory popupFactory = PopupFactory.getSharedInstance();
      final JToolTip info = new JToolTip();
      info.setTipText("<html>" + text + "</html>");
      popup = popupFactory.getPopup(parent, info, currentPoint.x + 20, currentPoint.y - 20);
      popup.show();
    }
  }
}