Search in sources :

Example 1 with Handle

use of org.cytoscape.view.presentation.property.values.Handle in project cytoscape-impl by cytoscape.

the class BendImpl method parseSerializableString.

public static Bend parseSerializableString(String strRepresentation) {
    final Bend bend = new BendImpl();
    // Validate
    if (strRepresentation == null)
        return bend;
    final String[] parts = strRepresentation.split("\\|");
    for (int i = 0; i < parts.length; i++) {
        final String str = parts[i];
        final Handle handle = HandleImpl.parseSerializableString(str);
        if (handle != null)
            bend.insertHandleAt(i, handle);
    }
    return bend;
}
Also used : Bend(org.cytoscape.view.presentation.property.values.Bend) Handle(org.cytoscape.view.presentation.property.values.Handle)

Example 2 with Handle

use of org.cytoscape.view.presentation.property.values.Handle in project cytoscape-impl by cytoscape.

the class DEdgeView method addHandlePoint.

/**
 * Add a new handle and returns its index.
 *
 * @param pt location of handle
 * @return new handle index.
 */
protected int addHandlePoint(final Point2D pt) {
    synchronized (graphView.m_lock) {
        // Obtain existing Bend object
        final Bend bend = graphView.m_edgeDetails.getBend(model, true);
        if (bend.getAllHandles().size() == 0) {
            // anchors object is empty. Add first handle.
            addHandleInternal(0, pt);
            // Index of this handle, which is first (0)
            return 0;
        }
        final Point2D sourcePt = graphView.getDNodeView(getCyEdge().getSource()).getOffset();
        final Point2D targetPt = graphView.getDNodeView(getCyEdge().getTarget()).getOffset();
        final Handle firstHandle = bend.getAllHandles().get(0);
        final Point2D point = firstHandle.calculateHandleLocation(graphView.getViewModel(), this);
        double bestDist = (pt.distance(sourcePt) + pt.distance(point)) - sourcePt.distance(point);
        int bestInx = 0;
        for (int i = 1; i < bend.getAllHandles().size(); i++) {
            final Handle handle1 = bend.getAllHandles().get(i);
            final Handle handle2 = bend.getAllHandles().get(i - 1);
            final Point2D point1 = handle1.calculateHandleLocation(graphView.getViewModel(), this);
            final Point2D point2 = handle2.calculateHandleLocation(graphView.getViewModel(), this);
            final double distCand = (pt.distance(point2) + pt.distance(point1)) - point1.distance(point2);
            if (distCand < bestDist) {
                bestDist = distCand;
                bestInx = i;
            }
        }
        final int lastIndex = bend.getAllHandles().size() - 1;
        final Handle lastHandle = bend.getAllHandles().get(lastIndex);
        final Point2D lastPoint = lastHandle.calculateHandleLocation(graphView.getViewModel(), this);
        final double lastCand = (pt.distance(targetPt) + pt.distance(lastPoint)) - targetPt.distance(lastPoint);
        if (lastCand < bestDist) {
            bestDist = lastCand;
            bestInx = bend.getAllHandles().size();
        }
        addHandleInternal(bestInx, pt);
        return bestInx;
    }
}
Also used : Point2D(java.awt.geom.Point2D) Bend(org.cytoscape.view.presentation.property.values.Bend) Paint(java.awt.Paint) Handle(org.cytoscape.view.presentation.property.values.Handle)

Example 3 with Handle

use of org.cytoscape.view.presentation.property.values.Handle in project cytoscape-impl by cytoscape.

the class LayerOrderNode method layout.

