use of java.awt.event.FocusListener in project vcell by virtualcell.
the class DisabledTreeCellEditor method getTreeCellEditorComponent.
@Override
public Component getTreeCellEditorComponent(final JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
Component container = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
// Note: System.out.println("Components Type: "+containeractually.getClass().getName());
// was used to show it was container, javax.swing.tree.DefaultTreeCellEditor$EditorContainer
// getTreeCellEditorComponent(parameters) is called as soon as editing begins
// also at this time editingComponent != null (aka initialized)
// so it's a good place to add in a Focus Listener
editingComponent.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
tree.stopEditing();
}
});
// (I think the return statement means it's about to be used)
return container;
}
use of java.awt.event.FocusListener in project omegat by omegat-org.
the class StaticUIUtils method makeCaretAlwaysVisible.
/**
* Make caret visible even when the {@link JTextComponent} is not editable.
*/
public static FocusListener makeCaretAlwaysVisible(final JTextComponent comp) {
FocusListener listener = new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
Caret caret = comp.getCaret();
caret.setVisible(true);
caret.setSelectionVisible(true);
}
};
comp.addFocusListener(listener);
return listener;
}
use of java.awt.event.FocusListener in project sldeditor by robward-scisys.
the class FieldConfigGeometry method createUI.
/**
* Creates the ui.
*/
/*
* (non-Javadoc)
*
* @see com.sldeditor.ui.detail.config.FieldConfigBase#createUI()
*/
@Override
public void createUI() {
if (textField == null) {
int xPos = getXPos();
FieldPanel fieldPanel = createFieldPanel(xPos, getLabel());
textField = new JTextField();
textField.setBounds(xPos + BasePanel.WIDGET_X_START, 0, this.isValueOnly() ? BasePanel.WIDGET_EXTENDED_WIDTH : BasePanel.WIDGET_STANDARD_WIDTH, BasePanel.WIDGET_HEIGHT);
fieldPanel.add(textField);
textField.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
originalValue = textField.getText();
}
@Override
public void focusLost(FocusEvent e) {
valueStored(textField.getText());
}
});
if (buttonText != null) {
final JButton buttonExternal = new JButton(buttonText);
buttonExternal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
externalButtonPressed(buttonExternal);
}
});
int buttonWidth = 26;
int padding = 3;
buttonExternal.setBounds(xPos + textField.getX() - buttonWidth - padding, 0, buttonWidth, BasePanel.WIDGET_HEIGHT);
fieldPanel.add(buttonExternal);
}
if (!isValueOnly()) {
setAttributeSelectionPanel(fieldPanel.internalCreateAttrButton(Geometry.class, this, isRasterSymbol()));
}
}
}
use of java.awt.event.FocusListener in project OsmAnd-tools by osmandapp.
the class OsmExtractionUI method updateStatusField.
private void updateStatusField(final JTextField statusField) {
popup = new JScrollPopupMenu();
popup.setMaximumVisibleRows(25);
popup.setFocusable(false);
searchUICore.setOnResultsComplete(new Runnable() {
@Override
public void run() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
updateSearchResult(statusField, searchUICore.getCurrentSearchResult(), true);
}
});
}
});
statusField.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
// if(e.getOppositeComponent() != popup) {
// popup.setVisible(false);
// }
}
@Override
public void focusGained(FocusEvent e) {
popup.setFocusable(false);
SearchSettings settings = searchUICore.getPhrase().getSettings().setOriginalLocation(new LatLon(mapPanel.getLatitude(), mapPanel.getLongitude()));
settings = settings.setLang(DataExtractionSettings.getSettings().getSearchLocale(), false);
searchUICore.updateSettings(settings);
}
});
statusField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
super.keyPressed(e);
mapPanel.setStatusField(null);
if (e.getKeyCode() == KeyEvent.VK_DOWN && popup.getComponentCount() > 0) {
popup.setVisible(false);
popup.setFocusable(true);
Point p = statusField.getLocation();
popup.show(e.getComponent(), p.x, p.y - 4);
// popup.show();
popup.requestFocus();
return;
}
}
@Override
public void keyTyped(KeyEvent e) {
mapPanel.setStatusField(null);
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
return;
}
String text = statusField.getText();
int ps = statusField.getCaretPosition();
if (e.getKeyChar() == '\b') {
// nothing
} else if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
if (ps >= text.length()) {
text += e.getKeyChar();
} else {
text = text.substring(0, ps) + e.getKeyChar() + text.substring(ps);
}
}
SearchSettings settings = searchUICore.getPhrase().getSettings();
if (settings.getRadiusLevel() != 1) {
searchUICore.updateSettings(settings.setRadiusLevel(1));
}
SearchResultCollection c = null;
if (!text.contains("#map")) {
searchUICore.search(text, true, null);
}
// if(c != null) {
// updateSearchResult(statusField, c, false);
// }
}
});
statusField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
mapPanel.setStatusField(statusField);
String txt = statusField.getText();
int i = txt.indexOf("#map=");
if (i != -1) {
String[] vs = txt.substring(i + "#map=".length()).split("/");
mapPanel.setLatLon(Float.parseFloat(vs[1]), Float.parseFloat(vs[2]));
mapPanel.setZoom(Integer.parseInt(vs[0]));
}
mapPanel.refresh();
}
});
}
use of java.awt.event.FocusListener in project ACS by ACS-Community.
the class ScriptFilter method getGroupTextField.
/**
* This method initializes groupTextField
* @return javax.swing.JTextField
*/
private JTextField getGroupTextField() {
if (groupTextField == null) {
Dimension d = new Dimension(150, 19);
groupTextField = new JTextField();
groupTextField.setPreferredSize(d);
//groupTextField.setSize(d);
groupTextField.setMinimumSize(d);
groupTextField.setToolTipText("Sampling Group where to add the new Sample. Only alphanumeric and underscore characters.");
groupTextField.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
groupTextField.setHorizontalAlignment(JTextField.LEFT);
groupTextField.setText("SampGroup");
groupTextField.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
// Do nothing special :)
}
public void focusLost(FocusEvent e) {
if (!groupTextField.getText().matches("^([a-z]|[A-Z]|[0-9]|_)+$")) {
JOptionPane.showConfirmDialog(SamplingSystemGUI.this, "Group name '" + groupTextField.getText() + "' is invalid.\nPlease use only alphanumeric characters and/or underscores.", "Invalid group name", JOptionPane.PLAIN_MESSAGE, JOptionPane.WARNING_MESSAGE);
groupTextField.setText("");
groupTextField.grabFocus();
}
}
});
}
return groupTextField;
}
Aggregations