use of javax.swing.event.DocumentListener in project yyl_example by Relucent.
the class Command method registerListener.
private void registerListener() {
txtDebug.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == 8 && execOffset >= doc.getLength()) {
e.setKeyCode(27);
}
if (e.getKeyCode() == 10 && execOffset < doc.getLength()) {
try {
String str = doc.getText(execOffset, doc.getLength() - execOffset);
exec(str + "\n");
} catch (BadLocationException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public void keyTyped(KeyEvent e) {
// System.out.println(e.getKeyChar());
}
});
doc.addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
}
public void insertUpdate(DocumentEvent e) {
}
public void removeUpdate(DocumentEvent e) {
}
});
txtDebug.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
if (execOffset > caret.getMark() || execOffset > caret.getDot()) {
caret.setDot(execOffset);
}
}
});
}
use of javax.swing.event.DocumentListener in project ACS by ACS-Community.
the class ScriptFilter method getFilterComponentTextField.
/**
* This method initializes filterComponentTextField
* @return javax.swing.JTextField
*/
private JTextField getFilterComponentTextField() {
if (filterComponentTextField == null) {
Dimension d = new Dimension(100, 19);
filterComponentTextField = new JTextField();
filterComponentTextField.setPreferredSize(d);
filterComponentTextField.setToolTipText("Write a word to find a particular component.");
//filterComponentTextField.setSize(d);
filterComponentTextField.setMinimumSize(d);
filterComponentTextField.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
filterComponentTextField.setHorizontalAlignment(JTextField.LEFT);
filterComponentTextField.getDocument().addDocumentListener(new DocumentListener() {
public void applyFilter() {
int total = compList.length;
String text = filterComponentTextField.getText();
if (!filterComponentTextField.getText().isEmpty()) {
ComponentComboBox.removeAllItems();
for (int i = 0; i < total; i++) {
if (compList[i].contains(text)) {
ComponentComboBox.addItem(compList[i]);
}
}
ComponentComboBox.hidePopup();
ComponentComboBox.showPopup();
} else {
ComponentComboBox.hidePopup();
ComponentComboBox.removeAllItems();
for (int j = 0; j < total; j++) {
ComponentComboBox.addItem(compList[j]);
}
}
if (ComponentComboBox.getItemCount() == 0) {
PropertyComboBox.removeAllItems();
}
}
public void changedUpdate(DocumentEvent e) {
}
public void insertUpdate(DocumentEvent e) {
applyFilter();
}
public void removeUpdate(DocumentEvent e) {
applyFilter();
}
});
}
return filterComponentTextField;
}
use of javax.swing.event.DocumentListener in project ACS by ACS-Community.
the class ScriptFilter method getFilterPropertyTextField.
/**
* This method initializes filterPropertyTextField
* @return javax.swing.JTextField
*/
private JTextField getFilterPropertyTextField() {
if (filterPropertyTextField == null) {
Dimension d = new Dimension(100, 19);
filterPropertyTextField = new JTextField();
filterPropertyTextField.setPreferredSize(d);
filterPropertyTextField.setToolTipText("Write a word to find a particular property.");
//filterPropertyTextField.setSize(d);
filterPropertyTextField.setMinimumSize(d);
filterPropertyTextField.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
filterPropertyTextField.setHorizontalAlignment(JTextField.LEFT);
filterPropertyTextField.getDocument().addDocumentListener(new DocumentListener() {
public void applyFilter() {
String item = (String) ComponentComboBox.getSelectedItem();
int i = -1;
for (int j = 0; j < compList.length; j++) {
if (compList[j].compareTo(item) == 0) {
i = j;
break;
}
}
if (i == -1) {
PropertyComboBox.removeAll();
return;
}
int total = propList.get(i).size();
String text = filterPropertyTextField.getText();
PropertyComboBox.removeAllItems();
for (int j = 0; j < total; j++) {
PropertyComboBox.addItem(propList.get(i).get(j).toString());
}
PropertyComboBox.showPopup();
if (!filterPropertyTextField.getText().isEmpty()) {
PropertyComboBox.removeAllItems();
for (int j = 0; j < total; j++) {
if (propList.get(i).get(j).toString().contains(text)) {
PropertyComboBox.addItem(propList.get(i).get(j).toString());
}
}
} else {
PropertyComboBox.hidePopup();
}
}
public void changedUpdate(DocumentEvent e) {
}
public void insertUpdate(DocumentEvent e) {
applyFilter();
}
public void removeUpdate(DocumentEvent e) {
applyFilter();
}
});
}
return filterPropertyTextField;
}
use of javax.swing.event.DocumentListener in project intellij-community by JetBrains.
the class ArrayRendererConfigurable method createComponent.
public JComponent createComponent() {
myPanel = new JPanel(new GridBagLayout());
myStartIndex = new JTextField(5);
myEndIndex = new JTextField(5);
myEntriesLimit = new JTextField(5);
final FontMetrics fontMetrics = myStartIndex.getFontMetrics(myStartIndex.getFont());
final Dimension minSize = new Dimension(myStartIndex.getPreferredSize());
//noinspection HardCodedStringLiteral
minSize.width = fontMetrics.stringWidth("AAAAA");
myStartIndex.setMinimumSize(minSize);
myEndIndex.setMinimumSize(minSize);
myEntriesLimit.setMinimumSize(minSize);
JLabel startIndexLabel = new JLabel(DebuggerBundle.message("label.array.renderer.configurable.start.index"));
startIndexLabel.setLabelFor(myStartIndex);
JLabel endIndexLabel = new JLabel(DebuggerBundle.message("label.array.renderer.configurable.end.index"));
endIndexLabel.setLabelFor(myEndIndex);
JLabel entriesLimitLabel = new JLabel(DebuggerBundle.message("label.array.renderer.configurable.max.count1"));
entriesLimitLabel.setLabelFor(myEntriesLimit);
myPanel.add(startIndexLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insetsRight(8), 0, 0));
myPanel.add(myStartIndex, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insetsRight(8), 0, 0));
myPanel.add(endIndexLabel, new GridBagConstraints(2, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insetsRight(8), 0, 0));
myPanel.add(myEndIndex, new GridBagConstraints(3, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
myPanel.add(entriesLimitLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insets(4, 0, 0, 8), 0, 0));
myPanel.add(myEntriesLimit, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insets(4, 0, 0, 8), 0, 0));
myPanel.add(new JLabel(DebuggerBundle.message("label.array.renderer.configurable.max.count2")), new GridBagConstraints(2, GridBagConstraints.RELATIVE, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.insetsTop(4), 0, 0));
// push other components up
myPanel.add(new JLabel(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
final DocumentListener listener = new DocumentListener() {
private void updateEntriesLimit() {
final boolean state = myIndexUpdateEnabled;
myIndexUpdateEnabled = false;
try {
if (myEntriesLimitUpdateEnabled) {
myEntriesLimit.setText(String.valueOf(getInt(myEndIndex) - getInt(myStartIndex) + 1));
}
} finally {
myIndexUpdateEnabled = state;
}
}
public void changedUpdate(DocumentEvent e) {
updateEntriesLimit();
}
public void insertUpdate(DocumentEvent e) {
updateEntriesLimit();
}
public void removeUpdate(DocumentEvent e) {
updateEntriesLimit();
}
};
myStartIndex.getDocument().addDocumentListener(listener);
myEndIndex.getDocument().addDocumentListener(listener);
myEntriesLimit.getDocument().addDocumentListener(new DocumentListener() {
private void updateEndIndex() {
final boolean state = myEntriesLimitUpdateEnabled;
myEntriesLimitUpdateEnabled = false;
try {
if (myIndexUpdateEnabled) {
myEndIndex.setText(String.valueOf(getInt(myEntriesLimit) + getInt(myStartIndex) - 1));
}
} finally {
myEntriesLimitUpdateEnabled = state;
}
}
public void insertUpdate(DocumentEvent e) {
updateEndIndex();
}
public void removeUpdate(DocumentEvent e) {
updateEndIndex();
}
public void changedUpdate(DocumentEvent e) {
updateEndIndex();
}
});
return myPanel;
}
use of javax.swing.event.DocumentListener in project zaproxy by zaproxy.
the class DialogAddUser method getNameTextField.
protected ZapTextField getNameTextField() {
if (nameTextField == null) {
nameTextField = new ZapTextField(25);
nameTextField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
checkValidAndEnableConfirmButton();
}
@Override
public void insertUpdate(DocumentEvent e) {
checkValidAndEnableConfirmButton();
}
@Override
public void changedUpdate(DocumentEvent e) {
checkValidAndEnableConfirmButton();
}
});
}
return nameTextField;
}
Aggregations