public void layout() {
    taskMonitor.setProgress(0.0);
    taskMonitor.setStatusMessage("Capturing snapshot of network and selected nodes");
    if (cancelled)
        return;
    /* construct node list with selected nodes first */
    int numLayoutNodes = nodesToLayOut.size();
    if (numLayoutNodes == 1) {
        // We were asked to do a hierchical layout of a single node -- done!
        return;
    }
    HashMap<Long, Integer> suid2Index = new HashMap<Long, Integer>(numLayoutNodes);
    List<View<CyNode>> nodeViews = new ArrayList<View<CyNode>>(nodesToLayOut);
    int index = 0;
    for (View<CyNode> view : nodeViews) {
        CyNode node = view.getModel();
        Long suid = node.getSUID();
        suid2Index.put(suid, index);
        index++;
    }
    if (cancelled)
        return;
    /* create edge list from edges between selected nodes */
    LinkedList<Edge> edges = new LinkedList();
    for (View<CyEdge> ev : networkView.getEdgeViews()) {
        // FIXME: much better would be to query adjacent edges of selected nodes...
        Integer edgeFrom = suid2Index.get(ev.getModel().getSource().getSUID());
        Integer edgeTo = suid2Index.get(ev.getModel().getTarget().getSUID());
        if ((edgeFrom == null) || (edgeTo == null)) {
            // Must be from an unselected node
            continue;
        }
        if (cancelled)
            return;
        if ((numLayoutNodes <= 1) || ((edgeFrom < numLayoutNodes) && (edgeTo < numLayoutNodes))) {
            /* add edge to graph */
            Edge theEdge = new Edge(edgeFrom, edgeTo);
            edges.add(theEdge);
        }
    }
    /* find horizontal and vertical coordinates of each node */
    Edge[] edge = new Edge[edges.size()];
    edges.toArray(edge);
    Graph graph = new Graph(numLayoutNodes, edge);
    /*
		int edgeIndex;
		for (edgeIndex = 0; edgeIndex<edge.length; edgeIndex++) {
		     System.out.println("Edge: " + edge[edgeIndex].getFrom() + " - " + edge[edgeIndex].getTo());
		}
		*/
    int[] cI = graph.componentIndex();
    int x;
    /*
		System.out.println("Node index:\n");
		for (x=0; x<graph.getNodecount(); x++) {
		    System.out.println(cI[x]);
		}
		System.out.println("Partitioning into components:\n");
		*/
    taskMonitor.setProgress(0.1);
    taskMonitor.setStatusMessage("Finding connected components");
    if (cancelled)
        return;
    int[] renumber = new int[cI.length];
    Graph[] component = graph.partition(cI, renumber);
    final int numComponents = component.length;
    int[][] layer = new int[numComponents][];
    int[][] horizontalPosition = new int[numComponents][];
    Graph[] reduced = new Graph[component.length];
    Graph[] reducedTmp = new Graph[component.length];
    HashMap<Integer, Edge>[] dummy2Edge = new HashMap[component.length];
    int[] dummyStartForComp = new int[component.length];
    HashMap<Edge, View<CyEdge>>[] myEdges2EdgeViews = new HashMap[component.length];
    for (x = 0; x < component.length; x++) {
        /*
			System.out.println("plain component:\n");
			System.out.println(component[x]);
			System.out.println("filtered component:\n");
			System.out.println(component[x].getGraphWithoutOneOrTwoCycles());
			System.out.println("nonmulti component:\n");
			System.out.println(component[x].getGraphWithoutMultipleEdges());
			int cycleEliminationPriority[] = component[x].getCycleEliminationVertexPriority();
			System.out.println("acyclic component:\n");
			System.out.println(component[x].getGraphWithoutCycles(cycleEliminationPriority));
			System.out.println("reduced component:\n");
			System.out.println(component[x].getReducedGraph());
			System.out.println("layer assignment:\n");
			*/
        taskMonitor.setProgress((20 + ((40 * (x * 3)) / numComponents / 3)) / 100.0);
        taskMonitor.setStatusMessage("making acyclic transitive reduction");
        Thread.yield();
        if (cancelled)
            return;
        reducedTmp[x] = component[x].getReducedGraph();
        taskMonitor.setProgress((20 + ((40 * ((x * 3) + 1)) / numComponents / 3)) / 100.0);
        taskMonitor.setStatusMessage("layering nodes vertically");
        Thread.yield();
        if (cancelled)
            return;
        layer[x] = reducedTmp[x].getVertexLayers();
        LinkedList<Integer> layerWithDummy = new LinkedList<Integer>();
        for (int i = 0; i < layer[x].length; i++) layerWithDummy.add(Integer.valueOf(layer[x][i]));
        /*
			int y;
			for (y=0;y<layer[x].length;y++) {
			    System.out.println("" + y + " : " + layer[x][y]);
			}
			System.out.println("horizontal position:\n");
			*/
        /* Insertion of the dummy nodes in the graph */
        Edge[] allEdges = component[x].GetEdges();
        LinkedList<Edge> edgesWithAdd = new LinkedList<Edge>();
        int dummyStart = component[x].getNodecount();
        dummyStartForComp[x] = dummyStart;
        dummy2Edge[x] = new HashMap<Integer, Edge>();
        for (int i = 0; i < allEdges.length; i++) {
            int from = allEdges[i].getFrom();
            int to = allEdges[i].getTo();
            if (layer[x][from] == (layer[x][to] + 1)) {
                edgesWithAdd.add(allEdges[i]);
            } else {
                if (layer[x][from] < layer[x][to]) {
                    int tmp = from;
                    from = to;
                    to = tmp;
                }
                layerWithDummy.add(Integer.valueOf(layer[x][to] + 1));
                dummy2Edge[x].put(Integer.valueOf(layerWithDummy.size() - 1), allEdges[i]);
                edgesWithAdd.add(new Edge(layerWithDummy.size() - 1, to));
                for (int j = layer[x][to] + 2; j < layer[x][from]; j++) {
                    layerWithDummy.add(Integer.valueOf(j));
                    dummy2Edge[x].put(Integer.valueOf(layerWithDummy.size() - 1), allEdges[i]);
                    edgesWithAdd.add(new Edge(layerWithDummy.size() - 1, layerWithDummy.size() - 2));
                }
                edgesWithAdd.add(new Edge(from, layerWithDummy.size() - 1));
            }
        }
        allEdges = new Edge[edgesWithAdd.size()];
        edgesWithAdd.toArray(allEdges);
        reduced[x] = new Graph(layerWithDummy.size(), allEdges);
        reduced[x].setDummyNodesStart(dummyStart);
        reduced[x].setReduced(true);
        int[] layerNew = new int[layerWithDummy.size()];
        Iterator<Integer> iter = layerWithDummy.iterator();
        for (int i = 0; i < layerNew.length; i++) layerNew[i] = iter.next();
        layer[x] = layerNew;
        taskMonitor.setProgress((20 + ((40 * ((x * 3) + 2)) / numComponents / 3)) / 100.0);
        taskMonitor.setStatusMessage("positioning nodes within layer");
        Thread.yield();
        if (cancelled)
            return;
        horizontalPosition[x] = reduced[x].getHorizontalPositionReverse(layer[x]);
    /*
			for (y=0;y<horizontalPosition[x].length;y++) {
			    System.out.println("" + y + " : " + horizontalPosition[x][y]);
			}
			*/
    }
    int resize = renumber.length;
    for (int i = 0; i < component.length; i++) resize += (layer[i].length - dummyStartForComp[i]);
    int[] newRenumber = new int[resize];
    int[] newcI = new int[resize];
    for (int i = 0; i < renumber.length; i++) {
        newRenumber[i] = renumber[i];
        newcI[i] = cI[i];
    }
    int t = renumber.length;
    for (int i = 0; i < reduced.length; i++) {
        for (int j = reduced[i].getDummyNodesStart(); j < reduced[i].getNodecount(); j++) {
            newRenumber[t] = j;
            newcI[t] = i;
            t++;
        }
    }
    renumber = newRenumber;
    cI = newcI;
    edges = new LinkedList<Edge>();
    for (int i = 0; i < reduced.length; i++) {
        edge = reduced[i].GetEdges();
        for (int j = 0; j < edge.length; j++) {
            // uzasna budzevina!!!!!! // FIXME: what does this mean?
            int from = -1;
            int to = -1;
            for (int k = 0; k < cI.length; k++) {
                if ((cI[k] == i) && (renumber[k] == edge[j].getFrom()))
                    from = k;
                if ((cI[k] == i) && (renumber[k] == edge[j].getTo()))
                    to = k;
                if ((from != -1) && (to != -1))
                    break;
            }
            // edges.add(new Edge(to, from));
            edges.add(new Edge(from, to));
        }
    }
    edge = new Edge[edges.size()];
    edges.toArray(edge);
    graph = new Graph(resize, edge);
    taskMonitor.setProgress(0.6);
    taskMonitor.setStatusMessage("Repositioning nodes in view");
    Thread.yield();
    if (cancelled)
        return;
    /* order nodeviews by layout order */
    HierarchyFlowLayoutOrderNode[] flowLayoutOrder = new HierarchyFlowLayoutOrderNode[resize];
    for (x = 0; x < resize; x++) {
        if (x < numLayoutNodes)
            flowLayoutOrder[x] = new HierarchyFlowLayoutOrderNode(nodeViews.get(x), cI[x], reduced[cI[x]].getNodecount(), layer[cI[x]][renumber[x]], horizontalPosition[cI[x]][renumber[x]], x);
        else
            flowLayoutOrder[x] = new HierarchyFlowLayoutOrderNode(null, cI[x], reduced[cI[x]].getNodecount(), layer[cI[x]][renumber[x]], horizontalPosition[cI[x]][renumber[x]], x);
        nodes2HFLON.put(x, flowLayoutOrder[x]);
    }
    Arrays.sort(flowLayoutOrder);
    int lastComponent = -1;
    int lastLayer = -1;
    int startBandY = context.topEdge;
    int cleanBandY = context.topEdge;
    int startComponentX = context.leftEdge;
    int cleanComponentX = context.leftEdge;
    int startLayerY = context.topEdge;
    int cleanLayerY = context.topEdge;
    int cleanLayerX = context.leftEdge;
    int[] layerStart = new int[numLayoutNodes + 1];
    /* layout nodes which are selected */
    int nodeIndex;
    /* layout nodes which are selected */
    int lastComponentEnd = -1;
    for (nodeIndex = 0; nodeIndex < resize; nodeIndex++) {
        HierarchyFlowLayoutOrderNode node = flowLayoutOrder[nodeIndex];
        int currentComponent = node.componentNumber;
        int currentLayer = node.layer;
        View<CyNode> currentView = node.nodeView;
        taskMonitor.setProgress((60 + ((40 * (nodeIndex + 1)) / resize)) / 100.0);
        taskMonitor.setStatusMessage("layering nodes vertically");
        Thread.yield();
        if (cancelled)
            return;
        if (lastComponent == -1) {
            /* this is the first component */
            lastComponent = currentComponent;
            lastLayer = currentLayer;
            layerStart[currentLayer] = -1;
        }
        if (lastComponent != currentComponent) {
            /* new component */
            // first call function for Horizontal Positioning of nodes in lastComponent
            int[] minXArray = new int[1];
            int maxX = HorizontalNodePositioning(nodeIndex - flowLayoutOrder[nodeIndex - 1].componentSize, nodeIndex - 1, flowLayoutOrder, graph, renumber, cI, dummyStartForComp, minXArray);
            int minX = minXArray[0];
            lastComponentEnd = nodeIndex - 1;
            for (int i = nodeIndex - flowLayoutOrder[nodeIndex - 1].componentSize; i <= (nodeIndex - 1); i++) flowLayoutOrder[i].xPos -= (minX - startComponentX);
            maxX -= (minX - startComponentX);
            layerStart[lastLayer] = startComponentX;
            /* initialize for new component */
            startComponentX = cleanComponentX + context.componentSpacing;
            if (maxX > startComponentX)
                startComponentX = maxX + context.componentSpacing;
            if (startComponentX > context.rightMargin) {
                /* new band */
                startBandY = cleanBandY + context.bandGap;
                cleanBandY = startBandY;
                startComponentX = context.leftEdge;
                cleanComponentX = context.leftEdge;
            }
            startLayerY = startBandY;
            cleanLayerY = startLayerY;
            cleanLayerX = startComponentX;
            layerStart[currentLayer] = -1;
        } else if (lastLayer != currentLayer) {
            /* new layer */
            layerStart[lastLayer] = startComponentX;
            startLayerY = cleanLayerY + context.nodeVerticalSpacing;
            cleanLayerY = startLayerY;
            cleanLayerX = startComponentX;
            layerStart[currentLayer] = -1;
        }
        node.setXPos(cleanLayerX);
        node.setYPos(startLayerY);
        cleanLayerX += context.nodeHorizontalSpacing;
        int currentBottom;
        int currentRight;
        if (currentView != null) {
            currentBottom = startLayerY + currentView.getVisualProperty(BasicVisualLexicon.NODE_HEIGHT).intValue();
            currentRight = cleanLayerX + currentView.getVisualProperty(BasicVisualLexicon.NODE_WIDTH).intValue();
        } else {
            currentBottom = startLayerY;
            currentRight = cleanLayerX;
        }
        if (currentBottom > cleanBandY)
            cleanBandY = currentBottom;
        if (currentRight > cleanComponentX)
            cleanComponentX = currentRight;
        if (currentBottom > cleanLayerY)
            cleanLayerY = currentBottom;
        if (currentRight > cleanLayerX)
            cleanLayerX = currentRight;
        lastComponent = currentComponent;
        lastLayer = currentLayer;
    }
    if (cancelled)
        return;
    /* Set horizontal positions of last component */
    int[] minXArray = new int[1];
    HorizontalNodePositioning(lastComponentEnd + 1, resize - 1, flowLayoutOrder, graph, renumber, cI, dummyStartForComp, minXArray);
    int minX = minXArray[0];
    for (int i = lastComponentEnd + 1; i < resize; i++) flowLayoutOrder[i].xPos -= (minX - startComponentX);
    /* Map edges to edge views in order to map dummy nodes to edge bends properly */
    for (View<CyEdge> ev : networkView.getEdgeViews()) {
        Integer edgeFrom = suid2Index.get(ev.getModel().getSource().getSUID());
        Integer edgeTo = suid2Index.get(ev.getModel().getTarget().getSUID());
        if ((edgeFrom == null) || (edgeTo == null)) {
            // Must be from an unselected node
            continue;
        }
        if ((numLayoutNodes <= 1) || ((edgeFrom < numLayoutNodes) && (edgeTo < numLayoutNodes))) {
            /* add edge to graph */
            Edge theEdge = component[cI[edgeFrom]].GetTheEdge(renumber[edgeFrom], renumber[edgeTo]);
            if (myEdges2EdgeViews[cI[edgeFrom]] == null)
                myEdges2EdgeViews[cI[edgeFrom]] = new HashMap<Edge, View<CyEdge>>();
            myEdges2EdgeViews[cI[edgeFrom]].put(theEdge, ev);
        }
    }
    for (nodeIndex = 0; nodeIndex < resize; nodeIndex++) {
        HierarchyFlowLayoutOrderNode node = flowLayoutOrder[nodeIndex];
        if (node.nodeView != null) {
            View<CyNode> currentView = node.nodeView;
            currentView.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION, Double.valueOf((double) node.getXPos()));
            currentView.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION, Double.valueOf((double) node.getYPos()));
        }
    }
    final HandleFactory handleFactory = serviceRegistrar.getService(HandleFactory.class);
    final BendFactory bendFactory = serviceRegistrar.getService(BendFactory.class);
    for (nodeIndex = 0; nodeIndex < resize; nodeIndex++) {
        HierarchyFlowLayoutOrderNode node = flowLayoutOrder[nodeIndex];
        if (node.nodeView == null) {
            Edge theEdge = (Edge) dummy2Edge[cI[node.graphIndex]].get(Integer.valueOf(renumber[node.graphIndex]));
            View<CyEdge> ev = myEdges2EdgeViews[cI[node.graphIndex]].get(theEdge);
            if (ev != null) {
                View<CyNode> source = networkView.getNodeView(ev.getModel().getSource());
                View<CyNode> target = networkView.getNodeView(ev.getModel().getTarget());
                double k = (getYPositionOf(target) - getYPositionOf(source)) / (getXPositionOf(target) - getXPositionOf(source));
                double xPos = getXPositionOf(source);
                if (k != 0)
                    xPos += ((node.yPos - getYPositionOf(source)) / k);
                Bend b = bendFactory.createBend();
                Handle h = handleFactory.createHandle(networkView, ev, xPos, node.yPos);
                b.insertHandleAt(0, h);
                ev.setVisualProperty(BasicVisualLexicon.EDGE_BEND, b);
            }
        }
    }
    for (nodeIndex = 0; nodeIndex < resize; nodeIndex++) {
        HierarchyFlowLayoutOrderNode node = flowLayoutOrder[nodeIndex];
        if (node.nodeView == null) {
            Edge theEdge = dummy2Edge[cI[node.graphIndex]].get(Integer.valueOf(renumber[node.graphIndex]));
            View<CyEdge> ev = myEdges2EdgeViews[cI[node.graphIndex]].get(theEdge);
            if (ev != null) {
                List<Handle> handles = ev.getVisualProperty(BasicVisualLexicon.EDGE_BEND).getAllHandles();
                for (Handle h : handles) {
                    Point2D handelPt = h.calculateHandleLocation(networkView, ev);
                    if (handelPt.getY() == node.yPos) {
                        h.defineHandle(networkView, ev, (double) (node.xPos), (double) (node.yPos));
                        break;
                    }
                }
            }
        }
    }
    taskMonitor.setProgress(1.0);
    taskMonitor.setStatusMessage("hierarchical layout complete");
}
Also used : BendFactory(org.cytoscape.view.presentation.property.values.BendFactory) HashMap(java.util.HashMap) Bend(org.cytoscape.view.presentation.property.values.Bend) ArrayList(java.util.ArrayList) HandleFactory(org.cytoscape.view.presentation.property.values.HandleFactory) Point2D(java.awt.geom.Point2D) CyNode(org.cytoscape.model.CyNode) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge) LinkedList(java.util.LinkedList) Handle(org.cytoscape.view.presentation.property.values.Handle) CyEdge(org.cytoscape.model.CyEdge)

