use of javax.swing.text.Highlighter in project omegaide by omegaui.
the class ErrorHighlighter method loadErrors.
public void loadErrors(String errorLog) {
removeAllHighlights();
StringTokenizer tokenizer = new StringTokenizer(errorLog, "\n");
boolean canRecord = false;
String path = "";
String code = "";
int line = 0;
try {
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (token.contains(".java") && token.contains(":") && !canRecord) {
int e = token.indexOf(':');
if (Screen.onWindows())
e = token.indexOf(':', e + 1);
path = token.substring(0, e);
path = JavaSyntaxParser.convertToProjectPath(path);
line = Integer.parseInt(token.substring(e + 1, token.indexOf(':', e + 1)));
if (new File(path).exists())
canRecord = true;
} else if (canRecord) {
code = token.trim();
File file = new File(path);
Editor e = Screen.getProjectFile().getScreen().getTabPanel().findEditor(file);
if (e == null) {
e = Screen.getProjectFile().getScreen().loadFile(file);
}
Highlighter h = e.getHighlighter();
HighlightPainter hp = new DefaultHighlighter.DefaultHighlightPainter(color);
String text = e.getText();
int index = 0;
int times = 0;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '\n' && times < line - 1) {
index = i;
times++;
}
}
int start = text.indexOf(code, line == 1 ? 0 : index + 1);
int end = start + code.length();
h.addHighlight(start, end, hp);
highlights.add(new Highlight(e, hp, start, end, false));
canRecord = false;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.swing.text.Highlighter in project omegaide by omegaui.
the class KotlinErrorHighlighter method loadErrors.
/*
testDir/src/kode/Main.kt:5:17: error: unresolved reference: getTitle
println(screen.getTitle())
^
testDir/src/kode/Screen.kt:9:20: error: import must be placed on a single line
import javax.swing.
^
*/
@Override
public void loadErrors(String errorLog) {
removeAllHighlights();
StringTokenizer tokenizer = new StringTokenizer(errorLog, "\n");
boolean canRecord = false;
String path = "";
String code = "";
String message = "";
int line = 0;
try {
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (!canRecord && CodeFramework.count(token, ':') >= 4 && !token.startsWith(" ")) {
int index;
path = token.substring(0, index = token.indexOf(':')).trim();
path = Screen.getProjectFile().getArgumentManager().compileDir + File.separator + path;
line = Integer.parseInt(token.substring(index + 1, index = token.indexOf(':', index + 1)).trim());
index = token.indexOf(':', index + 1);
message = token.substring(index + 1).trim();
canRecord = true;
} else if (canRecord) {
code = token.trim();
if (!path.contains(File.separator)) {
path = Screen.getProjectFile().getArgumentManager().compileDir + File.separator + path;
}
File file = new File(path);
if (file.exists()) {
Editor e = Screen.getProjectFile().getScreen().loadFile(file);
try {
ImageIcon icon = new ImageIcon(IconManager.fluenterrorImage);
int size = e.getGraphics().getFontMetrics().getHeight();
icon = new ImageIcon(icon.getImage().getScaledInstance(size, size, Image.SCALE_SMOOTH));
gutterIconInfos.add(new JavaSyntaxParserGutterIconInfo(e.getAttachment().getGutter().addLineTrackingIcon(line - 1, icon, message), e));
} catch (Exception ex) {
ex.printStackTrace();
}
Highlighter h = e.getHighlighter();
SquiggleUnderlineHighlightPainter painter = new SquiggleUnderlineHighlightPainter(Color.RED);
String text = e.getText();
int index = 0;
int times = 0;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == '\n' && times < line - 1) {
index = i;
times++;
}
}
int start = text.indexOf(code, line == 1 ? 0 : index + 1);
int end = start + code.length();
h.addHighlight(start, end, painter);
highlights.add(new Highlight(e, painter, start, end, false));
}
canRecord = false;
}
}
} catch (Exception e) {
e.printStackTrace();
}
int count = 0;
for (Highlight h : highlights) {
count = 0;
for (Highlight hx : highlights) {
if (h.editor.equals(hx.editor))
count++;
}
h.editor.javaErrorPanel.setDiagnosticData(count, 0);
}
}
use of javax.swing.text.Highlighter in project omegaide by omegaui.
the class BuildLog method setView.
public void setView(Error errorSet) {
this.currentError = errorSet;
Editor editorX = Screen.getScreen().loadFile(new File(errorSet.filePath));
if (editorX != null)
editorX.grabFocus();
String fullLog = "File Path : " + errorSet.filePath + "\n";
fullLog += "At Line : " + errorSet.line + "\n\n";
fullLog += errorSet.log;
errorArea.setText(fullLog);
try {
// Highlighting
String text = errorArea.getText();
Highlighter h = errorArea.getHighlighter();
Color color = isDarkMode() ? omega.io.UIManager.TOOLMENU_COLOR2_SHADE : ErrorHighlighter.color;
// Highlighting File Path
h.addHighlight(text.indexOf(':') + 2, text.indexOf('\n'), new DefaultHighlighter.DefaultHighlightPainter(color));
// Highlighting Line Number
h.addHighlight(text.indexOf(':', text.indexOf('\n') + 1) + 2, text.indexOf('\n', text.indexOf('\n') + 1), new DefaultHighlighter.DefaultHighlightPainter(color));
// Highlighting Concluding Error
h.addHighlight(text.indexOf(':', text.indexOf('\n', text.indexOf('\n', text.indexOf('\n') + 1) + 1)) + 2, text.indexOf('\n', text.indexOf('\n', text.indexOf('\n', text.indexOf('\n', text.indexOf('\n') + 1) + 1) + 1)), new DefaultHighlighter.DefaultHighlightPainter(color));
new Thread(() -> {
Editor editor = Screen.getScreen().getTabPanel().findEditor(new File(errorSet.filePath));
if (editor != null) {
String textM = editor.getText();
int lineN = 0;
for (int i = 0; i < textM.length(); i++) {
char ch = textM.charAt(i);
if (ch == '\n')
lineN++;
if (lineN == errorSet.line) {
Screen.getScreen().getTabPanel().showTab(editor);
editor.setCaretPosition(i);
break;
}
}
}
}).start();
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.swing.text.Highlighter in project visualvm by oracle.
the class Markers method markText.
/**
* add highlights for the given region on the given pane
* @param pane
* @param start
* @param end
* @param marker
*/
public static void markText(JTextComponent pane, int start, int end, SimpleMarker marker) {
try {
Highlighter hiliter = pane.getHighlighter();
int selStart = pane.getSelectionStart();
int selEnd = pane.getSelectionEnd();
// if there is no selection or selection does not overlap
if (selStart == selEnd || end < selStart || start > selStart) {
hiliter.addHighlight(start, end, marker);
return;
}
// selection starts within the highlight, highlight before slection
if (selStart > start && selStart < end) {
hiliter.addHighlight(start, selStart, marker);
}
// selection ends within the highlight, highlight remaining
if (selEnd > start && selEnd < end) {
hiliter.addHighlight(selEnd, end, marker);
}
} catch (BadLocationException ex) {
// nothing we can do if the request is out of bound
LOG.log(Level.SEVERE, null, ex);
}
}
use of javax.swing.text.Highlighter in project visualvm by oracle.
the class Markers method removeMarkers.
/**
* Removes only our private highlights
* This is public so that we can remove the highlights when the editorKit
* is unregistered. SimpleMarker can be null, in which case all instances of
* our Markers are removed.
* @param component the text component whose markers are to be removed
* @param marker the SimpleMarker to remove
*/
public static void removeMarkers(JTextComponent component, SimpleMarker marker) {
Highlighter hilite = component.getHighlighter();
Highlighter.Highlight[] hilites = hilite.getHighlights();
for (int i = 0; i < hilites.length; i++) {
if (hilites[i].getPainter() instanceof SimpleMarker) {
SimpleMarker hMarker = (SimpleMarker) hilites[i].getPainter();
if (marker == null || hMarker.equals(marker)) {
hilite.removeHighlight(hilites[i]);
}
}
}
}
Aggregations