Java 类java.awt.event.FocusEvent 实例源码

项目:incubator-netbeans    文件:EditorUI.java   
/** Construct extended UI for the use with a text component */
public EditorUI() {
    focusL = new FocusAdapter() {
                 public @Override void focusGained(FocusEvent evt) {
                     /* Fix of #25475 - copyAction's enabled flag
                      * must be updated on focus change
                      */
                     stateChanged(null);
                     if (component!=null){
                        BaseTextUI ui = (BaseTextUI)component.getUI();
                        if (ui!=null) ui.refresh();
                     }
                 }

                 @Override
                 public void focusLost(FocusEvent e) {
                     // see #222935, update actions before menu activates
                     if (e.isTemporary()) {
                         doStateChange(true);
                     }
                 }
             };

    getToolTipSupport();
}
项目:incubator-netbeans    文件:SpecialkeyPanel.java   
/** Creates new form SpecialkeyPanel */
public SpecialkeyPanel(final Popupable parent, JTextField target) {
    this.parent = parent;
    this.target = target;
    initComponents();

    target.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            parent.hidePopup();
        }
    });

    downButton.addActionListener(this);
    enterButton.addActionListener(this);
    escButton.addActionListener(this);
    leftButton.addActionListener(this);
    rightButton.addActionListener(this);
    tabButton.addActionListener(this);
    upButton.addActionListener(this);
    wheelUpButton.addActionListener(this);
    wheelDownButton.addActionListener(this);
}
项目:openjdk-jdk10    文件:XComponentPeer.java   
void handleJavaMouseEvent(MouseEvent e) {
        switch (e.getID()) {
          case MouseEvent.MOUSE_PRESSED:
              if (target == e.getSource() &&
                  !target.isFocusOwner() &&
                  XKeyboardFocusManagerPeer.shouldFocusOnClick(target))
              {
                  XWindowPeer parentXWindow = getParentTopLevel();
                  Window parentWindow = ((Window)parentXWindow.getTarget());
                  // Simple windows are non-focusable in X terms but focusable in Java terms.
                  // As X-non-focusable they don't receive any focus events - we should generate them
                  // by ourselfves.
//                   if (parentXWindow.isFocusableWindow() /*&& parentXWindow.isSimpleWindow()*/ &&
//                       !(getCurrentNativeFocusedWindow() == parentWindow))
//                   {
//                       setCurrentNativeFocusedWindow(parentWindow);
//                       WindowEvent wfg = new WindowEvent(parentWindow, WindowEvent.WINDOW_GAINED_FOCUS);
//                       parentWindow.dispatchEvent(wfg);
//                   }
                  XKeyboardFocusManagerPeer.requestFocusFor(target, FocusEvent.Cause.MOUSE_EVENT);
              }
              break;
        }
    }
