use of javax.swing.event.CaretEvent in project tetrad by cmu-phil.
the class TetradLogArea method buildSetupLoggingComponent.
/**
* The component used to config logging.
*/
public static JPanel buildSetupLoggingComponent() {
// build yes/no combo box.
JComboBox activateCombo = new JComboBox(new String[] { "No", "Yes" });
activateCombo.setMaximumSize(activateCombo.getPreferredSize());
activateCombo.setSelectedItem(TetradLogger.getInstance().isLogging() ? "Yes" : "No");
activateCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox combo = (JComboBox) e.getSource();
TetradLogger.getInstance().setLogging("Yes".equals(combo.getSelectedItem()));
}
});
String saveLocation = TetradLogger.getInstance().getLoggingDirectory();
final JTextField saveField = new JTextField(saveLocation);
saveField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JTextField field = (JTextField) e.getSource();
try {
TetradLogger.getInstance().setLoggingDirectory(field.getText());
} catch (IllegalArgumentException ex) {
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), ex.getMessage());
}
}
});
JButton chooseButton = new JButton(" ... ");
chooseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String saveLocation = TetradLogger.getInstance().getLoggingDirectory();
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setCurrentDirectory(new File(saveLocation));
int ret = chooser.showOpenDialog(JOptionUtils.centeringComp());
if (ret == JFileChooser.APPROVE_OPTION) {
File selectedFile = chooser.getSelectedFile();
Preferences.userRoot().put("loggingDirectory", selectedFile.getAbsolutePath());
saveField.setText(selectedFile.getAbsolutePath());
}
}
});
chooseButton.setBorder(new EtchedBorder());
JTextField prefixField = new JTextField(TetradLogger.getInstance().getLoggingFilePrefix());
prefixField.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
JTextField field = (JTextField) e.getSource();
String text = field.getText();
if (!text.matches("[a-zA-Z_]*")) {
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Spaces, numbers, and special characters (" + "except underlines) in filenames will be " + "ignored. You might want to delete them.", "Friendly Detail Message", JOptionPane.WARNING_MESSAGE);
}
TetradLogger.getInstance().setLoggingFilePrefix(text);
}
});
// Do Layout.
Box b1 = Box.createVerticalBox();
b1.add(createLogToBox());
b1.add(Box.createVerticalStrut(5));
Box b4 = Box.createHorizontalBox();
b4.add(new JLabel("Output Directory:"));
b4.add(Box.createHorizontalGlue());
b1.add(b4);
Box b5 = Box.createHorizontalBox();
b5.add(saveField);
b5.add(chooseButton);
b1.add(b5);
b1.add(Box.createVerticalStrut(5));
Box b6 = Box.createHorizontalBox();
b6.add(new JLabel("File Prefix:"));
b6.add(Box.createHorizontalGlue());
b1.add(b6);
Box b7 = Box.createHorizontalBox();
b7.add(prefixField);
b1.add(b7);
b1.add(Box.createVerticalStrut(5));
Box b8 = Box.createHorizontalBox();
b8.add(new JLabel("<html>" + "Output will be written to sequentially numbered files, using the<br>" + "given file prefix, in the given directory." + "</html>"));
b1.add(b8);
JPanel panel = new JPanel();
panel.add(b1, BorderLayout.CENTER);
return panel;
}
use of javax.swing.event.CaretEvent in project zaproxy by zaproxy.
the class CustomScanDialog method getCustomPanel.
private JPanel getCustomPanel() {
if (customPanel == null) {
customPanel = new JPanel(new GridBagLayout());
JScrollPane scrollPane = new JScrollPane();
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setViewportView(getRequestField());
JPanel buttonPanel = new JPanel(new GridBagLayout());
getRequestField().addCaretListener(new CaretListener() {
@Override
public void caretUpdate(CaretEvent event) {
setFieldStates();
}
});
// Spacer
buttonPanel.add(new JLabel(""), LayoutHelper.getGBC(0, 0, 1, 0.5));
buttonPanel.add(getAddCustomButton(), LayoutHelper.getGBC(1, 0, 1, 1, 0.0D, 0.0D, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST, new Insets(5, 5, 5, 5)));
// Spacer
buttonPanel.add(new JLabel(""), LayoutHelper.getGBC(2, 0, 1, 0.5));
// Spacer
buttonPanel.add(new JLabel(""), LayoutHelper.getGBC(0, 1, 1, 0.5));
buttonPanel.add(getRemoveCustomButton(), LayoutHelper.getGBC(1, 1, 1, 1, 0.0D, 0.0D, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST, new Insets(5, 5, 5, 5)));
// Spacer
buttonPanel.add(new JLabel(""), LayoutHelper.getGBC(2, 1, 1, 0.5));
JScrollPane scrollPane2 = new JScrollPane(getInjectionPointList());
scrollPane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
buttonPanel.add(new JLabel(Constant.messages.getString("ascan.custom.label.vectors")), LayoutHelper.getGBC(0, 2, 3, 0.0D, 0.0D));
buttonPanel.add(scrollPane2, LayoutHelper.getGBC(0, 3, 3, 1.0D, 1.0D));
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scrollPane, buttonPanel);
splitPane.setDividerLocation(550);
customPanel.add(splitPane, LayoutHelper.getGBC(0, 0, 1, 1, 1.0D, 1.0D));
customPanel.add(customPanelStatus, LayoutHelper.getGBC(0, 1, 1, 1, 1.0D, 0.0D));
customPanel.add(getDisableNonCustomVectors(), LayoutHelper.getGBC(0, 2, 1, 1, 1.0D, 0.0D));
}
return customPanel;
}
Aggregations