Merged
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
@@ -0,0 +1 @@
|
||||
Raw
|
||||
@@ -0,0 +1,7 @@
|
||||
DFA
|
||||
B0
|
||||
E1
|
||||
0>a>1
|
||||
0>b>1
|
||||
1>a>0
|
||||
1>b>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
|
||||
@@ -0,0 +1,9 @@
|
||||
NDFA
|
||||
B0
|
||||
E1
|
||||
0>a>1
|
||||
0>b>1
|
||||
0>$>1
|
||||
1>a>0
|
||||
1>b>1
|
||||
1>$>0
|
||||
@@ -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.
|
||||
*/
|
||||
public class Automata <T extends Comparable> {
|
||||
public class Automata <T extends Comparable> extends Importable {
|
||||
|
||||
protected Set<Transition<T>> transistions;
|
||||
|
||||
@@ -23,6 +23,7 @@ public class Automata <T extends Comparable> {
|
||||
}
|
||||
|
||||
public Automata(SortedSet<Character> symbols) {
|
||||
super(Type.ERROR);
|
||||
states = new TreeSet<T>();
|
||||
beginStates = new TreeSet<T>();
|
||||
eindStates = new TreeSet<T>();
|
||||
@@ -50,7 +51,17 @@ public class Automata <T extends Comparable> {
|
||||
|
||||
public void printTransitions () {
|
||||
transistions.forEach(System.out::println);
|
||||
}
|
||||
|
||||
public String getTransitions()
|
||||
{
|
||||
String s = "";
|
||||
for(Transition t : transistions)
|
||||
{
|
||||
s += t.toString() + "\n";
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public void print() {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.imegumii;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import javafx.util.Pair;
|
||||
|
||||
/**
|
||||
* Created by imegumii on 01/05/2017.
|
||||
@@ -10,10 +12,12 @@ public class DFA<T extends Comparable> extends Automata<T> {
|
||||
|
||||
public DFA(Character[] symbols) {
|
||||
super(symbols);
|
||||
this.type = Type.DFA;
|
||||
}
|
||||
|
||||
public DFA(SortedSet<Character> symbols) {
|
||||
super(symbols);
|
||||
this.type = Type.DFA;
|
||||
}
|
||||
|
||||
public boolean accepteer(String s) {
|
||||
@@ -120,5 +124,66 @@ public class DFA<T extends Comparable> extends Automata<T> {
|
||||
return returnDFA;
|
||||
}
|
||||
|
||||
//TODO: add and & or operations
|
||||
public DFA<String> en(DFA<T> other)
|
||||
{
|
||||
return maakTupleDFA((DFA<String>)this, (DFA<String>)other, false);
|
||||
}
|
||||
|
||||
public DFA<String> of(DFA<T> other)
|
||||
{
|
||||
return maakTupleDFA((DFA<String>)this, (DFA<String>)other, true);
|
||||
}
|
||||
|
||||
private DFA<String> maakTupleDFA(DFA<String> dfa1, DFA<String> dfa2, boolean of)
|
||||
{
|
||||
DFA<String> merged = new DFA<String>(dfa1.symbols);
|
||||
|
||||
//Create all transitions and states
|
||||
for(Transition t1 : dfa1.transistions)
|
||||
{
|
||||
for(Transition t2 : dfa2.transistions)
|
||||
{
|
||||
if(t1.symbol == t2.symbol) {
|
||||
Transition t3 = new Transition<String>(t1.vanState + "-" + t2.vanState, t1.symbol, t1.naarState + "-" + t2.naarState);
|
||||
|
||||
if(dfa1.beginStates.contains(t1.vanState) && dfa2.beginStates.contains(t2.vanState))
|
||||
merged.defineAsStartState((String)t3.vanState);
|
||||
|
||||
if(of)
|
||||
{
|
||||
if(dfa1.eindStates.contains(t1.vanState) || dfa2.eindStates.contains(t2.vanState))
|
||||
merged.defineAsEndState((String)t3.vanState);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(dfa1.eindStates.contains(t1.vanState) && dfa2.eindStates.contains(t2.vanState))
|
||||
merged.defineAsEndState((String)t3.vanState);
|
||||
}
|
||||
|
||||
merged.addTransition(t3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Delete wrong states
|
||||
SortedSet<String> usedStates = new TreeSet<String>();
|
||||
for(Transition t : merged.transistions)
|
||||
{
|
||||
usedStates.add((String)t.naarState);
|
||||
}
|
||||
|
||||
Iterator<Transition<String>> it = merged.transistions.iterator();
|
||||
|
||||
while(it.hasNext())
|
||||
{
|
||||
Transition<String> t = it.next();
|
||||
|
||||
if(!usedStates.contains(t.vanState))
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
return merged;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.imegumii;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.Buffer;
|
||||
|
||||
/**
|
||||
* Created by kenny on 8-6-2017.
|
||||
*/
|
||||
public class FileParser {
|
||||
|
||||
public static Importable read(String filename)
|
||||
{
|
||||
File f = new File("input/" + filename);
|
||||
|
||||
Importable imp = null;
|
||||
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(f))) {
|
||||
|
||||
String type = br.readLine();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case "DFA":
|
||||
imp = readDFA(br);
|
||||
break;
|
||||
case "NDFA":
|
||||
imp = readNDFA(br);
|
||||
break;
|
||||
case "REGEX":
|
||||
imp = readRegex(br);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
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;
|
||||
}
|
||||
|
||||
public static NDFA<String> readNDFA(BufferedReader br) throws IOException {
|
||||
|
||||
Character[] chars = {'a', 'b'};
|
||||
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); }
|
||||
}
|
||||
|
||||
else if(line.startsWith("E")) {
|
||||
String[] states = line.substring(1,line.length()).split(",");
|
||||
for(String s : states) { ndfa.defineAsEndState(s); }
|
||||
}
|
||||
|
||||
else {
|
||||
String[] trans = line.split(">");
|
||||
|
||||
if(trans[1].equals("$")) {
|
||||
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]));
|
||||
}
|
||||
}
|
||||
|
||||
return ndfa;
|
||||
}
|
||||
|
||||
public static RegExp readRegex(BufferedReader br) throws IOException {
|
||||
String line = "Error";
|
||||
line = br.readLine();
|
||||
|
||||
RegExp regex = new RegExp("a").of(new RegExp("b").ster()); //RegExp.parse(line);
|
||||
|
||||
return regex;
|
||||
}
|
||||
}
|
||||
@@ -19,13 +19,28 @@ public class Graph {
|
||||
|
||||
public static String generateGraphString(Automata<String> a)
|
||||
{
|
||||
String text = "digraph finite_state_machine {\nrankdir=LR;\nsize=\"8,5\";\nnode [shape = doublecircle];";
|
||||
String text = "digraph finite_state_machine {\nrankdir=LR;\nsize=\"8,5\";\n";
|
||||
|
||||
for(String s : a.eindStates){
|
||||
text += s + " ";
|
||||
|
||||
if(a.eindStates.size() > 0) {
|
||||
text += "node [shape=cirlce, peripheries=2];";
|
||||
|
||||
for (String s : a.eindStates) {
|
||||
text += "\"" + s + "\" ";
|
||||
}
|
||||
|
||||
text += ";";
|
||||
}
|
||||
|
||||
text += ";\nnode [shape = circle];\n";
|
||||
if(a.beginStates.size() > 0) {
|
||||
text += "\nnode [shape = point];\n";
|
||||
|
||||
for (String s : a.beginStates) {
|
||||
text += "\" \" -> \"" + s + "\" [label = \" \"];";
|
||||
}
|
||||
}
|
||||
|
||||
text += "\nnode [shape = circle];\n";
|
||||
|
||||
for(Transition<String> t : a.transistions)
|
||||
{
|
||||
@@ -35,7 +50,41 @@ public class Graph {
|
||||
else
|
||||
s = t.symbol + "";
|
||||
|
||||
text += t.vanState + " -> " + t.naarState + " [ label = \"" + s + "\"];\n";
|
||||
text += "\"" + t.vanState + "\" -> \"" + t.naarState + "\" [ label = \"" + s + "\"];\n";
|
||||
}
|
||||
|
||||
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 += "}";
|
||||
@@ -45,9 +94,9 @@ public class Graph {
|
||||
|
||||
public static void generateImage(Automata<String> a, String fileName) {
|
||||
try {
|
||||
File f = new File("images/" + a.toString() + ".dot");
|
||||
File f = new File("images/" + a.hashCode() + ".dot");
|
||||
PrintWriter w = new PrintWriter(f);
|
||||
w.println(Graph.generateGraphString(a));
|
||||
w.print(Graph.generateImageString(a));
|
||||
w.flush();
|
||||
w.close();
|
||||
MutableGraph g = Parser.read(f);
|
||||
@@ -57,8 +106,8 @@ public class Graph {
|
||||
Graphviz.fromGraph(g).width(1080).render(Format.PNG).toFile(new File("images/" + a.toString() + ".png"));
|
||||
}
|
||||
|
||||
if (f.delete()) {
|
||||
System.out.println("Succesfully deleted temp file");
|
||||
if (!f.delete()) {
|
||||
System.out.println("Failed to delete temp file");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.imegumii;
|
||||
|
||||
import jdk.nashorn.internal.runtime.Source;
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.Regex;
|
||||
import com.imegumii.ui.Frame;
|
||||
|
||||
import java.util.TreeSet;
|
||||
|
||||
@@ -395,15 +394,7 @@ public class Main {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Practicum1();
|
||||
|
||||
// Practicum2();
|
||||
|
||||
// Practicum4();
|
||||
|
||||
// Practicum5();
|
||||
|
||||
// ReverseAutomata();
|
||||
// Test.test();
|
||||
|
||||
// Hopcroft();
|
||||
// TestUitOpdrachtBeschrijving();
|
||||
@@ -445,5 +436,6 @@ public class Main {
|
||||
System.out.println(aantalOperators(reg.parseString(s5), 1));
|
||||
// System.out.println(reg.parseString(s3).getTaal(100)); // werkte!
|
||||
|
||||
new Frame();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,12 @@ import java.util.*;
|
||||
public class NDFA<T extends Comparable> extends Automata<T> {
|
||||
public NDFA(Character[] symbols) {
|
||||
super(symbols);
|
||||
this.type = Type.NDFA;
|
||||
}
|
||||
|
||||
public NDFA(SortedSet<Character> symbols) {
|
||||
super(symbols);
|
||||
this.type = Type.NDFA;
|
||||
}
|
||||
|
||||
public SortedSet<T> statesBereikbaarVanaf(T vanaf, char s) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.*;
|
||||
/**
|
||||
* Created by kenny on 2-5-2017.
|
||||
*/
|
||||
public class RegExp {
|
||||
public class RegExp extends Importable{
|
||||
|
||||
public enum Operator { PLUS, STER, OF, PUNT, EEN}
|
||||
|
||||
@@ -27,6 +27,7 @@ public class RegExp {
|
||||
|
||||
public RegExp()
|
||||
{
|
||||
super(Type.REGEX);
|
||||
operator = Operator.EEN;
|
||||
characters = "";
|
||||
links = null;
|
||||
@@ -34,6 +35,7 @@ public class RegExp {
|
||||
}
|
||||
|
||||
public RegExp(String chars){
|
||||
super(Type.REGEX);
|
||||
operator = Operator.EEN;
|
||||
characters = chars;
|
||||
links = null;
|
||||
|
||||
@@ -0,0 +1,415 @@
|
||||
package com.imegumii;
|
||||
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Created by kenny on 8-6-2017.
|
||||
*/
|
||||
public class Test {
|
||||
public static void test()
|
||||
{
|
||||
// Practicum1();
|
||||
|
||||
// Practicum2();
|
||||
|
||||
// Practicum4();
|
||||
|
||||
// Practicum5();
|
||||
|
||||
// ReverseAutomata();
|
||||
|
||||
// Hopcroft();
|
||||
|
||||
TupleConstructie();
|
||||
|
||||
// FileReadTest();
|
||||
}
|
||||
|
||||
public static void P1Opdracht1(TreeSet<String> stringsToParse) {
|
||||
Character [] characters = {'a', 'b'};
|
||||
DFA<String> myAutomata = new DFA<String>(characters);
|
||||
|
||||
// AAB
|
||||
myAutomata.addTransition(new Transition<String>("q0", 'a', "q1"));
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("q1", 'b', "q2"));
|
||||
myAutomata.addTransition(new Transition<String>("q1", 'a', "q0"));
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("q2", 'b', "q3"));
|
||||
myAutomata.addTransition(new Transition<String>("q2", 'a', "q5"));
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("q3", "q0"));
|
||||
|
||||
// BAAB
|
||||
myAutomata.addTransition(new Transition<String>("q0", 'b', "q4"));
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("q4", 'a', "q5"));
|
||||
myAutomata.addTransition(new Transition<String>("q4", 'b', "q4"));
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("q5", 'a', "q6"));
|
||||
myAutomata.addTransition(new Transition<String>("q5", 'b', "q4"));
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("q6", 'a', "q4"));
|
||||
myAutomata.addTransition(new Transition<String>("q6", 'b', "q7"));
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("q7", 'a', "q4"));
|
||||
myAutomata.addTransition(new Transition<String>("q7", 'b', "q4"));
|
||||
|
||||
myAutomata.defineAsStartState("q0");
|
||||
myAutomata.defineAsEndState("q3");
|
||||
myAutomata.defineAsEndState("q7");
|
||||
|
||||
myAutomata.printTransitions();
|
||||
|
||||
final long[] startTime = {System.currentTimeMillis()};
|
||||
myAutomata.geefTaalTotLengte(10).getSymbols().forEach((s) -> {
|
||||
long before = System.currentTimeMillis();
|
||||
boolean result = myAutomata.accepteer(s);
|
||||
long after = System.currentTimeMillis();
|
||||
long delta = (after-before);
|
||||
System.out.println("string " + s + " fully parsed, result: " + result + " , it took " + delta + " ms");
|
||||
startTime[0] += delta;
|
||||
});
|
||||
System.out.println((System.currentTimeMillis() - startTime[0]));
|
||||
}
|
||||
|
||||
public static void Practicum1() {
|
||||
TreeSet<String> stringsToParse = new TreeSet<>();
|
||||
stringsToParse.add("abbaa");
|
||||
stringsToParse.add("babaa");
|
||||
stringsToParse.add("abbaaabaab");
|
||||
stringsToParse.add("abaab");
|
||||
stringsToParse.add("aaaabba");
|
||||
stringsToParse.add("baab");
|
||||
stringsToParse.add("baaba");
|
||||
stringsToParse.add("baabaabba");
|
||||
stringsToParse.add("aaaaabb"); // this is wrong, something is wrong
|
||||
|
||||
|
||||
P1Opdracht1(stringsToParse);
|
||||
}
|
||||
|
||||
public static void Practicum2()
|
||||
{
|
||||
RegExp a = new RegExp("a");
|
||||
RegExp b = new RegExp("b");
|
||||
|
||||
// expr1: "baa"
|
||||
RegExp expr1 = new RegExp("baa");
|
||||
// expr2: "bb"
|
||||
RegExp expr2 = new RegExp("bb");
|
||||
// expr3: "baa | baa"
|
||||
RegExp expr3 = expr1.of(expr2);
|
||||
|
||||
// all: "(a|b)*"
|
||||
RegExp all = (a.of(b)).ster();
|
||||
|
||||
// expr4: "(baa | baa)+"
|
||||
RegExp expr4 = expr3.plus();
|
||||
// expr5: "(baa | baa)+ (a|b)*"
|
||||
RegExp expr5 = expr4.punt(all);
|
||||
|
||||
System.out.println("taal van (baa):\n" + expr1.getTaal(5));
|
||||
System.out.println("taal van (bb):\n" + expr2.getTaal(5));
|
||||
System.out.println("taal van (baa | bb):\n" + expr3.getTaal(5));
|
||||
|
||||
System.out.println("taal van (a|b)*:\n" + all.getTaal(5));
|
||||
System.out.println("taal van (baa | bb)+:\n" + expr4.getTaal(5));
|
||||
System.out.println("taal van (baa | bb)+ (a|b)*:\n" + expr5.getTaal(6));
|
||||
|
||||
}
|
||||
|
||||
public static void Thompson() {
|
||||
RegExp expr1 = new RegExp("a");
|
||||
RegExp expr2 = new RegExp("b");
|
||||
RegExp expr3 = new RegExp("c");
|
||||
RegExp expr4 = new RegExp("d");
|
||||
|
||||
RegExp expr5 = expr1.of(expr2);
|
||||
RegExp expr6 = expr3.of(expr4);
|
||||
|
||||
RegExp expr7 = expr5.punt(expr6);
|
||||
|
||||
NDFA<String> test = ThompsonConverter.convert(expr7);
|
||||
|
||||
System.out.println(Graph.generateGraphString(test));
|
||||
}
|
||||
|
||||
public static void Hopcroft()
|
||||
{
|
||||
Character [] characters = {'a', 'b'};
|
||||
DFA<String> automata = new DFA<String>(characters);
|
||||
|
||||
|
||||
automata.addTransition(new Transition<String>("q0", 'a', "q2"));
|
||||
automata.addTransition(new Transition<String>("q0", 'b', "q3"));
|
||||
automata.addTransition(new Transition<String>("q1", 'a', "q3"));
|
||||
automata.addTransition(new Transition<String>("q1", 'b', "q2"));
|
||||
automata.addTransition(new Transition<String>("q2", 'a', "q0"));
|
||||
automata.addTransition(new Transition<String>("q2", 'b', "q4"));
|
||||
automata.addTransition(new Transition<String>("q3", 'a', "q1"));
|
||||
automata.addTransition(new Transition<String>("q3", 'b', "q5"));
|
||||
automata.addTransition(new Transition<String>("q4", 'a', "q6"));
|
||||
automata.addTransition(new Transition<String>("q4", 'b', "q5"));
|
||||
automata.addTransition(new Transition<String>("q5", 'a', "q2"));
|
||||
automata.addTransition(new Transition<String>("q5", 'b', "q0"));
|
||||
automata.addTransition(new Transition<String>("q6", 'a', "q4"));
|
||||
automata.addTransition(new Transition<String>("q6", 'b', "q0"));
|
||||
|
||||
automata.defineAsStartState("q0");
|
||||
|
||||
automata.defineAsEndState("q1");
|
||||
automata.defineAsEndState("q3");
|
||||
automata.defineAsEndState("q4");
|
||||
automata.defineAsEndState("q6");
|
||||
|
||||
|
||||
/*
|
||||
automata.addTransition(new Transition<String>("0", 'a', "0"));
|
||||
automata.addTransition(new Transition<String>("0", 'b', "1"));
|
||||
|
||||
automata.addTransition(new Transition<String>("1", 'a', "2"));
|
||||
automata.addTransition(new Transition<String>("1", 'b', "1"));
|
||||
|
||||
automata.addTransition(new Transition<String>("2", 'a', "0"));
|
||||
automata.addTransition(new Transition<String>("2", 'b', "3"));
|
||||
|
||||
automata.addTransition(new Transition<String>("3", 'a', "4"));
|
||||
automata.addTransition(new Transition<String>("3", 'b', "1"));
|
||||
|
||||
automata.addTransition(new Transition<String>("4", 'a', "5"));
|
||||
automata.addTransition(new Transition<String>("4", 'b', "3"));
|
||||
|
||||
automata.addTransition(new Transition<String>("5", 'a', "0"));
|
||||
automata.addTransition(new Transition<String>("5", 'b', "3"));
|
||||
|
||||
automata.defineAsStartState("0");
|
||||
automata.defineAsEndState("2");
|
||||
automata.defineAsEndState("4");
|
||||
*/
|
||||
|
||||
System.out.println("\nNormal automata..");
|
||||
System.out.println(Graph.generateGraphString(automata));
|
||||
|
||||
HopcroftConverter convert = new HopcroftConverter(automata);
|
||||
DFA<String> minimized = convert.minimize();
|
||||
|
||||
System.out.println("\nMinimized automata..");
|
||||
Graph.generateImage(minimized, null);
|
||||
}
|
||||
|
||||
public static void ReverseAutomata()
|
||||
{
|
||||
Character [] characters = {'a', 'b'};
|
||||
DFA<String> myAutomata = new DFA<String>(characters);
|
||||
|
||||
// AAB
|
||||
myAutomata.addTransition(new Transition<String>("0", 'a', "0"));
|
||||
myAutomata.addTransition(new Transition<String>("0", 'b', "1"));
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("1", 'a', "0"));
|
||||
myAutomata.addTransition(new Transition<String>("1", 'b', "2"));
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("2", 'a', "0"));
|
||||
myAutomata.addTransition(new Transition<String>("2", 'b', "2"));
|
||||
|
||||
myAutomata.defineAsStartState("0");
|
||||
myAutomata.defineAsEndState("2");
|
||||
|
||||
// System.out.println(Graph.generateGraphString(myAutomata));
|
||||
|
||||
// System.out.println("\nREVERSE:");
|
||||
|
||||
NDFA<String> reverseAutomata = myAutomata.reverse();
|
||||
|
||||
// System.out.println(Graph.generateGraphString(reverseAutomata));
|
||||
|
||||
System.out.println("ORIGINEEL");
|
||||
myAutomata.printTransitions();
|
||||
System.out.println("MET BEGIN EN EIND");
|
||||
System.out.println(myAutomata.beginStates);
|
||||
System.out.println(myAutomata.eindStates);
|
||||
System.out.println("REVERSE");
|
||||
reverseAutomata.printTransitions();
|
||||
System.out.println("MET BEGIN EN EIND");
|
||||
System.out.println(reverseAutomata.beginStates);
|
||||
System.out.println(reverseAutomata.eindStates);
|
||||
}
|
||||
|
||||
public static void Practicum4() {
|
||||
Character [] characters = {'a', 'b'};
|
||||
NDFA<String> myAutomata = new NDFA<String>(characters);
|
||||
|
||||
// myAutomata.addTransition(new Transition<String>("0", 'a', "1"));
|
||||
// myAutomata.addTransition(new Transition<String>("0", 'a', "2"));
|
||||
// myAutomata.addTransition(new Transition<String>("1", 'a', "1"));
|
||||
// myAutomata.addTransition(new Transition<String>("1", 'a', "2"));
|
||||
// myAutomata.addTransition(new Transition<String>("2", 'b', "1"));
|
||||
// myAutomata.addTransition(new Transition<String>("2", 'b', "3"));
|
||||
// myAutomata.addTransition(new Transition<String>("3", 'a', "2"));
|
||||
// myAutomata.addTransition(new Transition<String>("3", 'a', "1"));
|
||||
// myAutomata.defineAsStartState("0");
|
||||
// myAutomata.defineAsEndState("0");
|
||||
// myAutomata.defineAsEndState("1");
|
||||
|
||||
// Test 2
|
||||
// myAutomata.addTransition(new Transition<String>("0", 'a', "1"));
|
||||
//
|
||||
// myAutomata.addTransition(new Transition<String>("0", 'a', "3"));
|
||||
// myAutomata.addTransition(new Transition<String>("0", 'b', "3"));
|
||||
//
|
||||
// myAutomata.addTransition(new Transition<String>("0", 'a', "2"));
|
||||
// myAutomata.addTransition(new Transition<String>("0", 'b', "2"));
|
||||
//
|
||||
// myAutomata.addTransition(new Transition<String>("1", 'a', "1"));
|
||||
// myAutomata.addTransition(new Transition<String>("1", 'b', "3"));
|
||||
//
|
||||
// myAutomata.addTransition(new Transition<String>("1", 'a', "2"));
|
||||
// myAutomata.addTransition(new Transition<String>("1", 'b', "2"));
|
||||
//
|
||||
// myAutomata.addTransition(new Transition<String>("2", 'b', "2"));
|
||||
// myAutomata.addTransition(new Transition<String>("2", 'b', "4"));
|
||||
//
|
||||
// myAutomata.addTransition(new Transition<String>("2", 'b', "3")); //ja? Ja.
|
||||
// myAutomata.addTransition(new Transition<String>("3", 'b', "2"));
|
||||
//
|
||||
// myAutomata.addTransition(new Transition<String>("3", 'b', "3"));
|
||||
//
|
||||
// myAutomata.addTransition(new Transition<String>("3", 'a', "4"));
|
||||
// myAutomata.addTransition(new Transition<String>("3", 'b', "4"));
|
||||
//
|
||||
// myAutomata.defineAsStartState("0");
|
||||
// myAutomata.defineAsEndState("1");
|
||||
|
||||
// Test 3
|
||||
|
||||
// myAutomata.addTransition(new Transition<String>("1", 'a', "2"));
|
||||
// myAutomata.addTransition(new Transition<String>("1", 'b', "1"));
|
||||
//
|
||||
// myAutomata.addTransition(new Transition<String>("2", 'a', "3"));
|
||||
// myAutomata.addTransition(new Transition<String>("2", 'b', "2"));
|
||||
// myAutomata.addTransition(new Transition<String>("2", Transition.EPSILON, "1"));
|
||||
//
|
||||
// myAutomata.addTransition(new Transition<String>("3", 'a', "4"));
|
||||
// myAutomata.addTransition(new Transition<String>("3", 'b', "3"));
|
||||
// myAutomata.addTransition(new Transition<String>("3", Transition.EPSILON, "2"));
|
||||
//
|
||||
// myAutomata.addTransition(new Transition<String>("4", 'a', "1"));
|
||||
// myAutomata.addTransition(new Transition<String>("4", 'b', "4"));
|
||||
// myAutomata.addTransition(new Transition<String>("4", Transition.EPSILON, "3"));
|
||||
//
|
||||
// myAutomata.defineAsStartState("1");
|
||||
// myAutomata.defineAsEndState("2");
|
||||
// myAutomata.defineAsEndState("3");
|
||||
|
||||
System.out.println("De NDFA is ");
|
||||
myAutomata.printTransitions();
|
||||
System.out.println("Met als begin en eind states");
|
||||
System.out.println(myAutomata.beginStates);
|
||||
System.out.println(myAutomata.eindStates);
|
||||
|
||||
System.out.println("DFA is dan ");
|
||||
DFA<String> myDfa = myAutomata.toDFA();
|
||||
myDfa.printTransitions();
|
||||
System.out.println("Met als begin en eind states");
|
||||
System.out.println(myDfa.beginStates);
|
||||
System.out.println(myDfa.eindStates);
|
||||
|
||||
}
|
||||
|
||||
public static void Practicum5 () {
|
||||
|
||||
Character [] characters = {'a', 'b'};
|
||||
DFA<String> myAutomata = new DFA<String>(characters);
|
||||
// Test 4 minimalisatie
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("0", 'a', "0"));
|
||||
myAutomata.addTransition(new Transition<String>("0", 'b', "1"));
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("1", 'a', "2"));
|
||||
myAutomata.addTransition(new Transition<String>("1", 'b', "1"));
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("2", 'a', "0"));
|
||||
myAutomata.addTransition(new Transition<String>("2", 'b', "3"));
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("3", 'a', "4"));
|
||||
myAutomata.addTransition(new Transition<String>("3", 'b', "1"));
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("4", 'a', "5"));
|
||||
myAutomata.addTransition(new Transition<String>("4", 'b', "3"));
|
||||
|
||||
myAutomata.addTransition(new Transition<String>("5", 'a', "0"));
|
||||
myAutomata.addTransition(new Transition<String>("5", 'b', "3"));
|
||||
|
||||
myAutomata.defineAsStartState("0");
|
||||
myAutomata.defineAsEndState("2");
|
||||
myAutomata.defineAsEndState("4");
|
||||
|
||||
System.out.println("Ongeminimaliseerd krijgen we:");
|
||||
myAutomata.print();
|
||||
System.out.println("-------");
|
||||
Graph.generateImage(myAutomata, null);
|
||||
|
||||
DFA<String> geminimaliseerd = myAutomata.minimaliseer();
|
||||
System.out.println("Geminimaliseerd krijgen we:");
|
||||
geminimaliseerd.print();
|
||||
System.out.println("------");
|
||||
Graph.generateImage(geminimaliseerd, null);
|
||||
geminimaliseerd.ontkenning();
|
||||
}
|
||||
|
||||
public static void TupleConstructie()
|
||||
{
|
||||
Character [] characters = {'a', 'b'};
|
||||
DFA<String> aut1 = new DFA<String>(characters);
|
||||
|
||||
aut1.addTransition(new Transition<String>("1", 'a', "2"));
|
||||
aut1.addTransition(new Transition<String>("1", 'b', "1"));
|
||||
|
||||
aut1.addTransition(new Transition<String>("2", 'a', "1"));
|
||||
aut1.addTransition(new Transition<String>("2", 'b', "2"));
|
||||
|
||||
|
||||
aut1.defineAsStartState("1");
|
||||
aut1.defineAsEndState("1");
|
||||
|
||||
System.out.println("\n\nA1\n--------");
|
||||
System.out.println(Graph.generateImageString(aut1));
|
||||
Graph.generateImage(aut1, "automaat1");
|
||||
|
||||
|
||||
DFA<String> aut2 = new DFA<String>(characters);
|
||||
|
||||
aut2.addTransition(new Transition<String>("1", 'a', "1"));
|
||||
aut2.addTransition(new Transition<String>("1", 'b', "2"));
|
||||
|
||||
aut2.addTransition(new Transition<String>("2", 'a', "1"));
|
||||
aut2.addTransition(new Transition<String>("2", 'b', "3"));
|
||||
|
||||
aut2.addTransition(new Transition<String>("3", 'a', "1"));
|
||||
aut2.addTransition(new Transition<String>("3", 'b', "4"));
|
||||
|
||||
aut2.addTransition(new Transition<String>("4", 'a', "4"));
|
||||
aut2.addTransition(new Transition<String>("4", 'b', "4"));
|
||||
|
||||
aut2.defineAsStartState("1");
|
||||
aut2.defineAsEndState("1");
|
||||
aut2.defineAsEndState("2");
|
||||
|
||||
System.out.println("\n\nA2\n--------");
|
||||
System.out.println(Graph.generateImageString(aut2));
|
||||
Graph.generateImage(aut2, "automaat2");
|
||||
|
||||
DFA<String> en = aut1.en(aut2);
|
||||
|
||||
System.out.println("\n\nEN\n--------");
|
||||
System.out.println(Graph.generateImageString(en));
|
||||
Graph.generateImage(en, "en");
|
||||
|
||||
DFA<String> of = aut1.of(aut2);
|
||||
|
||||
System.out.println("\n\nOF\n--------");
|
||||
System.out.println(Graph.generateImageString(of));
|
||||
Graph.generateImage(of, "of");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.imegumii.ui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Created by kenny on 8-6-2017.
|
||||
*/
|
||||
public class Frame extends JFrame {
|
||||
|
||||
public Frame()
|
||||
{
|
||||
super("Automata");
|
||||
|
||||
this.setSize(700, 800);
|
||||
this.setResizable(false);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
JPanel container = new JPanel(new BorderLayout());
|
||||
container.add(TabPanel.Instance(), BorderLayout.CENTER);
|
||||
container.add(InputPanel.Instance(), BorderLayout.NORTH);
|
||||
container.add(StatusPanel.Instance(), BorderLayout.SOUTH);
|
||||
|
||||
this.setContentPane(container);
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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