项目:incubator-netbeans    文件:BaseCaret.java   
public @Override void focusGained(FocusEvent evt) {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine(
                "BaseCaret.focusGained(); doc=" + // NOI18N
                component.getDocument().getProperty(Document.TitleProperty) + '\n'
        );
    }

    JTextComponent c = component;
    if (c != null) {
        updateType();
        if (component.isEnabled()) {
            if (component.isEditable()) {
                setVisible(true);
        }
            setSelectionVisible(true);
        }
        if (LOG.isLoggable(Level.FINER)) {
            LOG.finer("Caret visibility: " + isVisible() + '\n'); // NOI18N
        }
    } else {
        if (LOG.isLoggable(Level.FINER)) {
            LOG.finer("Text component is null, caret will not be visible" + '\n'); // NOI18N
        }
    }
}
项目:incubator-netbeans    文件:WeakListenerImpl.java   
/** Delegates to the original listener.
*/
@Override public void focusLost(FocusEvent ev) {
    FocusListener l = (FocusListener) super.get(ev);

    if (l != null) {
        l.focusLost(ev);
    }
}
项目:incubator-netbeans    文件:TreeView.java   
@Override
public Object run() {
    switch (type) {
    case 0:
        guardedPaint((Graphics) p1);
        break;
    case 1:
        guardedValidateTree();
        break;
    case 2:
        guardedDoLayout();
        break;
    case 3:
        ExplorerTree.super.processFocusEvent((FocusEvent)p1);
        //Since the selected when focused is different, we need to force a
        //repaint of the entire selection, but let's do it in guarded more
        //as any other repaint
        repaintSelection();
        break;
    default:
        throw new IllegalStateException("type: " + type);
    }

    return null;
}
项目:openjdk-jdk10    文件:DefaultKeyboardFocusManager.java   
private boolean doRestoreFocus(Component toFocus, Component vetoedComponent,
                               boolean clearOnFailure)
{
    if (toFocus != vetoedComponent && toFocus.isShowing() && toFocus.canBeFocusOwner() &&
        toFocus.requestFocus(false, FocusEvent.Cause.ROLLBACK))
    {
        return true;
    } else {
        Component nextFocus = toFocus.getNextFocusCandidate();
        if (nextFocus != null && nextFocus != vetoedComponent &&
            nextFocus.requestFocusInWindow(FocusEvent.Cause.ROLLBACK))
        {
            return true;
        } else if (clearOnFailure) {
            clearGlobalFocusOwnerPriv();
            return true;
        } else {
            return false;
        }
    }
}
项目:incubator-netbeans    文件:ETable.java   
@Override
public void focusLost(FocusEvent e) {
    Component c = e.getOppositeComponent();
    if (c != searchCombo) {
        removeSearchField();
    }
}
项目:incubator-netbeans    文件:DirectoryChooserUI.java   
/******** implementation of focus listener, for slow click rename cancelling ******/ 

        @Override
        public void focusGained(FocusEvent e) {
            // don't allow to invoke click to rename immediatelly after focus gain
            // what may happen is that tree gains focus by mouse
            // click on selected item - on some platforms selected item
            // is not visible without focus and click to rename will
            // be unwanted and surprising for users

            // see run method
            SwingUtilities.invokeLater(this);
        }
项目:openjdk-jdk10    文件:Util.java   
private static boolean trackEvent(int eventID, Component comp, Runnable action, int time, boolean printEvent) {
    EventListener listener = null;

    switch (eventID) {
    case WindowEvent.WINDOW_GAINED_FOCUS:
        listener = wgfListener;
        break;
    case FocusEvent.FOCUS_GAINED:
        listener = fgListener;
        break;
    case ActionEvent.ACTION_PERFORMED:
        listener = apListener;
        break;
    }

    listener.listen(comp, printEvent);
    action.run();
    return Util.waitForCondition(listener.getNotifier(), time);
}
项目:incubator-netbeans    文件:SimpleTestStepLocation.java   
/**
 */
private void tfClassToTestFocusLost(FocusEvent e) {
    final Component allowFocusGain = focusGainAllowedFor;
    focusGainAllowedFor = null;

    if (multipleSourceRoots
            && interactionRestrictionsActive
            && !interactionRestrictionsSuspended) {

        final Component opposite = e.getOppositeComponent();

        if ((allowFocusGain != null) && (opposite == allowFocusGain)) {
            return;
        }
        if (opposite == btnBrowse) {
            return;
        }
        if ((opposite instanceof JLabel)
                && (((JLabel) opposite).getLabelFor() == tfClassToTest)) {
            /*
             * When a JLabel's mnemonic key is pressed, the JLabel gains focus
             * until the key is released again. That's why we must ignore such
             * focus transfers.
             */
            return;
        }

        if (!maybeDisplaySourceGroupChooser()) {

            /* send the request back to the Test to Class textfield: */
            tfClassToTest.requestFocus();
        }
    }
}
项目:hearthstone    文件:PopUp.java   
/**
 * Configurar os componentes da janela
 */