Example 4 with Handle

use of org.cytoscape.view.presentation.property.values.Handle in project cytoscape-impl by cytoscape.

the class InnerCanvas method handleArrowKeys.

/**
 * Arrow key handler.
 * They are used to pan and mode nodes/edge bend handles.
 * @param k key event
 */
private void handleArrowKeys(KeyEvent k) {
    final int code = k.getKeyCode();
    double move = 1.0;
    // Adjust increment if Shift key is pressed
    if (k.isShiftDown())
        move = 15.0;
    // Pan if CTR is pressed.
    if (isControlOrMetaDown(k)) {
        // Pan
        if (code == KeyEvent.VK_UP) {
            pan(0, move);
        } else if (code == KeyEvent.VK_DOWN) {
            pan(0, -move);
        } else if (code == KeyEvent.VK_LEFT) {
            pan(-move, 0);
        } else if (code == KeyEvent.VK_RIGHT) {
            pan(move, 0);
        }
        return;
    }
    if (m_view.m_nodeSelection) {
        // move nodes
        final long[] selectedNodes = m_view.getSelectedNodeIndices();
        for (int i = 0; i < selectedNodes.length; i++) {
            DNodeView nv = ((DNodeView) m_view.getDNodeView(selectedNodes[i]));
            double xPos = nv.getXPosition();
            double yPos = nv.getYPosition();
            if (code == KeyEvent.VK_UP) {
                yPos -= move;
            } else if (code == KeyEvent.VK_DOWN) {
                yPos += move;
            } else if (code == KeyEvent.VK_LEFT) {
                xPos -= move;
            } else if (code == KeyEvent.VK_RIGHT) {
                xPos += move;
            }
            nv.setOffset(xPos, yPos);
        }
        // move edge anchors
        LongEnumerator anchorsToMove = m_view.m_selectedAnchors.searchRange(Integer.MIN_VALUE, Integer.MAX_VALUE, false);
        while (anchorsToMove.numRemaining() > 0) {
            final long edgeAndAnchor = anchorsToMove.nextLong();
            final long edge = edgeAndAnchor >>> 6;
            final int anchorInx = (int) (edgeAndAnchor & 0x000000000000003f);
            final DEdgeView ev = (DEdgeView) m_view.getDEdgeView(edge);
            if (!ev.isValueLocked(BasicVisualLexicon.EDGE_BEND)) {
                Bend defaultBend = ev.getDefaultValue(BasicVisualLexicon.EDGE_BEND);
                if (ev.getVisualProperty(BasicVisualLexicon.EDGE_BEND) == defaultBend) {
                    ev.setLockedValue(BasicVisualLexicon.EDGE_BEND, new BendImpl((BendImpl) defaultBend));
                } else {
                    ev.setLockedValue(BasicVisualLexicon.EDGE_BEND, new BendImpl((BendImpl) ev.getBend()));
                }
            }
            final Bend bend = ev.getVisualProperty(BasicVisualLexicon.EDGE_BEND);
            final Handle handle = bend.getAllHandles().get(anchorInx);
            final Point2D newPoint = handle.calculateHandleLocation(m_view.getViewModel(), ev);
            m_floatBuff1[0] = (float) newPoint.getX();
            m_floatBuff1[1] = (float) newPoint.getY();
            if (code == KeyEvent.VK_UP) {
                ev.moveHandleInternal(anchorInx, m_floatBuff1[0], m_floatBuff1[1] - move);
            } else if (code == KeyEvent.VK_DOWN) {
                ev.moveHandleInternal(anchorInx, m_floatBuff1[0], m_floatBuff1[1] + move);
            } else if (code == KeyEvent.VK_LEFT) {
                ev.moveHandleInternal(anchorInx, m_floatBuff1[0] - move, m_floatBuff1[1]);
            } else if (code == KeyEvent.VK_RIGHT) {
                ev.moveHandleInternal(anchorInx, m_floatBuff1[0] + move, m_floatBuff1[1]);
            }
        }
        repaint();
    }
}
Also used : LongEnumerator(org.cytoscape.util.intr.LongEnumerator) Point2D(java.awt.geom.Point2D) Bend(org.cytoscape.view.presentation.property.values.Bend) Point(java.awt.Point) Handle(org.cytoscape.view.presentation.property.values.Handle)

