use of javax.swing.text.AttributeSet in project pcgen by PCGen.
the class NotesView method colorButtonActionPerformed.
//GEN-LAST:event_leftJustifyButtonActionPerformed
private void colorButtonActionPerformed() {
//GEN-FIRST:event_colorButtonActionPerformed
AttributeSet as = editor.getCharacterAttributes();
SimpleAttributeSet sas = new SimpleAttributeSet(as);
Color newColor = JColorChooser.showDialog(GMGenSystem.inst, "Choose Text Color", editor.getStyledDocument().getForeground(as));
if (newColor != null) {
StyleConstants.setForeground(sas, newColor);
editor.setCharacterAttributes(sas, true);
}
editor.repaint();
}
use of javax.swing.text.AttributeSet in project freeplane by freeplane.
the class HtmlUtils method getURLOfExistingLink.
/**
* Gets the string URL of an existing link, or null if none.
*/
public static String getURLOfExistingLink(HTMLDocument doc, int pos) {
// setIgnoreActions(true);
final Element linkElement = HtmlUtils.getCurrentLinkElement(doc, pos);
final boolean foundLink = (linkElement != null);
if (!foundLink) {
return null;
}
final AttributeSet elemAttrs = linkElement.getAttributes();
final Object linkAttr = elemAttrs.getAttribute(HTML.Tag.A);
final Object href = ((AttributeSet) linkAttr).getAttribute(HTML.Attribute.HREF);
return href != null ? href.toString() : null;
}
use of javax.swing.text.AttributeSet in project freeplane by freeplane.
the class XHTMLWriter method isEndtag.
private boolean isEndtag(final Element elem) {
final AttributeSet attributes = elem.getAttributes();
final Object endTag = attributes.getAttribute(HTML.Attribute.ENDTAG);
final boolean isEndtag = (endTag instanceof String) && ((String) endTag).equals("true");
return isEndtag;
}
use of javax.swing.text.AttributeSet in project Zong by Xenoage.
the class FormattedTextConverter method fromStyledDocument.
/**
* Creates a {@link FormattedText} from the given {@link StyledDocument}.
*/
public static FormattedText fromStyledDocument(StyledDocument styledDoc) {
CList<FormattedTextParagraph> paragraphs = clist();
int endPos = styledDoc.getLength();
AttributeSet attribute = null;
String textelement = "";
String letter = "";
CList<FormattedTextElement> elements = clist();
Alignment alignment = null;
// paragraph, when '\n' is found
for (int i = 0; i < endPos; i++) {
try {
letter = styledDoc.getText(i, 1);
} catch (BadLocationException e) {
}
// line break: create new paragraph
if (letter.equals("\n")) {
if (!textelement.equals("")) {
elements.add(new FormattedTextString(textelement, getStyleFromAttributeSet(attribute)));
textelement = "";
}
paragraphs.add(new FormattedTextParagraph(elements, alignment));
elements = clist();
alignment = null;
} else if (attribute != styledDoc.getCharacterElement(i).getAttributes()) {
// set alignment, if not already done
if (alignment == null) {
alignment = fromAttributeSet(styledDoc.getParagraphElement(i).getAttributes());
}
// style has changed, so save old element and create a new one
if (!textelement.equals("")) {
elements.add(new FormattedTextString(textelement, getStyleFromAttributeSet(attribute)));
}
attribute = styledDoc.getCharacterElement(i).getAttributes();
textelement = letter;
} else {
// style stayed the same, so just append
textelement += letter;
}
}
if (!textelement.equals("")) {
// save the last string
elements.add(new FormattedTextString(textelement, getStyleFromAttributeSet(attribute)));
}
if (elements.size() > 0) {
// add (non-empty) paragraph
paragraphs.add(new FormattedTextParagraph(elements, alignment));
}
return new FormattedText(paragraphs);
}
use of javax.swing.text.AttributeSet in project energy3d by concord-consortium.
the class MyEditorPane method setText.
public void setText(final String text) {
editorPane.setText(text);
if (editorPane.getDocument() instanceof HTMLDocument) {
final HTMLDocument doc = (HTMLDocument) editorPane.getDocument();
final ElementIterator it = new ElementIterator(doc);
Element element;
while ((element = it.next()) != null) {
final AttributeSet as = element.getAttributes();
final Enumeration<?> en = as.getAttributeNames();
DefaultButtonModel buttonModel = null;
PlainDocument document = null;
String action = null;
String question = null;
String choice = null;
String key = null;
String dataName = null;
while (en.hasMoreElements()) {
final Object n = en.nextElement();
final Object v = as.getAttribute(n);
if (v instanceof DefaultButtonModel) {
buttonModel = (DefaultButtonModel) v;
} else if (v instanceof PlainDocument) {
document = (PlainDocument) v;
} else if (n.toString().equals("action")) {
action = v.toString();
} else if (n.toString().equals("question")) {
question = v.toString();
} else if (n.toString().equals("choice")) {
choice = v.toString();
} else if (n.toString().equals("key")) {
key = v.toString();
} else if (n.toString().equals("data")) {
dataName = v.toString();
}
}
if (action != null) {
final String a = action;
if (document != null) {
final String n = dataName;
final PlainDocument d = document;
document.addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(final DocumentEvent e) {
textFieldUpdated(a, n, d);
}
@Override
public void insertUpdate(final DocumentEvent e) {
textFieldUpdated(a, n, d);
}
@Override
public void changedUpdate(final DocumentEvent e) {
textFieldUpdated(a, n, d);
}
});
}
if (buttonModel != null) {
final QuestionnaireModel qm;
if (question != null && choice != null) {
boolean isKey = false;
if ("yes".equalsIgnoreCase(key) || "true".equalsIgnoreCase(key)) {
isKey = true;
}
qm = new QuestionnaireModel(question, choice, isKey);
} else {
qm = null;
}
final DefaultButtonModel bm = buttonModel;
if (buttonModel instanceof JToggleButton.ToggleButtonModel) {
buttonModel.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (qm != null) {
// fire only one for questionnaires
if (e.getStateChange() == ItemEvent.SELECTED) {
buttonActionPerformed(a, qm, bm);
}
} else {
buttonActionPerformed(a, qm, bm);
}
}
});
} else {
buttonModel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
buttonActionPerformed(a, qm, bm);
}
});
}
}
}
}
}
}
Aggregations