java.awt.KeyboardFocusManager Java Examples

The following examples show how to use java.awt.KeyboardFocusManager. 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: BoundingBoxWindow.java    From Pixie with MIT License 6 votes vote down vote up
private void initOtherVariables() {
    // add keyboard listener to be able to set events on the wanted keys
    boxKeyEventDispatch = new BBoxWinKeyEventDispatcher();
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(boxKeyEventDispatch);

    // display a label with the object id
    displayObjId();

    // add the size of the object        
    setFrameTitle();

    enableScribbleObjOpt(currentObject instanceof ObjectScribble);

    // compute the preffered width of the combo boxes based on the specified text
    jCBObjType.setPrototypeDisplayValue(Constants.OBJECT_ATTRIBUTES_TEXT);
    jCBObjClass.setPrototypeDisplayValue(Constants.OBJECT_ATTRIBUTES_TEXT);
    jCBObjValue.setPrototypeDisplayValue(Constants.OBJECT_ATTRIBUTES_TEXT);
}
 
Example #2
Source File: CopyAction.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
  public void actionPerformed(ActionEvent evt) {
    Component cFocusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();

    if (cFocusOwner instanceof JComponent) {
      if (cFocusOwner.isEnabled()) {
        // Cut all selected UserObjects from the tree
        if (cFocusOwner instanceof EditableComponent) {
          ((EditableComponent) cFocusOwner).copySelectedItems();
        }
      }
    }

    // "Old" version with JHotDraw clipboard
//    JComponent cTarget = target;
//
//    if (cTarget == null && (cFocusOwner instanceof JComponent)) {
//      cTarget = (JComponent) cFocusOwner;
//    }
//    // Note: copying is allowed for disabled components
//    if (cTarget != null && cTarget.getTransferHandler() != null) {
//      cTarget.getTransferHandler().exportToClipboard(cTarget, ClipboardUtil.getClipboard(), TransferHandler.COPY);
//    }
  }
 
Example #3
Source File: TimableEventQueue.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static boolean isWaitCursor() {
    Component focus = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (focus != null) {
        if (focus.getCursor().getType() == Cursor.WAIT_CURSOR) {
            LOG.finer("wait cursor on focus owner"); // NOI18N
            return true;
        }
        Window w = SwingUtilities.windowForComponent(focus);
        if (w != null && isWaitCursorOnWindow(w)) {
            LOG.finer("wait cursor on window"); // NOI18N
            return true;
        }
    }
    for (Frame f : Frame.getFrames()) {
        if (isWaitCursorOnWindow(f)) {
            LOG.finer("wait cursor on frame"); // NOI18N
            return true;
        }
    }
    LOG.finest("no wait cursor"); // NOI18N
    return false;
}
 
Example #4
Source File: UIManager.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static void maybeInitializeFocusPolicy(JComponent comp) {
    // Check for JRootPane which indicates that a swing toplevel
    // is coming, in which case a swing default focus policy
    // should be instatiated. See 7125044.
    if (comp instanceof JRootPane) {
        synchronized (classLock) {
            if (!getLAFState().focusPolicyInitialized) {
                getLAFState().focusPolicyInitialized = true;

                if (FocusManager.isFocusManagerEnabled()) {
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().
                        setDefaultFocusTraversalPolicy(
                            new LayoutFocusTraversalPolicy());
                }
            }
        }
    }
}
 
Example #5
Source File: JavaTargetLocator.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private Window findFocusWindow() {
    Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    if (w != null)
        return w;
    w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
    if (w != null)
        return w;

    Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (focusOwner != null)
        w = SwingUtilities.getWindowAncestor(focusOwner);
    if (w != null)
        return w;
    Window[] validWindows = getValidWindows();
    if (validWindows.length > 0)
        return validWindows[validWindows.length - 1];
    return null;
}
 
Example #6
Source File: CutAction.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
  public void actionPerformed(ActionEvent evt) {
    Component cFocusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();

    if (cFocusOwner instanceof JComponent) {
      if (cFocusOwner.isEnabled()) {
        // Cut all selected UserObjects from the tree
        if (cFocusOwner instanceof EditableComponent) {
          ((EditableComponent) cFocusOwner).cutSelectedItems();
        }
      }
    }

    // "Old" version with JHotDraw clipboard
//    JComponent cTarget = target;
//
//    if (cTarget == null && (cFocusOwner instanceof JComponent)) {
//      cTarget = (JComponent) cFocusOwner;
//    }
//
//    if (cTarget != null && cTarget.isEnabled() && cTarget.getTransferHandler() != null) {
//      cTarget.getTransferHandler().exportToClipboard(cTarget, ClipboardUtil.getClipboard(), TransferHandler.MOVE);
//    }
  }
 
