Revision 2157
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 | ||
---|---|---|
25 | 25 |
import org.gvsig.tools.swing.api.pickercontroller.DatePickerController; |
26 | 26 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
27 | 27 |
import org.gvsig.tools.swing.icontheme.IconThemeManager; |
28 |
import org.slf4j.Logger; |
|
29 |
import org.slf4j.LoggerFactory; |
|
28 | 30 |
|
29 | 31 |
/** |
30 | 32 |
* |
... | ... | |
40 | 42 |
private final JTextComponent txtDate; |
41 | 43 |
private JCalendar jcalendar; |
42 | 44 |
private DateFormat df; |
43 |
|
|
45 |
private static final Logger LOG = LoggerFactory.getLogger(DatePickerControllerImpl.class); |
|
46 |
|
|
44 | 47 |
public static void selfRegister() { |
45 | 48 |
URL imageResource = DatePickerControllerImpl.class.getClassLoader().getResource("org/gvsig/tools/swing/picker/picker-date.png"); |
46 | 49 |
if (imageResource != null) { |
... | ... | |
55 | 58 |
this.txtDate = txtDate; |
56 | 59 |
ToolsSwingLocator.getToolsSwingManager().addClearButton(txtDate, (ActionEvent e) -> { |
57 | 60 |
set(null); |
58 |
txtDate.setText(""); |
|
61 |
txtDate.setText("");
|
|
59 | 62 |
}); |
60 |
this.df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, Locale.getDefault());
|
|
63 |
this.df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
|
|
61 | 64 |
if( this.txtDate instanceof JFormattedTextField ) { |
62 | 65 |
JFormattedTextField ftf = (JFormattedTextField) this.txtDate; |
63 | 66 |
DefaultFormatterFactory formatterFactory = new DefaultFormatterFactory(new DateFormatter(df)); |
64 | 67 |
ftf.setFormatterFactory(formatterFactory); |
65 |
if( this.df instanceof SimpleDateFormat ) { |
|
68 |
ftf.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT); |
|
69 |
if( df instanceof SimpleDateFormat ) { |
|
66 | 70 |
try { |
67 | 71 |
SimpleDateFormat sdf = (SimpleDateFormat) this.df; |
68 | 72 |
String s = sdf.toPattern(); // d/M/yy H:mm:ss |
69 | 73 |
s = s.replace("d", "##"); |
74 |
s = s.replace("MM", "##"); |
|
70 | 75 |
s = s.replace("M", "##"); |
71 | 76 |
s = s.replace("y", "#"); |
77 |
s = s.replace("HH", "##"); |
|
72 | 78 |
s = s.replace("H", "##"); |
73 | 79 |
s = s.replace("m", "#"); |
80 |
|
|
74 | 81 |
s = s.replace("s", "#"); |
75 | 82 |
MaskFormatter mask = new MaskFormatter(s); |
76 | 83 |
mask.setPlaceholderCharacter('_'); |
77 |
mask.setPlaceholder(sdf.format(new Date())); |
|
84 |
//mask.setPlaceholder(sdf.format(new Date()));
|
|
78 | 85 |
mask.setAllowsInvalid(false); |
79 | 86 |
mask.install(ftf); |
80 | 87 |
} catch (Exception ex) { |
81 |
|
|
88 |
LOG.warn("Not been able to create mask", ex); |
|
82 | 89 |
} |
83 | 90 |
} |
84 | 91 |
} |
... | ... | |
135 | 142 |
|
136 | 143 |
@Override |
137 | 144 |
public void set(Date date) { |
138 |
this.txtDate.setText(this.df.format(date)); |
|
145 |
if (txtDate instanceof JFormattedTextField) { |
|
146 |
((JFormattedTextField) txtDate).setValue(date); |
|
147 |
} else { |
|
148 |
this.txtDate.setText(this.df.format(date)); |
|
149 |
} |
|
139 | 150 |
} |
140 | 151 |
|
141 | 152 |
@Override |
Also available in: Unified diff