From 9a2bae84c21afd16791243f5c36f52e3a283712f Mon Sep 17 00:00:00 2001 From: PHO Date: Wed, 8 Oct 2014 16:53:27 +0900 Subject: [PATCH] wip --- build.sbt | 2 + .../jp/ymir/taskReporter/core/Report.scala | 2 + .../jp/ymir/taskReporter/core/ReportSet.scala | 15 ++--- .../jp/ymir/taskReporter/ui/MainFrame.scala | 67 ++++++++++++++++--- 4 files changed, 69 insertions(+), 17 deletions(-) diff --git a/build.sbt b/build.sbt index ed20293..ebb6b47 100644 --- a/build.sbt +++ b/build.sbt @@ -8,4 +8,6 @@ libraryDependencies <+= libraryDependencies += "org.scala-tools.sbinary" %% "sbinary" % "0.4.2" +scalacOptions ++= Seq("-deprecation", "-unchecked", "-encoding", "UTF-8") + assemblySettings diff --git a/src/main/scala/jp/ymir/taskReporter/core/Report.scala b/src/main/scala/jp/ymir/taskReporter/core/Report.scala index ef9a437..e147e66 100644 --- a/src/main/scala/jp/ymir/taskReporter/core/Report.scala +++ b/src/main/scala/jp/ymir/taskReporter/core/Report.scala @@ -13,6 +13,8 @@ class Report(private val _date: Calendar) extends AbstractTableModel { def date : Calendar = _date def size : Int = _tasks.size + def apply(idx: Int) = _tasks(idx) + def +=(task: Task) { require(task.date == _date) _tasks = _tasks :+ task diff --git a/src/main/scala/jp/ymir/taskReporter/core/ReportSet.scala b/src/main/scala/jp/ymir/taskReporter/core/ReportSet.scala index b27af43..6285589 100644 --- a/src/main/scala/jp/ymir/taskReporter/core/ReportSet.scala +++ b/src/main/scala/jp/ymir/taskReporter/core/ReportSet.scala @@ -13,10 +13,7 @@ class ReportSet(private var _file: Option[File]) private var _reports : SortedMap[Calendar, Report] = TreeMap() private var _dirty = false - _file match { - case Some(file) => load(file) - case None => - } + _file.foreach { file => load(file) } def load(file: File) { var reports = _reports.empty @@ -45,6 +42,10 @@ class ReportSet(private var _file: Option[File]) def file = _file def dirty = _dirty + def apply(n: Int) : Report = + // THINKME: Any better way than this? + _reports.values.toIndexedSeq(n) + def save(file: File) { _file = Some(file); save } @@ -66,11 +67,9 @@ class ReportSet(private var _file: Option[File]) } def getValueAt(row: Int, column: Int) : Object = { - // THINKME: Any better way than this? - val report = _reports.values.toIndexedSeq(row) column match { - case 0 => report.dateString - case 1 => report.size : Integer + case 0 => this(row).dateString + case 1 => this(row).size : Integer } } } diff --git a/src/main/scala/jp/ymir/taskReporter/ui/MainFrame.scala b/src/main/scala/jp/ymir/taskReporter/ui/MainFrame.scala index 1807a06..d59493b 100644 --- a/src/main/scala/jp/ymir/taskReporter/ui/MainFrame.scala +++ b/src/main/scala/jp/ymir/taskReporter/ui/MainFrame.scala @@ -16,11 +16,19 @@ import scala.swing._ import scala.swing.event._ class MainFrame(reportFile: Option[File]) extends Frame { + frame => + private val reportSet = new ReportSet(reportFile) 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) { Preferences.mainFrameSize() = size @@ -32,7 +40,7 @@ class MainFrame(reportFile: Option[File]) extends Frame { 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 @@ -42,9 +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.load(chooser.selectedFile) - // FIXME: select the last report + val file = chooser.selectedFile + Preferences.lastChosenDir() = file.getParentFile + reportSet load file + frame publish FileOpened(file) } } }) @@ -93,7 +102,31 @@ class MainFrame(reportFile: Option[File]) extends Frame { leftComponent = new ScrollPane( new Table() { - peer.setModel(new Report()) // Empty report + 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() + } + } }) } @@ -102,13 +135,24 @@ class MainFrame(reportFile: Option[File]) extends Frame { val reportsScroll = new ScrollPane( new Table() { - peer.setModel(reportSet) - if (rowCount > 0) { - selection.rows += rowCount - 1 // Select the last report + 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) => - // FIXME + selection.rows.size match { + case 1 => + val report = reportSet(selection.rows.head) + frame publish ReportSelected(report) + case _ => + frame publish ReportDeselected() + } } }) layout(reportsScroll) = BorderPanel.Position.Center @@ -127,6 +171,11 @@ class MainFrame(reportFile: Option[File]) extends Frame { } } + reportSet.file match { + case Some(file) => frame publish FileOpened(file) + case None => frame publish ReportDeselected() + } + centerOnScreen visible = true -- 2.40.0