Search in sources :

Example 1 with NodeView

use of org.cytoscape.ding.NodeView in project cytoscape-impl by cytoscape.

the class InnerCanvas method adjustZoom.

private void adjustZoom(int notches) {
    final double factor;
    if (notches < 0)
        // scroll up, zoom in
        factor = 1.1;
    else if (notches > 0)
        // scroll down, zoom out
        factor = 0.9;
    else
        return;
    synchronized (m_lock) {
        m_scaleFactor = m_scaleFactor * factor;
    }
    m_view.setViewportChanged();
    // Update view model.
    m_view.setVisualProperty(BasicVisualLexicon.NETWORK_SCALE_FACTOR, m_scaleFactor);
    // TODO: Center the source point on the selected node perfectly.
    if (addEdgeMode.addingEdge()) {
        NodeView nodeView = mousePressedDelegator.getPickedNodeView();
        View<CyNode> view = (DNodeView) mousePressedDelegator.getPickedNodeView();
        AddEdgeStateMonitor.setSourceNode(m_view, view.getModel());
        double[] coords = new double[2];
        coords[0] = nodeView.getXPosition();
        coords[1] = nodeView.getYPosition();
        ensureInitialized();
        ((DGraphView) m_view).xformNodeToComponentCoords(coords);
        Point sourceP = new Point();
        sourceP.setLocation(coords[0], coords[1]);
        AddEdgeStateMonitor.setSourcePoint(m_view, sourceP);
    }
    repaint();
}
Also used : CyNode(org.cytoscape.model.CyNode) Point(java.awt.Point) NodeView(org.cytoscape.ding.NodeView)

Example 2 with NodeView

use of org.cytoscape.ding.NodeView in project cytoscape-impl by cytoscape.

the class DGraphView method syncFilterAndView.

// This is expensive and should only be called at initialization!!!
private void syncFilterAndView() {
    final List<CyNode> flaggedNodes = CyTableUtil.getNodesInState(getModel(), CyNetwork.SELECTED, true);
    final List<CyEdge> flaggedEdges = CyTableUtil.getEdgesInState(getModel(), CyNetwork.SELECTED, true);
    final List<CyNode> selectedNodes = getSelectedNodes();
    final List<CyEdge> selectedEdges = getSelectedEdges();
    // select all nodes that are flagged but not currently selected
    for (final CyNode node : flaggedNodes) {
        final NodeView nv = getDNodeView(node);
        if ((nv == null) || nv.isSelected())
            continue;
        nv.setSelected(true);
    }
    // select all edges that are flagged but not currently selected
    for (final CyEdge edge : flaggedEdges) {
        final EdgeView ev = getDEdgeView(edge);
        if ((ev == null) || ev.isSelected())
            continue;
        ev.setSelected(true);
    }
    // flag all nodes that are selected but not currently flagged
    select(selectedNodes, CyNode.class, true);
    // flag all edges that are selected but not currently flagged
    select(selectedEdges, CyEdge.class, true);
}
Also used : EdgeView(org.cytoscape.ding.EdgeView) CyNode(org.cytoscape.model.CyNode) NodeView(org.cytoscape.ding.NodeView) CyEdge(org.cytoscape.model.CyEdge)

Example 3 with NodeView

use of org.cytoscape.ding.NodeView in project cytoscape-impl by cytoscape.

the class DGraphView method addNodeViewInternal.

/**
 * Should synchronize around m_lock.
 */
private final DNodeView addNodeViewInternal(final CyNode node) {
    final long nodeInx = node.getSUID();
    final NodeView oldView = nodeViewMap.get(node);
    if (oldView != null)
        return null;
    m_drawPersp.addNode(node);
    final DNodeView dNodeView = new DNodeView(lexicon, this, node, serviceRegistrar);
    // WARNING: DO not call the following in view creation.  This is VERY slow.
    // Boolean selected = getModel().getRow(node).get(CyNetwork.SELECTED, Boolean.class);
    // if (selected != null && selected)
    // dNodeView.select();
    nodeViewMap.put(node, dNodeView);
    m_spacial.insert(nodeInx, m_defaultNodeXMin, m_defaultNodeYMin, m_defaultNodeXMax, m_defaultNodeYMax, dNodeView.getZPosition());
    getEventHelper().addEventPayload((CyNetworkView) this, (View<CyNode>) dNodeView, AddedNodeViewsEvent.class);
    return dNodeView;
}
Also used : CyNode(org.cytoscape.model.CyNode) NodeView(org.cytoscape.ding.NodeView)

