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

下面列出了怎么用java.awt.event.FocusEvent的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jdk8u_jdk   文件: KeyboardFocusManager.java
static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) {
    synchronized (heavyweightRequests) {
        // Any other case represents a failure condition which we did
        // not expect. We need to clearFocusRequestList() and patch up
        // the event as best as possible.

        if (removeFirstRequest()) {
            return (FocusEvent)retargetFocusEvent(fe);
        }

        Component source = fe.getComponent();
        Component opposite = fe.getOppositeComponent();
        boolean temporary = false;
        if (fe.getID() == FocusEvent.FOCUS_LOST &&
            (opposite == null || isTemporary(opposite, source)))
        {
            temporary = true;
        }
        return new CausedFocusEvent(source, fe.getID(), temporary, opposite,
                                    CausedFocusEvent.Cause.NATIVE_SYSTEM);
    }
}
 
源代码2 项目: Java8CN   文件: KeyboardFocusManager.java
static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) {
    synchronized (heavyweightRequests) {
        // Any other case represents a failure condition which we did
        // not expect. We need to clearFocusRequestList() and patch up
        // the event as best as possible.

        if (removeFirstRequest()) {
            return (FocusEvent)retargetFocusEvent(fe);
        }

        Component source = fe.getComponent();
        Component opposite = fe.getOppositeComponent();
        boolean temporary = false;
        if (fe.getID() == FocusEvent.FOCUS_LOST &&
            (opposite == null || isTemporary(opposite, source)))
        {
            temporary = true;
        }
        return new CausedFocusEvent(source, fe.getID(), temporary, opposite,
                                    CausedFocusEvent.Cause.NATIVE_SYSTEM);
    }
}
 
源代码3 项目: JDKSourceCode1.8   文件: KeyboardFocusManager.java
static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) {
    synchronized (heavyweightRequests) {
        // Any other case represents a failure condition which we did
        // not expect. We need to clearFocusRequestList() and patch up
        // the event as best as possible.

        if (removeFirstRequest()) {
            return (FocusEvent)retargetFocusEvent(fe);
        }

        Component source = fe.getComponent();
        Component opposite = fe.getOppositeComponent();
        boolean temporary = false;
        if (fe.getID() == FocusEvent.FOCUS_LOST &&
            (opposite == null || isTemporary(opposite, source)))
        {
            temporary = true;
        }
        return new CausedFocusEvent(source, fe.getID(), temporary, opposite,
                                    CausedFocusEvent.Cause.NATIVE_SYSTEM);
    }
}
 
源代码4 项目: ganttproject   文件: OptionsPageBuilder.java
public JComponent createGroupComponent(GPOptionGroup group) {
  GPOption<?>[] options = group.getOptions();
  final JComponent optionsPanel = createGroupComponent(group, options);
  if (group.isTitled()) {
    UIUtil.createTitle(optionsPanel, myi18n.getOptionGroupLabel(group));
  }
  JPanel result = new JPanel(new BorderLayout());
  result.add(optionsPanel, BorderLayout.NORTH);
  result.addFocusListener(new FocusAdapter() {
    @Override
    public void focusGained(FocusEvent e) {
      optionsPanel.requestFocus();
    }
  });
  return result;
}
 
源代码5 项目: netbeans   文件: BaseTable.java
public void focusGained(FocusEvent fe) {
    Component c = fe.getOppositeComponent();

    /*
    //handy for debugging
    System.out.println("Focus gained to " + (fe.getComponent().getName() == null ? fe.getComponent().getClass().getName() : fe.getComponent().getName()) + " temporary: " + fe.isTemporary()
    + " from " + (fe.getOppositeComponent() == null ? "null" :
        (fe.getOppositeComponent().getName() == null ? fe.getOppositeComponent().getClass().getName() : fe.getOppositeComponent().getName()))
    );
     */
    PropUtils.log(BaseTable.class, fe);

    if (!isKnownComponent(c)) {
        fireChange();
    }

    if (!inEditRequest() && !inEditorRemoveRequest() && (fe.getComponent() == this)) {
        //            System.out.println("Painting due to focus gain " + fe.getComponent());
        //            repaint(0,0,getWidth(),getHeight());
        paintSelectionRow();
    }
}
 
源代码6 项目: MeteoInfo   文件: JDayChooser.java
/**
 * JDayChooser is the FocusListener for all day buttons. (Added by Thomas
 * Schaefer)
 * 
 * @param e
 *            the FocusEvent
 */
