Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compiling, syntax highlighting with angry squiggles and GUI
- Loading branch information
Showing
38 changed files
with
1,823 additions
and
896 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: com.uddernetworks.mspaint.main.Main | ||
|
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/main/java/com/uddernetworks/mspaint/highlighter/AngrySquiggleHighlighter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.uddernetworks.mspaint.highlighter; | ||
|
||
import com.uddernetworks.mspaint.main.Letter; | ||
|
||
import javax.imageio.ImageIO; | ||
import javax.tools.Diagnostic; | ||
import javax.tools.JavaFileObject; | ||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class AngrySquiggleHighlighter { | ||
|
||
private BufferedImage image; | ||
private int extraSquigglePadding = 0; | ||
private BufferedImage squiggleImage; | ||
private File highlightedFile; | ||
private List<List<Letter>> grid; | ||
private List<Diagnostic<? extends JavaFileObject>> errors; | ||
|
||
public AngrySquiggleHighlighter(BufferedImage image, int extraSquigglePadding, File squiggleFile, File highlightedFile, List<List<Letter>> grid, List<Diagnostic<? extends JavaFileObject>> errors) throws IOException { | ||
this.image = image; | ||
this.extraSquigglePadding = extraSquigglePadding; | ||
this.squiggleImage = ImageIO.read(squiggleFile); | ||
this.highlightedFile = highlightedFile; | ||
this.grid = grid; | ||
this.errors = errors; | ||
} | ||
|
||
public void highlightAngrySquiggles() throws IOException { | ||
for (Diagnostic<? extends JavaFileObject> error : errors) { | ||
int lineNumber = Long.valueOf(error.getLineNumber()).intValue(); | ||
int columnNumber = Long.valueOf(error.getColumnNumber()).intValue(); | ||
|
||
int[] locs = getLineAndLength(lineNumber, columnNumber); | ||
int xIndex = locs[0]; | ||
int yIndex = locs[1]; | ||
int length = locs[2]; | ||
|
||
drawAngrySquiggle(xIndex, yIndex, length); | ||
} | ||
} | ||
|
||
private void drawAngrySquiggle(int squiggleX, int squiggleY, int length) throws IOException { | ||
for (int y = squiggleY; y < squiggleImage.getHeight() + squiggleY; y++) { | ||
for (int x = squiggleX; x < squiggleX + length; x++) { | ||
int squiggleImageX = (x - squiggleX) % squiggleImage.getWidth(); | ||
int squiggleImageY = y - squiggleY; | ||
|
||
Color imageColor = new Color(image.getRGB(x, y)); | ||
Color squiggleColor = new Color(squiggleImage.getRGB(squiggleImageX, squiggleImageY)); | ||
Color combinedAlpha = new Color(squiggleColor.getRed(), squiggleColor.getGreen(), squiggleColor.getBlue(), imageColor.getAlpha()); | ||
|
||
image.setRGB(x, y, combinedAlpha.getRGB()); | ||
} | ||
} | ||
|
||
ImageIO.write(image, "png", highlightedFile); | ||
} | ||
|
||
|
||
private int[] getLineAndLength(int lineNumber, int columnNumber) { | ||
int[] ret = new int[3]; // X index, Y index, length | ||
|
||
Letter startLetter = null; | ||
Letter lastLetter = null; | ||
int index = 0; | ||
for (Letter letter : grid.get(lineNumber - 1)) { | ||
if (letter == null) continue; | ||
index++; | ||
|
||
if (columnNumber != -1) { | ||
if (index == columnNumber) { | ||
ret[0] = letter.getX(); | ||
ret[1] = letter.getY() + 21; | ||
ret[2] = columnNumber; | ||
|
||
System.out.println("ret = " + Arrays.toString(ret)); | ||
break; | ||
} | ||
} | ||
|
||
if (startLetter == null) { | ||
if (!letter.getLetter().equals(" ")) startLetter = letter; | ||
} | ||
|
||
lastLetter = letter; | ||
} | ||
|
||
if (columnNumber == -1) { | ||
ret[0] = startLetter.getX(); | ||
ret[1] = startLetter.getY() + 21; | ||
ret[2] = lastLetter.getX() + lastLetter.getWidth() - startLetter.getX(); | ||
} else if (index != columnNumber) { | ||
ret[0] = lastLetter.getX() + 7; | ||
ret[1] = lastLetter.getY() + 21; | ||
ret[2] = 6; | ||
} | ||
|
||
ret[0] = ret[0] - extraSquigglePadding; | ||
ret[2] = ret[2] + extraSquigglePadding * 2; | ||
|
||
return ret; | ||
} | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/com/uddernetworks/mspaint/highlighter/CustomJavaRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.uddernetworks.mspaint.highlighter; | ||
|
||
import com.uwyn.jhighlight.highlighter.ExplicitStateHighlighter; | ||
import com.uwyn.jhighlight.highlighter.JavaHighlighter; | ||
import com.uwyn.jhighlight.tools.StringUtils; | ||
|
||
import java.io.*; | ||
import java.util.HashMap; | ||
|
||
public class CustomJavaRenderer { | ||
|
||
private String getCssClass(int style) { | ||
switch (style) { | ||
case 1: | ||
return "000,000,000,"; // plain | ||
case 2: | ||
return "000,000,000,"; // keyword | ||
case 3: | ||
return "000,044,221,"; // type | ||
case 4: | ||
return "000,124,031,"; // operator | ||
case 5: | ||
return "000,033,255,"; // separator | ||
case 6: | ||
return "188,000,000,"; // literal | ||
case 7: | ||
return "147,147,147,"; // comment | ||
case 8: | ||
return "147,147,147,"; // javadoc comment | ||
case 9: | ||
return "147,147,147,"; // javadoc tag | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
public String highlight(String text) throws IOException { | ||
ExplicitStateHighlighter highlighter = this.getHighlighter(); | ||
|
||
InputStream is = new ByteArrayInputStream(text.getBytes()); | ||
InputStreamReader isr = new InputStreamReader(is); | ||
BufferedReader r = new BufferedReader(isr); | ||
|
||
StringBuilder builder = new StringBuilder(); | ||
|
||
String line; | ||
char[] token; | ||
int length; | ||
int style; | ||
String css_class; | ||
while ((line = r.readLine()) != null) { | ||
line = StringUtils.convertTabsToSpaces(line, 4); | ||
|
||
Reader lineReader = new StringReader(line); | ||
highlighter.setReader(lineReader); | ||
int index = 0; | ||
while (index < line.length()) { | ||
style = highlighter.getNextToken(); | ||
length = highlighter.getTokenLength(); | ||
token = line.substring(index, index + length).toCharArray(); | ||
|
||
for (char ignored : token) { | ||
css_class = getCssClass(style); | ||
|
||
if (css_class != null) { | ||
builder.append(css_class); | ||
} | ||
} | ||
index += length; | ||
} | ||
|
||
builder.append("\n"); | ||
} | ||
|
||
return builder.toString(); | ||
} | ||
|
||
private ExplicitStateHighlighter getHighlighter() { | ||
JavaHighlighter highlighter = new JavaHighlighter(); | ||
JavaHighlighter.ASSERT_IS_KEYWORD = true; | ||
return highlighter; | ||
} | ||
} |
Oops, something went wrong.