javax.swing.Popup Java Examples

The following examples show how to use javax.swing.Popup. 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: FlatPopupFactory.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
@Override
public Popup getPopup( Component owner, Component contents, int x, int y )
	throws IllegalArgumentException
{
	if( !isDropShadowPainted( owner, contents ) )
		return new NonFlashingPopup( super.getPopup( owner, contents, x, y ), contents );

	// macOS and Linux adds drop shadow to heavy weight popups
	if( SystemInfo.IS_MAC || SystemInfo.IS_LINUX ) {
		Popup popup = getHeavyWeightPopup( owner, contents, x, y );
		if( popup == null )
			popup = super.getPopup( owner, contents, x, y );
		return new NonFlashingPopup( popup, contents );
	}

	// create drop shadow popup
	return new DropShadowPopup( super.getPopup( owner, contents, x, y ), owner, contents );
}
 
Example #2
Source File: FlatPopupFactory.java    From FlatLaf with 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 #3
Source File: CustomPopupFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Popup getPopup(Component owner, Component contents,
                      int x, int y) throws IllegalArgumentException {
    assert owner instanceof JComponent;
    Dimension d = contents.getPreferredSize();
    Container c = ((JComponent) owner).getTopLevelAncestor();
    if (c == null) {
        throw new IllegalArgumentException ("Not onscreen: " + owner);
    }
    Point p = new Point (x, y);
    SwingUtilities.convertPointFromScreen(p, c);
    Rectangle r = new Rectangle (p.x, p.y, d.width, d.height);
    if (c.getBounds().contains(r)) {
        //XXX need API to determine if editor area comp is heavyweight,
        //and if so, return a "medium weight" popup of a java.awt.Component
        //that embeds the passed contents component
        return new LWPopup (owner, contents, x, y);
    } else {
        return new HWPopup (owner, contents, x, y);
    }
}
 
Example #4
Source File: ShadowPopupFactory.java    From javamelody with Apache License 2.0 6 votes vote down vote up
static Popup getInstance(Component owner, Component contents, int x, int y,
		Popup delegate) {
	final ShadowPopup result;
	synchronized (ShadowPopup.class) {
		if (cache == null) {
			cache = new ArrayList<>(MAX_CACHE_SIZE);
		}
		if (!cache.isEmpty()) {
			result = cache.remove(0);
		} else {
			result = new ShadowPopup();
		}
	}
	result.reset(owner, contents, x, y, delegate);
	return result;
}
 
Example #5
Source File: CustomPopupFactory.java    From WorldGrower with GNU General Public License v3.0 6 votes vote down vote up
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 #6
Source File: LayoutPopupManager.java    From Logisim with 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 #7
Source File: PopupPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Checks if the focus is still on this component or its child components.
 */
private boolean isFocusInside(Object newFocusedComp) {
	if (newFocusedComp instanceof Popup) {
		return true;
	}
	if (newFocusedComp instanceof Component && !SwingUtilities.isDescendingFrom((Component) newFocusedComp, this)) {
		// Check if focus is on other window
		if (containingWindow == null) {
			return false;
		}

		Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();

		// if focus is on other window in owner chain, return false
		Window parent = containingWindow;
		do {
			if (parent == focusedWindow) {
				return false;
			} else {
				parent = parent.getOwner();
			}
		} while (parent != null);
	}
	return true;
}
 
Example #8
Source File: RoundedRectanglePopup.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
private void initPopup(Component owner, Component contents, int x, int y, Popup popup) {
	this.owner = owner;
	this.contents = contents;
	this.popup = popup;
	this.x = x;
	this.y = y;

	boolean mac = false;
	try {
		mac = System.getProperty("os.name").toLowerCase().startsWith("mac");
	} catch (SecurityException e) {
		// do nothing
	}
	if (mac) {
		((JComponent) contents).setBorder(Borders.getPopupMenuBorder());
	} else if (((JComponent) contents).getBorder() instanceof DummyBorder) {
		if ((owner != null) //
				&& (((owner instanceof JMenu) && ((JMenu) owner).isTopLevelMenu()) //
				|| ((owner.getParent() != null) && (owner.getParent() instanceof javax.swing.JToolBar)) //
				|| (owner instanceof javax.swing.JComboBox))) {
			((JComponent) contents).setBorder(Borders.getPopupBorder());
		} else {
			((JComponent) contents).setBorder(Borders.getShadowedPopupMenuBorder());
		}
	}
}
 
