use of org.cytoscape.util.intr.LongEnumerator in project cytoscape-impl by cytoscape.
the class DGraphView method fitSelected.
@Override
public void fitSelected() {
getEventHelper().flushPayloadEvents();
synchronized (m_lock) {
LongEnumerator selectedElms = m_selectedNodes.searchRange(Integer.MIN_VALUE, Integer.MAX_VALUE, false);
// Only check for selected edges if we don't have selected nodes.
if (selectedElms.numRemaining() == 0 && edgeSelectionEnabled()) {
selectedElms = getSelectedEdgeNodes();
if (selectedElms.numRemaining() == 0)
return;
}
float xMin = Float.POSITIVE_INFINITY;
float yMin = Float.POSITIVE_INFINITY;
float xMax = Float.NEGATIVE_INFINITY;
float yMax = Float.NEGATIVE_INFINITY;
long leftMost = 0;
long rightMost = 0;
while (selectedElms.numRemaining() > 0) {
final long node = selectedElms.nextLong();
m_spacial.exists(node, m_extentsBuff, 0);
if (m_extentsBuff[0] < xMin) {
xMin = m_extentsBuff[0];
leftMost = node;
}
if (m_extentsBuff[2] > xMax) {
xMax = m_extentsBuff[2];
rightMost = node;
}
yMin = Math.min(yMin, m_extentsBuff[1]);
yMax = Math.max(yMax, m_extentsBuff[3]);
}
xMin = xMin - (getLabelWidth(leftMost) / 2);
xMax = xMax + (getLabelWidth(rightMost) / 2);
if (!isValueLocked(BasicVisualLexicon.NETWORK_CENTER_Y_LOCATION)) {
double zoom = Math.min(((double) m_networkCanvas.getWidth()) / (((double) xMax) - ((double) xMin)), ((double) m_networkCanvas.getHeight()) / (((double) yMax) - ((double) yMin)));
zoom = checkZoom(zoom, m_networkCanvas.m_scaleFactor);
// Update view model. Zoom Level should be modified.
setVisualProperty(BasicVisualLexicon.NETWORK_SCALE_FACTOR, zoom);
}
if (!isValueLocked(BasicVisualLexicon.NETWORK_CENTER_X_LOCATION)) {
final double xCenter = (((double) xMin) + ((double) xMax)) / 2.0d;
setVisualProperty(BasicVisualLexicon.NETWORK_CENTER_X_LOCATION, xCenter);
}
if (!isValueLocked(BasicVisualLexicon.NETWORK_CENTER_Y_LOCATION)) {
final double yCenter = (((double) yMin) + ((double) yMax)) / 2.0d;
setVisualProperty(BasicVisualLexicon.NETWORK_CENTER_Y_LOCATION, yCenter);
}
}
updateView(false);
}
use of org.cytoscape.util.intr.LongEnumerator in project cytoscape-impl by cytoscape.
the class DGraphView method getSelectedNodes.
/**
* Returns a list of selected node objects.
*/
@Override
public List<CyNode> getSelectedNodes() {
synchronized (m_lock) {
// all nodes from the btree
final LongEnumerator elms = m_selectedNodes.searchRange(Integer.MIN_VALUE, Integer.MAX_VALUE, false);
final ArrayList<CyNode> returnThis = new ArrayList<>();
while (elms.numRemaining() > 0) // GINY requires all node indices to be negative (why?),
// hence the bitwise complement here.
returnThis.add(model.getNode(elms.nextLong()));
return returnThis;
}
}
use of org.cytoscape.util.intr.LongEnumerator in project cytoscape-impl by cytoscape.
the class DGraphView method getSelectedNodeIndices.
/**
* Returns an array of selected node indices.
*
* @return An array of selected node indices.
*/
@Override
public long[] getSelectedNodeIndices() {
// XXX: why isn't this synchronized on m_selectedNodes?
synchronized (m_lock) {
// all nodes from the btree
final LongEnumerator elms = m_selectedNodes.searchRange(Integer.MIN_VALUE, Integer.MAX_VALUE, false);
final long[] returnThis = new long[elms.numRemaining()];
for (int i = 0; i < returnThis.length; i++) // GINY requires all node indices to be negative (why?),
// hence the bitwise complement here.
returnThis[i] = elms.nextLong();
return returnThis;
}
}
use of org.cytoscape.util.intr.LongEnumerator in project cytoscape-impl by cytoscape.
the class InnerCanvas method setSelectedNodes.
private long[] setSelectedNodes() {
long[] selectedNodes = null;
m_ptBuff[0] = m_selectionRect.x;
m_ptBuff[1] = m_selectionRect.y;
m_view.xformComponentToNodeCoords(m_ptBuff);
final double xMin = m_ptBuff[0];
final double yMin = m_ptBuff[1];
m_ptBuff[0] = m_selectionRect.x + m_selectionRect.width;
m_ptBuff[1] = m_selectionRect.y + m_selectionRect.height;
m_view.xformComponentToNodeCoords(m_ptBuff);
final double xMax = m_ptBuff[0];
final double yMax = m_ptBuff[1];
m_stack.empty();
m_view.getNodesIntersectingRectangle((float) xMin, (float) yMin, (float) xMax, (float) yMax, (m_lastRenderDetail & GraphRenderer.LOD_HIGH_DETAIL) == 0, m_stack);
m_stack2.empty();
final LongEnumerator nodesXSect = m_stack.elements();
while (nodesXSect.numRemaining() > 0) {
final long nodeXSect = nodesXSect.nextLong();
if (m_view.m_selectedNodes.count(nodeXSect) == 0)
m_stack2.push(nodeXSect);
}
selectedNodes = new long[m_stack2.size()];
final LongEnumerator nodes = m_stack2.elements();
for (int i = 0; i < selectedNodes.length; i++) selectedNodes[i] = nodes.nextLong();
if (selectedNodes.length > 0)
m_view.setContentChanged();
return selectedNodes;
}
use of org.cytoscape.util.intr.LongEnumerator 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();
}
}
Aggregations