Example #7
Source File: ContainerFocusAutoTransferTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void test1(final TestCase t) {
    Runnable action = new Runnable() {
        public void run() {
            KeyboardFocusManager.setCurrentKeyboardFocusManager(new TestKFM());
            if (t == TestCase.REMOVAL) {
                frame.remove(frame.panel0);

            } else if (t == TestCase.HIDING) {
                frame.panel0.setVisible(false);
            }
            frame.repaint();
        }
    };
    if (!Util.trackFocusGained(frame.b3, action, 2000, false)) {
        throw new TestFailedException(t + ": focus wasn't transfered as expected!");
    }
    KeyboardFocusManager.setCurrentKeyboardFocusManager(kfm);
}
 
Example #8
Source File: UIManager.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static void maybeInitializeFocusPolicy(JComponent comp) {
    // Check for JRootPane which indicates that a swing toplevel
    // is coming, in which case a swing default focus policy
    // should be instatiated. See 7125044.
    if (comp instanceof JRootPane) {
        synchronized (classLock) {
            if (!getLAFState().focusPolicyInitialized) {
                getLAFState().focusPolicyInitialized = true;

                if (FocusManager.isFocusManagerEnabled()) {
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().
                        setDefaultFocusTraversalPolicy(
                            new LayoutFocusTraversalPolicy());
                }
            }
        }
    }
}
 
Example #9
Source File: MainFrameMenu.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
public void dispose() {
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.removeKeyEventDispatcher(keyEventDispatcher);

    Configuration.autoDeobfuscate.removeListener(configListenerAutoDeobfuscate);
    Configuration.simplifyExpressions.removeListener(configListenerSimplifyExpressions);
    Configuration.internalFlashViewer.removeListener(configListenerInternalFlashViewer);
    Configuration.parallelSpeedUp.removeListener(configListenerParallelSpeedUp);
    Configuration.decompile.removeListener(configListenerDecompile);
    //Configuration.cacheOnDisk.removeListener(configListenerCacheOnDisk);
    Configuration.gotoMainClassOnStartup.removeListener(configListenerGotoMainClassOnStartup);
    Configuration.autoRenameIdentifiers.removeListener(configListenerAutoRenameIdentifiers);
    Configuration.autoOpenLoadedSWFs.removeListener(configListenerAutoOpenLoadedSWFs);

    Main.stopRun();
}
 
Example #10
Source File: TestFocusFreeze.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    boolean all_passed = true;
    KeyboardFocusManager testKFM = new TestKFM(robot);
    KeyboardFocusManager defKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager();

    for (int i = 0; i < 10; i++) {
        test(testKFM, defKFM);
        Util.waitForIdle(robot);
        System.out.println("Iter " + i + ": " + (lock.get() ? "passed." : "failed!"));
        if (!lock.get()) {
            all_passed = false;
        }
    }
    if (!all_passed) {
        throw new RuntimeException("Test failed: not all iterations passed!");
    }
    System.out.println("Test passed.");
}
 
Example #11
Source File: UIManager.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private static void maybeInitializeFocusPolicy(JComponent comp) {
    // Check for JRootPane which indicates that a swing toplevel
    // is coming, in which case a swing default focus policy
    // should be instatiated. See 7125044.
    if (comp instanceof JRootPane) {
        synchronized (classLock) {
            if (!getLAFState().focusPolicyInitialized) {
                getLAFState().focusPolicyInitialized = true;

                if (FocusManager.isFocusManagerEnabled()) {
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().
                        setDefaultFocusTraversalPolicy(
                            new LayoutFocusTraversalPolicy());
                }
            }
        }
    }
}
 
Example #12
Source File: ProgressPanel.java    From wpcleaner with Apache License 2.0 6 votes vote down vote up
@Override
public void setVisible(boolean visible) {
  boolean oldVisible = isVisible();
  super.setVisible(visible);
  JRootPane rootPane = SwingUtilities.getRootPane(this);
  if ((rootPane != null) && (isVisible() != oldVisible)) {
    if (isVisible()) {
      Component focusOwner = KeyboardFocusManager.
          getCurrentKeyboardFocusManager().getPermanentFocusOwner();
      if ((focusOwner != null) &&
          SwingUtilities.isDescendingFrom(focusOwner, rootPane)) {
        recentFocusOwner = focusOwner;
      }
      rootPane.getLayeredPane().setVisible(false);
      requestFocusInWindow();
    } else {
      rootPane.getLayeredPane().setVisible(true);
      if (recentFocusOwner != null) {
        recentFocusOwner.requestFocusInWindow();
      }
      recentFocusOwner = null;
    }
  }
}
 
