KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > designer > view > DateInputView


1 /*
2  * (c) Rob Gordon 2005.
3  */

4 package org.oddjob.designer.view;
5
6 import java.awt.Component JavaDoc;
7 import java.awt.Container JavaDoc;
8 import java.awt.GridBagConstraints JavaDoc;
9 import java.awt.GridBagLayout JavaDoc;
10 import java.awt.Insets JavaDoc;
11
12 import javax.swing.JLabel JavaDoc;
13 import javax.swing.JPanel JavaDoc;
14 import javax.swing.SwingConstants JavaDoc;
15 import javax.swing.event.ChangeEvent JavaDoc;
16 import javax.swing.event.ChangeListener JavaDoc;
17
18 import net.sf.nachocalendar.CalendarFactory;
19 import net.sf.nachocalendar.components.DatePanel;
20
21 import org.oddjob.designer.Looks;
22 import org.oddjob.designer.model.DateInput;
23
24 /**
25  * Produces views for DateInput.
26  */

27 public class DateInputView implements ViewProducer {
28         
29     private final DateInput dateInput;
30     
31     private final JLabel JavaDoc label;
32     private final DatePanel datePanel;
33     
34     /**
35      * Constructor.
36      *
37      * @param di The DateInput model that this is a view on.
38      */

39     public DateInputView(DateInput di) {
40         this.dateInput = di;
41
42         String JavaDoc title = dateInput.getTitle();
43         StringBuffer JavaDoc paddedTitle = new StringBuffer JavaDoc();
44         paddedTitle.append(title);
45         for (int i = title.length(); i < Looks.LABEL_SIZE; ++i) {
46             paddedTitle.append(' ');
47         }
48         label = new JLabel JavaDoc(paddedTitle.toString(), SwingConstants.LEADING);
49                 
50         datePanel = CalendarFactory.createDatePanel();
51         if (dateInput.getDate() != null) {
52             datePanel.setDate(dateInput.getDate());
53         }
54         datePanel.addChangeListener(new ChangeListener JavaDoc() {
55             public void stateChanged(ChangeEvent JavaDoc e) {
56                 dateInput.setDate(datePanel.getDate());
57             }
58         });
59     }
60     
61     /*
62      * (non-Javadoc)
63      * @see org.oddjob.designer.view.ViewProducer#dialog()
64      */

65     public Component JavaDoc dialog() {
66         return group();
67     }
68     
69     /*
70      * (non-Javadoc)
71      * @see org.oddjob.designer.view.ViewProducer#group()
72      */

73     public Component JavaDoc group() {
74         JPanel JavaDoc form = new JPanel JavaDoc();
75         form.setLayout(new GridBagLayout JavaDoc());
76         form.setBorder(Looks.groupBorder(dateInput.getTitle()));
77         
78         form.add(datePanel);
79         return form;
80     }
81
82     /* (non-Javadoc)
83      * @see org.oddjob.designer.view.ViewProducer#detailEdit(org.oddjob.designer.view.ActionWrapper)
84      */

85     public Component JavaDoc detailEdit() {
86         return ViewHelper.createDetailButton(dateInput);
87     }
88     
89     
90     public Component JavaDoc cell() {
91         return datePanel;
92     }
93     
94     /* (non-Javadoc)
95      * @see org.oddjob.designer.view.ViewProducer#inline(java.awt.Container, int, int, boolean)
96      */

97     public int inline(Container JavaDoc container, int row, int column,
98             boolean selectionInGroup) {
99         int columnCount = column;
100         
101         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
102
103         c.weightx = 1.0;
104         c.weighty = 0.0;
105         
106         c.fill = GridBagConstraints.HORIZONTAL;
107         c.anchor = GridBagConstraints.NORTHWEST;
108         c.gridx = columnCount++;
109         c.gridy = row;
110         if (selectionInGroup) {
111             c.gridwidth = 2;
112             columnCount++;
113         }
114         
115         c.insets = new Insets JavaDoc(3, 3, 3, 20);
116
117         container.add(label, c);
118         
119         c.fill = GridBagConstraints.HORIZONTAL;
120         c.anchor = GridBagConstraints.NORTHEAST;
121         c.gridx = columnCount++;
122         c.gridwidth = 1;
123         c.insets = new Insets JavaDoc(3, 0, 3, 0);
124         
125 // container.add(dateField, c);
126

127         return row + 1;
128     }
129
130     /* (non-Javadoc)
131      * @see org.oddjob.designer.view.ViewProducer#setEnabled(boolean)
132      */

133     public void setEnabled(boolean enabled) {
134         datePanel.setEnabled(enabled);
135         if (!enabled) {
136             dateInput.setDate(null);
137         }
138     }
139     
140 }
141
Popular Tags