Skip to content

Commit 32c8094

Browse files
committed
Merge branch 'master' of github.com:miho/VWorkflows
2 parents 99fa463 + 1c46453 commit 32c8094

File tree

2 files changed

+49
-13
lines changed

2 files changed

+49
-13
lines changed

VWorkflows-Core/src/main/java/eu/mihosoft/vrl/workflow/VisualizationRequest.java

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public interface VisualizationRequest extends PropertyStorage{
5757
*/
5858
static final String KEY_NODE_NOT_REMOVABLE = "visualization-request:skin:node-not-removable";
5959

60+
/**
61+
* Defines whether connector prefers top-down layout.
62+
*/
63+
static final String KEY_CONNECTOR_PREFER_TOP_DOWN = "visualization-request:connector:prefer-top-down";
64+
6065
public void setStyle(String style);
6166
public String getStyle();
6267
}

VWorkflows-FX/src/main/java/eu/mihosoft/vrl/workflow/fx/FXFlowNodeSkin.java

+44-13
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import eu.mihosoft.vrl.workflow.VisualizationRequest;
4242
import eu.mihosoft.vrl.workflow.skin.VNodeSkin;
4343

44-
4544
import javafx.beans.property.IntegerProperty;
4645
import javafx.beans.property.ObjectProperty;
4746
import javafx.beans.property.SimpleIntegerProperty;
@@ -143,7 +142,7 @@ protected FlowNodeWindow createNodeWindow() {
143142
cShape.getNode().setCache(!flowNodeWindow.isResizing());
144143
});
145144
});
146-
145+
147146
flowNodeWindow.resizingProperty().addListener((ov) -> {
148147
if (flowNodeWindow.isResizing()) {
149148
flowNodeWindow.setCache(false);
@@ -177,7 +176,6 @@ private void init() {
177176
addConnector(connector);
178177
}
179178

180-
181179
getModel().getConnectors().addListener(
182180
(ListChangeListener.Change<? extends Connector> change) -> {
183181
boolean numConnectorsHasChanged = false;
@@ -192,7 +190,7 @@ private void init() {
192190
// // TODO update item
193191
// }
194192
// else
195-
193+
196194
if (change.wasRemoved()) {
197195
numConnectorsHasChanged = true;
198196
// removed
@@ -335,12 +333,37 @@ private void layoutConnector(Connector c, boolean updateOthers) {
335333

336334
ConnectorShape connectorShape = connectors.get(c);
337335

338-
connectorShape.getNode().setLayoutX(computeConnectorXValue(c) - connectorShape.getRadius() );
339-
connectorShape.getNode().setLayoutY(computeConnectorYValue(c) - connectorShape.getRadius() );
336+
connectorShape.getNode().setLayoutX(computeConnectorXValue(c) - connectorShape.getRadius());
337+
connectorShape.getNode().setLayoutY(computeConnectorYValue(c) - connectorShape.getRadius());
340338

341339
Collection<Connection> conns = getModel().getFlow().
342340
getConnections(c.getType()).getAllWith(c);
341+
//----------------------------B
342+
343+
Optional<Boolean> preferTD = c.getVisualizationRequest().
344+
get(VisualizationRequest.KEY_CONNECTOR_PREFER_TOP_DOWN);
345+
boolean preferTopDown = preferTD.orElse(false);
346+
347+
if (preferTopDown && conns.isEmpty()) {
348+
int oldEdgeIndex = connectorToIndexMap.get(c);
349+
350+
int newEdgeIndex = c.isInput() ? TOP : BOTTOM;
351+
352+
connectorShape.getNode().setLayoutX(computeConnectorXValue(c)- connectorShape.getRadius());
353+
connectorShape.getNode().setLayoutY(computeConnectorYValue(c)- connectorShape.getRadius());
354+
355+
if (newEdgeIndex != oldEdgeIndex) {
343356

357+
shapeLists.get(oldEdgeIndex).remove(connectorShape);
358+
shapeLists.get(newEdgeIndex).add(connectorShape);
359+
connectorToIndexMap.put(c, newEdgeIndex);
360+
361+
// update all other connectors
362+
layoutConnectors();
363+
}
364+
}
365+
366+
//----------------------------E
344367
if (conns.isEmpty()) {
345368
return;
346369
}
@@ -410,8 +433,10 @@ private void layoutConnector(Connector c, boolean updateOthers) {
410433
}
411434
} // end if switchEdges
412435

413-
connectorShape.getNode().setLayoutX(computeConnectorXValue(c) - connectorShape.getRadius());
414-
connectorShape.getNode().setLayoutY(computeConnectorYValue(c) - connectorShape.getRadius());
436+
connectorShape.getNode().setLayoutX(computeConnectorXValue(c)
437+
- connectorShape.getRadius());
438+
connectorShape.getNode().setLayoutY(computeConnectorYValue(c)
439+
- connectorShape.getRadius());
415440

416441
// System.out.println("c: " + c);
417442
if (updateOthers) {
@@ -535,15 +560,21 @@ protected void addConnector(final Connector connector) {
535560
connectorNode.setManaged(false);
536561

537562
connectors.put(connector, connectorShape);
538-
563+
//--------------------B
564+
Optional<Boolean> preferTD = connector.getVisualizationRequest().
565+
get(VisualizationRequest.KEY_CONNECTOR_PREFER_TOP_DOWN);
566+
boolean preferTopDown = preferTD.orElse(false);
567+
int inputDefault = preferTopDown ? TOP : LEFT;
568+
int outputDefault = preferTopDown ? BOTTOM : RIGHT;
569+
//--------------------E
539570
if (connector.isInput()) {
540571
// inputList.add(connectorNode);
541-
shapeLists.get(LEFT).add(connectorShape);
542-
connectorToIndexMap.put(connector, LEFT);
572+
shapeLists.get(inputDefault).add(connectorShape);
573+
connectorToIndexMap.put(connector, inputDefault);
543574
} else if (connector.isOutput()) {
544575
// outputList.add(connectorNode);
545-
shapeLists.get(RIGHT).add(connectorShape);
546-
connectorToIndexMap.put(connector, RIGHT);
576+
shapeLists.get(outputDefault).add(connectorShape);
577+
connectorToIndexMap.put(connector, outputDefault);
547578
}
548579

549580
node.boundsInLocalProperty().addListener((ov, oldValue, newValue) -> {

0 commit comments

Comments
 (0)