java.awt.Window Java Examples

The following examples show how to use java.awt.Window. 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: Test6541987.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws AWTException {
    robot = new Robot();
    // test escape after selection
    start();
    click(KeyEvent.VK_ESCAPE);
    toolkit.realSync();
    // test double escape after editing
    start();
    click(KeyEvent.VK_1);
    click(KeyEvent.VK_0);
    click(KeyEvent.VK_ESCAPE);
    click(KeyEvent.VK_ESCAPE);
    toolkit.realSync();
    // all windows should be closed
    for (Window window : Window.getWindows()) {
        if (window.isVisible()) {
            throw new Error("found visible window: " + window.getName());
        }
    }
}
 
Example #2
Source File: ProcessingTopicPanel.java    From wandora with GNU General Public License v3.0 6 votes vote down vote up
private void showRichErrorDialog(String msg) {
final JTextArea area = new JTextArea();
area.setFont(errorMessageFont);
//area.setPreferredSize(new Dimension(520, 180));
area.setEditable(false);
area.setText(msg);

// Make the JOptionPane resizable using the HierarchyListener
       area.addHierarchyListener(new HierarchyListener() {
           public void hierarchyChanged(HierarchyEvent e) {
               Window window = SwingUtilities.getWindowAncestor(area);
               if (window instanceof Dialog) {
                   Dialog dialog = (Dialog)window;
                   if (!dialog.isResizable()) {
                       dialog.setResizable(true);
                   }
               }
           }
       });

JScrollPane scroller = new JScrollPane(area);
scroller.setPreferredSize(new Dimension(520, 180));
JOptionPane.showMessageDialog(Wandora.getWandora(), scroller, "Errors", JOptionPane.PLAIN_MESSAGE);
   }
 
Example #3
Source File: Test6541987.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws AWTException {
    robot = new Robot();
    // test escape after selection
    start();
    click(KeyEvent.VK_ESCAPE);
    toolkit.realSync();
    // test double escape after editing
    start();
    click(KeyEvent.VK_1);
    click(KeyEvent.VK_0);
    click(KeyEvent.VK_ESCAPE);
    click(KeyEvent.VK_ESCAPE);
    toolkit.realSync();
    // all windows should be closed
    for (Window window : Window.getWindows()) {
        if (window.isVisible()) {
            throw new Error("found visible window: " + window.getName());
        }
    }
}
 
Example #4
Source File: JOptionPane.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
Example #5
Source File: SplashFrameHandler.java    From ib-controller with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean filterEvent(Window window, int eventId) {
    /*
     * Note that we are only interested in the closing of the gateway splash
     * frame, because that indicates that the gateway is now in a position to
     * start handling menu commands.
     * 
     * Note also that the splash frame's window title is repeatedly changed during 
     * gateway initialisation, and it's only the last title value that we use for 
     * recognising it
     */
    switch (eventId) {
        case WindowEvent.WINDOW_CLOSED:
            return true;
        default:
            return false;
    }
}
 
Example #6
Source File: GroupEditorBuilder.java    From raccoon4 with Apache License 2.0 6 votes vote down vote up
private void editGroup() {
	Window window = SwingUtilities.getWindowAncestor(add);
	Object obj = JOptionPane.showInputDialog(window,
			Messages.getString(ID + ".edit.message"),
			Messages.getString(ID + ".edit.title"), JOptionPane.QUESTION_MESSAGE,
			null, null, list.getSelectedValue().getName());
	String str;
	if (obj != null && (str = obj.toString()).length() > 0) {
		try {
			AppGroup ag = list.getSelectedValue();
			if (!ag.getName().equals(str)) {
				ag.setName(str);
				DatabaseManager dbm = globals.get(DatabaseManager.class);
				dbm.get(AppGroupDao.class).update(ag);
			}
		}
		catch (Exception e) {
			JOptionPane.showMessageDialog(window,
					Messages.getString(ID + ".failure"));
			// e.printStackTrace();
		}
		reload();
	}
}
 
