Java Code Examples for java.awt.Window#toFront()

The following examples show how to use java.awt.Window#toFront() . 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: DockingWindowsScreenShots.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testCaptureWindow_Menu() throws Exception {
	performMemorySearch("85d2");
	performMemorySearch("9000");
	waitForTasks();

	DockingWindowManager mgr = DockingWindowManager.getActiveInstance();
	Window mainWindow = mgr.getMainWindow();
	mainWindow.toFront();
	waitForSwing();

	captureMenuBarMenuHierachy("Window");

	ImageUtils.waitForImage(null, image);
	int width = image.getWidth(null);
	int height = image.getHeight(null);

	// trim the image a bit, it is much wider than it needs to be, as the menu bar is large
	int extra = 300; // this is anecdotal; if this becomes wrong, then we can use the tool's size
	Rectangle newBounds = new Rectangle(0, 0, width - 300, height);
	crop(newBounds);
}
 
Example 2
Source File: WindowManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Attempts to bring the parent <code>Window</code> of the given <code>TopComponent</code>
 * to front of other windows.
 * @see java.awt.Window#toFront()
 * @since 5.8
 */
protected void topComponentToFront(TopComponent tc) {
    Window parentWindow = SwingUtilities.getWindowAncestor(tc);

    // be defensive, although w probably will always be non-null here
    if (null != parentWindow) {
        if (parentWindow instanceof Frame) {
            Frame parentFrame = (Frame) parentWindow;
            int state = parentFrame.getExtendedState();

            if ((state & Frame.ICONIFIED) > 0) {
                parentFrame.setExtendedState(state & ~Frame.ICONIFIED);
            }
        }

        parentWindow.toFront();
    }
}
 
Example 3
Source File: Util.java    From beanshell with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: WindowsMenu.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent event) {

    Object src = event.getSource();

    if (src instanceof FrameMenuItem) {
      FrameMenuItem item = (FrameMenuItem) src;
      Window frame = item.getFrame();
      frame.toFront();
      frame.requestFocus();
    }

    if (src == closeAllMenuItem) {
      // Close all Swing Frames
      for (Frame window : Frame.getFrames()) {
        if (window != MZmineCore.getDesktop().getMainWindow()) {
          window.dispose();
        }
      }
    }

  }
 
Example 5
Source File: SlideBarContainer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateActive(boolean active) {
    // #48588 - when in SDI, slidein needs to front the editor frame.
    if(active) {
        Window window = SwingUtilities.getWindowAncestor(panel);
        if(window != null && !window.isActive() && WindowManagerImpl.getInstance().getEditorAreaState() == Constants.EDITOR_AREA_SEPARATED) {
            window.toFront();
        }
    }
}
 
Example 6
Source File: UiUtils.java    From pgptool with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Hack to make sure window is visible. On windows it's sometimes created but on
 * a background. User can see "flashing" icon in a task bar but window stays on
 * a background.
 * 
 * PRESUMING: setVisible(true) was already called
 * 
 * More ion tihs jere:
 * http://stackoverflow.com/questions/309023/how-to-bring-a-window-to-the-front
 */
public static void makeSureWindowBroughtToFront(Window window) {
	// int state = dialog.getExtendedState();
	// state &= ~JFrame.ICONIFIED;
	// dialog.setExtendedState(state);
	window.setAlwaysOnTop(true);
	window.toFront();
	window.requestFocus();
	window.setAlwaysOnTop(false);
	window.repaint();
}
 
Example 7
Source File: PdfDockable.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void toFrontAndFocus() {
    Window window = UIUtilities.getAncestorOfType(this, Window.class);
    if (window != null) {
        window.toFront();
    }
    DockContainer dc = getDockContainer();
    dc.setCurrentDockable(this);
    dc.doLayout();
    dc.acquireFocus();
}
 
Example 8
Source File: DataFileDockable.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void toFrontAndFocus() {
    Window window = UIUtilities.getAncestorOfType(this, Window.class);
    if (window != null) {
        window.toFront();
    }
    DockContainer dc = getDockContainer();
    dc.setCurrentDockable(this);
    dc.doLayout();
    dc.acquireFocus();
}
 
