Added file loading and displaying of images in tabs
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
@@ -0,0 +1 @@
|
|||||||
|
Raw
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
DFA
|
||||||
B0
|
B0
|
||||||
E1
|
E1
|
||||||
0>a>1
|
0>a>1
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
DFA
|
||||||
|
B0
|
||||||
|
E4,2
|
||||||
|
0>a>1
|
||||||
|
0>b>2
|
||||||
|
1>a>0
|
||||||
|
1>b>2
|
||||||
|
2>a>3
|
||||||
|
2>b>4
|
||||||
|
3>a>0
|
||||||
|
3>b>2
|
||||||
|
4>a>1
|
||||||
|
4>b>0
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
NDFA
|
||||||
B0
|
B0
|
||||||
E1
|
E1
|
||||||
0>a>1
|
0>a>1
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
REGEX
|
||||||
|
(a|b)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
Tabs voor openstaande grafieken, met manier om te sluiten ofzo
|
||||||
|
File selector voor dot files
|
||||||
|
Error message
|
||||||
|
loading bar
|
||||||
|
regex input
|
||||||
|
exporteren van plaatje
|
||||||
|
exporteren van raw data
|
||||||
@@ -8,7 +8,7 @@ import java.util.TreeSet;
|
|||||||
/**
|
/**
|
||||||
* Created by imegumii on 18/04/2017.
|
* Created by imegumii on 18/04/2017.
|
||||||
*/
|
*/
|
||||||
public class Automata <T extends Comparable> {
|
public class Automata <T extends Comparable> extends Importable {
|
||||||
|
|
||||||
protected Set<Transition<T>> transistions;
|
protected Set<Transition<T>> transistions;
|
||||||
|
|
||||||
@@ -23,6 +23,7 @@ public class Automata <T extends Comparable> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Automata(SortedSet<Character> symbols) {
|
public Automata(SortedSet<Character> symbols) {
|
||||||
|
super(Type.ERROR);
|
||||||
states = new TreeSet<T>();
|
states = new TreeSet<T>();
|
||||||
beginStates = new TreeSet<T>();
|
beginStates = new TreeSet<T>();
|
||||||
eindStates = new TreeSet<T>();
|
eindStates = new TreeSet<T>();
|
||||||
@@ -50,7 +51,17 @@ public class Automata <T extends Comparable> {
|
|||||||
|
|
||||||
public void printTransitions () {
|
public void printTransitions () {
|
||||||
transistions.forEach(System.out::println);
|
transistions.forEach(System.out::println);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTransitions()
|
||||||
|
{
|
||||||
|
String s = "";
|
||||||
|
for(Transition t : transistions)
|
||||||
|
{
|
||||||
|
s += t.toString() + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void print() {
|
public void print() {
|
||||||
|
|||||||
@@ -12,10 +12,12 @@ public class DFA<T extends Comparable> extends Automata<T> {
|
|||||||
|
|
||||||
public DFA(Character[] symbols) {
|
public DFA(Character[] symbols) {
|
||||||
super(symbols);
|
super(symbols);
|
||||||
|
this.type = Type.DFA;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DFA(SortedSet<Character> symbols) {
|
public DFA(SortedSet<Character> symbols) {
|
||||||
super(symbols);
|
super(symbols);
|
||||||
|
this.type = Type.DFA;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean accepteer(String s) {
|
public boolean accepteer(String s) {
|
||||||
|
|||||||
@@ -1,101 +1,108 @@
|
|||||||
package com.imegumii;
|
package com.imegumii;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.Buffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by kenny on 8-6-2017.
|
* Created by kenny on 8-6-2017.
|
||||||
*/
|
*/
|
||||||
public class FileParser {
|
public class FileParser {
|
||||||
|
|
||||||
public static DFA<String> readDFA(String filename)
|
public static Importable read(String filename)
|
||||||
{
|
{
|
||||||
File f = new File("input/" + filename + ".dot");
|
File f = new File("input/" + filename);
|
||||||
|
|
||||||
Character[] chars = {'a', 'b'};
|
Importable imp = null;
|
||||||
DFA<String> dfa = new DFA<String>(chars);
|
|
||||||
|
|
||||||
try (BufferedReader br = new BufferedReader(new FileReader(f))) {
|
try (BufferedReader br = new BufferedReader(new FileReader(f))) {
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null) {
|
|
||||||
if(line.startsWith("B")) {
|
|
||||||
String[] states = line.substring(1,line.length()).split(",");
|
|
||||||
for(String s : states) { dfa.defineAsStartState(s); }
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(line.startsWith("E")) {
|
String type = br.readLine();
|
||||||
String[] states = line.substring(1,line.length()).split(",");
|
|
||||||
for(String s : states) { dfa.defineAsEndState(s); }
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
switch (type)
|
||||||
String[] trans = line.split(">");
|
{
|
||||||
dfa.addTransition(new Transition<String>(trans[0], trans[1].toCharArray()[0], trans[2]));
|
case "DFA":
|
||||||
}
|
imp = readDFA(br);
|
||||||
|
break;
|
||||||
|
case "NDFA":
|
||||||
|
imp = readNDFA(br);
|
||||||
|
break;
|
||||||
|
case "REGEX":
|
||||||
|
imp = readRegex(br);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return imp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DFA<String> readDFA(BufferedReader br) throws IOException {
|
||||||
|
|
||||||
|
Character[] chars = {'a', 'b'};
|
||||||
|
DFA<String> dfa = new DFA<String>(chars);
|
||||||
|
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
if(line.startsWith("B")) {
|
||||||
|
String[] states = line.substring(1,line.length()).split(",");
|
||||||
|
for(String s : states) { dfa.defineAsStartState(s); }
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(line.startsWith("E")) {
|
||||||
|
String[] states = line.substring(1,line.length()).split(",");
|
||||||
|
for(String s : states) { dfa.defineAsEndState(s); }
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
String[] trans = line.split(">");
|
||||||
|
dfa.addTransition(new Transition<String>(trans[0], trans[1].toCharArray()[0], trans[2]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return dfa;
|
return dfa;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NDFA<String> readNDFA(String filename)
|
public static NDFA<String> readNDFA(BufferedReader br) throws IOException {
|
||||||
{
|
|
||||||
File f = new File("input/" + filename + ".dot");
|
|
||||||
|
|
||||||
Character[] chars = {'a', 'b'};
|
Character[] chars = {'a', 'b'};
|
||||||
NDFA<String> ndfa = new NDFA<String>(chars);
|
NDFA<String> ndfa = new NDFA<String>(chars);
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
if(line.startsWith("B")) {
|
||||||
|
String[] states = line.substring(1,line.length()).split(",");
|
||||||
|
for(String s : states) { ndfa.defineAsStartState(s); }
|
||||||
|
}
|
||||||
|
|
||||||
try (BufferedReader br = new BufferedReader(new FileReader(f))) {
|
else if(line.startsWith("E")) {
|
||||||
String line;
|
String[] states = line.substring(1,line.length()).split(",");
|
||||||
while ((line = br.readLine()) != null) {
|
for(String s : states) { ndfa.defineAsEndState(s); }
|
||||||
if(line.startsWith("B")) {
|
}
|
||||||
String[] states = line.substring(1,line.length()).split(",");
|
|
||||||
for(String s : states) { ndfa.defineAsStartState(s); }
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(line.startsWith("E")) {
|
|
||||||
String[] states = line.substring(1,line.length()).split(",");
|
|
||||||
for(String s : states) { ndfa.defineAsEndState(s); }
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
else {
|
||||||
String[] trans = line.split(">");
|
String[] trans = line.split(">");
|
||||||
|
|
||||||
if(trans[1].equals("$")) {
|
if(trans[1].equals("$")) {
|
||||||
ndfa.addTransition(new Transition<String>(trans[0], Transition.EPSILON, trans[2]));
|
ndfa.addTransition(new Transition<String>(trans[0], Transition.EPSILON, trans[2]));
|
||||||
}
|
|
||||||
else
|
|
||||||
ndfa.addTransition(new Transition<String>(trans[0], trans[1].toCharArray()[0], trans[2]));
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
ndfa.addTransition(new Transition<String>(trans[0], trans[1].toCharArray()[0], trans[2]));
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ndfa;
|
return ndfa;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RegExp readRegex(String filename)
|
public static RegExp readRegex(BufferedReader br) throws IOException {
|
||||||
{
|
|
||||||
File f = new File("input/" + filename + ".dot");
|
|
||||||
|
|
||||||
BufferedReader br = null;
|
|
||||||
String line = "Error";
|
String line = "Error";
|
||||||
try {
|
line = br.readLine();
|
||||||
br = new BufferedReader(new FileReader(f));
|
|
||||||
line = br.readLine();
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
RegExp regex = new RegExp("a"); //RegExp.parse(line);
|
RegExp regex = new RegExp("a").of(new RegExp("b").ster()); //RegExp.parse(line);
|
||||||
|
|
||||||
return regex;
|
return regex;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class Graph {
|
|||||||
|
|
||||||
|
|
||||||
if(a.eindStates.size() > 0) {
|
if(a.eindStates.size() > 0) {
|
||||||
text += "node [shape = doublecircle];";
|
text += "node [shape=cirlce, peripheries=2];";
|
||||||
|
|
||||||
for (String s : a.eindStates) {
|
for (String s : a.eindStates) {
|
||||||
text += "\"" + s + "\" ";
|
text += "\"" + s + "\" ";
|
||||||
@@ -58,11 +58,45 @@ public class Graph {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String generateImageString(Automata<String> a)
|
||||||
|
{
|
||||||
|
String text = "digraph {\nrankdir=LR;\n";
|
||||||
|
|
||||||
|
if(a.eindStates.size() > 0) {
|
||||||
|
for (String s : a.eindStates) {
|
||||||
|
text += "\"" + s + "\" [peripheries=2]\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(a.beginStates.size() > 0) {
|
||||||
|
text += "\nstart [shape = point];\n";
|
||||||
|
|
||||||
|
for (String s : a.beginStates) {
|
||||||
|
text += "\"start\" -> \"" + s + "\" [label = \" \", color=aquamarine4];";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Transition<String> t : a.transistions)
|
||||||
|
{
|
||||||
|
String s = "";
|
||||||
|
if(t.symbol == Transition.EPSILON)
|
||||||
|
s = "$";
|
||||||
|
else
|
||||||
|
s = t.symbol + "";
|
||||||
|
|
||||||
|
text += "\"" + t.vanState + "\" -> \"" + t.naarState + "\" [ label = \"" + s + "\"];\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
text += "}";
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
public static void generateImage(Automata<String> a, String fileName) {
|
public static void generateImage(Automata<String> a, String fileName) {
|
||||||
try {
|
try {
|
||||||
File f = new File("images/" + a.hashCode() + ".dot");
|
File f = new File("images/" + a.hashCode() + ".dot");
|
||||||
PrintWriter w = new PrintWriter(f);
|
PrintWriter w = new PrintWriter(f);
|
||||||
w.print(Graph.generateGraphString(a));
|
w.print(Graph.generateImageString(a));
|
||||||
w.flush();
|
w.flush();
|
||||||
w.close();
|
w.close();
|
||||||
MutableGraph g = Parser.read(f);
|
MutableGraph g = Parser.read(f);
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.imegumii;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by kenny on 9-6-2017.
|
||||||
|
*/
|
||||||
|
public class Importable {
|
||||||
|
public static enum Type {DFA, NDFA, REGEX, ERROR};
|
||||||
|
|
||||||
|
public Type type;
|
||||||
|
|
||||||
|
public Importable(Type t)
|
||||||
|
{
|
||||||
|
this.type = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,10 +8,12 @@ import java.util.*;
|
|||||||
public class NDFA<T extends Comparable> extends Automata<T> {
|
public class NDFA<T extends Comparable> extends Automata<T> {
|
||||||
public NDFA(Character[] symbols) {
|
public NDFA(Character[] symbols) {
|
||||||
super(symbols);
|
super(symbols);
|
||||||
|
this.type = Type.NDFA;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NDFA(SortedSet<Character> symbols) {
|
public NDFA(SortedSet<Character> symbols) {
|
||||||
super(symbols);
|
super(symbols);
|
||||||
|
this.type = Type.NDFA;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SortedSet<T> statesBereikbaarVanaf(T vanaf, char s) {
|
public SortedSet<T> statesBereikbaarVanaf(T vanaf, char s) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.util.TreeSet;
|
|||||||
/**
|
/**
|
||||||
* Created by kenny on 2-5-2017.
|
* Created by kenny on 2-5-2017.
|
||||||
*/
|
*/
|
||||||
public class RegExp {
|
public class RegExp extends Importable{
|
||||||
|
|
||||||
public enum Operator { PLUS, STER, OF, PUNT, EEN}
|
public enum Operator { PLUS, STER, OF, PUNT, EEN}
|
||||||
|
|
||||||
@@ -27,6 +27,7 @@ public class RegExp {
|
|||||||
|
|
||||||
public RegExp()
|
public RegExp()
|
||||||
{
|
{
|
||||||
|
super(Type.REGEX);
|
||||||
operator = Operator.EEN;
|
operator = Operator.EEN;
|
||||||
characters = "";
|
characters = "";
|
||||||
links = null;
|
links = null;
|
||||||
@@ -34,6 +35,7 @@ public class RegExp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RegExp(String chars){
|
public RegExp(String chars){
|
||||||
|
super(Type.REGEX);
|
||||||
operator = Operator.EEN;
|
operator = Operator.EEN;
|
||||||
characters = chars;
|
characters = chars;
|
||||||
links = null;
|
links = null;
|
||||||
|
|||||||
+10
-15
@@ -20,9 +20,9 @@ public class Test {
|
|||||||
|
|
||||||
// Hopcroft();
|
// Hopcroft();
|
||||||
|
|
||||||
// TupleConstructie();
|
TupleConstructie();
|
||||||
|
|
||||||
FileReadTest();
|
// FileReadTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void P1Opdracht1(TreeSet<String> stringsToParse) {
|
public static void P1Opdracht1(TreeSet<String> stringsToParse) {
|
||||||
@@ -374,7 +374,8 @@ public class Test {
|
|||||||
aut1.defineAsEndState("1");
|
aut1.defineAsEndState("1");
|
||||||
|
|
||||||
System.out.println("\n\nA1\n--------");
|
System.out.println("\n\nA1\n--------");
|
||||||
System.out.println(Graph.generateGraphString(aut1));
|
System.out.println(Graph.generateImageString(aut1));
|
||||||
|
Graph.generateImage(aut1, "automaat1");
|
||||||
|
|
||||||
|
|
||||||
DFA<String> aut2 = new DFA<String>(characters);
|
DFA<String> aut2 = new DFA<String>(characters);
|
||||||
@@ -396,25 +397,19 @@ public class Test {
|
|||||||
aut2.defineAsEndState("2");
|
aut2.defineAsEndState("2");
|
||||||
|
|
||||||
System.out.println("\n\nA2\n--------");
|
System.out.println("\n\nA2\n--------");
|
||||||
System.out.println(Graph.generateGraphString(aut2));
|
System.out.println(Graph.generateImageString(aut2));
|
||||||
|
Graph.generateImage(aut2, "automaat2");
|
||||||
|
|
||||||
DFA<String> en = aut1.en(aut2);
|
DFA<String> en = aut1.en(aut2);
|
||||||
|
|
||||||
System.out.println("\n\nEN\n--------");
|
System.out.println("\n\nEN\n--------");
|
||||||
System.out.println(Graph.generateGraphString(en));
|
System.out.println(Graph.generateImageString(en));
|
||||||
|
Graph.generateImage(en, "en");
|
||||||
|
|
||||||
DFA<String> of = aut1.of(aut2);
|
DFA<String> of = aut1.of(aut2);
|
||||||
|
|
||||||
System.out.println("\n\nOF\n--------");
|
System.out.println("\n\nOF\n--------");
|
||||||
System.out.println(Graph.generateGraphString(of));
|
System.out.println(Graph.generateImageString(of));
|
||||||
}
|
Graph.generateImage(of, "of");
|
||||||
|
|
||||||
public static void FileReadTest()
|
|
||||||
{
|
|
||||||
DFA<String> dfa1 = FileParser.readDFA("dfa1");
|
|
||||||
System.out.println(Graph.generateGraphString(dfa1));
|
|
||||||
|
|
||||||
NDFA<String> ndfa1 = FileParser.readNDFA("ndfa1");
|
|
||||||
System.out.println(Graph.generateGraphString(ndfa1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ public class Frame extends JFrame {
|
|||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
JPanel container = new JPanel(new BorderLayout());
|
JPanel container = new JPanel(new BorderLayout());
|
||||||
container.add(ImagePanel.Instance(), BorderLayout.CENTER);
|
container.add(TabPanel.Instance(), BorderLayout.CENTER);
|
||||||
container.add(RegexPanel.Instance(), BorderLayout.NORTH);
|
container.add(InputPanel.Instance(), BorderLayout.NORTH);
|
||||||
|
container.add(StatusPanel.Instance(), BorderLayout.SOUTH);
|
||||||
|
|
||||||
this.setContentPane(container);
|
this.setContentPane(container);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.imegumii.ui;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by kenny on 9-6-2017.
|
||||||
|
*/
|
||||||
|
public class GraphImagePanel extends JPanel {
|
||||||
|
|
||||||
|
private BufferedImage image;
|
||||||
|
|
||||||
|
public GraphImagePanel(File f)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.setBackground(Color.WHITE);
|
||||||
|
|
||||||
|
try {
|
||||||
|
image = ImageIO.read(f);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paintComponent(Graphics g){
|
||||||
|
super.paintComponent(g);
|
||||||
|
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
|
||||||
|
g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC));
|
||||||
|
|
||||||
|
if(image != null){
|
||||||
|
|
||||||
|
int width = this.getWidth();
|
||||||
|
int height = this.getHeight();
|
||||||
|
|
||||||
|
if(image.getWidth() > image.getHeight()) {
|
||||||
|
height = (int)((width * image.getHeight()) / image.getWidth());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
width = (int) ((height * image.getWidth()) / image.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
g2d.drawImage(image, 0,50, width, height, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package com.imegumii.ui;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.Border;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by kenny on 8-6-2017.
|
||||||
|
*/
|
||||||
|
public class GraphPanel extends JPanel {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private File imageLocation;
|
||||||
|
private String export;
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GraphPanel(String name, File f, String export)
|
||||||
|
{
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
this.name = name;
|
||||||
|
this.imageLocation = f;
|
||||||
|
this.export = export;
|
||||||
|
|
||||||
|
this.add(new GraphImagePanel(imageLocation), BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JPanel buttonPanel = new JPanel();
|
||||||
|
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
|
||||||
|
buttonPanel.setBackground(Color.WHITE);
|
||||||
|
buttonPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.BLACK), BorderFactory.createEmptyBorder(10, 10, 10, 10)));
|
||||||
|
|
||||||
|
JButton closeTab = new JButton("Close");
|
||||||
|
closeTab.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
TabPanel.Instance().remove(GraphPanel.this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JButton exportData = new JButton("Export raw data");
|
||||||
|
exportData.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
String filename = "raw." + name.toLowerCase() + ".dot";
|
||||||
|
File file = new File("export/" + filename);
|
||||||
|
|
||||||
|
if(file.exists()){
|
||||||
|
int reply = JOptionPane.showConfirmDialog(null, "The file " + filename + "already exists. Do you want to overwrite it?", "File exists", JOptionPane.YES_NO_OPTION);
|
||||||
|
if (reply != JOptionPane.YES_OPTION) {
|
||||||
|
StatusPanel.Instance().setStatus("Cancelled export");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintWriter w = null;
|
||||||
|
try {
|
||||||
|
w = new PrintWriter(file);
|
||||||
|
w.print(export);
|
||||||
|
w.flush();
|
||||||
|
w.close();
|
||||||
|
StatusPanel.Instance().setStatus("Success: " + filename);
|
||||||
|
} catch (FileNotFoundException e1) {
|
||||||
|
StatusPanel.Instance().setStatus("Something went wrong while exporting the file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JButton exportImage = new JButton("Export image");
|
||||||
|
exportImage.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
|
String filename = "img." + name.toLowerCase() + ".png";
|
||||||
|
File file = new File("export/" + filename);
|
||||||
|
|
||||||
|
if(file.exists()){
|
||||||
|
int reply = JOptionPane.showConfirmDialog(null, "The file " + filename + "already exists. Do you want to overwrite it?", "File exists", JOptionPane.YES_NO_OPTION);
|
||||||
|
if (reply != JOptionPane.YES_OPTION) {
|
||||||
|
StatusPanel.Instance().setStatus("Cancelled export");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileUtils.copyFile(f, file);
|
||||||
|
StatusPanel.Instance().setStatus("Success: " + filename);
|
||||||
|
} catch (IOException e1) {
|
||||||
|
StatusPanel.Instance().setStatus("Something went wrong while exporting the file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonPanel.add(Box.createHorizontalGlue());
|
||||||
|
buttonPanel.add(exportImage);
|
||||||
|
buttonPanel.add(Box.createRigidArea(new Dimension(10,0)));
|
||||||
|
buttonPanel.add(exportData);
|
||||||
|
buttonPanel.add(Box.createRigidArea(new Dimension(10,0)));
|
||||||
|
buttonPanel.add(closeTab);
|
||||||
|
|
||||||
|
this.add(buttonPanel, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package com.imegumii.ui;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.io.*;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by kenny on 8-6-2017.
|
|
||||||
*/
|
|
||||||
public class ImagePanel extends JPanel {
|
|
||||||
|
|
||||||
private static ImagePanel panel;
|
|
||||||
|
|
||||||
public static ImagePanel Instance()
|
|
||||||
{
|
|
||||||
if(panel == null)
|
|
||||||
panel = new ImagePanel();
|
|
||||||
|
|
||||||
return panel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ImageIcon image;
|
|
||||||
private JLabel label;
|
|
||||||
|
|
||||||
private ImagePanel()
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
|
|
||||||
image = new ImageIcon();
|
|
||||||
label = new JLabel();
|
|
||||||
label.setIcon(image);
|
|
||||||
|
|
||||||
this.add(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImage(File f)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
BufferedImage bfimg = ImageIO.read(f);
|
|
||||||
image = new ImageIcon(bfimg);
|
|
||||||
label.setIcon(image);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
package com.imegumii.ui;
|
||||||
|
|
||||||
|
import com.imegumii.*;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by kenny on 8-6-2017.
|
||||||
|
*/
|
||||||
|
public class InputPanel extends JPanel {
|
||||||
|
|
||||||
|
private static InputPanel panel;
|
||||||
|
|
||||||
|
public static InputPanel Instance()
|
||||||
|
{
|
||||||
|
if(panel == null)
|
||||||
|
panel = new InputPanel();
|
||||||
|
|
||||||
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private InputPanel()
|
||||||
|
{
|
||||||
|
super(new BorderLayout());
|
||||||
|
|
||||||
|
JPanel topPanel = new JPanel();
|
||||||
|
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.LINE_AXIS));
|
||||||
|
topPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
|
||||||
|
|
||||||
|
topPanel.add(new JLabel("Regular expression"));
|
||||||
|
topPanel.add(Box.createRigidArea(new Dimension(10,0)));
|
||||||
|
|
||||||
|
JTextField text = new JTextField();
|
||||||
|
|
||||||
|
topPanel.add(text);
|
||||||
|
|
||||||
|
topPanel.add(Box.createRigidArea(new Dimension(10, 0)));
|
||||||
|
|
||||||
|
JButton button = new JButton("Generate");
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
TabPanel.Instance().addGraph("DFA: En", new File("images/en.png"), "Dit is nog meer rauwe en data");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
topPanel.add(button);
|
||||||
|
|
||||||
|
topPanel.add(Box.createHorizontalGlue());
|
||||||
|
this.add(topPanel, BorderLayout.NORTH);
|
||||||
|
|
||||||
|
|
||||||
|
//------------
|
||||||
|
//BOTTOM PANEL
|
||||||
|
//-----------
|
||||||
|
|
||||||
|
JPanel bottomPanel = new JPanel();
|
||||||
|
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.LINE_AXIS));
|
||||||
|
bottomPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
|
||||||
|
|
||||||
|
bottomPanel.add(new JLabel("File"));
|
||||||
|
bottomPanel.add(Box.createRigidArea(new Dimension(10,0)));
|
||||||
|
|
||||||
|
JComboBox<String> fileCombo = new JComboBox<String>(findFiles());
|
||||||
|
|
||||||
|
bottomPanel.add(fileCombo);
|
||||||
|
|
||||||
|
bottomPanel.add(Box.createRigidArea(new Dimension(10, 0)));
|
||||||
|
|
||||||
|
JButton fileButton = new JButton("Generate");
|
||||||
|
fileButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
StatusPanel.Instance().setStatus("Parsing file", 10);
|
||||||
|
|
||||||
|
String file = (String)fileCombo.getSelectedItem();
|
||||||
|
String name = file.replaceAll(".dot", "");
|
||||||
|
|
||||||
|
Importable p = FileParser.read(file);
|
||||||
|
|
||||||
|
if(p.type == Importable.Type.NDFA)
|
||||||
|
{
|
||||||
|
StatusPanel.Instance().setStatus("Generating image for NDFA", 60);
|
||||||
|
NDFA<String> ndfa = (NDFA<String>)p;
|
||||||
|
|
||||||
|
Graph.generateImage(ndfa, name);
|
||||||
|
|
||||||
|
TabPanel.Instance().addGraph("NDFA: " + name, new File("images/" + name + ".png"), ndfa.getTransitions());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(p.type == Importable.Type.DFA)
|
||||||
|
{
|
||||||
|
StatusPanel.Instance().setStatus("Generating image for DFA", 60);
|
||||||
|
DFA<String> dfa = (DFA<String>)p;
|
||||||
|
|
||||||
|
Graph.generateImage(dfa, name);
|
||||||
|
|
||||||
|
TabPanel.Instance().addGraph("DFA: " + name, new File("images/" + name + ".png"), dfa.getTransitions());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(p.type == Importable.Type.REGEX)
|
||||||
|
{
|
||||||
|
StatusPanel.Instance().setStatus("Converting REGEX to NDFA", 40);
|
||||||
|
RegExp regex = (RegExp) p;
|
||||||
|
|
||||||
|
NDFA<String> ndfa = ThompsonConverter.convert(regex);
|
||||||
|
|
||||||
|
StatusPanel.Instance().setStatus("Generating image for NDFA", 70);
|
||||||
|
|
||||||
|
Graph.generateImage(ndfa, name);
|
||||||
|
|
||||||
|
TabPanel.Instance().addGraph("REGEX: " + name, new File("images/" + name + ".png"), ndfa.getTransitions());
|
||||||
|
}
|
||||||
|
|
||||||
|
StatusPanel.Instance().setStatus("Done", 100);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bottomPanel.add(fileButton);
|
||||||
|
|
||||||
|
bottomPanel.add(Box.createHorizontalGlue());
|
||||||
|
this.add(bottomPanel, BorderLayout.SOUTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] findFiles()
|
||||||
|
{
|
||||||
|
File folder = new File("input");
|
||||||
|
File[] listOfFiles = folder.listFiles();
|
||||||
|
|
||||||
|
ArrayList<String> fileNames = new ArrayList<String>();
|
||||||
|
|
||||||
|
for (int i = 0; i < listOfFiles.length; i++) {
|
||||||
|
if (listOfFiles[i].isFile() && listOfFiles[i].getName().endsWith(".dot")) {
|
||||||
|
fileNames.add(listOfFiles[i].getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] files = new String[fileNames.size()];
|
||||||
|
files = fileNames.toArray(files);
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package com.imegumii.ui;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by kenny on 8-6-2017.
|
|
||||||
*/
|
|
||||||
public class RegexPanel extends JPanel {
|
|
||||||
|
|
||||||
private static RegexPanel panel;
|
|
||||||
|
|
||||||
public static RegexPanel Instance()
|
|
||||||
{
|
|
||||||
if(panel == null)
|
|
||||||
panel = new RegexPanel();
|
|
||||||
|
|
||||||
return panel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private RegexPanel()
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
|
|
||||||
this.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
|
|
||||||
|
|
||||||
JTextField text = new JTextField();
|
|
||||||
|
|
||||||
this.add(text);
|
|
||||||
|
|
||||||
this.add(Box.createRigidArea(new Dimension(10, 0)));
|
|
||||||
|
|
||||||
JButton button = new JButton("Generate");
|
|
||||||
button.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
ImagePanel.Instance().setImage(new File("images/en.png"));
|
|
||||||
System.out.println("Refreshing image");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.add(button);
|
|
||||||
|
|
||||||
this.add(Box.createHorizontalGlue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.imegumii.ui;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by kenny on 9-6-2017.
|
||||||
|
*/
|
||||||
|
public class StatusPanel extends JPanel {
|
||||||
|
|
||||||
|
private static StatusPanel panel;
|
||||||
|
|
||||||
|
private JLabel status;
|
||||||
|
private JProgressBar progress;
|
||||||
|
|
||||||
|
public static StatusPanel Instance()
|
||||||
|
{
|
||||||
|
if(panel == null)
|
||||||
|
panel = new StatusPanel();
|
||||||
|
|
||||||
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StatusPanel()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
|
||||||
|
this.setBackground(Color.LIGHT_GRAY);
|
||||||
|
this.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
|
||||||
|
|
||||||
|
progress = new JProgressBar();
|
||||||
|
progress.setValue(0);
|
||||||
|
progress.setPreferredSize(new Dimension(250, 0));
|
||||||
|
|
||||||
|
status = new JLabel("Application ready");
|
||||||
|
|
||||||
|
this.add(progress);
|
||||||
|
this.add(Box.createHorizontalGlue());
|
||||||
|
this.add(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String text, int progress)
|
||||||
|
{
|
||||||
|
this.progress.setValue(progress);
|
||||||
|
this.status.setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(int progress)
|
||||||
|
{
|
||||||
|
this.progress.setValue(progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String text)
|
||||||
|
{
|
||||||
|
this.status.setText(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.imegumii.ui;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by kenny on 9-6-2017.
|
||||||
|
*/
|
||||||
|
public class TabPanel extends JTabbedPane {
|
||||||
|
|
||||||
|
private static TabPanel panel;
|
||||||
|
|
||||||
|
public static TabPanel Instance()
|
||||||
|
{
|
||||||
|
if(panel == null)
|
||||||
|
panel = new TabPanel();
|
||||||
|
|
||||||
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private TabPanel()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addGraph(String name, File image, String rawData)
|
||||||
|
{
|
||||||
|
this.addTab(name, new GraphPanel(name, image, rawData));
|
||||||
|
this.setSelectedIndex(this.getTabCount() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeGraph(GraphPanel component)
|
||||||
|
{
|
||||||
|
this.remove(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user