1
28 package demo.layout.partial;
29
30 import y.layout.Layouter;
31 import y.layout.orthogonal.OrthogonalGroupLayouter;
32 import y.layout.partial.PartialLayouter;
33 import y.option.OptionHandler;
34 import y.view.Graph2DLayoutExecutor;
35
36 import javax.swing.AbstractAction;
37 import javax.swing.Action;
38 import javax.swing.JToolBar;
39 import java.awt.EventQueue;
40 import java.awt.event.ActionEvent;
41 import java.util.Locale;
42
43
62 public class OrthogonalPartialLayoutDemo extends PartialLayoutBase {
63
64 public OrthogonalPartialLayoutDemo() {
65 this(null);
66 }
67
68 public OrthogonalPartialLayoutDemo(final String helpFilePath) {
69 super(helpFilePath);
70 }
71
72
75 protected void loadInitialGraph() {
76 loadGraph("resource/orthogonal.graphml");
77 }
78
79
82 protected JToolBar createToolBar() {
83 JToolBar toolBar = super.createToolBar();
84
85 final OrthogonalLayoutAction orthogonalLayoutAction = new OrthogonalLayoutAction("Orthogonal Layout");
86 orthogonalLayoutAction.putValue(Action.SHORT_DESCRIPTION, "Orthogonal Layout");
87 toolBar.add(orthogonalLayoutAction);
88
89 return toolBar;
90 }
91
92 protected OptionHandler createOptionHandler() {
93 final OptionHandler layoutOptionHandler = new OptionHandler("Option Table");
94
95 layoutOptionHandler.addEnum("Subgraph Layout",
96 new Object[]{"Orthogonal Layout", "Unchanged"}, 0);
97 layoutOptionHandler.addInt("Grid Size", 10, 1, 50);
98 layoutOptionHandler.addEnum("Component Assignment",
99 new Object[]{"Single Nodes", "Connected Graphs", "Same Component"}, 0);
100 layoutOptionHandler.addBool("Use Snapping", true);
101 layoutOptionHandler.addBool("Use Sketch", false);
102 layoutOptionHandler.addBool("Resize Fixed Groups", true);
103
104 return layoutOptionHandler;
105 }
106
107 protected Layouter createConfiguredPartialLayouter() {
108 final PartialLayouter partialLayouter = new PartialLayouter();
109
110 if (optionHandler != null) {
111 switch (optionHandler.getEnum("Subgraph Layout")) {
112 default:
113 case 0:
114 partialLayouter.setCoreLayouter(getOrthogonalLayouter());
115 break;
116 case 1:
117 }
119 partialLayouter.setPositioningStrategy(
120 optionHandler.getBool(
121 "Use Sketch") ? PartialLayouter.SUBGRAPH_POSITIONING_STRATEGY_FROM_SKETCH : PartialLayouter.SUBGRAPH_POSITIONING_STRATEGY_BARYCENTER);
122
123 switch (optionHandler.getEnum("Component Assignment")) {
124 default:
125 case 0:
126 partialLayouter.setComponentAssignmentStrategy(PartialLayouter.COMPONENT_ASSIGNMENT_STRATEGY_SINGLE);
127 break;
128 case 1:
129 partialLayouter.setComponentAssignmentStrategy(PartialLayouter.COMPONENT_ASSIGNMENT_STRATEGY_CONNECTED);
130 break;
131 case 2:
132 partialLayouter.setComponentAssignmentStrategy(PartialLayouter.COMPONENT_ASSIGNMENT_STRATEGY_CUSTOMIZED);
133 break;
134 }
135 partialLayouter.setConsiderNodeAlignment(optionHandler.getBool("Use Snapping"));
136 partialLayouter.setFixedGroupResizingEnabled(optionHandler.getBool("Resize Fixed Groups"));
137 partialLayouter.setMinimalNodeDistance(optionHandler.getInt("Grid Size"));
138 }
139 partialLayouter.setEdgeRoutingStrategy(PartialLayouter.EDGE_ROUTING_STRATEGY_ORTHOGONAL);
140 partialLayouter.setLayoutOrientation(PartialLayouter.ORIENTATION_NONE);
141 return partialLayouter;
142 }
143
144
148 private OrthogonalGroupLayouter getOrthogonalLayouter() {
149 OrthogonalGroupLayouter layouter = new OrthogonalGroupLayouter();
150 if (optionHandler != null) {
151 layouter.setGrid(optionHandler.getInt("Grid Size"));
152 }
153 return layouter;
154 }
155
156
159 class OrthogonalLayoutAction extends AbstractAction {
160 OrthogonalLayoutAction(String name) {
161 super(name);
162 }
163
164 public void actionPerformed(ActionEvent e) {
165 Graph2DLayoutExecutor executor = new Graph2DLayoutExecutor();
166 executor.getLayoutMorpher().setEasedExecution(true);
167 executor.getLayoutMorpher().setSmoothViewTransform(true);
168 executor.doLayout(view, getOrthogonalLayouter());
169 view.updateView();
170 }
171 }
172
173 public static void main(String[] args) {
174 EventQueue.invokeLater(new Runnable() {
175 public void run() {
176 Locale.setDefault(Locale.ENGLISH);
177 initLnF();
178 (new OrthogonalPartialLayoutDemo("resource/orthogonallayouthelp.html"))
179 .start("Orthogonal Partial Layouter Demo");
180 }
181 });
182 }
183 }
184