public final void init() {
    setLayout(new AbsoluteLayout());
    setUndecorated(true);
    setBackground(new Color(0, 0, 0, 0));
    add(new JLabel(imagem), new AbsoluteConstraints(0, 0));
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            dispose();
        }
    });
}
项目:educational-plugin    文件:CCCreateAnswerPlaceholderPanel.java   
public CCCreateAnswerPlaceholderPanel(@Nullable String placeholderText, @NotNull List<String> hints) {
  if (hints.isEmpty()) {
    myHints.add(HINT_PLACEHOLDER);
  }
  else {
    myHints.addAll(hints);
  }

  myPlaceholderTextArea.setBorder(BorderFactory.createLineBorder(JBColor.border()));
  myPlaceholderTextArea.setText(placeholderText);
  myPlaceholderTextArea.addFocusListener(new FocusAdapter() {
    @Override
    public void focusGained(FocusEvent e) {
      myPlaceholderTextArea.selectAll();
    }
  });
  myPlaceholderTextArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
  myPlaceholderTextArea.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);

  myHintsPanel.setBorder(BorderFactory.createLineBorder(JBColor.border()));
  ((GridLayoutManager)myHintsPanel.getLayout()).setHGap(1);

  myHintTextArea.setFont(UIUtil.getLabelFont());
  myPlaceholderTextArea.setFont(UIUtil.getLabelFont());
  myHintTextArea.addFocusListener(createFocusListenerToSetDefaultHintText());

  actionsPanel.add(createHintToolbarComponent(), BorderLayout.WEST);
  showHint();
}
项目:incubator-netbeans    文件:FileNameController.java   
@Override
public void focusGained(FocusEvent e) {

    /*
     * Order of method calls hideInfo() and super.focusGained(e) is
     * important! See bug #113202.
     */

    if (infoDisplayed) {
        hideInfo();
    }
    super.focusGained(e);   //selects all text
}
项目:OpenDA    文件:CaseExtractorGUI.java   
public void focusLost(FocusEvent e) {
       Object source = e.getSource();
       if (source == windowsSwanExeTextField) {
        //if windowsSwanExeTextField lost focus.
        updateSwanExecutableFromTextField();
       }
}
项目:AgentWorkbench    文件:ChartEditorJPanel.java   
@Override
public void focusLost(FocusEvent fe) {
    // --- Recalculate image size when leaving one of the text fields
    if(fe.getSource()==tfImageWidth){
        this.recalculateImageHeight();
    } else if(fe.getSource()==tfImageHeight) {
        this.recalculateImageWidth();
    }
}
项目:incubator-netbeans    文件:UIUtils.java   
@SuppressWarnings("OverridableMethodCallInConstructor")
DummyDatePickerComponent () {
    super(13);
    addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            Date newValue = getDate();
            if(! Objects.equals(oldValue, newValue)) {
                support.fireChange();
            }
            setDate(newValue);
        }
    });
}
项目:openjdk-jdk10    文件:APIFocusDriver.java   
@Override
public void giveFocus(ComponentOperator operator) {
    operator.requestFocus();
    eDriver.dispatchEvent(operator.getSource(),
            new FocusEvent(operator.getSource(),
                    FocusEvent.FOCUS_GAINED));
}
项目:incubator-netbeans    文件:IOWindow.java   
@Override
public void processFocusEvent(FocusEvent fe) {
    super.processFocusEvent(fe);
    if (Boolean.TRUE.equals(getClientProperty("isSliding"))) { //NOI18N
        repaint(200);
    }
}
项目:incubator-netbeans    文件:NameChangeSupport.java   
@Override
public void focusLost(FocusEvent e) {
    // must revalidate immediately
    if (validateTask.cancel()) {
        this.validateName = control.getText().trim();
        run();
    }
}
项目:openjdk-jdk10    文件:ContainerFocusAutoTransferTest.java   
public void init() {
    robot = Util.createRobot();
    kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        public void eventDispatched(AWTEvent event) {
            System.out.println("--> " + event);
        }
    }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);
}
项目:openjdk-jdk10    文件:XKeyboardFocusManagerPeer.java   
public static boolean deliverFocus(Component lightweightChild,
                                   Component target,
                                   boolean temporary,
                                   boolean focusedWindowChangeAllowed,
                                   long time,
                                   FocusEvent.Cause cause)
{
    return KeyboardFocusManagerPeerImpl.deliverFocus(lightweightChild,
                                                     target,
                                                     temporary,
                                                     focusedWindowChangeAllowed,
                                                     time,
                                                     cause,
                                                     getInstance().getCurrentFocusOwner());
}
项目:SE2017-Team2    文件:HintTextField.java   
@Override
public void focusLost(FocusEvent e) {
    if (this.getText().isEmpty()) {
        super.setText(hint);
        super.setForeground(Color.gray);
        showingHint = true;
    }
}
项目:openjdk-jdk10    文件:IndependenceSwingTest.java   
public IndependenceSwingTest() {

        frame = new JFrame();
        frame.setSize(200, 200);

        // This textfield will be used to update the contents of clipboards
        tf1 = new JTextField();
        tf1.addFocusListener(new FocusAdapter() {
            public void focusGained(FocusEvent fe) {
                tf1.setText("Clipboards_Independance_Testing");
            }
        });

        // TextFields to get the contents of clipboard
        tf2 = new JTextField();
        tf3 = new JTextField();

        panel = new JPanel();
        panel.setLayout(new BorderLayout());

        panel.add(tf2, BorderLayout.NORTH);
        panel.add(tf3, BorderLayout.SOUTH);

        frame.add(tf1, BorderLayout.NORTH);
        frame.add(panel, BorderLayout.CENTER);

        frame.setVisible(true);
        tf1.requestFocus();
    }
