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;
  }
Beispiel #2
0
  public void updateDependencies(final VisualStyle style, final JsonNode rootNode) {
    final Set<VisualPropertyDependency<?>> deps = style.getAllVisualPropertyDependencies();

    final Map<String, VisualPropertyDependency<?>> names = new HashMap<>();
    for (final VisualPropertyDependency<?> dep : deps) {
      names.put(dep.getIdString(), dep);
    }

    for (final JsonNode depNode : rootNode) {
      String depId = depNode.get(VisualStyleMapper.VP_DEPENDENCY).textValue();
      final VisualPropertyDependency<?> dep = names.get(depId);
      if (dep == null) {
        continue;
      }

      final JsonNode enabled = depNode.get("enabled");
      if (enabled == null) {
        continue;
      }

      boolean value = enabled.asBoolean();
      dep.setDependency(value);
    }
  }
  /**
   * @param netView
   * @param view a View&lt;CyNode&gt;, View&lt;CyEdge&gt; or View&lt;CyNetwork&gt; 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;
  }