use of java.awt.event.FocusEvent 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.FocusEvent in project JMRI by JMRI.
the class AddSignalMastPanel method dccUnLitPanel.
void dccUnLitPanel() {
dccUnLitPanel.setLayout(new BoxLayout(dccUnLitPanel, BoxLayout.Y_AXIS));
JPanel dccDetails = new JPanel();
dccDetails.add(new JLabel(Bundle.getMessage("DCCMastSetAspectId") + ":"));
dccDetails.add(unLitAspectField);
unLitAspectField.setText("31");
dccUnLitPanel.add(dccDetails);
TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black));
border.setTitle(Bundle.getMessage("DCCUnlitAspectNumber"));
dccUnLitPanel.setBorder(border);
unLitAspectField.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
if (unLitAspectField.getText().equals("")) {
return;
}
if (!validateAspectId(unLitAspectField.getText())) {
unLitAspectField.requestFocusInWindow();
}
}
@Override
public void focusGained(FocusEvent e) {
}
});
}
use of java.awt.event.FocusEvent in project JMRI by JMRI.
the class AbstractStreamConnectionConfig method checkInitDone.
@SuppressWarnings("unchecked")
@Override
protected void checkInitDone() {
if (log.isDebugEnabled()) {
log.debug("init called for " + name());
}
if (init) {
return;
}
if (adapter.getSystemConnectionMemo() != null) {
systemPrefixField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!adapter.getSystemConnectionMemo().setSystemPrefix(systemPrefixField.getText())) {
JOptionPane.showMessageDialog(null, "System Prefix " + systemPrefixField.getText() + " is already assigned");
systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
}
}
});
systemPrefixField.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
if (!adapter.getSystemConnectionMemo().setSystemPrefix(systemPrefixField.getText())) {
JOptionPane.showMessageDialog(null, "System Prefix " + systemPrefixField.getText() + " is already assigned");
systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
}
}
@Override
public void focusGained(FocusEvent e) {
}
});
connectionNameField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!adapter.getSystemConnectionMemo().setUserName(connectionNameField.getText())) {
JOptionPane.showMessageDialog(null, "Connection Name " + connectionNameField.getText() + " is already assigned");
connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
}
}
});
connectionNameField.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
if (!adapter.getSystemConnectionMemo().setUserName(connectionNameField.getText())) {
JOptionPane.showMessageDialog(null, "Connection Name " + connectionNameField.getText() + " is already assigned");
connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
}
}
@Override
public void focusGained(FocusEvent e) {
}
});
for (String i : options.keySet()) {
final String item = i;
if (options.get(i).getComponent() instanceof JComboBox) {
((JComboBox<?>) options.get(i).getComponent()).addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adapter.setOptionState(item, options.get(item).getItem());
}
});
}
}
}
init = true;
}
use of java.awt.event.FocusEvent in project JMRI by JMRI.
the class AddSignalMastPanel method updateDCCMastPanel.
void updateDCCMastPanel() {
if ((!Bundle.getMessage("DCCMast").equals(signalMastDriver.getSelectedItem())) && (!Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem()))) {
return;
}
dccAspect = new HashMap<String, DCCAspectPanel>(10);
java.util.List<jmri.CommandStation> connList = jmri.InstanceManager.getList(jmri.CommandStation.class);
systemPrefixBox.removeAllItems();
if (!connList.isEmpty()) {
for (int x = 0; x < connList.size(); x++) {
jmri.CommandStation station = connList.get(x);
if (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem())) {
if (station instanceof jmri.jmrix.loconet.SlotManager) {
systemPrefixBox.addItem(station.getUserName());
}
} else {
systemPrefixBox.addItem(station.getUserName());
}
}
} else {
systemPrefixBox.addItem("None");
}
String mastType = mastNames.get(mastBox.getSelectedIndex()).getName();
mastType = mastType.substring(11, mastType.indexOf(".xml"));
jmri.implementation.DefaultSignalAppearanceMap sigMap = jmri.implementation.DefaultSignalAppearanceMap.getMap(sigsysname, mastType);
java.util.Enumeration<String> aspects = sigMap.getAspects();
SignalSystem sigsys = InstanceManager.getDefault(jmri.SignalSystemManager.class).getSystem(sigsysname);
while (aspects.hasMoreElements()) {
String aspect = aspects.nextElement();
DCCAspectPanel aPanel = new DCCAspectPanel(aspect);
dccAspect.put(aspect, aPanel);
aPanel.setAspectId((String) sigsys.getProperty(aspect, "dccAspect"));
}
dccMastPanel.removeAll();
dccMastPanel.setLayout(new jmri.util.javaworld.GridLayout2(dccAspect.size() + 3, 2));
dccMastPanel.add(systemPrefixBoxLabel);
dccMastPanel.add(systemPrefixBox);
dccMastPanel.add(dccAspectAddressLabel);
dccMastPanel.add(dccAspectAddressField);
if (dccAddressListener == null) {
dccAddressListener = new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
if (dccAspectAddressField.getText().equals("")) {
return;
}
validateDCCAddress();
}
@Override
public void focusGained(FocusEvent e) {
}
};
dccAspectAddressField.addFocusListener(dccAddressListener);
}
if (mast == null) {
systemPrefixBoxLabel.setEnabled(true);
systemPrefixBox.setEnabled(true);
dccAspectAddressLabel.setEnabled(true);
dccAspectAddressField.setEnabled(true);
}
for (String aspect : dccAspect.keySet()) {
// load aspect panels from hashmap
dccMastPanel.add(dccAspect.get(aspect).getPanel());
}
if ((dccAspect.size() & 1) == 1) {
// spacer
dccMastPanel.add(new JLabel());
}
dccMastPanel.add(new JLabel(Bundle.getMessage("DCCMastCopyAspectId") + ":"));
dccMastPanel.add(copyFromMastSelection());
}
use of java.awt.event.FocusEvent in project JMRI by JMRI.
the class JsonNetworkConnectionConfig method checkInitDone.
@Override
protected void checkInitDone() {
super.checkInitDone();
//options.put(Bundle.getMessage("DiscoveredServices"), new Option(Bundle.getMessage("DiscoveredServices"), services, false));
if (this.adapter.getSystemConnectionMemo() != null) {
final JsonClientSystemConnectionMemo memo = (JsonClientSystemConnectionMemo) this.adapter.getSystemConnectionMemo();
this.transmitPrefixField.setText(memo.getTransmitPrefix());
this.transmitPrefixField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
memo.setTransmitPrefix(transmitPrefixField.getText());
transmitPrefixField.setText(memo.getTransmitPrefix());
}
});
this.transmitPrefixField.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
memo.setTransmitPrefix(transmitPrefixField.getText());
transmitPrefixField.setText(memo.getTransmitPrefix());
}
@Override
public void focusGained(FocusEvent e) {
// nothing to do
}
});
this.nodeIdentityField.setText(memo.getNodeIdentity());
this.nodeIdentityField.setToolTipText(Bundle.getMessage("NodeIdentityToolTip"));
}
}
Aggregations