use of javax.swing.text.SimpleAttributeSet in project jdk8u_jdk by JetBrains.
the class DocumentParser method handleStartTag.
/**
* Handle Start Tag.
*/
protected void handleStartTag(TagElement tag) {
Element elem = tag.getElement();
if (elem == dtd.body) {
inbody++;
} else if (elem == dtd.html) {
} else if (elem == dtd.head) {
inhead++;
} else if (elem == dtd.title) {
intitle++;
} else if (elem == dtd.style) {
instyle++;
} else if (elem == dtd.script) {
inscript++;
}
if (debugFlag) {
if (tag.fictional()) {
debug("Start Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Start Tag: " + tag.getHTMLTag() + " attributes: " + getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED, Boolean.TRUE);
callback.handleStartTag(tag.getHTMLTag(), attrs, getBlockStartPosition());
} else {
callback.handleStartTag(tag.getHTMLTag(), getAttributes(), getBlockStartPosition());
flushAttributes();
}
}
use of javax.swing.text.SimpleAttributeSet in project pcgen by PCGen.
the class ExtendedHTMLEditorKit method removeTag.
/**
* Remove a tag
* @param pane
* @param element
* @param closingTag
*/
public static void removeTag(JTextPane pane, Element element, boolean closingTag) {
if (element == null) {
return;
}
HTML.Tag tag = getHTMLTag(element);
// Versieht den Tag mit einer einmaligen ID
String source = pane.getText();
boolean hit;
String idString;
int counter = 0;
do {
hit = false;
idString = "diesisteineidzumsuchenimsource" + counter;
if (source.contains(idString)) {
counter++;
hit = true;
if (counter > 10000) {
return;
}
}
} while (hit);
SimpleAttributeSet sa = new SimpleAttributeSet(element.getAttributes());
sa.addAttribute("id", idString);
((ExtendedHTMLDocument) pane.getStyledDocument()).replaceAttributes(element, sa, tag);
source = pane.getText();
StringBuilder newHtmlString = new StringBuilder();
int[] position = getPositions(element, source, closingTag, idString);
if (position == null) {
return;
}
for (final int aPosition : position) {
if (aPosition < 0) {
return;
}
}
int beginStartTag = position[0];
int endStartTag = position[1];
if (closingTag) {
int beginEndTag = position[2];
int endEndTag = position[3];
newHtmlString.append(source.substring(0, beginStartTag));
newHtmlString.append(source.substring(endStartTag, beginEndTag));
newHtmlString.append(source.substring(endEndTag, source.length()));
} else {
newHtmlString.append(source.substring(0, beginStartTag));
newHtmlString.append(source.substring(endStartTag, source.length()));
}
pane.setText(newHtmlString.toString());
}
use of javax.swing.text.SimpleAttributeSet 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();
}
Aggregations