Skip to content

Commit

Permalink
Compiling, syntax highlighting with angry squiggles and GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
RubbaBoy committed Dec 11, 2017
1 parent d18db4b commit 14f7018
Show file tree
Hide file tree
Showing 38 changed files with 1,823 additions and 896 deletions.
Binary file modified LetterGridObject.txt
Binary file not shown.
3 changes: 3 additions & 0 deletions META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.uddernetworks.mspaint.main.Main

Binary file added images/compiler_output.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/input_highlighted.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/letter_input.png
Binary file not shown.
Binary file removed images/letter_input_contrast.png
Binary file not shown.
Binary file modified images/long_input.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/long_input_contrast.png
Binary file not shown.
Binary file added images/output.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/searching.png
Binary file not shown.
Binary file removed images/src/Main.png
Binary file not shown.
Binary file removed images/subInput.png
Binary file not shown.
137 changes: 81 additions & 56 deletions pom.xml
Expand Up @@ -7,6 +7,33 @@
<groupId>com.uddernetworks.mspaint</groupId>
<artifactId>MSPaintIDE</artifactId>
<version>1.0-SNAPSHOT</version>

<profiles>
<profile>
<id>windows_profile</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>osx_profile</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>
</profile>
</profiles>


<build>
<plugins>
<plugin>
Expand All @@ -17,6 +44,56 @@
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>com.uddernetworks.mspaint.main.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>junit:junit</artifact>
<includes>
<include>junit/framework/**</include>
<include>org/junit/**</include>
</includes>
<excludes>
<exclude>org/junit/experimental/**</exclude>
<exclude>org/junit/runners/**</exclude>
</excludes>
</filter>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand All @@ -27,66 +104,14 @@

<dependencies>


<!-- Tess4J -->
<!-- https://mvnrepository.com/artifact/com.intellij/forms_rt -->
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>3.2.1</version>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>7.0.3</version>
</dependency>

<!--<dependency>-->
<!--<groupId>com.google.apis</groupId>-->
<!--<artifactId>google-api-services-vision</artifactId>-->
<!--<version>v1-rev366-1.23.0</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.google.api-client</groupId>-->
<!--<artifactId>google-api-client</artifactId>-->
<!--<version>1.23.0</version>-->
<!--<exclusions>-->
<!--<exclusion> &lt;!&ndash; exclude an old version of Guava &ndash;&gt;-->
<!--<groupId>com.google.guava</groupId>-->
<!--<artifactId>guava-jdk5</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.google.guava</groupId>-->
<!--<artifactId>guava</artifactId>-->
<!--<version>20.0</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.apache.opennlp</groupId>-->
<!--<artifactId>opennlp-tools</artifactId>-->
<!--<version>1.8.3</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>redis.clients</groupId>-->
<!--<artifactId>jedis</artifactId>-->
<!--<version>2.9.0</version>-->
<!--</dependency>-->

<!--&lt;!&ndash; Test Dependencies &ndash;&gt;-->
<!--<dependency>-->
<!--<groupId>junit</groupId>-->
<!--<artifactId>junit</artifactId>-->
<!--<version>4.12</version>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.google.truth</groupId>-->
<!--<artifactId>truth</artifactId>-->
<!--<version>0.36</version>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
<!--<dependency>-->
<!--&lt;!&ndash; for checking HTTP response codes &ndash;&gt;-->
<!--<groupId>javax.servlet</groupId>-->
<!--<artifactId>javax.servlet-api</artifactId>-->
<!--<version>3.1.0</version>-->
<!--<scope>test</scope>-->
<!--</dependency>-->

<!-- JHighlight -->
<dependency>
Expand Down
@@ -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;
}

}
@@ -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;
}
}

0 comments on commit 14f7018

Please sign in to comment.