]> gitweb @ CieloNegro.org - task-reporter.git/blob - src/main/scala/jp/ymir/taskReporter/ui/TaskEditor.scala
wip
[task-reporter.git] / src / main / scala / jp / ymir / taskReporter / ui / TaskEditor.scala
1 package jp.ymir.taskReporter.ui
2 import java.awt.Insets
3 import java.util.Calendar
4 import jp.ymir.taskReporter.core._
5 import scala.collection.immutable._
6 import scala.swing._
7 import scala.swing.event._
8
9 class TaskEditor extends GridBagPanel {
10   import GridBagPanel._
11
12   case class TaskUpdated(t: Task) extends Event
13
14   def task: (Calendar => Task) = d => Task(
15     date                   = d,
16     ticketID               = noneIfEmpty(ticketID.text).map(_.toInt),
17     title                  = title.text,
18     expectedCompletionDate = expectedCompletionDate.calendar.getOrElse(Task.endOfCurrentHalf),
19     deadline               = deadline.calendar,
20     status                 = status.selection.item,
21     description            = noneIfEmpty(description.text)
22   )
23
24   def task_=(t: Task) = {
25     ticketID.text                   = t.ticketID.fold("")(_.toString)
26     title.text                      = t.title
27     expectedCompletionDate.calendar = Some(t.expectedCompletionDate)
28     deadline.calendar               = t.deadline
29     status.selection.item           = t.status
30     description.text                = t.description.getOrElse("")
31   }
32
33   private val commonInsets = new Insets(2, 3, 2, 3)
34
35   private def noneIfEmpty[T <% StringLike[_]](str: T): Option[T] = str match {
36     case "" => None
37     case _  => Some(str)
38   }
39
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)
45   }
46   add(
47     new Label("チケットID"),
48     new Constraints { gridx = 0; gridy = 0 })
49   add(
50     ticketID,
51     new Constraints() {
52       gridx = 1; gridy = 0; anchor = Anchor.West; insets = commonInsets
53     })
54   ticketID.minimumSize = ticketID.preferredSize
55
56   private val title = new TextField() {
57     peer.setMargin(commonInsets)
58   }
59   add(
60     new Label("作業名"),
61     new Constraints { gridx = 0; gridy = 1 })
62   add(
63     title,
64     new Constraints() {
65       gridx = 1; gridy = 1; fill = Fill.Horizontal; weightx = 1.0
66       insets = commonInsets
67     })
68
69   private val expectedCompletionDate = new DateChooser {
70     dateFormatString = "yyyy-MM-dd"
71     calendarChooser.todayButtonVisible = true
72     calendarChooser.weekOfYearVisible  = false
73   }
74   add(
75     new Label("作業完了予定年月日"),
76     new Constraints { gridx = 0; gridy = 2 })
77   add(
78     expectedCompletionDate,
79     new Constraints() {
80       gridx = 1; gridy = 2; anchor = Anchor.West
81       ipadx = 3; ipady = 2; insets = commonInsets
82     })
83   expectedCompletionDate.minimumSize = expectedCompletionDate.preferredSize
84
85   private val deadline = new DateChooser {
86     dateFormatString = "yyyy-MM-dd"
87     calendarChooser.nullDateButtonVisible = true
88     calendarChooser.todayButtonVisible    = true
89     calendarChooser.weekOfYearVisible     = false
90   }
91   add(
92     new Label("タスク期限"),
93     new Constraints { gridx = 0; gridy = 3 })
94   add(
95     deadline,
96     new Constraints() {
97       gridx = 1; gridy = 3; anchor = Anchor.West
98       ipadx = 3; ipady = 3; insets = commonInsets
99     })
100   deadline.minimumSize = deadline.preferredSize
101
102   private val status = new ComboBox[Task.Status](Task.Status.all)
103   add(
104     new Label("状態"),
105     new Constraints { gridx = 0; gridy = 4 })
106   add(
107     status,
108     new Constraints {
109       gridx = 1; gridy = 4; anchor = Anchor.West
110       ipadx = 3; ipady = 3; insets = commonInsets
111     })
112
113   private val description = new TextArea() {
114     rows = 5
115     peer.setMargin(commonInsets)
116   }
117   private val scrollingDescription = new ScrollPane(description)
118   add(
119     new Label("説明"),
120     new Constraints { gridx = 0; gridy = 5 })
121   add(
122     scrollingDescription,
123     new Constraints() {
124       gridx = 1; gridy = 5; fill = Fill.Horizontal; weightx = 1.0
125       insets = commonInsets
126     })
127   scrollingDescription.minimumSize = scrollingDescription.preferredSize
128 }