private Set<View<CyNode>> getLayoutNodes(CyLayoutAlgorithm layout, CyNetworkView networkView) { if (layout.getSupportsSelectedOnly() && selectedTunable.selectedNodesOnly) { Set<View<CyNode>> nodeViews = new HashSet<View<CyNode>>(); CyNetwork network = networkView.getModel(); for (View<CyNode> view : networkView.getNodeViews()) { if (network.getRow(view.getModel()).get(CyNetwork.SELECTED, Boolean.class) && view.getVisualProperty(BasicVisualLexicon.NODE_VISIBLE)) { nodeViews.add(view); } } return nodeViews; } return CyLayoutAlgorithm.ALL_NODE_VIEWS; }
public void undo() { final Collection<CyNetworkView> views = networkViewManager.getNetworkViews(network); CyNetworkView view = null; if (views.size() != 0) view = views.iterator().next(); networkCenterX = view.getVisualProperty(NETWORK_CENTER_X_LOCATION); networkCenterY = view.getVisualProperty(NETWORK_CENTER_Y_LOCATION); networkCenterZ = view.getVisualProperty(NETWORK_CENTER_Z_LOCATION); networkScaleFactor = view.getVisualProperty(NETWORK_SCALE_FACTOR); final Collection<View<CyNode>> nodeViews = view.getNodeViews(); nodesAndLocations = new WeakHashMap<CyNode, NodeLocations>(nodeViews.size()); for (final View<CyNode> nodeView : nodeViews) nodesAndLocations.put(nodeView.getModel(), new NodeLocations(nodeView)); networkViewManager.destroyNetworkView(view); }
public void redo() { ; final CyNetworkView view = viewFactory.createNetworkView(network); networkViewManager.addNetworkView(view); for (final View<CyNode> nodeView : view.getNodeViews()) nodesAndLocations.get(nodeView.getModel()).restoreLocations(nodeView); view.setVisualProperty(NETWORK_CENTER_X_LOCATION, networkCenterX); view.setVisualProperty(NETWORK_CENTER_Y_LOCATION, networkCenterY); view.setVisualProperty(NETWORK_CENTER_Z_LOCATION, networkCenterZ); view.setVisualProperty(NETWORK_SCALE_FACTOR, networkScaleFactor); eventHelper.flushPayloadEvents(); view.updateView(); }
private final void clearAll( final CyNetworkView netView, final View<? extends CyIdentifiable> nodeView) { boolean needToUpdateView = false; final VisualStyle style = vmm.getCurrentVisualStyle(); for (VisualProperty<?> vp : vpSet) { final boolean lock = nodeView.isDirectlyLocked(vp); if (lock) { nodeView.clearValueLock(vp); needToUpdateView = true; } } if (needToUpdateView) { style.apply(netView); netView.updateView(); } }
public TaskIterator createTaskIterator(View<CyNode> nView, CyNetworkView netView) { List<CyNode> selectedNodes = CyTableUtil.getNodesInState(netView.getModel(), CyNetwork.SELECTED, true); if (selectedNodes == null || selectedNodes.size() == 0) selectedNodes = Collections.singletonList(nView.getModel()); return new TaskIterator( new SMARTSSearchTask(netView.getModel(), selectedNodes, scope, showResult, settings)); }
/** * Apply bypass * * @param netView * @param graphObjectView * @param vp */ private final void applBypassValue( final CyNetworkView netView, final View<? extends CyIdentifiable> graphObjectView, VisualProperty<?> vp) { final ValueEditor<Object> editor = (ValueEditor<Object>) editorManager.getValueEditor(vp.getRange().getType()); final Object bypassValue = editor.showEditor(null, graphObjectView.getVisualProperty(vp)); // Set lock for the vp graphObjectView.setLockedValue(vp, bypassValue); // Apply the new value only for the given view // TODO don't do this, because it overwrites some bypassed values with default ones!!! Calling // setLockedValue should be enough // final CyRow row = netView.getModel().getRow(graphObjectView.getModel()); // vmm.getCurrentVisualStyle().apply(row, graphObjectView); // Redraw the view netView.updateView(); }
@SuppressWarnings({"unchecked", "rawtypes"}) @Override public void apply(final CyRow row, final View<? extends CyIdentifiable> view) { if (view == null) { logger.warn("Tried to apply Visual Style to null view"); return; } ApplyHandler handler = null; for (final Class<?> viewType : applyHandlersMap.keySet()) { if (viewType.isAssignableFrom(view.getModel().getClass())) { handler = applyHandlersMap.get(viewType); break; } } if (handler == null) throw new IllegalArgumentException("This view type is not supported: " + view.getClass()); handler.apply(row, view); }
/** * Directly update view object. * * @param view * @param rootNode * @param lexicon */ public Response updateView( final View<? extends CyIdentifiable> view, final JsonNode rootNode, final VisualLexicon lexicon) { for (final JsonNode vpNode : rootNode) { String vpName = vpNode.get(MAPPING_VP).textValue(); final VisualProperty<?> vp = getVisualProperty(vpName, lexicon); final JsonNode value = vpNode.get(MAPPING_DISCRETE_VALUE); if (vp == null || value == null) { continue; } Object parsedValue = null; if (value.isTextual()) { parsedValue = vp.parseSerializableString(value.asText()); } else { parsedValue = vp.parseSerializableString(value.toString()); } view.setVisualProperty(vp, parsedValue); } return Response.ok().build(); }
@Override public List<BarLayer> getLayers( CyNetworkView networkView, View<? extends CyIdentifiable> nodeView) { CyNetwork network = networkView.getModel(); if (!(nodeView.getModel() instanceof CyNode)) return null; layers = new ArrayList<>(); CyNode node = (CyNode) nodeView.getModel(); // Create all of our pie slices. Each slice becomes a layer if (attributes != null && attributes.size() > 0) { // System.out.println("Getting data from attributes for node "+node); values = getDataFromAttributes(network, node, attributes, labels); // System.out.println("Data from attributes returns "+values.size()+" values"); colorList = convertInputToColor(colorString, values); } // Protect against missing values in the input stream // if (values == null || colorList == null) return layers; if (labels != null && labels.size() > 0 && (labels.size() != values.size() || labels.size() != colorList.size())) { logger.error( "barchart: number of labels (" + labels.size() + "), values (" + values.size() + "), and colors (" + colorList.size() + ") don't match"); return null; } List<BarLayer> labelList = new ArrayList<BarLayer>(); double minValue = 0.000001; double maxValue = -minValue; for (Double val : values) { if (val == null) continue; minValue = Math.min(minValue, val); maxValue = Math.max(maxValue, val); } double labelMin = minValue; if (normalized) { minValue = rangeMin; maxValue = rangeMax; } int nBars = values.size(); Font font = getFont(); for (int bar = 0; bar < nBars; bar++) { String label = null; if (labels != null && labels.size() > 0) label = labels.get(bar); if (values.get(bar) == null || values.get(bar) == 0.0) continue; // System.out.println("Creating bar #"+bar); // Create the slice BarLayer bl = new BarLayer( bar, nBars, separation, values.get(bar), minValue, maxValue, normalized, ybase, colorList.get(bar), showAxes, borderWidth, scale); if (bl == null) continue; layers.add(bl); // System.out.println("BarLayer: "+bar+" bounds: "+bl.getShape().getBounds2D()); if (label != null) { // System.out.println("Creating label for bar #"+bar); // Now, create the label BarLayer labelLayer = new BarLayer( bar, nBars, separation, minValue, maxValue, normalized, labelMin, ybase, label, font, labelColor, showAxes, scale); if (labelLayer != null) labelList.add(labelLayer); } } // System.out.println("Created "+layers.size()+" bar layers"); // Now add all of our labels so they will be on top of our slices if (labelList != null && labelList.size() > 0) layers.addAll(labelList); // System.out.println("Created "+layers.size()+" total layers"); shapeLayers = layers; return layers; }
public TaskIterator createTaskIterator(View<CyEdge> arg0, CyNetworkView arg1) { return new TaskIterator(new RemoveEdgeTask(mgr, arg0.getModel())); }
public boolean isReady(View<CyEdge> edgeView, CyNetworkView networkView) { if (super.isReady(edgeView, networkView) && mgr.setsCount() == 0) return false; if (mgr.isInSet(edgeView.getModel().getSUID())) return true; return false; }
void restoreLocations(final View<CyNode> nodeView) { nodeView.setVisualProperty(NODE_X_LOCATION, xLocation); nodeView.setVisualProperty(NODE_Y_LOCATION, yLocation); nodeView.setVisualProperty(NODE_Z_LOCATION, zLocation); }
NodeLocations(final View<CyNode> nodeView) { xLocation = nodeView.getVisualProperty(NODE_X_LOCATION); yLocation = nodeView.getVisualProperty(NODE_Y_LOCATION); zLocation = nodeView.getVisualProperty(NODE_Z_LOCATION); }
/** * @param netView * @param view a View<CyNode>, View<CyEdge> or View<CyNetwork> object * @return */ public CyMenuItem build(final CyNetworkView netView, final View<? extends CyIdentifiable> view) { final Class<? extends CyIdentifiable> targetClass = view.getModel().getClass(); final Queue<VisualLexiconNode> queue = new PriorityQueue<VisualLexiconNode>(50, new VisualLexiconNodeComparator()); final Map<VisualLexiconNode, JMenuItem> menuMap = new HashMap<VisualLexiconNode, JMenuItem>(); final JMenu rootJMenu = new JMenu(ROOT_MENU_LABEL); final CyMenuItem rootMenu = new CyMenuItem(rootJMenu, ROOT_GRAVITY); queue.addAll(root.getChildren()); menuMap.put(root, rootMenu.getMenuItem()); // Node size, width and height JMenuItem menuItemNodeSize = null; JMenuItem menuItemNodeWidth = null; JMenuItem menuItemNodeHeight = null; final Set<VisualLexiconNode> nextNodes = new HashSet<VisualLexiconNode>(); while (!queue.isEmpty()) { final VisualLexiconNode curretNode = queue.poll(); final VisualProperty<?> vp = curretNode.getVisualProperty(); if (vp.getTargetDataType().isAssignableFrom(targetClass)) { final Collection<VisualLexiconNode> children = curretNode.getChildren(); nextNodes.addAll(children); final JMenuItem menu; if (children.isEmpty() && PropertySheetUtil.isCompatible(vp)) { final boolean lock = view.isDirectlyLocked(vp); if (lock) { menu = new JMenu(vp.getDisplayName()); final JMenuItem clear = new JMenuItem("Clear"); clear.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { view.clearValueLock(vp); netView.updateView(); } }); final JMenuItem edit = new JMenuItem("Edit Bypass"); edit.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { applBypassValue(netView, view, vp); } }); menu.add(clear); menu.add(edit); // Update color menu.setForeground(ENABLED_COLOR); menu.setIcon(ENABLED_ICON); menu.setFont(ENABLED_FONT); VisualLexiconNode parent = curretNode.getParent(); while (parent != root) { JMenuItem enabledPath = menuMap.get(parent); enabledPath.setForeground(ENABLED_COLOR); enabledPath.setIcon(ENABLED_ICON); enabledPath.setFont(ENABLED_FONT); parent = parent.getParent(); } rootJMenu.setIcon(ENABLED_ICON); rootJMenu.setForeground(ENABLED_COLOR); rootJMenu.setFont(ENABLED_FONT); vpSet.add(vp); } else { menu = new JMenuItem(vp.getDisplayName()); menu.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { applBypassValue(netView, view, vp); } }); if (vp.getDisplayName() .equalsIgnoreCase(BasicVisualLexicon.NODE_WIDTH.getDisplayName())) { menuItemNodeWidth = menu; } if (vp.getDisplayName() .equalsIgnoreCase(BasicVisualLexicon.NODE_HEIGHT.getDisplayName())) { menuItemNodeHeight = menu; } } } else { menu = new JMenu(vp.getDisplayName()); if (vp.getDisplayName().equalsIgnoreCase(BasicVisualLexicon.NODE_SIZE.getDisplayName())) { menuItemNodeSize = menu; vp_nodeSize = vp; } } if (PropertySheetUtil.isCompatible(vp)) { menuMap.get(curretNode.getParent()).add(menu); menuMap.put(curretNode, menu); } } if (queue.isEmpty()) { queue.addAll(nextNodes); nextNodes.clear(); } } // handle node size if (menuItemNodeSize != null) { // JMenuItem menuItemNodeSize1 = new JMenuItem(vp_nodeSize.getDisplayName()); menuItemNodeSize1.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { applBypassValue(netView, view, vp_nodeSize); } }); menuItemNodeSize.add(menuItemNodeSize1); // Check if nose size is locked boolean nodeSizeIsLocked = false; java.util.Iterator it = vmm.getCurrentVisualStyle().getAllVisualPropertyDependencies().iterator(); while (it.hasNext()) { org.cytoscape.view.vizmap.VisualPropertyDependency dep = (org.cytoscape.view.vizmap.VisualPropertyDependency) it.next(); if (dep.getDisplayName().equalsIgnoreCase("Lock node width and height") && dep.isDependencyEnabled()) { nodeSizeIsLocked = true; } } if (nodeSizeIsLocked) { // In case the Node size is locked, disable menuItem Node_width and Nod_height if (menuItemNodeWidth != null) menuItemNodeWidth.setEnabled(false); if (menuItemNodeHeight != null) menuItemNodeHeight.setEnabled(false); } else { // In case the Node size is not locked, disable menuItem Node_size if (menuItemNodeSize1 != null) menuItemNodeSize1.setEnabled(false); } } final JSeparator separator = new JSeparator(); final JMenuItem resetMenu = new JMenuItem("Reset All"); resetMenu.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { clearAll(netView, view); } }); rootJMenu.add(separator); rootJMenu.add(resetMenu); return rootMenu; }
private void checkView(final CyNetworkView view) { assertEquals(Color.BLACK, view.getVisualProperty(NETWORK_BACKGROUND_PAINT)); assertEquals(new Double(639.0d), view.getVisualProperty(NETWORK_WIDTH)); assertEquals(new Double(624.0d), view.getVisualProperty(NETWORK_HEIGHT)); assertEquals( new Double(3091.2991395970175d), view.getVisualProperty(NETWORK_CENTER_X_LOCATION)); assertEquals(new Double(3610.396738076269d), view.getVisualProperty(NETWORK_CENTER_Y_LOCATION)); assertEquals(new Double(0.05044042295795177d), view.getVisualProperty(NETWORK_SCALE_FACTOR)); // All nodes have the same size, border and shape final View<CyNode> nv = view.getNodeView(view.getModel().getNodeList().iterator().next()); assertEquals(80, nv.getVisualProperty(NODE_WIDTH).intValue()); assertEquals(30, nv.getVisualProperty(NODE_HEIGHT).intValue()); assertEquals(NodeShapeVisualProperty.ROUND_RECTANGLE, nv.getVisualProperty(NODE_SHAPE)); assertEquals(180, nv.getVisualProperty(NODE_TRANSPARENCY).intValue()); assertEquals(2, nv.getVisualProperty(NODE_BORDER_WIDTH).intValue()); assertEquals(LineTypeVisualProperty.SOLID, nv.getVisualProperty(NODE_BORDER_LINE_TYPE)); assertEquals(new Color(153, 153, 255), nv.getVisualProperty(NODE_BORDER_PAINT)); assertEquals(255, nv.getVisualProperty(NODE_BORDER_TRANSPARENCY).intValue()); assertEquals(new Color(255, 255, 255), nv.getVisualProperty(NODE_LABEL_COLOR)); assertEquals(255, nv.getVisualProperty(NODE_LABEL_TRANSPARENCY).intValue()); // All edges have the same width and other properties final View<CyEdge> ev = view.getEdgeView(view.getModel().getEdgeList().iterator().next()); assertEquals(new Double(1.0), ev.getVisualProperty(EDGE_WIDTH)); assertEquals(255, ev.getVisualProperty(EDGE_TRANSPARENCY).intValue()); assertEquals(ArrowShapeVisualProperty.NONE, ev.getVisualProperty(EDGE_SOURCE_ARROW_SHAPE)); assertEquals(ArrowShapeVisualProperty.NONE, ev.getVisualProperty(EDGE_TARGET_ARROW_SHAPE)); }
public boolean isReady(View<CyNode> nView, CyNetworkView netView) { if (nView != null && settings.hasNodeCompounds(Collections.singletonList(nView.getModel()))) return true; return selectedNodesReady(netView.getModel()); }