001: package net.sf.borg.ui.util;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Dimension;
005: import java.awt.FlowLayout;
006: import java.awt.Frame;
007: import java.awt.GridLayout;
008: import java.awt.event.ActionEvent;
009: import java.awt.event.ActionListener;
010: import java.awt.event.KeyEvent;
011: import java.util.Calendar;
012:
013: import javax.swing.JButton;
014: import javax.swing.JComponent;
015: import javax.swing.JDialog;
016: import javax.swing.JLabel;
017: import javax.swing.JPanel;
018: import javax.swing.KeyStroke;
019:
020: import net.sf.borg.ui.ResourceHelper;
021:
022: import com.toedter.calendar.JDateChooser;
023:
024: public class DateDialog extends JDialog {
025: public DateDialog(Frame frmParent) {
026: super (frmParent, "Enter Date", true);
027: initUI();
028: }
029:
030: // Accessors
031: public final Calendar getCalendar() {
032: return calendar;
033: }
034:
035: // Modifiers
036: public final void setCalendar(Calendar cal) {
037: dateComboBox.setCalendar(cal);
038: }
039:
040: // private //
041: private JDateChooser dateComboBox;
042: private Calendar calendar;
043:
044: private void initUI() {
045: initCtrls();
046: pack();
047:
048: // Make it a little wider
049: Dimension dim = getSize();
050: dim.width += 40;
051: setSize(dim);
052: setLocationRelativeTo(null);
053: }
054:
055: private void initCtrls() {
056: JPanel pnlMain = new JPanel();
057: getContentPane().add(pnlMain);
058: pnlMain.setLayout(new BorderLayout());
059:
060: JPanel pnlInputAndIcon = new JPanel();
061: pnlMain.add(pnlInputAndIcon, BorderLayout.CENTER);
062: pnlInputAndIcon.setLayout(new BorderLayout());
063:
064: JPanel pnlInput = new JPanel();
065: pnlInputAndIcon.add(pnlInput, BorderLayout.CENTER);
066: pnlInput.setLayout(new BorderLayout());
067:
068: JPanel pnlIcon = new JPanel();
069: pnlInputAndIcon.add(pnlIcon, BorderLayout.WEST);
070: pnlIcon.setLayout(new BorderLayout());
071: // pnlIcon.add(new JLabel(new ImageIcon(getClass().getResource("/resource/borg.jpg"))));
072:
073: JPanel pnlFields = new JPanel();
074: pnlInput.add(pnlFields, BorderLayout.CENTER);
075: pnlFields.setLayout(new GridLayout(0, 1));
076: pnlFields.add(dateComboBox = new JDateChooser());
077:
078: JPanel pnlLabels = new JPanel();
079: pnlInput.add(pnlLabels, BorderLayout.WEST);
080: pnlLabels.setLayout(new GridLayout(0, 1));
081:
082: JLabel lblDate;
083: pnlLabels.add(lblDate = new JLabel());
084:
085: ResourceHelper.setText(lblDate, "Date");
086: lblDate.setLabelFor(dateComboBox);
087: lblDate.setText(lblDate.getText() + ":");
088:
089: JPanel pnlButtons = new JPanel();
090: pnlButtons.setLayout(new FlowLayout(FlowLayout.CENTER));
091: pnlMain.add(pnlButtons, BorderLayout.SOUTH);
092: JButton bn;
093: pnlButtons.add(bn = new JButton("OK"));
094: getRootPane().setDefaultButton(bn);
095: bn.addActionListener(new ActionListener() {
096: public void actionPerformed(ActionEvent e) {
097: calendar = dateComboBox.getCalendar();
098: setVisible(false);
099: }
100: });
101:
102: pnlButtons.add(bn = new JButton("Cancel"));
103: ActionListener cancelListener = new ActionListener() {
104: public void actionPerformed(ActionEvent e) {
105: calendar = null;
106: setVisible(false);
107: }
108: };
109: bn.addActionListener(cancelListener);
110: getRootPane().registerKeyboardAction(cancelListener,
111: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
112: JComponent.WHEN_IN_FOCUSED_WINDOW);
113: }
114: }
|