1
14 package demo.layout.router;
15
16 import y.layout.router.BusRouter;
17 import y.module.BusRouterModule;
18 import y.option.IntOptionItem;
19 import y.option.OptionGroup;
20 import y.option.OptionHandler;
21 import y.option.OptionItem;
22 import y.option.ResourceBundleGuiFactory;
23
24 import java.util.MissingResourceException;
25
26
30 class BusRouterDemoModule extends BusRouterModule {
31
32 private static final String GROUP_LAYOUT = "GROUP_LAYOUT";
33 private static final String MIN_DISTANCE_TO_NODES = "MIN_DISTANCE_TO_NODES";
34 private static final String MIN_DISTANCE_TO_EDGES = "MIN_DISTANCE_TO_EDGES";
35
36
39 BusRouterDemoModule() {
40 optionsLayout = false;
41 optionsSelection = true;
42 optionsRouting = true;
43 }
44
45
50 protected void addOptionItems(final OptionHandler oh) {
51 OptionItem item;
52 OptionGroup og;
53
54 item = oh.addInt(MIN_DISTANCE_TO_NODES, 20);
55 item.setAttribute(IntOptionItem.ATTRIBUTE_MIN_VALUE, new Integer(1));
56 item = oh.addInt(MIN_DISTANCE_TO_EDGES, 10);
57 item.setAttribute(IntOptionItem.ATTRIBUTE_MIN_VALUE, new Integer(1));
58
59 og = new OptionGroup();
60 og.setAttribute(OptionGroup.ATTRIBUTE_TITLE, GROUP_LAYOUT);
61 og.addItem(oh.getItem(MIN_DISTANCE_TO_EDGES));
62 og.addItem(oh.getItem(MIN_DISTANCE_TO_NODES));
63
64 super.addOptionItems(oh);
65 }
66
67 protected BusRouter getBusRouter() {
68 return super.getBusRouter();
69 }
70
71
74 protected OptionHandler createOptionHandler() {
75 final OptionHandler oh = super.createOptionHandler();
76 ResourceBundleGuiFactory gf = new ResourceBundleGuiFactory();
77 try {
78 gf.addBundle(BusRouterModule.class.getName());
79 gf.addBundle(BusRouterDemo.class.getName());
80 } catch (MissingResourceException mre) {
81 }
82 oh.setGuiFactory(gf);
83
84 final BusRouter router = getBusRouter();
86 router.setPreferredBackboneSegmentCount(1);
87 initOptionHandler(oh, router);
88
89 return oh;
90 }
91
92
98 public void configure(BusRouter busRouter) {
99 super.configure(busRouter);
100 final OptionHandler oh = getOptionHandler();
101
102 busRouter.setMinimumDistanceToNode(oh.getInt(MIN_DISTANCE_TO_NODES));
103 busRouter.setMinimumDistanceToEdge(oh.getInt(MIN_DISTANCE_TO_EDGES));
104 }
105
106
112 protected void initOptionHandler(OptionHandler oh, BusRouter busRouter) {
113 super.initOptionHandler(oh, busRouter);
114
115 oh.set(MIN_DISTANCE_TO_NODES, new Integer(busRouter.getMinimumDistanceToNode()));
116 oh.set(MIN_DISTANCE_TO_EDGES, new Integer(busRouter.getMinimumDistanceToEdge()));
117 }
118
119 }
120