Java 类java.awt.KeyboardFocusManager 实例源码
项目:incubator-netbeans
文件:Utilities.java
/**
* Finds out the monitor where the user currently has the input focus.
* This method is usually used to help the client code to figure out on
* which monitor it should place newly created windows/frames/dialogs.
*
* @return the GraphicsConfiguration of the monitor which currently has the
* input focus
*/
private static GraphicsConfiguration getCurrentGraphicsConfiguration() {
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (focusOwner != null) {
Window w = SwingUtilities.getWindowAncestor(focusOwner);
if (w != null) {
return w.getGraphicsConfiguration();
} else {
//#217737 - try to find the main window which could be placed in secondary screen
for( Frame f : Frame.getFrames() ) {
if( "NbMainWindow".equals(f.getName())) { //NOI18N
return f.getGraphicsConfiguration();
}
}
}
}
return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
}
项目:marathonv5
文件:EventQueueDevice.java
public Component getComponent() {
if (component == null) {
Window activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
if (activeWindow != null) {
return activeWindow.getFocusOwner();
}
Window[] windows = Window.getWindows();
if (windows.length > 0) {
if (windows[0].getFocusOwner() != null) {
return windows[0].getFocusOwner();
}
return windows[0];
}
}
return component;
}
项目:VASSAL-src
文件:PrivMsgCommand.java
public void executeCommand() {
PrivateChatter chat = mgr.getChatterFor(p);
if (chat == null) {
return;
}
Window f = SwingUtilities.getWindowAncestor(chat);
if (!f.isVisible()) {
f.setVisible(true);
Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager()
.getFocusOwner();
if (c == null || !SwingUtilities.isDescendingFrom(c, f)) {
java.awt.Toolkit.getDefaultToolkit().beep();
for (int i = 0,j = chat.getComponentCount(); i < j; ++i) {
if (chat.getComponent(i) instanceof JTextField) {
(chat.getComponent(i)).requestFocus();
break;
}
}
}
}
else {
f.toFront();
}
chat.show(msg);
}
项目:jdk8u-jdk
文件:UIManager.java
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());
}
}
}
}
}
项目:litiengine
文件:KeyBoard.java
/**
* Instantiates a new key board.
*/
public KeyBoard() {
this.keySpecificTypedConsumer = new CopyOnWriteArrayList<>();
this.keySpecificPressedConsumer = new CopyOnWriteArrayList<>();
this.keySpecificReleasedConsumer = new CopyOnWriteArrayList<>();
this.keyPressedConsumer = new CopyOnWriteArrayList<>();
this.keyReleasedConsumer = new CopyOnWriteArrayList<>();
this.keyTypedConsumer = new CopyOnWriteArrayList<>();
this.pressedKeys = new CopyOnWriteArrayList<>();
this.releasedKeys = new CopyOnWriteArrayList<>();
this.typedKeys = new CopyOnWriteArrayList<>();
this.keyObservers = new CopyOnWriteArrayList<>();
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);
Input.InputLoop.attach(this);
}
项目:incubator-netbeans
文件:ViewTooltips.java
private void detach() {
KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(this);
if (tree != null) {
tree.getSelectionModel().removeTreeSelectionListener(this);
tree.getModel().removeTreeModelListener(this);
tree.removeHierarchyBoundsListener(this);
tree.removeHierarchyListener(this);
tree.removeComponentListener(this);
} else {
list.getSelectionModel().removeListSelectionListener(this);
list.getModel().removeListDataListener(this);
list.removeHierarchyBoundsListener(this);
list.removeHierarchyListener(this);
list.removeComponentListener(this);
}
pane.getHorizontalScrollBar().getModel().removeChangeListener(this);
pane.getVerticalScrollBar().getModel().removeChangeListener(this);
detached = true;
}
项目:incubator-netbeans
文件:BaseTable.java
/** 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;
}
项目:incubator-netbeans
文件:EditableDisplayerTest.java
public void testRadioButtonThreshold() throws Exception {
if (!canRun) return;
System.err.println("running");
clickOn(basicRen);
tagsRen2.setRadioButtonMax(2);
clickOn(tagsRen2);
Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
assertTrue("after setting radio max below threshold, click on the renderer should focus a combo box, not " + c, c instanceof JComboBox);
clickOn(basicRen);
tagsRen2.setRadioButtonMax(10);
sleep();
clickOn(tagsRen2, 80, 25);
tagsRen2.requestFocus();
sleep();
c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
assertTrue("after setting radio button max > threshold, focus owner should be a radio button, not " + c, c instanceof JRadioButton);
}
项目:incubator-netbeans
文件:EditableDisplayerTest.java
public void testEditableCombo() throws Exception{
if (!canRun) return;
edRen.setUpdatePolicy(edRen.UPDATE_ON_CONFIRMATION);
clickOn(edRen);
requestFocus(edRen);
sleep();
sleep();
JComponent c = (JComponent)KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
Object o = edRen.getProperty().getValue();
String nuVal = "FOO";
typeKey(c, KeyEvent.VK_F);
typeKey(c, KeyEvent.VK_O);
typeKey(c, KeyEvent.VK_O);
assertEquals("After typing into editable combo, value should match the typed value", nuVal, edRen.getEnteredValue());
assertNotSame("After typing into editable combo with policy UPDATE_ON_CONFIRMATION, the property should not have the value typed",
nuVal, edRen.getProperty().getValue());
pressKey(c, KeyEvent.VK_ENTER);
assertEquals("After pressing enter on an editable combo, value should be updated", nuVal, edRen.getProperty().getValue());
}
项目:incubator-netbeans
文件:CategoryList.java
@Override
public void actionPerformed(ActionEvent e) {
int selIndexBefore = getSelectedIndex();
defaultAction.actionPerformed( e );
int selIndexCurrent = getSelectedIndex();
if( selIndexBefore != selIndexCurrent )
return;
if( focusNext && 0 == selIndexCurrent && getModel().getSize() > 1 && getModel().getSize() > getColumnCount() )
return;
KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
Container container = kfm.getCurrentFocusCycleRoot();
FocusTraversalPolicy policy = container.getFocusTraversalPolicy();
if( null == policy )
policy = kfm.getDefaultFocusTraversalPolicy();
Component next = focusNext ? policy.getComponentAfter( container, CategoryList.this )
: policy.getComponentBefore( container, CategoryList.this );
if( null != next && next instanceof CategoryButton ) {
clearSelection();
next.requestFocus();
}
}
项目:incubator-netbeans
文件:ColumnSelectionPanel.java
private static GraphicsConfiguration getCurrentGraphicsConfiguration() {
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (focusOwner != null) {
Window w = SwingUtilities.getWindowAncestor(focusOwner);
if (w != null) {
return w.getGraphicsConfiguration();
}
}
return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
}
项目:incubator-netbeans
文件:NewPropertyPanelTest.java
public void disabled_testReadOnlyMode() throws Exception {
requestFocus (focusButton);
changeProperty (stringPanel, stringProp);
setPreferences(stringPanel, PropertyPanel.PREF_READ_ONLY | PropertyPanel.PREF_INPUT_STATE);
Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
requestFocus(stringPanel);
Component owner2 = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
assertSame("Requesting focus on a read only inline editor panel should not change the focus owner, but it was " + owner2, owner, owner2);
requestFocus(stringPanel);
setPreferences(filePanel, PropertyPanel.PREF_READ_ONLY | PropertyPanel.PREF_CUSTOM_EDITOR);
jf.repaint();
Component owner3 = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
assertSame("Requesting focus on a read only custom editor panel should not change the focus owner, not " + owner3, owner, owner3);
}
项目:incubator-netbeans
文件:AbstractViewTabDisplayerUI.java
@Override
public void mousePressed(MouseEvent e) {
Point p = e.getPoint();
int i = getLayoutModel().indexOfPoint(p.x, p.y);
tabState.setPressed(i);
SingleSelectionModel sel = getSelectionModel();
selectionChanged = i != sel.getSelectedIndex();
// invoke possible selection change
if ((i != -1) || !selectionChanged) {
boolean change = shouldPerformAction(TabDisplayer.COMMAND_SELECT,
i, e);
if (change) {
getSelectionModel().setSelectedIndex(i);
tabState.setSelected(i);
Component tc = i >= 0 ? getDataModel().getTab(i).getComponent() : null;
if( null != tc && tc instanceof TopComponent
&& !((TopComponent)tc).isAncestorOf( KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner() ) ) {
((TopComponent)tc).requestActive();
}
}
}
if (e.isPopupTrigger()) {
//Post a popup menu show request
shouldPerformAction(TabDisplayer.COMMAND_POPUP_REQUEST, i, e);
}
}
项目:incubator-netbeans
文件:TimableEventQueue.java
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;
}
项目:incubator-netbeans
文件:NbPresenter.java
/**
* @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;
}
项目:incubator-netbeans
文件:RunOffEDTTest.java
public void testDlgIsShown() throws Exception {
final R r = new R();
r.l = new CountDownLatch(1);
final boolean[] shown = new boolean[] { false };
KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
if (w != null) {
r.l.countDown();
shown[0] = true;
}
}
});
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
ProgressUtils.runOffEventDispatchThread(r, "Test", new AtomicBoolean(false), true, 10, 100);
}
});
if (!shown[0]) {
fail("Dialog was not shown");
}
}
项目:rapidminer
文件:CutCopyPasteDeleteAction.java
private CutCopyPasteDeleteAction(String i18nKey, String action) {
super(i18nKey);
putValue(ACTION_COMMAND_KEY, action);
KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
manager.addPropertyChangeListener("permanentFocusOwner", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
Object o = evt.getNewValue();
if (o instanceof JComponent) {
focusOwner = (JComponent) o;
} else {
focusOwner = null;
}
}
});
}
项目:openjdk-jdk10
文件:MultiMonPrintDlgTest.java
public void actionPerformed (ActionEvent ae) {
javax.print.attribute.PrintRequestAttributeSet prSet =
new javax.print.attribute.HashPrintRequestAttributeSet();
java.awt.print.PrinterJob.getPrinterJob().pageDialog(prSet);
Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
int dialogButton = JOptionPane.showConfirmDialog (w,
"Did the pageDialog shown in non-default monitor?",
null, JOptionPane.YES_NO_OPTION);
if(dialogButton == JOptionPane.NO_OPTION) {
fail("PageDialog is shown in wrong monitor");
} else {
java.awt.print.PrinterJob.getPrinterJob().printDialog(prSet);
dialogButton = JOptionPane.showConfirmDialog (w,
"Did the printDialog shown in non-default monitor?",
null, JOptionPane.YES_NO_OPTION);
if(dialogButton == JOptionPane.NO_OPTION) {
fail("PrintDialog is shown in wrong monitor");
} else {
pass();
}
}
}
项目:rapidminer
文件:PopupPanel.java
/**
* Checks if the focus is still on this component or its child components.
*/
private boolean isFocusInside(Object newFocusedComp) {
if (newFocusedComp instanceof Popup) {
return true;
}
if (newFocusedComp instanceof Component && !SwingUtilities.isDescendingFrom((Component) newFocusedComp, this)) {
// Check if focus is on other window
if (containingWindow == null) {
return false;
}
Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
// if focus is on other window return true
if (containingWindow == focusedWindow) {
return false;
}
}
return true;
}
项目:rapidminer
文件:PopupAction.java
private Point calculatePosition(Component source) {
int xSource = source.getLocationOnScreen().x;
int ySource = source.getLocationOnScreen().y;
// get size of popup
Dimension popupSize = ((Component) popupComponent).getSize();
if (popupSize.width == 0) {
popupSize = ((Component) popupComponent).getPreferredSize();
}
int xPopup = 0;
int yPopup = 0;
// get max x and y window positions
Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
int maxX = focusedWindow.getLocationOnScreen().x + focusedWindow.getWidth();
int maxY = focusedWindow.getLocationOnScreen().y + focusedWindow.getHeight();
switch (position) {
case VERTICAL:
// place popup at sources' x position
xPopup = xSource;
// check if popup is outside active window
if (xPopup + popupSize.width > maxX) {
// move popup x position to the left
// to fit inside the active window
xPopup = maxX - popupSize.width - BORDER_OFFSET;
}
// place popup always below source (to avoid overlapping)
yPopup = ySource + source.getHeight();
// if the popup now would be moved outside of RM Studio to the left it would look
// silly, so in that case just show it at its intended position and let it be cut
// off on the right side as we cannot do anything about it
if (xPopup < focusedWindow.getLocationOnScreen().x
|| (xPopup - focusedWindow.getLocationOnScreen().x) + popupSize.width > focusedWindow.getWidth()) {
xPopup = xSource;
}
break;
case HORIZONTAL:
// place popup always to the right side of the source (to avoid overlapping)
xPopup = xSource + source.getWidth();
yPopup = ySource;
// check if popup is outside active window
if (yPopup + popupSize.height > maxY) {
// move popup upwards to fit into active window
yPopup = maxY - popupSize.height - BORDER_OFFSET;
}
// if the popup now would be moved outside of RM Studio at the top it would look
// silly, so in that case just show it at its intended position and let it be cut
// off on the bottom side as we cannot do anything about it
if (yPopup < focusedWindow.getLocationOnScreen().y
|| (yPopup - focusedWindow.getLocationOnScreen().y) + popupSize.height > focusedWindow.getHeight()) {
yPopup = ySource;
}
break;
}
return new Point(xPopup, yPopup);
}
项目:marathonv5
文件:JavaTargetLocator.java
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;
}
项目:Equella
文件:FlatterSpinnerUI.java
/**
* Requests focus on a child of the spinner if the spinner doesn't have
* focus.
*/
private void focusSpinnerIfNecessary()
{
Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if( spinner.isRequestFocusEnabled() && (fo == null || !SwingUtilities.isDescendingFrom(fo, spinner)) )
{
Container root = spinner;
if( !root.isFocusCycleRoot() )
{
root = root.getFocusCycleRootAncestor();
}
if( root != null )
{
FocusTraversalPolicy ftp = root.getFocusTraversalPolicy();
Component child = ftp.getComponentAfter(root, spinner);
if( child != null && SwingUtilities.isDescendingFrom(child, spinner) )
{
child.requestFocus();
}
}
}
}
项目:jdk8u-jdk
文件:ContainerFocusAutoTransferTest.java
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);
}
项目:OpenJSharp
文件:UIManager.java
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());
}
}
}
}
}
项目:scorekeeperfrontend
文件:BarcodeScannerWatcher.java
/**
* Dump some of the queued key events back into the regular event system.
*/
private void _dumpQueue(int count)
{
KeyboardFocusManager mgr = KeyboardFocusManager.getCurrentKeyboardFocusManager();
while ((count > 0) && (queue.size() > 0))
{
KeyEvent ke = queue.pop();
mgr.redispatchEvent(ke.getComponent(), ke);
count--;
}
}
项目:incubator-netbeans
文件:TableQuickSearchSupport.java
@Override
public void quickSearchCanceled() {
// Check whether the cancel was explicit or implicit.
// Implicit cancel has undefined focus owner
// TODO: After switch to JDK 8, we can e.g. add a static method to Callback providing the info.
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (focusOwner != null) {
displaySearchResult(quickSearchInitialRow, quickSearchInitialColumn);
}
quickSearchInitialRow = -1;
quickSearchInitialColumn = -1;
quickSearchLastPos = null;
}
项目:incubator-netbeans
文件:FocusAfterBadEditTest.java
public void testFocusReturn() throws Exception {
if (!focusWorks) {
return;
}
clickOn(tb, 1, 1);
requestFocus(tb);
typeKey(tb, KeyEvent.VK_B);
typeKey(tb, KeyEvent.VK_E);
typeKey(tb, KeyEvent.VK_SPACE);
typeKey(tb, KeyEvent.VK_N);
typeKey(tb, KeyEvent.VK_I);
typeKey(tb, KeyEvent.VK_C);
typeKey(tb, KeyEvent.VK_E);
sleep();
SLEEP_LENGTH=1000;
Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
sleep();
pressKey(c, KeyEvent.VK_ENTER);
typeKey(c, KeyEvent.VK_ENTER);
sleep();
sleep();
sleep();
sleep();
c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
assertNotNull(c);
Container top = ((JComponent) c).getTopLevelAncestor();
assertTrue("Focus should no longer be on the property sheet after an erroneous value was entered", top != jf);
assertTrue("An error dialog should be showing after an exception was thrown in setAsText() but focus owner is " + c, jf != top);
JRootPane jrp = ((JComponent) c).getRootPane();
jrp.getDefaultButton().doClick();
sleep();
c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
assertTrue("After the error dialog is closed following a bad property edit, the table should return to edit mode on the previously edited property",
c instanceof InplaceEditor);
}
项目:incubator-netbeans
文件:PropertyMarkingTest.java
public void testPostSetAction() throws Exception {
if (!canSafelyRunFocusTests()) {
System.err.println("Cannot run post set " +
"action test - testing machine's focus behavior is not sane");
return;
}
pressCell(tb, 1, 1);
sleep();
requestFocus(tb);
System.err.println("WILL TYPE MIAOU");
JComponent focusOwner = (JComponent)KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
assertTrue("Focus should be on a JTextField, not " + focusOwner, focusOwner instanceof JTextField);
typeString("MIAOU", focusOwner);
sleep();
sleep();
System.err.println("MIAOU TYPED");
postSetAction.assertNotPerformed();
System.err.println("ACTION NOT PERFORMED AS IT SHOULD BE");
pressKey(tb, KeyEvent.VK_ENTER);
System.err.println("SENDING ENTER TO " + tb);
Thread.currentThread().sleep(1000);
sleep();
System.err.println("TYPING ENTER TO " + tb);
typeKey(tb, KeyEvent.VK_ENTER);
sleep();
sleep();
System.err.println("POST SET ACTION PERFORMED: " + postSetAction.performed);
postSetAction.assertPerformed();
click(tb, 1, 0);
}
项目:openjdk-jdk10
文件:bug8033699.java
private static void runTest8() throws Exception {
hitKey(robot, KeyEvent.VK_TAB);
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != radioBtnSingle) {
System.out.println("Separate Component added in button group layout");
throw new RuntimeException("Focus is not on Radio Button Single as Expected");
}
}
});
}
项目:openjdk-jdk10
文件:bug8033699.java
private static void runTest3() throws Exception {
hitKey(robot, KeyEvent.VK_SHIFT, KeyEvent.VK_TAB);
hitKey(robot, KeyEvent.VK_SHIFT, KeyEvent.VK_TAB);
hitKey(robot, KeyEvent.VK_SHIFT, KeyEvent.VK_TAB);
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != radioBtn1) {
System.out.println("Radio button Group/Non Grouped Radio Button SHIFT-Tab Key Test failed");
throw new RuntimeException("Focus is not on Radio Button A as Expected");
}
}
});
}
项目:incubator-netbeans
文件:ExtTestCase.java
public static boolean waitForDialog() {
Container c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
int ct = 0;
while (!(c instanceof Dialog)) {
try {
Thread.currentThread().sleep(50);
} catch (Exception e) {}
c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
ct++;
if (ct > 100) {
return false;
}
}
return true;
}
项目:incubator-netbeans
文件:ExtTestCase.java
public static boolean waitForFrame() {
Container c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
int ct = 0;
while (!(c instanceof JFrame)) {
try {
Thread.currentThread().sleep(50);
} catch (Exception e) {}
c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
ct++;
if (ct > 100) {
return false;
}
}
return true;
}
项目:incubator-netbeans
文件:ExtTestCase.java
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;
}
项目:incubator-netbeans
文件:EditableDisplayerTest.java
public void testCustomEditorTitle() throws Exception {
if (!canRun) return;
requestFocus(custRen);
Runnable run = new Runnable() {
public void run() {
try {
doCtrlPressKey(stringRen, KeyEvent.VK_SPACE);
} catch (Exception e) {}
}
};
new Thread(run).start();
Thread.currentThread().sleep(1000);
sleep();
Component owner =
KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
assertTrue("Control press should invoke custom editor", ((JComponent) owner).getTopLevelAncestor() !=
stringRen.getTopLevelAncestor());
Container c = ((JComponent) owner).getTopLevelAncestor();
System.err.println("CLASS: " + c.getClass());
if (c instanceof JDialog) {
assertEquals("Custom editor supplying a title via client properties should be shown in a dialog with that title",
((JDialog) c).getTitle(), "Don't panic");
}
}
项目:incubator-netbeans
文件:RepositoryBrowserPanel.java
@Override
public void addNotify () {
super.addNotify();
getExplorerManager().setRootContext(root);
getExplorerManager().addPropertyChangeListener(this);
if (toolbar.isVisible()) {
attachToolbarListeners();
}
revisionsPanel1.lstRevisions.addListSelectionListener(this);
revisionsPanel1.lstRevisions.addMouseListener(this);
if (options.contains(Option.DISPLAY_REVISIONS)) {
KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(this);
revisionsPanel1.updateHistory(currRepository, roots, currRevision);
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
int width = revisionsPanel1.getPreferredSize().width;
int leftPanelWidth = jSplitPane1.getPreferredSize().width - width;
jSplitPane1.setDividerLocation(Math.min(200, leftPanelWidth));
if (sliderPos > 0) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run () {
jSplitPane1.setDividerLocation(sliderPos);
}
});
}
}
});
}
if (options.contains(Option.EXPAND_BRANCHES) || options.contains(Option.EXPAND_TAGS)) {
tree.expandNode(root);
}
}
项目:incubator-netbeans
文件:RepositoryBrowserPanel.java
@Override
public void removeNotify() {
if (options.contains(Option.DISPLAY_REVISIONS)) {
KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(this);
}
revisionsPanel1.lstRevisions.removeListSelectionListener(this);
getExplorerManager().removePropertyChangeListener(this);
if (toolbar.isVisible()) {
detachToolbarListeners();
}
super.removeNotify();
}
项目:incubator-netbeans
文件:ETable.java
@Override
public void actionPerformed(ActionEvent e) {
if (isEditing() || editorComp != null) {
removeEditor();
return;
} else {
Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
InputMap imp = getRootPane().getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
ActionMap am = getRootPane().getActionMap();
KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
Object key = imp.get(escape);
if (key == null) {
//Default for NbDialog
key = "Cancel";
}
if (key != null) {
Action a = am.get(key);
if (a != null) {
String commandKey = (String)a.getValue(Action.ACTION_COMMAND_KEY);
if (commandKey == null) {
commandKey = key.toString();
}
a.actionPerformed(new ActionEvent(this,
ActionEvent.ACTION_PERFORMED, commandKey)); //NOI18N
}
}
}
}
项目:incubator-netbeans
文件:TTVTest.java
@RandomlyFails // NB-Core-Build #8093
public void testNodesReleasing () {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
fillAndShowTTV();
// wait for a while to be sure that TTV was completely painted
// and references between property panels -> properties -> nodes
// established
Timer timer = new Timer(5000, new ActionListener () {
public void actionPerformed (ActionEvent evt) {
TTVTest.this.cleanAndCheckTTV();
}
});
timer.setRepeats(false);
timer.start();
}
});
// wait for results
synchronized (this) {
try {
wait();
KeyboardFocusManager.getCurrentKeyboardFocusManager ().clearGlobalFocusOwner ();
for (WeakReference<Node> weakNode : weakNodes) {
assertGC ("Check Node weakNode", weakNode);
}
} catch (InterruptedException exc) {
fail("Test was interrupted somehow.");
}
}
// result needn't be synced, was set before we were notified
if (result > 0) {
System.out.println("OK, TreeTableView released nodes after " + result + " GC cycles");
} else {
System.out.println("TreeTableView leaks memory! Nodes were not freed even after 10 GC cycles.");
fail("TreeTableView leaks memory! Nodes were not freed even after 10 GC cycles.");
}
}
项目:jdk8u-jdk
文件:BasicPopupMenuUI.java
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;
}
项目:incubator-netbeans
文件:NewPropertyPanelTest.java
public void disabled_testTableUIBehavior () throws Exception {
requestFocus (tagsPanel);
System.err.println("TAGS PANEL BOUNDS: " + tagsPanel.getBounds());
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
assertTrue ("After requesting focus on a property with tags, a combo box should have focus, not " + focusOwner,
focusOwner instanceof JComboBox);
assertTrue("After requesting focus on a property with tags, with TableUI false, the combo's popup should not be open",
!((JComboBox) focusOwner).isPopupVisible());
requestFocus(focusButton);
tagsPanel.setPreferences(PropertyPanel.PREF_TABLEUI);
requestFocus(tagsPanel);
focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
assertTrue ("After requesting focus on a property with tags, a combo box should have focus, not " + focusOwner,
focusOwner instanceof JComboBox);
assertTrue("After requesting focus on a property with tags, with TableUI true, the combo's popup should be open",
((JComboBox) focusOwner).isPopupVisible());
sleep();
requestFocus(focusButton);
/*
//Commenting this out for now - too heavily depends to on the look and
//feel's behavior
assertTrue("After shifting focus away from a tableUI combo box, its popup should no longer be open",
!((JComboBox) focusOwner).isPopupVisible());
*/
}