private void addStyledText(String text, Style style) { try { doc.insertString(doc.getLength(), text, style); } catch (BadLocationException ble) { ble.printStackTrace(); } }
private void initializeStyles() { errorStyle = doc.addStyle( "errorStyle", StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE)); errorStyleRed = doc.addStyle("errorStyleRed", errorStyle); StyleConstants.setForeground(errorStyleRed, Color.RED); errorStyleMono = doc.addStyle("errorStyleMono", errorStyle); StyleConstants.setFontFamily(errorStyleMono, "Monospaced"); }
@Override public void mouseClicked(MouseEvent me) { Element el = doc.getCharacterElement(viewToModel(me.getPoint())); if (el == null) return; AttributeSet as = el.getAttributes(); if (as.isDefined("ip")) { String ip = (String) as.getAttribute("ip"); ScriptException se = (ScriptException) as.getAttribute("exception"); Node node = net.getAtIP(ip); if (node == null) { Utility.displayError("Error", "Computer does not exist"); return; } String errorString = "--ERROR--\n" + "Error at line number " + se.getLineNumber() + " and column number " + se.getColumnNumber() + "\n" + se.getMessage(); new ScriptDialog( parentFrame, str -> { if (str != null) { node.setScript(str); } }, node.getScript(), errorString) .setVisible(true); } }
@Override public void mouseMoved(MouseEvent me) { Element el = doc.getCharacterElement(viewToModel(me.getPoint())); if (el == null) return; AttributeSet as = el.getAttributes(); if (as.isDefined("ip")) { setCursor(handCursor); } else { setCursor(defaultCursor); } }