mirror of
https://github.com/Noratrieb/UMLetClassParser.git
synced 2026-01-14 08:35:07 +01:00
can now get java code from path to console
This commit is contained in:
parent
09b837ca29
commit
5b0937a8eb
6 changed files with 154 additions and 46 deletions
|
|
@ -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,32 +8,97 @@
|
|||
<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="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="50"/>
|
||||
<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/>
|
||||
</component>
|
||||
<component id="66adb" class="javax.swing.JButton" binding="convertButton" default-binding="true">
|
||||
<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">
|
||||
<preferred-size width="150" height="50"/>
|
||||
<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"/>
|
||||
</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>
|
||||
<properties>
|
||||
<editable value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
21
src/UMLManager.java
Normal 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()));
|
||||
}
|
||||
}
|
||||
|
|
@ -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 {
|
||||
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);
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document doc = builder.parse(inputFile);
|
||||
System.out.println("Root element: " + doc.getDocumentElement().getNodeName());
|
||||
System.out.println("---------");
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue