Search in sources :

Example 46 with JTextComponent

use of javax.swing.text.JTextComponent in project cuba by cuba-platform.

the class DesktopPickerField method setEditableToComponent.

@Override
protected void setEditableToComponent(boolean editable) {
    for (Action action : actionsOrder) {
        if (action instanceof StandardAction) {
            ((StandardAction) action).setEditable(editable);
        }
    }
    if (!editable && impl.getEditor() instanceof JTextComponent) {
        JTextComponent editor = (JTextComponent) impl.getEditor();
        editor.setEditable(false);
    }
    updateMissingValueState();
}
Also used : AbstractAction(javax.swing.AbstractAction) Action(com.haulmont.cuba.gui.components.Action) JTextComponent(javax.swing.text.JTextComponent)

Example 47 with JTextComponent

use of javax.swing.text.JTextComponent in project blue by kunstmusik.

the class FindReplaceDialog method showFindReplace.

public static void showFindReplace(JTextComponent textComponent) {
    Component root = SwingUtilities.getRoot(textComponent);
    if (!map.containsKey(root)) {
        FindReplaceDialog dialog;
        if (root instanceof Frame) {
            dialog = new FindReplaceDialog((Frame) root);
        } else if (root instanceof Dialog) {
            dialog = new FindReplaceDialog((Dialog) root);
        } else {
            return;
        }
        map.put(root, dialog);
    }
    FindReplaceDialog findReplaceDialog = map.get(root);
    findReplaceDialog.setTextArea(textComponent);
    String selectedText = textComponent.getSelectedText();
    if (selectedText != null) {
        findReplaceDialog.setInititalSearchText(selectedText);
    }
    findReplaceDialog.setVisible(true);
}
Also used : Frame(java.awt.Frame) JFrame(javax.swing.JFrame) Dialog(java.awt.Dialog) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent)

Example 48 with JTextComponent

use of javax.swing.text.JTextComponent in project syncope by apache.

the class ResourceExplorerTopComponent method saveContent.

private void saveContent() {
    try {
        JTextComponent ed = EditorRegistry.lastFocusedComponent();
        Document document = ed.getDocument();
        String content = document.getText(0, document.getLength());
        String path = (String) document.getProperty(Document.TitleProperty);
        String[] temp = path.split(File.separator);
        String name = temp[temp.length - 1];
        String templateType = temp[temp.length - 2];
        temp = name.split("\\.");
        String format = temp[1];
        String key = temp[0];
        if (templateType.equals("Mail")) {
            if (format.equals("txt")) {
                mailTemplateManagerService.setFormat(key, MailTemplateFormat.TEXT, IOUtils.toInputStream(content, encodingPattern));
            } else {
                mailTemplateManagerService.setFormat(key, MailTemplateFormat.HTML, IOUtils.toInputStream(content, encodingPattern));
            }
        } else if (format.equals("html")) {
            reportTemplateManagerService.setFormat(key, ReportTemplateFormat.HTML, IOUtils.toInputStream(content, encodingPattern));
        } else if (format.equals("fo")) {
            reportTemplateManagerService.setFormat(key, ReportTemplateFormat.FO, IOUtils.toInputStream(content, encodingPattern));
        } else {
            reportTemplateManagerService.setFormat(key, ReportTemplateFormat.CSV, IOUtils.toInputStream(content, encodingPattern));
        }
    } catch (BadLocationException e) {
        Exceptions.printStackTrace(e);
    }
}
Also used : JTextComponent(javax.swing.text.JTextComponent) Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Example 49 with JTextComponent

use of javax.swing.text.JTextComponent in project com.revolsys.open by revolsys.

the class SwingUtil method newComboBox.

