ludc
2024-09-14 36c2449aec5b51e5ed4e5c6841154b746060e09a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
package com.vci.client.ui.date;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
 
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.UIManager;
import javax.swing.border.AbstractBorder;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.plaf.basic.BasicComboPopup;
 
import org.apache.commons.lang3.StringUtils;
 
import com.vci.client.ui.image.BundleImage;
import com.vci.client.ui.swing.components.VCIJComboBox;
 
/**
 * <p>Title: </p>
 * <p>Description: DatePopup 选择框弹出的日期选择面板</p>
 * <p>Copyright: Copyright (c) 2009</p>
 * <p>Company: VCI</p>
 * @author eddie
 * @time 2009-5-6
 * @version 1.0
 */
public class PopupCalendarPanel extends BasicComboPopup {
 
    /**
     *  
     */
    private static final long serialVersionUID = 4194644973069213593L;
    protected Calendar calendar;
    protected JLabel monthLabel;
    protected JPanel days = null;
    protected Color selectedBackground;
    protected Color selectedForeground;
    protected Color background;
    protected Color foreground;
    
    protected VCIJComboBox jcombobox = new VCIJComboBox();
    
    ImageIcon todayIcon;
    /**
     * 年月日格式
     */
    public SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
 
    /**
     * 年月格式
     */
    public SimpleDateFormat monthFormat = new SimpleDateFormat("yyyy-MM");
 
    /**
     * 日格式
     */
    public SimpleDateFormat dayFormat = new SimpleDateFormat("d");
    
    public String itemStyleValue = null;
    private JSpinner spinnerHour = null;
    private JSpinner spinnerMinute = null;
    private JSpinner spinnerSecond = null;
    private boolean hasDate = true;
    private boolean hasTime = false;
    private boolean required = false;
    private String format = "";
    private SimpleDateFormat sdfDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
    private SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
    
    public PopupCalendarPanel(VCIJComboBox box){
        this(box, true, false, false,"");//add by caill 增加了参数""
    }
 
    private SimpleDateFormat getSimpleDateFormatByInputValue(String inputValue) {
        SimpleDateFormat sdf = null;
        try {
            sdfDateTime.parse(inputValue);
            sdf = sdfDateTime;
        } catch (ParseException e) {
            try {
                sdfDate.parse(inputValue);
                sdf =  sdfDate;
            } catch (ParseException e2) {
                try {
                    sdfTime.parse(inputValue);
                    sdf =  sdfTime;
                } catch (ParseException e3) {
                }
            }
        }
        if(sdf == null){
            sdf = sdfDateTime;
        }
        return sdf;
    }
    
