Search in sources :

Example 11 with CaretListener

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;
}
Also used : JScrollPane(javax.swing.JScrollPane) CaretEvent(javax.swing.event.CaretEvent) JPanel(javax.swing.JPanel) CaretListener(javax.swing.event.CaretListener) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) JSplitPane(javax.swing.JSplitPane)

Example 12 with CaretListener

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() };
    }
}
Also used : CaretEvent(javax.swing.event.CaretEvent) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) KeyEvent(java.awt.event.KeyEvent) CaretListener(javax.swing.event.CaretListener) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout) WindowEvent(java.awt.event.WindowEvent) EmptyBorder(javax.swing.border.EmptyBorder) JDialog(javax.swing.JDialog)

Aggregations

CaretEvent (javax.swing.event.CaretEvent)12 CaretListener (javax.swing.event.CaretListener)12 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)6 DocumentEvent (javax.swing.event.DocumentEvent)3 Dimension (java.awt.Dimension)2 KeyAdapter (java.awt.event.KeyAdapter)2 KeyEvent (java.awt.event.KeyEvent)2 File (java.io.File)2 JPanel (javax.swing.JPanel)2 EtchedBorder (javax.swing.border.EtchedBorder)2 DocumentListener (javax.swing.event.DocumentListener)2 BadLocationException (javax.swing.text.BadLocationException)2 DocumentAdapter (com.intellij.ui.DocumentAdapter)1 BorderLayout (java.awt.BorderLayout)1 Container (java.awt.Container)1 Frame (java.awt.Frame)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 Panel (java.awt.Panel)1