/*
 * Code below commented out by Mark Brown on 24 Aug 2004. This code breaks
 * the JDateChooser code by triggering the actionPerformed method on the
 * next day button. This causes the date chosen to always be incremented by
 * one day.
 */
public void focusGained(FocusEvent e) {
	// JButton button = (JButton) e.getSource();
	// String buttonText = button.getText();
	//
	// if ((buttonText != null) && !buttonText.equals("") &&
	// !e.isTemporary()) {
	// actionPerformed(new ActionEvent(e.getSource(), 0, null));
	// }
}
 
源代码7 项目: cuba   文件: TableFocusManager.java
public void processFocusEvent(FocusEvent e) {
//TODO: CUBA 7 Rework TableFocusManager for Java 9
//https://github.com/cuba-platform/cuba/issues/893
//        if (e.getID() == FocusEvent.FOCUS_GAINED) {
//            if (e instanceof CausedFocusEvent) {
//                if (((CausedFocusEvent) e).getCause() == CausedFocusEvent.Cause.TRAVERSAL_FORWARD) {
//                    if (impl.getModel().getRowCount() > 0) {
//                        // if focus from cell editor
//                        if (e.getSource() == impl && impl.getSelectedRow() >= 0) {
//                            int selectedColumn = impl.getSelectedColumn();
//                            focusTo(impl.getSelectedRow(), selectedColumn >= 0 ? selectedColumn : 0);
//                        } else
//                            moveToStart(0, 0);
//                    } else
//                        impl.transferFocus();
//
//                } else if (((CausedFocusEvent) e).getCause() == CausedFocusEvent.Cause.TRAVERSAL_BACKWARD) {
//                    if (impl.getModel().getRowCount() > 0) {
//                        moveToEnd(impl.getRowCount() - 1, impl.getColumnCount() - 1);
//                    } else
//                        impl.transferFocusBackward();
//                }
//            }
//        }
    }
 
源代码8 项目: jaamsim   文件: GUIFrame.java
private void addSnapToGridField(JToolBar buttonBar, Insets margin) {

		gridSpacing = new JTextField("1000000 m") {
			@Override
			protected void processFocusEvent(FocusEvent fe) {
				if (fe.getID() == FocusEvent.FOCUS_LOST) {
					GUIFrame.this.setSnapGridSpacing(this.getText().trim());
				}
				else if (fe.getID() == FocusEvent.FOCUS_GAINED) {
					gridSpacing.selectAll();
				}
				super.processFocusEvent( fe );
			}
		};

		gridSpacing.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) {
				GUIFrame.this.setSnapGridSpacing(gridSpacing.getText().trim());
				controlStartResume.requestFocusInWindow();
			}
		});

		gridSpacing.setMaximumSize(gridSpacing.getPreferredSize());
		int hght = snapToGrid.getPreferredSize().height;
		gridSpacing.setPreferredSize(new Dimension(gridSpacing.getPreferredSize().width, hght));

		gridSpacing.setHorizontalAlignment(JTextField.RIGHT);
		gridSpacing.setToolTipText(formatToolTip("Snap Grid Spacing",
				"Distance between adjacent grid points, e.g. 0.1 m, 10 km, etc."));

		gridSpacing.setEnabled(snapToGrid.isSelected());

		buttonBar.add(gridSpacing);
	}
 
源代码9 项目: radiance   文件: SelectAllOnFocusGainWidget.java
@Override
public void installListeners() {
    this.focusListener = new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            SwingUtilities.invokeLater(() -> {
                if (WidgetUtilities.hasTextFocusSelectAllProperty(jcomp)
                        && jcomp.isEditable())
                    jcomp.selectAll();
            });
        }
    };
    this.jcomp.addFocusListener(this.focusListener);
}
 
源代码10 项目: jdk8u-dev-jdk   文件: LWTextFieldPeer.java
/**
 * Restoring native behavior. We should sets the selection range to zero,
 * when component lost its focus.
 *
 * @param e the focus event
 */
@Override
void handleJavaFocusEvent(final FocusEvent e) {
    if (e.getID() == FocusEvent.FOCUS_LOST) {
        // In order to de-select the selection
        setCaretPosition(0);
    }
    super.handleJavaFocusEvent(e);
}
 
