Search in sources :

Example 51 with JTextComponent

use of javax.swing.text.JTextComponent in project jsql-injection by ron190.

the class DeleteNextCharAction method actionPerformed.

/**
 * The operation to perform when this action is triggered.
 */
@Override
public void actionPerformed(ActionEvent e) {
    JTextComponent target = this.getTextComponent(e);
    if ((target != null) && (target.isEditable())) {
        try {
            Document doc = target.getDocument();
            Caret caret = target.getCaret();
            int dot = caret.getDot();
            int mark = caret.getMark();
            if (dot != mark) {
                doc.remove(Math.min(dot, mark), Math.abs(dot - mark));
            } else if (dot < doc.getLength()) {
                int delChars = 1;
                if (dot < doc.getLength() - 1) {
                    String dotChars = doc.getText(dot, 2);
                    char c0 = dotChars.charAt(0);
                    char c1 = dotChars.charAt(1);
                    if (c0 >= '\uD800' && c0 <= '\uDBFF' && c1 >= '\uDC00' && c1 <= '\uDFFF') {
                        delChars = 2;
                    }
                }
                doc.remove(dot, delChars);
            }
        } catch (BadLocationException ble) {
            LOGGER.error(ble, ble);
        }
    }
}
Also used : JTextComponent(javax.swing.text.JTextComponent) Document(javax.swing.text.Document) Caret(javax.swing.text.Caret) BadLocationException(javax.swing.text.BadLocationException)

Example 52 with JTextComponent

use of javax.swing.text.JTextComponent in project jsql-injection by ron190.

the class SilentDeleteTextAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    JTextComponent target = this.getTextComponent(e);
    if (Objects.nonNull(target) && target.isEditable()) {
        Caret caret = target.getCaret();
        int dot = caret.getDot();
        int mark = caret.getMark();
        if (DefaultEditorKit.deletePrevCharAction.equals(this.getValue(Action.NAME))) {
            // @see javax/swing/text/DefaultEditorKit.java DeletePrevCharAction
            if (dot == 0 && mark == 0) {
                return;
            }
        } else {
            // @see javax/swing/text/DefaultEditorKit.java DeleteNextCharAction
            Document doc = target.getDocument();
            if (dot == mark && doc.getLength() == dot) {
                return;
            }
        }
    }
    this.deleteAction.actionPerformed(e);
}
Also used : JTextComponent(javax.swing.text.JTextComponent) Document(javax.swing.text.Document) Caret(javax.swing.text.Caret)

Example 53 with JTextComponent

use of javax.swing.text.JTextComponent in project flutter-intellij by flutter.

the class FlutterSettingsStepFixture method enterPackageName.

@SuppressWarnings("Duplicates")
@NotNull
public FlutterSettingsStepFixture enterPackageName(@NotNull String text) {
    LabelWithEditButton editLabel = robot().finder().findByType(target(), LabelWithEditButton.class);
    JButton editButton = robot().finder().findByType(editLabel, JButton.class);
    robot().click(editButton);
    JTextComponent textField = findTextFieldWithLabel("Package name");
    replaceText(textField, text);
    // click "Done"
    robot().click(editButton);
    return this;
}
Also used : LabelWithEditButton(com.android.tools.adtui.LabelWithEditButton) JTextComponent(javax.swing.text.JTextComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 54 with JTextComponent

use of javax.swing.text.JTextComponent in project flutter-intellij by flutter.

the class FlutterSettingsStepFixture method enterCompanyDomain.

@NotNull
public FlutterSettingsStepFixture enterCompanyDomain(@NotNull String text) {
    JTextComponent textField = findTextFieldWithLabel("Company domain");
    replaceText(textField, text);
    return this;
}
Also used : JTextComponent(javax.swing.text.JTextComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 55 with JTextComponent

use of javax.swing.text.JTextComponent in project flutter-intellij by flutter.

the class FlutterGeneratorPeer method init.

private void init() {
    mySdkPathComboWithBrowse.getComboBox().setEditable(true);
    FlutterSdkUtil.addKnownSDKPathsToCombo(mySdkPathComboWithBrowse.getComboBox());
    mySdkPathComboWithBrowse.addBrowseFolderListener(FlutterBundle.message("flutter.sdk.browse.path.label"), null, null, FileChooserDescriptorFactory.createSingleFolderDescriptor(), TextComponentAccessor.STRING_COMBOBOX_WHOLE_TEXT);
    final JTextComponent editorComponent = (JTextComponent) getSdkEditor().getEditorComponent();
    editorComponent.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            validate();
        }
    });
    // When this changes the corresponding parts of FlutterProjectStep should also be changed.
    myInstallActionLink.setIcon(myInstallSdkAction.getLinkIcon());
    myInstallActionLink.setDisabledIcon(IconLoader.getDisabledIcon(myInstallSdkAction.getLinkIcon()));
    myInstallActionLink.setText(myInstallSdkAction.getLinkText());
    // noinspection unchecked
    myInstallActionLink.setListener((label, linkUrl) -> myInstallSdkAction.actionPerformed(null), null);
    myProgressText.setFont(UIUtil.getLabelFont(UIUtil.FontSize.NORMAL).deriveFont(Font.ITALIC));
    // Some feedback on hover.
    myCancelProgressButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    myCancelProgressButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            myListener.actionCanceled();
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) DocumentAdapter(com.intellij.ui.DocumentAdapter) JTextComponent(javax.swing.text.JTextComponent) DocumentEvent(javax.swing.event.DocumentEvent)

Aggregations

JTextComponent (javax.swing.text.JTextComponent)181 Component (java.awt.Component)28 JComponent (javax.swing.JComponent)16 BadLocationException (javax.swing.text.BadLocationException)13 NotNull (org.jetbrains.annotations.NotNull)13 DocumentEvent (javax.swing.event.DocumentEvent)11 DocumentAdapter (com.intellij.ui.DocumentAdapter)8 Caret (javax.swing.text.Caret)8 Document (javax.swing.text.Document)8 Point (java.awt.Point)7 ActionEvent (java.awt.event.ActionEvent)7 ActionListener (java.awt.event.ActionListener)7 ArrayList (java.util.ArrayList)7 ComboBoxEditor (javax.swing.ComboBoxEditor)7 FocusEvent (java.awt.event.FocusEvent)6 Color (java.awt.Color)5 KeyEvent (java.awt.event.KeyEvent)5 MouseEvent (java.awt.event.MouseEvent)5 JButton (javax.swing.JButton)5 JComboBox (javax.swing.JComboBox)5