Exemplo n.º 1
0
  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);
  }
Exemplo n.º 2
0
  /**
   * @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;
  }