Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

plantuml java

import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.SourceStringReader;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.sequencediagram.Message;
import net.sourceforge.plantuml.sequencediagram.Participant;
import net.sourceforge.plantuml.sequencediagram.SequenceDiagram;
import net.sourceforge.plantuml.sequencediagram.SequenceDiagramFactory;
import net.sourceforge.plantuml.skin.ArrowConfiguration;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import static com.google.common.base.Preconditions.checkState;

public class PlantUMLDemoMain {
    public static void main(String[] args) throws Exception {
        generateFromStringSource(new File("from-string.png"));
        generateFromApi(new File("from-api.png"));
    }

    private static void generateFromApi(File file) throws IOException {
        // 1. setup:
        SequenceDiagramFactory f = new SequenceDiagramFactory();
        SequenceDiagram diagram = f.createEmptyDiagram();

        // 2. Build the diagram:
        // "Bob -> Alice : hello"
        // See net.sourceforge.plantuml.sequencediagram.command.CommandArrow#executeArg
        Display bobD = Display.getWithNewlines("Bob");
        Participant bobP = diagram.getOrCreateParticipant("Bob", bobD);

        Display aliceD = Display.getWithNewlines("Alice");
        Participant aliceP = diagram.getOrCreateParticipant("Alice", aliceD);

        Display label = Display.getWithNewlines("hello");
        ArrowConfiguration config = ArrowConfiguration.withDirectionNormal();

        Message msg = new Message(bobP, aliceP, label, config, diagram.getNextMessageNumber());

        checkState(null == diagram.addMessage(msg));

        // 3. Output the diagram
        // See net.sourceforge.plantuml.SourceStringReader#generateImage
        diagram.makeDiagramReady();
        checkState(1 == diagram.getNbImages());
        try (OutputStream os = new FileOutputStream(file)) {
            ImageData imageData = diagram.exportDiagram(os, 0, new FileFormatOption(FileFormat.PNG));
            System.out.println("generateFromApi: " + diagram.getDescription().getDescription());
        }
    }

    private static void generateFromStringSource(File file) throws IOException {
        String source = "@startuml
";
        source += "Bob -> Alice : hello
";
        source += "@enduml
";

        SourceStringReader reader = new SourceStringReader(source);
        // Write the first image to "png"
        String desc = reader.generateImage(file);
        // Return a null string if no generation
        System.out.println("generateFromStringSource: " + desc);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: get bimap by uri in android 
Java :: variable for java 
Java :: concatenar java 
Java :: java secureRandom certain range 
Java :: How to Access Elements of an Array in Java? 
Java :: Reverse Order Output for Java Do-While Loop 
Java :: first method in jdbc 
Java :: Java/Perl - "sprintf function in java" or "string format" 
Java :: load list of integers from console 
Java :: getcokor from drawable in java android studio 
Java :: jsp form upload file 
Java :: search for a string in byte array 
Java :: JAVA XML COURSE 
Java :: @android:color/system_neutral1_1000 
Java :: java reverse serach 
Java :: java 8 validate based on pair of strings 
Java :: How can i stub Instant object using powermock 
Java :: springBoot Disable a Specific Auto-Configuration 
Java :: how to declare and allocate memory to array in java 
Java :: system.out.print 
Java :: How to handle exceptions thrown by application with another servlet? 
Java :: java circular buffer implementation on array 
Java :: convert kotlin to java online editor 
Java :: bukkit scheduler self cancelling task 
Java :: odd numbers in java 
Java :: split each character in a string (java) 
Java :: java check if instance of subclass 
Java :: javafx access fxml elements 
Java :: java, how to find the most repeated character 
Java :: postfix operator in java 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =