public ActionsWithRoutingPolicyTest() { mainLayer = new LayerWidget(this); addChild(mainLayer); LayerWidget connLayer = new LayerWidget(this); addChild(connLayer); Widget source = createLabel("Source", 50, 200, Color.GREEN); Widget target = createLabel("Target", 450, 200, Color.GREEN); connection = new ConnectionWidget(this); connection.setSourceAnchor( AnchorFactory.createDirectionalAnchor( source, AnchorFactory.DirectionalAnchorKind.HORIZONTAL)); connection.setTargetAnchor( AnchorFactory.createDirectionalAnchor( target, AnchorFactory.DirectionalAnchorKind.HORIZONTAL)); connection.setTargetAnchorShape(AnchorShape.TRIANGLE_FILLED); connection.setPaintControlPoints(true); connection.setControlPointShape(PointShape.SQUARE_FILLED_BIG); connection.setRouter(RouterFactory.createOrthogonalSearchRouter(mainLayer)); connection .getActions() .addAction( ActionFactory.createAddRemoveControlPointAction( 1.0, 5.0, ConnectionWidget.RoutingPolicy.UPDATE_END_POINTS_ONLY)); connection .getActions() .addAction( ActionFactory.createMoveControlPointAction( ActionFactory.createFreeMoveControlPointProvider(), ConnectionWidget.RoutingPolicy.UPDATE_END_POINTS_ONLY)); connLayer.addChild(connection); }
public static Element deserialize(PaletteScene scene, Element rootElement) { HashMap<String, PluginNode> registeredNodeMap = new HashMap<String, PluginNode>(); Element pluginsElement = rootElement.getChild("plugins"); List plugins = pluginsElement.getChildren("plugin"); ArrayList<AbstractPlugin> addedPlugins = new ArrayList<AbstractPlugin>(); PluginUtilities pm = PluginUtilities.getDefault(); String pluginID, pluginName, isHudVisible, isParameterPanelHidden; Element pluginElement; for (Object plugin : plugins) { pluginElement = (Element) plugin; pluginID = pluginElement.getAttributeValue(ATT_PLUGIN_ID); pluginName = pluginElement.getAttributeValue(ATT_PLUGIN_NAME); isHudVisible = pluginElement.getAttributeValue(ATT_HUD_VISIBLE); isHudVisible = isHudVisible == null ? "false" : isHudVisible; isParameterPanelHidden = pluginElement.getAttributeValue(ATT_PLUGIN_HIDDEN); isParameterPanelHidden = isParameterPanelHidden == null ? "false" : isParameterPanelHidden; AbstractPlugin p = pm.instantiate(pluginID, pluginName, scene.getDefaultPaletteModel()); p.setParameterPanelHidden(Boolean.parseBoolean(isParameterPanelHidden)); if (p instanceof IParameterPanel) { ((IParameterPanel) p).loadSavedWorkspaceParameters(pluginElement.getChild("parameters")); } if (p instanceof HudInterface && Boolean.parseBoolean(isHudVisible)) { actionShowHUD(p); } addedPlugins.add(p); PluginNode thisNode = new PluginNode(p); registeredNodeMap.put(thisNode.getName(), thisNode); Widget nodeWidget = scene.addNode(thisNode); int x = Integer.parseInt(pluginElement.getAttributeValue(ATT_PLUGIN_X)); int y = Integer.parseInt(pluginElement.getAttributeValue(ATT_PLUGIN_Y)); // nodeWidget.setPreferredLocation(new Point(x, y)); nodeWidget.setPreferredLocation(new Point(x, y)); } scene.revalidate(); Lookup.Result<IPluginsAdded> pluginsAdded = LatizLookup.getDefault().lookupResult(IPluginsAdded.class); for (IPluginsAdded ipa : pluginsAdded.allInstances()) { ipa.pluginsAdded(scene, addedPlugins); } List connections = rootElement.getChild("connections").getChildren("connection"); Element connectionElement; for (Object connection : connections) { connectionElement = (Element) connection; ConnectorEdge edge = new ConnectorEdge(connectionElement.getAttributeValue(ATT_EDGE_ID)); PluginNode sourceNode = registeredNodeMap.get(connectionElement.getAttributeValue(ATT_EDGE_SOURCE)); PluginNode targetNode = registeredNodeMap.get(connectionElement.getAttributeValue(ATT_EDGE_TARGET)); // Create connection panels. Lookup.Result<IPluginConnection> pcis = LatizLookup.getDefault().lookupResult(IPluginConnection.class); for (IPluginConnection pci : pcis.allInstances()) { pci.connectionMade(scene, sourceNode.getPlugin(), targetNode.getPlugin()); } scene.addEdge(edge); scene.setEdgeSource(edge, sourceNode); scene.setEdgeTarget(edge, targetNode); // Apply vertices ArrayList<Point> controlPoints = new ArrayList<Point>(); List verts = connectionElement.getChild("verts").getChildren(); Element vertElement; for (Object vert : verts) { vertElement = (Element) vert; int x = Integer.parseInt(vertElement.getAttributeValue(ATT_VERT_X)); int y = Integer.parseInt(vertElement.getAttributeValue(ATT_VERT_Y)); controlPoints.add(new Point(x, y)); } ConnectionWidget cw = (ConnectionWidget) scene.findWidget(edge); String router = connectionElement.getAttributeValue(ATT_EDGE_ROUTER); if (router.equals("FreeRouter")) { cw.setRouter(RouterFactory.createFreeRouter()); } else if (router.equals("DirectRouter")) { cw.setRouter(RouterFactory.createDirectRouter()); } else if (router.equals("OrthogonalSearchRouter")) { cw.setRouter(RouterFactory.createOrthogonalSearchRouter(scene.getMainLayer())); } cw.setControlPoints(controlPoints, true); } // Deserialize I/O connections Element ioConnectionsElement = rootElement.getChild("ioConnections"); if (ioConnectionsElement == null) { return rootElement; } List<String> ioConnections = scene.getDefaultPaletteModel().getConnections(); ioConnections.clear(); for (Object o : ioConnectionsElement.getChildren()) { ioConnections.add(((Element) o).getAttributeValue("name")); } // Annotations Element annotationsElement = rootElement.getChild("annotations"); Element annotationElement; AnnotationWidget aw; if (annotationsElement != null) { for (Object o : annotationsElement.getChildren()) { annotationElement = (Element) o; aw = new AnnotationWidget(scene, annotationElement.getAttributeValue("text")); String fontName = annotationElement.getAttributeValue("font"); int fontSize = Integer.parseInt(annotationElement.getAttributeValue("fontSize")); int fontStyle = Integer.parseInt(annotationElement.getAttributeValue("fontStyle")); Font font = new Font(fontName, fontStyle, fontSize); aw.setFont(font); int xLoc = Integer.parseInt(annotationElement.getAttributeValue("xLoc")); int yLoc = Integer.parseInt(annotationElement.getAttributeValue("yLoc")); aw.setPreferredLocation(new Point(xLoc, yLoc)); aw.setForeground(Color.decode(annotationElement.getAttributeValue("fore"))); aw.setBackground(Color.decode(annotationElement.getAttributeValue("back"))); aw.setOrientation(Orientation.valueOf(annotationElement.getAttributeValue("orient"))); scene.addChild(aw); } } scene.validate(); // Removed all Plugin Selection Cookies. LatizLookup.getDefault().removeAllFromLookup(PluginSelectionCookie.class); return rootElement; }