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();
}
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);
}
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;
}
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;
}
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());
}
}
}