]> gitweb @ CieloNegro.org - task-reporter.git/blobdiff - src/main/scala/jp/ymir/taskReporter/ui/MainFrame.scala
wip
[task-reporter.git] / src / main / scala / jp / ymir / taskReporter / ui / MainFrame.scala
index 3759437c664d32886a537faa6705fe0b79fdae03..a09aa5dfa6f2b655ce8c67dc71c1f7a30973b298 100644 (file)
@@ -12,15 +12,22 @@ import javax.swing.filechooser.FileNameExtensionFilter
 import jp.ymir.taskReporter._
 import jp.ymir.taskReporter.core._
 import scala.swing._
+import scala.swing.Swing._
 import scala.swing.event._
 
 class MainFrame(reportFile: Option[File]) extends Frame {
-  private var reportSet = new ReportSet(reportFile)
+  frame =>
 
-  title = "Task Reporter " + Main.getVersion
+  private val reportSet = new ReportSet(reportFile)
 
-  size = Preferences.mainFrameSize()
-  centerOnScreen
+  title         = "Task Reporter " + Main.getVersion
+  preferredSize = Preferences.mainFrameSize()
+
+  case class FileOpened(file: File)         extends Event
+  case class ReportSelected(report: Report) extends Event
+  case class ReportDeselected()             extends Event
+  case class TaskSelected(task: Task)       extends Event
+  case class TaskDeselected()               extends Event
 
   peer.addComponentListener(new ComponentAdapter() {
     override def componentResized(e: ComponentEvent) {
@@ -28,65 +35,12 @@ class MainFrame(reportFile: Option[File]) extends Frame {
     }
   })
 
-  override def closeOperation {
-    if (dirty) {
-      val r = JOptionPane.showConfirmDialog(
-        peer,
-        "The report file \"" + reportSet.file.get.getName + "\" has been modified.\n" +
-          "Do you want to save it before closing?",
-        "Confirmation",
-        JOptionPane.YES_NO_CANCEL_OPTION);
-
-      r match {
-        case JOptionPane.YES_OPTION => save; dispose
-        case JOptionPane.NO_OPTION  => dispose
-        case _ =>
-      }
-    }
-    else {
-      dispose
-    }
-  }
-
-  def dirty : Boolean = {
-    return reportSet.dirty
-  }
-
-  def save {
-    if (reportSet.file.isEmpty) {
-      val chooser = new FileChooser(Preferences.lastChosenDir())
-      val r = chooser.showSaveDialog(null)
-      if (r != FileChooser.Result.Approve) {
-        return
-      }
-
-      if (chooser.selectedFile.exists) {
-        val r = JOptionPane.showConfirmDialog(
-          peer,
-          "The chosen file or directory \"" + chooser.selectedFile.getName + "\" already exists.\n" +
-            "Do you want to overwrite it?",
-          "Confirmation",
-          JOptionPane.YES_NO_OPTION)
-
-        r match {
-          case JOptionPane.YES_OPTION =>
-          case JOptionPane.NO_OPTION  => return
-        }
-      }
-
-      Preferences.lastChosenDir() = chooser.selectedFile.getParentFile
-      reportSet.file = Some(chooser.selectedFile)
-    }
-
-    reportSet.save
-  }
-
   menuBar = new MenuBar {
     contents += new Menu("File") {
       mnemonic = Key.F
 
       val miOpen = new MenuItem(new Action("Open...") {
-        accelerator = Some(KeyStroke.getKeyStroke("control O"))
+        accelerator = Some(KeyStroke getKeyStroke "control O")
         def apply {
           val chooser = new FileChooser(Preferences.lastChosenDir()) {
             fileSelectionMode = FileChooser.SelectionMode.FilesOnly
@@ -96,8 +50,10 @@ class MainFrame(reportFile: Option[File]) extends Frame {
           }
           val r = chooser.showOpenDialog(null)
           if (r == FileChooser.Result.Approve) {
-            Preferences.lastChosenDir() = chooser.selectedFile.getParentFile
-            reportSet = new ReportSet(Some(chooser.selectedFile))
+            val file = chooser.selectedFile
+            Preferences.lastChosenDir() = file.getParentFile
+            reportSet load file
+            frame publish FileOpened(file)
           }
         }
       })
@@ -134,25 +90,158 @@ class MainFrame(reportFile: Option[File]) extends Frame {
 
   contents = new SplitPane {
     peer.setOrientation(JSplitPane.HORIZONTAL_SPLIT)
-    resizeWeight = 0.3
+    continuousLayout   = true
+    oneTouchExpandable = true
+    resizeWeight       = 0 // Let the left pane be fixed
+
+    rightComponent = new BoxPanel(Orientation.Vertical) {
+      border = EmptyBorder(5, 5, 5, 5)
+
+      contents += new ScrollPane(
+        new Table() {
+          peer setFillsViewportHeight true
+          listenTo(frame)
+
+          override def model : Report = super.model.asInstanceOf[Report]
+
+          reactions += {
+            case ReportSelected(report) =>
+              model = report
+              if (rowCount > 0) {
+                selection.rows += rowCount - 1 // Select the last report
+              }
+            case ReportDeselected() =>
+              model = new Report() // Empty report
+          }
+
+          selection.reactions += {
+            case TableRowsSelected(_, _, false) =>
+              selection.rows.size match {
+                case 1 =>
+                  val task = model(selection.rows.head)
+                  frame publish TaskSelected(task)
+                case _ =>
+                  frame publish TaskDeselected()
+              }
+          }
+        })
+      contents += VStrut(5)
+      contents += new Separator(Orientation.Horizontal)
+      contents += VStrut(5)
+      contents += new TaskEditor
+      contents += VStrut(5)
+      contents += new Separator(Orientation.Horizontal)
+      contents += VStrut(5)
+      contents += new FlowPanel(FlowPanel.Alignment.Left)() {
+        contents += new Button(new Action("New") {
+          def apply = {} // FIXME
+        })
+        contents += new Button(new Action("Delete...") {
+          def apply = {} // FIXME
+        })
+      }
+    }
 
     leftComponent = new BorderPanel {
-      val title = new Label("Report date") {
-        horizontalAlignment = Alignment.Leading
+      border = EmptyBorder(5, 5, 5, 5)
+
+      add(
+        new ScrollPane(
+          new Table() {
+            peer setFillsViewportHeight true
+            peer setModel reportSet
+            listenTo(frame)
+            reactions += {
+              case FileOpened(f) =>
+                if (rowCount > 0) {
+                  selection.rows += rowCount - 1 // Select the last report
+                }
+            }
+            selection.reactions += {
+              case TableRowsSelected(_, _, false) =>
+                selection.rows.size match {
+                  case 1 =>
+                    val report = reportSet(selection.rows.head)
+                    frame publish ReportSelected(report)
+                  case _ =>
+                    frame publish ReportDeselected()
+                }
+            }
+          }), BorderPanel.Position.Center)
+
+      add(
+        new FlowPanel(FlowPanel.Alignment.Left)() {
+          contents += new Button(new Action("New...") {
+            def apply = {} // FIXME
+          })
+          contents += new Button(new Action("Delete...") {
+            def apply = {} // FIXME
+          })
+        }, BorderPanel.Position.South)
+
+      preferredSize = minimumSize
+    }
+  }
+
+  reportSet.file match {
+    case Some(file) => frame publish FileOpened(file)
+    case None       => frame publish ReportDeselected()
+  }
+
+  centerOnScreen
+  visible = true
+
+  override def closeOperation {
+    if (dirty) {
+      val r = JOptionPane.showConfirmDialog(
+        peer,
+        "The report file \"" + reportSet.file.get.getName + "\" has been modified.\n" +
+          "Do you want to save it before closing?",
+        "Confirmation",
+        JOptionPane.YES_NO_CANCEL_OPTION);
+
+      r match {
+        case JOptionPane.YES_OPTION => save; dispose
+        case JOptionPane.NO_OPTION  => dispose
+        case _ =>
       }
-      layout(title) = BorderPanel.Position.North
-
-      val scroll = new ScrollPane {
-        horizontalScrollBarPolicy = ScrollPane.BarPolicy.Never
-        verticalScrollBarPolicy   = ScrollPane.BarPolicy.Always
-        contents = new ListView[String] {
-          // FIXME
-          // listData =
+    }
+    else {
+      dispose
+    }
+  }
+
+  def dirty : Boolean = {
+    return reportSet.dirty
+  }
+
+  def save {
+    if (reportSet.file.isEmpty) {
+      val chooser = new FileChooser(Preferences.lastChosenDir())
+      val r = chooser.showSaveDialog(null)
+      if (r != FileChooser.Result.Approve) {
+        return
+      }
+
+      if (chooser.selectedFile.exists) {
+        val r = JOptionPane.showConfirmDialog(
+          peer,
+          "The chosen file or directory \"" + chooser.selectedFile.getName + "\" already exists.\n" +
+            "Do you want to overwrite it?",
+          "Confirmation",
+          JOptionPane.YES_NO_OPTION)
+
+        r match {
+          case JOptionPane.YES_OPTION =>
+          case JOptionPane.NO_OPTION  => return
         }
       }
-      layout(scroll) = BorderPanel.Position.Center
+
+      Preferences.lastChosenDir() = chooser.selectedFile.getParentFile
+      reportSet.save(chooser.selectedFile)
+    }
+    else {
+      reportSet.save
     }
   }
-
-  visible = true
 }