1616package guru .nidi .graphviz .engine ;
1717
1818import javax .annotation .Nullable ;
19+ import java .io .File ;
1920import java .util .regex .Matcher ;
2021import java .util .regex .Pattern ;
2122
@@ -41,24 +42,27 @@ public final class Options {
4142 FORMAT = Pattern .compile ("format:'(.*?)'" ),
4243 ENGINE = Pattern .compile ("engine:'(.*?)'" ),
4344 MEMORY = Pattern .compile ("totalMemory:'(.*?)'" ),
44- Y_INVERT = Pattern .compile ("yInvert:(.*?)" );
45+ Y_INVERT = Pattern .compile ("yInvert:(.*?)" ),
46+ BASE_DIR = Pattern .compile ("basedir:'(.*?)'" );
4547
4648 final Engine engine ;
4749 final Format format ;
4850 @ Nullable
4951 final Integer totalMemory ;
5052 @ Nullable
5153 final Boolean yInvert ;
54+ final File basedir ;
5255
53- private Options (Engine engine , Format format , @ Nullable Integer totalMemory , @ Nullable Boolean yInvert ) {
56+ private Options (Engine engine , Format format , @ Nullable Integer totalMemory , @ Nullable Boolean yInvert , File basedir ) {
5457 this .engine = engine ;
5558 this .format = format ;
5659 this .totalMemory = totalMemory ;
5760 this .yInvert = yInvert ;
61+ this .basedir = basedir ;
5862 }
5963
6064 public static Options create () {
61- return new Options (Engine .DOT , Format .SVG , null , null );
65+ return new Options (Engine .DOT , Format .SVG , null , null , new File ( "." ) );
6266 }
6367
6468 public static Options fromJson (String json ) {
@@ -70,38 +74,43 @@ public static Options fromJson(String json) {
7074 final boolean hasMemory = memory .find ();
7175 final Matcher yInvert = Y_INVERT .matcher (json );
7276 final boolean hasYInvert = yInvert .find ();
77+ final Matcher basedir = BASE_DIR .matcher (json );
78+ basedir .find ();
79+
7380 return new Options (
7481 Engine .valueOf (engine .group (1 )),
7582 Format .valueOf (format .group (1 )),
7683 hasMemory ? Integer .parseInt (memory .group (1 )) : null ,
77- hasYInvert ? Boolean .parseBoolean (yInvert .group (1 )) : null );
84+ hasYInvert ? Boolean .parseBoolean (yInvert .group (1 )) : null ,
85+ new File (basedir .group (1 )));
7886 }
7987
8088 public Options engine (Engine engine ) {
81- return new Options (engine , format , totalMemory , yInvert );
89+ return new Options (engine , format , totalMemory , yInvert , basedir );
8290 }
8391
8492 public Options format (Format format ) {
85- return new Options (engine , format , totalMemory , yInvert );
93+ return new Options (engine , format , totalMemory , yInvert , basedir );
8694 }
8795
8896 public Options totalMemory (@ Nullable Integer totalMemory ) {
89- return new Options (engine , format , totalMemory , yInvert );
97+ return new Options (engine , format , totalMemory , yInvert , basedir );
9098 }
9199
92100 public Options yInvert (@ Nullable Boolean yInvert ) {
93- return new Options (engine , format , totalMemory , yInvert );
101+ return new Options (engine , format , totalMemory , yInvert , basedir );
94102 }
95103
96- public Options fontAdjust ( double fontAdjust ) {
97- return new Options (engine , format , totalMemory , yInvert );
104+ public Options basedir ( File basedir ) {
105+ return new Options (engine , format , totalMemory , yInvert , basedir );
98106 }
99107
100108 public String toJson (boolean raw ) {
101109 final String form = "format:'" + (raw ? format : format .vizName ) + "'" ;
102110 final String eng = ",engine:'" + (raw ? engine : engine .toString ().toLowerCase (ENGLISH )) + "'" ;
103111 final String mem = totalMemory == null ? "" : (",totalMemory:'" + totalMemory + "'" );
104112 final String yInv = yInvert == null ? "" : (",yInvert:" + yInvert );
105- return "{" + form + eng + mem + yInv + "}" ;
113+ final String base = ",basedir:'" + basedir .getAbsolutePath () + "'" ;
114+ return "{" + form + eng + mem + yInv + base + ",images: [ { path: '/Users/nidi/idea/graphviz-java-parent/out2.png', width: '400px', height: '300px' }]}" ;
106115 }
107116}
0 commit comments