Example 4 with NodeView

use of org.cytoscape.ding.NodeView in project cytoscape-impl by cytoscape.

the class DGraphView method addEdgeView.

@Override
public EdgeView addEdgeView(final CyEdge edge) {
    if (edge == null)
        throw new NullPointerException("edge is null");
    final NodeView sourceNode;
    final NodeView targetNode;
    final DEdgeView dEdgeView;
    synchronized (m_lock) {
        final EdgeView oldView = edgeViewMap.get(edge);
        if (oldView != null)
            return oldView;
        sourceNode = addNodeViewInternal(edge.getSource());
        targetNode = addNodeViewInternal(edge.getTarget());
        m_drawPersp.addEdge(edge);
        dEdgeView = new DEdgeView(this, edge, handleFactory, lexicon, serviceRegistrar);
        edgeViewMap.put(edge, dEdgeView);
        setContentChanged();
    }
    // Under no circumstances should we be holding m_lock when the listener
    // events are fired.
    /* final GraphViewChangeListener listener = m_lis[0];

		if (listener != null) {
			// Only fire this event if either of the nodes is new. The node
			// will be null if it already existed.
			if ((sourceNode != null) || (targetNode != null)) {
				long[] nodeInx;

				if (sourceNode == null) {
					nodeInx = new long[] { targetNode.getCyNode().getSUID() };
				} else if (targetNode == null) {
					nodeInx = new long[] { sourceNode.getCyNode().getSUID() };
				} else {
					nodeInx = new long[] { sourceNode.getCyNode().getSUID(),
							targetNode.getCyNode().getSUID()};
				}

				listener.graphViewChanged(new GraphViewNodesRestoredEvent(this,
						makeNodeList(nodeInx, this)));
			}

			listener.graphViewChanged(new GraphViewEdgesRestoredEvent(this,
					makeList(dEdgeView.getCyEdge())));
		}
		*/
    getEventHelper().addEventPayload((CyNetworkView) this, (View<CyEdge>) dEdgeView, AddedEdgeViewsEvent.class);
    return dEdgeView;
}
Also used : EdgeView(org.cytoscape.ding.EdgeView) NodeView(org.cytoscape.ding.NodeView) CyEdge(org.cytoscape.model.CyEdge)

Example 5 with NodeView

use of org.cytoscape.ding.NodeView in project cytoscape-impl by cytoscape.

the class ViewState method apply.

/**
 * Applies the recorded state to the view used to create
 * this object.
 */
public void apply() {
    if (points != null) {
        // Use nodes as keys because they are less volatile than views...
        for (CyNode n : points.keySet()) {
            NodeView nv = view.getDNodeView(n);
            Point2D.Double p = points.get(n);
            nv.setXPosition(p.getX());
            nv.setYPosition(p.getY());
        }
    }
    view.setZoom(scaleFactor);
    view.setCenter(center.getX(), center.getY());
    view.updateView();
    if (anchors != null) {
        for (final CyEdge e : anchors.keySet()) {
            final EdgeView ev = view.getDEdgeView(e);
            // FIXME!
            // ev.getBend().setHandles( anchors.get(e) );
            ev.setLineCurved(linetype.get(e).intValue());
        }
    }
}
Also used : Point2D(java.awt.geom.Point2D) EdgeView(org.cytoscape.ding.EdgeView) CyNode(org.cytoscape.model.CyNode) NodeView(org.cytoscape.ding.NodeView) CyEdge(org.cytoscape.model.CyEdge)

Aggregations

NodeView (org.cytoscape.ding.NodeView)5 CyNode (org.cytoscape.model.CyNode)4 EdgeView (org.cytoscape.ding.EdgeView)3 CyEdge (org.cytoscape.model.CyEdge)3 Point (java.awt.Point)1 Point2D (java.awt.geom.Point2D)1