源代码11 项目: darklaf   文件: ColorValueFormatter.java
public void focusGained(final FocusEvent event) {
    Object source = event.getSource();
    if (source instanceof JFormattedTextField) {
        this.text = (JFormattedTextField) source;
        SwingUtilities.invokeLater(() -> {
            if (this.text != null) {
                this.text.selectAll();
            }
        });
    }
}
 
源代码12 项目: ECG-Viewer   文件: DefaultValueAxisEditor.java
/**
 *  Revalidates minimum/maximum range.
 *
 *  @param event  the event.
 */
@Override
public void focusLost(FocusEvent event) {
    if (event.getSource() == this.minimumRangeValue) {
        validateMinimum();
    }
    else if (event.getSource() == this.maximumRangeValue) {
        validateMaximum();
    }
}
 
源代码13 项目: javamoney-examples   文件: FormDateHandler.java
public
void
focusLost(FocusEvent event)
{
  JTextField field = (JTextField)event.getSource();

  field.setText(UI_DATE_FORMAT.format(getDate(field)));
}
 
源代码14 项目: netbeans   文件: URLPatternStep.java
public void focusGained(FocusEvent evt) {
    if(evt.getSource() == urlPatternPanel.depthComboBox && 
       ! urlPatternPanel.useSubfolderRadioButton.isSelected()) 
    {
        urlPatternPanel.useSubfolderRadioButton.setSelected(true);
    }        
}
 
源代码15 项目: flutter-intellij   文件: FlutterSettingsStep.java
@Override
protected void onWizardStarting(@NotNull ModelWizard.Facade wizard) {
  FlutterProjectModel model = getModel();
  myKotlinCheckBox.setText(FlutterBundle.message("module.wizard.language.name_kotlin"));
  mySwiftCheckBox.setText(FlutterBundle.message("module.wizard.language.name_swift"));
  myBindings.bindTwoWay(new SelectedProperty(myUseAndroidxCheckBox), getModel().useAndroidX());

  TextProperty packageNameText = new TextProperty(myPackageName);

  Expression<String> computedPackageName = new DomainToPackageExpression(model.companyDomain(), model.projectName()) {
    @Override
    public String get() {
      return super.get().replaceAll("_", "");
    }
  };
  BoolProperty isPackageSynced = new BoolValueProperty(true);
  myBindings.bind(packageNameText, computedPackageName, isPackageSynced);
  myBindings.bind(model.packageName(), packageNameText);
  myListeners.listen(packageNameText, value -> isPackageSynced.set(value.equals(computedPackageName.get())));

  // The wizard changed substantially in 3.5. Something causes this page to not get properly validated
  // after it is added to the Swing tree. Here we check that we have to validate the tree, then do so.
  // It only needs to be done once, so we remove the listener to prevent possible flicker.
  focusListener = new FocusAdapter() {
    @Override
    public void focusGained(FocusEvent e) {
      super.focusGained(e);
      Container parent = myRoot;
      while (parent != null && !(parent instanceof JBLayeredPane)) {
        parent = parent.getParent();
      }
      if (parent != null) {
        parent.validate();
      }
      myPackageName.removeFocusListener(focusListener);
    }
  };
  myPackageName.addFocusListener(focusListener);
}
 
源代码16 项目: rest-client   文件: UrlComboBox.java
public UrlComboBox() {
    setToolTipText("URL");
    setEditable(true);
    final JTextField editorComponent = (JTextField) getEditor().getEditorComponent();
    editorComponent.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            editorComponent.selectAll();
        }
    });
    
    AutoCompletion ac = new AutoCompletion(this);
    ac.setStrict(false);
    ac.setStrictCompletion(false);
}
 
@Override
public void focusLost(FocusEvent focusEvent) {
    String controllerName = getControllerName();
    if (controllerName == null) {
        return;
    }
    form.getControllerNameBox().getChildComponent().getEditor().setItem(controllerName);

}
 
@Override
public void focusGained(FocusEvent e) {
    if (e.getSource() instanceof JTextField) {
        JTextField tf = (JTextField) e.getSource();
        if (!tf.getText().isEmpty()) {
            tf.setText("");
            tf.setForeground(new Color(50, 50, 50));
        }
    }
}
 
源代码19 项目: netbeans   文件: QueryController.java
@Override
public void focusGained(FocusEvent e) {
    if(panel.changedFromTextField.getText().equals("")) {                   // NOI18N
        String lastChangeFrom = BugzillaConfig.getInstance().getLastChangeFrom();
        panel.changedFromTextField.setText(lastChangeFrom);
        panel.changedFromTextField.setSelectionStart(0);
        panel.changedFromTextField.setSelectionEnd(lastChangeFrom.length());
    }
}
 
