src/Tools/Graphview/mutator_dialog.scala
changeset 75393 87ebf5a50283
parent 73367 77ef8bef0593
child 75394 42267c650205
equal deleted inserted replaced
75388:b3ca4a6ed74b 75393:87ebf5a50283
    22 class Mutator_Dialog(
    22 class Mutator_Dialog(
    23     graphview: Graphview,
    23     graphview: Graphview,
    24     container: Mutator_Container,
    24     container: Mutator_Container,
    25     caption: String,
    25     caption: String,
    26     reverse_caption: String = "Inverse",
    26     reverse_caption: String = "Inverse",
    27     show_color_chooser: Boolean = true)
    27     show_color_chooser: Boolean = true
    28   extends Dialog
    28 ) extends Dialog {
    29 {
       
    30   title = caption
    29   title = caption
    31 
    30 
    32   private var _panels: List[Mutator_Panel] = Nil
    31   private var _panels: List[Mutator_Panel] = Nil
    33   private def panels = _panels
    32   private def panels = _panels
    34   private def panels_=(panels: List[Mutator_Panel]): Unit =
    33   private def panels_=(panels: List[Mutator_Panel]): Unit = {
    35   {
       
    36     _panels = panels
    34     _panels = panels
    37     paint_panels()
    35     paint_panels()
    38   }
    36   }
    39 
    37 
    40   container.events +=
    38   container.events +=
    41   {
    39     {
    42     case Mutator_Event.Add(m) => add_panel(new Mutator_Panel(m))
    40       case Mutator_Event.Add(m) => add_panel(new Mutator_Panel(m))
    43     case Mutator_Event.New_List(ms) => panels = get_panels(ms)
    41       case Mutator_Event.New_List(ms) => panels = get_panels(ms)
    44   }
    42     }
    45 
    43 
    46   override def open(): Unit =
    44   override def open(): Unit = {
    47   {
       
    48     if (!visible) panels = get_panels(container())
    45     if (!visible) panels = get_panels(container())
    49     super.open()
    46     super.open()
    50   }
    47   }
    51 
    48 
    52   minimumSize = new Dimension(700, 200)
    49   minimumSize = new Dimension(700, 200)
    58     .map(m => new Mutator_Panel(m))
    55     .map(m => new Mutator_Panel(m))
    59 
    56 
    60   private def get_mutators(panels: List[Mutator_Panel]): List[Mutator.Info] =
    57   private def get_mutators(panels: List[Mutator_Panel]): List[Mutator.Info] =
    61     panels.map(panel => panel.get_mutator)
    58     panels.map(panel => panel.get_mutator)
    62 
    59 
    63   private def movePanelUp(m: Mutator_Panel) =
    60   private def movePanelUp(m: Mutator_Panel) = {
    64   {
       
    65     def moveUp(l: List[Mutator_Panel]): List[Mutator_Panel] =
    61     def moveUp(l: List[Mutator_Panel]): List[Mutator_Panel] =
    66       l match {
    62       l match {
    67         case x :: y :: xs => if (y == m) y :: x :: xs else x :: moveUp(y :: xs)
    63         case x :: y :: xs => if (y == m) y :: x :: xs else x :: moveUp(y :: xs)
    68         case _ => l
    64         case _ => l
    69       }
    65       }
    70 
    66 
    71     panels = moveUp(panels)
    67     panels = moveUp(panels)
    72   }
    68   }
    73 
    69 
    74   private def movePanelDown(m: Mutator_Panel) =
    70   private def movePanelDown(m: Mutator_Panel) = {
    75   {
       
    76     def moveDown(l: List[Mutator_Panel]): List[Mutator_Panel] =
    71     def moveDown(l: List[Mutator_Panel]): List[Mutator_Panel] =
    77       l match {
    72       l match {
    78         case x :: y :: xs => if (x == m) y :: x :: xs else x :: moveDown(y :: xs)
    73         case x :: y :: xs => if (x == m) y :: x :: xs else x :: moveDown(y :: xs)
    79         case _ => l
    74         case _ => l
    80       }
    75       }
    81 
    76 
    82     panels = moveDown(panels)
    77     panels = moveDown(panels)
    83   }
    78   }
    84 
    79 
    85   private def removePanel(m: Mutator_Panel): Unit =
    80   private def removePanel(m: Mutator_Panel): Unit = {
    86   {
       
    87     panels = panels.filter(_ != m).toList
    81     panels = panels.filter(_ != m).toList
    88   }
    82   }
    89 
    83 
    90   private def add_panel(m: Mutator_Panel): Unit =
    84   private def add_panel(m: Mutator_Panel): Unit = {
    91   {
       
    92     panels = panels ::: List(m)
    85     panels = panels ::: List(m)
    93   }
    86   }
    94 
    87 
    95   def paint_panels(): Unit =
    88   def paint_panels(): Unit = {
    96   {
       
    97     Focus_Traveral_Policy.clear()
    89     Focus_Traveral_Policy.clear()
    98     filter_panel.contents.clear()
    90     filter_panel.contents.clear()
    99     panels.map(x => {
    91     panels.map(x => {
   100         filter_panel.contents += x
    92         filter_panel.contents += x
   101         Focus_Traveral_Policy.addAll(x.focusList)
    93         Focus_Traveral_Policy.addAll(x.focusList)
   158     layout(new ScrollPane(filter_panel)) = BorderPanel.Position.Center
   150     layout(new ScrollPane(filter_panel)) = BorderPanel.Position.Center
   159     layout(botPanel) = BorderPanel.Position.South
   151     layout(botPanel) = BorderPanel.Position.South
   160   }
   152   }
   161 
   153 
   162   private class Mutator_Panel(initials: Mutator.Info)
   154   private class Mutator_Panel(initials: Mutator.Info)
   163     extends BoxPanel(Orientation.Horizontal)
   155   extends BoxPanel(Orientation.Horizontal) {
   164   {
       
   165     private val inputs: List[(String, Input)] = get_inputs()
   156     private val inputs: List[(String, Input)] = get_inputs()
   166     var focusList = List.empty[java.awt.Component]
   157     var focusList = List.empty[java.awt.Component]
   167     private val enabledBox = new Check_Box_Input("Enabled", initials.enabled)
   158     private val enabledBox = new Check_Box_Input("Enabled", initials.enabled)
   168 
   159 
   169     border = new EmptyBorder(5, 5, 5, 5)
   160     border = new EmptyBorder(5, 5, 5, 5)
   241       }
   232       }
   242     }
   233     }
   243 
   234 
   244     focusList = focusList.reverse
   235     focusList = focusList.reverse
   245 
   236 
   246     def get_mutator: Mutator.Info =
   237     def get_mutator: Mutator.Info = {
   247     {
       
   248       val model = graphview.model
   238       val model = graphview.model
   249       val m =
   239       val m =
   250         initials.mutator match {
   240         initials.mutator match {
   251           case Mutator.Identity() =>
   241           case Mutator.Identity() =>
   252             Mutator.Identity()
   242             Mutator.Identity()
   315             ("", new Check_Box_Input("Children", children)))
   305             ("", new Check_Box_Input("Children", children)))
   316         case _ => Nil
   306         case _ => Nil
   317       }
   307       }
   318   }
   308   }
   319 
   309 
   320   private trait Input
   310   private trait Input {
   321   {
       
   322     def string: String
   311     def string: String
   323     def bool: Boolean
   312     def bool: Boolean
   324   }
   313   }
   325 
   314 
   326   private class Text_Field_Input(txt: String, check: String => Boolean = (_: String) => true)
   315   private class Text_Field_Input(txt: String, check: String => Boolean = (_: String) => true)
   327     extends TextField(txt) with Input
   316   extends TextField(txt) with Input {
   328   {
       
   329     preferredSize = new Dimension(125, 18)
   317     preferredSize = new Dimension(125, 18)
   330 
   318 
   331     private val default_foreground = foreground
   319     private val default_foreground = foreground
   332     reactions +=
   320     reactions +=
   333     {
   321       {
   334       case ValueChanged(_) =>
   322         case ValueChanged(_) =>
   335         foreground = if (check(text)) default_foreground else graphview.error_color
   323           foreground = if (check(text)) default_foreground else graphview.error_color
   336     }
   324       }
   337 
   325 
   338     def string = text
   326     def string = text
   339     def bool = true
   327     def bool = true
   340   }
   328   }
   341 
   329 
   342   private class Check_Box_Input(txt: String, s: Boolean) extends CheckBox(txt) with Input
   330   private class Check_Box_Input(txt: String, s: Boolean)
   343   {
   331   extends CheckBox(txt) with Input {
   344     selected = s
   332     selected = s
   345 
   333 
   346     def string = ""
   334     def string = ""
   347     def bool = selected
   335     def bool = selected
   348   }
   336   }
   349 
   337 
   350   private object Focus_Traveral_Policy extends FocusTraversalPolicy
   338   private object Focus_Traveral_Policy extends FocusTraversalPolicy {
   351   {
       
   352     private var items = Vector.empty[java.awt.Component]
   339     private var items = Vector.empty[java.awt.Component]
   353 
   340 
   354     def add(c: java.awt.Component): Unit = { items = items :+ c }
   341     def add(c: java.awt.Component): Unit = { items = items :+ c }
   355     def addAll(cs: IterableOnce[java.awt.Component]): Unit = { items = items ++ cs }
   342     def addAll(cs: IterableOnce[java.awt.Component]): Unit = { items = items ++ cs }
   356     def clear(): Unit = { items = Vector.empty }
   343     def clear(): Unit = { items = Vector.empty }
   357 
   344 
   358     def getComponentAfter(root: java.awt.Container, c: java.awt.Component): java.awt.Component =
   345     def getComponentAfter(root: java.awt.Container, c: java.awt.Component): java.awt.Component = {
   359     {
       
   360       val i = items.indexOf(c)
   346       val i = items.indexOf(c)
   361       if (i < 0) getDefaultComponent(root)
   347       if (i < 0) getDefaultComponent(root)
   362       else items((i + 1) % items.length)
   348       else items((i + 1) % items.length)
   363     }
   349     }
   364 
   350 
   365     def getComponentBefore(root: java.awt.Container, c: java.awt.Component): java.awt.Component =
   351     def getComponentBefore(root: java.awt.Container, c: java.awt.Component): java.awt.Component = {
   366     {
       
   367       val i = items.indexOf(c)
   352       val i = items.indexOf(c)
   368       if (i < 0) getDefaultComponent(root)
   353       if (i < 0) getDefaultComponent(root)
   369       else items((i - 1) % items.length)
   354       else items((i - 1) % items.length)
   370     }
   355     }
   371 
   356