use of javax.swing.text.MutableAttributeSet in project intellij-community by JetBrains.
the class PyPIPackageUtil method parsePyPIListFromWeb.
@NotNull
private static List<String> parsePyPIListFromWeb(@NotNull String url, boolean isSimpleIndex) throws IOException {
LOG.debug("Fetching index of all packages available on " + url);
return HttpRequests.request(url).userAgent(getUserAgent()).connect(request -> {
final List<String> packages = new ArrayList<>();
final Reader reader = request.getReader();
new ParserDelegator().parse(reader, new HTMLEditorKit.ParserCallback() {
boolean inTable = false;
HTML.Tag myTag;
@Override
public void handleStartTag(@NotNull HTML.Tag tag, @NotNull MutableAttributeSet set, int i) {
myTag = tag;
if (!isSimpleIndex) {
if ("table".equals(tag.toString())) {
inTable = !inTable;
}
if (inTable && "a".equals(tag.toString())) {
packages.add(String.valueOf(set.getAttribute(HTML.Attribute.HREF)));
}
}
}
@Override
public void handleText(@NotNull char[] data, int pos) {
if (isSimpleIndex) {
if (myTag != null && "a".equals(myTag.toString())) {
packages.add(String.valueOf(data));
}
}
}
@Override
public void handleEndTag(@NotNull HTML.Tag tag, int i) {
if (!isSimpleIndex) {
if ("table".equals(tag.toString())) {
inTable = !inTable;
}
}
}
}, true);
return packages;
});
}
use of javax.swing.text.MutableAttributeSet 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;
}
use of javax.swing.text.MutableAttributeSet in project org.alloytools.alloy by AlloyTools.
the class OurSyntaxDocument method do_setFont.
/**
* Changes the font and tabsize for the document.
*/
public final void do_setFont(String fontName, int fontSize, int tabSize) {
if (tabSize < 1)
tabSize = 1;
else if (tabSize > 100)
tabSize = 100;
if (fontName.equals(this.font) && fontSize == this.fontSize && tabSize == this.tabSize)
return;
this.font = fontName;
this.fontSize = fontSize;
this.tabSize = tabSize;
for (MutableAttributeSet s : all) {
StyleConstants.setFontFamily(s, fontName);
StyleConstants.setFontSize(s, fontSize);
}
do_reapplyAll();
// this
BufferedImage im = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
// is
// used
// to
// derive
// the
// tab
// width
int gap = tabSize * im.createGraphics().getFontMetrics(new Font(fontName, Font.PLAIN, fontSize)).charWidth('X');
TabStop[] pos = new TabStop[100];
for (int i = 0; i < 100; i++) {
pos[i] = new TabStop(i * gap + gap);
}
StyleConstants.setTabSet(tabset, new TabSet(pos));
setParagraphAttributes(0, getLength(), tabset, false);
}
use of javax.swing.text.MutableAttributeSet in project vcell by virtualcell.
the class MultiPurposeTextPanel method highlightComments.
private void highlightComments() {
String text = getTextPane().getText();
StyledDocument doc = (StyledDocument) getTextPane().getDocument();
MutableAttributeSet cstyle = getCommentStyle();
boolean inComment = false;
try (CountingLineReader reader = new CountingLineReader(new StringReader(text))) {
String line = reader.readLine();
while (line != null) {
if (!inComment) {
int cstart = line.indexOf(Commented.BEFORE_COMMENT);
if (cstart != NOT_THERE) {
inComment = parseAndMarkEndComment(doc, line, reader.lastStringPosition(), cstart);
}
int start = line.indexOf(Commented.AFTER_COMMENT);
if (start != NOT_THERE) {
int length = line.length() - start;
doc.setCharacterAttributes(reader.lastStringPosition() + start, length, cstyle, true);
}
} else {
// currently inside a /* */. comment
inComment = parseAndMarkEndComment(doc, line, reader.lastStringPosition(), 0);
}
line = reader.readLine();
}
} catch (IOException e) {
}
}
use of javax.swing.text.MutableAttributeSet in project omegat by omegat-org.
the class FontFallbackMarker method getAttributes.
private AttributeSet getAttributes(Font font) {
MutableAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setFontFamily(attrs, font.getFamily());
StyleConstants.setFontSize(attrs, editorFont.getSize());
return attrs;
}
Aggregations