Revision 2166

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
3 3
import java.awt.Color;
4 4
import static java.awt.Component.RIGHT_ALIGNMENT;
5 5
import java.awt.event.ActionEvent;
6
import java.awt.event.ActionListener;
6 7
import java.net.URL;
7 8
import java.text.DateFormat;
8 9
import java.text.ParseException;
......
27 28
import org.gvsig.tools.swing.api.pickercontroller.DatePickerController;
28 29
import org.gvsig.tools.swing.icontheme.IconTheme;
29 30
import org.gvsig.tools.swing.icontheme.IconThemeManager;
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32 31

  
33 32
/**
34 33
 *
......
43 42
  private final JTextComponent txtDate;
44 43
  private JCalendar jcalendar;
45 44
  private DateFormat df;
46
  private static final Logger LOG = LoggerFactory.getLogger(DatePickerControllerImpl.class);
47 45

  
48 46
  public static void selfRegister() {
49 47
    URL imageResource = DatePickerControllerImpl.class.getClassLoader().getResource("org/gvsig/tools/swing/picker/picker-date.png");
......
58 56
  private final DocumentListener documentListener;
59 57
  private final Color colorOk;
60 58
  private final Color colorErr;
61
  private String emptyValue;
59
  private String emptyText;
60
  private MaskFormatter mask;
61
  private final ActionListener buttonListener;
62 62

  
63 63
  public DatePickerControllerImpl(JTextComponent txtDate, JButton btnDate) {
64 64
    this.txtDate = txtDate;
......
97 97
          s = s.replace("y", "#");
98 98
          s = s.replace("d", "#");
99 99
          s = s.replace("M", "#");
100
          MaskFormatter mask = new MaskFormatter(s);
100
          this.mask = new MaskFormatter(s);
101 101
          mask.setPlaceholderCharacter('_');
102
          this.emptyValue = s.replace("#","_");
102
          this.emptyText = s.replace("#","_");
103 103
          mask.setAllowsInvalid(false);
104 104
          mask.install(ftf);
105 105
        } catch (Exception ex) {
......
136 136
      this.btnDate.setText("");
137 137
    }
138 138

  
139
    this.btnDate.addActionListener((ActionEvent e) -> {
139
    this.buttonListener = (ActionEvent e) -> {
140 140
      doShowCalendar();
141
    });
141
    };
142
    this.btnDate.addActionListener(this.buttonListener);
142 143
  }
143 144

  
144 145
  @Override
145 146
  public void uninstall() {
146

  
147
    this.document.removeDocumentListener(documentListener);
148
    if( this.mask!=null ) {
149
      this.mask.uninstall();
150
    }
151
    this.txtDate.setBackground(colorOk);
152
    this.btnDate.removeActionListener(buttonListener);    
147 153
  }
148 154
  
149
  private String getText() {
155
  protected String getText() {
150 156
    String s = this.txtDate.getText();
151
    if( this.emptyValue!=null && this.emptyValue.equals(s) ) {
157
    if( this.emptyText!=null && this.emptyText.equals(s) ) {
152 158
      return "";
153 159
    }
154 160
    s = s.replace("_", "");
155 161
    return s;
156 162
  }
157 163

  
158
  private void checkContents() {
164
  protected void checkContents() {
159 165
    if( this.isValid() ) {
160 166
      this.txtDate.setBackground(colorOk);
161 167
    } else {
......
228 234
    }
229 235
    JPopupMenu menu = new JPopupMenu();
230 236
    menu.add(getJCalendar());
231
    Date v = this.get();
237
    Date v = new Date();
238
    if( !isEmpty() ) {
239
      v = this.get();
240
    }
232 241
    if (v != null) {
233 242
      getJCalendar().setDate(v);
234 243
    }
......
251 260
    this.set((Date) this.coerce(DataTypes.DATE, value, new Date()));
252 261
  }
253 262

  
263
  @Override
264
  public DateFormat getDateFormat() {
265
    return this.df;
266
  }
267

  
268
  @Override
269
  public MaskFormatter  getMask() {
270
      return this.mask;
271
  }
272

  
273
  @Override
274
  public void setEmptyText(String emptyText) {
275
    this.emptyText = emptyText;
276
  }
277

  
254 278
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/pickercontroller/DatePickerController.java
1 1
package org.gvsig.tools.swing.api.pickercontroller;
2 2

  
3
import java.text.DateFormat;
3 4
import java.util.Date;
5
import javax.swing.text.MaskFormatter;
4 6

  
5 7
/**
6 8
 *
......
8 10
 */
9 11
public interface DatePickerController extends PickerController<Date> {
10 12
  public void uninstall();
13
  
14
  public DateFormat getDateFormat();
15
  
16
  public MaskFormatter getMask();
17
  
18
  public void setEmptyText(String emptyText);
19
  
11 20
}

Also available in: Unified diff