Example #13
Source File: TestFocusFreeze.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    boolean all_passed = true;
    KeyboardFocusManager testKFM = new TestKFM(robot);
    KeyboardFocusManager defKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager();

    for (int i = 0; i < 10; i++) {
        test(testKFM, defKFM);
        Util.waitForIdle(robot);
        System.out.println("Iter " + i + ": " + (lock.get() ? "passed." : "failed!"));
        if (!lock.get()) {
            all_passed = false;
        }
    }
    if (!all_passed) {
        throw new RuntimeException("Test failed: not all iterations passed!");
    }
    System.out.println("Test passed.");
}
 
Example #14
Source File: ContainerFocusAutoTransferTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
void test1(final TestCase t) {
    Runnable action = new Runnable() {
        public void run() {
            KeyboardFocusManager.setCurrentKeyboardFocusManager(new TestKFM());
            if (t == TestCase.REMOVAL) {
                frame.remove(frame.panel0);

            } else if (t == TestCase.HIDING) {
                frame.panel0.setVisible(false);
            }
            frame.repaint();
        }
    };
    if (!Util.trackFocusGained(frame.b3, action, 2000, false)) {
        throw new TestFailedException(t + ": focus wasn't transfered as expected!");
    }
    KeyboardFocusManager.setCurrentKeyboardFocusManager(kfm);
}
 
Example #15
Source File: TestFocusFreeze.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    boolean all_passed = true;
    KeyboardFocusManager testKFM = new TestKFM(robot);
    KeyboardFocusManager defKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager();

    for (int i = 0; i < 10; i++) {
        test(testKFM, defKFM);
        Util.waitForIdle(robot);
        System.out.println("Iter " + i + ": " + (lock.get() ? "passed." : "failed!"));
        if (!lock.get()) {
            all_passed = false;
        }
    }
    if (!all_passed) {
        throw new RuntimeException("Test failed: not all iterations passed!");
    }
    System.out.println("Test passed.");
}
 
Example #16
Source File: BaseTable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Overridden to hide the selection when not focused, and paint across the
 * selected row if focused. */
public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
    Object value = getValueAt(row, col);

    Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();

    boolean isSelected = isSelected(row, focusOwner);

    Component result = renderer.getTableCellRendererComponent(this, value, isSelected, false, row, col);

    if( PropUtils.isNimbus ) {
        //HACK to get rid of alternate row background colors
        if( !isSelected ) {
            Color bkColor = getBackground();
            if( null != bkColor ) 
                result.setBackground( new Color( bkColor.getRGB() ) );
        }
    }

    return result;
}
 
Example #17
Source File: BasicPopupMenuUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void doReturn() {
    KeyboardFocusManager fmgr =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Component focusOwner = fmgr.getFocusOwner();
    if(focusOwner != null && !(focusOwner instanceof JRootPane)) {
        return;
    }

    MenuSelectionManager msm = MenuSelectionManager.defaultManager();
    MenuElement path[] = msm.getSelectedPath();
    MenuElement lastElement;
    if(path.length > 0) {
        lastElement = path[path.length-1];
        if(lastElement instanceof JMenu) {
            MenuElement newPath[] = new MenuElement[path.length+1];
            System.arraycopy(path,0,newPath,0,path.length);
            newPath[path.length] = ((JMenu)lastElement).getPopupMenu();
            msm.setSelectedPath(newPath);
        } else if(lastElement instanceof JMenuItem) {
            JMenuItem mi = (JMenuItem)lastElement;

            if (mi.getUI() instanceof BasicMenuItemUI) {
                ((BasicMenuItemUI)mi.getUI()).doClick(msm);
            }
            else {
                msm.clearSelectedPath();
                mi.doClick(0);
            }
        }
    }
}
 
Example #18
Source File: NbPresenter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * @return Focused and showing Window or null.
 */
private Window findFocusedWindow() {
    Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    while( null != w && !w.isShowing() ) {
        w = w.getOwner();
    }
    return w;
}
 