Example 5 with Handle

use of org.cytoscape.view.presentation.property.values.Handle in project cytoscape-impl by cytoscape.

the class BendImpl method getSerializableString.

@Override
public String getSerializableString() {
    final StringBuilder builder = new StringBuilder();
    for (Handle handle : handles) builder.append(handle.getSerializableString() + DELIMITER);
    final String serialized = builder.toString();
    if (serialized.length() == 0)
        return "";
    return serialized.substring(0, serialized.length() - 1);
}
Also used : Handle(org.cytoscape.view.presentation.property.values.Handle)

Aggregations

Handle (org.cytoscape.view.presentation.property.values.Handle)10 Bend (org.cytoscape.view.presentation.property.values.Bend)8 Point2D (java.awt.geom.Point2D)5 Paint (java.awt.Paint)3 CyEdge (org.cytoscape.model.CyEdge)3 CyNode (org.cytoscape.model.CyNode)2 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 CyColumn (org.cytoscape.model.CyColumn)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyTable (org.cytoscape.model.CyTable)1 LongEnumerator (org.cytoscape.util.intr.LongEnumerator)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1 View (org.cytoscape.view.model.View)1 BendFactory (org.cytoscape.view.presentation.property.values.BendFactory)1 HandleFactory (org.cytoscape.view.presentation.property.values.HandleFactory)1 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)1 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)1