private void showJPopupMenu(MouseEvent e) { try { if (e.isPopupTrigger() && menu != null) { if (window == null) { if (isWindows) { window = new JDialog((Frame) null); ((JDialog) window).setUndecorated(true); } else { window = new JWindow((Frame) null); } window.setAlwaysOnTop(true); Dimension size = menu.getPreferredSize(); Point centerPoint = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); if (e.getY() > centerPoint.getY()) window.setLocation(e.getX(), e.getY() - size.height); else window.setLocation(e.getX(), e.getY()); window.setVisible(true); menu.show(((RootPaneContainer) window).getContentPane(), 0, 0); // popup works only for focused windows window.toFront(); } } } catch (Exception ignored) { } }
/** * Uninstalls the sheet on the owner. This method is invoked immediately after the JSheet is * hidden. */ protected void uninstallSheet() { if (isInstalled) { Window owner = getOwner(); if (owner != null) { if (isExperimentalSheet()) { owner.removeWindowListener(windowEventHandler); } else { // Note: We mustn't change the windows focusable state // because // this also affects the focusable state of the JSheet. // owner.setFocusableWindowState(true); owner.setEnabled(true); // ((JFrame) owner).setResizable(true); owner.removeComponentListener(ownerMovementHandler); if (shiftBackLocation != null) { owner.setLocation(shiftBackLocation); } if (oldFocusOwner != null) { owner.toFront(); oldFocusOwner.requestFocus(); } } } isInstalled = false; } }
/** * Show the window. * * @param container - Window of JFrame to show */ private void showPopup(Window container) { if (visibleComponent.isEnabled()) { Point pt = visibleComponent.getLocationOnScreen(); pt.translate(0, visibleComponent.getHeight()); container.setLocation(pt); container.toFront(); ApplicationManager.setCurrentlySelectedField(fieldName); if (container instanceof OntologySelector) { ((OntologySelector) container).makeVisible(); } else { container.setVisible(true); container.requestFocusInWindow(); } } }
public void mousePressed(MouseEvent ev) { JRootPane rootPane = getRootPane(); if (rootPane.getWindowDecorationStyle() == JRootPane.NONE) { return; } Point dragWindowOffset = ev.getPoint(); Window w = (Window) ev.getSource(); if (w != null) { w.toFront(); } Point convertedDragWindowOffset = SwingUtilities.convertPoint(w, dragWindowOffset, getTitlePane()); Frame f = null; Dialog d = null; if (w instanceof Frame) { f = (Frame) w; } else if (w instanceof Dialog) { d = (Dialog) w; } int frameState = (f != null) ? f.getExtendedState() : 0; if (getTitlePane() != null && getTitlePane().contains(convertedDragWindowOffset)) { if ((f != null && ((frameState & Frame.MAXIMIZED_BOTH) == 0) || (d != null)) && dragWindowOffset.y >= BORDER_DRAG_THICKNESS && dragWindowOffset.x >= BORDER_DRAG_THICKNESS && dragWindowOffset.x < w.getWidth() - BORDER_DRAG_THICKNESS) { isMovingWindow = true; dragOffsetX = dragWindowOffset.x; dragOffsetY = dragWindowOffset.y; } } else if (f != null && f.isResizable() && ((frameState & Frame.MAXIMIZED_BOTH) == 0) || (d != null && d.isResizable())) { dragOffsetX = dragWindowOffset.x; dragOffsetY = dragWindowOffset.y; dragWidth = w.getWidth(); dragHeight = w.getHeight(); dragCursor = getCursor(calculateCorner(w, dragWindowOffset.x, dragWindowOffset.y)); } }
/* This could live in the desktop script. However we'd like to get it on the screen as quickly as possible. */ public static void startSplashScreen() { int width = 275, height = 148; Window win = new Window(new Frame()); win.pack(); BshCanvas can = new BshCanvas(); can.setSize(width, height); // why is this necessary? Toolkit tk = Toolkit.getDefaultToolkit(); Dimension dim = tk.getScreenSize(); win.setBounds(dim.width / 2 - width / 2, dim.height / 2 - height / 2, width, height); win.add("Center", can); Image img = tk.getImage(Interpreter.class.getResource("/bsh/util/lib/splash.gif")); MediaTracker mt = new MediaTracker(can); mt.addImage(img, 0); try { mt.waitForAll(); } catch (Exception e) { } Graphics gr = can.getBufferedGraphics(); gr.drawImage(img, 0, 0, can); win.setVisible(true); win.toFront(); splashScreen = win; }
/** Bring the dialog to the front */ public void toFront() { if (!windowOk()) { return; } window.toFront(); }