源代码20 项目: java-swing-tips   文件: MainPanel.java
private MainPanel() {
  super(new GridLayout(2, 1));

  JTextField field = new JTextField("aaaaaaaaa");
  field.addFocusListener(new FocusAdapter() {
    @Override public void focusGained(FocusEvent e) {
      ((JTextComponent) e.getComponent()).selectAll();
    }
  });

  add(makeTitledPanel("focusGained: selectAll", field));
  add(makeTitledPanel("default", new JTextField("bbbbbbbbb")));
  setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
  setPreferredSize(new Dimension(320, 240));
}
 
源代码21 项目: gcs   文件: PageField.java
@Override
protected void processFocusEvent(FocusEvent event) {
    super.processFocusEvent(event);
    if (event.getID() == FocusEvent.FOCUS_GAINED) {
        selectAll();
    }
}
 
源代码22 项目: mylizzie   文件: ChangeMoveDialog.java
private void handleSpinnerMoveNumberEditorFocusGained(FocusEvent e) {
    Component component = e.getComponent();

    if (component instanceof JTextComponent) {
        final JTextComponent textComponent = (JTextComponent) component;
        Lizzie.miscExecutor.schedule(() -> SwingUtilities.invokeLater(textComponent::selectAll), 250, TimeUnit.MILLISECONDS);
    }
}
 
源代码23 项目: 3DSoftwareRenderer   文件: Input.java
/** Updates state when the window loses focus */
public void focusLost(FocusEvent e) {
	for (int i = 0; i < keys.length; i++)
		keys[i] = false;
	for (int i = 0; i < mouseButtons.length; i++)
		mouseButtons[i] = false;
}
 
源代码24 项目: netbeans   文件: WeakListener.java
/** Delegates to the original listener.
*/
public void focusGained(FocusEvent ev) {
    FocusListener l = (FocusListener) super.get(ev);

    if (l != null) {
        l.focusGained(ev);
    }
}
 
@Override
protected void processFocusEvent(FocusEvent e) {
    super.processFocusEvent(e);
    floatingLabel.update();
    line.update();
    repaint();
}
 
源代码26 项目: netbeans   文件: ButtonFactory.java
@Override
protected void processFocusEvent(FocusEvent fe) {
    super.processFocusEvent(fe);
    if (fe.getID() == FocusEvent.FOCUS_LOST) {
        stopTimer();
    }
}
 
@SuppressWarnings("deprecation")
public static boolean deliverFocus(Component lightweightChild,
                                   Component target,
                                   boolean temporary,
                                   boolean focusedWindowChangeAllowed,
                                   long time,
                                   CausedFocusEvent.Cause cause,
                                   Component currentFocusOwner) // provided by the descendant peers
{
    if (lightweightChild == null) {
        lightweightChild = target;
    }

    Component currentOwner = currentFocusOwner;
    if (currentOwner != null && currentOwner.getPeer() == null) {
        currentOwner = null;
    }
    if (currentOwner != null) {
        FocusEvent fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST,
                                             false, lightweightChild, cause);

        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
            focusLog.finer("Posting focus event: " + fl);
        }
        SunToolkit.postEvent(SunToolkit.targetToAppContext(currentOwner), fl);
    }

    FocusEvent fg = new CausedFocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED,
                                         false, currentOwner, cause);

    if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
        focusLog.finer("Posting focus event: " + fg);
    }
    SunToolkit.postEvent(SunToolkit.targetToAppContext(lightweightChild), fg);
    return true;
}
 
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);
}
 
@Override
public void clearGlobalFocusOwner(Window activeWindow) {
    if (activeWindow != null) {
        Component focusOwner = activeWindow.getFocusOwner();
        if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
            focusLog.fine("Clearing global focus owner " + focusOwner);
        }
        if (focusOwner != null) {
            FocusEvent fl = new CausedFocusEvent(focusOwner, FocusEvent.FOCUS_LOST, false, null,
                                                 CausedFocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER);
            SunToolkit.postPriorityEvent(fl);
        }
    }
}
 
源代码30 项目: openjdk-8-source   文件: XComponentPeer.java
/**
 * Called when component receives focus
 */
public void focusGained(FocusEvent e) {
    if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
        focusLog.fine("{0}", e);
    }
    bHasFocus = true;
}