use of javax.swing.event.DocumentEvent in project jabref by JabRef.
the class JTextFieldChangeListenerUtil method addChangeListener.
/**
* Installs a listener to receive notification when the text of any
* {@code JTextComponent} is changed. Internally, it installs a
* {@link DocumentListener} on the text component's {@link Document},
* and a {@link PropertyChangeListener} on the text component to detect
* if the {@code Document} itself is replaced.
*
* Taken from
*
* @param text any text component, such as a {@link JTextField}
* or {@link JTextArea}
* @param changeListener a listener to receive {@link ChangeEvent}s
* when the text is changed; the source object for the events
* will be the text component
* @throws NullPointerException if either parameter is null
*/
public static void addChangeListener(JTextComponent text, ChangeListener changeListener) {
Objects.requireNonNull(text);
Objects.requireNonNull(changeListener);
DocumentListener dl = new DocumentListener() {
private int lastChange;
private int lastNotifiedChange;
@Override
public void insertUpdate(DocumentEvent e) {
changedUpdate(e);
}
@Override
public void removeUpdate(DocumentEvent e) {
changedUpdate(e);
}
@Override
public void changedUpdate(DocumentEvent e) {
lastChange++;
SwingUtilities.invokeLater(() -> {
if (lastNotifiedChange != lastChange) {
lastNotifiedChange = lastChange;
changeListener.stateChanged(new ChangeEvent(text));
}
});
}
};
text.addPropertyChangeListener("document", (PropertyChangeEvent e) -> {
Document d1 = (Document) e.getOldValue();
Document d2 = (Document) e.getNewValue();
if (d1 != null) {
d1.removeDocumentListener(dl);
}
if (d2 != null) {
d2.addDocumentListener(dl);
}
dl.changedUpdate(null);
});
Document d = text.getDocument();
if (d != null) {
d.addDocumentListener(dl);
}
}
use of javax.swing.event.DocumentEvent in project jabref by JabRef.
the class ExternalFileTypeEntryEditor method init.
private void init(ExternalFileType inEntry) {
entry = inEntry;
icon.setText(null);
ButtonGroup bg = new ButtonGroup();
bg.add(useDefault);
bg.add(other);
FormBuilder builder = FormBuilder.create();
builder.layout(new FormLayout("left:pref, 4dlu, fill:150dlu, 4dlu, fill:pref", "p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p"));
builder.add(Localization.lang("Icon")).xy(1, 1);
builder.add(icon).xy(3, 1);
builder.add(Localization.lang("Name")).xy(1, 3);
builder.add(name).xy(3, 3);
builder.add(Localization.lang("Extension")).xy(1, 5);
builder.add(extension).xy(3, 5);
builder.add(Localization.lang("MIME type")).xy(1, 7);
builder.add(mimeType).xy(3, 7);
builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
builder.add(Localization.lang("Application")).xy(1, 9);
JButton browseBut = new JButton(Localization.lang("Browse"));
if (OS.WINDOWS) {
builder.add(useDefault).xy(3, 9);
builder.appendRows("2dlu, p");
JPanel p1 = new JPanel();
builder.add(p1).xy(1, 11);
JPanel p2 = new JPanel();
application.setPreferredSize(new Dimension(300, application.getPreferredSize().height));
BorderLayout bl = new BorderLayout();
bl.setHgap(4);
p2.setLayout(bl);
p2.add(other, BorderLayout.WEST);
p2.add(application, BorderLayout.CENTER);
builder.add(p2).xy(3, 11);
builder.add(browseBut).xy(5, 11);
} else {
builder.add(application).xy(3, 9);
builder.add(browseBut).xy(5, 9);
}
ButtonBarBuilder bb = new ButtonBarBuilder();
bb.addGlue();
bb.addButton(ok);
bb.addButton(cancel);
bb.addGlue();
ok.addActionListener(e -> {
okPressed = true;
storeSettings(ExternalFileTypeEntryEditor.this.entry);
diag.dispose();
});
cancel.addActionListener(e -> diag.dispose());
if (OS.WINDOWS) {
application.getDocument().addDocumentListener(new DocumentListener() {
private void handle() {
if (application.getText().isEmpty()) {
useDefault.setSelected(true);
} else {
other.setSelected(true);
}
}
@Override
public void insertUpdate(DocumentEvent documentEvent) {
handle();
}
@Override
public void removeUpdate(DocumentEvent documentEvent) {
handle();
}
@Override
public void changedUpdate(DocumentEvent documentEvent) {
handle();
}
});
}
String title = editFileTitle;
if (entry.getName().isEmpty()) {
title = newFileTitle;
}
if (dParent == null) {
diag = new JDialog(fParent, title, true);
} else {
diag = new JDialog(dParent, title, true);
}
diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
diag.pack();
browseBut.addActionListener(browsePressed);
if (dParent == null) {
diag.setLocationRelativeTo(fParent);
} else {
diag.setLocationRelativeTo(dParent);
}
setValues(entry);
}
use of javax.swing.event.DocumentEvent in project intellij-plugins by JetBrains.
the class DartGeneratorPeer method addSettingsStateListener.
@Override
public void addSettingsStateListener(@NotNull final WebProjectGenerator.SettingsStateListener stateListener) {
// invalid Dartium path is not a blocking error
final JTextComponent editorComponent = (JTextComponent) mySdkPathComboWithBrowse.getComboBox().getEditor().getEditorComponent();
editorComponent.getDocument().addDocumentListener(new DocumentAdapter() {
protected void textChanged(final DocumentEvent e) {
stateListener.stateChanged(validate() == null);
}
});
myCreateSampleProjectCheckBox.addActionListener(e -> stateListener.stateChanged(validate() == null));
myTemplatesList.addListSelectionListener(e -> stateListener.stateChanged(validate() == null));
}
use of javax.swing.event.DocumentEvent in project intellij-plugins by JetBrains.
the class RegistrationForm method setupFormActionsAndLF.
private void setupFormActionsAndLF() {
myUseExisting.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
boolean useExisting = myUseExisting.isSelected();
JComponent[] hideableFields = new JComponent[] { myNickname, myNicknameLabel, myFirstName, myFirstNameLabel, myLastName, myLastNameLabel, myPasswordAgain, myPasswordAgainLabel };
for (JComponent hideableField : hideableFields) {
hideableField.setVisible(!useExisting);
}
Window window = SwingUtilities.getWindowAncestor(myPanel);
if (window != null) {
window.pack();
}
}
});
UIUtil.traverse(myPanel, new UIUtil.TraverseAction() {
public boolean executeAndContinue(Component c) {
if (c instanceof JTextComponent) {
JTextComponent textComponent = (JTextComponent) c;
textComponent.getDocument().addDocumentListener(new DocumentAdapter() {
protected void textChanged(DocumentEvent e) {
myErrorLabel.setText(null);
}
});
}
return true;
}
});
}
use of javax.swing.event.DocumentEvent in project JMRI by JMRI.
the class AbstractMonFrame method initComponents.
@Override
public void initComponents() throws Exception {
p = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
// the following code sets the frame's initial state
// NOI18N
clearButton.setText(Bundle.getMessage("ButtonClearScreen"));
clearButton.setVisible(true);
// NOI18N
clearButton.setToolTipText(Bundle.getMessage("TooltipClearMonHistory"));
// NOI18N
freezeButton.setText(Bundle.getMessage("ButtonFreezeScreen"));
freezeButton.setVisible(true);
// NOI18N
freezeButton.setToolTipText(Bundle.getMessage("TooltipStopScroll"));
// NOI18N
enterButton.setText(Bundle.getMessage("ButtonAddMessage"));
enterButton.setVisible(true);
// NOI18N
enterButton.setToolTipText(Bundle.getMessage("TooltipAddMessage"));
monTextPane.setVisible(true);
// NOI18N
monTextPane.setToolTipText(Bundle.getMessage("TooltipMonTextPane"));
monTextPane.setEditable(false);
// Add document listener to scroll to end when modified if required
monTextPane.getDocument().addDocumentListener(new DocumentListener() {
// References to the JTextArea and JCheckBox
// of this instantiation
JTextArea ta = monTextPane;
JCheckBox chk = autoScrollCheckBox;
@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());
}
});
// NOI18N
entryField.setToolTipText(Bundle.getMessage("TooltipEntryPane"));
// fix a width for current character set
JTextField t = new JTextField(80);
int x = jScrollPane1.getPreferredSize().width + t.getPreferredSize().width;
int y = jScrollPane1.getPreferredSize().height + 10 * t.getPreferredSize().height;
jScrollPane1.getViewport().add(monTextPane);
jScrollPane1.setPreferredSize(new Dimension(x, y));
jScrollPane1.setVisible(true);
// NOI18N
startLogButton.setText(Bundle.getMessage("ButtonStartLogging"));
startLogButton.setVisible(true);
// NOI18N
startLogButton.setToolTipText(Bundle.getMessage("TooltipStartLogging"));
// NOI18N
stopLogButton.setText(Bundle.getMessage("ButtonStopLogging"));
stopLogButton.setVisible(true);
// NOI18N
stopLogButton.setToolTipText(Bundle.getMessage("TooltipStopLogging"));
// NOI18N
rawCheckBox.setText(Bundle.getMessage("ButtonShowRaw"));
rawCheckBox.setVisible(true);
// NOI18N
rawCheckBox.setToolTipText(Bundle.getMessage("TooltipShowRaw"));
rawCheckBox.setSelected(p.getSimplePreferenceState(rawDataCheck));
// NOI18N
timeCheckBox.setText(Bundle.getMessage("ButtonShowTimestamps"));
timeCheckBox.setVisible(true);
// NOI18N
timeCheckBox.setToolTipText(Bundle.getMessage("TooltipShowTimestamps"));
timeCheckBox.setSelected(p.getSimplePreferenceState(timeStampCheck));
// NOI18N
alwaysOnTopCheckBox.setText(Bundle.getMessage("ButtonWindowOnTop"));
alwaysOnTopCheckBox.setVisible(true);
// NOI18N
alwaysOnTopCheckBox.setToolTipText(Bundle.getMessage("TooltipWindowOnTop"));
alwaysOnTopCheckBox.setSelected(p.getSimplePreferenceState(alwaysOnTopCheck));
setAlwaysOnTop(alwaysOnTopCheckBox.isSelected());
// NOI18N
autoScrollCheckBox.setText(Bundle.getMessage("ButtonAutoScroll"));
autoScrollCheckBox.setVisible(true);
// NOI18N
autoScrollCheckBox.setToolTipText(Bundle.getMessage("TooltipAutoScroll"));
autoScrollCheckBox.setSelected(!p.getSimplePreferenceState(autoScrollCheck));
// NOI18N
openFileChooserButton.setText(Bundle.getMessage("ButtonChooseLogFile"));
openFileChooserButton.setVisible(true);
// NOI18N
openFileChooserButton.setToolTipText(Bundle.getMessage("TooltipChooseLogFile"));
setTitle(title());
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
// add items to GUI
getContentPane().add(jScrollPane1);
JPanel paneA = new JPanel();
paneA.setLayout(new BoxLayout(paneA, BoxLayout.Y_AXIS));
JPanel pane1 = new JPanel();
pane1.setLayout(new BoxLayout(pane1, BoxLayout.X_AXIS));
pane1.add(clearButton);
pane1.add(freezeButton);
pane1.add(rawCheckBox);
pane1.add(timeCheckBox);
pane1.add(alwaysOnTopCheckBox);
paneA.add(pane1);
JPanel pane2 = new JPanel();
pane2.setLayout(new BoxLayout(pane2, BoxLayout.X_AXIS));
pane2.add(openFileChooserButton);
pane2.add(startLogButton);
pane2.add(stopLogButton);
paneA.add(pane2);
JPanel pane3 = new JPanel();
pane3.setLayout(new BoxLayout(pane3, BoxLayout.X_AXIS));
pane3.add(enterButton);
pane3.add(entryField);
paneA.add(pane3);
getContentPane().add(paneA);
// connect actions to buttons
clearButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
clearButtonActionPerformed(e);
}
});
startLogButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
startLogButtonActionPerformed(e);
}
});
stopLogButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stopLogButtonActionPerformed(e);
}
});
openFileChooserButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
openFileChooserButtonActionPerformed(e);
}
});
enterButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
enterButtonActionPerformed(e);
}
});
alwaysOnTopCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setAlwaysOnTop(alwaysOnTopCheckBox.isSelected());
}
});
autoScrollCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doAutoScroll(monTextPane, autoScrollCheckBox.isSelected());
}
});
// set file chooser to a default
// NOI18N
logFileChooser.setSelectedFile(new File("monitorLog.txt"));
// connect to data source
init();
// add help menu to window
addHelpMenu();
// prevent button areas from expanding
pack();
paneA.setMaximumSize(paneA.getSize());
pack();
}
Aggregations