项目:incubator-netbeans    文件:WatchAnnotationProvider.java   
@Override
public void focusLost(FocusEvent e) {
    if (lastFocusOwner != null) {
        lastFocusOwner.removeKeyListener(this);
        lastFocusOwner = null;
    }
    unsetSelectCursor();
}
项目:VASSAL-src    文件:PropertySheet.java   
public void focusLost(FocusEvent event) {
  if (event.getComponent() instanceof JTable) {
    JTable table = (JTable) event.getComponent();
    if (table.isEditing()) {
      table.getCellEditor().stopCellEditing();
    }
  }
}
项目:OpenDA    文件:Query.java   
public void focusLost(FocusEvent e) {
    // NOTE: Java's lame AWT has no reliable way
    // to take action on window closing, so this focus lost
    // notification is the only reliable way we have of reacting
    // to a closing window.  If the previous
    // notification was an erroneous one and the value has not
    // changed, then no further notification occurs.
    // This could be a problem for some users of this class.
    _notifyListeners(_name);
}
项目:routerapp    文件:PropertyInteractionWindow.java   
/**
 * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
 */
public void focusGained(FocusEvent e) {
    if (e.getSource() == editableField) {
        String text = editableField.getText();

        editableField.setSelectionStart(0);
        editableField.setSelectionEnd(text.length());
    }
}
项目:jdk8u-jdk    文件:ContainerFocusAutoTransferTest.java   
public void init() {
    robot = Util.createRobot();
    kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        public void eventDispatched(AWTEvent event) {
            System.out.println("--> " + event);
        }
    }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);
}
项目:openjdk-jdk10    文件:XComponentPeer.java   
/**
 * Called when component loses focus
 */
public void focusLost(FocusEvent e) {
    if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
        focusLog.fine("{0}", e);
    }
    bHasFocus = false;
}
项目:incubator-netbeans    文件:ETable.java   
@Override
public void focusLost(FocusEvent e) {
    Component c = e.getOppositeComponent();
    if (c != searchTextField) {
        removeSearchField();
    }
}
项目:ramus    文件:DFrame.java   
public DFrame(final Control control) {
    super(new BorderLayout());
    setFocusable(true);
    setFocusCycleRoot(true);
    this.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            control.focusGained(DFrame.this);
        }
    });
    control.addDFrame(this);
}
项目:WhatsappCrush    文件:WhatsappCrushGUI.java   
@Override
public void focusLost(FocusEvent e) {
    PointerInfo pi = MouseInfo.getPointerInfo();
    Point p = pi.getLocation();
    System.out.println("X is " + p.x);
    System.out.println("Y is " + p.y);
    x = p.x;
    y = p.y;
    button1.setLabel("Try Again");
    label.setText("Successfully Clicked. Ready to Start Crushing...");
    label.setBackground(Color.GREEN);
    button2.setEnabled(true);
    button1.removeFocusListener(focusListerner);
}
项目:incubator-netbeans    文件:NewConnectionPanel.java   
@Override
public void focusLost(FocusEvent e) {
    Object source = e.getSource();
    if (source instanceof JTextField) {
        JTextField textField = (JTextField) source;
        String inputText = textField.getText();
        switch(targetToken) {
            case JdbcUrl.TOKEN_HOST:
            case JdbcUrl.TOKEN_DB:
            case JdbcUrl.TOKEN_SID:
            case JdbcUrl.TOKEN_SERVICENAME:
            case JdbcUrl.TOKEN_TNSNAME:
            case JdbcUrl.TOKEN_DSN:
            case JdbcUrl.TOKEN_SERVERNAME:
            case JdbcUrl.TOKEN_INSTANCE:
            case USERINPUT_FIELD:
                textField.setText(inputText.trim());
                break;
            case JdbcUrl.TOKEN_PORT:
                Integer port = null;
                try {
                    port = Integer.valueOf(inputText.trim());
                } catch (NumberFormatException ex) {}
                if(port != null) {
                    textField.setText(Integer.toString(port));
                } else {
                    Matcher numberMatcher = numbers.matcher(inputText);
                    if(numberMatcher.find()) {
                        textField.setText(numberMatcher.group(1));
                    } else {
                        textField.setText("");
                    }
                }
                break;
            default:
                // Unhandled fields are left untouched
                break;
        }
    }
}
项目:jaer    文件:PotPanel.java   
public void focusGained(FocusEvent e) { // some control sends this event, color the pot control border red for that control and others blank
        Component src=e.getComponent();
//        log.info("focus gained by "+src.getClass().getSimpleName());
        if (selectedControl != null)((JComponent)selectedControl).setBorder(unselectedBorder);
        do{
            Component parent=src.getParent();
            if (componentList.contains(parent)) {
                ((JComponent)parent).setBorder(selectedBorder);
                selectedControl=parent;
                break;
            }
            src = parent;
        } while(src != null);
    }
