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