X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=src%2Fmain%2Fscala%2Fjp%2Fymir%2FtaskReporter%2Fui%2FMainFrame.scala;h=3878d21e65186afee95c4771c5b9208da51a416a;hb=HEAD;hp=94897af964a7dd3920c1286603d7eca46034705f;hpb=79bcb816daaaa042ec7f1855c8307d9143f61956;p=task-reporter.git diff --git a/src/main/scala/jp/ymir/taskReporter/ui/MainFrame.scala b/src/main/scala/jp/ymir/taskReporter/ui/MainFrame.scala index 94897af..3878d21 100644 --- a/src/main/scala/jp/ymir/taskReporter/ui/MainFrame.scala +++ b/src/main/scala/jp/ymir/taskReporter/ui/MainFrame.scala @@ -3,7 +3,6 @@ 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 @@ -13,14 +12,23 @@ 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 { + 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,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.load(chooser.selectedFile) + val file = chooser.selectedFile + Preferences.lastChosenDir() = file.getParentFile + reportSet load file + frame publish FileOpened(file) } } }) @@ -78,26 +88,107 @@ class MainFrame(reportFile: Option[File]) extends Frame { } } - val rootSplit = new SplitPane { + contents = new SplitPane { peer.setOrientation(JSplitPane.HORIZONTAL_SPLIT) continuousLayout = true oneTouchExpandable = true - resizeWeight = 0.3 + resizeWeight = 0 // Let the left pane be fixed - leftComponent = new BorderPanel { - border = BorderFactory.createEmptyBorder(5, 5, 5, 5) + rightComponent = new BoxPanel(Orientation.Vertical) { + border = EmptyBorder(5, 5, 5, 5) - val scroll = new ScrollPane( + contents += new ScrollPane( new Table() { - peer.setModel(reportSet) + 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() + } + } }) - layout(scroll) = BorderPanel.Position.Center + contents += VStrut(5) + contents += new TaskEditor { + listenTo(frame) + reactions += { + case TaskSelected(t) => task = t + case TaskDeselected() => task = Task() + } + } + 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 { + 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 } } - contents = rootSplit - // This can only be done after putting the pane on the frame. - rootSplit.dividerLocation = 0.3 + reportSet.file match { + case Some(file) => frame publish FileOpened(file) + case None => frame publish ReportDeselected() + } centerOnScreen visible = true