Example #19
Source File: RequestFocusAndHideTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException, java.lang.reflect.InvocationTargetException
{
    final Frame frame = new Frame("the test");
    frame.setLayout(new FlowLayout());
    final Button btn1 = new Button("button 1");
    frame.add(btn1);
    frame.add(new Button("button 2"));
    frame.add(new Button("button 3"));
    frame.pack();
    frame.setVisible(true);

    Robot r = Util.createRobot();
    Util.waitForIdle(r);
    Util.clickOnComp(btn1, r);
    Util.waitForIdle(r);
    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    if (kfm.getFocusOwner() != btn1) {
        throw new RuntimeException("test error: can not set focus on " + btn1 + ".");
    }

    EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                final int n_comps = frame.getComponentCount();
                for (int i = 0; i < n_comps; ++i) {
                    frame.getComponent(i).setVisible(false);
                }
            }
        });
    Util.waitForIdle(r);
    final Component focus_owner = kfm.getFocusOwner();

    if (focus_owner != null && !focus_owner.isVisible()) {
        throw new RuntimeException("we have invisible focus owner");
    }
    System.out.println("test passed");
    frame.dispose();
}
 
Example #20
Source File: CutCopyPasteDeleteAction.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
private CutCopyPasteDeleteAction(String i18nKey, String action) {
	super(i18nKey);
	putValue(ACTION_COMMAND_KEY, action);
	KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
	manager.addPropertyChangeListener("permanentFocusOwner", evt -> {
		Object o = evt.getNewValue();
		if (o instanceof JComponent) {
			focusOwner = (JComponent) o;
		} else {
			focusOwner = null;
		}
	});
}
 
Example #21
Source File: GroundContainerMouseState.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
	ignoreClick = contextMenuFlag;
	windowWasActiveOnMousePressed = (KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow() != null);
	xOnMousePressed = e.getX();
	yOnMousePressed = e.getY();
	/*
	 * The canvas does not want to keep the focus, but this way it at least
	 * will end up for the right component.
	 */
	ground.getCanvas().requestFocus();
	super.mousePressed(e);
}
 
Example #22
Source File: ExtTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static Component waitForComponentOrChildToGetFocus(Container c) {
    Component foc = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    int ct=0;
    while (foc == null || (foc != c && !c.isAncestorOf(foc))) {
        try {
            Thread.currentThread().sleep(100);
        } catch (Exception e ) {}
        foc = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        ct++;
        if (ct > 200) {
            break;
        }
    }
    return foc;
}
 
Example #23
Source File: BasicPopupMenuUI.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
void removeItems() {
    if (lastFocused != null) {
        if(!lastFocused.requestFocusInWindow()) {
            // Workarounr for 4810575.
            // If lastFocused is not in currently focused window
            // requestFocusInWindow will fail. In this case we must
            // request focus by requestFocus() if it was not
            // transferred from our popup.
            Window cfw = KeyboardFocusManager
                         .getCurrentKeyboardFocusManager()
                          .getFocusedWindow();
            if(cfw != null &&
               "###focusableSwingPopup###".equals(cfw.getName())) {
                lastFocused.requestFocus();
            }

        }
        lastFocused = null;
    }
    if (invokerRootPane != null) {
        invokerRootPane.removeKeyListener(this);
        invokerRootPane.setFocusTraversalKeysEnabled(focusTraversalKeysEnabled);
        removeUIInputMap(invokerRootPane, menuInputMap);
        removeUIActionMap(invokerRootPane, menuActionMap);
        invokerRootPane = null;
    }
    receivedKeyPressed = false;
}
 
Example #24
Source File: UIManager.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void initialize() {
    Properties swingProps = loadSwingProperties();
    initializeSystemDefaults(swingProps);
    initializeDefaultLAF(swingProps);
    initializeAuxiliaryLAFs(swingProps);
    initializeInstalledLAFs(swingProps);

    // Install Swing's PaintEventDispatcher
    if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) {
        sun.awt.PaintEventDispatcher.setPaintEventDispatcher(
                                    new SwingPaintEventDispatcher());
    }
    // Install a hook that will be invoked if no one consumes the
    // KeyEvent.  If the source isn't a JComponent this will process
    // key bindings, if the source is a JComponent it implies that
    // processKeyEvent was already invoked and thus no need to process
    // the bindings again, unless the Component is disabled, in which
    // case KeyEvents will no longer be dispatched to it so that we
    // handle it here.
    KeyboardFocusManager.getCurrentKeyboardFocusManager().
            addKeyEventPostProcessor(new KeyEventPostProcessor() {
                public boolean postProcessKeyEvent(KeyEvent e) {
                    Component c = e.getComponent();

                    if ((!(c instanceof JComponent) ||
                         (c != null && !c.isEnabled())) &&
                            JComponent.KeyboardState.shouldProcess(e) &&
                            SwingUtilities.processKeyBindings(e)) {
                        e.consume();
                        return true;
                    }
                    return false;
                }
            });
    AWTAccessor.getComponentAccessor().
        setRequestFocusController(JComponent.focusController);
}
 
