use of java.awt.event.FocusListener in project intellij-community by JetBrains.
the class BaseControl method initialize.
private void initialize(final Bound boundComponent) {
myBoundComponent = createMainComponent(boundComponent);
final JComponent highlightedComponent = getHighlightedComponent(myBoundComponent);
myDefaultForeground = highlightedComponent.getForeground();
myDefaultBackground = highlightedComponent.getBackground();
final JComponent component = getComponentToListenFocusLost(myBoundComponent);
if (component != null) {
component.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
if (!e.isTemporary() && isValid()) {
commit();
}
}
});
}
updateComponent();
}
use of java.awt.event.FocusListener in project intellij-community by JetBrains.
the class XWatchesViewImpl method installEditListeners.
private void installEditListeners() {
final XDebuggerTree watchTree = getTree();
final Alarm quitePeriod = new Alarm();
final Alarm editAlarm = new Alarm();
final ClickListener mouseListener = new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent event, int clickCount) {
if (!SwingUtilities.isLeftMouseButton(event) || ((event.getModifiers() & (InputEvent.SHIFT_MASK | InputEvent.ALT_MASK | InputEvent.CTRL_MASK | InputEvent.META_MASK)) != 0)) {
return false;
}
boolean sameRow = isAboveSelectedItem(event, watchTree, false);
if (!sameRow || clickCount > 1) {
editAlarm.cancelAllRequests();
return false;
}
final AnAction editWatchAction = ActionManager.getInstance().getAction(XDebuggerActions.XEDIT_WATCH);
Presentation presentation = editWatchAction.getTemplatePresentation().clone();
DataContext context = DataManager.getInstance().getDataContext(watchTree);
final AnActionEvent actionEvent = new AnActionEvent(null, context, "WATCH_TREE", presentation, ActionManager.getInstance(), 0);
Runnable runnable = () -> editWatchAction.actionPerformed(actionEvent);
if (editAlarm.isEmpty() && quitePeriod.isEmpty()) {
editAlarm.addRequest(runnable, UIUtil.getMultiClickInterval());
} else {
editAlarm.cancelAllRequests();
}
return false;
}
};
final ClickListener mouseEmptySpaceListener = new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent event) {
if (!isAboveSelectedItem(event, watchTree, true)) {
myRootNode.addNewWatch();
return true;
}
return false;
}
};
ListenerUtil.addClickListener(watchTree, mouseListener);
ListenerUtil.addClickListener(watchTree, mouseEmptySpaceListener);
final FocusListener focusListener = new FocusListener() {
@Override
public void focusGained(@NotNull FocusEvent e) {
quitePeriod.addRequest(EmptyRunnable.getInstance(), UIUtil.getMultiClickInterval());
}
@Override
public void focusLost(@NotNull FocusEvent e) {
editAlarm.cancelAllRequests();
}
};
ListenerUtil.addFocusListener(watchTree, focusListener);
final TreeSelectionListener selectionListener = new TreeSelectionListener() {
@Override
public void valueChanged(@NotNull TreeSelectionEvent e) {
quitePeriod.addRequest(EmptyRunnable.getInstance(), UIUtil.getMultiClickInterval());
}
};
watchTree.addTreeSelectionListener(selectionListener);
myDisposables.add(new Disposable() {
@Override
public void dispose() {
ListenerUtil.removeClickListener(watchTree, mouseListener);
ListenerUtil.removeClickListener(watchTree, mouseEmptySpaceListener);
ListenerUtil.removeFocusListener(watchTree, focusListener);
watchTree.removeTreeSelectionListener(selectionListener);
}
});
}
use of java.awt.event.FocusListener in project intellij-community by JetBrains.
the class TrailingSpacesStripperTest method testModifyAndAltTabAway.
public void testModifyAndAltTabAway() throws IOException {
configureFromFileText("x.txt", "xxx<caret>\nyyy");
type(' ');
FocusEvent event = new FocusEvent(getEditor().getContentComponent(), 1005);
FocusListener[] listeners = getEditor().getContentComponent().getListeners(FocusListener.class);
for (FocusListener listener : listeners) {
listener.focusLost(event);
}
stripTrailingSpaces();
checkResultByText("xxx <caret>\nyyy");
}
use of java.awt.event.FocusListener in project adempiere by adempiere.
the class Find method jbInit.
/**
* Static Init.
* <pre>
* tabbedPane
* simplePanel
* scontentPanel
* confirmPanelS
* advancedPanel
* toolBar
* GC
* confirmPanelA
* southPanel
* statusBar
* </pre>
* @throws Exception
*/
private void jbInit() throws Exception {
spaceE = Box.createHorizontalStrut(8);
spaceN = Box.createVerticalStrut(8);
spaceW = Box.createHorizontalStrut(8);
spaceS = Box.createVerticalStrut(8);
bIgnore.setIcon(new ImageIcon(org.compiere.Adempiere.class.getResource("images/Ignore24.gif")));
bIgnore.setMargin(new Insets(2, 2, 2, 2));
bIgnore.setToolTipText(Msg.getMsg(Env.getCtx(), "Ignore"));
bIgnore.addActionListener(this);
fQueryName.setToolTipText(m_sToolTipText);
fQueryName.setEditable(true);
fQueryName.addActionListener(this);
fQueryName.getEditor().getEditorComponent().addFocusListener(new FocusListener() {
public void focusGained(FocusEvent arg0) {
// fQueryName received the focus - delete the tip text so the user can type without
// having to delete the tip.
int index = fQueryName.getSelectedIndex();
if (index < 0) {
if (fQueryName.getSelectedItem() == null || fQueryName.getSelectedItem().equals(m_sTipText)) {
fQueryName.setSelectedIndex(-1);
fQueryName.setSelectedItem("");
}
}
}
public void focusLost(FocusEvent arg0) {
// fQueryName lost the focus. If the field is blank, replace the tip text.
if (fQueryName.getSelectedItem() != null && fQueryName.getSelectedItem().equals("")) {
fQueryName.setSelectedItem(m_sTipText);
}
}
});
bSave.setIcon(new ImageIcon(org.compiere.Adempiere.class.getResource("images/Save24.gif")));
bSave.setMargin(new Insets(2, 2, 2, 2));
bSave.setToolTipText(Msg.getMsg(Env.getCtx(), "Save"));
bSave.addActionListener(this);
bNew.setIcon(new ImageIcon(org.compiere.Adempiere.class.getResource("images/New24.gif")));
bNew.setMargin(new Insets(2, 2, 2, 2));
bNew.setToolTipText(Msg.getMsg(Env.getCtx(), "New"));
bNew.addActionListener(this);
bDelete.setIcon(new ImageIcon(org.compiere.Adempiere.class.getResource("images/Delete24.gif")));
bDelete.setMargin(new Insets(2, 2, 2, 2));
bDelete.setToolTipText(Msg.getMsg(Env.getCtx(), "Delete"));
bDelete.addActionListener(this);
//
southPanel.setLayout(southLayout);
valueLabel.setLabelFor(valueField);
valueLabel.setText(Msg.translate(Env.getCtx(), "Value"));
nameLabel.setLabelFor(nameField);
nameLabel.setText(Msg.translate(Env.getCtx(), "Name"));
descriptionLabel.setLabelFor(descriptionField);
descriptionLabel.setText(Msg.translate(Env.getCtx(), "Description"));
valueField.setText("%");
valueField.setColumns(FIELDLENGTH);
nameField.setText("%");
nameField.setColumns(FIELDLENGTH);
descriptionField.setText("%");
descriptionField.setColumns(FIELDLENGTH);
scontentPanel.setToolTipText(Msg.getMsg(Env.getCtx(), "FindTip"));
docNoLabel.setLabelFor(docNoField);
docNoLabel.setText(Msg.translate(Env.getCtx(), "DocumentNo"));
docNoField.setText("%");
docNoField.setColumns(FIELDLENGTH);
advancedScrollPane.setPreferredSize(new Dimension(540, 410));
southPanel.add(statusBar, BorderLayout.SOUTH);
this.getContentPane().add(southPanel, BorderLayout.SOUTH);
//
scontentPanel.setLayout(scontentLayout);
simplePanel.setLayout(simpleLayout);
simplePanel.add(confirmPanelS, BorderLayout.SOUTH);
simplePanel.add(scontentPanel, BorderLayout.CENTER);
scontentPanel.add(valueLabel, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 5, 0, 5), 0, 0));
scontentPanel.add(nameLabel, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 5, 0, 5), 0, 0));
scontentPanel.add(descriptionLabel, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 5, 5, 5), 0, 0));
scontentPanel.add(valueField, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 5), 0, 0));
scontentPanel.add(descriptionField, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
scontentPanel.add(docNoLabel, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 5, 0, 5), 0, 0));
scontentPanel.add(nameField, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 5), 0, 0));
scontentPanel.add(docNoField, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 5), 0, 0));
//
scontentPanel.add(spaceE, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0));
scontentPanel.add(spaceN, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0));
scontentPanel.add(spaceW, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0));
scontentPanel.add(spaceS, new GridBagConstraints(2, 15, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0));
//
// tabbedPane.add(simplePanel, Msg.getMsg(Env.getCtx(),"Find"));
tabbedPane.add(simplePanel, Msg.getMsg(Env.getCtx(), "Find"));
//
toolBar.add(bIgnore, null);
toolBar.addSeparator();
toolBar.add(bNew, null);
toolBar.add(bDelete, null);
toolBar.add(fQueryName, null);
toolBar.add(bSave, null);
advancedPanel.setLayout(advancedLayout);
advancedPanel.add(toolBar, BorderLayout.NORTH);
advancedPanel.add(confirmPanelA, BorderLayout.SOUTH);
advancedPanel.add(advancedScrollPane, BorderLayout.CENTER);
advancedScrollPane.getViewport().add(advancedTable, null);
// tabbedPane.add(advancedPanel, Msg.getMsg(Env.getCtx(),"Advanced"));
tabbedPane.add(advancedPanel, Msg.getMsg(Env.getCtx(), "Advanced"));
//
this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
//
confirmPanelA.addActionListener(this);
confirmPanelS.addActionListener(this);
//
JButton b = ConfirmPanel.createNewButton(true);
confirmPanelS.addComponent(b);
b.addActionListener(this);
// teo_sarca, [ 1670847 ] Find dialog: closing and canceling need same functionality
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
cmd_cancel();
}
});
}
use of java.awt.event.FocusListener in project jgnash by ccavanaugh.
the class JTextFieldEx method installFocusListener.
/*public JTextFieldEx(final String text, final int columns) {
super(text, columns);
installFocusListener();
}
public JTextFieldEx(final Document doc, final String text, final int columns) {
super(doc, text, columns);
installFocusListener();
}*/
private void installFocusListener() {
FocusListener focusListener = new FocusAdapter() {
@Override
public void focusGained(final FocusEvent e) {
EventQueue.invokeLater(() -> {
if (isEditable() && JTextFieldEx.select) {
selectAll();
}
});
}
};
addFocusListener(focusListener);
}
Aggregations