use of javax.swing.event.CaretListener 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;
}
use of javax.swing.event.CaretListener in project omegat by omegat-org.
the class SplittingPanelController method show.
/**
* Show the dialog. The dialog is modal, so this method will block until complete.
* <p>
* If the user cancels, the result array will contain as its sole member the original string provided to
* the constructor. Otherwise the array will contain the (trimmed) results of splitting the original
* string.
*
* @param parent
* The parent window of the dialog
* @return The result array
*/
public String[] show(Window parent) {
final JDialog dialog = new JDialog(parent, OStrings.getString("ALIGNER_DIALOG_SPLITTER"), ModalityType.DOCUMENT_MODAL);
dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
doCancel(dialog);
}
});
StaticUIUtils.setEscapeClosable(dialog);
final EditingPanel panel = new EditingPanel();
panel.editorPane.setEditable(false);
panel.editorPane.setText(text);
StaticUIUtils.makeCaretAlwaysVisible(panel.editorPane);
panel.okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
splitOffset = panel.editorPane.getCaretPosition();
dialog.dispose();
}
});
panel.cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doCancel(dialog);
}
});
panel.okButton.setEnabled(false);
panel.editorPane.addCaretListener(new CaretListener() {
@Override
public void caretUpdate(CaretEvent e) {
panel.okButton.setEnabled(e.getDot() == e.getMark() && e.getDot() > 0 && e.getDot() < text.length());
}
});
panel.editorPane.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
panel.okButton.doClick();
}
}
});
if (reference != null) {
JPanel referencePanel = new JPanel(new BorderLayout());
JTextArea textArea = new JTextArea(reference);
textArea.setOpaque(false);
textArea.setWrapStyleWord(true);
textArea.setLineWrap(true);
textArea.setEditable(false);
textArea.setFocusable(false);
referencePanel.add(textArea);
referencePanel.setBorder(new EmptyBorder(10, 10, 10, 10));
panel.add(referencePanel, BorderLayout.NORTH);
}
panel.helpText.setText(OStrings.getString("ALIGNER_DIALOG_SPLITTER_HELP"));
dialog.add(panel);
dialog.getRootPane().setDefaultButton(panel.okButton);
dialog.setMinimumSize(new Dimension(450, 250));
dialog.pack();
dialog.setLocationRelativeTo(parent);
dialog.setVisible(true);
if (splitOffset == -1) {
return new String[] { text };
} else {
return new String[] { text.substring(0, splitOffset).trim(), text.substring(splitOffset, text.length()).trim() };
}
}
Aggregations