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"?> <?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="UMLClassView"> <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"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<xy x="20" y="20" width="500" height="400"/> <xy x="20" y="20" width="500" height="400"/>
@ -8,32 +8,97 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<component id="aeb5e" class="javax.swing.JTextArea" binding="textArea1" default-binding="true"> <tabbedpane id="97eb">
<constraints> <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"> <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="150" height="50"/> <preferred-size width="200" height="200"/>
</grid> </grid>
</constraints> </constraints>
<properties/> <properties/>
</component> <border type="none"/>
<component id="66adb" class="javax.swing.JButton" binding="convertButton" default-binding="true"> <children>
<constraints> <grid id="fc27a" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<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"/> <margin top="0" left="0" bottom="0" right="0"/>
</constraints> <constraints>
<properties> <tabbedpane title="File Mode"/>
<text value="Convert"/> </constraints>
</properties> <properties/>
</component> <border type="none"/>
<component id="54ac1" class="javax.swing.JTextArea" binding="textArea2" default-binding="true"> <children>
<constraints> <component id="71a25" class="javax.swing.JLabel">
<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"> <constraints>
<preferred-size width="150" height="50"/> <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>
<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"/>
</grid>
</constraints>
<properties/>
</component>
<component id="54ac1" class="javax.swing.JTextArea" binding="outputArea">
<constraints>
<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>
<properties>
<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> </constraints>
<properties> </vspacer>
<editable value="false"/>
</properties>
</component>
</children> </children>
</grid> </grid>
</form> </form>

View file

@ -5,30 +5,41 @@ import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
public class UMLClassView { public class UMLClassView {
private JTextArea textArea1; private JTextArea inputArea;
private JPanel panel1; private JPanel panel1;
private JButton convertButton; private JButton convertButton;
private JTextArea textArea2; private JTextArea outputArea;
private JTextField pathField;
private JButton convertFileButton;
private UMLManager manager;
public UMLClassView() { public UMLClassView() {
convertButton.addActionListener(e -> { convertButton.addActionListener(e -> {
String text = textArea1.getText(); String text = inputArea.getText();
UMLClass umlClass = new UMLClass(text); UMLClass umlClass = new UMLClass(text);
textArea2.setText(umlClass.toString()); outputArea.setText(umlClass.toString());
}); });
textArea1.addKeyListener(new KeyAdapter() { inputArea.addKeyListener(new KeyAdapter() {
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
String text = textArea1.getText(); String text = inputArea.getText();
UMLClass umlClass = new UMLClass(text); 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() { public JPanel getPanel1() {
return panel1; 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) { public static void main(String[] args) {
JFrame frame = new JFrame(); 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.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setExtendedState(Frame.MAXIMIZED_BOTH); frame.pack();
//frame.setExtendedState(Frame.MAXIMIZED_BOTH);
frame.setVisible(true); frame.setVisible(true);
} }

View file

@ -20,7 +20,6 @@ public class UMLField {
public UMLField(String line) { public UMLField(String line) {
String formatted = line.replaceAll("([+\\-~#]) ((?:[a-z]|[A-Z]|[0-1])+): (.*)", "$1;$3;$2"); String formatted = line.replaceAll("([+\\-~#]) ((?:[a-z]|[A-Z]|[0-1])+): (.*)", "$1;$3;$2");
System.out.println(formatted);
String[] formattedSplit = formatted.split(";"); String[] formattedSplit = formatted.split(";");
this.encapsulation = switch (formattedSplit[0]) { 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 javax.xml.parsers.ParserConfigurationException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
public class Main { public class XMLParser {
public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException { private Document doc;
String path = "C:\\Users\\nilsh\\Desktop\\Umlet/test.uxf"; public XMLParser(String path) {
try {
File inputFile = new File(path);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
doc = builder.parse(inputFile);
} catch (ParserConfigurationException | SAXException | IOException e){
e.printStackTrace();
}
}
File inputFile = new File(path); public ArrayList<String> getClassesText(){
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder(); ArrayList<String> classes = new ArrayList<>();
Document doc = builder.parse(inputFile);
System.out.println("Root element: " + doc.getDocumentElement().getNodeName());
System.out.println("---------");
NodeList nList = doc.getDocumentElement().getElementsByTagName("element"); NodeList nList = doc.getDocumentElement().getElementsByTagName("element");
for (int i = 0; i < nList.getLength(); i++) { for (int i = 0; i < nList.getLength(); i++) {
Node node = nList.item(i); Node node = nList.item(i);
System.out.println("Current Element: " + node.getNodeName());
if (node.getNodeType() == Node.ELEMENT_NODE){ if (node.getNodeType() == Node.ELEMENT_NODE){
@ -35,13 +41,13 @@ public class Main {
if(element.getElementsByTagName("id").item(0).getTextContent().equals("UMLClass")){ 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;
} }
} }