Example #9
Source File: MultiPopupMenuUI.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Invokes the <code>getPopup</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 * @since 1.4
 */
public Popup getPopup(JPopupMenu a, int b, int c) {
    Popup returnValue =
        ((PopupMenuUI) (uis.elementAt(0))).getPopup(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((PopupMenuUI) (uis.elementAt(i))).getPopup(a,b,c);
    }
    return returnValue;
}
 
Example #10
Source File: MultiPopupMenuUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getPopup</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 * @since 1.4
 */
public Popup getPopup(JPopupMenu a, int b, int c) {
    Popup returnValue =
        ((PopupMenuUI) (uis.elementAt(0))).getPopup(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((PopupMenuUI) (uis.elementAt(i))).getPopup(a,b,c);
    }
    return returnValue;
}
 
Example #11
Source File: MultiPopupMenuUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getPopup</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 * @since 1.4
 */
public Popup getPopup(JPopupMenu a, int b, int c) {
    Popup returnValue =
        ((PopupMenuUI) (uis.elementAt(0))).getPopup(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((PopupMenuUI) (uis.elementAt(i))).getPopup(a,b,c);
    }
    return returnValue;
}
 
Example #12
Source File: ShadowPopupFactory.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * Reinitializes this ShadowPopup using the given parameters.
 *
 * @param newOwner component mouse coordinates are relative to, may be null
 * @param newContents the contents of the popup
 * @param newX the desired x location of the popup
 * @param newY the desired y location of the popup
 * @param newPopup the popup to wrap
 */
private void reset(Component newOwner, Component newContents, int newX, int newY,
		Popup newPopup) {
	this.owner = newOwner;
	this.contents = newContents;
	this.popup = newPopup;
	this.x = newX;
	this.y = newY;
	if (newOwner instanceof JComboBox) {
		return;
	}
	// Do not install the shadow border when the contents
	// has a preferred size less than or equal to 0.
	// We can't use the size, because it is(0, 0) for new popups.
	final Dimension contentsPrefSize = newContents.getPreferredSize();
	if (contentsPrefSize.width <= 0 || contentsPrefSize.height <= 0) {
		return;
	}
	for (Container p = newContents.getParent(); p != null; p = p.getParent()) {
		if (p instanceof JWindow || p instanceof Panel) {
			// Workaround for the gray rect problem.
			p.setBackground(newContents.getBackground());
			heavyWeightContainer = p;
			break;
		}
	}
	final JComponent parent = (JComponent) newContents.getParent();
	oldOpaque = parent.isOpaque();
	oldBorder = parent.getBorder();
	parent.setOpaque(false);
	parent.setBorder(SHADOW_BORDER);
	// Pack it because we have changed the border.
	if (heavyWeightContainer != null) {
		heavyWeightContainer.setSize(heavyWeightContainer.getPreferredSize());
	} else {
		parent.setSize(parent.getPreferredSize());
	}
}
 
Example #13
Source File: CoolPopupFactory.java    From Swing9patch with Apache License 2.0 5 votes vote down vote up
@Override
public Popup getPopup(Component owner, Component contents, int x, int y)
		throws IllegalArgumentException
{
	// A more complete implementation would cache and reuse popups
	return new TranslucentPopup(owner, contents, x, y);
}
 
Example #14
Source File: StyledPopupMenuUI.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Popup getPopup(JPopupMenu menu, int x, int y) {
	Popup popup = super.getPopup(menu, x, y);
	/*
	 * The menu should now have a parent, which is probably a JPanel, In
	 * which case its borders need to be deleted.
	 */
	Container parent = menu.getParent();
	if (parent instanceof JComponent) {
		((JComponent) parent).setBorder(null);
	}

	return popup;
}
 
Example #15
Source File: MultiPopupMenuUI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getPopup</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 * @since 1.4
 */
public Popup getPopup(JPopupMenu a, int b, int c) {
    Popup returnValue =
        ((PopupMenuUI) (uis.elementAt(0))).getPopup(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((PopupMenuUI) (uis.elementAt(i))).getPopup(a,b,c);
    }
    return returnValue;
}
 
Example #16
Source File: MultiPopupMenuUI.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getPopup</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 * @since 1.4
 */
