01: package org.dbbrowser.ui.helper.exporthelper.wizard.panel;
02:
03: import infrastructure.internationalization.InternationalizationManager;
04: import java.awt.BorderLayout;
05: import java.awt.event.ActionEvent;
06: import java.awt.event.ActionListener;
07: import java.text.DateFormat;
08: import java.text.SimpleDateFormat;
09: import javax.swing.BorderFactory;
10: import javax.swing.JComboBox;
11: import javax.swing.JPanel;
12: import org.dbbrowser.ui.UIControllerForQueries;
13:
14: public class DateFormatWizardPanel extends AbstractWizardPanel
15: implements ActionListener {
16: private static final long serialVersionUID = UIControllerForQueries.version;
17: private static final String PANEL_TITLE = InternationalizationManager
18: .getInstance()
19: .getMessage(
20: "dbbrowser-export-wizard",
21: "dbbrowser-ui-export-wizard-date-format-panel-title",
22: null);;
23: private JComboBox comboBoxForDateFormats = null;
24: private static final ExportWizardSimpleDateFormat[] dateFormats = new ExportWizardSimpleDateFormat[] {
25: new ExportWizardSimpleDateFormat("dd/MM/yyyy HH:mm a"),
26: new ExportWizardSimpleDateFormat("yyyy-MM-dd"),
27: new ExportWizardSimpleDateFormat("dd-MM-yyyy"),
28: new ExportWizardSimpleDateFormat("dd/MM/yyyy"),
29: new ExportWizardSimpleDateFormat("MM/dd/yyyy"),
30: new ExportWizardSimpleDateFormat("MM-dd-yyyy"),
31: new ExportWizardSimpleDateFormat("MM/dd/yyyy HH:mm a"),
32: new ExportWizardSimpleDateFormat("MM-dd-yyyy HH:mm a") };
33: private String dateFormatPattern = "";
34:
35: /**
36: * Constrcuter
37: * @param wizard
38: */
39: public DateFormatWizardPanel() {
40: super (PANEL_TITLE);
41: this .add(setupPanel(), BorderLayout.CENTER);
42: }
43:
44: private JPanel setupPanel() {
45: JPanel panel = new JPanel();
46: panel.setBorder(BorderFactory.createEtchedBorder());
47: panel.setLayout(new BorderLayout());
48:
49: //Setup the combo box
50: comboBoxForDateFormats = new JComboBox(dateFormats);
51: comboBoxForDateFormats.setEditable(false);
52: comboBoxForDateFormats.addActionListener(this );
53:
54: //Store the first date format as default
55: this .dateFormatPattern = dateFormats[0].toString();
56:
57: //Add the combo box
58: panel.add(comboBoxForDateFormats, BorderLayout.NORTH);
59:
60: return panel;
61: }
62:
63: public void actionPerformed(ActionEvent e) {
64: this .dateFormatPattern = dateFormats[this .comboBoxForDateFormats
65: .getSelectedIndex()].toString();
66: }
67:
68: public String getDateFormatPattern() {
69: return this .dateFormatPattern;
70: }
71:
72: /**
73: * Private class to represent a date format - overrides toString method to return the pattern used to format/parse dates
74: * @author amangat
75: */
76: private static class ExportWizardSimpleDateFormat {
77: private String pattern = null;
78: private DateFormat dateFormat = null;
79:
80: public ExportWizardSimpleDateFormat(String pattern) {
81: this .pattern = pattern;
82: this .dateFormat = new SimpleDateFormat(pattern);
83: }
84:
85: public String toString() {
86: return this .pattern;
87: }
88:
89: public DateFormat getSimpleDateFormat() {
90: return this.dateFormat;
91: }
92: }
93: }
|