1 17 package org.columba.core.gui.dialog; 18 19 import java.awt.BorderLayout ; 20 import java.awt.Dialog ; 21 import java.awt.GridLayout ; 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.util.Calendar ; 25 import java.util.Date ; 26 27 import javax.swing.BorderFactory ; 28 import javax.swing.JButton ; 29 import javax.swing.JDialog ; 30 import javax.swing.JPanel ; 31 32 import org.columba.core.gui.base.ButtonWithMnemonic; 33 import org.columba.core.gui.base.DateChooser; 34 import org.columba.core.resourceloader.GlobalResourceLoader; 35 36 39 40 public class DateChooserDialog extends JDialog implements ActionListener { 41 protected DateChooser dateChooser; 42 43 protected JButton okButton; 44 protected JButton cancelButton; 45 protected JPanel panel; 46 47 protected boolean success = false; 48 49 protected JDialog dialog; 50 51 public DateChooserDialog(JDialog parent) { 52 super(parent, true); 53 54 setTitle("Choose Date..."); 56 57 dateChooser = new DateChooser(); 58 59 panel = new JPanel (); 60 panel.setLayout(new BorderLayout ()); 61 62 getContentPane().add(panel, BorderLayout.CENTER); 63 64 panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); 65 66 panel.add(dateChooser, BorderLayout.CENTER); 67 68 JPanel bottomPanel = new JPanel (); 69 70 76 bottomPanel.setLayout(new BorderLayout ()); 77 bottomPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); 78 79 JPanel buttonPanel = new JPanel (); 80 buttonPanel.setLayout(new GridLayout (1, 2, 10, 10)); 81 bottomPanel.add(buttonPanel, BorderLayout.EAST); 82 83 cancelButton = new ButtonWithMnemonic(GlobalResourceLoader.getString( 84 "global", "global", "cancel")); 85 cancelButton.setActionCommand("CANCEL"); 86 cancelButton.addActionListener(this); 87 okButton = new ButtonWithMnemonic(GlobalResourceLoader.getString("global", 88 "global", "ok")); 89 okButton.setActionCommand("OK"); 90 okButton.addActionListener(this); 91 92 buttonPanel.add(cancelButton); 93 buttonPanel.add(okButton); 94 95 panel.add(bottomPanel, BorderLayout.SOUTH); 96 97 pack(); 98 99 100 setLocationRelativeTo(null); 101 } 102 103 public Date getDate() { 104 return dateChooser.getSelectedDate().getTime(); 105 } 106 107 public void setDate(Date d) { 108 Calendar c = Calendar.getInstance(); 109 c.setTime(d); 110 dateChooser.setSelectedDate(c); 111 } 112 113 public boolean success() { 114 return success; 115 } 116 117 public void actionPerformed(ActionEvent ev) { 118 String action = ev.getActionCommand(); 119 120 if (action.equals("OK")) { 121 success = true; 122 setVisible(false); 123 } else if (action.equals("CANCEL")) { 124 success = false; 125 setVisible(false); 126 } 127 } 128 } 129 | Popular Tags |