Anonymous avatar Anonymous committed c1610f6

improved Gap DSL for DialogLayout

Comments (0)

Files changed (1)

src/de/matthiasmann/twlscala/DialogLayout.scala

 
     type TWLGroup = TWLDialogLayout#Group
     
-    sealed abstract class Gap
+    sealed abstract class Gap {
+        protected def size2string(s:Int) = s match {
+            case TWLDialogLayout.SMALL_GAP   => "SmallGap"
+            case TWLDialogLayout.MEDIUM_GAP  => "MediumGap"
+            case TWLDialogLayout.LARGE_GAP   => "LargeGap"
+            case TWLDialogLayout.DEFAULT_GAP => "DefaultGap"
+            case Gap.MAX                     => "MAX"
+            case x => x.toString
+        }
+    }
+    case class MinPrefMaxGap private[twlscala] (min:Int, pref:Int, max:Int) extends Gap {
+        def atleast (g:FixedGap) = new MinPrefMaxGap(g.size, pref, max)
+        def lessThen(g:FixedGap) = new MinPrefMaxGap(min, pref, g.size)
+        override def toString = "MinPrefMaxGap("+size2string(min)+","+size2string(pref)+","+size2string(max)+")"
+    }
+    case class FixedGap private[twlscala] (size:Int) extends Gap {
+        def atleast (g:FixedGap) = new MinPrefMaxGap(g.size, this.size, Gap.MAX)
+        def lessThen(g:FixedGap) = new MinPrefMaxGap(0, this.size, g.size)
+        def orMore               = new MinPrefMaxGap(this.size, this.size, Gap.MAX)
+        override def toString = "FixedGap("+size2string(size)+")"
+    }
     case object Filler extends Gap
-    case object SmallGap extends Gap
-    case object MediumGap extends Gap
-    case object LargeGap extends Gap
-    case object DefaultGap extends Gap
-    case class FixedGap(size:Int) extends Gap { require(size >= 0) }
+    case object SmallGap extends FixedGap(TWLDialogLayout.SMALL_GAP)
+    case object MediumGap extends FixedGap(TWLDialogLayout.MEDIUM_GAP)
+    case object LargeGap extends FixedGap(TWLDialogLayout.LARGE_GAP)
+    case object DefaultGap extends FixedGap(TWLDialogLayout.DEFAULT_GAP)
+    object Gap {
+        def apply(size:Int) = { require(size >= 0); new FixedGap(if(size<MAX) size else MAX) }
+        def between(min:FixedGap, max:FixedGap) = new MinPrefMaxGap(min.size, min.size, max.size)
+        def between(min:Int, max:FixedGap):MinPrefMaxGap = between(Gap(min), max)
+        def between(min:FixedGap, max:Int):MinPrefMaxGap = between(min, Gap(max))
+        def between(min:Int, max:Int):MinPrefMaxGap = between(Gap(min), Gap(max))
+        private[twlscala] val MAX = 32767
+    }
 
     abstract class GroupWrapper {
         def underlaying:TWLGroup
         protected def addGap(g:Gap):Unit =  g match {
-            case Filler      => underlaying.addGap
-            case SmallGap    => underlaying.addGap(TWLDialogLayout.SMALL_GAP)
-            case MediumGap   => underlaying.addGap(TWLDialogLayout.MEDIUM_GAP)
-            case LargeGap    => underlaying.addGap(TWLDialogLayout.LARGE_GAP)
-            case DefaultGap  => underlaying.addGap(TWLDialogLayout.DEFAULT_GAP)
-            case FixedGap(s) => underlaying.addGap(s)
+            case Filler                      => underlaying.addGap
+            case FixedGap(s)                 => underlaying.addGap(s)
+            case MinPrefMaxGap(min,pref,max) => underlaying.addGap(min,pref,max)
         }
     }
     class ParallelGroupWrapper(val underlaying:TWLGroup) extends GroupWrapper {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.