UML API for Java

I'm looking for APIs that can draw UML class diagrams and represent them in a JPanel (or any other suitable UI object) for a windowed application. It has to be built into the application, so I'm not looking for some standalone tool that can generate UML based on java files or some plugin. I need real jars that can be implemented to create class diagrams so I can use them in a windowed application. I researched a few, but all the sources I find are standalone programs or cannot be implemented in the application and you need to distract the user's attention from the application. I am using NetBeans IDE but I also have Eclipse installed.

DECIDE:

I used the PlantUML API. I manually enter a string according to PlantUML input language syntax and then used the simple and simple generateImage method to populate an array of bytes, which is then converted to an image and saved to the desktop. This matches what I wanted because it allows the user to focus on my application and mine alone. Alternatively, you can create a buffered image in the window or something else. The PlantUML API needs to be imported into an app package. This code creates an image on my desktop (don't forget to change the directory path) with a UML class image for the Person class:

public class PaintUML {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws IOException, InterruptedException {
    // TODO code application logic here
    ByteArrayOutputStream bous = new ByteArrayOutputStream();
    String source = "@startuml\n";
    source += "class Person {\n";
    source += "String name\n";
    source += "int age\n";
    source += "int money\n";
    source += "String getName()\n";
    source += "void setName(String name)\n";
    source += "}\n";
    source += "@enduml\n";

    SourceStringReader reader = new SourceStringReader(source);
    // Write the first image to "png"
    String desc = reader.generateImage(bous);
    // Return a null string if no generation
    byte [] data = bous.toByteArray();

    InputStream in = new ByteArrayInputStream(data);
    BufferedImage convImg = ImageIO.read(in);

    ImageIO.write(convImg, "png", new File("C:\\Users\\Aaron\\Desktop\\image.png"));

    System.out.print(desc);
}
}

      

+3


source to share


2 answers


Have you seen PlantUML?

http://plantuml.sourceforge.net



It is open source, so you can pick a few bits to suit.

+3


source


Have a look at Eclipse UML2 API and Eclipse Papyrus . They should provide the functionality you are looking for. You may need some extra work to support drawing in JPanels.



The Eclipse UML2 API provides a Java interface to the UML2 metamodel. Papyrus is a set of components that allows you to create diagrams and graphical editors for UML models.

+1


source







All Articles