use of javax.swing.text.Element in project languagetool by languagetool-org.
the class ResultAreaHelper method setHeader.
private void setHeader(String txt) {
HTMLDocument d = (HTMLDocument) statusPane.getDocument();
Element e = d.getElement(HEADER);
try {
d.setInnerHTML(e, "<p class=\"grayed\">" + txt + "</p>");
} catch (BadLocationException ex) {
Tools.showError(ex);
} catch (IOException ex) {
Tools.showError(ex);
}
}
use of javax.swing.text.Element in project languagetool by languagetool-org.
the class ResultAreaHelper method setMain.
private void setMain(String html) {
HTMLDocument d = (HTMLDocument) statusPane.getDocument();
Element e = d.getElement(MAIN);
try {
d.setInnerHTML(e, html);
} catch (BadLocationException ex) {
Tools.showError(ex);
} catch (IOException ex) {
Tools.showError(ex);
}
}
use of javax.swing.text.Element in project sonarqube by SonarSource.
the class TextLineNumber method getOffsetY.
/*
* Determine the Y offset for the current row
*/
private int getOffsetY(int rowStartOffset, FontMetrics fontMetrics) throws BadLocationException {
// Get the bounding rectangle of the row
Rectangle r = component.modelToView(rowStartOffset);
int lineHeight = fontMetrics.getHeight();
int y = r.y + r.height;
int descent = 0;
if (// default font is being used
r.height == lineHeight) {
descent = fontMetrics.getDescent();
} else // We need to check all the attributes for font changes
{
if (fonts == null)
fonts = new HashMap<>();
Element root = component.getDocument().getDefaultRootElement();
int index = root.getElementIndex(rowStartOffset);
Element line = root.getElement(index);
for (int i = 0; i < line.getElementCount(); i++) {
Element child = line.getElement(i);
AttributeSet as = child.getAttributes();
String fontFamily = (String) as.getAttribute(StyleConstants.FontFamily);
Integer fontSize = (Integer) as.getAttribute(StyleConstants.FontSize);
String key = fontFamily + fontSize;
FontMetrics fm = fonts.get(key);
if (fm == null) {
Font font = new Font(fontFamily, Font.PLAIN, fontSize);
fm = component.getFontMetrics(font);
fonts.put(key, fm);
}
descent = Math.max(descent, fm.getDescent());
}
}
return y - descent;
}
use of javax.swing.text.Element in project sonarqube by SonarSource.
the class TextLineNumber method isCurrentLine.
/*
* We need to know if the caret is currently positioned on the line we
* are about to paint so the line number can be highlighted.
*/
private boolean isCurrentLine(int rowStartOffset) {
int caretPosition = component.getCaretPosition();
Element root = component.getDocument().getDefaultRootElement();
return root.getElementIndex(rowStartOffset) == root.getElementIndex(caretPosition);
}
use of javax.swing.text.Element in project sonarqube by SonarSource.
the class TextLineNumber method getTextLineNumber.
/*
* Get the line number to be drawn. The empty string will be returned
* when a line of text has wrapped.
*/
protected String getTextLineNumber(int rowStartOffset) {
Element root = component.getDocument().getDefaultRootElement();
int index = root.getElementIndex(rowStartOffset);
Element line = root.getElement(index);
if (line.getStartOffset() == rowStartOffset)
return String.valueOf(index + 1);
else
return "";
}
Aggregations