static ComboBox<Identifier> newComboBox(final String fieldName, final CodeTable codeTable, final boolean required, final int maxLength, final boolean idSuffix) {
    if (codeTable == null) {
        return null;
    } else {
        final ComboBox<Identifier> comboBox = CodeTableComboBoxModel.newComboBox(fieldName, codeTable, !required, idSuffix);
        if (comboBox.getModel().getSize() > 0) {
            comboBox.setSelectedIndex(0);
        }
        int longestLength = -1;
        for (final Entry<Identifier, List<Object>> codes : codeTable.getCodes().entrySet()) {
            int length = 0;
            if (idSuffix) {
                final Identifier identifier = codes.getKey();
                length += identifier.toString().length() + 3;
            }
            final List<Object> values = codes.getValue();
            if (values != null && !values.isEmpty()) {
                final String text = Strings.toString(values);
                length += text.length();
            }
            if (length > longestLength) {
                longestLength = length;
            }
        }
        if (longestLength == -1) {
            longestLength = 10;
        }
        if (maxLength > 0 && longestLength > maxLength) {
            longestLength = maxLength;
        }
        final StringBuilder value = new StringBuilder();
        for (int i = 0; i < longestLength; i++) {
            value.append("W");
        }
        comboBox.setPrototypeDisplayValue(Identifier.newIdentifier(value));
        final ComboBoxEditor editor = comboBox.getEditor();
        final Component editorComponent = editor.getEditorComponent();
        if (editorComponent instanceof JTextComponent) {
            final JTextField textComponent = (JTextField) editorComponent;
            textComponent.setColumns((int) (longestLength * 0.8));
            final MenuFactory menu = MenuFactory.getPopupMenuFactory(textComponent);
            MenuFactory.addToComponent(comboBox, menu);
        } else {
            MenuFactory.getPopupMenuFactory(comboBox);
        }
        return comboBox;
    }
}
Also used : JTextComponent(javax.swing.text.JTextComponent) JTextField(javax.swing.JTextField) ComboBoxEditor(javax.swing.ComboBoxEditor) Point(java.awt.Point) Identifier(com.revolsys.identifier.Identifier) MenuFactory(com.revolsys.swing.menu.MenuFactory) List(java.util.List) ArrayList(java.util.ArrayList) JList(javax.swing.JList) Component(java.awt.Component) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent)

Example 50 with JTextComponent

use of javax.swing.text.JTextComponent in project com.revolsys.open by revolsys.

the class QueryWhereConditionField method setSearchField.

private void setSearchField(final FieldDefinition fieldDefinition) {
    if (this.searchField != null) {
        Property.removeListener(this.searchField, this);
        if (this.searchField instanceof JTextComponent) {
            final JTextComponent textField = (JTextComponent) this.searchField;
            textField.getDocument().removeDocumentListener(this);
        }
    }
    this.searchFieldPanel.removeAll();
    final String fieldName = fieldDefinition.getName();
    this.codeTable = this.recordDefinition.getCodeTableByFieldName(fieldName);
    this.searchField = this.layer.newSearchField(fieldDefinition, this.codeTable);
    final boolean oldFieldComparable = this.fieldComparable;
    this.fieldComparable = false;
    final boolean oldLikeEnabled = this.likeEnabled;
    this.likeEnabled = false;
    if (this.codeTable == null) {
        final Class<?> fieldClass = fieldDefinition.getTypeClass();
        if (Number.class.isAssignableFrom(fieldClass) || Date.class.isAssignableFrom(fieldClass)) {
            this.fieldComparable = true;
        } else if (String.class.isAssignableFrom(fieldClass)) {
            this.likeEnabled = true;
        }
    }
    firePropertyChange("fieldComparable", oldFieldComparable, this.fieldComparable);
    firePropertyChange("likeEnabled", oldLikeEnabled, this.likeEnabled);
    this.searchFieldPanel.add(this.searchField);
    setHasSearchText(((Field) this.searchField).isHasValidValue());
    Property.addListener(this.searchField, this);
    if (this.searchField instanceof JTextComponent) {
        final JTextComponent textField = (JTextComponent) this.searchField;
        textField.getDocument().addDocumentListener(this);
    }
    GroupLayouts.makeColumns(this.searchFieldPanel, false);
}
Also used : JTextComponent(javax.swing.text.JTextComponent) Date(java.util.Date)

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