示例#1
0
  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));
  }
 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();
  }
  @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);
  }
示例#6
0
  @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;
 }
  /**
   * @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;
  }
示例#10
0
  public boolean isReady(View<CyNode> nView, CyNetworkView netView) {
    if (nView != null && settings.hasNodeCompounds(Collections.singletonList(nView.getModel())))
      return true;

    return selectedNodesReady(netView.getModel());
  }