use of javax.swing.text.Element in project processdash by dtuma.
the class PersonLookupDialog method processUserInterfaceChanges.
private void processUserInterfaceChanges(HTMLDocument htmlDoc) {
// if we find a title in the HTML doc, use it as the title of the dialog
Object docTitle = htmlDoc.getProperty(HTMLDocument.TitleProperty);
if (docTitle != null)
dialog.setTitle(String.valueOf(docTitle));
// enlarge the dialog if necessary to fit the contents.
Dimension pref = html.getPreferredSize();
Dimension curr = scrollPane.getViewport().getSize();
Dimension d = dialog.getSize();
// First, test to see if the dialog needs to be taller. If so,
// enlarge it.
double yDelta = pref.getHeight() - curr.getHeight();
if (yDelta > 0) {
d.height = (int) Math.min(d.height + yDelta + 1, MAX_DIALOG_HEIGHT);
dialog.setSize(d);
dialog.validate();
// changing the dialog height could have caused a vertical
// scrollbar to appear or disappear. Just in case, get the new
// size of the viewport so the horizontal resizing logic can use it.
curr = scrollPane.getViewport().getSize();
}
// Now test to see if the dialog needs to be wider. If so, enlarge it.
double xDelta = pref.getWidth() - curr.getWidth();
if (xDelta > 0) {
d.width = (int) (d.width + xDelta + 4);
dialog.setSize(d);
dialog.validate();
}
// stays in the same location as before
if (yDelta > 0 || xDelta > 0) {
Point location = dialog.getLocation();
//
location.setLocation(Math.max(0, location.x - Math.max(0, xDelta / 2)), Math.max(0, location.y - Math.max(0, yDelta / 2)));
dialog.setLocation(location);
}
// scan the HTML document, and arrange for all text fields to perform
// a "select all" when they receive the focus. Also, arrange for all
// buttons to accept Enter as an activation key.
tweakInputFields(html);
// if one of the elements on the form has the ID "grabFocus," arrange
// for it to receive focus immediately.
Element e = htmlDoc.getElement("grabFocus");
JComponent c = findComponentForInputElement(e);
if (c != null)
new GrabFocus(c);
}
use of javax.swing.text.Element in project knime-core by knime.
the class AbstractRuleParser method parse.
/**
* {@inheritDoc}
*/
@Override
public ParseResult parse(final RSyntaxDocument doc, final String style) {
if (isNotApplicable(style)) {
return new DefaultParseResult(this);
}
DefaultParseResult res = new DefaultParseResult(this);
Element rootElement = doc.getDefaultRootElement();
boolean wasCatchAllRule = false;
for (int line = 0; line < rootElement.getElementCount(); ++line) {
String lastString = null;
StringBuilder sb = new StringBuilder();
// Go through the tokens
Token token = doc.getTokenListForLine(line);
while (token != null && token.isPaintable()) {
String lexeme = token.getLexeme();
// If it is an operator, make it a reserved word.
if (getOperators().contains(lexeme)) {
token.setType(TokenTypes.RESERVED_WORD);
token.setLanguageIndex(0);
}
sb.append(lexeme);
if (lexeme.length() > 0 && lexeme.charAt(0) == '"' && lexeme.charAt(lexeme.length() - 1) == '"') {
lastString = lexeme;
}
token = token.getNextToken();
}
try {
String lineText = sb.toString();
// Check for potential error in outcomes.
if (lineText.trim().endsWith("\"") && m_warnOnColRefsInStrings) {
String lastContent = lastString != null && lastString.length() > 2 ? lastString.substring(1, lastString.length() - 1) : lastString;
// ENH better check
if (lastContent != null && lastContent.endsWith("$") && lastContent.charAt(0) == '$') {
DefaultParserNotice notice = new DefaultParserNotice(this, "You might be referring to a column or flow variable, although no String " + "interpolation is implemented, you might want to " + "remove the quotes around the reference.", line, doc.getTokenListForLine(line).getOffset() + lineText.lastIndexOf(lastContent), lastContent.length());
notice.setLevel(ParserNotice.Level.WARNING);
res.addNotice(notice);
}
}
if (!lineText.isEmpty()) {
wasCatchAllRule |= parseAndWarn(doc, res, wasCatchAllRule, line, lineText);
}
} catch (ParseException e) {
DefaultParserNotice notice;
if (e.getErrorOffset() >= sb.length()) {
notice = new DefaultParserNotice(this, e.getMessage(), line);
} else {
notice = new DefaultParserNotice(this, e.getMessage(), line, doc.getTokenListForLine(line).getOffset() + e.getErrorOffset(), sb.length() - e.getErrorOffset());
}
res.addNotice(notice);
}
}
return res;
}
use of javax.swing.text.Element in project blue by kunstmusik.
the class BSBCompletionProvider method getRowFirstNonWhite.
static int getRowFirstNonWhite(StyledDocument doc, int offset) throws BadLocationException {
Element lineElement = doc.getParagraphElement(offset);
int start = lineElement.getStartOffset();
while (start + 1 < lineElement.getEndOffset()) {
try {
if (doc.getText(start, 1).charAt(0) != ' ') {
break;
}
} catch (BadLocationException ex) {
throw (BadLocationException) new BadLocationException("calling getText(" + start + ", " + (start + 1) + ") on doc of length: " + doc.getLength(), start).initCause(ex);
}
start++;
}
return start;
}
use of javax.swing.text.Element in project com.revolsys.open by revolsys.
the class TextPane method getLineStartOffset.
public int getLineStartOffset(final int line) {
if (line < 0) {
return -1;
} else {
final Element map = getDocument().getDefaultRootElement();
final Element lineElem = map.getElement(line);
if (lineElem == null) {
return -1;
} else {
return lineElem.getStartOffset();
}
}
}
use of javax.swing.text.Element in project mdw-designer by CenturyLinkCloud.
the class ExportHelper method printHtmlParagraphsPdf.
private void printHtmlParagraphsPdf(Section section, String content, int parentLevel) throws Exception {
if (content == null || content.length() == 0)
return;
String vContent = content;
if (isBase64Encoded(content) || "true".equals(System.getProperty("mdw.designer.force.msword"))) {
byte[] docBytes = decodeBase64(content);
vContent = new DocxBuilder(docBytes).toHtml();
vContent = vContent.replaceAll(" ", " ");
}
JEditorPane documentation = new JEditorPane();
documentation.setContentType("text/html");
documentation.setText(vContent);
javax.swing.text.Document swingdoc = documentation.getDocument();
Element[] elements = swingdoc.getRootElements();
for (Element e : elements) {
Object gen = generateElementHtml(e, 0, normalFont);
addSectionContentPdf(section, gen, parentLevel);
}
}
Aggregations