@SuppressWarnings({"rawtypes", "unchecked"}) private final ContinuousMapping parseContinuous( String columnName, Class<?> type, VisualProperty<?> vp, VisualMappingFunctionFactory factory, JsonNode mappingNode) { final ContinuousMapping mapping = (ContinuousMapping) factory.createVisualMappingFunction(columnName, type, vp); for (JsonNode point : mappingNode.get("points")) { JsonNode val = point.get("value"); JsonNode lesser = point.get("lesser"); JsonNode equal = point.get("equal"); JsonNode greater = point.get("greater"); final BoundaryRangeValues newPoint = new BoundaryRangeValues( vp.parseSerializableString(lesser.asText()), vp.parseSerializableString(equal.asText()), vp.parseSerializableString(greater.asText())); mapping.addPoint(val.asDouble(), newPoint); } return mapping; }
private String getSingleVp( final String visualProperty, final View<? extends CyIdentifiable> view, final Collection<VisualProperty<?>> vps) { VisualProperty<?> targetVp = null; for (final VisualProperty<?> vp : vps) { if (vp.getIdString().equals(visualProperty)) { targetVp = vp; break; } } if (targetVp == null) { throw getError( "Could not find such Visual Property: " + visualProperty, new NotFoundException(), Response.Status.NOT_FOUND); } try { return styleSerializer.serializeSingleVisualProp(view, targetVp); } catch (IOException e) { throw getError( "Could not serialize the view object.", e, Response.Status.INTERNAL_SERVER_ERROR); } }
private void applyCustomGraphicsPosition( final VisualProperty<?> vp, final ObjectPosition position) { // No need to modify if (position == null) return; // Use dependency to retrieve its parent. final VisualLexiconNode lexNode = lexicon.getVisualLexiconNode(vp); final Collection<VisualLexiconNode> leavs = lexNode.getParent().getChildren(); VisualProperty<?> parent = null; for (VisualLexiconNode vlNode : leavs) { if (vlNode.getVisualProperty().getRange().getType().equals(CyCustomGraphics.class)) { parent = vlNode.getVisualProperty(); break; } } if (parent == null) throw new NullPointerException( "Associated Custom Graphics VP is missing for " + vp.getDisplayName()); final Set<CustomGraphicLayer> currentCG = cgMap.get(parent); if (currentCG == null || currentCG.size() == 0) return; final Set<CustomGraphicLayer> newList = new HashSet<CustomGraphicLayer>(); for (CustomGraphicLayer g : currentCG) newList.add(moveCustomGraphicsToNewPosition(g, position)); currentCG.clear(); currentCG.addAll(newList); this.cgMap.put(parent, currentCG); }
@SuppressWarnings({"rawtypes", "unchecked"}) private final void parseDefaults( final JsonNode defaults, final VisualStyle style, final VisualLexicon lexicon) { for (final JsonNode vpNode : defaults) { String vpName = vpNode.get(MAPPING_VP).textValue(); final VisualProperty vp = getVisualProperty(vpName, lexicon); final JsonNode value = vpNode.get("value"); if (vp == null || value == null) { continue; } Object parsedValue = null; if (value.isTextual()) { parsedValue = vp.parseSerializableString(value.asText()); } else { parsedValue = vp.parseSerializableString(value.toString()); } style.setDefaultValue(vp, parsedValue); } }
/** * 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(); }
/** * 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({"rawtypes", "unchecked"}) private final DiscreteMapping parseDiscrete( String columnName, Class<?> type, VisualProperty<?> vp, VisualMappingFunctionFactory factory, JsonNode discreteMapping) { DiscreteMapping mapping = (DiscreteMapping) factory.createVisualMappingFunction(columnName, type, vp); final Map map = new HashMap(); for (JsonNode pair : discreteMapping) { final Object key = parseKeyValue(type, pair.get(MAPPING_DISCRETE_KEY).textValue()); if (key != null) { map.put(key, vp.parseSerializableString(pair.get(MAPPING_DISCRETE_VALUE).textValue())); } } mapping.putAll(map); return mapping; }
@Override @SuppressWarnings({"unchecked", "rawtypes"}) public void clearValueLock(final VisualProperty<?> vp) { final boolean isDefault; synchronized (graphView.m_lock) { isDefault = !visualProperties.containsKey(vp); } super.clearValueLock(vp); // Reset to the visual style default if visualProperties map doesn't contain this vp if (isDefault) { if (vp == BasicVisualLexicon .NODE_VISIBLE) // TODO: what if the default value of the visual style is different // (e.g. invisible)? applyVisualProperty((VisualProperty) vp, vp.getDefault()); else graphView.nodeViewDefaultSupport.setViewDefault( (VisualProperty) vp, graphView.m_nodeDetails.getDefaultValue(vp)); } }
/** * @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; }
/** Edit all selected cells at once. This is for Discrete Mapping only. */ @Override @SuppressWarnings({"rawtypes", "unchecked"}) public void actionPerformed(final ActionEvent e) { final VizMapperMainPanel vizMapperMainPanel = getVizMapperMainPanel(); if (vizMapperMainPanel == null) return; final VisualPropertySheet vpSheet = vizMapperMainPanel.getSelectedVisualPropertySheet(); if (vpSheet == null) return; for (final VisualPropertySheetItem<?> vpSheetItem : vpSheet.getSelectedItems()) { final VisualPropertySheetItemModel<?> model = vpSheetItem.getModel(); final PropertySheetTable table = vpSheetItem.getPropSheetPnl().getTable(); final int[] selected = table.getSelectedRows(); if (selected == null || selected.length == 0 || !(model.getVisualMappingFunction() instanceof DiscreteMapping)) continue; // Test with the first selected item final DiscreteMapping dm = (DiscreteMapping) model.getVisualMappingFunction(); final VisualProperty vp = dm.getVisualProperty(); Object newValue = null; try { // Get new value newValue = editorManager.showVisualPropertyValueEditor(vizMapperMainPanel, vp, vp.getDefault()); } catch (Exception ex) { logger.error("Could not edit value.", ex); } if (newValue == null) continue; final Map<Object, Object> newValues = new HashMap<Object, Object>(); final Map<Object, Object> previousValues = new HashMap<Object, Object>(); for (int i = 0; i < selected.length; i++) { final Item item = ((Item) table.getValueAt(selected[i], 0)); if (item != null && item.getProperty() instanceof VizMapperProperty) { final VizMapperProperty<?, ?, ?> prop = (VizMapperProperty<?, ?, ?>) item.getProperty(); if (prop.getCellType() == CellType.DISCRETE) { // Save the current value for undo previousValues.put(prop.getKey(), prop.getValue()); // New value newValues.put(prop.getKey(), newValue); } } } // Save the mapping->old_values for undo if (!previousValues.isEmpty()) previousMappingValues.put(dm, previousValues); // Save the mapping->new_values for redo if (!newValues.isEmpty()) newMappingValues.put(dm, newValues); // Update the visual mapping dm.putAll(newValues); } // Undo support if (!previousMappingValues.isEmpty()) { final UndoSupport undo = servicesUtil.get(UndoSupport.class); undo.postEdit(new EditSelectedDiscreteValuesEdit()); } }
@Override @SuppressWarnings("unchecked") protected <T, V extends T> void applyVisualProperty( final VisualProperty<? extends T> vpOriginal, V value) { VisualProperty<?> vp = vpOriginal; // Check to make sure our view hasn't gotten disconnected somewhere along the line if (graphView.getNodeView(this.getModel()) == null) return; // Null means set value to VP's default. if (value == null) value = (V) vp.getDefault(); if (vp == DVisualLexicon.NODE_SHAPE) { setShape(((NodeShape) value)); } else if (vp == DVisualLexicon.NODE_SELECTED_PAINT) { setSelectedPaint((Paint) value); } else if (vp == BasicVisualLexicon.NODE_SELECTED) { setSelected((Boolean) value); } else if (vp == BasicVisualLexicon.NODE_VISIBLE) { if (((Boolean) value).booleanValue()) { graphView.showGraphObject(this); isVisible = true; } else { graphView.hideGraphObject(this); isVisible = false; } } else if (vp == BasicVisualLexicon.NODE_FILL_COLOR) { setUnselectedPaint((Paint) value); } else if (vp == DVisualLexicon.NODE_BORDER_PAINT) { setBorderPaint((Color) value); } else if (vp == DVisualLexicon.NODE_BORDER_TRANSPARENCY) { final Integer opacity = ((Number) value).intValue(); setBorderTransparency(opacity); } else if (vp == DVisualLexicon.NODE_BORDER_WIDTH) { setBorderWidth(((Number) value).floatValue()); } else if (vp == DVisualLexicon.NODE_BORDER_LINE_TYPE) { final DLineType dLineType = DLineType.getDLineType((LineType) value); final float currentBorderWidth = graphView.m_nodeDetails.getBorderWidth(model); setBorder(dLineType.getStroke(currentBorderWidth)); } else if (vp == DVisualLexicon.NODE_TRANSPARENCY) { setTransparency(((Number) value).intValue()); } else if (vp == BasicVisualLexicon.NODE_WIDTH) { setWidth(((Number) value).doubleValue()); } else if (vp == BasicVisualLexicon.NODE_HEIGHT) { setHeight(((Number) value).doubleValue()); } else if (vp == BasicVisualLexicon.NODE_LABEL) { setText(value.toString()); } else if (vp == BasicVisualLexicon.NODE_LABEL_WIDTH) { setLabelWidth(((Number) value).doubleValue()); } else if (vp == BasicVisualLexicon.NODE_X_LOCATION) { setXPosition(((Number) value).doubleValue()); } else if (vp == BasicVisualLexicon.NODE_Y_LOCATION) { setYPosition(((Number) value).doubleValue()); } else if (vp == BasicVisualLexicon.NODE_Z_LOCATION) { setZPosition(((Number) value).doubleValue()); } else if (vp == DVisualLexicon.NODE_TOOLTIP) { setToolTip(value.toString()); } else if (vp == BasicVisualLexicon.NODE_LABEL_COLOR) { setTextPaint((Color) value); } else if (vp == BasicVisualLexicon.NODE_LABEL_TRANSPARENCY) { final int opacity = ((Number) value).intValue(); setLabelTransparency(opacity); } else if (vp == DVisualLexicon.NODE_LABEL_FONT_FACE) { final float currentFontSize = graphView.m_nodeDetails.getLabelFont(model, 0).getSize(); final Font newFont = ((Font) value).deriveFont(currentFontSize); setFont(newFont); } else if (vp == DVisualLexicon.NODE_LABEL_FONT_SIZE) { final float newSize = ((Number) value).floatValue(); final Font newFont = graphView.m_nodeDetails.getLabelFont(model, 0).deriveFont(newSize); setFont(newFont); } else if (vp == DVisualLexicon.NODE_LABEL_POSITION) { this.setLabelPosition((ObjectPosition) value); } else if (vp == BasicVisualLexicon.NODE_NESTED_NETWORK_IMAGE_VISIBLE) { setNestedNetworkImgVisible(Boolean.TRUE.equals(value)); } else if (vp instanceof CustomGraphicsVisualProperty) { applyCustomGraphics(vp, (CyCustomGraphics<CustomGraphicLayer>) value); } else if (vp instanceof ObjectPositionVisualProperty) { applyCustomGraphicsPosition(vp, (ObjectPosition) value); } }