use of javax.swing.event.DocumentListener in project zaproxy by zaproxy.
the class OptionsLangPanel method getFileTextField.
private ZapTextField getFileTextField() {
if (fileTextField == null) {
fileTextField = new ZapTextField();
fileTextFieldDoc = fileTextField.getDocument();
fileTextFieldDoc.addDocumentListener(new DocumentListener() {
@Override
public void changedUpdate(DocumentEvent e) {
updated(e);
}
@Override
public void insertUpdate(DocumentEvent e) {
updated(e);
}
@Override
public void removeUpdate(DocumentEvent e) {
updated(e);
}
private void updated(DocumentEvent e) {
try {
String inputString = e.getDocument().getText(0, e.getDocument().getLength());
importButton.setEnabled(inputString.endsWith(".zaplang"));
} catch (BadLocationException e1) {
//logger.error(e1.getMessage());
}
}
});
}
return fileTextField;
}
use of javax.swing.event.DocumentListener 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.DocumentListener in project intellij-community by JetBrains.
the class IdeaGradleProjectSettingsControlBuilder method addGradleHomeComponents.
@Override
public IdeaGradleProjectSettingsControlBuilder addGradleHomeComponents(PaintAwarePanel content, int indentLevel) {
if (dropGradleHomePathComponents)
return this;
myGradleHomeLabel = new JBLabel(GradleBundle.message("gradle.settings.text.home.path"));
myGradleHomePathField = new TextFieldWithBrowseButton();
myGradleHomePathField.addBrowseFolderListener("", GradleBundle.message("gradle.settings.text.home.path"), null, GradleUtil.getGradleHomeFileChooserDescriptor(), TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT);
myGradleHomePathField.getTextField().getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
myGradleHomePathField.getTextField().setForeground(LocationSettingType.EXPLICIT_CORRECT.getColor());
}
@Override
public void removeUpdate(DocumentEvent e) {
myGradleHomePathField.getTextField().setForeground(LocationSettingType.EXPLICIT_CORRECT.getColor());
}
@Override
public void changedUpdate(DocumentEvent e) {
}
});
content.add(myGradleHomeLabel, ExternalSystemUiUtil.getLabelConstraints(indentLevel));
content.add(myGradleHomePathField, ExternalSystemUiUtil.getFillLineConstraints(0));
return this;
}
use of javax.swing.event.DocumentListener in project ChatGameFontificator by GlitchCog.
the class ControlPanelChat method build.
@Override
protected void build() {
resizableBox = new JCheckBox("Resize Chat by Dragging");
scrollableBox = new JCheckBox("Mouse Wheel Scrolls Chat");
reverseScrollBox = new JCheckBox("Reverse Chat Order");
chatFromBottomBox = new JCheckBox("Chat Starts from Bottom");
widthInput = new LabeledInput("Width", 3);
heightInput = new LabeledInput("Height", 3);
DocumentListener chatSizeDocListener = new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
somethingChanged(e);
}
@Override
public void removeUpdate(DocumentEvent e) {
somethingChanged(e);
}
@Override
public void changedUpdate(DocumentEvent e) {
somethingChanged(e);
}
/**
* Something changed, so try to get the new width and height and set the updateSizeButton to enabled or
* disabled accordingly
*
* @param e
*/
private void somethingChanged(DocumentEvent e) {
try {
int w = Integer.parseInt(widthInput.getText());
int h = Integer.parseInt(heightInput.getText());
updateSizeButton.setEnabled(w != config.getWidth() || h != config.getHeight());
} catch (Exception ex) {
updateSizeButton.setEnabled(false);
}
}
};
DocumentListener chromaDocListener = new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
toggleChromaButtonEnabled();
}
@Override
public void removeUpdate(DocumentEvent e) {
toggleChromaButtonEnabled();
}
@Override
public void changedUpdate(DocumentEvent e) {
toggleChromaButtonEnabled();
}
};
widthInput.addDocumentListener(chatSizeDocListener);
heightInput.addDocumentListener(chatSizeDocListener);
updateSizeButton = new JButton("Update Chat Size");
chromaEnabledBox = new JCheckBox("Enable Chroma Key Border");
chromaInvertBox = new JCheckBox("Invert Chroma Key Border");
chromaCornerSlider = new LabeledSlider("Corner Radius", "pixels", ConfigChat.MIN_CHROMA_CORNER_RADIUS, ConfigChat.MAX_CHROMA_CORNER_RADIUS);
final String[] chromaLabels = new String[] { "Left", "Top", "Right", "Bottom" };
chromaBorderInput = new LabeledInput[chromaLabels.length];
for (int i = 0; i < chromaBorderInput.length; i++) {
chromaBorderInput[i] = new LabeledInput(chromaLabels[i], 4);
chromaBorderInput[i].addDocumentListener(chromaDocListener);
}
updateChromaSizeButton = new JButton("Update Chroma Border");
ActionListener boxListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JCheckBox source = (JCheckBox) e.getSource();
if (resizableBox.equals(source)) {
chatWindow.setResizable(resizableBox.isSelected());
config.setResizable(resizableBox.isSelected());
} else if (scrollableBox.equals(source)) {
config.setScrollable(scrollableBox.isSelected());
if (!scrollableBox.isSelected()) {
// No scrolling, so reset any existing scroll offset
chat.resetScrollOffset();
}
} else if (reverseScrollBox.equals(source)) {
config.setReverseScrolling(reverseScrollBox.isSelected());
} else if (chatFromBottomBox.equals(source)) {
// Reset scrolling to avoid having to translate it between chat-start top/bottom styles
chat.resetScrollOffset();
config.setChatFromBottom(chatFromBottomBox.isSelected());
} else if (chromaEnabledBox.equals(source)) {
config.setChromaEnabled(chromaEnabledBox.isSelected());
toggleChromaInputFields();
} else if (chromaInvertBox.equals(source)) {
config.setChromaInvert(chromaInvertBox.isSelected());
}
chat.repaint();
}
};
resizableBox.addActionListener(boxListener);
scrollableBox.addActionListener(boxListener);
reverseScrollBox.addActionListener(boxListener);
chatFromBottomBox.addActionListener(boxListener);
chromaEnabledBox.addActionListener(boxListener);
chromaInvertBox.addActionListener(boxListener);
ActionListener dimListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
LoadConfigReport report = new LoadConfigReport();
config.validateDimStrings(report, widthInput.getText(), heightInput.getText());
if (report.isErrorFree()) {
final int width = Integer.parseInt(widthInput.getText());
final int height = Integer.parseInt(heightInput.getText());
config.setWidth(width);
config.setHeight(height);
chatWindow.setSize(config.getWidth(), config.getHeight());
} else {
ChatWindow.popup.handleProblem(report);
}
} catch (Exception ex) {
ChatWindow.popup.handleProblem("Chat Width and Chat Height values could not be parsed", ex);
}
}
};
updateSizeButton.addActionListener(dimListener);
ActionListener chromaDimListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
LoadConfigReport report = new LoadConfigReport();
config.validateChromaDimStrings(report, chromaBorderInput[0].getText(), chromaBorderInput[1].getText(), chromaBorderInput[2].getText(), chromaBorderInput[3].getText());
if (report.isErrorFree()) {
inputToConfigChromaBorders();
chat.repaint();
} else {
ChatWindow.popup.handleProblem(report);
}
} catch (Exception ex) {
ChatWindow.popup.handleProblem("Chat Chroma border values could not be parsed", ex);
}
}
};
updateChromaSizeButton.addActionListener(chromaDimListener);
chromaCornerSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
config.setChromaCornerRadius(chromaCornerSlider.getValue());
chat.repaint();
}
});
JPanel chatDimPanel = new JPanel(new GridBagLayout());
JPanel chatOptionsPanel = new JPanel(new GridBagLayout());
JPanel chromaDimPanel = new JPanel(new GridBagLayout());
chatDimPanel.setBorder(new TitledBorder(baseBorder, "Chat Window Size", TitledBorder.CENTER, TitledBorder.TOP));
chatOptionsPanel.setBorder(new TitledBorder(baseBorder, "Chat Window Options", TitledBorder.CENTER, TitledBorder.TOP));
chromaDimPanel.setBorder(baseBorder);
GridBagConstraints dGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, DEFAULT_INSETS, 0, 0);
dGbc.gridx = 0;
dGbc.gridy = 0;
dGbc.gridwidth = 1;
chatDimPanel.add(widthInput, dGbc);
dGbc.gridx++;
chatDimPanel.add(heightInput, dGbc);
dGbc.gridx = 0;
dGbc.gridy++;
dGbc.gridwidth = 2;
chatDimPanel.add(updateSizeButton, dGbc);
dGbc.gridy++;
chatDimPanel.add(resizableBox, dGbc);
dGbc.gridy++;
GridBagConstraints coGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, DEFAULT_INSETS, 0, 0);
coGbc.anchor = GridBagConstraints.WEST;
chatOptionsPanel.add(scrollableBox, coGbc);
coGbc.gridy++;
chatOptionsPanel.add(reverseScrollBox, coGbc);
coGbc.gridy++;
chatOptionsPanel.add(chatFromBottomBox, coGbc);
coGbc.gridy++;
GridBagConstraints chromaGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, NO_INSETS, 0, 0);
chromaGbc.gridwidth = 3;
chromaDimPanel.add(chromaEnabledBox, chromaGbc);
chromaGbc.gridy++;
chromaDimPanel.add(chromaBorderInput[1], chromaGbc);
chromaGbc.gridy++;
chromaGbc.gridwidth = 1;
chromaGbc.anchor = GridBagConstraints.EAST;
chromaDimPanel.add(chromaBorderInput[0], chromaGbc);
chromaGbc.gridx++;
chromaGbc.anchor = GridBagConstraints.CENTER;
chromaDimPanel.add(updateChromaSizeButton, chromaGbc);
chromaGbc.gridx++;
chromaGbc.anchor = GridBagConstraints.WEST;
chromaDimPanel.add(chromaBorderInput[2], chromaGbc);
chromaGbc.gridx = 0;
chromaGbc.anchor = GridBagConstraints.CENTER;
chromaGbc.gridy++;
chromaGbc.gridwidth = 3;
chromaDimPanel.add(chromaBorderInput[3], chromaGbc);
chromaGbc.gridy++;
chromaDimPanel.add(chromaInvertBox, chromaGbc);
chromaGbc.gridy++;
chromaDimPanel.add(chromaCornerSlider, chromaGbc);
JPanel everything = new JPanel(new GridBagLayout());
GridBagConstraints eGbc = new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, NO_INSETS, 0, 0);
eGbc.weighty = 0.5;
eGbc.weightx = 0.5;
eGbc.fill = GridBagConstraints.HORIZONTAL;
eGbc.insets = new Insets(0, 3, 0, 3);
everything.add(chatDimPanel, eGbc);
eGbc.weightx = 0.5;
eGbc.gridx++;
everything.add(chatOptionsPanel, eGbc);
eGbc.weightx = 1.0;
eGbc.weighty = 0.0;
eGbc.gridx = 0;
eGbc.gridy++;
eGbc.gridwidth = 2;
eGbc.fill = GridBagConstraints.BOTH;
eGbc.anchor = GridBagConstraints.CENTER;
everything.add(chromaDimPanel, eGbc);
eGbc.gridy++;
gbc.anchor = GridBagConstraints.NORTH;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
add(everything, gbc);
}
use of javax.swing.event.DocumentListener in project intellij-community by JetBrains.
the class PlaybackDebugger method initUi.
private void initUi() {
myComponent = new JPanel(new BorderLayout());
myLog = new JEditorPane();
myLog.setEditorKit(new StyledEditorKit());
myLog.setEditable(false);
myState = ServiceManager.getService(PlaybackDebuggerState.class);
final DefaultActionGroup controlGroup = new DefaultActionGroup();
controlGroup.add(new RunOnFameActivationAction());
controlGroup.add(new ActivateFrameAndRun());
controlGroup.add(new StopAction());
JPanel north = new JPanel(new BorderLayout());
north.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, controlGroup, true).getComponent(), BorderLayout.WEST);
final JPanel right = new JPanel(new BorderLayout());
right.add(myCurrentScript, BorderLayout.CENTER);
myCurrentScript.setText(myState.currentScript);
myCurrentScript.setEditable(false);
final DefaultActionGroup fsGroup = new DefaultActionGroup();
SaveAction saveAction = new SaveAction();
saveAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("control S")), myComponent);
fsGroup.add(saveAction);
SetScriptFileAction setScriptFileAction = new SetScriptFileAction();
setScriptFileAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("control O")), myComponent);
fsGroup.add(setScriptFileAction);
AnAction newScriptAction = new NewScriptAction();
newScriptAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke("control N")), myComponent);
fsGroup.add(newScriptAction);
final ActionToolbar tb = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, fsGroup, true);
tb.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY);
right.add(tb.getComponent(), BorderLayout.EAST);
north.add(right, BorderLayout.CENTER);
myComponent.add(north, BorderLayout.NORTH);
myCodeEditor = new JTextArea();
myCodeEditor.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
myChanged = true;
}
@Override
public void removeUpdate(DocumentEvent e) {
myChanged = true;
}
@Override
public void changedUpdate(DocumentEvent e) {
myChanged = true;
}
});
if (pathToFile() != null) {
loadFrom(pathToFile());
}
final Splitter script2Log = new Splitter(true);
script2Log.setFirstComponent(ScrollPaneFactory.createScrollPane(myCodeEditor));
script2Log.setSecondComponent(ScrollPaneFactory.createScrollPane(myLog));
myComponent.add(script2Log, BorderLayout.CENTER);
myVfsListener = new VirtualFileAdapter() {
@Override
public void contentsChanged(@NotNull VirtualFileEvent event) {
final VirtualFile file = pathToFile();
if (file != null && file.equals(event.getFile())) {
loadFrom(event.getFile());
}
}
};
LocalFileSystem.getInstance().addVirtualFileListener(myVfsListener);
}
Aggregations