1 package jp.ymir.taskReporter.ui
3 import java.util.Calendar
4 import jp.ymir.taskReporter.core._
5 import scala.collection.immutable._
7 import scala.swing.event._
9 class TaskEditor extends GridBagPanel {
12 case class TaskUpdated(t: Task) extends Event
14 def task: (Calendar => Task) = d => Task(
16 ticketID = noneIfEmpty(ticketID.text).map(_.toInt),
18 expectedCompletionDate = expectedCompletionDate.calendar.getOrElse(Task.endOfCurrentHalf),
19 deadline = deadline.calendar,
20 status = status.selection.item,
21 description = noneIfEmpty(description.text)
24 def task_=(t: Task) = {
25 ticketID.text = t.ticketID.fold("")(_.toString)
27 expectedCompletionDate.calendar = Some(t.expectedCompletionDate)
28 deadline.calendar = t.deadline
29 status.selection.item = t.status
30 description.text = t.description.getOrElse("")
33 private val commonInsets = new Insets(2, 3, 2, 3)
35 private def noneIfEmpty[T <% StringLike[_]](str: T): Option[T] = str match {
40 private val ticketID = new TextField(6) {
41 def isDigit(c : Char) = c >= '0' && c <= '9'
42 inputVerifier = _ => wrapString(text).forall(isDigit)
43 horizontalAlignment = Alignment.Right
44 peer.setMargin(commonInsets)
48 new Constraints { gridx = 0; gridy = 0 })
52 gridx = 1; gridy = 0; anchor = Anchor.West; insets = commonInsets
54 ticketID.minimumSize = ticketID.preferredSize
56 private val title = new TextField() {
57 peer.setMargin(commonInsets)
61 new Constraints { gridx = 0; gridy = 1 })
65 gridx = 1; gridy = 1; fill = Fill.Horizontal; weightx = 1.0
69 private val expectedCompletionDate = new DateChooser {
70 dateFormatString = "yyyy-MM-dd"
71 calendarChooser.todayButtonVisible = true
72 calendarChooser.weekOfYearVisible = false
75 new Label("作業完了予定年月日"),
76 new Constraints { gridx = 0; gridy = 2 })
78 expectedCompletionDate,
80 gridx = 1; gridy = 2; anchor = Anchor.West
81 ipadx = 3; ipady = 2; insets = commonInsets
83 expectedCompletionDate.minimumSize = expectedCompletionDate.preferredSize
85 private val deadline = new DateChooser {
86 dateFormatString = "yyyy-MM-dd"
87 calendarChooser.nullDateButtonVisible = true
88 calendarChooser.todayButtonVisible = true
89 calendarChooser.weekOfYearVisible = false
93 new Constraints { gridx = 0; gridy = 3 })
97 gridx = 1; gridy = 3; anchor = Anchor.West
98 ipadx = 3; ipady = 3; insets = commonInsets
100 deadline.minimumSize = deadline.preferredSize
102 private val status = new ComboBox[Task.Status](Task.Status.all)
105 new Constraints { gridx = 0; gridy = 4 })
109 gridx = 1; gridy = 4; anchor = Anchor.West
110 ipadx = 3; ipady = 3; insets = commonInsets
113 private val description = new TextArea() {
115 peer.setMargin(commonInsets)
117 private val scrollingDescription = new ScrollPane(description)
120 new Constraints { gridx = 0; gridy = 5 })
122 scrollingDescription,
124 gridx = 1; gridy = 5; fill = Fill.Horizontal; weightx = 1.0
125 insets = commonInsets
127 scrollingDescription.minimumSize = scrollingDescription.preferredSize