isac-java/src/java/isac/gui/mawen/editor/BoxUtil.scala
changeset 5201 5c61af5d1fc8
parent 5200 80152e6a6702
parent 5199 3799cb07f123
child 5202 a4d087dd5e5d
equal deleted inserted replaced
5200:80152e6a6702 5201:5c61af5d1fc8
     1 package isac.gui.mawen.editor
     1 package isac.gui.mawen.editor
     2 
     2 
     3 import isac.gui.mawen.editor.Box._
     3 import java.awt.Graphics
       
     4 import java.awt.Color
       
     5 import javax.swing.JTextField
       
     6 import java.awt.Dimension
       
     7 import javax.swing.JButton
     4 import isac.gui.mawen.syntax.Ast._
     8 import isac.gui.mawen.syntax.Ast._
     5 import isac.gui.mawen.syntax.Ast
     9 import isac.gui.mawen.syntax.Ast
       
    10 import java.awt.Font
       
    11 import isac.gui.mawen.editor.Box._
       
    12 import java.awt.Graphics2D
     6 import isac.gui.mawen.syntax.XSyntax
    13 import isac.gui.mawen.syntax.XSyntax
     7 import java.awt.Graphics
       
     8 import java.awt.Color
       
     9 import java.awt.Dimension
       
    10 import java.awt.Font
       
    11 import java.awt.Graphics2D
       
    12 import javax.swing.JButton
       
    13 import javax.swing.JTextField
       
    14 
    14 
    15 /**
    15 /**
    16  * <code>paint</code>s a <code>Box</code> according to 
    16  * <code>paint</code>s a <code>Box</code> according to 
    17  * a <code>Box.name</code>, which refers to
    17  * a <code>Box.name</code>, which refers to
    18  * specific layouts defined in <code>CalcUtil</code>.
    18  * specific layouts defined in <code>CalcUtil</code>.
    19  */
    19  */
    20 object BoxUtil {
    20 object BoxUtil {
    21 
    21   
       
    22   
       
    23   
       
    24   
    22   def Draw(box : DrawBox, g: Graphics) : Unit = box.name match {
    25   def Draw(box : DrawBox, g: Graphics) : Unit = box.name match {
    23     case "GAP"                         => drawGap(g, box) 
    26     case "GAP"                         => drawGap(g, box) 
    24     case "CURSOR"                      => drawCursor(g, box)
    27     case "CURSOR"                      => drawCursor(g, box)
    25     case "Groups.plus_class.plus"      => drawPlus(g, box)
    28     case "Groups.plus_class.plus"      => drawPlus(g, box)
    26     case "Fields.inverse_class.divide" => drawDivide(g, box) 
    29     case "Fields.inverse_class.divide" => drawDivide(g, box) 
    31     case _ =>  {
    34     case _ =>  {
    32       drawString(g, box)
    35       drawString(g, box)
    33       box.children.foreach( Draw(_, g) )
    36       box.children.foreach( Draw(_, g) )
    34     }
    37     }
    35   }
    38   }
       
    39   
       
    40   
    36   def drawGap(g: Graphics, box : DrawBox) {
    41   def drawGap(g: Graphics, box : DrawBox) {
    37     g.fillRoundRect(box.x, box.y- box.height, box.width, box.height, 15, 15)
    42     g.fillRoundRect(box.x, box.y- box.height, box.width, box.height, 15, 15)
    38     drawBox(box, g)
    43     drawBox(box, g)
       
    44     
    39   }
    45   }
    40   def drawCursor(g: Graphics, box : DrawBox) = System.currentTimeMillis() match {
    46   def drawCursor(g: Graphics, box : DrawBox) = System.currentTimeMillis() match {
    41     case n if (n / 250) % 1 == 0  => box.ast match {
    47     case n if (n / 250) % 1 == 0  => box.ast match {
    42       case Appl(List(Constant("CURSOR"), a)) => {
    48       case Appl(List(Constant("CURSOR"), a)) => {
    43         g.setColor(Color.RED)
    49         g.setColor(Color.RED)
    44         g.asInstanceOf[Graphics2D].drawLine(box.x, box.y, box.x + box.width , box.y)
    50         g.asInstanceOf[Graphics2D].drawLine(box.x, box.y, box.x + box.width , box.y)
    45         g.asInstanceOf[Graphics2D].drawLine(box.x, box.y, box.x, box.y - box.height)
    51         g.asInstanceOf[Graphics2D].drawLine(box.x, box.y, box.x, box.y - box.height)
    46 
    52         
       
    53         
       
    54   //      g.drawRect(box.x, box.y - box.height, box.width, box.height)
    47         g.setColor(Color.BLACK)
    55         g.setColor(Color.BLACK)
    48         if (box.children.length >= 1) Draw(box.children.head, g)
    56         if (box.children.length >= 1)
       
    57           Draw(box.children.head, g)
       
    58       
       
    59   		
       
    60   //		  Box.drawBox(box, g)
       
    61         
       
    62         
    49       }
    63       }
       
    64       
    50       case Appl(List(a, Constant("CURSOR"))) => {
    65       case Appl(List(a, Constant("CURSOR"))) => {
    51         g.setColor(Color.RED)
    66         g.setColor(Color.RED)
    52         g.asInstanceOf[Graphics2D].drawLine(box.x, box.y, box.x + box.width , box.y)
    67         g.asInstanceOf[Graphics2D].drawLine(box.x, box.y, box.x + box.width , box.y)
    53         g.asInstanceOf[Graphics2D].drawLine(box.x+ box.width, box.y, box.x + box.width, box.y - box.height)
    68         g.asInstanceOf[Graphics2D].drawLine(box.x+ box.width, box.y, box.x + box.width, box.y - box.height)
    54         
    69         
    55         g.setColor(Color.BLACK)
    70         g.setColor(Color.BLACK)
    56         if (box.children.length >= 1)
    71         if (box.children.length >= 1)
    57           Draw(box.children.head, g)
    72           Draw(box.children.head, g)
    58       }
    73       }
       
    74       
    59     }
    75     }
    60     case _ => {
    76     case _ => {
    61       if (box.children.length >= 1)
    77       if (box.children.length >= 1)
    62           Draw(box.children.head, g)
    78           Draw(box.children.head, g)
    63     }
    79     }
       
    80     
    64   }
    81   }
       
    82     
       
    83     
       
    84     
       
    85     
       
    86   
    65   def drawPlus(g: Graphics, box : DrawBox) {
    87   def drawPlus(g: Graphics, box : DrawBox) {
    66     val font_var = new Font("CMCSC8", Font.PLAIN,  CalcUtil.fontsizeOf(box.level))
    88     val font_var = new Font("CMCSC8", Font.PLAIN,  CalcUtil.fontsizeOf(box.level))
    67     g.setFont(font_var)
    89     g.setFont(font_var)
    68     
    90     
    69     g.drawString("+", box.x0, box.y0)
    91     g.drawString("+", box.x0, box.y0)
    70     drawBox(box, g)
    92     drawBox(box, g)
       
    93 
    71   }
    94   }
       
    95   
    72   def drawDivide(g: Graphics, box : DrawBox) {
    96   def drawDivide(g: Graphics, box : DrawBox) {
    73     g.drawLine(box.x, box.y, box.x + box.width, box.y)
    97     g.drawLine(box.x, box.y, box.x + box.width, box.y)
    74     drawBox(box, g)
    98     drawBox(box, g)
    75   }
    99   }
    76   def drawString(g: Graphics, box : DrawBox) {
   100   def drawString(g: Graphics, box : DrawBox) {
    80         // Operator
   104         // Operator
    81         val font_var = new Font(fontname, Font.PLAIN,  CalcUtil.fontsizeOf(box.level))
   105         val font_var = new Font(fontname, Font.PLAIN,  CalcUtil.fontsizeOf(box.level))
    82         g.setFont(font_var)
   106         g.setFont(font_var)
    83         g.drawString(charIndex.toChar.toString(), box.x0, box.y0)
   107         g.drawString(charIndex.toChar.toString(), box.x0, box.y0)
    84         drawBox(box, g)
   108         drawBox(box, g)
       
   109         
    85       }
   110       }
    86       case None => {
   111       case None => {
    87         // Ident
   112         // Ident
    88         if (box.name.forall(c => EditingUtil.isNumber(c) || EditingUtil.isIdentifier(c)) ) {
   113         if (box.name.forall(c => EditingUtil.isNumber(c) || EditingUtil.isIdentifier(c)) ) {
    89           val font_var = new Font("CMMI12", Font.PLAIN,  CalcUtil.fontsizeOf(box.level))
   114           val font_var = new Font("CMMI12", Font.PLAIN,  CalcUtil.fontsizeOf(box.level))
    95         g.drawString(box.name, box.x0, box.y0)
   120         g.drawString(box.name, box.x0, box.y0)
    96         drawBox(box, g)
   121         drawBox(box, g)
    97       }
   122       }
    98     }
   123     }
    99 
   124 
       
   125     
       
   126     
   100   }
   127   }
   101   
   128   
   102   
   129   
   103   
   130   
   104   
   131