    public PopupCalendarPanel(VCIJComboBox box, boolean hasDate, boolean hasTime, boolean required, String itemStyle) {//add by caill 2016.2.19增加itemStyle参数用来传递附加属性的内容
        super(box);
        setHasDate(hasDate);
        setHasTime(hasTime);
        setRequired(required);
        jcombobox = box;
        todayIcon = new BundleImage().createImageIcon("today.gif");
        calendar = Calendar.getInstance();
        //add by caill start 2016.2.19  如果日期输入框中当前有值,就将此值赋给calendar;如果输入框中没有值,calendar就取当前时间为值  
        if(itemStyle != null && !itemStyle.trim().equals("")){
            String[] str = itemStyle.split(";");
            for(int i = 0;i < str.length;i++){
                if(str[i].trim().equals("minseczeroFlag=1")){ //判断附加属性中是否存在minseczeroFlag=1的字符串,如果有,则把它赋给itemStyleValue
                    itemStyleValue = str[i].trim();
                    break;
                }
            }
        }
                 
        if(jcombobox.getSelectedItem() != null){
             String preValue = jcombobox.getSelectedItem().toString();
            if (StringUtils.isBlank(preValue)) {
                calendar.setTime(new Date());
            } else {
                SimpleDateFormat formater = getSimpleDateFormatByInputValue(preValue);
 
                try {
                    // monthLabel.setText(monthFormat.format(formater.parse(preValue)));
                    calendar.setTime(formater.parse(preValue));
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        //add by caill end
        background = UIManager.getColor("ComboBox.background");
        foreground = UIManager.getColor("ComboBox.foreground");
        selectedBackground = UIManager.getColor(
            "ComboBox.selectionBackground");
        selectedForeground = UIManager.getColor(
            "ComboBox.selectionForeground");
        spinnerHour = getJSpinner("HH", 0, 23, 1);
        spinnerMinute = getJSpinner("mm", 0, 59, 1);
        spinnerSecond = getJSpinner("ss", 0, 59, 1);
        initializePopup();
    }
    /**
     * 初始化弹出面板
     * @param string 
     * @param string 
     */
    protected void initializePopup() {
        //<< <   9999/99/99  > >>
       //add by caill start 2016.2.19  如果日期输入框中当前有值,就将此值赋给calendar;如果输入框中没有值,calendar就取当前时间为值  
        if(jcombobox.getSelectedItem() != null){
             String preValue = jcombobox.getSelectedItem().toString();
            if (StringUtils.isBlank(preValue)) {
                calendar.setTime(new Date());
            } else {
                SimpleDateFormat formater = getSimpleDateFormatByInputValue(preValue);
 
                try {
                    // monthLabel.setText(monthFormat.format(formater.parse(preValue)));
                    calendar.setTime(formater.parse(preValue));
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        //add by caill end
        JPanel header = new JPanel();
        header.setLayout(new BoxLayout(header, BoxLayout.X_AXIS));
        header.setBackground(new Color(0, 0, 128));
        header.setForeground(Color.white);
        header.setPreferredSize(new Dimension(1, 25));
 
        JLabel label;
        label = createUpdateButton(Calendar.YEAR, -1);
        label.setText("<<");
        header.add(Box.createHorizontalStrut(12));
        header.add(label);
        header.add(Box.createHorizontalStrut(12));
 
        label = createUpdateButton(Calendar.MONTH, -1);
        label.setText("< ");
        header.add(label);
 
        monthLabel = new JLabel("", JLabel.CENTER);
        monthLabel.setBackground(new Color(0, 0, 128));
        monthLabel.setForeground(Color.white);
        header.add(Box.createHorizontalGlue());
        header.add(monthLabel);
        header.add(Box.createHorizontalGlue());
 
        label = createUpdateButton(Calendar.MONTH, 1);
        label.setText(" >");
        header.add(label);
 
        label = createUpdateButton(Calendar.YEAR, 1);
        label.setText(">>");
 
        header.add(Box.createHorizontalStrut(12));
        header.add(label);
        header.add(Box.createHorizontalStrut(12));
 
        //星期日 星期一 星期二 星期三 星期四 星期五 星期六
        JPanel pWeeks = new JPanel(new GridLayout(0, 7));
        pWeeks.setBackground(background);
        pWeeks.setOpaque(true);
        DateFormatSymbols sy = new DateFormatSymbols(Locale.getDefault());
        String strWeeks[] = sy.getShortWeekdays();
        for (int i = 1; i <= 7; i++) {
          label = new JLabel();
          label.setHorizontalAlignment(JLabel.CENTER);
          label.setForeground(foreground);
          label.setText(strWeeks[i]);
          pWeeks.add(label);
        }
        //中间放日期的面板
        days = new JPanel(new GridLayout(0, 7));
        days.setBorder(new TopBottomLineBorder(Color.black));
        days.setBackground(background);
        days.setOpaque(true);
        JPanel pCenter = new JPanel(new BorderLayout());
        pCenter.setBackground(background);
        pCenter.setOpaque(true);
        pCenter.add(pWeeks, BorderLayout.NORTH);
        pCenter.add(days, BorderLayout.CENTER);
        //显示今天的日期,直接单击图标跳到今天
        String today = "Today:";
        if(isHasTime()){
            today = "";
        }
        //add by caill start 2016.2.19 如果文本框内有值,将日期控件下端的日期设置为文本框内的值;如果没有值,则显示当前时间
        JLabel lbToday =null;
        if(jcombobox.getSelectedItem() != null){
             String preValue = jcombobox.getSelectedItem().toString();
            if (StringUtils.isBlank(preValue)) {
                lbToday = new JDayLable(new Date(), today + dateFormat.format(new Date()));
            } else {
                SimpleDateFormat formater = getSimpleDateFormatByInputValue(preValue);
                try {
                    lbToday = new JDayLable(formater.parse(preValue),
                            today + dateFormat.format(formater.parse(preValue)));
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }else{
              lbToday = new JDayLable(new Date(), today + dateFormat.format(new Date()));
        }
        //add by caill end
       // JLabel lbToday = new JDayLable(new Date(), today + dateFormat.format(new Date()));
        lbToday.setIcon(todayIcon);
        lbToday.setHorizontalAlignment(JLabel.LEFT);
 
        JLabel lbClear = new JDayLable("清空");
        lbClear.setHorizontalAlignment(JLabel.CENTER);
 
        JLabel lbOk = new JDayLable("确定");
        lbClear.setHorizontalAlignment(JLabel.CENTER);
 
        JPanel pSouth = new JPanel(new BorderLayout());
        pSouth.setBackground(background);
        pSouth.setForeground(foreground);
 
        if(isHasDate()){
            pSouth.add(lbToday, BorderLayout.CENTER);
        }
        
        JPanel pal = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        if(isHasTime()){
            pal.add(spinnerHour);
            pal.add(spinnerMinute);
            pal.add(spinnerSecond);
        }
        if(!isHasDate() && isHasTime()){
             pal.add(lbOk);
        }
        if(!isRequired()){
            pal.add(lbClear);
        }
        pSouth.add(pal, BorderLayout.EAST);
        
        
        setForeground(foreground);
        setBackground(background);
        setBorder(BorderFactory.createLineBorder(Color.black));
        setLayout(new BorderLayout());
        removeAll();
        if(isHasDate()){
            add(BorderLayout.NORTH, header);
            add(BorderLayout.CENTER, pCenter);
        }
        add(BorderLayout.SOUTH, pSouth);
    }
 
    private JSpinner getJSpinner(String initValueFormat, int minVal, int maxVal, int stepVal){
        Date initDate = calendar.getTime();
        Date newDate = calendar.getTime();
        boolean flag = true;
        try {
            // 将 每个时间对象的时、分、秒设置为0
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
            String dateTimeString = sdf.format(initDate);
            initDate = sdf.parse(dateTimeString);
        } catch (ParseException e) {
        }
        calendar.add(Calendar.YEAR, -500);
        Date earliestDate = calendar.getTime();
        calendar.add(Calendar.YEAR, 1000);
        Date latestDate = calendar.getTime();
        calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        //add by caill start 2016.2.19 将日期控件下端的时、分、秒按判断条件回显
        SpinnerDateModel model = null;  
        boolean equals = false;
        if(itemStyleValue != null){
              equals = itemStyleValue.trim().equals("minseczeroFlag=1");//add by caill 判断附加属性内容从而设置分秒为0
        }
        
        //JSpinner spinner = null;
        if(jcombobox.getSelectedItem() != null && !jcombobox.getSelectedItem().toString().trim().equals("") && !equals){ //如果当前文本框中有值,并且附加属性的内容不为“minseczeroFlag=1”,则回显当前文本框中的值
             String preValue = jcombobox.getSelectedItem().toString();
             SimpleDateFormat formater = getSimpleDateFormatByInputValue(preValue);
            
             try {
                 model = new SpinnerDateModel(formater.parse(preValue), earliestDate, latestDate, Calendar.SECOND);
             } catch (ParseException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             }
            
        }else if(equals && jcombobox.getSelectedItem() != null && !jcombobox.getSelectedItem().toString().trim().equals("")){ //如果当前文本框中有值,并且附加属性的内容为“minseczeroFlag=1”,在回显当前文本框中的值的同时,将分钟和秒设置为0
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
            String dateTimeString = sdf.format(newDate);
            try {
                newDate = sdf.parse(dateTimeString);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            model = new SpinnerDateModel(newDate, earliestDate, latestDate, Calendar.SECOND);
            flag = false;
            
        }else if(equals){ //如果当前文本框中没有值,并且附加属性的内容为“minseczeroFlag=1”,则回显当前时间的值,但将分钟和秒设置为0
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
            String dateTimeString = sdf.format(newDate);
            try {
                newDate = sdf.parse(dateTimeString);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
            model = new SpinnerDateModel(newDate, earliestDate, latestDate, Calendar.SECOND);
            flag = false;
            
        }else{ //如果当前文本框中没有值,并且附加属性的内容不为“minseczeroFlag=1”,则回显当前时间的值
            model = new SpinnerDateModel(calendar.getTime(), earliestDate, latestDate, Calendar.SECOND);
        }
        //add by caill end  
        //SpinnerModel model = new SpinnerDateModel(calendar.getTime(), earliestDate, latestDate, Calendar.SECOND);
        JSpinner spinner = new JSpinner(model);
        //add by caill start 2016.2.19 当将分钟和秒设置为0时,上下按钮处于不可编辑状态
        if((initValueFormat.equals("mm") || initValueFormat.equals("ss")) && (flag == false)){
            spinner.setEditor(new JSpinner.DateEditor(spinner, "00"));//此处将分钟和秒写死为00,从而使按钮处于无效状态,实现不可修改功能
            
        }else{
            spinner.setEditor(new JSpinner.DateEditor(spinner, initValueFormat));
        }
        //add by caill end
        //spinner.setEditor(new JSpinner.DateEditor(spinner, initValueFormat));
        ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField().setEditable(false);
    //    ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField().setEnabled(false);
        ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField().setColumns(0);
        ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField().setHorizontalAlignment(JFormattedTextField.REVERT);
        return spinner;
    }
 
    public boolean isHasDate() {
        return hasDate;
    }
    public void setHasDate(boolean hasDate) {
        this.hasDate = hasDate;
    }
    /**
     * 返回 是否包含时间
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-11-21
     * @return
     */
    public boolean isHasTime() {
        return hasTime;
    }
    /**
     * 设置是否包含时间
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-11-21
     * @param hasTime
     */
    public void setHasTime(boolean hasTime) {
        this.hasTime = hasTime;
    }
    public boolean isRequired() {
        return required;
    }
    public void setRequired(boolean required) {
        this.required = required;
    }
    /**
     * 返回日期格&时间格式字符串
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-11-21
     * @return
     */
    public String getFormat() {
        return format;
    }
    /**
     * 设置日期&时间格式字符串
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-11-21
     * @param format
     */
    public void setFormat(String format) {
        this.format = format;
    }
    /**
     * 返回时间字符串
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2012-11-21
     * @return
     */
    private String getTimeString(){
        String res = String.format("%s:%s:%s",
                ((JSpinner.DefaultEditor)spinnerHour.getEditor()).getTextField().getText(),
                ((JSpinner.DefaultEditor)spinnerMinute.getEditor()).getTextField().getText(),
                ((JSpinner.DefaultEditor) spinnerSecond.getEditor()).getTextField().getText());
        return res;
    }
    
    /**
     * 显示弹出面板
     */
    public void show() {
        updatePopup();
        super.show();
    }
 
    public void destroy() {
        this.setVisible(false);
    }
 
    /**
     * 创建上一月,下一月,上一年,下一年"按钮"
     * @param field int
     * @param amount int
     * @return JLabel
     */
    protected JLabel createUpdateButton(final int field, final int amount) {
        final JLabel label = new JLabel();
        final Border selectedBorder = new LineBorder(Color.black);
        final Border unselectedBorder = new EmptyBorder(selectedBorder.getBorderInsets(new JLabel()));
        label.setBorder(unselectedBorder);
        label.setBackground(new Color(0, 0, 128));
        label.setForeground(Color.white);
        label.setRequestFocusEnabled(false);
        label.addMouseListener(new MouseAdapter() {
          public void mouseReleased(MouseEvent e) {
            calendar.add(field, amount);
            updatePopup();
          }
 
          public void mouseEntered(MouseEvent e) {
            label.setBorder(selectedBorder);
          }
 
          public void mouseExited(MouseEvent e) {
            label.setBorder(unselectedBorder);
          }
        });
        return label;
    }
 
    /**
     * 更新日期
     */
    protected void updatePopup() {
        monthLabel.setText(monthFormat.format(calendar.getTime()));
        days.removeAll();
 
        Calendar setupCalendar = (Calendar) calendar.clone();
        setupCalendar.set(Calendar.DAY_OF_MONTH, 1);
        int first = setupCalendar.get(Calendar.DAY_OF_WEEK);
        /**
                        1  2  3  4  5  6  7
         2  3  4  5  6  7  8  9  10 11 12 13
         8  9  10 11 12 13 14 15 16 17 18 19
         14 15 16 17 18 19 20 21 22 23 24 25
         20 21 22 23 24 25 26 27 28 29 30 31
         26 27 28 29 30 31
         */
        setupCalendar.add(Calendar.DATE, -first);
        int flag = 0;
        for (int i = 0; i < 42; i++) {
          setupCalendar.add(Calendar.DATE, 1);
          String txt = dayFormat.format(setupCalendar.getTime());
          JLabel label = new JDayLable(setupCalendar.getTime(), txt);
          days.add(label);
          if (txt.equals("1")) {
            flag++;
          }
          if (flag != 1) {
            label.setEnabled(false);
          }
        }
        days.repaint();
        pack();
    }
 
    /**
     * <p>Title: </p>
     * <p>Description: TopBottomLineBorder只带上下两条线的边界Border</p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author <a
     * @version 1.0
     */
    class TopBottomLineBorder extends AbstractBorder {
        /**
         * 
         */
        private static final long serialVersionUID = -3057182793363756740L;
        private Color lineColor;
        public TopBottomLineBorder(Color color) {
          lineColor = color;
        }
 
        public void paintBorder(Component c, Graphics g, int x, int y,
                                int width, int height) {
          g.setColor(lineColor);
          g.drawLine(0, 0, c.getWidth(), 0);
          g.drawLine(0, c.getHeight() - 1, c.getWidth(),
                     c.getHeight() - 1);
        }
    }
 
    /**
     * <p>Title: JDatePicker</p>
     * <p>Description:JDayLable 带选取日期功能的JLabel </p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author
     * @version 1.0
     */
    class JDayLable extends JLabel implements MouseListener {
        /**
         * 
         */
        private static final long serialVersionUID = 4031255003084656843L;
        Date date;
        Image img;
        boolean isToday = false;
        public JDayLable(Date date, String text) {
            setHorizontalAlignment(JLabel.CENTER);
            setForeground(foreground);
            setPreferredSize(new Dimension(40, 20));
            setToolTipText(dateFormat.format(date));
            addMouseListener(this);
            this.date = date;
            setText(text);
            Date d = new Date();
            //add by caill start 2016.2.19  如果日期输入框中当前有值,就将此值赋给d;如果输入框中没有值,d就取当前时间为值  
            if(jcombobox.getSelectedItem() != null && !jcombobox.getSelectedItem().toString().trim().equals("")){      
                String preValue = jcombobox.getSelectedItem().toString();
                    SimpleDateFormat formater = getSimpleDateFormatByInputValue(preValue);
                    try {
                     d=formater.parse(preValue);
                 } catch (ParseException e1) {
                     // TODO Auto-generated catch block
                     e1.printStackTrace();
                 }
            }
            //add by caill end
            isToday = (text.length() < 3) && dateFormat.format(date).equals(dateFormat.format(d));
            if (calendar.getTime().equals(date)) {
                setBorder(new LineBorder(selectedBackground, 1));
            }
        }
 
        public JDayLable(String text) {
            setHorizontalAlignment(JLabel.CENTER);
            setForeground(foreground);
            setPreferredSize(new Dimension(40, 20));
            addMouseListener(this);
            setText(text);
        }
 
        public void mousePressed(MouseEvent e) {}
 
        public void mouseClicked(MouseEvent e) {}
 
        public void mouseReleased(MouseEvent e) {
            if (isEnabled()) {
                setOpaque(false);
                setBackground(background);
                setForeground(foreground);
            }
            Object itemobj = null;
 
            if(isHasDate() && isHasTime()){
                calendar.setTime(date);
                itemobj = dateFormat.format(calendar.getTime());
                // add by xhcao 2012.11.21
                if(isHasTime()){
                    itemobj = itemobj.toString() + " " + getTimeString();
                }
            } else if(isHasDate()){
                if(date != null){
                    calendar.setTime(date);
                    itemobj = dateFormat.format(calendar.getTime());
                } else {
                    itemobj = "";
                }
            } else if(isHasTime()){
                if(isHasTime()){
                    itemobj = getTimeString();
                }
            }
 
            String oldValue = "";
            if(jcombobox.getSelectedItem() != null){
                oldValue = jcombobox.getSelectedItem().toString();
            }
            String newValue = itemobj.toString();
            jcombobox.removeAllItems();
            if(!isRequired()){
                jcombobox.addItem("");
            }
            jcombobox.addItem(itemobj);
            jcombobox.setSelectedItem(itemobj);
            jcombobox.firePropertyChangeV2("valueChange", oldValue, newValue);
            destroy();
        }
 
        public void mouseEntered(MouseEvent e) {
            if (isEnabled()) {
                setOpaque(true);
                setBackground(selectedBackground);
                setForeground(selectedForeground);
            }
        }
 
        public void mouseExited(MouseEvent e) {
            if (isEnabled()) {
                setOpaque(false);
                setBackground(background);
                setForeground(foreground);
            }
        }
 
        public void paint(Graphics g) {
            super.paint(g);
            if (isToday && todayIcon != null && isEnabled()) {
                int x = (this.getWidth() - todayIcon.getIconWidth()) / 2;
                int y = (this.getHeight() - todayIcon.getIconHeight()) / 2;
                todayIcon.paintIcon(this, g, x, y);
            }
        }
    }
}