
se.wfh.libs.common.gui.widgets.WTimeTextField Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gui Show documentation
Show all versions of gui Show documentation
Some helper classes i needed for several projects (GUI / Swing parts)
package se.wfh.libs.common.gui.widgets;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import se.wfh.libs.common.gui.AbstractWTextField;
import se.wfh.libs.common.utils.DateTools;
import se.wfh.libs.common.utils.DateTools.ConvertType;
public class WTimeTextField extends AbstractWTextField {
private static final long serialVersionUID = 1L;
public WTimeTextField() {
this(null);
}
public WTimeTextField(final Date defval) {
this(defval, 10);
}
public WTimeTextField(final Date defval, final int columns) {
super(defval, columns);
if (defval != null) {
getComponent().setText(DateTools.toString(defval, ConvertType.TIME));
}
changeBackground(getValueInternal() != null);
}
@Override
public Date getValue() {
return getValueInternal();
}
private Date getValueInternal() {
Calendar cal = null;
try {
cal = DateTools.fromString(getComponent().getText(), ConvertType.TIME);
} catch (ParseException pex) {
// Ignore
pex.getErrorOffset(); // for PMD
}
return cal == null ? null : cal.getTime();
}
@Override
public boolean isInputValid(final Date value) {
return value != null;
}
@Override
public void setValue(final Date value) {
getComponent().setText(DateTools.toString(value, ConvertType.TIME));
changeBackground(isValidValue(value));
updatePreviousValue(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy