001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * JDateTimePicker.java
028: *
029: * Created on August 30, 2006, 12:33 PM
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.prompt;
034:
035: import it.businesslogic.ireport.util.I18n;
036: import it.businesslogic.ireport.util.LanguageChangedEvent;
037: import it.businesslogic.ireport.util.LanguageChangedListener;
038: import java.awt.BorderLayout;
039: import java.util.GregorianCalendar;
040: import java.util.Locale;
041: import javax.swing.SpinnerNumberModel;
042:
043: /**
044: *
045: * @author gtoffoli
046: */
047: public class JDateTimePicker extends javax.swing.JPanel implements
048: LanguageChangedListener {
049:
050: private Locale locale = null;
051: private com.michaelbaranov.microba.calendar.DatePicker datePicker = null;
052:
053: /** Creates new form NewJPanel */
054: public JDateTimePicker() {
055: initComponents();
056:
057: jSpinnerH.setModel(new javax.swing.SpinnerNumberModel(0, 0, 23,
058: 1));
059: jSpinnerM.setModel(new javax.swing.SpinnerNumberModel(0, 0, 59,
060: 1));
061: jSpinnerS.setModel(new javax.swing.SpinnerNumberModel(0, 0, 59,
062: 1));
063:
064: datePicker = new com.michaelbaranov.microba.calendar.DatePicker();
065: jPanel1.add(datePicker, BorderLayout.CENTER);
066: setLocale(I18n.getCurrentLocale());
067: setDate(new java.util.Date());
068:
069: it.businesslogic.ireport.util.I18n
070: .addOnLanguageChangedListener(this );
071: applyI18n();
072: }
073:
074: public void setLocale(Locale locale) {
075: this .locale = locale;
076: datePicker.setLocale(locale);
077: }
078:
079: public Locale getLocale() {
080: return locale;
081: }
082:
083: public void setDate(java.util.Date d) {
084: if (d == null)
085: return;
086: GregorianCalendar gc = null;
087:
088: if (getLocale() != null)
089: gc = new GregorianCalendar(getLocale());
090: else
091: gc = new GregorianCalendar();
092:
093: gc.setTime(d);
094:
095: jSpinnerH.setValue(new Integer(gc.get(gc.HOUR_OF_DAY)));
096: jSpinnerM.setValue(new Integer(gc.get(gc.MINUTE)));
097: jSpinnerS.setValue(new Integer(gc.get(gc.SECOND)));
098: try {
099: datePicker.setDate(d);
100: } catch (Exception ex) {
101:
102: }
103: }
104:
105: public java.util.Date getDate() {
106: if (datePicker.getDate() == null)
107: return null;
108: GregorianCalendar gc = new GregorianCalendar();
109: gc.setTime(datePicker.getDate());
110: gc.set(gc.HOUR_OF_DAY, ((SpinnerNumberModel) jSpinnerH
111: .getModel()).getNumber().intValue());
112: gc.set(gc.MINUTE, ((SpinnerNumberModel) jSpinnerM.getModel())
113: .getNumber().intValue());
114: gc.set(gc.MINUTE, ((SpinnerNumberModel) jSpinnerS.getModel())
115: .getNumber().intValue());
116:
117: return gc.getTime();
118: }
119:
120: public void languageChanged(LanguageChangedEvent evt) {
121: applyI18n();
122: }
123:
124: public void applyI18n() {
125: // Start autogenerated code ----------------------
126: jLabelMin.setText(I18n.getString("jDateTimePicker.labelMin",
127: ":"));
128: jLabelSec.setText(I18n.getString("jDateTimePicker.labelSec",
129: ":"));
130: // End autogenerated code ----------------------
131: jLabelH.setText(it.businesslogic.ireport.util.I18n.getString(
132: "time_picker", "Time"));
133: }
134:
135: /** This method is called from within the constructor to
136: * initialize the form.
137: * WARNING: Do NOT modify this code. The content of this method is
138: * always regenerated by the Form Editor.
139: */
140: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
141: private void initComponents() {
142: java.awt.GridBagConstraints gridBagConstraints;
143:
144: jPanel1 = new javax.swing.JPanel();
145: jLabelH = new javax.swing.JLabel();
146: jSpinnerH = new javax.swing.JSpinner();
147: jLabelMin = new javax.swing.JLabel();
148: jSpinnerM = new javax.swing.JSpinner();
149: jLabelSec = new javax.swing.JLabel();
150: jSpinnerS = new javax.swing.JSpinner();
151:
152: setLayout(new java.awt.GridBagLayout());
153:
154: setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1,
155: 1));
156: jPanel1.setLayout(new java.awt.BorderLayout());
157:
158: jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(
159: 1, 1, 1, 1));
160: gridBagConstraints = new java.awt.GridBagConstraints();
161: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
162: gridBagConstraints.weightx = 1.0;
163: gridBagConstraints.weighty = 1.0;
164: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
165: add(jPanel1, gridBagConstraints);
166:
167: jLabelH.setText("Time");
168: gridBagConstraints = new java.awt.GridBagConstraints();
169: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 2);
170: add(jLabelH, gridBagConstraints);
171:
172: jSpinnerH.setMinimumSize(new java.awt.Dimension(35, 18));
173: jSpinnerH.setPreferredSize(new java.awt.Dimension(35, 18));
174: add(jSpinnerH, new java.awt.GridBagConstraints());
175:
176: jLabelMin.setText(":");
177: gridBagConstraints = new java.awt.GridBagConstraints();
178: gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
179: add(jLabelMin, gridBagConstraints);
180:
181: jSpinnerM.setMinimumSize(new java.awt.Dimension(35, 18));
182: jSpinnerM.setPreferredSize(new java.awt.Dimension(35, 18));
183: add(jSpinnerM, new java.awt.GridBagConstraints());
184:
185: jLabelSec.setText(":");
186: gridBagConstraints = new java.awt.GridBagConstraints();
187: gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
188: add(jLabelSec, gridBagConstraints);
189:
190: jSpinnerS.setMinimumSize(new java.awt.Dimension(35, 18));
191: jSpinnerS.setPreferredSize(new java.awt.Dimension(35, 18));
192: add(jSpinnerS, new java.awt.GridBagConstraints());
193:
194: }// </editor-fold>//GEN-END:initComponents
195:
196: // Variables declaration - do not modify
197: //GEN-BEGIN:variables
198: private javax.swing.JLabel jLabelH;
199: private javax.swing.JLabel jLabelMin;
200: private javax.swing.JLabel jLabelSec;
201: private javax.swing.JPanel jPanel1;
202: private javax.swing.JSpinner jSpinnerH;
203: private javax.swing.JSpinner jSpinnerM;
204: private javax.swing.JSpinner jSpinnerS;
205: // End of variables declaration//GEN-END:variables
206:
207: }
|