Example #7
Source File: AncestorNotifier.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void addListeners(Component ancestor, boolean addToFirst) {
    Component a;

    firstInvisibleAncestor = null;
    for (a = ancestor;
         firstInvisibleAncestor == null;
         a = a.getParent()) {
        if (addToFirst || a != ancestor) {
            a.addComponentListener(this);

            if (a instanceof JComponent) {
                JComponent jAncestor = (JComponent)a;

                jAncestor.addPropertyChangeListener(this);
            }
        }
        if (!a.isVisible() || a.getParent() == null || a instanceof Window) {
            firstInvisibleAncestor = a;
        }
    }
    if (firstInvisibleAncestor instanceof Window &&
        firstInvisibleAncestor.isVisible()) {
        firstInvisibleAncestor = null;
    }
}
 
Example #8
Source File: InputContext.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private synchronized void notifyClientWindowChange(Window window) {
    if (inputMethod == null) {
        return;
    }

    // if the window is invisible or iconified, send null to the input method.
    if (!window.isVisible() ||
        ((window instanceof Frame) && ((Frame)window).getState() == Frame.ICONIFIED)) {
        clientWindowLocation = null;
        inputMethod.notifyClientWindowChange(null);
        return;
    }
    Rectangle location = window.getBounds();
    if (clientWindowLocation == null || !clientWindowLocation.equals(location)) {
        clientWindowLocation = location;
        inputMethod.notifyClientWindowChange(clientWindowLocation);
    }
}
 
Example #9
Source File: XComponentPeer.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/*************************************************
 * END OF FOCUS STUFF
 *************************************************/



public void setVisible(boolean b) {
    if (b) {

        focusLog.fine("A component " + getTarget().getClass().getName()
                + " is going to be shown. Put the window on the waiting list: " +
                ((Window)XToolkit.windowToXWindow(getWindow()).getToplevelXWindow().getTarget()).getClass().getName() +
        "; windowId : " + Long.toHexString(getWindow()));

        if (getTarget() instanceof javax.swing.Popup) {
            WindowStateMachine.get().waitForNotifyAfterRaise(getWindow());
        }
    }
    xSetVisible(b);
}
 
Example #10
Source File: TargetProductSelector.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent event) {
    Window windowAncestor = null;
    if (event.getSource() instanceof JComponent) {
        JComponent eventSource = (JComponent) event.getSource();
        windowAncestor = SwingUtilities.getWindowAncestor(eventSource);
    }
    final JFileChooser chooser = FileChooserFactory.getInstance().createDirChooser(model.getProductDir());
    chooser.setDialogTitle("Select Target Directory");
    if (chooser.showDialog(windowAncestor, APPROVE_BUTTON_TEXT) == JFileChooser.APPROVE_OPTION) {
        final File selectedDir = chooser.getSelectedFile();
        if (selectedDir != null) {
            model.setProductDir(selectedDir);
        } else {
            model.setProductDir(new File("."));
        }
    }
}
 
Example #11
Source File: SyncAlwaysOnTopFieldTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    final Window rootWindow = createWindow(null);

    new Thread(() -> {
        for (int i = 0; i < WINDOWS_COUNT; i++) {
            createWindow(rootWindow);
        }
    }).start();

    boolean alwaysOnTop = true;
    for (int i = 0; i < STEPS_COUNT; i++) {
        Thread.sleep(10);
        rootWindow.setAlwaysOnTop(alwaysOnTop);
        alwaysOnTop = !alwaysOnTop;
    }
}
 
Example #12
Source File: LuckRootPaneUI.java    From littleluck with Apache License 2.0 6 votes vote down vote up
/**
 * <p>创建窗体鼠标监听器, 处理窗体的移动和拖拽事件</p>
 * 
 * <p>Create Window mouse listener, handle window move and drag event.</p>
 *
 * @param root <code>JRootPane</code>
 * @return <code>MouseInputListener</code> window move and drag event listener.
 */
