use of javax.swing.event.DocumentEvent in project zaproxy by zaproxy.
the class EncodeDecodeDialog method getInputField.
private ZapTextArea getInputField() {
if (inputField == null) {
inputField = newField(true);
inputField.setName(ENCODE_DECODE_FIELD);
inputField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent documentEvent) {
updateEncodeDecodeFields();
}
@Override
public void removeUpdate(DocumentEvent documentEvent) {
updateEncodeDecodeFields();
}
@Override
public void changedUpdate(DocumentEvent documentEvent) {
}
});
inputField.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mousePressed(java.awt.event.MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY());
}
}
});
}
return inputField;
}
use of javax.swing.event.DocumentEvent in project azure-tools-for-java by Microsoft.
the class SparkSubmissionContentPanel method addSelectedArtifactLineItem.
private void addSelectedArtifactLineItem() {
final String tipInfo = "The Artifact you want to use.";
JLabel artifactSelectLabel = new JLabel("Select an Artifact to submit");
artifactSelectLabel.setToolTipText(tipInfo);
selectedArtifactComboBox = new ComboBox();
selectedArtifactComboBox.setToolTipText(tipInfo);
errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()] = new JLabel("Artifact should not be null!");
errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()].setForeground(DarkThemeManager.getInstance().getErrorMessageColor());
errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()].setVisible(false);
errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()] = new JLabel("Could not find the local jar package for Artifact");
errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()].setForeground(DarkThemeManager.getInstance().getErrorMessageColor());
errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()].setVisible(false);
selectedArtifactTextField = new TextFieldWithBrowseButton();
selectedArtifactTextField.setToolTipText("Artifact from local jar package.");
selectedArtifactTextField.setEditable(true);
selectedArtifactTextField.setEnabled(false);
selectedArtifactTextField.getTextField().getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
setVisibleForFixedErrorMessageLabel(2, !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText()));
}
@Override
public void removeUpdate(DocumentEvent e) {
setVisibleForFixedErrorMessageLabel(2, !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText()));
}
@Override
public void changedUpdate(DocumentEvent e) {
setVisibleForFixedErrorMessageLabel(2, !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText()));
}
});
selectedArtifactTextField.getButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
FileChooserDescriptor chooserDescriptor = new FileChooserDescriptor(false, false, true, false, true, false);
chooserDescriptor.setTitle("Select Local Artifact File");
VirtualFile chooseFile = FileChooser.chooseFile(chooserDescriptor, null, null);
if (chooseFile != null) {
String path = chooseFile.getPath();
if (path.endsWith("!/")) {
path = path.substring(0, path.length() - 2);
}
selectedArtifactTextField.setText(path);
}
}
});
intelliJArtifactRadioButton = new JRadioButton("Artifact from IntelliJ project:", true);
localArtifactRadioButton = new JRadioButton("Artifact from local disk:", false);
intelliJArtifactRadioButton.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
selectedArtifactComboBox.setEnabled(true);
selectedArtifactTextField.setEnabled(false);
mainClassTextField.setButtonEnabled(true);
setVisibleForFixedErrorMessageLabel(2, false);
if (selectedArtifactComboBox.getItemCount() == 0) {
setVisibleForFixedErrorMessageLabel(2, true);
}
}
}
});
localArtifactRadioButton.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
selectedArtifactComboBox.setEnabled(false);
selectedArtifactTextField.setEnabled(true);
mainClassTextField.setButtonEnabled(false);
setVisibleForFixedErrorMessageLabel(1, false);
if (StringHelper.isNullOrWhiteSpace(selectedArtifactTextField.getText())) {
setVisibleForFixedErrorMessageLabel(2, true);
}
}
}
});
ButtonGroup group = new ButtonGroup();
group.add(intelliJArtifactRadioButton);
group.add(localArtifactRadioButton);
intelliJArtifactRadioButton.setSelected(true);
add(artifactSelectLabel, new GridBagConstraints(0, ++displayLayoutCurrentRow, 0, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(margin, margin, 0, margin), 0, 0));
add(intelliJArtifactRadioButton, new GridBagConstraints(0, ++displayLayoutCurrentRow, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(margin / 3, margin * 3, 0, margin), 0, 0));
add(selectedArtifactComboBox, new GridBagConstraints(1, displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(margin / 3, margin, 0, margin), 0, 0));
add(errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()], new GridBagConstraints(1, ++displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, margin, 0, 0), 0, 0));
add(localArtifactRadioButton, new GridBagConstraints(0, ++displayLayoutCurrentRow, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(margin / 3, margin * 3, 0, margin), 0, 0));
add(selectedArtifactTextField, new GridBagConstraints(1, displayLayoutCurrentRow, 0, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(margin / 3, margin, 0, margin), 0, 0));
add(errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()], new GridBagConstraints(1, ++displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, margin, 0, 0), 0, 0));
}
use of javax.swing.event.DocumentEvent 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.DocumentEvent in project intellij-community by JetBrains.
the class HgBookmarkDialog method createCenterPanel.
@Override
@NotNull
protected JComponent createCenterPanel() {
JPanel contentPanel = new JPanel(new GridBagLayout());
GridBag g = new GridBag().setDefaultInsets(new Insets(0, 0, DEFAULT_VGAP, DEFAULT_HGAP)).setDefaultAnchor(GridBagConstraints.LINE_START).setDefaultFill(GridBagConstraints.HORIZONTAL);
JLabel icon = new JLabel(UIUtil.getQuestionIcon(), SwingConstants.LEFT);
myBookmarkName = new JBTextField(13);
myBookmarkName.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent e) {
validateFields();
}
});
JBLabel bookmarkLabel = new JBLabel("Bookmark name:");
bookmarkLabel.setLabelFor(myBookmarkName);
myActiveCheckbox = new JBCheckBox("Inactive", false);
contentPanel.add(icon, g.nextLine().next().coverColumn(3).pady(DEFAULT_HGAP));
contentPanel.add(bookmarkLabel, g.next().fillCellNone().insets(new Insets(0, 6, DEFAULT_VGAP, DEFAULT_HGAP)));
contentPanel.add(myBookmarkName, g.next().coverLine().setDefaultWeightX(1));
contentPanel.add(myActiveCheckbox, g.nextLine().next().next().coverLine(2));
return contentPanel;
}
use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.
the class MavenArtifactSearchPanel method initComponents.
private void initComponents(String initialText) {
myResultList = new Tree();
myResultList.setExpandableItemsEnabled(false);
myResultList.getEmptyText().setText("Loading...");
myResultList.setRootVisible(false);
myResultList.setShowsRootHandles(true);
myResultList.setModel(null);
MyArtifactCellRenderer renderer = myClassMode ? new MyClassCellRenderer(myResultList) : new MyArtifactCellRenderer(myResultList);
myResultList.setCellRenderer(renderer);
myResultList.setRowHeight(renderer.getPreferredSize().height);
mySearchField = new JTextField(initialText);
mySearchField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
int d;
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
d = 1;
} else if (e.getKeyCode() == KeyEvent.VK_UP) {
d = -1;
} else {
return;
}
int row = myResultList.getSelectionModel().getLeadSelectionRow();
row += d;
if (row >= 0 && row < myResultList.getRowCount()) {
myResultList.setSelectionRow(row);
}
}
});
setLayout(new BorderLayout());
add(mySearchField, BorderLayout.NORTH);
JScrollPane pane = ScrollPaneFactory.createScrollPane(myResultList);
pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
// Don't remove this line.
pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
// Without VERTICAL_SCROLLBAR_ALWAYS policy our custom layout
// works incorrectly, see https://youtrack.jetbrains.com/issue/IDEA-72986
add(pane, BorderLayout.CENTER);
mySearchField.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
scheduleSearch();
}
});
myResultList.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (!myAlarm.isEmpty())
return;
boolean hasSelection = !myResultList.isSelectionEmpty();
myListener.canSelectStateChanged(MavenArtifactSearchPanel.this, hasSelection);
}
});
myResultList.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER && myResultList.getLastSelectedPathComponent() != null) {
myListener.itemSelected();
e.consume();
}
}
});
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
final TreePath path = myResultList.getPathForLocation(e.getX(), e.getY());
if (path != null && myResultList.isPathSelected(path)) {
Object sel = path.getLastPathComponent();
if (sel != null && myResultList.getModel().isLeaf(sel)) {
myListener.itemSelected();
return true;
}
}
return false;
}
}.installOn(myResultList);
}
Aggregations