Revision 2156

View differences:

org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/pickercontroller/DatePickerControllerImpl.java
2 2

  
3 3
import static java.awt.Component.RIGHT_ALIGNMENT;
4 4
import java.awt.event.ActionEvent;
5
import java.awt.event.ActionListener;
6 5
import java.net.URL;
7 6
import java.text.DateFormat;
8 7
import java.text.ParseException;
8
import java.text.SimpleDateFormat;
9 9
import java.util.Date;
10 10
import java.util.Locale;
11 11
import javax.swing.ImageIcon;
......
15 15
import javax.swing.text.JTextComponent;
16 16
import javax.swing.text.DateFormatter;
17 17
import javax.swing.text.DefaultFormatterFactory;
18
import javax.swing.text.MaskFormatter;
18 19
import org.apache.commons.lang3.StringUtils;
19 20
import org.freixas.jcalendar.DateEvent;
20
import org.freixas.jcalendar.DateListener;
21 21
import org.freixas.jcalendar.JCalendar;
22 22
import org.gvsig.tools.dataTypes.DataTypes;
23 23
import org.gvsig.tools.swing.api.ToolsSwingLocator;
......
30 30
 *
31 31
 * @author jjdelcerro
32 32
 */
33
@SuppressWarnings("UseSpecificCatch")
33 34
public class DatePickerControllerImpl 
34 35
        extends AbstractPickerController<Date> 
35 36
        implements DatePickerController
......
52 53
    
53 54
    public DatePickerControllerImpl(JTextComponent txtDate, JButton btnDate) {
54 55
        this.txtDate = txtDate;
55
        ToolsSwingLocator.getToolsSwingManager().addClearButton(txtDate, new ActionListener() {
56
          @Override
57
          public void actionPerformed(ActionEvent e) {
58
            set(null);
59
            txtDate.setText("");
60
          }
56
        ToolsSwingLocator.getToolsSwingManager().addClearButton(txtDate, (ActionEvent e) -> {
57
          set(null);
58
          txtDate.setText("");
61 59
        });
62 60
        this.df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, Locale.getDefault());
63 61
        if( this.txtDate instanceof JFormattedTextField ) {
62
            JFormattedTextField ftf = (JFormattedTextField) this.txtDate;
64 63
            DefaultFormatterFactory formatterFactory = new DefaultFormatterFactory(new DateFormatter(df));
65
            ((JFormattedTextField)(this.txtDate)).setFormatterFactory(formatterFactory);
64
            ftf.setFormatterFactory(formatterFactory);
65
            if( this.df instanceof SimpleDateFormat ) {
66
              try {
67
                SimpleDateFormat sdf = (SimpleDateFormat) this.df;
68
                String s = sdf.toPattern(); // d/M/yy H:mm:ss
69
                s = s.replace("d", "##");
70
                s = s.replace("M", "##");
71
                s = s.replace("y", "#");
72
                s = s.replace("H", "##");
73
                s = s.replace("m", "#");
74
                s = s.replace("s", "#");
75
                MaskFormatter mask = new MaskFormatter(s);
76
                mask.setPlaceholderCharacter('_');
77
                mask.setPlaceholder(sdf.format(new Date()));
78
                mask.setAllowsInvalid(false);
79
                mask.install(ftf);
80
              } catch (Exception ex) {
81
                
82
              }
83
            }
66 84
        }
67 85
        this.btnDate = btnDate;
68 86
        this.txtDate.setAlignmentX(RIGHT_ALIGNMENT);
......
71 89
        this.btnDate.setIcon(this.getIcon("picker-date"));
72 90
        this.btnDate.setText("");
73 91
        
74
        this.btnDate.addActionListener(new ActionListener() {
75
            @Override
76
            public void actionPerformed(ActionEvent e) {
77
                doShowCalendar();
78
            }
92
        this.btnDate.addActionListener((ActionEvent e) -> {
93
          doShowCalendar();
79 94
        });
80 95
    }
81 96

  
......
152 167
    protected JCalendar getJCalendar() {
153 168
        if (this.jcalendar == null) {
154 169
            this.jcalendar = new JCalendar();
155
            this.jcalendar.addDateListener(new DateListener() {
156
                @Override
157
                public void dateChanged(DateEvent arg0) {
158
                    set(getJCalendar().getDate());
159
                    fireChangeEvent();
160
                }
170
            this.jcalendar.addDateListener((DateEvent arg0) -> {
171
              set(getJCalendar().getDate());
172
              fireChangeEvent();
161 173
            });
162 174
        }
163 175
        return (JCalendar) this.jcalendar;

Also available in: Unified diff