protected MouseInputListener installWindowListeners(JRootPane root)
{
    Window window = SwingUtilities.getWindowAncestor(root);

    if (window != null)
    {
        if (mouseInputListener == null)
        {
            mouseInputListener = new WindowMouseHandler(root);
        }

        window.addMouseListener(mouseInputListener);

        window.addMouseMotionListener(mouseInputListener);
    }

    return mouseInputListener;
}
 
Example #13
Source File: AudioPlayerUI.java    From pumpernickel with MIT License 6 votes vote down vote up
public void doBrowseForFile(AudioPlayerComponent apc) {
	Window w = SwingUtilities.getWindowAncestor(apc);
	if (!(w instanceof Frame))
		throw new RuntimeException(
				"cannot invoke a FileDialog if the player is not in a java.awt.Frame");
	// the button shouldn't be enabled if w isn't a Frame...
	Frame f = (Frame) w;
	FileDialog fd = new FileDialog(f);
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);

	if (fd.getFile() == null)
		throw new UserCancelledException();
	File file = new File(fd.getDirectory() + fd.getFile());
	try {
		apc.setSource(file.toURI().toURL());
	} catch (MalformedURLException e) {
		e.printStackTrace();
		apc.setSource(null);
	}
}
 
Example #14
Source File: GuiUtil.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
public static void showMessages(Component parent, List<String> messages) {

        if ((messages == null) || (messages.size() == 0)){
            return;
        }

        Window window = SwingUtilities.windowForComponent(parent);

        StringBuilder sb = new StringBuilder();
        if (messages != null) {
            for (int i = 0, size = messages.size(); i < size; i++) {
                sb.append(messages.get(i));
                if (i < size - 1) {
                    sb.append("\r\n");
                }
            }
        }
        JOptionPane.showMessageDialog(window, sb.toString());
    }
 
Example #15
Source File: AncestorNotifier.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
void addListeners(Component ancestor, boolean addToFirst) {
    Component a;

    firstInvisibleAncestor = null;
    for (a = ancestor;
         firstInvisibleAncestor == null;
         a = a.getParent()) {
        if (addToFirst || a != ancestor) {
            a.addComponentListener(this);

            if (a instanceof JComponent) {
                JComponent jAncestor = (JComponent)a;

                jAncestor.addPropertyChangeListener(this);
            }
        }
        if (!a.isVisible() || a.getParent() == null || a instanceof Window) {
            firstInvisibleAncestor = a;
        }
    }
    if (firstInvisibleAncestor instanceof Window &&
        firstInvisibleAncestor.isVisible()) {
        firstInvisibleAncestor = null;
    }
}
 
Example #16
Source File: JOptionPane.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private JDialog createDialog(Component parentComponent, String title,
        int style)
        throws HeadlessException {

    final JDialog dialog;

    Window window = JOptionPane.getWindowForComponent(parentComponent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    if (window instanceof SwingUtilities.SharedOwnerFrame) {
        WindowListener ownerShutdownListener =
                SwingUtilities.getSharedOwnerFrameShutdownListener();
        dialog.addWindowListener(ownerShutdownListener);
    }
    initDialog(dialog, style, parentComponent);
    return dialog;
}
 
Example #17
Source File: CFunctionHelpers.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * Shows a dialog where the user can resolve a function.
 *
 * @param parent Parent window used for dialogs.
 * @param database Database the function belongs to.
 * @param function Function to be forwarded to another module.
 */
public static void resolveFunction(final Window parent, final IDatabase database,
    final INaviFunction function) {
  final CFunctionSelectionDialog dlg = new CFunctionSelectionDialog(parent, database);

  GuiHelper.centerChildToParent(parent, dlg, true);

  dlg.setVisible(true);

  final INaviFunction selectedFunction = dlg.getSelectedFunction();

  if (selectedFunction != null) {
    try {
      function.setForwardedFunction(selectedFunction);
    } catch (final CouldntSaveDataException e) {
      CUtilityFunctions.logException(e);
    }
  }
}
 
Example #18
Source File: LegacyGlueFocusTraversalPolicy.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example #19
Source File: LWLightweightFramePeer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
    if (!focusAllowedFor()) {
        return false;
    }
    if (getPlatformWindow().rejectFocusRequest(cause)) {
        return false;
    }

    Window opposite = LWKeyboardFocusManagerPeer.getInstance().
        getCurrentFocusedWindow();

    changeFocusedWindow(true, opposite);

    return true;
}
 
