Search in sources :

Example 21 with Document

use of javax.swing.text.Document in project android by JetBrains.

the class IconStep method init.

@Override
public void init() {
    super.init();
    myAssetGenerator = new AssetStudioAssetGenerator(new ScopedStateStoreAdapter(myState));
    myState.put(ATTR_ASSET_TYPE, AssetType.LAUNCHER);
    String relativeTemplatePath = FileUtil.join(Template.CATEGORY_PROJECTS, WizardConstants.MODULE_TEMPLATE_NAME, "root", "res", "mipmap-xhdpi", "ic_launcher.png");
    myState.put(ATTR_IMAGE_PATH, new File(TemplateManager.getTemplateRootFolder(), relativeTemplatePath).getAbsolutePath());
    register(ATTR_OUTPUT_FOLDER, mySourceSetComboBox);
    register(ATTR_IMAGE_PATH, myImageFile);
    register(ATTR_TEXT, myText);
    register(ATTR_PADDING, myPaddingSlider);
    register(ATTR_PADDING, myPaddingTextField, new ComponentBinding<Integer, JTextField>() {

        @Override
        public void setValue(@Nullable Integer newValue, @NotNull JTextField component) {
            component.setText(newValue == null ? "" : String.valueOf(newValue));
        }

        @Nullable
        @Override
        public Integer getValue(@NotNull JTextField component) {
            try {
                // so the user already receives enough feedback.
                return Math.max(0, Math.min(Integer.parseInt(component.getText()), 100));
            } catch (NumberFormatException e) {
                return 0;
            }
        }

        @Override
        public void addActionListener(@NotNull ActionListener listener, @NotNull JTextField component) {
            component.addActionListener(listener);
        }

        @Nullable
        @Override
        public Document getDocument(@NotNull JTextField component) {
            return component.getDocument();
        }
    });
    register(ATTR_TRIM, myTrimBlankSpace);
    register(ATTR_FONT, myFontFamily);
    register(ATTR_SOURCE_TYPE, ImmutableMap.of(myImageRadioButton, SourceType.IMAGE, myClipartRadioButton, SourceType.CLIPART, myTextRadioButton, SourceType.TEXT));
    register(ATTR_FOREGROUND_COLOR, myForegroundColor);
    register(ATTR_BACKGROUND_COLOR, myBackgroundColor);
    register(ATTR_ASSET_NAME, myResourceNameField);
    register(ATTR_CLIPART_NAME, myChooseClipart, new ComponentBinding<String, JButton>() {

        @Override
        public void setValue(@Nullable String newValue, @NotNull JButton component) {
            component.setIcon(getClipartIcon(newValue));
            component.setText(newValue);
        }
    });
}
Also used : AssetStudioAssetGenerator(com.android.tools.idea.npw.AssetStudioAssetGenerator) Document(javax.swing.text.Document) ActionListener(java.awt.event.ActionListener) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with Document

use of javax.swing.text.Document in project android by JetBrains.

the class ScopedDataBinder method register.

/**
   * Connects the given {@link JComponent} to the given key through the given binding
   * and sets a listener to pick up changes that need to trigger validation and UI updates.
   */
public <T, C extends JComponent> void register(@NotNull Key<T> key, @NotNull C component, @NotNull ComponentBinding<T, ? super C> binding) {
    T value = bindAndGet(key, component, binding);
    if (value != null) {
        try {
            binding.setValue(value, component);
        } catch (UnsupportedOperationException e) {
        // Expected.
        }
    } else {
        try {
            myState.put(key, binding.getValue(component));
        } catch (UnsupportedOperationException e) {
        // Expected.
        }
    }
    component.addFocusListener(this);
    binding.addActionListener(this, component);
    binding.addChangeListener(this, component);
    binding.addItemListener(this, component);
    Document document = binding.getDocument(component);
    if (document != null) {
        myDocumentsToComponent.put(document, component);
        document.addDocumentListener(this);
    }
}
Also used : Document(javax.swing.text.Document)

Example 23 with Document

use of javax.swing.text.Document in project android by JetBrains.

the class MergedManifestFixture method clickLinkText.

public void clickLinkText(String linkText) {
    try {
        // Can't use myInfoPane.text() -- which gives us the HTML markup. We
        // want the rendered text instead
        Document document = myInfoPane.target().getDocument();
        String text = document.getText(0, document.getLength());
        int index = text.indexOf(linkText);
        Truth.assertThat(index).isAtLeast(0);
        Rectangle rect = myInfoPane.target().modelToView(index);
        Point location = rect.getLocation();
        location.translate(2, 0);
        robot().click(myInfoPane.target(), location, MouseButton.LEFT_BUTTON, 1);
    } catch (Exception ex) {
        throw new AssertionError(ex);
    }
}
Also used : Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Example 24 with Document

use of javax.swing.text.Document in project jdk8u_jdk by JetBrains.

the class LWTextComponentPeer method setText.

@Override
public final void setText(final String text) {
    synchronized (getDelegateLock()) {
        // JTextArea.setText() posts two different events (remove & insert).
        // Since we make no differences between text events,
        // the document listener has to be disabled while
        // JTextArea.setText() is called.
        final Document document = getTextComponent().getDocument();
        document.removeDocumentListener(this);
        getTextComponent().setText(text);
        revalidate();
        if (firstChangeSkipped) {
            postEvent(new TextEvent(getTarget(), TextEvent.TEXT_VALUE_CHANGED));
        }
        document.addDocumentListener(this);
    }
    repaintPeer();
}
Also used : TextEvent(java.awt.event.TextEvent) Document(javax.swing.text.Document)

Example 25 with Document

use of javax.swing.text.Document in project jdk8u_jdk by JetBrains.

the class ElementTreePanel method propertyChange.

// PropertyChangeListener
/**
     * Invoked when a property changes. We are only interested in when the
     * Document changes to reset the DocumentListener.
     */
public void propertyChange(PropertyChangeEvent e) {
    if (e.getSource() == getEditor() && e.getPropertyName().equals("document")) {
        Document oldDoc = (Document) e.getOldValue();
        Document newDoc = (Document) e.getNewValue();
        // Reset the DocumentListener
        oldDoc.removeDocumentListener(this);
        newDoc.addDocumentListener(this);
        // Recreate the TreeModel.
        treeModel = new ElementTreeModel(newDoc);
        tree.setModel(treeModel);
    }
}
Also used : Document(javax.swing.text.Document)

Aggregations

Document (javax.swing.text.Document)64 BadLocationException (javax.swing.text.BadLocationException)29 DocumentEvent (javax.swing.event.DocumentEvent)10 DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)8 DocumentAdapter (com.intellij.ui.DocumentAdapter)7 HTMLDocument (javax.swing.text.html.HTMLDocument)7 ActionEvent (java.awt.event.ActionEvent)5 PlainDocument (javax.swing.text.PlainDocument)5 ActionListener (java.awt.event.ActionListener)4 File (java.io.File)3 IOException (java.io.IOException)3 DocumentListener (javax.swing.event.DocumentListener)3 Element (javax.swing.text.Element)3 FieldPanel (com.intellij.ui.FieldPanel)2 CheckBox (com.intellij.util.ui.CheckBox)2 NumberFormat (java.text.NumberFormat)2 ParseException (java.text.ParseException)2 AbstractAction (javax.swing.AbstractAction)2 AbstractDocument (javax.swing.text.AbstractDocument)2 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)2