Added mnimize button
This commit is contained in:
@@ -73,7 +73,7 @@ public class RegExp extends Importable{
|
||||
// System.out.println("Toreplace is " + toReplace.toString());
|
||||
toProcessAfter = toProcessAfter.replace(toReplace, replaceWith);
|
||||
|
||||
processedParantheses.add(stringNaarRegExp(sub, new RegExp(), null));
|
||||
processedParantheses.add(stringNaarRegExp(sub, r, null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,14 +10,14 @@ public class ThompsonConverter {
|
||||
public static NDFA<String> convert(RegExp regex)
|
||||
{
|
||||
Character [] characters = {'a', 'b'};
|
||||
NDFA generated = new NDFA<String>(characters);
|
||||
NDFA<String> generated = new NDFA<String>(characters);
|
||||
|
||||
convertStatement(regex, generated);
|
||||
|
||||
return generated;
|
||||
}
|
||||
|
||||
private static void convertStatement(RegExp regex, NDFA automata)
|
||||
private static void convertStatement(RegExp regex, NDFA<String> automata)
|
||||
{
|
||||
switch(regex.operator)
|
||||
{
|
||||
@@ -25,8 +25,8 @@ public class ThompsonConverter {
|
||||
|
||||
//Links
|
||||
convertStatement(regex.links, automata);
|
||||
String endLink1 = (String) automata.eindStates.first();
|
||||
String beginLink1 = (String) automata.beginStates.first();
|
||||
String endLink1 = automata.eindStates.first();
|
||||
String beginLink1 = automata.beginStates.first();
|
||||
|
||||
//Repeat and skip
|
||||
automata.addTransition(new Transition(endLink1, Transition.EPSILON, beginLink1));
|
||||
@@ -42,8 +42,8 @@ public class ThompsonConverter {
|
||||
|
||||
//Links
|
||||
convertStatement(regex.links, automata);
|
||||
String endLink2 = (String) automata.eindStates.first();
|
||||
String beginLink2 = (String) automata.beginStates.first();
|
||||
String endLink2 = automata.eindStates.first();
|
||||
String beginLink2 = automata.beginStates.first();
|
||||
|
||||
//New states
|
||||
String start2 = getState();
|
||||
@@ -66,13 +66,13 @@ public class ThompsonConverter {
|
||||
|
||||
//Links
|
||||
convertStatement(regex.links, automata);
|
||||
String topEnd = (String) automata.eindStates.first();
|
||||
String topBegin = (String) automata.beginStates.first();
|
||||
String topEnd = automata.eindStates.first();
|
||||
String topBegin = automata.beginStates.first();
|
||||
|
||||
//Rechts
|
||||
convertStatement(regex.rechts, automata);
|
||||
String bottomBegin = (String) automata.beginStates.first();
|
||||
String bottomEnd = (String) automata.eindStates.first();
|
||||
String bottomBegin = automata.beginStates.first();
|
||||
String bottomEnd = automata.eindStates.first();
|
||||
|
||||
//New states
|
||||
String start3 = getState();
|
||||
@@ -96,13 +96,13 @@ public class ThompsonConverter {
|
||||
|
||||
//Links
|
||||
convertStatement(regex.links, automata);
|
||||
String endLink = (String) automata.eindStates.first();
|
||||
String newBeginLink = (String) automata.beginStates.first();
|
||||
String endLink = automata.eindStates.first();
|
||||
String newBeginLink = automata.beginStates.first();
|
||||
|
||||
//Rechts
|
||||
convertStatement(regex.rechts, automata);
|
||||
String beginLink = (String) automata.beginStates.first();
|
||||
String newEndLink = (String) automata.eindStates.first();
|
||||
String beginLink = automata.beginStates.first();
|
||||
String newEndLink = automata.eindStates.first();
|
||||
|
||||
//Link both
|
||||
automata.addTransition(new Transition(endLink, Transition.EPSILON, beginLink));
|
||||
@@ -115,11 +115,26 @@ public class ThompsonConverter {
|
||||
|
||||
break;
|
||||
case EEN:
|
||||
|
||||
char[] s = regex.characters.toCharArray();
|
||||
|
||||
automata.clearBeginStates();
|
||||
automata.clearEindStates();
|
||||
|
||||
if(regex.characters.length() <= 0)
|
||||
{
|
||||
String state1 = getState();
|
||||
String state2 = getState();
|
||||
|
||||
Transition<String> t = new Transition<String>(state1, Transition.EPSILON, state2);
|
||||
|
||||
automata.addTransition(t);
|
||||
automata.defineAsStartState(state1);
|
||||
automata.defineAsEndState(state2);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
String prevState = getState();
|
||||
String newState = "";
|
||||
automata.defineAsStartState(prevState);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.imegumii.ui;
|
||||
|
||||
import com.imegumii.*;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -18,20 +19,20 @@ public class GraphPanel extends JPanel {
|
||||
|
||||
private String name;
|
||||
private File imageLocation;
|
||||
private String export;
|
||||
private Automata<String> automata;
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public GraphPanel(String name, File f, String export)
|
||||
public GraphPanel(String name, File f, Automata<String> automata)
|
||||
{
|
||||
super(new BorderLayout());
|
||||
|
||||
this.name = name;
|
||||
this.imageLocation = f;
|
||||
this.export = export;
|
||||
this.automata = automata;
|
||||
|
||||
this.add(new GraphImagePanel(imageLocation), BorderLayout.CENTER);
|
||||
|
||||
@@ -66,7 +67,7 @@ public class GraphPanel extends JPanel {
|
||||
PrintWriter w = null;
|
||||
try {
|
||||
w = new PrintWriter(file);
|
||||
w.print(export);
|
||||
w.print(automata.getTransitions());
|
||||
w.flush();
|
||||
w.close();
|
||||
StatusPanel.Instance().setStatus("Success: " + filename);
|
||||
@@ -101,7 +102,53 @@ public class GraphPanel extends JPanel {
|
||||
}
|
||||
});
|
||||
|
||||
JButton minimizeButton = new JButton("Minimize graph");
|
||||
minimizeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
System.out.println("Kaas");
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
System.out.println(automata.type);
|
||||
|
||||
if(automata.type == Importable.Type.NDFA)
|
||||
{
|
||||
StatusPanel.Instance().setStatus("Converting to DFA " + name, 20);
|
||||
|
||||
DFA<String> convert = ((NDFA<String>) automata).toDFA();
|
||||
|
||||
StatusPanel.Instance().setStatus("Generating image for DFA " + name, 30);
|
||||
|
||||
Graph.generateImage(convert, "cdfa." + name);
|
||||
|
||||
TabPanel.Instance().addGraph("DFA: " + name, new File("images/cdfa." + name), convert);
|
||||
|
||||
StatusPanel.Instance().setStatus("Minimizing cdfa." + name, 50);
|
||||
|
||||
DFA<String> mini = convert.minimaliseerHopcroft();
|
||||
|
||||
StatusPanel.Instance().setStatus("Generating minimized image", 70);
|
||||
|
||||
Graph.generateImage(mini, "mcdfa." + name);
|
||||
|
||||
TabPanel.Instance().addGraph("DFA: mcdfa." + name, new File("images/mcdfa." + name), mini);
|
||||
|
||||
StatusPanel.Instance().setStatus("Done", 100);
|
||||
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
buttonPanel.add(Box.createHorizontalGlue());
|
||||
buttonPanel.add(minimizeButton);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
|
||||
buttonPanel.add(exportImage);
|
||||
buttonPanel.add(Box.createRigidArea(new Dimension(10,0)));
|
||||
buttonPanel.add(exportData);
|
||||
|
||||
@@ -70,7 +70,7 @@ public class InputPanel extends JPanel {
|
||||
|
||||
Graph.generateImage(ndfa, name);
|
||||
|
||||
TabPanel.Instance().addGraph("REGEX: " + name, new File("images/" + name + ".png"), ndfa.getTransitions());
|
||||
TabPanel.Instance().addGraph("REGEX: " + name, new File("images/" + name + ".png"), ndfa);
|
||||
|
||||
StatusPanel.Instance().setStatus("Done", 100);
|
||||
}
|
||||
@@ -124,7 +124,7 @@ public class InputPanel extends JPanel {
|
||||
|
||||
Graph.generateImage(ndfa, name);
|
||||
|
||||
TabPanel.Instance().addGraph("NDFA: " + name, new File("images/" + name + ".png"), ndfa.getTransitions());
|
||||
TabPanel.Instance().addGraph("NDFA: " + name, new File("images/" + name + ".png"), ndfa);
|
||||
}
|
||||
|
||||
if(p.type == Importable.Type.DFA)
|
||||
@@ -134,7 +134,7 @@ public class InputPanel extends JPanel {
|
||||
|
||||
Graph.generateImage(dfa, name);
|
||||
|
||||
TabPanel.Instance().addGraph("DFA: " + name, new File("images/" + name + ".png"), dfa.getTransitions());
|
||||
TabPanel.Instance().addGraph("DFA: " + name, new File("images/" + name + ".png"), dfa);
|
||||
}
|
||||
|
||||
if(p.type == Importable.Type.REGEX)
|
||||
@@ -142,6 +142,8 @@ public class InputPanel extends JPanel {
|
||||
StatusPanel.Instance().setStatus("Converting REGEX to NDFA", 40);
|
||||
RegExp regex = (RegExp) p;
|
||||
|
||||
System.out.println(regex.getTaal(10));
|
||||
|
||||
NDFA<String> ndfa = ThompsonConverter.convert(regex);
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
@@ -152,7 +154,7 @@ public class InputPanel extends JPanel {
|
||||
|
||||
Graph.generateImage(ndfa, name);
|
||||
|
||||
TabPanel.Instance().addGraph("REGEX: " + name, new File("images/" + name + ".png"), ndfa.getTransitions());
|
||||
TabPanel.Instance().addGraph("REGEX: " + name, new File("images/" + name + ".png"), ndfa);
|
||||
}
|
||||
|
||||
StatusPanel.Instance().setStatus("Done", 100);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.imegumii.ui;
|
||||
|
||||
import com.imegumii.Automata;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
@@ -24,9 +26,9 @@ public class TabPanel extends JTabbedPane {
|
||||
super();
|
||||
}
|
||||
|
||||
public void addGraph(String name, File image, String rawData)
|
||||
public void addGraph(String name, File image, Automata<String> a)
|
||||
{
|
||||
this.addTab(name, new GraphPanel(name, image, rawData));
|
||||
this.addTab(name, new GraphPanel(name, image, a));
|
||||
this.setSelectedIndex(this.getTabCount() - 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user