javax.swing.PopupFactory Java Examples

The following examples show how to use javax.swing.PopupFactory. 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: SwingPopup.java    From xpra-client with 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 #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: TextValueCompleter.java    From netbeans with 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 #4
Source File: KeymapPanel.java    From netbeans with 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 #5
Source File: ShortcutCellPanel.java    From netbeans with 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 #6
Source File: ProfilerTableHover.java    From netbeans with 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 #7
Source File: ButtonPopupSwitcher.java    From netbeans with 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 #8
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 #9
Source File: ProfilerTableHover.java    From visualvm with 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 #10
Source File: HeavyweightOSXPopupFactory.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
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 #11
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 #12
Source File: CompletionLayoutPopup.java    From netbeans with 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 #13
Source File: InnerPanelSupport.java    From netbeans with 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 #14
Source File: LuceneDataStoreSearchGUI.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #15
Source File: LuceneDataStoreSearchGUI.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 #16
Source File: Toast.java    From arcusplatform with 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 #17
Source File: JPopover.java    From pumpernickel with 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 #18
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 #19
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 #20
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 #21
Source File: LuckPopupMenuUIBundle.java    From littleluck with 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 #22
Source File: FlatLaf.java    From FlatLaf with 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 #23
Source File: RoundedPopupFactory.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void install() {
	PopupFactory factory = PopupFactory.getSharedInstance();
	if (factory instanceof RoundedPopupFactory) {
		return;
	}
	PopupFactory.setSharedInstance(new RoundedPopupFactory(factory));
}
 
Example #24
Source File: RoundedPopupFactory.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void uninstall() {
	PopupFactory factory = PopupFactory.getSharedInstance();
	if (!(factory instanceof RoundedPopupFactory)) {
		return;
	}
	PopupFactory stored = ((RoundedPopupFactory) factory).storedFactory;
	PopupFactory.setSharedInstance(stored);
}
 
Example #25
Source File: RapidMinerGUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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 #26
Source File: MapUnitTooltipManager.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
@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();
    }
  }
}
 
Example #27
Source File: ShadowPopupFactory.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * Installs the ShadowPopupFactory as the shared popup factory
 * on non-Mac platforms. Also stores the previously set factory,
 * so that it can be restored in <code>#uninstall</code>.<p>
 *
 * In some Mac Java environments the popup factory throws
 * a NullPointerException when we call <code>#getPopup</code>.<p>
 *
 * The Mac case shows that we may have problems replacing
 * non PopupFactory instances. Therefore we should consider
 * replacing only instances of PopupFactory.
 *
 * @see #uninstall()
 */
public static void install() {
	final String os = System.getProperty("os.name");
	final boolean macintosh = os != null && os.indexOf("Mac") != -1;
	if (macintosh) {
		return;
	}

	final PopupFactory factory = PopupFactory.getSharedInstance();
	if (factory instanceof ShadowPopupFactory) {
		return;
	}

	PopupFactory.setSharedInstance(new ShadowPopupFactory(factory));
}
 
Example #28
Source File: ShadowPopupFactory.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * Uninstalls the ShadowPopupFactory and restores the original
 * popup factory as the new shared popup factory.
 *
 * @see #install()
 */
public static void uninstall() {
	final PopupFactory factory = PopupFactory.getSharedInstance();
	if (!(factory instanceof ShadowPopupFactory)) {
		return;
	}

	final PopupFactory stored = ((ShadowPopupFactory) factory).storedFactory;
	PopupFactory.setSharedInstance(stored);
}
 
Example #29
Source File: Application.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
/**
 * Setup applications Look and Feel.
 */
private void setupLookAndFeel(ApplicationArguments args)
{
	/* 
	 * Don't prevent the user from overriding the laf is they choose to use 
	 * Swing's default laf prop 
	 */
	String userSpecifiedOverride = System.getProperty("swing.defaultlaf");
	if (userSpecifiedOverride != null && !"".equals(userSpecifiedOverride)) { return; }

	String lafClassName =
		args.useNativeLAF() ? UIManager.getSystemLookAndFeelClassName() : MetalLookAndFeel.class.getName();

	if (!args.useDefaultMetalTheme())
	{
		MetalLookAndFeel.setCurrentTheme(new AllBluesBoldMetalTheme());
	}

	try
	{
		// The following is a work-around for the problem on Mac OS X where
		// the Apple LAF delegates to the Swing Popup factory but then
		// tries to set a 90% alpha on the underlying Cocoa window, which
		// will always be null if you're using JGoodies L&F
		// see http://www.caimito.net/pebble/2005/07/26/1122392314480.html#comment1127522262179
		// This has no effect on Linux/Windows
		PopupFactory.setSharedInstance(new PopupFactory());

		UIManager.setLookAndFeel(lafClassName);
	}
	catch (Exception ex)
	{
		// i18n[Application.error.setlaf=Error setting LAF]
		s_log.error(s_stringMgr.getString("Application.error.setlaf"), ex);
	}
}
 
Example #30
Source File: CompletionLayoutPopup.java    From netbeans with 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;
}