1
14
15 package demo.layout.module;
16
17 import demo.layout.withoutview.DiagonalLayouter;
18
19 import java.io.FileInputStream;
20 import java.io.FileOutputStream;
21 import java.io.IOException;
22 import java.util.Locale;
23 import java.util.MissingResourceException;
24 import java.util.Properties;
25 import y.module.LayoutModule;
26 import y.module.YModule;
27 import y.option.OptionHandler;
28 import y.option.PropertiesIOHandler;
29 import y.option.ResourceBundleGuiFactory;
30
31
46 public class DiagonalLayoutModule extends LayoutModule
47 {
48 public DiagonalLayoutModule()
49 {
50 super("DIAGONAL", "yWorks Layout Team", "Wrapper for DiagonalLayouter");
51 }
52
53 protected OptionHandler createOptionHandler()
54 {
55 DiagonalLayouter layouter = new DiagonalLayouter();
56 OptionHandler op = new OptionHandler(getModuleName());
57 op.addDouble("MINIMAL_NODE_DISTANCE", layouter.getMinimalNodeDistance());
58 return op;
59 }
60
61 protected void mainrun()
62 {
63 DiagonalLayouter layouter = new DiagonalLayouter();
64 OptionHandler op = getOptionHandler();
65 layouter.setMinimalNodeDistance(op.getDouble("MINIMAL_NODE_DISTANCE"));
66 launchLayouter(layouter);
67 }
68
69
70
73 public static void main(String[] args)
74 {
75 if (args.length > 1){
77 Locale.setDefault(new Locale(args[0],args[1]));
78 } else if (args.length > 0){
79 Locale.setDefault(new Locale(args[0],""));
80 }
81
82 System.out.println("Executing using Locale "+Locale.getDefault().getDisplayName());
83
84 YModule module = new DiagonalLayoutModule();
86 OptionHandler oh = module.getOptionHandler();
87
88 try{
90 ResourceBundleGuiFactory gf = new ResourceBundleGuiFactory();
91
92 gf.addBundle("demo.layout.module.OptionHandler");
94
95 gf.addBundle(module.getClass().getName());
97 oh.setGuiFactory(gf);
98 } catch (MissingResourceException mre){
99 System.err.println("Could not find resources! "+mre);
100 }
101
102
104 Properties p = new Properties();
106 try{
107 FileInputStream fis = new FileInputStream(module.getClass().getName()+"Settings.properties");
109 p.load(fis);
110 fis.close();
111 } catch (IOException ioe){
112 System.err.println(ioe);
113 }
114 oh.setOptionsIOHandler(new PropertiesIOHandler(p));
116
117 oh.read();
119
120 oh.showEditor();
122
123 try{
125 FileOutputStream fos = new FileOutputStream(module.getClass().getName()+"Settings.properties");
126 p.store(fos, "Saved Settings for "+module.getClass().getName());
127 fos.flush();
128 fos.close();
129 } catch (IOException ioe){
130 System.err.println(ioe);
131 }
132
133 System.exit(0);
135 }
136
137 }
138
139