Skip to content

Commit 5dacfc2

Browse files
committed
Move main constructor to top for readability.
1 parent a2aece7 commit 5dacfc2

1 file changed

Lines changed: 75 additions & 73 deletions

File tree

src/main/java/com/brunomnsilva/smartgraph/graphview/SmartGraphPanel.java

Lines changed: 75 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,81 @@ THESE HAVE PRIORITY OVER ANY MODEL ANNOTATIONS (E.G., SmartLabelSource)
124124
//This value was obtained experimentally
125125
private static final int AUTOMATIC_LAYOUT_ITERATIONS = 20;
126126

127+
/**
128+
* Constructs a visualization of the graph referenced by
129+
* <code>theGraph</code>, using custom parameters.
130+
* <br/>
131+
* This is the only FXML-friendly constructor (there can only be one). If you need to instantiate the default
132+
* parameters (besides <code>graph</code>), they are the following:
133+
* <ul>
134+
* <li>properties - <code>new SmartGraphProperties()</code></li>
135+
* <li>placementStrategy - <code>new SmartCircularSortedPlacementStrategy()</code></li>
136+
* <li>cssFileURI - <code>new File("smartgraph.css").toURI()</code></li>
137+
* <li>automaticLayoutStrategy - <code>new ForceDirectedSpringGravityLayoutStrategy()</code></li>
138+
* </ul>
139+
*
140+
* @param theGraph underlying graph
141+
* @param properties custom properties
142+
* @param placementStrategy placement strategy
143+
* @param cssFile alternative css file, instead of default 'smartgraph.css'
144+
* @param layoutStrategy the automatic layout strategy to use
145+
* @throws IllegalArgumentException if any of the arguments is <code>null</code>
146+
*/
147+
public SmartGraphPanel(@NamedArg("graph") Graph<V, E> theGraph,
148+
@NamedArg("properties") SmartGraphProperties properties,
149+
@NamedArg("placementStrategy") SmartPlacementStrategy placementStrategy,
150+
@NamedArg("cssFileURI") URI cssFile,
151+
@NamedArg("automaticLayoutStrategy") ForceDirectedLayoutStrategy<V> layoutStrategy) {
152+
153+
Args.requireNotNull(theGraph, "theGraph");
154+
Args.requireNotNull(properties, "properties");
155+
Args.requireNotNull(placementStrategy, "placementStrategy");
156+
Args.requireNotNull(cssFile, "cssFile");
157+
Args.requireNotNull(layoutStrategy, "layoutStrategy");
158+
159+
this.theGraph = theGraph;
160+
this.graphProperties = properties;
161+
this.placementStrategy = placementStrategy;
162+
163+
this.edgesWithArrows = this.graphProperties.getUseEdgeArrow();
164+
165+
this.automaticLayoutStrategy = layoutStrategy;
166+
167+
this.vertexNodes = new HashMap<>();
168+
this.edgeNodes = new HashMap<>();
169+
this.connections = new HashMap<>();
170+
171+
// consumers initially are not set. This initialization is not necessary, but we make it explicit
172+
// for the sake of readability
173+
this.vertexClickConsumer = null;
174+
this.edgeClickConsumer = null;
175+
176+
//set stylesheet and class
177+
loadAndApplyStylesheet(cssFile);
178+
179+
initNodes();
180+
181+
enableDoubleClickListener();
182+
183+
//automatic layout initializations
184+
timer = new AnimationTimer() {
185+
186+
@Override
187+
public void handle(long now) {
188+
runAutomaticLayout();
189+
}
190+
};
191+
192+
this.automaticLayoutProperty = new SimpleBooleanProperty(false);
193+
this.automaticLayoutProperty.addListener((observable, oldValue, newValue) -> {
194+
if (newValue) {
195+
timer.start();
196+
} else {
197+
timer.stop();
198+
}
199+
});
200+
}
201+
127202
/**
128203
* Constructs a visualization of the graph referenced by
129204
* <code>theGraph</code>, using default properties, default circular
@@ -264,80 +339,7 @@ public SmartGraphPanel(Graph<V, E> theGraph, SmartGraphProperties properties,
264339
);
265340
}
266341

267-
/**
268-
* Constructs a visualization of the graph referenced by
269-
* <code>theGraph</code>, using custom parameters.
270-
* <br/>
271-
* This is the only FXML-friendly constructor (there can only be one). If you need to instantiate the default
272-
* parameters (besides <code>graph</code>), they are the following:
273-
* <ul>
274-
* <li>properties - <code>new SmartGraphProperties()</code></li>
275-
* <li>placementStrategy - <code>new SmartCircularSortedPlacementStrategy()</code></li>
276-
* <li>cssFileURI - <code>new File("smartgraph.css").toURI()</code></li>
277-
* <li>automaticLayoutStrategy - <code>new ForceDirectedSpringGravityLayoutStrategy()</code></li>
278-
* </ul>
279-
*
280-
* @param theGraph underlying graph
281-
* @param properties custom properties
282-
* @param placementStrategy placement strategy
283-
* @param cssFile alternative css file, instead of default 'smartgraph.css'
284-
* @param layoutStrategy the automatic layout strategy to use
285-
* @throws IllegalArgumentException if any of the arguments is <code>null</code>
286-
*/
287-
public SmartGraphPanel(@NamedArg("graph") Graph<V, E> theGraph,
288-
@NamedArg("properties") SmartGraphProperties properties,
289-
@NamedArg("placementStrategy") SmartPlacementStrategy placementStrategy,
290-
@NamedArg("cssFileURI") URI cssFile,
291-
@NamedArg("automaticLayoutStrategy") ForceDirectedLayoutStrategy<V> layoutStrategy) {
292-
293-
Args.requireNotNull(theGraph, "theGraph");
294-
Args.requireNotNull(properties, "properties");
295-
Args.requireNotNull(placementStrategy, "placementStrategy");
296-
Args.requireNotNull(cssFile, "cssFile");
297-
Args.requireNotNull(layoutStrategy, "layoutStrategy");
298-
299-
this.theGraph = theGraph;
300-
this.graphProperties = properties;
301-
this.placementStrategy = placementStrategy;
302-
303-
this.edgesWithArrows = this.graphProperties.getUseEdgeArrow();
304-
305-
this.automaticLayoutStrategy = layoutStrategy;
306-
307-
this.vertexNodes = new HashMap<>();
308-
this.edgeNodes = new HashMap<>();
309-
this.connections = new HashMap<>();
310-
311-
// consumers initially are not set. This initialization is not necessary, but we make it explicit
312-
// for the sake of readability
313-
this.vertexClickConsumer = null;
314-
this.edgeClickConsumer = null;
315-
316-
//set stylesheet and class
317-
loadAndApplyStylesheet(cssFile);
318-
319-
initNodes();
320-
321-
enableDoubleClickListener();
322342

323-
//automatic layout initializations
324-
timer = new AnimationTimer() {
325-
326-
@Override
327-
public void handle(long now) {
328-
runAutomaticLayout();
329-
}
330-
};
331-
332-
this.automaticLayoutProperty = new SimpleBooleanProperty(false);
333-
this.automaticLayoutProperty.addListener((observable, oldValue, newValue) -> {
334-
if (newValue) {
335-
timer.start();
336-
} else {
337-
timer.stop();
338-
}
339-
});
340-
}
341343

342344
private synchronized void runAutomaticLayout() {
343345
for (int i = 0; i < AUTOMATIC_LAYOUT_ITERATIONS; i++) {

0 commit comments

Comments
 (0)