use of javax.swing.text.SimpleAttributeSet in project pcgen by PCGen.
the class ExtendedHTMLEditorKit method insertListElement.
/**
* Insert a list element
* @param pane
* @param content
*/
public static void insertListElement(JTextPane pane, String content) {
int pos = pane.getCaretPosition();
ExtendedHTMLDocument htmlDoc = (ExtendedHTMLDocument) pane.getStyledDocument();
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);
Element element = getListItemParent(htmlDoc.getCharacterElement(pane.getCaretPosition()));
if (element == null) {
return;
}
SimpleAttributeSet sa = new SimpleAttributeSet(element.getAttributes());
sa.addAttribute("id", idString);
((ExtendedHTMLDocument) pane.getStyledDocument()).replaceAttributes(element, sa, HTML.Tag.LI);
source = pane.getText();
StringBuilder newHtmlString = new StringBuilder();
int[] positions = getPositions(element, source, true, idString);
newHtmlString.append(source.substring(0, positions[3]));
newHtmlString.append("<li>");
newHtmlString.append(content);
newHtmlString.append("</li>");
newHtmlString.append(source.substring(positions[3] + 1, source.length()));
pane.setText(newHtmlString.toString());
pane.setCaretPosition(pos - 1);
element = getListItemParent(htmlDoc.getCharacterElement(pane.getCaretPosition()));
sa = new SimpleAttributeSet(element.getAttributes());
sa = removeAttributeByKey(sa, "id");
((ExtendedHTMLDocument) pane.getStyledDocument()).replaceAttributes(element, sa, HTML.Tag.LI);
}
use of javax.swing.text.SimpleAttributeSet in project pcgen by PCGen.
the class ExtendedHTMLEditorKit method removeAttribute.
/**
* Remove arttribute
* @param sourceAS
* @param removeAS
* @return the attribute set
*/
private static SimpleAttributeSet removeAttribute(SimpleAttributeSet sourceAS, SimpleAttributeSet removeAS) {
try {
String[] sourceKeys = new String[sourceAS.getAttributeCount()];
String[] sourceValues = new String[sourceAS.getAttributeCount()];
Enumeration<?> sourceEn = sourceAS.getAttributeNames();
int i = 0;
while (sourceEn.hasMoreElements()) {
Object temp;
temp = sourceEn.nextElement();
sourceKeys[i] = temp.toString();
sourceValues[i] = "";
sourceValues[i] = sourceAS.getAttribute(temp).toString();
i++;
}
String[] removeKeys = new String[removeAS.getAttributeCount()];
String[] removeValues = new String[removeAS.getAttributeCount()];
Enumeration<?> removeEn = removeAS.getAttributeNames();
int j = 0;
while (removeEn.hasMoreElements()) {
removeKeys[j] = removeEn.nextElement().toString();
removeValues[j] = removeAS.getAttribute(removeKeys[j]).toString();
j++;
}
SimpleAttributeSet result = new SimpleAttributeSet();
for (int countSource = 0; countSource < sourceKeys.length; countSource++) {
boolean hit = false;
if ("name".equals(sourceKeys[countSource]) || "resolver".equals(sourceKeys[countSource])) {
hit = true;
} else {
for (int countRemove = 0; countRemove < removeKeys.length; countRemove++) {
if (!"NULL".equals(removeKeys[countRemove])) {
if (sourceKeys[countSource].equals(removeKeys[countRemove])) {
if (!"NULL".equals(removeValues[countRemove])) {
if (sourceValues[countSource].equals(removeValues[countRemove])) {
hit = true;
}
} else if ("NULL".equals(removeValues[countRemove])) {
hit = true;
}
}
} else if ("NULL".equals(removeKeys[countRemove]) && sourceValues[countSource].equals(removeValues[countRemove])) {
hit = true;
}
}
}
if (!hit) {
result.addAttribute(sourceKeys[countSource], sourceValues[countSource]);
}
}
return result;
} catch (ClassCastException cce) {
return null;
}
}
use of javax.swing.text.SimpleAttributeSet in project pcgen by PCGen.
the class ExtendedHTMLEditorKit method removeAttributeByKey.
/**
* Remove attribute by key
* @param sourceAS
* @param removeKey
* @return attribute set
*/
private static SimpleAttributeSet removeAttributeByKey(SimpleAttributeSet sourceAS, String removeKey) {
SimpleAttributeSet temp = new SimpleAttributeSet();
temp.addAttribute(removeKey, "NULL");
return removeAttribute(sourceAS, temp);
}
use of javax.swing.text.SimpleAttributeSet in project camel by apache.
the class JavadocParser method startTag.
@Override
protected void startTag(TagElement tag) throws ChangedCharSetException {
super.startTag(tag);
final HTML.Tag htmlTag = tag.getHTMLTag();
if (htmlTag != null) {
if (HTML.Tag.A.equals(htmlTag)) {
final SimpleAttributeSet attributes = getAttributes();
final Object name = attributes.getAttribute(HTML.Attribute.NAME);
if (name != null) {
final String nameAttr = (String) name;
if (parserState == ParserState.INIT && ("method_summary".equals(nameAttr) || "method.summary".equals(nameAttr))) {
parserState = ParserState.METHOD_SUMMARY;
} else if (parserState == ParserState.METHOD) {
if (methodWithTypes == null) {
final String hrefAttr = (String) attributes.getAttribute(HTML.Attribute.HREF);
if (hrefAttr != null && hrefAttr.contains(hrefPattern)) {
// unescape HTML
String methodSignature = hrefAttr.substring(hrefAttr.indexOf('#') + 1);
final int firstHyphen = methodSignature.indexOf('-');
if (firstHyphen != -1) {
final int lastHyphen = methodSignature.lastIndexOf('-');
methodSignature = methodSignature.substring(0, firstHyphen) + "(" + methodSignature.substring(firstHyphen + 1, lastHyphen) + ")";
methodSignature = methodSignature.replaceAll("-", ",");
}
// support varargs
if (methodSignature.contains("...)")) {
methodSignature = methodSignature.replaceAll("\\.\\.\\.\\)", "[])");
}
// map Java8 array types
if (methodSignature.contains(":A")) {
methodSignature = methodSignature.replaceAll(":A", "[]");
}
methodWithTypes = unescapeHtml(methodSignature);
}
} else {
final String title = (String) attributes.getAttribute(HTML.Attribute.TITLE);
if (title != null) {
// append package name to type name text
methodTextBuilder.append(title.substring(title.lastIndexOf(' '))).append('.');
}
}
}
}
} else if (parserState == ParserState.METHOD_SUMMARY && HTML.Tag.CODE.equals(htmlTag)) {
parserState = ParserState.METHOD;
}
}
}
use of javax.swing.text.SimpleAttributeSet in project JMRI by JMRI.
the class JTextPaneAppender method createAttributes.
private void createAttributes() {
String[] prio = new String[6];
prio[0] = Level.FATAL.toString();
prio[1] = Level.ERROR.toString();
prio[2] = Level.WARN.toString();
prio[3] = Level.INFO.toString();
prio[4] = Level.DEBUG.toString();
prio[5] = Level.TRACE.toString();
myAttributeSet = new Hashtable<String, MutableAttributeSet>();
for (int i = 0; i < prio.length; i++) {
MutableAttributeSet att = new SimpleAttributeSet();
myAttributeSet.put(prio[i], att);
StyleConstants.setFontSize(att, 14);
}
StyleConstants.setForeground(myAttributeSet.get(Level.FATAL.toString()), Color.red);
StyleConstants.setForeground(myAttributeSet.get(Level.ERROR.toString()), Color.red);
StyleConstants.setForeground(myAttributeSet.get(Level.WARN.toString()), Color.orange);
StyleConstants.setForeground(myAttributeSet.get(Level.INFO.toString()), Color.black);
StyleConstants.setForeground(myAttributeSet.get(Level.DEBUG.toString()), Color.black);
StyleConstants.setForeground(myAttributeSet.get(Level.TRACE.toString()), Color.black);
}
Aggregations