Example 9
Source File: ButtonCellEditor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean stopCellEditing() {
    String s = cell.toString();
    Window ancestorWindow = (Window)SwingUtilities.getRoot(cell);
    // #236458: options are now saved asynchronously. If the dialog was to 
    if (ancestorWindow == null) {
        return true;
    }
    // HACK: if this Editor creates a dialog, it will lose the focus and Swing
    // will remove the editor, calling JTable.cancelEditing. Any re-selections performed
    // by the JTable will occur BEFORE the dialog is finished, so we need to
    // reestablish the column selection later from here.
    // This binds the BCEditor to the KeymapTable layout / internals.
    JTable parent = (JTable)cell.getParent();
    
    ShortcutAction sca = (ShortcutAction) action;
    Set<ShortcutAction> conflictingAction = model.getMutableModel().findActionForShortcutPrefix(s);
    conflictingAction.remove(sca); //remove the original action
    
    Collection<ShortcutAction> sameScopeActions = model.getMutableModel().filterSameScope(conflictingAction, sca);
    
    if (!conflictingAction.isEmpty()) {
         if (!SwingUtilities.isEventDispatchThread()) {
             // #236458: options are now saved asynchronously, off EDT. If we display dialog, the IDE will lock up.
            cell.getTextField().setText(orig);
            fireEditingCanceled();
            return true;
         }
        //there is a conflicting action, show err dialog
        Object overrride = overrride(conflictingAction, sameScopeActions);
        
        // bring the focus back
        ancestorWindow.toFront();
        parent.requestFocus();
        if (overrride.equals(DialogDescriptor.YES_OPTION)) {
            for (ShortcutAction sa : conflictingAction) {
                removeConflictingShortcut(sa, s); //remove all conflicting shortcuts
            }
            //proceed with override
        } else if (overrride == DialogDescriptor.CANCEL_OPTION) {
            cell.getTextField().setText(orig);
            fireEditingCanceled();
            setBorderEmpty();
            return true;
        }
        // NO_OPTION fallls through and adds additional shortcut.
    }
    cell.getTextField().removeActionListener(delegate);
    cell.getTextField().removeKeyListener(escapeAdapter);
    model.getMutableModel().removeShortcut((ShortcutAction) action, orig);
    if (!(s.length() == 0)) // do not add empty shortcuts
        model.getMutableModel().addShortcut((ShortcutAction) action, s);
    fireEditingStopped();
    setBorderEmpty();
    model.update();
    return true;
}
 
Example 10
Source File: WindowMouseHandler.java    From littleluck with Apache License 2.0 4 votes vote down vote up
/**
 *  v1.0.1:修复自定义拖拽区域BUG, 增加边界判断
 */
public void mousePressed(MouseEvent e)
{
    Window window = (Window) e.getSource();

    JRootPane root = LuckWindowUtil.getRootPane(window);

    // 不包含窗体装饰直接返回
    if (root == null || root.getWindowDecorationStyle() == JRootPane.NONE)
    {
        return;
    }
    
    if (window != null)
    {
        window.toFront();
    }

    // 如果是单击标题栏, 则标记接下来的拖动事件为移动窗口, 判断当前鼠标是否超出边界
    if (dragArea.contains(e.getPoint())
            && dragCursor == Cursor.DEFAULT_CURSOR)
    {
        if(window instanceof JFrame)
        {
            JFrame frame = (JFrame)window;

            // 如果当前窗体是全屏状态则直接返回
            if(frame.getExtendedState() == JFrame.MAXIMIZED_BOTH)
            {
                return;
            }
        }

        // 设置为可以移动并记录当前坐标
        isMovingWindow = true;

        dragOffsetX = e.getPoint().x;

        dragOffsetY = e.getPoint().y;
    }
    else if(LuckWindowUtil.isResizable(window))
    {
        dragOffsetX = e.getPoint().x;

        dragOffsetY = e.getPoint().y;

        dragWidth = window.getWidth();

        dragHeight = window.getHeight();

        JRootPane rootPane = LuckWindowUtil.getRootPane(window);

        if(rootPane != null && LuckWindowUtil.isResizable(window))
        {
            dragCursor = getCursor(dragWidth, dragHeight, e.getPoint(), rootPane.getInsets());
        }
    }
}