]> 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..1807a064d3535292c20dee4fb8493d57b2492022 100644 (file)
@@ -3,6 +3,7 @@ import java.awt.Dimension
 import java.awt.event.ComponentAdapter
 import java.awt.event.ComponentEvent
 import java.io._
+import javax.swing.BorderFactory
 import javax.swing.JOptionPane
 import javax.swing.JSplitPane
 import javax.swing.KeyStroke
@@ -15,12 +16,10 @@ import scala.swing._
 import scala.swing.event._
 
 class MainFrame(reportFile: Option[File]) extends Frame {
-  private var reportSet = new ReportSet(reportFile)
+  private val reportSet = new ReportSet(reportFile)
 
-  title = "Task Reporter " + Main.getVersion
-
-  size = Preferences.mainFrameSize()
-  centerOnScreen
+  title         = "Task Reporter " + Main.getVersion
+  preferredSize = Preferences.mainFrameSize()
 
   peer.addComponentListener(new ComponentAdapter() {
     override def componentResized(e: ComponentEvent) {
@@ -28,59 +27,6 @@ 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
@@ -97,7 +43,8 @@ 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))
+            reportSet.load(chooser.selectedFile)
+            // FIXME: select the last report
           }
         }
       })
@@ -134,25 +81,106 @@ 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 SplitPane {
+      peer.setOrientation(JSplitPane.VERTICAL_SPLIT)
+      continuousLayout   = true
+      oneTouchExpandable = true
+      resizeWeight       = 0.5
+
+      leftComponent = new ScrollPane(
+        new Table() {
+          peer.setModel(new Report()) // Empty report
+        })
+    }
 
     leftComponent = new BorderPanel {
-      val title = new Label("Report date") {
-        horizontalAlignment = Alignment.Leading
-      }
-      layout(title) = BorderPanel.Position.North
-
-      val scroll = new ScrollPane {
-        horizontalScrollBarPolicy = ScrollPane.BarPolicy.Never
-        verticalScrollBarPolicy   = ScrollPane.BarPolicy.Always
-        contents = new ListView[String] {
-          // FIXME
-          // listData =
-        }
+      border = BorderFactory.createEmptyBorder(5, 5, 5, 5)
+
+      val reportsScroll = new ScrollPane(
+        new Table() {
+          peer.setModel(reportSet)
+          if (rowCount > 0) {
+            selection.rows += rowCount - 1 // Select the last report
+          }
+          selection.reactions += {
+            case TableRowsSelected(_, _, false) =>
+              // FIXME
+          }
+        })
+      layout(reportsScroll) = BorderPanel.Position.Center
+
+      val buttons = new FlowPanel(FlowPanel.Alignment.Left)() {
+        contents += new Button(new Action("Add") {
+          def apply = {} // FIXME
+        })
+        contents += new Button(new Action("Delete...") {
+          def apply = {} // FIXME
+        })
       }
-      layout(scroll) = BorderPanel.Position.Center
+      layout(buttons) = BorderPanel.Position.South
+
+      preferredSize = minimumSize
     }
   }
 
+  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 _ =>
+      }
+    }
+    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.save(chooser.selectedFile)
+    }
+    else {
+      reportSet.save
+    }
+  }
 }