1.1 --- a/isac-java/src/java/isac/gui/mawen/editor/CalcUtil.scala Tue Sep 12 14:33:21 2017 +0200
1.2 +++ b/isac-java/src/java/isac/gui/mawen/editor/CalcUtil.scala Tue Sep 12 14:46:07 2017 +0200
1.3 @@ -63,8 +63,7 @@
1.4 /*
1.5 * calc* calculates the size of a fram around <code>DrawBox</code> for
1.6 */
1.7 - // TODOWN rename f
1.8 - def calcVariable( emptybox: EmptyLeafOpBox, f:(DrawBox) => Unit): DrawBox = {
1.9 + def calcVariable( emptybox: EmptyLeafOpBox, callback_calc:(DrawBox) => Unit): DrawBox = {
1.10 val level = emptybox.level
1.11 val x0 = emptybox.x0
1.12 val y0 = emptybox.y0
1.13 @@ -72,11 +71,10 @@
1.14 val str = AstInfoUtil.VariableString(emptybox.ast)
1.15 val box : Rectangle = Settings.getStringBoundOf(str, level, x0, y0) // getStringBounds(g.asInstanceOf[Graphics2D], str, x0, y0) // TODO: Why does this work without x0,y0?
1.16 val b = DrawBox(str, level, box.x, box.y + box.height, box.width, box.height, x0, y0, ast)
1.17 - f(b) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.18 + callback_calc(b) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.19 b
1.20 }
1.21 - // TODOWN rename f
1.22 - def calcConstant( emptyBox: EmptyLeafOpBox, f:(DrawBox) => Unit) = {
1.23 + def calcConstant( emptyBox: EmptyLeafOpBox, callback_calc:(DrawBox) => Unit) = {
1.24 val level = emptyBox.level
1.25 val x0 = emptyBox.x0
1.26 val y0 = emptyBox.y0
1.27 @@ -86,21 +84,20 @@
1.28 val midline = y0 - (fontsizeOf(level) * (2f / 3f)*(1f / 3f)).round
1.29 val newY = ((box.y - y0) * -1) - box.height /2 + midline
1.30 val b = DrawBox(op, level, box.x, y0, box.width, fontWidthOf(fontsizeOf(level)),x0, newY, ast)
1.31 - f(b) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.32 + callback_calc(b) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.33 b
1.34 }
1.35 - // TODOWN rename f
1.36 - def calcGAP( emptyBox: EmptyLeafOpBox, f:(DrawBox) => Unit) = {
1.37 + def calcGAP( emptyBox: EmptyLeafOpBox, callback_calc:(DrawBox) => Unit) = {
1.38 val level = emptyBox.level
1.39 val x0 = emptyBox.x0
1.40 val y0 = emptyBox.y0
1.41 val ast = emptyBox.ast
1.42 val box : Rectangle = Settings.getStringBoundOf("xx", level, x0, y0) //getStringBounds(g.asInstanceOf[Graphics2D], "xx", x0, y0)
1.43 val b = new DrawBox("GAP", level, box.x, y0, box.width, fontWidthOf(fontsizeOf(level)),x0, y0, ast)
1.44 - f(b) // see callback mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.45 + callback_calc(b) // see callback mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.46 b
1.47 }
1.48 - // NO f, because a frame does NOT accept a mouse interaction
1.49 + // NO callback_calc, because a frame does NOT accept a mouse interaction
1.50 def CalcBox( str: String, emptyBox: EmptyUniOpBox, f:(DrawBox) => Unit) = {
1.51 val box = assembleBoxesRec( new EmptyBox(emptyBox.level, emptyBox.x0, emptyBox.y0, emptyBox.param), f)
1.52 box.isBoxed = true
1.53 @@ -113,24 +110,22 @@
1.54 }
1.55 box
1.56 }
1.57 - // TODOWN rename f
1.58 - def calcCursor( emptyBox: EmptyUniOpBox, f:(DrawBox) => Unit) = {
1.59 + def calcCursor( emptyBox: EmptyUniOpBox, callback_calc:(DrawBox) => Unit) = {
1.60 val x0 = emptyBox.x0
1.61 val y0 = emptyBox.y0
1.62 val level = emptyBox.level
1.63 val ast = emptyBox.ast
1.64 val param = emptyBox.param
1.65 - val childBox = assembleBoxesRec( new EmptyBox(level, x0, y0, param), f)
1.66 + val childBox = assembleBoxesRec( new EmptyBox(level, x0, y0, param), callback_calc)
1.67 val b = new DrawBox("CURSOR", level, childBox.x - 1, childBox.y + 1, childBox.width + 2, childBox.height + 2, x0, y0, ast)
1.68 - f(b) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.69 + callback_calc(b) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.70 b.children = List(childBox)
1.71 b
1.72 }
1.73 /*
1.74 * layout of horizontal type +, (binary)-, *, =
1.75 */
1.76 - // TODOWN rename f
1.77 - def calcDefaultBinOp( emptyBox: EmptyBinOpBox, f:(DrawBox) => Unit) = {
1.78 + def calcDefaultBinOp( emptyBox: EmptyBinOpBox, callback_calc:(DrawBox) => Unit) = {
1.79 val operator = emptyBox.operator
1.80 val paraml = emptyBox.paraml
1.81 val paramr = emptyBox.paramr
1.82 @@ -156,15 +151,17 @@
1.83 rspaceOpen = constantSpace.width
1.84 rspaceClose = horizontalCloseBracketSpace.width
1.85 }
1.86 - val l_box = assembleBoxesRec( emptyBox.toEmptyBox(x0 + lspaceOpen, y0, paraml), f)
1.87 + val l_box = assembleBoxesRec( emptyBox.toEmptyBox(x0 + lspaceOpen, y0, paraml), callback_calc)
1.88 val l_width = l_box.width
1.89 val l_height = l_box.height
1.90
1.91 - val o_box = assembleBoxesRec( emptyBox.toEmptyBox(x0 + l_width + leftSpace + lspaceOpen + lspaceClose, y0, operator), f)
1.92 + val o_box = assembleBoxesRec( emptyBox.toEmptyBox(x0 + l_width + leftSpace +
1.93 + lspaceOpen + lspaceClose, y0, operator), callback_calc)
1.94 val operator_width = o_box.width
1.95 val operator_height = o_box.height
1.96
1.97 - val r_box = assembleBoxesRec( emptyBox.toEmptyBox(x0 + l_width + leftSpace + operator_width + rightSpace + lspaceOpen + lspaceClose + rspaceOpen, y0, paramr), f)
1.98 + val r_box = assembleBoxesRec( emptyBox.toEmptyBox(x0 + l_width + leftSpace + operator_width +
1.99 + rightSpace + lspaceOpen + lspaceClose + rspaceOpen, y0, paramr), callback_calc)
1.100 val r_width = r_box.width
1.101 val r_height = r_box.height
1.102
1.103 @@ -197,14 +194,13 @@
1.104
1.105 b.children = openBracketR :: closeBracketR :: b.children
1.106 }
1.107 - f(b) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.108 + callback_calc(b) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.109 b
1.110 }
1.111 /*
1.112 * layout of vertical type ^
1.113 */
1.114 - // TODOWN rename f
1.115 - def calcPow( emptyBox: EmptyBinOpBox, f:(DrawBox) => Unit) = {
1.116 + def calcPow( emptyBox: EmptyBinOpBox, callback_calc:(DrawBox) => Unit) = {
1.117 val operator = emptyBox.operator
1.118 val paraml = emptyBox.paraml
1.119 val paramr = emptyBox.paramr
1.120 @@ -213,25 +209,25 @@
1.121 val level= emptyBox.level
1.122 val ast = emptyBox.ast
1.123
1.124 - val l_box = assembleBoxesRec( new EmptyBox(level, x0, y0, paraml), f)
1.125 + val l_box = assembleBoxesRec( new EmptyBox(level, x0, y0, paraml), callback_calc)
1.126 val l_width = l_box.width
1.127 val l_height = l_box.height
1.128
1.129 - val r_box = assembleBoxesRec( new EmptyBox(level + 1, x0 + l_width + Settings.POWHORIZONTALSPACE, y0 - (l_height * (0.7f + level / 10f)).round, paramr), f)
1.130 + val r_box = assembleBoxesRec( new EmptyBox(level + 1, x0 + l_width +
1.131 + Settings.POWHORIZONTALSPACE, y0 - (l_height * (0.7f + level / 10f)).round, paramr), callback_calc)
1.132 val r_width = r_box.width
1.133 val r_height= r_box.height
1.134
1.135 val b = DrawBox ("", level, x0, y0, l_width + Settings.POWHORIZONTALSPACE + r_width, l_height + r_height,x0, y0,ast)
1.136 b.children = l_box :: r_box :: List.empty[DrawBox]
1.137 - f(b) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.138 + callback_calc(b) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.139 b
1.140 }
1.141
1.142 /*
1.143 * layout of vertical type with horizontal fraction bar
1.144 */
1.145 - // TODOWN rename f
1.146 - def calcFrac( emptyBox: EmptyBinOpBox, f:(DrawBox) => Unit) = {
1.147 + def calcFrac( emptyBox: EmptyBinOpBox, callback_calc:(DrawBox) => Unit) = {
1.148 val operator = emptyBox.operator
1.149 val paramUpper = emptyBox.paraml
1.150 val paramLower = emptyBox.paramr
1.151 @@ -262,19 +258,19 @@
1.152 val l_x0 = x0 + (maxWidth / 2f - l_box.width / 2f).round
1.153 val l_y0 = y_midline + Settings.FRACVERTIKALSPACE + fontWidthOf(fontsizeOf(level)) + difY0upper
1.154
1.155 - val u_res_box = assembleBoxesRec( new EmptyBox(level+1, u_x0, u_y0,paramUpper), f)
1.156 - val l_res_box = assembleBoxesRec( new EmptyBox(level+1, l_x0, l_y0, paramLower), f)
1.157 + val u_res_box = assembleBoxesRec( new EmptyBox(level+1, u_x0, u_y0,paramUpper), callback_calc)
1.158 + val l_res_box = assembleBoxesRec( new EmptyBox(level+1, l_x0, l_y0, paramLower), callback_calc)
1.159
1.160 val b = new DrawBox(
1.161 "", level, x0, l_res_box.y, maxWidth,
1.162 u_res_box.height + l_res_box.height + line_box.height + Settings.FRACVERTIKALSPACE + Settings.FRACVERTIKALSPACE,
1.163 x0, y0, ast)
1.164 b.children = line_box :: u_res_box :: l_res_box :: List.empty[DrawBox]
1.165 - f(b) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.166 + callback_calc(b) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.167 b
1.168 }
1.169 - // TODOWN rename f
1.170 - def calcDefault( str: String, param: List[Ast], x0: Int, y0: Int, level: Int, ast : Ast, f:(DrawBox) => Unit) = {
1.171 + // default for rendering unknown Asts (tuple, list, ...)
1.172 + def calcDefault( str: String, param: List[Ast], x0: Int, y0: Int, level: Int, ast : Ast, callback_calc:(DrawBox) => Unit) = {
1.173 val boxes = param.map(x => assembleBoxesRec( new EmptyBox(level, x0, y0, x),emptyFunc))
1.174
1.175 val horizontalSpace = Settings.getStringBoundOf(",x", level, x0, y0)
1.176 @@ -287,7 +283,7 @@
1.177 var resBoxes = List.empty[DrawBox]
1.178
1.179 for (box <- boxes) {
1.180 - val b = assembleBoxesRec( new EmptyBox(level, x, y, box.ast), f)
1.181 + val b = assembleBoxesRec( new EmptyBox(level, x, y, box.ast), callback_calc)
1.182 resBoxes = b :: resBoxes
1.183 if (box == boxes.last) {
1.184 resBoxes = new DrawBox(")", level, b.x,b.y,horizontalSpace.width,horizontalSpace.height,b.x + b.width,y,null) :: resBoxes
1.185 @@ -299,16 +295,11 @@
1.186 }
1.187 val resultBox = new DrawBox(XSyntax.isa_ast(str) + "(", level, x0, y0, x - x0 , boxes.map(mb => mb.height).max, x0, y0, ast);
1.188 resultBox.children = resBoxes
1.189 - f(resultBox) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.190 + callback_calc(resultBox) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.191 resultBox
1.192 }
1.193 -
1.194 - /* TODOWN: generalise together with calcPlus to calcHorizontal
1.195 - * calculate Boxes with the form Appl(Constant("HOL.eq"), Variable(str), Variable(str)) --> str = str
1.196 - * nearly similar to calcPlus() but with more Space between Variable and Constant (LARGESPACE instance of MEDIUMSPACE)
1.197 - */
1.198 - // TODOWN unify with calcDefaultBinOp , rename f
1.199 - def calcEqualation( emptyBox: EmptyBinOpBox, f:(DrawBox) => Unit) = {
1.200 + // different from calcDefaultBinOp due to different spaces
1.201 + def calcEqualation( emptyBox: EmptyBinOpBox, callback_calc:(DrawBox) => Unit) = {
1.202 val operator = emptyBox.operator
1.203 val paraml = emptyBox.paraml
1.204 val paramr = emptyBox.paramr
1.205 @@ -317,21 +308,23 @@
1.206 val level= emptyBox.level
1.207 val ast = emptyBox.ast
1.208
1.209 - val l_box = assembleBoxesRec( new EmptyBox(level, x0, y0, paraml), f)
1.210 + val l_box = assembleBoxesRec( new EmptyBox(level, x0, y0, paraml), callback_calc)
1.211 val l_width = l_box.width
1.212 val l_height = l_box.height
1.213
1.214 - val o_box = assembleBoxesRec( new EmptyBox(level, x0 + l_width + Settings.LARGESPACE, y0, Constant("=")), f)
1.215 + val o_box = assembleBoxesRec( new EmptyBox(level, x0 + l_width +
1.216 + Settings.LARGESPACE, y0, Constant("=")), callback_calc)
1.217 val operator_width = o_box.width
1.218 val operator_height = o_box.height
1.219
1.220 - val r_box = assembleBoxesRec( new EmptyBox(level, x0 + l_width + Settings.LARGESPACE + operator_width + Settings.LARGESPACE, y0, paramr), f)
1.221 + val r_box = assembleBoxesRec( new EmptyBox(level, x0 + l_width +
1.222 + Settings.LARGESPACE + operator_width + Settings.LARGESPACE, y0, paramr), callback_calc)
1.223 val r_width = r_box.width
1.224 val r_height = r_box.height
1.225
1.226 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)
1.227 b.children = o_box :: l_box :: r_box :: List.empty[DrawBox]
1.228 - f(b) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.229 + callback_calc(b) // see mmahringer $4.3.1 p.53/54 and $4.3.2 p.56
1.230 b
1.231 }
1.232 def lowestY0(b: DrawBox): Int = {