fix zooming problems
authormmahringer <s1520454056@students.fh-hagenberg.at>
Thu, 29 Jun 2017 13:27:00 +0200
changeset 516469958bb0692a
parent 5163 433e26729739
child 5167 7d8922399461
fix zooming problems
isac-java/src/java/isac/gui/mawen/editor/AstComponent.scala
isac-java/src/java/isac/gui/mawen/editor/Box.scala
isac-java/src/java/isac/gui/mawen/editor/BoxUtil.scala
isac-java/src/java/isac/gui/mawen/editor/CalcUtil.scala
isac-java/src/java/isac/gui/mawen/editor/EditorDrawing.scala
isac-java/src/java/isac/gui/mawen/editor/EditorDrawingBoxes.scala
isac-java/src/java/isac/gui/mawen/editor/Settings.scala
isac-java/src/java/isac/gui/mawen/syntax/syntax.scala
     1.1 --- a/isac-java/src/java/isac/gui/mawen/editor/AstComponent.scala	Thu Jun 29 09:41:02 2017 +0200
     1.2 +++ b/isac-java/src/java/isac/gui/mawen/editor/AstComponent.scala	Thu Jun 29 13:27:00 2017 +0200
     1.3 @@ -51,6 +51,9 @@
     1.4        RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
     1.5      g2.setRenderingHints(rh);
     1.6      
     1.7 +    
     1.8 +    
     1.9 +    
    1.10      // white background
    1.11      g.setColor(Color.WHITE)
    1.12      g.fillRect(0, 0, getWidth, getHeight)
    1.13 @@ -60,7 +63,9 @@
    1.14      g.translate(Settings.translateX, Settings.translateY)
    1.15      g2.scale(Settings.zoom, Settings.zoom)
    1.16      
    1.17 -    box =  CalcUtil.assembleBoxes(g, ast, (box: DrawBox) => 
    1.18 +    Settings.fillStringbounds(ast, g2)
    1.19 +    
    1.20 +    box =  CalcUtil.assembleBoxes(ast, (box: DrawBox) => 
    1.21          {
    1.22            if (EventUtil.foreachBoxFunction != null) {
    1.23              EventUtil.foreachBoxFunction(g2, box)
    1.24 @@ -115,9 +120,8 @@
    1.25  		  
    1.26  		  EventUtil.foreachBoxFunction = EventUtil.doInBox(e.getPoint,
    1.27  		      (g, box) => {
    1.28 -		        println(isac.gui.mawen.syntax.Ast.raw_string_of(ast))
    1.29 +		        
    1.30    	        ast = TransformAstUtil.Update(ast, box.ast, TransformAstUtil.AstToCursor)
    1.31 -  	        println(isac.gui.mawen.syntax.Ast.raw_string_of(ast))
    1.32    	        
    1.33    	        repaint()
    1.34  		      }
     2.1 --- a/isac-java/src/java/isac/gui/mawen/editor/Box.scala	Thu Jun 29 09:41:02 2017 +0200
     2.2 +++ b/isac-java/src/java/isac/gui/mawen/editor/Box.scala	Thu Jun 29 13:27:00 2017 +0200
     2.3 @@ -8,14 +8,19 @@
     2.4  object Box {
     2.5    
     2.6    sealed abstract class Box(val ast: Ast)
     2.7 -  class EmptyBox(val level: Int, val x0: Int, val y0: Int, override val ast: Ast) extends Box(ast)
     2.8 +  class EmptyBox(val level: Int, val x0: Int, val y0: Int, override val ast: Ast) extends Box(ast) {
     2.9 +    def apply (level: Int, x0: Int, y0: Int, ast: Ast) = new EmptyBox(level, x0, y0, ast)
    2.10 +    def toEmptyBox() = new EmptyBox(level, x0, y0, ast)
    2.11 +    def toEmptyBox(ast: Ast) = new EmptyBox(level, x0, y0, ast)
    2.12 +    def toEmptyBox(x: Int, y: Int, ast: Ast) = new EmptyBox(level, x, y, ast)
    2.13 +  }
    2.14    case class EmptyLeafOpBox(override val level: Int, override val x0: Int, override val y0: Int, override val ast: Ast) extends EmptyBox(level, x0, y0, ast)
    2.15    case class EmptyUniOpBox(override val level: Int, override val x0: Int, override val y0: Int, param: Ast, override val ast: Ast) extends EmptyBox(level, x0, y0, ast)
    2.16    case class EmptyBinOpBox(override val level: Int, override val x0: Int, override val y0: Int, operator: Ast, paraml: Ast, paramr: Ast, override val ast: Ast) extends EmptyBox(level, x0, y0, ast)
    2.17    
    2.18    
    2.19  
    2.20 -  case class DrawBox(name: String, val x: Int, val y: Int, val width: Int, val height: Int, x0 : Int, y0 : Int, override val ast: Ast) extends Box(ast) {
    2.21 +  case class DrawBox(name: String, val level: Int, val x: Int, val y: Int, val width: Int, val height: Int, x0 : Int, y0 : Int, override val ast: Ast) extends Box(ast) {
    2.22      
    2.23      var children : List[DrawBox] = List.empty[DrawBox]
    2.24      var isBoxed: Boolean  = false
     3.1 --- a/isac-java/src/java/isac/gui/mawen/editor/BoxUtil.scala	Thu Jun 29 09:41:02 2017 +0200
     3.2 +++ b/isac-java/src/java/isac/gui/mawen/editor/BoxUtil.scala	Thu Jun 29 13:27:00 2017 +0200
     3.3 @@ -52,6 +52,7 @@
     3.4    }
     3.5    
     3.6    def drawPlus(g: Graphics, box : DrawBox) {
     3.7 +    
     3.8      g.drawString("+", box.x0, box.y0)
     3.9      drawBox(box, g)
    3.10  
    3.11 @@ -62,6 +63,9 @@
    3.12      drawBox(box, g)
    3.13    }
    3.14    def drawString(g: Graphics, box : DrawBox) {
    3.15 +    val font_var = new Font("CMCSC8", Font.PLAIN,  CalcUtil.fontsizeOf(box.level))
    3.16 +    g.setFont(font_var)
    3.17 +    
    3.18      g.drawString(box.name, box.x0, box.y0)
    3.19      drawBox(box, g)
    3.20    }
     4.1 --- a/isac-java/src/java/isac/gui/mawen/editor/CalcUtil.scala	Thu Jun 29 09:41:02 2017 +0200
     4.2 +++ b/isac-java/src/java/isac/gui/mawen/editor/CalcUtil.scala	Thu Jun 29 13:27:00 2017 +0200
     4.3 @@ -24,41 +24,41 @@
     4.4  
     4.5    def assembleComponent(ast : Ast) : JComponent = new AstComponent(ast)
     4.6  
     4.7 -  def assembleBoxes (g : Graphics, ast : Ast, f: (DrawBox) => Unit ) =  assembleBoxesRec(g, new EmptyBox(0,0,0,ast), f)
     4.8 +  def assembleBoxes (ast : Ast, f: (DrawBox) => Unit ) =  assembleBoxesRec(new EmptyBox(0,0,0,ast), f)
     4.9  
    4.10 -  def assembleBoxesRec(g : Graphics, emptyBox: EmptyBox, f:(DrawBox) => Unit) : DrawBox = emptyBox.ast match {
    4.11 -    case Appl(operator :: param :: Nil)                =>   assembleUniopBoxes(g, EmptyUniOpBox(emptyBox.level, emptyBox.x0, emptyBox.y0, param, emptyBox.ast), f)
    4.12 -    case Appl(operator :: paraml :: paramr :: Nil)     =>   assembleBinopBoxes(g, AstInfoUtil.OperatorString(operator), EmptyBinOpBox(emptyBox.level,emptyBox.x0, emptyBox.y0, operator, paraml, paramr,emptyBox.ast), f)
    4.13 -    case Appl(Constant(str) :: param)                  =>   calcDefault(g, str,param, emptyBox.x0, emptyBox.y0, emptyBox.level, emptyBox.ast, f)
    4.14 -    case a                                             =>   assembleLeafBoxes(g, EmptyLeafOpBox(emptyBox.level, emptyBox.x0, emptyBox.y0, emptyBox.ast), f)
    4.15 +  def assembleBoxesRec(emptyBox: EmptyBox, f:(DrawBox) => Unit) : DrawBox = emptyBox.ast match {
    4.16 +    case Appl(operator :: param :: Nil)                =>   assembleUniopBoxes(EmptyUniOpBox(emptyBox.level, emptyBox.x0, emptyBox.y0, param, emptyBox.ast), f)
    4.17 +    case Appl(operator :: paraml :: paramr :: Nil)     =>   assembleBinopBoxes(AstInfoUtil.OperatorString(operator), EmptyBinOpBox(emptyBox.level,emptyBox.x0, emptyBox.y0, operator, paraml, paramr,emptyBox.ast), f)
    4.18 +    case Appl(Constant(str) :: param)                  =>   calcDefault(str,param, emptyBox.x0, emptyBox.y0, emptyBox.level, emptyBox.ast, f)
    4.19 +    case a                                             =>   assembleLeafBoxes(EmptyLeafOpBox(emptyBox.level, emptyBox.x0, emptyBox.y0, emptyBox.ast), f)
    4.20    }
    4.21    
    4.22 -  def assembleLeafBoxes(g : Graphics, emptyBox: EmptyLeafOpBox, f:(DrawBox) => Unit) : DrawBox = emptyBox.ast match {
    4.23 -    case Variable("GAP")                                                          => calcGAP(g, emptyBox, f)
    4.24 -    case Constant("GAP")                                                          => calcGAP(g, emptyBox, f)
    4.25 -    case Constant(str)                                                            => calcConstant(g, emptyBox, f)
    4.26 -    case Variable(str)                                                            => calcVariable(g, emptyBox, f)
    4.27 +  def assembleLeafBoxes(emptyBox: EmptyLeafOpBox, f:(DrawBox) => Unit) : DrawBox = emptyBox.ast match {
    4.28 +    case Variable("GAP")                                                          => calcGAP( emptyBox, f)
    4.29 +    case Constant("GAP")                                                          => calcGAP( emptyBox, f)
    4.30 +    case Constant(str)                                                            => calcConstant( emptyBox, f)
    4.31 +    case Variable(str)                                                            => calcVariable( emptyBox, f)
    4.32      case ast => throw new AstException("assembleBoxesRec, uncovered match: " + raw_string_of(ast))
    4.33    }
    4.34    
    4.35 -  def assembleUniopBoxes(g : Graphics, emptyBox: EmptyUniOpBox, f:(DrawBox) => Unit) : DrawBox = emptyBox.ast match {
    4.36 +  def assembleUniopBoxes( emptyBox: EmptyUniOpBox, f:(DrawBox) => Unit) : DrawBox = emptyBox.ast match {
    4.37      
    4.38 -    case Appl(Constant(str) ::  ast :: Nil)       if str.startsWith("BOX")        => CalcBox(g, str.replace("BOX.", ""), emptyBox, f)
    4.39 -    case Appl(Constant("CURSOR") :: param :: Nil)                                 => calcCursor(g, EmptyUniOpBox(emptyBox.level,emptyBox.x0,emptyBox.y0, param, emptyBox.ast), f)
    4.40 -    case Appl(param :: Constant("CURSOR") :: Nil)                                 => calcCursor(g, EmptyUniOpBox(emptyBox.level,emptyBox.x0,emptyBox.y0, param, emptyBox.ast), f)
    4.41 -    case Appl(Constant(str) :: param :: Nil)                                      => calcDefault(g, str, List(param), emptyBox.x0, emptyBox.y0, emptyBox.level, emptyBox.ast, f)
    4.42 +    case Appl(Constant(str) ::  ast :: Nil)       if str.startsWith("BOX")        => CalcBox( str.replace("BOX.", ""), emptyBox, f)
    4.43 +    case Appl(Constant("CURSOR") :: param :: Nil)                                 => calcCursor( EmptyUniOpBox(emptyBox.level,emptyBox.x0,emptyBox.y0, param, emptyBox.ast), f)
    4.44 +    case Appl(param :: Constant("CURSOR") :: Nil)                                 => calcCursor( EmptyUniOpBox(emptyBox.level,emptyBox.x0,emptyBox.y0, param, emptyBox.ast), f)
    4.45 +    case Appl(Constant(str) :: param :: Nil)                                      => calcDefault( str, List(param), emptyBox.x0, emptyBox.y0, emptyBox.level, emptyBox.ast, f)
    4.46      case ast => throw new AstException("assembleBoxesRec, uncovered match: " + raw_string_of(ast))
    4.47    }
    4.48    
    4.49    
    4.50 -  def assembleBinopBoxes(g : Graphics, operatorString: String, emptyBox: EmptyBinOpBox, f:(DrawBox) => Unit) : DrawBox = operatorString match {
    4.51 -    case "Groups.plus_class.plus"           => calcDefaultBinOp(g, emptyBox, f)
    4.52 -    case "Groups.minus_class.minus"         => calcDefaultBinOp(g, emptyBox, f)
    4.53 -    case "Groups.times_class.times"         => calcDefaultBinOp(g, emptyBox, f)
    4.54 -    case "Atools.pow"                       => calcPow(g, emptyBox, f)
    4.55 -    case "Fields.inverse_class.divide"      => calcFrac(g, emptyBox, f)
    4.56 -    case "HOL.eq"                           => calcEqualation(g, emptyBox, f)
    4.57 -    case _                                  => calcDefault(g, operatorString, List(emptyBox.paramr, emptyBox.paraml), emptyBox.x0, emptyBox.y0, emptyBox.level, emptyBox.ast, f)
    4.58 +  def assembleBinopBoxes( operatorString: String, emptyBox: EmptyBinOpBox, f:(DrawBox) => Unit) : DrawBox = operatorString match {
    4.59 +    case "Groups.plus_class.plus"           => calcDefaultBinOp( emptyBox, f)
    4.60 +    case "Groups.minus_class.minus"         => calcDefaultBinOp( emptyBox, f)
    4.61 +    case "Groups.times_class.times"         => calcDefaultBinOp( emptyBox, f)
    4.62 +    case "Atools.pow"                       => calcPow( emptyBox, f)
    4.63 +    case "Fields.inverse_class.divide"      => calcFrac( emptyBox, f)
    4.64 +    case "HOL.eq"                           => calcEqualation( emptyBox, f)
    4.65 +    case _                                  => calcDefault( operatorString, List(emptyBox.paramr, emptyBox.paraml), emptyBox.x0, emptyBox.y0, emptyBox.level, emptyBox.ast, f)
    4.66      
    4.67      //case ast => throw new AstException("assembleBinopBoxes, uncovered match: " + operatorString)
    4.68    }
    4.69 @@ -67,19 +67,19 @@
    4.70    
    4.71  
    4.72    
    4.73 -  def calcVariable(g: Graphics, emptybox: EmptyLeafOpBox, f:(DrawBox) => Unit) = {
    4.74 +  def calcVariable( emptybox: EmptyLeafOpBox, f:(DrawBox) => Unit) = {
    4.75      val level = emptybox.level
    4.76      val x0 = emptybox.x0
    4.77      val y0 = emptybox.y0
    4.78      val ast =  emptybox.ast
    4.79      val str = AstInfoUtil.VariableString(emptybox.ast)
    4.80      
    4.81 -    val font_var = new Font("CMMI12", Font.PLAIN, fontsizeOf(level))
    4.82 -    g.setFont(font_var)
    4.83 +//    val font_var = new Font("CMMI12", Font.PLAIN, fontsizeOf(level))
    4.84 +//    g.setFont(font_var)
    4.85      
    4.86 -    val box : Rectangle = getStringBounds(g.asInstanceOf[Graphics2D], str, x0, y0)
    4.87 -    
    4.88 -    val b = DrawBox(str, box.x, box.y + box.height, box.width, box.height, x0, y0, ast)
    4.89 +    val box : Rectangle =  Settings.getStringBoundOf(str, level, x0, y0) //  getStringBounds(g.asInstanceOf[Graphics2D], str, x0, y0) // TODO: Why does this work without x0,y0?
    4.90 +
    4.91 +    val b = DrawBox(str, level, box.x, box.y + box.height, box.width, box.height, x0, y0, ast)
    4.92      f(b)
    4.93        
    4.94      b
    4.95 @@ -88,7 +88,7 @@
    4.96    
    4.97    
    4.98    
    4.99 -  def calcConstant(g: Graphics, emptyBox: EmptyLeafOpBox, f:(DrawBox) => Unit) = {
   4.100 +  def calcConstant( emptyBox: EmptyLeafOpBox, f:(DrawBox) => Unit) = {
   4.101      val level = emptyBox.level
   4.102      val x0 = emptyBox.x0
   4.103      val y0 = emptyBox.y0
   4.104 @@ -96,40 +96,34 @@
   4.105      val op = XSyntax.isa_ast(AstInfoUtil.OperatorString(emptyBox.ast))
   4.106      
   4.107      
   4.108 -    val font_var = new Font("CMCSC8", Font.PLAIN,  fontsizeOf(level))
   4.109 -    g.setFont(font_var)
   4.110 +//    val font_var = new Font("CMCSC8", Font.PLAIN,  fontsizeOf(level))
   4.111 +//    g.setFont(font_var)
   4.112      
   4.113 -    val box : Rectangle = getStringBounds(g.asInstanceOf[Graphics2D], op, x0, y0)
   4.114 +    val box : Rectangle = Settings.getStringBoundOf(op, level)  //getStringBounds(g.asInstanceOf[Graphics2D], op, x0, y0)
   4.115      
   4.116      val midline = y0 - (fontsizeOf(level) * (2f / 3f)*(1f / 3f)).round
   4.117      val newY = ((box.y - y0) * -1) - box.height /2 + midline
   4.118      
   4.119      
   4.120      
   4.121 -    val b = DrawBox(op, box.x, y0, box.width, fontWidthOf(fontsizeOf(level)),x0, newY, ast)
   4.122 +    val b = DrawBox(op, level, box.x, y0, box.width, fontWidthOf(fontsizeOf(level)),x0, newY, ast)
   4.123      
   4.124      f(b)
   4.125      b
   4.126      
   4.127    }
   4.128 -  def calcGAP(g: Graphics, emptyBox: EmptyLeafOpBox, f:(DrawBox) => Unit) = {
   4.129 +  def calcGAP( emptyBox: EmptyLeafOpBox, f:(DrawBox) => Unit) = {
   4.130      val level = emptyBox.level
   4.131      val x0 = emptyBox.x0
   4.132      val y0 = emptyBox.y0
   4.133      val ast =  emptyBox.ast
   4.134      
   4.135 -    val font_var = new Font("CMCSC8", Font.PLAIN,  fontsizeOf(level))
   4.136 -    g.setFont(font_var)
   4.137 -    
   4.138 -    val box : Rectangle = getStringBounds(g.asInstanceOf[Graphics2D], "xx", x0, y0)
   4.139 -    
   4.140 -    val midline = y0 - (fontsizeOf(level) * (2f / 3f)*(1f / 3f)).round
   4.141 -    val newY = ((box.y - y0) * -1) - box.height /2 + midline
   4.142 +    val box : Rectangle = Settings.getStringBoundOf("xx", level, x0, y0) //getStringBounds(g.asInstanceOf[Graphics2D], "xx", x0, y0)
   4.143      
   4.144  
   4.145      
   4.146      
   4.147 -    val b = new DrawBox("GAP", box.x, y0, box.width, fontWidthOf(fontsizeOf(level)),x0, y0, ast)
   4.148 +    val b = new DrawBox("GAP", level, box.x, y0, box.width, fontWidthOf(fontsizeOf(level)),x0, y0, ast)
   4.149      //g.setColor(Color.BLACK)
   4.150      //g.fillRect(b.x, y0 - g.getFontMetrics.getHeight, b.width - 10, g.getFontMetrics.getHeight - 25)
   4.151      
   4.152 @@ -139,8 +133,8 @@
   4.153      b
   4.154    }
   4.155     
   4.156 -  def CalcBox(g: Graphics, str: String, emptyBox: EmptyUniOpBox, f:(DrawBox) => Unit) = {
   4.157 -     val box = assembleBoxesRec(g, new EmptyBox(emptyBox.level, emptyBox.x0, emptyBox.y0, emptyBox.param), f)
   4.158 +  def CalcBox( str: String, emptyBox: EmptyUniOpBox, f:(DrawBox) => Unit) = {
   4.159 +     val box = assembleBoxesRec( new EmptyBox(emptyBox.level, emptyBox.x0, emptyBox.y0, emptyBox.param), f)
   4.160       box.isBoxed = true
   4.161       
   4.162       if (str.split('.').head == "MAIN") {
   4.163 @@ -158,32 +152,22 @@
   4.164     
   4.165     
   4.166     
   4.167 -   def calcCursor(g: Graphics, emptyBox: EmptyUniOpBox, f:(DrawBox) => Unit) = {
   4.168 +   def calcCursor( emptyBox: EmptyUniOpBox, f:(DrawBox) => Unit) = {
   4.169       val x0 = emptyBox.x0
   4.170       val y0 = emptyBox.y0
   4.171       val level = emptyBox.level
   4.172       val ast = emptyBox.ast
   4.173       val param = emptyBox.param
   4.174 +    
   4.175 +    
   4.176       
   4.177 -     
   4.178 +    val childBox = assembleBoxesRec( new EmptyBox(level, x0, y0, param), f)
   4.179      
   4.180 -    val font_var = new Font("CMCSC8", Font.PLAIN,  fontsizeOf(level))
   4.181 -    g.setFont(font_var)
   4.182 -    
   4.183 -    val box : Rectangle = getStringBounds(g.asInstanceOf[Graphics2D], "xx", x0, y0)
   4.184 -    
   4.185 -    val midline = y0 - (fontsizeOf(level) * (2f / 3f)*(1f / 3f)).round
   4.186 -    val newY = ((box.y - y0) * -1) - box.height /2 + midline
   4.187 -    
   4.188 -
   4.189 -    
   4.190 -    val b = new DrawBox("CURSOR", box.x, y0, box.width, fontWidthOf(fontsizeOf(level)),x0, y0, ast)
   4.191 -    //g.setColor(Color.BLACK)
   4.192 -    //g.fillRect(b.x, y0 - g.getFontMetrics.getHeight, b.width - 10, g.getFontMetrics.getHeight - 25)
   4.193 +    val b = new DrawBox("CURSOR", level, childBox.x - 1, childBox.y + 1, childBox.width + 2,  childBox.height + 2, x0, y0, ast)
   4.194      
   4.195      f(b)
   4.196      
   4.197 -    val childBox = assembleBoxesRec(g, new EmptyBox(level, x0, y0, param), f)
   4.198 +    
   4.199      b.children = List(childBox)
   4.200      b
   4.201    }
   4.202 @@ -192,7 +176,7 @@
   4.203    
   4.204    
   4.205  
   4.206 -  def calcDefaultBinOp(g: Graphics, emptyBox: EmptyBinOpBox, f:(DrawBox) => Unit) = {
   4.207 +  def calcDefaultBinOp( emptyBox: EmptyBinOpBox, f:(DrawBox) => Unit) = {
   4.208      val operator = emptyBox.operator
   4.209      val paraml = emptyBox.paraml
   4.210      val paramr = emptyBox.paramr
   4.211 @@ -203,27 +187,40 @@
   4.212      
   4.213      
   4.214      
   4.215 -    val l_box = assembleBoxesRec(g, new EmptyBox(level, x0, y0, paraml), f)
   4.216 +    val l_box = assembleBoxesRec( emptyBox.toEmptyBox(paraml), f)
   4.217      val l_width = l_box.width
   4.218      val l_height = l_box.height
   4.219      
   4.220 -    val o_box = assembleBoxesRec(g, new EmptyBox(level, x0 + l_width + Settings.MEDIUMSPACE, y0, operator), f)
   4.221 +    val o_box = assembleBoxesRec( emptyBox.toEmptyBox(x0 + l_width + Settings.MEDIUMSPACE, y0, operator), f)
   4.222      val operator_width = o_box.width
   4.223      val operator_height  = o_box.height
   4.224      
   4.225 -    val r_box = assembleBoxesRec(g, new EmptyBox(level, x0 + l_width + Settings.MEDIUMSPACE + operator_width + Settings.MEDIUMSPACE, y0, paramr), f)
   4.226 +    val r_box = assembleBoxesRec( emptyBox.toEmptyBox(x0 + l_width + Settings.MEDIUMSPACE + operator_width + Settings.MEDIUMSPACE, y0, paramr), f)
   4.227      val r_width = r_box.width
   4.228      val r_height = r_box.height
   4.229      
   4.230 +    
   4.231 +    val newX = x0
   4.232 +    val newY = Math.max(l_box.y, r_box.y)
   4.233 +    val newWidth = l_width + Settings.MEDIUMSPACE + operator_width + Settings.MEDIUMSPACE + r_width
   4.234 +    val newHeight = Math.max(l_height, r_height)
   4.235  
   4.236 -    val b = new DrawBox("",  x0, y0, l_width + Settings.MEDIUMSPACE + operator_width + Settings.MEDIUMSPACE + r_width, Math.max(l_height, r_height), x0, y0, ast)
   4.237 +    val b = new DrawBox("", level,  
   4.238 +        newX, 
   4.239 +        newY, 
   4.240 +        newWidth, 
   4.241 +        newHeight
   4.242 +        , x0, y0, ast)
   4.243 +    
   4.244 +    
   4.245 +    
   4.246      b.children =  o_box :: l_box :: r_box :: List.empty[DrawBox]
   4.247      
   4.248      f(b)
   4.249      b
   4.250    }
   4.251    
   4.252 -  def calcPow(g: Graphics, emptyBox: EmptyBinOpBox, f:(DrawBox) => Unit) = {
   4.253 +  def calcPow( emptyBox: EmptyBinOpBox, f:(DrawBox) => Unit) = {
   4.254      val operator = emptyBox.operator
   4.255      val paraml = emptyBox.paraml
   4.256      val paramr = emptyBox.paramr
   4.257 @@ -232,15 +229,15 @@
   4.258      val level= emptyBox.level
   4.259      val ast = emptyBox.ast
   4.260      
   4.261 -    val l_box = assembleBoxesRec(g, new EmptyBox(level, x0, y0, paraml), f)
   4.262 +    val l_box = assembleBoxesRec( new EmptyBox(level, x0, y0, paraml), f)
   4.263      val l_width = l_box.width
   4.264      val l_height = l_box.height
   4.265  
   4.266 -    val r_box = assembleBoxesRec(g, new EmptyBox(level + 1, x0 + l_width + Settings.POWHORIZONTALSPACE, y0 - (l_height * (0.7f + level / 10f)).round, paramr), f)
   4.267 +    val r_box = assembleBoxesRec( new EmptyBox(level + 1, x0 + l_width + Settings.POWHORIZONTALSPACE, y0 - (l_height * (0.7f + level / 10f)).round, paramr), f)
   4.268      val r_width = r_box.width
   4.269      val r_height= r_box.height
   4.270      
   4.271 -    val b = DrawBox ("", x0, y0, l_width + Settings.POWHORIZONTALSPACE + r_width, l_height + r_height,x0, y0,ast)
   4.272 +    val b = DrawBox ("", level, x0, y0, l_width + Settings.POWHORIZONTALSPACE + r_width, l_height + r_height,x0, y0,ast)
   4.273      b.children =  l_box :: r_box :: List.empty[DrawBox]
   4.274      
   4.275      f(b);
   4.276 @@ -248,7 +245,7 @@
   4.277      b
   4.278    }
   4.279    
   4.280 -  def calcFrac(g: Graphics, emptyBox: EmptyBinOpBox, f:(DrawBox) => Unit) = {
   4.281 +  def calcFrac( emptyBox: EmptyBinOpBox, f:(DrawBox) => Unit) = {
   4.282      val operator = emptyBox.operator
   4.283      val paramUpper = emptyBox.paraml
   4.284      val paramLower = emptyBox.paramr
   4.285 @@ -259,8 +256,8 @@
   4.286      
   4.287      
   4.288      
   4.289 -    val u_box = assembleBoxesRec(g, new EmptyBox(level+1, x0, y0, paramUpper), emptyFunc)
   4.290 -    val l_box = assembleBoxesRec(g, new EmptyBox(level+1, x0, y0, paramLower), emptyFunc)
   4.291 +    val u_box = assembleBoxesRec( new EmptyBox(level+1, x0, y0, paramUpper), emptyFunc)
   4.292 +    val l_box = assembleBoxesRec( new EmptyBox(level+1, x0, y0, paramLower), emptyFunc)
   4.293      
   4.294      
   4.295      val y_midline = y0 - (fontsizeOf(level) * (2f / 3f)*(1f / 3f)).round
   4.296 @@ -272,7 +269,7 @@
   4.297      val maxWidth = Math.max(u_box.width, l_box.width)
   4.298      
   4.299      //g.drawLine(-50, y_midline, x0 + maxWidth, y_midline)
   4.300 -    val line_box = new DrawBox("Fields.inverse_class.divide", x0, y_midline, maxWidth, 3, x0, y0, ast);
   4.301 +    val line_box = new DrawBox("Fields.inverse_class.divide", level, x0, y_midline, maxWidth, 3, x0, y0, ast);
   4.302      
   4.303      // calc position for upper Frac
   4.304      val u_x0 = x0 + (maxWidth / 2f - u_box.width / 2f).round
   4.305 @@ -284,46 +281,46 @@
   4.306      val l_x0 = x0 + (maxWidth / 2f - l_box.width / 2f).round
   4.307      val l_y0 = y_midline + l_box.height  + Settings.FRACVERTIKALSPACE
   4.308      
   4.309 -    val u_res_box = assembleBoxesRec(g, new EmptyBox(level+1,  u_x0, u_y0,paramUpper), f)
   4.310 -    val l_res_box = assembleBoxesRec(g, new EmptyBox(level+1, l_x0, l_y0, paramLower), f)
   4.311 +    val u_res_box = assembleBoxesRec( new EmptyBox(level+1,  u_x0, u_y0,paramUpper), f)
   4.312 +    val l_res_box = assembleBoxesRec( new EmptyBox(level+1, l_x0, l_y0, paramLower), f)
   4.313      
   4.314      
   4.315 -    val b = new DrawBox("", x0, l_res_box.y, maxWidth, u_res_box.height + l_res_box.height + line_box.height + Settings.FRACVERTIKALSPACE + Settings.FRACVERTIKALSPACE, x0, y0, ast)
   4.316 +    val b = new DrawBox("", level, x0, l_res_box.y, maxWidth, u_res_box.height + l_res_box.height + line_box.height + Settings.FRACVERTIKALSPACE + Settings.FRACVERTIKALSPACE, x0, y0, ast)
   4.317      b.children = line_box :: u_res_box :: l_res_box :: List.empty[DrawBox]
   4.318      
   4.319      f(b)
   4.320      
   4.321  //    if (level == 1)
   4.322 -//      b.draw(g, false)
   4.323 +//      b.draw( false)
   4.324      
   4.325      b
   4.326    }
   4.327    
   4.328 -  def calcDefault(g: Graphics, str: String, param: List[Ast], x0: Int, y0: Int, level: Int, ast : Ast, f:(DrawBox) => Unit) = {
   4.329 +  def calcDefault( str: String, param: List[Ast], x0: Int, y0: Int, level: Int, ast : Ast, f:(DrawBox) => Unit) = {
   4.330      
   4.331 -    val boxes = param.map(x => assembleBoxesRec(g, new EmptyBox(level, x0, y0, x),emptyFunc))
   4.332 +    val boxes = param.map(x => assembleBoxesRec( new EmptyBox(level, x0, y0, x),emptyFunc))
   4.333      
   4.334 -    val horizontalSpace = getStringBounds(g.asInstanceOf[Graphics2D], ",x", x0, y0)
   4.335 -    val horizontalCloseBracketSpace = getStringBounds(g.asInstanceOf[Graphics2D], ")", x0, y0)
   4.336 -    val constantSpace = getStringBounds(g.asInstanceOf[Graphics2D], str + "(i", x0, y0)
   4.337 -    
   4.338 +    val horizontalSpace =             Settings.getStringBoundOf(",x", level, x0, y0) //getStringBounds(g.asInstanceOf[Graphics2D], ",x", x0, y0)
   4.339 +    val horizontalCloseBracketSpace = Settings.getStringBoundOf(")", level, x0, y0) //getStringBounds(g.asInstanceOf[Graphics2D], ")", x0, y0)
   4.340 +    val constant =               Settings.getStringBoundOf(str, level, x0, y0) //getStringBounds(g.asInstanceOf[Graphics2D], str + "(i", x0, y0)
   4.341 +    val constantSpace = constant.union(Settings.getStringBoundOf("(i", level, x0, y0))
   4.342     
   4.343      var x = x0 + constantSpace.width
   4.344      var y = y0
   4.345      
   4.346      
   4.347      var resBoxes = List.empty[DrawBox]
   4.348 -    //resBoxes = assembleBoxesRec(g, Constant(str), x0, y0, level,f) :: resBoxes
   4.349 +    //resBoxes = assembleBoxesRec( Constant(str), x0, y0, level,f) :: resBoxes
   4.350      
   4.351      
   4.352      for (box <- boxes) {
   4.353 -      val b = assembleBoxesRec(g, new EmptyBox(level, x, y, box.ast), f)
   4.354 +      val b = assembleBoxesRec( new EmptyBox(level, x, y, box.ast), f)
   4.355        resBoxes = b :: resBoxes 
   4.356        if (box == boxes.last) {
   4.357 -        resBoxes =  new DrawBox(")",b.x,b.y,horizontalSpace.width,horizontalSpace.height,b.x + b.width,b.y,null) :: resBoxes
   4.358 +        resBoxes =  new DrawBox(")", level, b.x,b.y,horizontalSpace.width,horizontalSpace.height,b.x + b.width,b.y,null) :: resBoxes
   4.359          x = x  + horizontalCloseBracketSpace.width +  b.width
   4.360        } else {
   4.361 -        resBoxes =  new DrawBox(", ",b.x,b.y,horizontalSpace.width,horizontalSpace.height,b.x + b.width,b.y,null) :: resBoxes
   4.362 +        resBoxes =  new DrawBox(", ", level, b.x,b.y,horizontalSpace.width,horizontalSpace.height,b.x + b.width,b.y,null) :: resBoxes
   4.363          x = x + horizontalSpace.width  + b.width
   4.364        }
   4.365        
   4.366 @@ -332,7 +329,7 @@
   4.367      }
   4.368      
   4.369      
   4.370 -    val resultBox = new DrawBox(str + "(", x0, y0, x - x0, boxes.map(mb => mb.height).max, x0, y0, ast);
   4.371 +    val resultBox = new DrawBox(str + "(", level, x0, y0, x - x0, boxes.map(mb => mb.height).max, x0, y0, ast);
   4.372      resultBox.children = resBoxes
   4.373      f(resultBox)
   4.374      
   4.375 @@ -343,7 +340,7 @@
   4.376     * calculate Boxes with the form Appl(Constant("HOL.eq"), Variable(str), Variable(str)) --> str = str
   4.377     * nearly similar to calcPlus() but with more Space between Variable and Constant (LARGESPACE instance of MEDIUMSPACE)
   4.378     */
   4.379 -  def calcEqualation(g: Graphics, emptyBox: EmptyBinOpBox, f:(DrawBox) => Unit) = {
   4.380 +  def calcEqualation( emptyBox: EmptyBinOpBox, f:(DrawBox) => Unit) = {
   4.381      val operator = emptyBox.operator
   4.382      val paraml = emptyBox.paraml
   4.383      val paramr = emptyBox.paramr
   4.384 @@ -354,21 +351,21 @@
   4.385      
   4.386      
   4.387      
   4.388 -    val l_box = assembleBoxesRec(g, new EmptyBox(level, x0, y0, paraml), f)
   4.389 +    val l_box = assembleBoxesRec( new EmptyBox(level, x0, y0, paraml), f)
   4.390      val l_width = l_box.width
   4.391      val l_height = l_box.height
   4.392      
   4.393      
   4.394 -    val o_box = assembleBoxesRec(g, new EmptyBox(level, x0 + l_width + Settings.LARGESPACE, y0, Constant("=")), f)
   4.395 +    val o_box = assembleBoxesRec( new EmptyBox(level, x0 + l_width + Settings.LARGESPACE, y0, Constant("=")), f)
   4.396      val operator_width = o_box.width
   4.397      val operator_height  = o_box.height
   4.398      
   4.399 -    val r_box = assembleBoxesRec(g, new EmptyBox(level, x0 + l_width + Settings.LARGESPACE + operator_width + Settings.LARGESPACE, y0, paramr), f)
   4.400 +    val r_box = assembleBoxesRec( new EmptyBox(level, x0 + l_width + Settings.LARGESPACE + operator_width + Settings.LARGESPACE, y0, paramr), f)
   4.401      val r_width = r_box.width
   4.402      val r_height = r_box.height
   4.403      
   4.404  
   4.405 -    val b = new DrawBox("", x0, y0, l_width + Settings.LARGESPACE + operator_width + Settings.LARGESPACE + r_width, Math.max(l_height, r_height),x0, y0, ast)
   4.406 +    val b = new DrawBox("", level, x0, y0, l_width + Settings.LARGESPACE + operator_width + Settings.LARGESPACE + r_width, Math.max(l_height, r_height),x0, y0, ast)
   4.407      b.children =  o_box :: l_box :: r_box :: List.empty[DrawBox]
   4.408      
   4.409      f(b)
   4.410 @@ -382,16 +379,7 @@
   4.411    
   4.412    
   4.413    
   4.414 -  def getStringBounds (g2: Graphics2D, str: String , x: Float , y: Float ) : Rectangle = 
   4.415 -  {
   4.416 -    val frc = g2.getFontRenderContext()
   4.417 -    val gv = g2.getFont().createGlyphVector(frc, str)
   4.418 -    val rect : Rectangle = gv.getPixelBounds(null, x, y)
   4.419 -
   4.420 -    val norm_rect = new Rectangle((rect.x / Settings.zoom).round, (rect.y / Settings.zoom).round, (rect.width / Settings.zoom).round, (rect.height / Settings.zoom).round)
   4.421 -    
   4.422 -    new Rectangle(norm_rect.x, norm_rect.y, norm_rect.width, norm_rect.height)
   4.423 -  }
   4.424 +  
   4.425    
   4.426    def fontWidthOf(fontsize: Int) = ((fontsize * 2f) / 3f).round
   4.427    
     5.1 --- a/isac-java/src/java/isac/gui/mawen/editor/EditorDrawing.scala	Thu Jun 29 09:41:02 2017 +0200
     5.2 +++ b/isac-java/src/java/isac/gui/mawen/editor/EditorDrawing.scala	Thu Jun 29 13:27:00 2017 +0200
     5.3 @@ -15,7 +15,7 @@
     5.4      
     5.5     
     5.6      
     5.7 -    val box : Rectangle = CalcUtil.getStringBounds(g.asInstanceOf[Graphics2D], str, x0, y0)
     5.8 +    val box : Rectangle = Settings.getStringBounds(g.asInstanceOf[Graphics2D], str, x0, y0)
     5.9      val midline = y0 - (fontsize * (2f / 3f)*(1f / 3f)).round
    5.10      
    5.11      
    5.12 @@ -28,7 +28,7 @@
    5.13        val font_var = new Font("CMMI12", Font.PLAIN, fontsize)
    5.14        g.setFont(font_var)
    5.15        
    5.16 -      val box : Rectangle = CalcUtil.getStringBounds(
    5.17 +      val box : Rectangle = Settings.getStringBounds(
    5.18            g.asInstanceOf[Graphics2D], str, x0, y0)
    5.19        
    5.20        //g.drawLine(-10, 0, getWidth-10, 0)
     6.1 --- a/isac-java/src/java/isac/gui/mawen/editor/EditorDrawingBoxes.scala	Thu Jun 29 09:41:02 2017 +0200
     6.2 +++ b/isac-java/src/java/isac/gui/mawen/editor/EditorDrawingBoxes.scala	Thu Jun 29 13:27:00 2017 +0200
     6.3 @@ -15,7 +15,7 @@
     6.4      g.setFont(font_var)
     6.5      
     6.6    
     6.7 -    val box : Rectangle = CalcUtil.getStringBounds(g.asInstanceOf[Graphics2D], str, x0, y0)
     6.8 +    val box : Rectangle = Settings.getStringBounds(g.asInstanceOf[Graphics2D], str, x0, y0)
     6.9      
    6.10      val midline = y0 - (fontsize * (2f / 3f)*(1f / 3f)).round
    6.11      
    6.12 @@ -32,7 +32,7 @@
    6.13        val font_var = new Font("CMMI12", Font.PLAIN, fontsize)
    6.14        g.setFont(font_var)
    6.15        
    6.16 -      val box : Rectangle = CalcUtil.getStringBounds(
    6.17 +      val box : Rectangle = Settings.getStringBounds(
    6.18            g.asInstanceOf[Graphics2D], str, x0, y0)
    6.19        
    6.20        g.drawLine(-200, y0, 8000, y0)
     7.1 --- a/isac-java/src/java/isac/gui/mawen/editor/Settings.scala	Thu Jun 29 09:41:02 2017 +0200
     7.2 +++ b/isac-java/src/java/isac/gui/mawen/editor/Settings.scala	Thu Jun 29 13:27:00 2017 +0200
     7.3 @@ -4,6 +4,11 @@
     7.4  import java.util.Properties
     7.5  import isac.util.WindowApplicationPaths
     7.6  import scala.io.Source
     7.7 +import java.awt.Rectangle
     7.8 +import isac.gui.mawen.syntax.XSyntax
     7.9 +import isac.gui.mawen.syntax.Ast._
    7.10 +import java.awt.Graphics2D
    7.11 +import java.awt.Font
    7.12  
    7.13  object Settings {
    7.14    
    7.15 @@ -46,6 +51,64 @@
    7.16    
    7.17    val POWHORIZONTALSPACE = (INITIALFONTSIZE / 100f * 8f).round
    7.18    
    7.19 +  var ast_Stringbounds = Map.empty[String, (Rectangle, Rectangle, Rectangle)]
    7.20 +  
    7.21 +  def getStringBoundOf(key: String, level: Int) : Rectangle = {
    7.22 +
    7.23 +    ast_Stringbounds(key).productElement(level).asInstanceOf[Rectangle].clone().asInstanceOf[Rectangle]
    7.24 +  }
    7.25 +  def getStringBoundOf(key: String, level: Int, dx: Int, dy: Int) : Rectangle =  {
    7.26 +    val r = getStringBoundOf(key, level)
    7.27 +    r.translate(dx, dy)
    7.28 +    return r;
    7.29 +  }
    7.30 +  
    7.31 +  def fillStringbounds(ast: Ast, g: Graphics2D) {
    7.32 +    fillStringboundsRec(Variable(",x"), g)
    7.33 +    fillStringboundsRec(Variable(")"), g)
    7.34 +    fillStringboundsRec(Variable("(i"), g)
    7.35 +    fillStringboundsRec(Variable("xx"), g)
    7.36 +    fillStringboundsRec(ast, g)
    7.37 +  }
    7.38 +  
    7.39 +  def fillStringboundsRec(ast: Ast, g: Graphics2D) : Unit = ast match {
    7.40 +    case Constant(str) => {
    7.41 +      val op = XSyntax.isa_ast(str)
    7.42 +      g.setFont(new Font("CMCSC8", Font.PLAIN, CalcUtil.fontsizeOf(0)))
    7.43 +      val RectLv0 = getStringBounds(g, op, 0f,0f)
    7.44 +      g.setFont(new Font("CMCSC8", Font.PLAIN, CalcUtil.fontsizeOf(1)))
    7.45 +      val RectLv1 = getStringBounds(g, op, 0f,0f)
    7.46 +      g.setFont(new Font("CMCSC8", Font.PLAIN, CalcUtil.fontsizeOf(2)))
    7.47 +      val RectLv2 = getStringBounds(g, op, 0f,0f)
    7.48 +      ast_Stringbounds = ast_Stringbounds + (op -> (RectLv0, RectLv1, RectLv2))
    7.49 +    }
    7.50 +    case Variable(str) => {
    7.51 +      g.setFont(new Font("CMMI12", Font.PLAIN, CalcUtil.fontsizeOf(0)))
    7.52 +      val RectLv0 = getStringBounds(g, str, 0f,0f)
    7.53 +      g.setFont(new Font("CMMI12", Font.PLAIN, CalcUtil.fontsizeOf(1)))
    7.54 +      val RectLv1 = getStringBounds(g, str, 0f,0f)
    7.55 +      g.setFont(new Font("CMMI12", Font.PLAIN, CalcUtil.fontsizeOf(2)))
    7.56 +      val RectLv2 = getStringBounds(g, str, 0f,0f)
    7.57 +      ast_Stringbounds = ast_Stringbounds + (str -> (RectLv0, RectLv1, RectLv2))
    7.58 +    }
    7.59 +    case Appl(asts) => asts.foreach(x => fillStringbounds(x, g))
    7.60 +  }
    7.61 +
    7.62 +  
    7.63 +  
    7.64 +  
    7.65 +  def getStringBounds (g2: Graphics2D, str: String , x: Float , y: Float ) : Rectangle = 
    7.66 +  {
    7.67 +    val frc = g2.getFontRenderContext()
    7.68 +    val gv = g2.getFont().createGlyphVector(frc, str)
    7.69 +    val rect : Rectangle = gv.getPixelBounds(null, x, y)
    7.70 +
    7.71 +    val norm_rect = new Rectangle((rect.x / Settings.zoom).round, (rect.y / Settings.zoom).round, (rect.width / Settings.zoom).round, (rect.height / Settings.zoom).round)
    7.72 +    
    7.73 +    new Rectangle(norm_rect.x, norm_rect.y, norm_rect.width, norm_rect.height)
    7.74 +  }
    7.75 +  
    7.76 +  
    7.77    
    7.78    
    7.79    val CollorMapping: Map[Int, java.awt.Color] =  Map(
     8.1 --- a/isac-java/src/java/isac/gui/mawen/syntax/syntax.scala	Thu Jun 29 09:41:02 2017 +0200
     8.2 +++ b/isac-java/src/java/isac/gui/mawen/syntax/syntax.scala	Thu Jun 29 13:27:00 2017 +0200
     8.3 @@ -137,4 +137,9 @@
     8.4    def print_rules (key: String): List[Tuple2[Ast, Ast]] =
     8.5      if (symtab.contains(key)) symtab(key) else List()
     8.6  
     8.7 +    
     8.8 +    
     8.9 +
    8.10 +    
    8.11 +    
    8.12  }
    8.13 \ No newline at end of file