Example #25
Source File: RequestFocusAndHideTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException, java.lang.reflect.InvocationTargetException
{
    final Frame frame = new Frame("the test");
    frame.setLayout(new FlowLayout());
    final Button btn1 = new Button("button 1");
    frame.add(btn1);
    frame.add(new Button("button 2"));
    frame.add(new Button("button 3"));
    frame.pack();
    frame.setVisible(true);

    Robot r = Util.createRobot();
    Util.waitForIdle(r);
    Util.clickOnComp(btn1, r);
    Util.waitForIdle(r);
    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    if (kfm.getFocusOwner() != btn1) {
        throw new RuntimeException("test error: can not set focus on " + btn1 + ".");
    }

    EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                final int n_comps = frame.getComponentCount();
                for (int i = 0; i < n_comps; ++i) {
                    frame.getComponent(i).setVisible(false);
                }
            }
        });
    Util.waitForIdle(r);
    final Component focus_owner = kfm.getFocusOwner();

    if (focus_owner != null && !focus_owner.isVisible()) {
        throw new RuntimeException("we have invisible focus owner");
    }
    System.out.println("test passed");
    frame.dispose();
}
 
Example #26
Source File: ConnectionsCustomizer.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private boolean displayFocus() {
    if (table == null) return false;
    Component focusOwner = KeyboardFocusManager.
            getCurrentKeyboardFocusManager().getFocusOwner();
    return focusOwner != null ? focusOwner == table || SwingUtilities.
            isDescendingFrom(focusOwner, this) : false;
}
 
Example #27
Source File: BasicPopupMenuUI.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private void doReturn() {
    KeyboardFocusManager fmgr =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Component focusOwner = fmgr.getFocusOwner();
    if(focusOwner != null && !(focusOwner instanceof JRootPane)) {
        return;
    }

    MenuSelectionManager msm = MenuSelectionManager.defaultManager();
    MenuElement path[] = msm.getSelectedPath();
    MenuElement lastElement;
    if(path.length > 0) {
        lastElement = path[path.length-1];
        if(lastElement instanceof JMenu) {
            MenuElement newPath[] = new MenuElement[path.length+1];
            System.arraycopy(path,0,newPath,0,path.length);
            newPath[path.length] = ((JMenu)lastElement).getPopupMenu();
            msm.setSelectedPath(newPath);
        } else if(lastElement instanceof JMenuItem) {
            JMenuItem mi = (JMenuItem)lastElement;

            if (mi.getUI() instanceof BasicMenuItemUI) {
                ((BasicMenuItemUI)mi.getUI()).doClick(msm);
            }
            else {
                msm.clearSelectedPath();
                mi.doClick(0);
            }
        }
    }
}
 
Example #28
Source File: SelectBlockPluginTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void pressSelectBytes(final SelectBlockDialog dialog) {
	executeOnSwingWithoutBlocking(
		() -> pressButtonByText(dialog, SELECT_BYTES_BUTTON_NAME, true));

	// make sure the warning dialog is not showing
	KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
	Window window = kfm.getActiveWindow();
	if (window instanceof JDialog) {
		JButton button = findButtonByText(window, "OK");
		if (button != null) {
			pressButton(button);
		}
	}
}
 
Example #29
Source File: ProgramActionContext.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public ProgramActionContext(ComponentProvider provider, Program program,
		Component sourceComponent, Object contextObject) {
	super(provider, contextObject, sourceComponent);
	this.program = program;

	// the case where the first constructor is called, which does not specify the component
	if (sourceComponent == null) {
		KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
		setSourceObject(kfm.getFocusOwner());
	}
}
 
Example #30
Source File: BasicPopupMenuUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
void removeItems() {
    if (lastFocused != null) {
        if(!lastFocused.requestFocusInWindow()) {
            // Workarounr for 4810575.
            // If lastFocused is not in currently focused window
            // requestFocusInWindow will fail. In this case we must
            // request focus by requestFocus() if it was not
            // transferred from our popup.
            Window cfw = KeyboardFocusManager
                         .getCurrentKeyboardFocusManager()
                          .getFocusedWindow();
            if(cfw != null &&
               "###focusableSwingPopup###".equals(cfw.getName())) {
                lastFocused.requestFocus();
            }

        }
        lastFocused = null;
    }
    if (invokerRootPane != null) {
        invokerRootPane.removeKeyListener(this);
        invokerRootPane.setFocusTraversalKeysEnabled(focusTraversalKeysEnabled);
        removeUIInputMap(invokerRootPane, menuInputMap);
        removeUIActionMap(invokerRootPane, menuActionMap);
        invokerRootPane = null;
    }
    receivedKeyPressed = false;
}