예제 #1
0
 public SizeHandle(VertexView vertexview, GraphContext ctx) {
   graph = ctx.getGraph();
   vertex = vertexview;
   editing = graph.getEditingCell() == vertex.getCell();
   int sizeableAxis = GraphConstants.getSizeableAxis(vertex.getAllAttributes());
   if (sizeableAxis == GraphConstants.X_AXIS) cursors = xCursors;
   else if (sizeableAxis == GraphConstants.Y_AXIS) cursors = yCursors;
   else cursors = defaultCursors;
   // PortView Preview
   portViews = ctx.createTemporaryPortViews();
   initialBounds = (Rectangle2D) vertex.getBounds().clone();
   context = ctx;
   for (int i = 0; i < r.length; i++) r[i] = new Rectangle2D.Double();
   invalidate();
 }
예제 #2
0
 protected Rectangle2D computeBounds(MouseEvent event) {
   double left = initialBounds.getX();
   double right = initialBounds.getX() + initialBounds.getWidth() - 1;
   double top = initialBounds.getY();
   double bottom = initialBounds.getY() + initialBounds.getHeight() - 1;
   Point2D p = graph.fromScreen(graph.snap((Point2D) event.getPoint().clone()));
   // Not into negative coordinates
   p.setLocation(Math.max(0, p.getX()), Math.max(0, p.getY()));
   // Bottom row
   if (index > 4) bottom = p.getY();
   // Top row
   else if (index < 3) top = p.getY();
   // Left col
   if (index == 0 || index == 3 || index == 5) left = p.getX();
   // Right col
   else if (index == 2 || index == 4 || index == 7) right = p.getX();
   double width = right - left;
   double height = bottom - top;
   if (isConstrainedSizeEvent(event)
       || GraphConstants.isConstrained(vertex.getAllAttributes())) {
     if (index == 3 || index == 4 || index == 5) height = width;
     else if (index == 1 || index == 6 || index == 2 || index == 7) width = height;
     else {
       height = width;
       top = bottom - height;
     }
   }
   if (width < 0) { // Flip over left side
     left += width;
     width = Math.abs(width);
   }
   if (height < 0) { // Flip over top side
     top += height;
     height = Math.abs(height);
   }
   return new Rectangle2D.Double(left, top, width + 1, height + 1);
 }