can now get java code from path to console

This commit is contained in:
nora 2020-11-19 19:43:06 +01:00
parent 09b837ca29
commit 5b0937a8eb
6 changed files with 154 additions and 46 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="UMLClassView">
<grid id="27dc6" binding="panel1" default-binding="true" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="panel1" default-binding="true" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
@ -8,7 +8,63 @@
<properties/>
<border type="none"/>
<children>
<component id="aeb5e" class="javax.swing.JTextArea" binding="textArea1" default-binding="true">
<tabbedpane id="97eb">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="200" height="200"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="fc27a" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title="File Mode"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="71a25" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Path:"/>
</properties>
</component>
<vspacer id="8c974">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="a9bfd" class="javax.swing.JTextField" binding="pathField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="fa74" class="javax.swing.JButton" binding="convertFileButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="convert"/>
</properties>
</component>
</children>
</grid>
<grid id="425fa" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title="Text Mode"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="aeb5e" class="javax.swing.JTextArea" binding="inputArea">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
@ -16,17 +72,9 @@
</constraints>
<properties/>
</component>
<component id="66adb" class="javax.swing.JButton" binding="convertButton" default-binding="true">
<component id="54ac1" class="javax.swing.JTextArea" binding="outputArea">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Convert"/>
</properties>
</component>
<component id="54ac1" class="javax.swing.JTextArea" binding="textArea2" default-binding="true">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
</constraints>
@ -34,6 +82,23 @@
<editable value="false"/>
</properties>
</component>
<component id="66adb" class="javax.swing.JButton" binding="convertButton" default-binding="true">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Convert"/>
</properties>
</component>
</children>
</grid>
</children>
</tabbedpane>
<vspacer id="6f6a3">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</form>

View file

@ -5,30 +5,41 @@ import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class UMLClassView {
private JTextArea textArea1;
private JTextArea inputArea;
private JPanel panel1;
private JButton convertButton;
private JTextArea textArea2;
private JTextArea outputArea;
private JTextField pathField;
private JButton convertFileButton;
private UMLManager manager;
public UMLClassView() {
convertButton.addActionListener(e -> {
String text = textArea1.getText();
String text = inputArea.getText();
UMLClass umlClass = new UMLClass(text);
textArea2.setText(umlClass.toString());
outputArea.setText(umlClass.toString());
});
textArea1.addKeyListener(new KeyAdapter() {
inputArea.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
String text = textArea1.getText();
String text = inputArea.getText();
UMLClass umlClass = new UMLClass(text);
outputArea.setText(umlClass.toString());
}
});
textArea2.setText(umlClass.toString());
convertFileButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String path = pathField.getText();
XMLParser parser = new XMLParser(path);
manager.parseClasses(parser.getClassesText());
}
});
}
@ -36,4 +47,8 @@ public class UMLClassView {
public JPanel getPanel1() {
return panel1;
}
public void setManager(UMLManager manager) {
this.manager = manager;
}
}

View file

@ -5,11 +5,13 @@ public class UMLConverterMain {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setContentPane( new UMLClassView().getPanel1());
UMLClassView view = new UMLClassView();
new UMLManager(view);
frame.setContentPane(view.getPanel1());
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
frame.pack();
//frame.setExtendedState(Frame.MAXIMIZED_BOTH);
frame.setVisible(true);
}

View file

@ -20,7 +20,6 @@ public class UMLField {
public UMLField(String line) {
String formatted = line.replaceAll("([+\\-~#]) ((?:[a-z]|[A-Z]|[0-1])+): (.*)", "$1;$3;$2");
System.out.println(formatted);
String[] formattedSplit = formatted.split(";");
this.encapsulation = switch (formattedSplit[0]) {

21
src/UMLManager.java Normal file
View file

@ -0,0 +1,21 @@
import java.util.ArrayList;
public class UMLManager {
UMLClassView view;
public UMLManager(UMLClassView view){
this.view = view;
view.setManager(this);
}
public void parseClasses(ArrayList<String> classesText){
ArrayList<UMLClass> classes = new ArrayList<>();
for (String text : classesText){
classes.add(new UMLClass(text));
}
classes.forEach(e -> System.out.println(e.toString()));
}
}

View file

@ -9,25 +9,31 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
public class Main {
public class XMLParser {
public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException {
String path = "C:\\Users\\nilsh\\Desktop\\Umlet/test.uxf";
private Document doc;
public XMLParser(String path) {
try {
File inputFile = new File(path);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(inputFile);
System.out.println("Root element: " + doc.getDocumentElement().getNodeName());
System.out.println("---------");
doc = builder.parse(inputFile);
} catch (ParserConfigurationException | SAXException | IOException e){
e.printStackTrace();
}
}
public ArrayList<String> getClassesText(){
ArrayList<String> classes = new ArrayList<>();
NodeList nList = doc.getDocumentElement().getElementsByTagName("element");
for (int i = 0; i < nList.getLength(); i++) {
Node node = nList.item(i);
System.out.println("Current Element: " + node.getNodeName());
if (node.getNodeType() == Node.ELEMENT_NODE){
@ -35,13 +41,13 @@ public class Main {
if(element.getElementsByTagName("id").item(0).getTextContent().equals("UMLClass")){
System.out.println("class");
}
String classBody = element.getElementsByTagName("panel_attributes").item(0).getTextContent();
classes.add(classBody);
}
}
}
return classes;
}
}