项目:incubator-netbeans    文件:NewPropertyPanelTest.java   
public void assertLost(String msg) {
    int currLostCount = lostCount;
    lostCount = 0;
    FocusEvent lost = lostEvent;
    lostEvent = null;
    assertNotNull (msg, lost);
    assertTrue("Received wrong number of focus lost events for a single click away from a focused renderer" + currLostCount, currLostCount == 1);
}
项目:incubator-netbeans    文件:ConfigurationsComboModel.java   
@Override
public void focusLost(FocusEvent fe) {
    confirm(fe);
}
项目:jdk8u-jdk    文件:SynthTextFieldUI.java   
public void focusLost(FocusEvent e) {
    getComponent().repaint();
}
项目:incubator-netbeans    文件:TextFieldFocusListener.java   
@Override
public void focusLost(FocusEvent e) {
    /*
     * do nothing
     */
}
项目:openjdk-jdk10    文件:WComponentPeer.java   
@Override
public boolean requestFocus(Component lightweightChild, boolean temporary,
                            boolean focusedWindowChangeAllowed, long time,
                            FocusEvent.Cause cause)
{
    if (WKeyboardFocusManagerPeer.
        processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
                                              focusedWindowChangeAllowed, time))
    {
        return true;
    }

    int result = WKeyboardFocusManagerPeer
        .shouldNativelyFocusHeavyweight((Component)target, lightweightChild,
                                        temporary, focusedWindowChangeAllowed,
                                        time, cause);

    switch (result) {
      case WKeyboardFocusManagerPeer.SNFH_FAILURE:
          return false;
      case WKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
          if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
              focusLog.finer("Proceeding with request to " + lightweightChild + " in " + target);
          }
          Window parentWindow = SunToolkit.getContainingWindow((Component)target);
          if (parentWindow == null) {
              return rejectFocusRequestHelper("WARNING: Parent window is null");
          }
          final WWindowPeer wpeer = AWTAccessor.getComponentAccessor()
                                               .getPeer(parentWindow);
          if (wpeer == null) {
              return rejectFocusRequestHelper("WARNING: Parent window's peer is null");
          }
          boolean res = wpeer.requestWindowFocus(cause);

          if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
              focusLog.finer("Requested window focus: " + res);
          }
          // If parent window can be made focused and has been made focused(synchronously)
          // then we can proceed with children, otherwise we retreat.
          if (!(res && parentWindow.isFocused())) {
              return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
          }
          return WKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
                                                        (Component)target,
                                                        temporary,
                                                        focusedWindowChangeAllowed,
                                                        time, cause);

      case WKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
          // Either lightweight or excessive request - all events are generated.
          return true;
    }
    return false;
}