Example #20
Source File: ReflectCompletionDialog.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Display the dialog.
 * @param target text component (its Window will be the parent)
 */
public void displayFor(JTextComponent target) {
	try {
		int dot = target.getSelectionStart();
		Window window = SwingUtilities.getWindowAncestor(target);
		Rectangle rt = target.modelToView(dot);
		Point loc = new Point(rt.x, rt.y);
		// convert the location from Text Componet coordinates to
		// Frame coordinates...
		loc = SwingUtilities.convertPoint(target, loc, window);
		// and then to Screen coordinates
		SwingUtilities.convertPointToScreen(loc, window);
		setLocationRelativeTo(window);
		setLocation(loc);
	} catch (BadLocationException ex) {
		Logger.getLogger(ReflectCompletionDialog.class.getName()).log(Level.SEVERE, null, ex);
	} finally {
		setFonts(target.getFont());
		updateItems();
		jTxtItem.setText(target.getSelectedText());
		setVisible(true);
	}
}
 
Example #21
Source File: CProjectLoader.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * Loads a project inside a thread.
 * 
 * @param parent Parent window used for dialogs.
 * @param project Project to load.
 * @param projectTree Project tree to expand on project loading. This argument can be null.
 */
private static void loadProjectThreaded(final Window parent, final INaviProject project,
    final JTree projectTree) {
  Preconditions.checkNotNull(parent, "IE00005: Parent argument can not be null");

  Preconditions.checkNotNull(project, "IE01284: Project argument can not be null");

  if (project.isLoading()) {
    return;
  }

  new Thread() {
    @Override
    public void run() {
      loadProjectInternal(parent, project, projectTree);
    }
  }.start();
}
 
Example #22
Source File: ControlWindow.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
public void adjustSize() { // overrides its super
  String size = getProperty("size"); //$NON-NLS-1$
  ((Window) getComponent()).validate();
  if((size!=null)&&size.trim().toLowerCase().equals("pack")) { //$NON-NLS-1$
    ((Window) getComponent()).pack();
  } else {
    super.adjustSize();
  }
}
 
Example #23
Source File: ErrorDialogFunctions.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Opens the Bugtracker URL.
 *
 * @param parent Parent window used for dialogs.
 */
public static void reportBug(final Window parent) {
  // Parent can be null because errors appear before windows are created.
  try {
    Desktop.getDesktop().browse(new URL("https://github.com/google/binnavi/issues").toURI());
  } catch (final Exception e) {
    CUtilityFunctions.logException(e);
    CMessageBox.showError(parent, "Could not open the bugtracker URL in the browser.");
  }
}
 
Example #24
Source File: JDialogOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A method to be used from subclasses. Uses timeouts and output passed as
 * parameters during the waiting.
 *
 * @param owner a window - dialog owner.
 * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
 * @param index Ordinal component index.
 * @param timeouts timeouts to be used during the waiting.
 * @param output an output to be used during the waiting.
 * @return Component instance or null if component was not found.
 */
protected static JDialog waitJDialog(Window owner, ComponentChooser chooser, int index,
        Timeouts timeouts, TestOut output) {
    try {
        DialogWaiter waiter = new DialogWaiter();
        waiter.setTimeouts(timeouts);
        waiter.setOutput(output);
        return ((JDialog) waiter.
                waitDialog(owner, new JDialogFinder(chooser), index));
    } catch (InterruptedException e) {
        JemmyProperties.getCurrentOutput().printStackTrace(e);
        return null;
    }
}
 
