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);
}
});
}
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);
}
}
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);
}
}
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();
}
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);
}
}
Aggregations