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