public Popup getPopup(JPopupMenu a, int b, int c) {
    Popup returnValue =
        ((PopupMenuUI) (uis.elementAt(0))).getPopup(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((PopupMenuUI) (uis.elementAt(i))).getPopup(a,b,c);
    }
    return returnValue;
}
 
Example #17
Source File: Popup401.java    From jdk8u_jdk with 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 #18
Source File: QPopupFactory.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
public Popup getPopup(Component owner, Component contents, int x, int y)
		throws IllegalArgumentException {
	Popup p;
	if (contents instanceof JToolTip) {
		JComponent c = (JComponent) contents;
		return getQPopup(owner, null, c, new Point(x, y));
	} else {
		p = delegate.getPopup(owner, contents, x, y);
	}
	return p;
}
 
Example #19
Source File: JDialog705.java    From jdk8u_jdk with 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 #20
Source File: TranslucentPopupFactory.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
@Override
public Popup getPopup(Component owner, Component contents, int x, int y)
		throws IllegalArgumentException
{
	// A more complete implementation would cache and reuse popups
	return new TranslucentPopup(owner, contents, x, y);
}
 
Example #21
Source File: MultiPopupMenuUI.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getPopup</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 * @since 1.4
 */
public Popup getPopup(JPopupMenu a, int b, int c) {
    Popup returnValue =
        ((PopupMenuUI) (uis.elementAt(0))).getPopup(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((PopupMenuUI) (uis.elementAt(i))).getPopup(a,b,c);
    }
    return returnValue;
}
 
Example #22
Source File: MultiPopupMenuUI.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getPopup</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 * @since 1.4
 */
public Popup getPopup(JPopupMenu a, int b, int c) {
    Popup returnValue =
        ((PopupMenuUI) (uis.elementAt(0))).getPopup(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((PopupMenuUI) (uis.elementAt(i))).getPopup(a,b,c);
    }
    return returnValue;
}
 
Example #23
Source File: JDialog741.java    From jdk8u_jdk with 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 #24
Source File: MultiPopupMenuUI.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Invokes the <code>getPopup</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 * @since 1.4
 */
public Popup getPopup(JPopupMenu a, int b, int c) {
    Popup returnValue =
        ((PopupMenuUI) (uis.elementAt(0))).getPopup(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((PopupMenuUI) (uis.elementAt(i))).getPopup(a,b,c);
    }
    return returnValue;
}
 
Example #25
Source File: LayoutPopupManager.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
public void hideCurrentPopup() {
	Popup cur = curPopup;
	if (cur != null) {
		curPopup = null;
		dragStart = null;
		cur.hide();
	}
}
 
Example #26
Source File: MultiPopupMenuUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getPopup</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 * @since 1.4
 */
public Popup getPopup(JPopupMenu a, int b, int c) {
    Popup returnValue =
        ((PopupMenuUI) (uis.elementAt(0))).getPopup(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((PopupMenuUI) (uis.elementAt(i))).getPopup(a,b,c);
    }
    return returnValue;
}
 
Example #27
Source File: PopupMenuTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
    Popup popup = ((PopMenuUIExt) jpopup.getUI()).getPopup();
    if (popup != null) {
        isLightWeight = !popup.getClass().toString().
                contains("HeavyWeightPopup");
    }
}
 
Example #28
Source File: PopupMenuTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void dispose() throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        Popup popup = PopMenuUIExt.getPopup();
        if (popup != null) {
            popup.hide();
        }
        frame.dispose();
    });
}
 
Example #29
Source File: MultiPopupMenuUI.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes the <code>getPopup</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 * @since 1.4
 */
public Popup getPopup(JPopupMenu a, int b, int c) {
    Popup returnValue =
        ((PopupMenuUI) (uis.elementAt(0))).getPopup(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((PopupMenuUI) (uis.elementAt(i))).getPopup(a,b,c);
    }
    return returnValue;
}
 
Example #30
Source File: MultiPopupMenuUI.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Invokes the <code>getPopup</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 * @since 1.4
 */
public Popup getPopup(JPopupMenu a, int b, int c) {
    Popup returnValue =
        ((PopupMenuUI) (uis.elementAt(0))).getPopup(a,b,c);
    for (int i = 1; i < uis.size(); i++) {
        ((PopupMenuUI) (uis.elementAt(i))).getPopup(a,b,c);
    }
    return returnValue;
}