1 | // Copyright 2004-2007 Jean-Francois Poilpret |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | package net.sourceforge.hiveboard.dialog; |
16 | |
17 | import java.text.SimpleDateFormat; |
18 | import java.util.Date; |
19 | |
20 | import javax.swing.JFormattedTextField; |
21 | import javax.swing.JLabel; |
22 | import javax.swing.text.DateFormatter; |
23 | |
24 | import org.jdesktop.application.Action; |
25 | |
26 | import net.sourceforge.hiveboard.Board; |
27 | import net.sourceforge.hivegui.component.EmptyFormat; |
28 | |
29 | import zappini.designgridlayout.DesignGridLayout; |
30 | |
31 | public class LoadCommentsParamsPanel extends AbstractBoardPanel |
32 | { |
33 | static private final String NAME = "load-comments"; |
34 | |
35 | public LoadCommentsParamsPanel(Board board) |
36 | { |
37 | super(NAME); |
38 | |
39 | _board = board; |
40 | |
41 | _lblFrom.setName(NAME + "-from-label"); |
42 | _fromDate.setName(NAME + "-from"); |
43 | _lblUntil.setName(NAME + "-until-label"); |
44 | _untilDate.setName(NAME + "-until"); |
45 | |
46 | _lblFrom.setLabelFor(_fromDate); |
47 | _lblUntil.setLabelFor(_untilDate); |
48 | |
49 | DesignGridLayout layout = new DesignGridLayout(this); |
50 | setLayout(layout); |
51 | |
52 | layout.row().label(_lblFrom).add(_fromDate); |
53 | layout.row().label(_lblUntil).add(_untilDate); |
54 | } |
55 | |
56 | public void setDateFormat(String dateFormat) |
57 | { |
58 | _dateFormat = dateFormat; |
59 | _dateFormatter.setFormat(new EmptyFormat(new SimpleDateFormat(_dateFormat))); |
60 | } |
61 | |
62 | public Date getFromDate() |
63 | { |
64 | return _from; |
65 | } |
66 | |
67 | public Date getUntilDate() |
68 | { |
69 | return _until; |
70 | } |
71 | |
72 | @Action public void accept() |
73 | { |
74 | _from = (Date) _fromDate.getValue(); |
75 | _until = (Date) _untilDate.getValue(); |
76 | _parent.close(false); |
77 | } |
78 | |
79 | private Date _from = null; |
80 | private Date _until = null; |
81 | private final JLabel _lblFrom = new JLabel(); |
82 | private final DateFormatter _dateFormatter = new DateFormatter(); |
83 | private final JFormattedTextField _fromDate = new JFormattedTextField(_dateFormatter); |
84 | private final JLabel _lblUntil = new JLabel(); |
85 | private final JFormattedTextField _untilDate = new JFormattedTextField(_dateFormatter); |
86 | private String _dateFormat; |
87 | } |