@Override
 public void execute() {
   Map<SNode, Point2D.Double> diffs = new HashMap<SNode, Point2D.Double>();
   double left = Integer.MAX_VALUE;
   for (SNode node : context.getSelection().items()) {
     left = Math.min(left, node.getTransformedBounds().getX());
   }
   for (SNode node : context.getSelection().items()) {
     Bounds bounds = node.getTransformedBounds();
     double diff = left - (bounds.getX());
     node.setTranslateX(node.getTranslateX() + diff);
     diffs.put(node, new Point2D.Double(diff, 0));
   }
   context.redraw();
   AlignUndoAction action = new AlignUndoAction(diffs, context, getDisplayName());
   context.getUndoManager().pushAction(action);
 }
 @Override
 public void execute() {
   Map<SNode, Point2D.Double> diffs = new HashMap<SNode, Point2D.Double>();
   double top = Integer.MAX_VALUE;
   for (SNode node : context.getSelection().items()) {
     top = Math.min(top, node.getTransformedBounds().getY());
   }
   for (SNode node : context.getSelection().items()) {
     Bounds bounds = node.getTransformedBounds();
     double diff = top - (bounds.getY());
     node.setTranslateY(node.getTranslateY() + diff);
     diffs.put(node, new Point2D.Double(0, diff));
   }
   context.redraw();
   AlignUndoAction action = new AlignUndoAction(diffs, context, getString("menus.alignNodeTop"));
   context.getUndoManager().pushAction(action);
 }
 @Override
 public void execute() {
   Map<SNode, Point2D.Double> diffs = new HashMap<SNode, Point2D.Double>();
   double bottom = Integer.MIN_VALUE;
   for (SNode node : context.getSelection().items()) {
     Bounds bounds = node.getTransformedBounds();
     bottom = Math.max(bottom, bounds.getY() + bounds.getHeight());
   }
   for (SNode node : context.getSelection().items()) {
     Bounds bounds = node.getTransformedBounds();
     double diff = bottom - (bounds.getY() + bounds.getHeight());
     node.setTranslateY(node.getTranslateY() + diff);
     diffs.put(node, new Point2D.Double(0, diff));
   }
   context.redraw();
   AlignUndoAction action = new AlignUndoAction(diffs, context, getDisplayName());
   context.getUndoManager().pushAction(action);
 }
Beispiel #4
0
  private void processInput(MouseEvent event) {
    double ex = event.getX();
    double ey = event.getY();

    if (event.getType() == MouseEvent.MousePressed) {
      Bounds startArrowBounds = getStartArrowBounds();
      if (startArrowBounds.contains(event.getX(), event.getY())) {
        setValue(getValue() - smallScroll);
        return;
      }
      Bounds endArrowBounds = getEndArrowBounds();
      if (endArrowBounds.contains(event.getX(), event.getY())) {
        setValue(getValue() + smallScroll);
        return;
      }

      Bounds trackBounds = getTrackBounds();
      Bounds thumbBounds = calculateThumbBounds();
      if (thumbBounds.contains(ex, ey)) {
        thumbPressed = true;
        if (isVertical()) {
          offPX = event.getY() - calculateThumbBounds().getY();
        } else {
          offPX = event.getX() - calculateThumbBounds().getX();
        }
        startPX = new Point2D.Double(ex, ey);
      } else {
        if (trackBounds.contains(ex, ey)) {
          if (ex < thumbBounds.getX()) {
            setValue(getValue() - largeScroll);
          }
          if (ex > thumbBounds.getX() + thumbBounds.getWidth()) {
            setValue(getValue() + largeScroll);
          }
          if (ey < thumbBounds.getY()) {
            setValue(getValue() - largeScroll);
          }
          if (ey > thumbBounds.getY() + thumbBounds.getHeight()) {
            setValue(getValue() + largeScroll);
          }
        }
      }
    }

    if (event.getType() == MouseEvent.MouseDragged) {
      if (thumbPressed) {
        Point2D currentPX = new Point2D.Double(event.getX(), event.getY());
        double value = pxToValue(currentPX, offPX);
        setValue(value);
      }
    }
    if (event.getType() == MouseEvent.MouseReleased) {
      thumbPressed = false;
    }
  }
Beispiel #5
0
  @Override
  public void draw(GFX g) {
    if (!isVisible()) return;
    boxPainter.draw(g, styleInfo, sizeInfo, "");

    Bounds leftArrowBounds = new Bounds(0, 0, arrowLength, getHeight());
    Bounds rightArrowBounds = new Bounds(getWidth() - arrowLength, 0, arrowLength, getHeight());
    Bounds thumbBounds = calculateThumbBounds();
    if (isVertical()) {
      leftArrowBounds = new Bounds(0, 0, getWidth(), arrowLength);
      rightArrowBounds = new Bounds(0, getHeight() - arrowLength, getWidth(), arrowLength);
    }

    Bounds trackBounds = getTrackBounds();
    trackSizeInfo.width = trackBounds.getWidth();
    trackSizeInfo.height = trackBounds.getHeight();
    g.translate(trackBounds.getX(), trackBounds.getY());
    trackPainter.draw(g, trackStyleInfo, trackSizeInfo, "");
    g.translate(-trackBounds.getX(), -trackBounds.getY());

    leftArrowSizeInfo.width = leftArrowBounds.getWidth();
    leftArrowSizeInfo.height = leftArrowBounds.getHeight();
    leftArrowPainter.draw(g, leftArrowStyleInfo, leftArrowSizeInfo, "");

    g.translate(rightArrowBounds.getX(), rightArrowBounds.getY());
    rightArrowSizeInfo.width = rightArrowBounds.getWidth();
    rightArrowSizeInfo.height = rightArrowBounds.getHeight();
    rightArrowPainter.draw(g, rightArrowStyleInfo, rightArrowSizeInfo, "");
    g.translate(-rightArrowBounds.getX(), -rightArrowBounds.getY());

    g.translate(thumbBounds.getX(), thumbBounds.getY());
    thumbSizeInfo.width = thumbBounds.getWidth();
    thumbSizeInfo.height = thumbBounds.getHeight();
    thumbPainter.draw(g, thumbStyleInfo, thumbSizeInfo, "");
    g.translate(-thumbBounds.getX(), -thumbBounds.getY());

    // draw the arrows
    /*
    g.setPaint(new FlatColor(0x303030));
    if(isVertical()) {
        GraphicsUtil.fillUpArrow(g,2,2,10);
        GraphicsUtil.fillDownArrow(g,2,getHeight()-2-10,10);
    } else {
        GraphicsUtil.fillLeftArrow(g,2,2,10);
        GraphicsUtil.fillRightArrow(g,getWidth()-2-10,2,10);
    }
    */
  }