use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation in project cytoscape-impl by cytoscape.
the class CanvasMouseWheelListener method mouseWheelMoved.
// To handle zooming in and out
public void mouseWheelMoved(MouseWheelEvent e) {
int notches = e.getWheelRotation();
double factor = 1.0;
// scroll up, zoom in
if (notches < 0)
factor = 1.1;
else if (notches > 0)
factor = 0.9;
else
return;
Set<DingAnnotation> selectedAnnotations = cyAnnotator.getSelectedAnnotations();
if (selectedAnnotations != null && selectedAnnotations.size() > 0) {
// If some annotations are selected
for (DingAnnotation annotation : selectedAnnotations) {
annotation.setSpecificZoom(prevZoom * factor);
}
// In that case only increase the size (Change font in some cases)
// for those specific annotations
prevZoom *= factor;
} else {
networkCanvas.mouseWheelMoved(e);
}
}
use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation in project cytoscape-impl by cytoscape.
the class AnnotationManagerImpl method removeAnnotations.
@Override
public void removeAnnotations(Collection<? extends Annotation> annotations) {
Map<DGraphView, List<DingAnnotation>> annotationsByView = groupByView(annotations);
if (annotationsByView.isEmpty())
return;
invokeOnEDTAndWait(() -> {
annotationsByView.forEach((view, viewAnnotations) -> {
Map<ArbitraryGraphicsCanvas, List<DingAnnotation>> annotationsByCanvas = groupByCanvas(view, viewAnnotations);
annotationsByCanvas.forEach((canvas, dingAnnotations) -> {
// The following code is a batch version of Annotation.removeAnnotation()
for (DingAnnotation a : dingAnnotations) {
GroupAnnotation parent = a.getGroupParent();
if (parent != null) {
parent.removeMember(a);
}
}
canvas.removeAnnotations(getArrows(dingAnnotations));
canvas.removeAnnotations(dingAnnotations);
canvas.repaint();
});
});
});
}
use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation in project cytoscape-impl by cytoscape.
the class CanvasKeyListener method keyPressed.
public void keyPressed(KeyEvent e) {
int code = e.getKeyCode();
Set<DingAnnotation> selectedAnnotations = cyAnnotator.getSelectedAnnotations();
if ((selectedAnnotations != null && selectedAnnotations.size() > 0) && ((code == KeyEvent.VK_UP) || (code == KeyEvent.VK_DOWN) || (code == KeyEvent.VK_LEFT) || (code == KeyEvent.VK_RIGHT))) {
// Some annotations have been double clicked and selected
int move = 2;
for (DingAnnotation annotation : selectedAnnotations) {
Component c = annotation.getComponent();
int x = c.getX(), y = c.getY();
int shiftMask = e.getModifiers() & KeyEvent.SHIFT_DOWN_MASK;
if (annotation instanceof ShapeAnnotationImpl && e.isShiftDown()) {
ShapeAnnotationImpl sa = (ShapeAnnotationImpl) annotation;
int width = c.getWidth(), height = c.getHeight();
if (code == KeyEvent.VK_UP) {
height -= move;
} else if (code == KeyEvent.VK_DOWN) {
height += move;
} else if (code == KeyEvent.VK_LEFT) {
width -= move;
} else if (code == KeyEvent.VK_RIGHT) {
width += move;
}
// Adjust the size of the selected annotations
sa.setSize((double) width, (double) height);
} else {
if (code == KeyEvent.VK_UP)
y -= move;
else if (code == KeyEvent.VK_DOWN)
y += move;
else if (code == KeyEvent.VK_LEFT)
x -= move;
else if (code == KeyEvent.VK_RIGHT)
x += move;
// Adjust the locations of the selected annotations
annotation.getComponent().setLocation(x, y);
}
annotation.update();
annotation.getCanvas().repaint();
}
return;
} else if (code == KeyEvent.VK_ESCAPE) {
if (cyAnnotator.getResizeShape() != null) {
cyAnnotator.getResizeShape().contentChanged();
cyAnnotator.resizeShape(null);
return;
}
if (cyAnnotator.getRepositioningArrow() != null) {
cyAnnotator.getRepositioningArrow().contentChanged();
cyAnnotator.positionArrow(null);
return;
}
if (cyAnnotator.getMovingAnnotation() != null) {
cyAnnotator.getMovingAnnotation().contentChanged();
cyAnnotator.moveAnnotation(null);
return;
}
}
networkCanvas.keyPressed(e);
}
use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation in project cytoscape-impl by cytoscape.
the class CanvasMouseMotionListener method mouseMoved.
public void mouseMoved(MouseEvent e) {
AbstractAnnotation resizeAnnotation = cyAnnotator.getResizeShape();
DingAnnotation moveAnnotation = cyAnnotator.getMovingAnnotation();
ArrowAnnotationImpl repositionAnnotation = cyAnnotator.getRepositioningArrow();
if (resizeAnnotation == null && moveAnnotation == null && repositionAnnotation == null) {
networkCanvas.mouseMoved(e);
return;
}
int mouseX = e.getX();
int mouseY = e.getY();
if (moveAnnotation != null) {
// Get our current transform
double[] nextLocn = new double[2];
nextLocn[0] = (double) mouseX;
nextLocn[1] = (double) mouseY;
view.xformComponentToNodeCoords(nextLocn);
// OK, now update
moveAnnotation.moveAnnotation(new Point2D.Double(nextLocn[0], nextLocn[1]));
moveAnnotation.update();
moveAnnotation.getCanvas().repaint();
} else if (resizeAnnotation != null) {
Component resizeComponent = resizeAnnotation.getComponent();
int cornerX1 = resizeComponent.getX();
int cornerY1 = resizeComponent.getY();
// int cornerX2 = cornerX1 + resizeComponent.getWidth();
// int cornerY2 = cornerY1 + resizeComponent.getHeight();
int cornerX2 = mouseX;
int cornerY2 = mouseY;
double borderWidth = 0;
if (resizeAnnotation instanceof ShapeAnnotationImpl)
borderWidth = ((ShapeAnnotationImpl) resizeAnnotation).getBorderWidth();
/*
* TODO: change over to use anchors at some point
*/
/*
if (Math.abs(mouseX-cornerX1) < Math.abs(mouseX-cornerX2)) {
// Left
cornerX1 = mouseX;
} else {
// Right
cornerX2 = mouseX;
}
*/
// System.out.println("X1 = "+cornerX1+", X2 = "+cornerX2+" width = "+resizeComponent.getWidth());
double width = (double) cornerX2 - (double) cornerX1 - (borderWidth * 2 * resizeAnnotation.getZoom());
// System.out.println("width = "+width);
/*
if (mouseY <= cornerY1) {
// Upper
cornerY1 = mouseY;
} else if (mouseY >= cornerY2-resizeComponent.getHeight()/2) {
// Lower
cornerY2 = mouseY;
}
*/
double height = (double) cornerY2 - (double) cornerY1 - (borderWidth * 2 * resizeAnnotation.getZoom());
if (width == 0.0)
width = 2;
if (height == 0.0)
height = 2;
if ((Math.abs(width - resizeComponent.getWidth()) < 5) && (Math.abs(height - resizeComponent.getHeight()) < 5))
return;
Dimension d = new Dimension();
d.setSize(width, height);
// If shift is down, adjust to preserve the aspect ratio
if (e.isShiftDown()) {
d = resizeAnnotation.adjustAspectRatio(d);
}
// resizeComponent.setLocation(cornerX1, cornerY1);
resizeAnnotation.setSize(d);
resizeAnnotation.update();
resizeAnnotation.getCanvas().repaint();
} else if (repositionAnnotation != null) {
Point2D mousePoint = new Point2D.Double(mouseX, mouseY);
// See what's under our mouse
// Annotation?
List<DingAnnotation> annotations = cyAnnotator.getAnnotationsAt(mousePoint);
if (annotations.contains(repositionAnnotation))
annotations.remove(repositionAnnotation);
if (annotations.size() > 0) {
repositionAnnotation.setTarget(annotations.get(0));
// Node?
} else if (overNode(mousePoint)) {
CyNode overNode = getNodeAtLocation(mousePoint);
repositionAnnotation.setTarget(overNode);
// Nope, just set the point
} else {
repositionAnnotation.setTarget(mousePoint);
}
repositionAnnotation.update();
repositionAnnotation.getCanvas().repaint();
}
}
use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation in project cytoscape-impl by cytoscape.
the class LayerAnnotationTask method run.
@Override
public void run(TaskMonitor tm) throws Exception {
JComponent canvas = annotation.getCanvas();
if (annotation instanceof GroupAnnotation) {
int z = zorder;
for (Annotation ann : ((GroupAnnotation) annotation).getMembers()) {
DingAnnotation dAnn = (DingAnnotation) ann;
z += 1;
dAnn.getCanvas().setComponentZOrder(dAnn.getComponent(), z);
}
}
canvas.setComponentZOrder(annotation.getComponent(), zorder);
canvas.repaint();
if (view instanceof DGraphView) {
DGraphView dView = (DGraphView) view;
CyAnnotator cyAnnotator = dView.getCyAnnotator();
// Force an update of all of the argMaps
for (Annotation ann : cyAnnotator.getAnnotations()) cyAnnotator.addAnnotation(ann);
}
// We need to do this to update the Bird's Eye View
annotation.contentChanged();
}
Aggregations