Package ket.display.box

Examples of ket.display.box.Box


    switch (displayStyle) {
      case JOIN:
        for (State state : states) {
          boxArgs.add(state.toBox(argument, bold, colourScheme));
        }
        Box box = BoxTools.centredHorizontalBoxList(argument, 0L, boxArgs);
        box.setProperty(settings);
        return box;

      case SUBSCRIPT:
        assert size()==2 : "Cannot process subscript size";
        Box first = states.firstElement().toBox(
            argument,
            Box.RIGHT_ALIGN|Box.Y_CENTRE_ALIGN|bold,
            colourScheme);
        //- first.setArgument(argument);
        boxArgs.add(first);
        Box subscript = states.lastElement().toBox(
            argument,
            Box.LEFT_ALIGN|Box.BOTTOM_ALIGN|Box.SMALL_FONT,
            colourScheme);
        //- subscript.setArgument(argument);
        boxArgs.add(subscript);
        Box result = Function.SUBSCRIPT.toBox(
            argument,
            boxArgs,
            settings,
            colourScheme);
        //- result.setArgument(argument);
View Full Code Here


      case 2:
        // Repeated pattern new String[]{number.number, pattern};
        BoxWord prefix = new BoxWord(argument, string[0], settings);
        BoxWord pattern = new BoxWord(argument, string[1], settings);
        BoxGraphic horizontalBar = new BoxGraphic(argument, 0L, BoxGraphic.HORIZONTAL_LINE);
        Box argsAndOverbar = BoxTools.centredVerticalBoxList(argument, settings, horizontalBar, pattern);
        Box box = BoxTools.centredHorizontalBoxList(argument, 0L, prefix, argsAndOverbar);
        horizontalBar.setProperty(Box.HORIZONTAL_STRETCH);
        horizontalBar.setProperty(Box.BOTTOM_ALIGN);
        return box;

      default:
View Full Code Here

  @Override
  public Box toBox(Argument argument, long settings, ColourScheme colourScheme, Vector<Argument> args) {
    Box[][] table = asTable(args, colourScheme);
    if (table!=null) {
      Box matrixWithoutBrackets = BoxTools.gridToBox(argument, table);
      BoxGraphic open = new BoxGraphic(argument, 0L, BoxGraphic.OPEN_PARENTHESIS);
      BoxList result = BoxTools.centredHorizontalBoxList(argument, settings, open, matrixWithoutBrackets);
      open.setProperty(Box.PRESERVE_ASPECT_RATIO|Box.VERTICAL_STRETCH|Box.PLAIN_FONT);
      result.setProperty(settings); //n
      return result;
View Full Code Here

  @Override
  public Box toBox(Argument argument, Vector<Box> boxArgs, long settings, ColourScheme colourScheme) {
    if (isPrefixOnly() && f.displayBrackets()) {
      // Generalization of a simple function, e.g. \alpha:(x,y).
      Box boxText = getPrefix().toBox(argument,
          Box.PLAIN_FONT|Box.RIGHT_ALIGN|Box.Y_CENTRE_ALIGN,
          colourScheme);

      Box commaArgs = BoxTools.commaList(argument, boxArgs, settings, colourScheme);
      Box brackets = BoxTools.roundBrackets(argument, commaArgs, settings, colourScheme);
      brackets.setArgument(argument);
      brackets.setProperty(Box.VERTICAL_STRETCH);

      boxText.setArgument(argument);
      brackets.setArgument(argument);

      return BoxTools.centredHorizontalBoxList(argument, settings, boxText, brackets);
    } else {
      Vector<Box> boxes = new Vector<Box>();
      if (isPrefix()) {
        Box pre = getPrefix().toBox(argument, Box.PLAIN_FONT, colourScheme);
        //- pre.setArgument(argument);
        boxes.add(pre);
      }
      switch ( boxArgs.size() ) {
        case 0:
          // Infix-only operators act like prefix operators for single arguments.
          if (isInfixOnly()) {
            Box inf = getInfix().toBox(argument, Box.PLAIN_FONT, colourScheme);
            //- inf.setArgument(argument);
            boxes.add(inf);
          }
          break;

        case 1:
          if (isInfixOnly()) {
            Box inf = getInfix().toBox(argument, Box.PLAIN_FONT, colourScheme);
            //- inf.setArgument(argument);
            boxes.add(inf);
          }
          boxes.add(boxArgs.lastElement());
          break;

        default:
          SymbolicState infixSymbol = isInfix() ? getInfix() : Symbol.COMMA;
          for (int i=0; i<boxArgs.size()-1; i++) {
            boxes.add(boxArgs.get(i));
            Box inf = infixSymbol.toBox(argument, Box.PLAIN_FONT, colourScheme);
            //- inf.setArgument(argument);
            boxes.add(inf);
          }
          boxes.add(boxArgs.lastElement());
      }
      if (isPostfix()) {
        Box post = getPostfix().toBox(argument, Box.PLAIN_FONT, colourScheme);
        //- post.setArgument(argument);
        boxes.add(post);
      }
      return BoxTools.centredHorizontalBoxList(argument, settings, boxes);
    }
View Full Code Here

    double shapeWidth = WIDTH - KetPanel.BORDER_OFFSET.width;
    return new Offset(shapeWidth, minimumHeight);
  }

  private void paintAndSaveFrames() throws InterruptedException {
    Box afterRootBox = treeDiff.getAfter().toBox(0L, COLOUR_SCHEME);
    afterRootBox.setupInnerRectangle(FONT_SIZE);
    Offset windowWithoutLabel = getWindowWithoutLabel(afterRootBox);
    Box beforeRootBox = getBeforeRootBox(windowWithoutLabel);
    afterRootBox.setupOuterRectangle(windowWithoutLabel);
    afterRootBox.calcRootOffset();
    int animationStart = initialFrameNumber + START_NUMBER;
    int animationEnd = animationStart + TRANSITION_NUMBER;
    Position topLeft = calcTopLeft(afterRootBox);
    Vector<Transition> transitions = treeDiff.getTransitions(beforeRootBox, afterRootBox); // Done once!
    for (int frame=initialFrameNumber; frame<animationEnd+END_NUMBER; frame++) {
      g2D.setColor(COLOUR_SCHEME.getBackgroundColour());
      g2D.fillRect(0, 0, WIDTH, HEIGHT);
      if (frame<animationStart) { // Draw the 'before' box.
        beforeRootBox.paintAt(g2D, topLeft, COLOUR_SCHEME);
      } else if (frame>=animationEnd) { // Draw the 'after' box.
        afterRootBox.paintAt(g2D, topLeft, COLOUR_SCHEME);
      } else { // Animate between 'before' and 'after' boxes.
        double fractionalTime = frame-animationStart;
        fractionalTime /= animationEnd - animationStart - 1.0;
View Full Code Here

      Thread.sleep(PAUSE_TIME);
    }
  }

  private Box getBeforeRootBox(Offset windowWithoutLabel) {
    Box beforeRootBox = treeDiff.getBefore().toBox(0L, COLOUR_SCHEME);
    beforeRootBox.setupInnerRectangle(FONT_SIZE);
    beforeRootBox.setupOuterRectangle(windowWithoutLabel);
    beforeRootBox.calcRootOffset();
    return beforeRootBox;
  }
View Full Code Here

    return;
  }

  public boolean textSelect(Position p) {
    Message message = modes.getMessage();
    Box box = findDeepestBox(p);
    Argument finishArgument = box!=null ? box.getArgument() : null;
    if ( ! (box instanceof BoxText) ) {
      return false;
    }
    int index = ((BoxText) box).getIndex(p);
    if (index==-1) {
View Full Code Here

    icon = null;
  }

  public void updateDragIcon(Position dragPosition) {
    //- this.dragPosition = dragPosition;
    Box box = getCurrent().toBox(0L, getColourScheme());
    box.setupInnerRectangle(getFontSize());
    Offset innerRectangle = box.getInnerRectangle();
    int w = (int) Math.max(10, innerRectangle.width);
    int h = (int) Math.max(10, innerRectangle.height);
    icon = ImageTools.boxToBufferedImage(box, w, h, getColourScheme(), false);
    deepest = null;
  }
View Full Code Here

  public Argument findDeepestArgument(Position p) {
    Argument equationMatch = equation.findDeepestArgument(p);
    if (equationMatch!=null) {
      return equationMatch;
    }
    Box labelMatch = label.findDeepestBox(p);
    if (labelMatch!=null && labelMatch.getArgument()!=null) {
      Argument root = equation.getArgument();
      if (root!=null) {
        return root;
      }
    }
View Full Code Here

  public Equation pointToEquation(Position p) {
    // Find the closest equation to the mouse click where part of it is above and to the left of the click.
    Equation e = null;
    Double bestLength2 = null; // Skip unnecessary and expensive square roots.
    for (BoxEquation next : boxSet) {
      Box box = next.getEquationBox();
      if (box==null) continue; //HACK
      if (box.getTopLeft()==null) continue; // HACK
      double left   = box.getTopLeft().x;
      double top    = box.getTopLeft().y;
      double dx = p.x - left;
      double dy = p.y - top;
      if (dx>0 && dy>0) {
        double length2 = dx*dx + dy*dy;
        if (bestLength2==null || length2<bestLength2) {
          bestLength2 = length2;
          e = box.getArgument().getEquation();
        }
      }
    }
    return e;
  }
View Full Code Here

TOP

Related Classes of ket.display.box.Box

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.