From 79bcb816daaaa042ec7f1855c8307d9143f61956 Mon Sep 17 00:00:00 2001 From: PHO Date: Sun, 5 Oct 2014 18:32:45 +0900 Subject: [PATCH] wip --- .gitignore | 1 + .../jp/ymir/taskReporter/core/Report.scala | 9 ++- .../jp/ymir/taskReporter/core/ReportSet.scala | 59 +++++++++++++++---- .../jp/ymir/taskReporter/ui/MainFrame.scala | 41 ++++++------- 4 files changed, 78 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index eb5a316..404053b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ target +*.tsv diff --git a/src/main/scala/jp/ymir/taskReporter/core/Report.scala b/src/main/scala/jp/ymir/taskReporter/core/Report.scala index 5fa1ceb..5494260 100644 --- a/src/main/scala/jp/ymir/taskReporter/core/Report.scala +++ b/src/main/scala/jp/ymir/taskReporter/core/Report.scala @@ -1,14 +1,21 @@ package jp.ymir.taskReporter.core import java.util.Calendar +import java.text.SimpleDateFormat import scala.collection.immutable._ class Report(private val _date: Calendar) { private var _tasks : Seq[Task] = Vector() - def date = _date + def date : Calendar = _date + def size : Int = _tasks.size def +=(task: Task) { require(task.date == _date) _tasks = _tasks :+ task } + + def dateString : String = { + val fmt = new SimpleDateFormat("yyyy-MM-dd") + fmt.format(_date.getTime) + } } diff --git a/src/main/scala/jp/ymir/taskReporter/core/ReportSet.scala b/src/main/scala/jp/ymir/taskReporter/core/ReportSet.scala index 0bbd672..f90071d 100644 --- a/src/main/scala/jp/ymir/taskReporter/core/ReportSet.scala +++ b/src/main/scala/jp/ymir/taskReporter/core/ReportSet.scala @@ -1,38 +1,75 @@ package jp.ymir.taskReporter.core import java.io._ import java.util.Calendar +import javax.swing.table.AbstractTableModel import jp.ymir.taskReporter.core._ import scala.collection.immutable._ import scala.io._ -class ReportSet(private var _file: Option[File]) { - private var _dirty = false +class ReportSet(private var _file: Option[File]) + extends AbstractTableModel { + private var _reports : SortedMap[Calendar, Report] = TreeMap() + private var _dirty = false + + _file match { + case Some(file) => load(file) + case None => + } + + def load(file: File) { + var reports = _reports.empty + val src = Source.fromFile(file, "UTF-8") - if (!_file.isEmpty) { - val src = Source.fromFile(_file.get, "UTF-8") for (line <- src.getLines) { if (!line.isEmpty) { val task = new Task(line) - if (_reports.isDefinedAt(task.date)) { - _reports(task.date) += task + if (reports.isDefinedAt(task.date)) { + reports(task.date) += task } else { val report = new Report(task.date) - report += task - _reports = _reports + (report.date -> report) + report += task + reports += (report.date -> report) } } } - } - def file = _file - def file_=(f: Option[File]) { _file = f } + _file = Some(file) + _reports = reports + _dirty = false + fireTableDataChanged + } + def file = _file def dirty = _dirty + def save(file: File) { + _file = Some(file); save + } def save { // FIXME _dirty = false } + + /* Method definitions for AbstractTableModel + */ + def getColumnCount = 2 + def getRowCount = _reports.size + + override def getColumnName(column: Int) : String = { + column match { + case 0 => "Date" + case 1 => "# Tasks" + } + } + + 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 + } + } } diff --git a/src/main/scala/jp/ymir/taskReporter/ui/MainFrame.scala b/src/main/scala/jp/ymir/taskReporter/ui/MainFrame.scala index 957afae..94897af 100644 --- a/src/main/scala/jp/ymir/taskReporter/ui/MainFrame.scala +++ b/src/main/scala/jp/ymir/taskReporter/ui/MainFrame.scala @@ -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,7 +16,7 @@ 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 preferredSize = Preferences.mainFrameSize() @@ -42,7 +43,7 @@ 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) } } }) @@ -77,27 +78,26 @@ class MainFrame(reportFile: Option[File]) extends Frame { } } - contents = new SplitPane { + val rootSplit = new SplitPane { peer.setOrientation(JSplitPane.HORIZONTAL_SPLIT) - resizeWeight = 0.3 + continuousLayout = true + oneTouchExpandable = true + resizeWeight = 0.3 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 scroll = new ScrollPane( + new Table() { + peer.setModel(reportSet) + }) layout(scroll) = BorderPanel.Position.Center } } + contents = rootSplit + + // This can only be done after putting the pane on the frame. + rootSplit.dividerLocation = 0.3 centerOnScreen visible = true @@ -149,9 +149,10 @@ class MainFrame(reportFile: Option[File]) extends Frame { } Preferences.lastChosenDir() = chooser.selectedFile.getParentFile - reportSet.file = Some(chooser.selectedFile) + reportSet.save(chooser.selectedFile) + } + else { + reportSet.save } - - reportSet.save } } -- 2.40.0