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)
+ }
}
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
+ }
+ }
}
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
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()
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)
}
}
})
}
}
- 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
}
Preferences.lastChosenDir() = chooser.selectedFile.getParentFile
- reportSet.file = Some(chooser.selectedFile)
+ reportSet.save(chooser.selectedFile)
+ }
+ else {
+ reportSet.save
}
-
- reportSet.save
}
}