private void display() { CyServiceRegistrarImpl register = new CyServiceRegistrarImpl(bc); CyNetworkViewManager viewManager = register.getService(CyNetworkViewManager.class); CyNetworkViewFactory viewFactory = register.getService(CyNetworkViewFactory.class); CyNetworkView networkView = viewFactory.createNetworkView(network); viewManager.addNetworkView(networkView); VisualMappingFunctionFactory passthroughFactory = register.getService(VisualMappingFunctionFactory.class, "(mapping.type=passthrough)"); VisualMappingFunctionFactory continuousFactory = register.getService(VisualMappingFunctionFactory.class, "(mapping.type=continuous)"); VisualMappingManager vmManager = register.getService(VisualMappingManager.class); VisualStyleFactory vsFactory = register.getService(VisualStyleFactory.class); VisualStyle vs = vsFactory.createVisualStyle( network.getDefaultNetworkTable().getRow(network.getSUID()).get("name", String.class)); PassthroughMapping pMapping = (PassthroughMapping) passthroughFactory.createVisualMappingFunction( "name", String.class, BasicVisualLexicon.NODE_LABEL); vs.addVisualMappingFunction(pMapping); vs.apply(networkView); ContinuousMapping mapping = (ContinuousMapping) continuousFactory.createVisualMappingFunction( "score", Double.class, BasicVisualLexicon.NODE_FILL_COLOR); Double val1 = getMinimum(network.getDefaultNodeTable().getColumn("score")); BoundaryRangeValues<Paint> brv1 = new BoundaryRangeValues<Paint>(Color.GREEN, Color.GREEN, Color.GREEN); Double val3 = getMaximum(network.getDefaultNodeTable().getColumn("score")); BoundaryRangeValues<Paint> brv3 = new BoundaryRangeValues<Paint>(Color.RED, Color.RED, Color.RED); Double val2 = (val1 + val3 + val1 + val1) / 4; BoundaryRangeValues<Paint> brv2 = new BoundaryRangeValues<Paint>(Color.YELLOW, Color.YELLOW, Color.YELLOW); mapping.addPoint(val1, brv1); mapping.addPoint(val2, brv2); mapping.addPoint(val3, brv3); vs.addVisualMappingFunction(mapping); vs.apply(networkView); vmManager.addVisualStyle(vs); vmManager.setVisualStyle(vs, networkView); networkView.updateView(); }
private boolean syncToNode() { boolean sync = false; if (vmm.getCurrentVisualStyle() != null) { Set<VisualPropertyDependency<?>> dependencies = vmm.getCurrentVisualStyle().getAllVisualPropertyDependencies(); for (VisualPropertyDependency<?> dep : dependencies) { if (dep.getIdString().equals("nodeCustomGraphicsSizeSync")) { sync = dep.isDependencyEnabled(); break; } } } return sync; }
private void initializeVisualStyleComboBox() { vsComboBoxModel = new DefaultComboBoxModel(); final VisualStyle defaultVS = this.vmm.getDefaultVisualStyle(); final Set<VisualStyle> styles = vmm.getAllVisualStyles(); for (VisualStyle style : styles) vsComboBoxModel.addElement(style); visualStyleComboBox = new JComboBox(vsComboBoxModel); visualStyleComboBox.setSelectedItem(defaultVS); }
@Override @SuppressWarnings("unchecked") public void setValue(final Object value) { if (value instanceof ContinuousMapping == false) throw new IllegalArgumentException("Value should be ContinuousMapping: this is " + value); final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class); final CyNetwork currentNetwork = appMgr.getCurrentNetwork(); if (currentNetwork == null) return; mapping = (ContinuousMapping<K, V>) value; Class<? extends CyIdentifiable> type = (Class<? extends CyIdentifiable>) mapping.getVisualProperty().getTargetDataType(); final CyNetworkTableManager netTblMgr = servicesUtil.get(CyNetworkTableManager.class); final CyTable attr = netTblMgr.getTable(appMgr.getCurrentNetwork(), type, CyNetwork.DEFAULT_ATTRS); final VisualMappingManager vmMgr = servicesUtil.get(VisualMappingManager.class); editorPanel = new C2CMappingEditorPanel<K, V>(vmMgr.getCurrentVisualStyle(), mapping, attr, servicesUtil); }
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(); } }
/** * @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; }