1 4 package org.oddjob.designer.view; 5 6 import java.awt.Component ; 7 import java.awt.Container ; 8 import java.awt.GridBagConstraints ; 9 import java.awt.GridBagLayout ; 10 import java.awt.Insets ; 11 12 import javax.swing.JLabel ; 13 import javax.swing.JPanel ; 14 import javax.swing.SwingConstants ; 15 import javax.swing.event.ChangeEvent ; 16 import javax.swing.event.ChangeListener ; 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 27 public class DateInputView implements ViewProducer { 28 29 private final DateInput dateInput; 30 31 private final JLabel label; 32 private final DatePanel datePanel; 33 34 39 public DateInputView(DateInput di) { 40 this.dateInput = di; 41 42 String title = dateInput.getTitle(); 43 StringBuffer paddedTitle = new StringBuffer (); 44 paddedTitle.append(title); 45 for (int i = title.length(); i < Looks.LABEL_SIZE; ++i) { 46 paddedTitle.append(' '); 47 } 48 label = new JLabel (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 () { 55 public void stateChanged(ChangeEvent e) { 56 dateInput.setDate(datePanel.getDate()); 57 } 58 }); 59 } 60 61 65 public Component dialog() { 66 return group(); 67 } 68 69 73 public Component group() { 74 JPanel form = new JPanel (); 75 form.setLayout(new GridBagLayout ()); 76 form.setBorder(Looks.groupBorder(dateInput.getTitle())); 77 78 form.add(datePanel); 79 return form; 80 } 81 82 85 public Component detailEdit() { 86 return ViewHelper.createDetailButton(dateInput); 87 } 88 89 90 public Component cell() { 91 return datePanel; 92 } 93 94 97 public int inline(Container container, int row, int column, 98 boolean selectionInGroup) { 99 int columnCount = column; 100 101 GridBagConstraints c = new GridBagConstraints (); 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 (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 (3, 0, 3, 0); 124 125 127 return row + 1; 128 } 129 130 133 public void setEnabled(boolean enabled) { 134 datePanel.setEnabled(enabled); 135 if (!enabled) { 136 dateInput.setDate(null); 137 } 138 } 139 140 } 141 | Popular Tags |