X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=src%2Fmain%2Fscala%2Fjp%2Fymir%2FtaskReporter%2Fui%2FMainFrame.scala;h=da35f395a362576526e0a7444c7a9cd238fa397b;hb=48fca3f185c25534d4e58e4f4e379d65bb1ab6ad;hp=957afae23826dbf8ee6b8ba8e84b273cbd58e9ab;hpb=520a3f6ce5c36e933bfe6dd3977fa157aa506d05;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 957afae..da35f39 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,11 +16,19 @@ import scala.swing._ import scala.swing.event._ class MainFrame(reportFile: Option[File]) extends Frame { - private var reportSet = new ReportSet(reportFile) + 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 @@ -31,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 @@ -41,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 = new ReportSet(Some(chooser.selectedFile)) + val file = chooser.selectedFile + Preferences.lastChosenDir() = file.getParentFile + reportSet load file + frame publish FileOpened(file) } } }) @@ -79,24 +90,98 @@ 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 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 + } - 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 = + 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() + } + } + }) +/* rightComponent = new BoxPanel(Orientation.Vertical) { + contents += new TaskEditor { + border = BorderFactory.createEmptyBorder(5, 5, 5, 5) } + */ + rightComponent = new TaskEditor { + border = BorderFactory.createEmptyBorder(5, 5, 5, 5) } - layout(scroll) = BorderPanel.Position.Center } + + leftComponent = new BorderPanel { + border = BorderFactory.createEmptyBorder(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("Add") { + def apply = {} // FIXME + }) + contents += new Button(new Action("Delete...") { + def apply = {} // FIXME + }) + }, BorderPanel.Position.South) + + preferredSize = minimumSize + } + } + + reportSet.file match { + case Some(file) => frame publish FileOpened(file) + case None => frame publish ReportDeselected() } centerOnScreen @@ -149,9 +234,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 } }