use of javax.swing.event.DocumentListener in project kotlin by JetBrains.
the class K2JSRunConfigurationEditor method setUpChooseGenerateFilePath.
private void setUpChooseGenerateFilePath() {
FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.getDirectoryChooserDescriptor("directory where generated files will be stored");
fileChooserDescriptor.setRoots(ProjectRootManager.getInstance(project).getContentRoots());
generatedChooseFile.addBrowseFolderListener(null, null, project, fileChooserDescriptor);
final JTextField textField = generatedChooseFile.getTextField();
textField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(@NotNull DocumentEvent e) {
onChange();
}
@Override
public void removeUpdate(@NotNull DocumentEvent e) {
onChange();
}
@Override
public void changedUpdate(@NotNull DocumentEvent e) {
onChange();
}
private void onChange() {
File file = new File(generatedChooseFile.getText());
if (!file.isDirectory()) {
textField.setForeground(JBColor.red);
} else {
textField.setForeground(JBColor.foreground());
}
}
});
}
use of javax.swing.event.DocumentListener in project joda-time by JodaOrg.
the class AgeCalculator method addTopArea.
private void addTopArea(Container container) {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.add(fixedHeight(new JLabel("Birthdate")));
panel.add(Box.createHorizontalStrut(10));
final JTextField birthdateField = new JTextField(iBirthdateStr + ' ');
Document doc = birthdateField.getDocument();
doc.addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
update(e);
}
public void removeUpdate(DocumentEvent e) {
update(e);
}
public void changedUpdate(DocumentEvent e) {
update(e);
}
private void update(DocumentEvent e) {
iBirthdateStr = birthdateField.getText();
updateResults();
}
});
panel.add(fixedHeight(birthdateField));
panel.add(Box.createHorizontalStrut(10));
Object[] ids = DateTimeZone.getAvailableIDs().toArray();
final JComboBox zoneSelector = new JComboBox(ids);
zoneSelector.setSelectedItem(DateTimeZone.getDefault().getID());
panel.add(fixedSize(zoneSelector));
zoneSelector.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String id = (String) zoneSelector.getSelectedItem();
iChronology = ISOChronology.getInstance(DateTimeZone.forID(id));
updateResults();
}
});
container.add(fixedHeight(panel));
}
use of javax.swing.event.DocumentListener in project android by JetBrains.
the class SelectionEditors method createDocumentListener.
/**
* Create a document listener that will update the {@link MockupViewPanel} selection
* when the attached document is updated.
*
* @return the new document listener
*/
private DocumentListener createDocumentListener() {
return new DocumentListener() {
private void processChange(@NotNull DocumentEvent e) {
if (myBoundsUpdating) {
return;
}
try {
Document document = e.getDocument();
int value;
if (document.getLength() <= 0) {
value = 0;
} else {
value = Integer.parseInt(document.getText(0, document.getLength()));
}
SelectionLayer selectionLayer = myMockupViewPanel.getSelectionLayer();
Rectangle selection = selectionLayer.getSelection();
if (document == myBoundsDocuments[W]) {
selectionLayer.setSelection(selection.x, selection.y, value, selection.height);
} else if (document == myBoundsDocuments[H]) {
selectionLayer.setSelection(selection.x, selection.y, selection.width, value);
} else if (document == myBoundsDocuments[X]) {
selectionLayer.setSelection(value, selection.y, selection.width, selection.height);
} else if (document == myBoundsDocuments[Y]) {
selectionLayer.setSelection(selection.x, value, selection.width, selection.height);
}
} catch (BadLocationException | NumberFormatException ex) {
// Do nothing
}
}
@Override
public void insertUpdate(DocumentEvent e) {
processChange(e);
}
@Override
public void removeUpdate(DocumentEvent e) {
processChange(e);
}
@Override
public void changedUpdate(DocumentEvent e) {
}
};
}
use of javax.swing.event.DocumentListener in project intellij-plugins by JetBrains.
the class SwingUtils method addTextChangeListener.
public static void addTextChangeListener(final JTextComponent textComponent, final TextChangeListener textChangeListener) {
final String[] oldTextContainer = { textComponent.getText() };
textChangeListener.textChanged("", textComponent.getText());
textComponent.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
textChanged();
}
@Override
public void removeUpdate(DocumentEvent e) {
textChanged();
}
@Override
public void changedUpdate(DocumentEvent e) {
textChanged();
}
public void textChanged() {
String oldText = ObjectUtils.notNull(oldTextContainer[0], "");
String newText = ObjectUtils.notNull(textComponent.getText(), "");
if (!oldText.equals(newText)) {
textChangeListener.textChanged(oldText, newText);
oldTextContainer[0] = newText;
}
}
});
}
use of javax.swing.event.DocumentListener in project JMRI by JMRI.
the class SystemConsole method createFrame.
/**
* Layout the console frame
*/
private void createFrame() {
// Use a JmriJFrame to ensure that we fit on the screen
frame = new JmriJFrame(Bundle.getMessage("TitleConsole"));
pref = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
// Add Help menu (Windows menu automaitically added)
// NOI18N
frame.addHelpMenu("package.apps.SystemConsole", true);
// Grab a reference to the system clipboard
final Clipboard clipboard = frame.getToolkit().getSystemClipboard();
// Setup the scroll pane
JScrollPane scroll = new JScrollPane(console);
frame.add(scroll, BorderLayout.CENTER);
// Add button to allow copy to clipboard
JPanel p = new JPanel();
JButton copy = new JButton(Bundle.getMessage("ButtonCopyClip"));
copy.addActionListener((ActionEvent event) -> {
StringSelection text = new StringSelection(console.getText());
clipboard.setContents(text, text);
});
p.add(copy);
// Add button to allow console window to be closed
JButton close = new JButton(Bundle.getMessage("ButtonClose"));
close.addActionListener((ActionEvent event) -> {
frame.setVisible(false);
frame.dispose();
});
p.add(close);
JButton stackTrace = new JButton(Bundle.getMessage("ButtonStackTrace"));
stackTrace.addActionListener((ActionEvent event) -> {
performStackTrace();
});
p.add(stackTrace);
// Add checkbox to enable/disable auto-scrolling
// Use the inverted SimplePreferenceState to default as enabled
p.add(autoScroll = new JCheckBox(Bundle.getMessage("CheckBoxAutoScroll"), !pref.getSimplePreferenceState(alwaysScrollCheck)));
autoScroll.addActionListener((ActionEvent event) -> {
doAutoScroll(console, autoScroll.isSelected());
pref.setSimplePreferenceState(alwaysScrollCheck, !autoScroll.isSelected());
});
// Add checkbox to enable/disable always on top
p.add(alwaysOnTop = new JCheckBox(Bundle.getMessage("CheckBoxOnTop"), pref.getSimplePreferenceState(alwaysOnTopCheck)));
alwaysOnTop.setVisible(true);
alwaysOnTop.setToolTipText(Bundle.getMessage("ToolTipOnTop"));
alwaysOnTop.addActionListener((ActionEvent event) -> {
frame.setAlwaysOnTop(alwaysOnTop.isSelected());
pref.setSimplePreferenceState(alwaysOnTopCheck, alwaysOnTop.isSelected());
});
frame.setAlwaysOnTop(alwaysOnTop.isSelected());
// Define the pop-up menu
copySelection = new JMenuItem(Bundle.getMessage("MenuItemCopy"));
copySelection.addActionListener((ActionEvent event) -> {
StringSelection text = new StringSelection(console.getSelectedText());
clipboard.setContents(text, text);
});
popup.add(copySelection);
JMenuItem menuItem = new JMenuItem(Bundle.getMessage("ButtonCopyClip"));
menuItem.addActionListener((ActionEvent event) -> {
StringSelection text = new StringSelection(console.getText());
clipboard.setContents(text, text);
});
popup.add(menuItem);
popup.add(new JSeparator());
JRadioButtonMenuItem rbMenuItem;
// Define the colour scheme sub-menu
schemeMenu = new JMenu(rbc.getString("ConsoleSchemeMenu"));
schemeGroup = new ButtonGroup();
for (final Scheme s : schemes) {
rbMenuItem = new JRadioButtonMenuItem(s.description);
rbMenuItem.addActionListener((ActionEvent event) -> {
setScheme(schemes.indexOf(s));
});
rbMenuItem.setSelected(getScheme() == schemes.indexOf(s));
schemeMenu.add(rbMenuItem);
schemeGroup.add(rbMenuItem);
}
popup.add(schemeMenu);
// Define the wrap style sub-menu
wrapMenu = new JMenu(rbc.getString("ConsoleWrapStyleMenu"));
wrapGroup = new ButtonGroup();
rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleNone"));
rbMenuItem.addActionListener((ActionEvent event) -> {
setWrapStyle(WRAP_STYLE_NONE);
});
rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_NONE);
wrapMenu.add(rbMenuItem);
wrapGroup.add(rbMenuItem);
rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleLine"));
rbMenuItem.addActionListener((ActionEvent event) -> {
setWrapStyle(WRAP_STYLE_LINE);
});
rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_LINE);
wrapMenu.add(rbMenuItem);
wrapGroup.add(rbMenuItem);
rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleWord"));
rbMenuItem.addActionListener((ActionEvent event) -> {
setWrapStyle(WRAP_STYLE_WORD);
});
rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_WORD);
wrapMenu.add(rbMenuItem);
wrapGroup.add(rbMenuItem);
popup.add(wrapMenu);
// Bind pop-up to objects
MouseListener popupListener = new PopupListener();
console.addMouseListener(popupListener);
frame.addMouseListener(popupListener);
// Add document listener to scroll to end when modified if required
console.getDocument().addDocumentListener(new DocumentListener() {
// References to the JTextArea and JCheckBox
// of this instantiation
JTextArea ta = console;
JCheckBox chk = autoScroll;
@Override
public void insertUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
@Override
public void removeUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
@Override
public void changedUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
});
// Add the button panel to the frame & then arrange everything
frame.add(p, BorderLayout.SOUTH);
frame.pack();
}
Aggregations