Example #25
Source File: DeleteTaskWork.java    From egdownloader with GNU General Public License v2.0 5 votes vote down vote up
public void doWork(Window window, MouseEvent e) {
	final EgDownloaderWindow mainWindow = (EgDownloaderWindow)window;
	final TaskingTable table = (TaskingTable) mainWindow.runningTable;
	final int[] rows = table.getSelectedRows();
	SwingUtilities.invokeLater(new Runnable(){
		public void run() {
			if(rows.length == 0){
				JOptionPane.showMessageDialog(mainWindow, "请选择至少一个任务");
				return;
			}
			int option = JOptionPane.showConfirmDialog(mainWindow, "确定要删除" + (rows.length > 1 ? "这" + rows.length + "个" : "这个【"  + table.getTasks().get(rows[0]).getDisplayName() + "】") + "任务吗");
			if(option == JOptionPane.OK_OPTION){
						//mainWindow.setEnabled(false);
						DeletingWindow w = (DeletingWindow) mainWindow.deletingWindow;
						if(w == null){
							mainWindow.deletingWindow = new DeletingWindow(mainWindow);
						}
						w = (DeletingWindow) mainWindow.deletingWindow;
						w.setData("    0/" + rows.length);
						w.setInfo("正在收集任务图片");
						int o = JOptionPane.showConfirmDialog(mainWindow, "是否删除下载的文件?");
						w.setVisible(true);
						//执行删除线程
						new DeleteWorker(mainWindow, table, w, rows, o == 0).execute();
					
			}
		}
	});
}
 
Example #26
Source File: StructureEditorNotifiedTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
	public void testModifiedEditedDataTypeChangedYes() throws Exception {
		Window dialog;
		init(complexStructure, pgmTestCat);

		runSwing(() -> {
			try {
//					model.setLocked(false);
				model.insert(model.getNumComponents(), new ByteDataType(), 1);
				model.insert(model.getNumComponents(), new PointerDataType(), 4);
			}
			catch (UsrException e) {
				Assert.fail(e.getMessage());
			}
		});
		SwingUtilities.invokeLater(() -> complexStructure.add(new CharDataType()));
		waitForPostedSwingRunnables();
		DataType origCopy = complexStructure.clone(null);

		// Verify the Reload Structure Editor? dialog is displayed.
		dialog = env.waitForWindow("Reload Structure Editor?", 1000);
		assertNotNull(dialog);
		pressButtonByText(dialog, "Yes");
		dialog.dispose();
		dialog = null;

		assertEquals(((Structure) origCopy).getNumComponents(), model.getNumComponents());
		assertTrue(origCopy.isEquivalent(model.viewComposite));
	}
 
Example #27
Source File: PolicyTool.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * displays a dialog box describing an error which occurred.
 */
void displayErrorDialog(Window w, Throwable t) {
    if (t instanceof NoDisplayException) {
        return;
    }
    displayErrorDialog(w, t.toString());
}
 
Example #28
Source File: TabControlButtonFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void addNotify() {
    super.addNotify();
    //#205194 - cannot minimize floating tab group
    Window w = SwingUtilities.getWindowAncestor( displayer );
    boolean isFloating = w != WindowManager.getDefault().getMainWindow();
    if( isFloating )
        setVisible( false );
}
 
Example #29
Source File: Win32PrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public PrintRequestAttributeSet
    showDocumentProperties(PrinterJob job,
                           Window owner,
                           PrintService service,
                           PrintRequestAttributeSet aset) {

    if (!(job instanceof WPrinterJob)) {
        return null;
    }
    WPrinterJob wJob = (WPrinterJob)job;
    return wJob.showDocumentProperties(owner, service, aset);
}
 
Example #30
Source File: CViewSearcher.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Searches through the views of a view container.
 * 
 * @param parent Parent window used for dialogs.
 * @param container Container to search through.
 * @param address The initial address to search for. This argument can be null.
 */
public static void searchView(final Window parent, final IViewContainer container,
    final IAddress address) {
  final CViewSearcherDialog dlg = new CViewSearcherDialog(parent, container, address);

  dlg.setVisible(true);

  final INaviView result = dlg.getSelectionResult();

  if (result != null) {
    CViewOpener.showView(parent, container, result, CWindowManager.instance().getLastWindow());
  }
}