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 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 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.SimpleAttributeSet in project litiengine by gurkenlabs.
the class ConsoleLogHandler method publish.
@Override
public void publish(final LogRecord record) {
StyledDocument doc = textPane.getStyledDocument();
SimpleAttributeSet keyWord = new SimpleAttributeSet();
StyleConstants.setForeground(keyWord, getColor(record.getLevel()));
StyleConstants.setBold(keyWord, true);
StyleConstants.setFontSize(keyWord, 12);
StyleConstants.setFontFamily(keyWord, CONSOLE_FONT);
SimpleAttributeSet text = new SimpleAttributeSet();
StyleConstants.setForeground(text, getColor(record.getLevel()));
StyleConstants.setFontFamily(text, CONSOLE_FONT);
try {
doc.insertString(doc.getLength(), String.format("%1$-10s", record.getLevel()), keyWord);
if (record.getParameters() != null) {
doc.insertString(doc.getLength(), MessageFormat.format(record.getMessage(), record.getParameters()), text);
} else {
doc.insertString(doc.getLength(), record.getMessage(), text);
}
doc.insertString(doc.getLength(), "\n", text);
} catch (BadLocationException e) {
}
textPane.setCaretPosition(doc.getLength());
}
use of javax.swing.text.SimpleAttributeSet in project org.alloytools.alloy by AlloyTools.
the class OurConsole method style.
/*
* Helper method that construct a mutable style with the given font name, font
* size, boldness, color, and left indentation.
*/
static MutableAttributeSet style(String fontName, int fontSize, boolean boldness, boolean italic, boolean strike, Color color, int leftIndent) {
MutableAttributeSet s = new SimpleAttributeSet();
StyleConstants.setFontFamily(s, fontName);
StyleConstants.setFontSize(s, fontSize);
StyleConstants.setLineSpacing(s, -0.2f);
StyleConstants.setBold(s, boldness);
StyleConstants.setItalic(s, italic);
StyleConstants.setForeground(s, color);
StyleConstants.setLeftIndent(s, leftIndent);
StyleConstants.setStrikeThrough(s, strike);
return s;
}
Aggregations