001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016:
017: package org.columba.core.gui.dialog;
018:
019: import java.awt.BorderLayout;
020: import java.awt.Dialog;
021: import java.awt.GridLayout;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import java.util.Calendar;
025: import java.util.Date;
026:
027: import javax.swing.BorderFactory;
028: import javax.swing.JButton;
029: import javax.swing.JDialog;
030: import javax.swing.JPanel;
031:
032: import org.columba.core.gui.base.ButtonWithMnemonic;
033: import org.columba.core.gui.base.DateChooser;
034: import org.columba.core.resourceloader.GlobalResourceLoader;
035:
036: /**
037: * @author fdietz
038: */
039:
040: public class DateChooserDialog extends JDialog implements
041: ActionListener {
042: protected DateChooser dateChooser;
043:
044: protected JButton okButton;
045: protected JButton cancelButton;
046: protected JPanel panel;
047:
048: protected boolean success = false;
049:
050: protected JDialog dialog;
051:
052: public DateChooserDialog(JDialog parent) {
053: super (parent, true);
054:
055: //TODO (@author fdietz): i18n
056: setTitle("Choose Date...");
057:
058: dateChooser = new DateChooser();
059:
060: panel = new JPanel();
061: panel.setLayout(new BorderLayout());
062:
063: getContentPane().add(panel, BorderLayout.CENTER);
064:
065: panel
066: .setBorder(BorderFactory.createEmptyBorder(10, 10, 10,
067: 10));
068:
069: panel.add(dateChooser, BorderLayout.CENTER);
070:
071: JPanel bottomPanel = new JPanel();
072:
073: /*
074: * bottomPanel.setBorder(new WizardTopBorder()); Border border =
075: * bottomPanel.getBorder(); Border margin =
076: * BorderFactory.createEmptyBorder(15, 10, 10, 10);
077: * bottomPanel.setBorder(new CompoundBorder(border, margin));
078: */
079: bottomPanel.setLayout(new BorderLayout());
080: bottomPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0,
081: 0));
082:
083: JPanel buttonPanel = new JPanel();
084: buttonPanel.setLayout(new GridLayout(1, 2, 10, 10));
085: bottomPanel.add(buttonPanel, BorderLayout.EAST);
086:
087: cancelButton = new ButtonWithMnemonic(GlobalResourceLoader
088: .getString("global", "global", "cancel"));
089: cancelButton.setActionCommand("CANCEL");
090: cancelButton.addActionListener(this );
091: okButton = new ButtonWithMnemonic(GlobalResourceLoader
092: .getString("global", "global", "ok"));
093: okButton.setActionCommand("OK");
094: okButton.addActionListener(this );
095:
096: buttonPanel.add(cancelButton);
097: buttonPanel.add(okButton);
098:
099: panel.add(bottomPanel, BorderLayout.SOUTH);
100:
101: pack();
102:
103: setLocationRelativeTo(null);
104: }
105:
106: public Date getDate() {
107: return dateChooser.getSelectedDate().getTime();
108: }
109:
110: public void setDate(Date d) {
111: Calendar c = Calendar.getInstance();
112: c.setTime(d);
113: dateChooser.setSelectedDate(c);
114: }
115:
116: public boolean success() {
117: return success;
118: }
119:
120: public void actionPerformed(ActionEvent ev) {
121: String action = ev.getActionCommand();
122:
123: if (action.equals("OK")) {
124: success = true;
125: setVisible(false);
126: } else if (action.equals("CANCEL")) {
127: success = false;
128: setVisible(false);
129: }
130: }
131: }
|