public TimePeriodChooser(int alignment) {
this(-1, -1, alignment);
}
public TimePeriodChooser(int from, int to, int alignment) {
FlowLayout layout = new FlowLayout(FlowLayout.LEFT, 0, 0);
JPanel content = new JPanel(new FormLayout("pref, 3dlu, pref, 3dlu, pref, 3dlu, pref", "pref"));
mTimeFromSp = new JSpinner(new SpinnerDateModel());
JSpinner.DateEditor dateEditor = new JSpinner.DateEditor(mTimeFromSp, Settings.getTimePattern());
mTimeFromSp.setEditor(dateEditor);
CaretPositionCorrector.createCorrector(dateEditor.getTextField(), new char[] {':'}, -1);
mTimeToSp = new JSpinner(new SpinnerDateModel());
dateEditor = new JSpinner.DateEditor(mTimeToSp, Settings.getTimePattern());
mTimeToSp.setEditor(dateEditor);
CaretPositionCorrector.createCorrector(dateEditor.getTextField(), new char[] {':'}, -1);
CellConstraints cc = new CellConstraints();
content.add(mLabel1 = new JLabel(mLocalizer.msg("between", "between")), cc.xy(1, 1));
content.add(mTimeFromSp, cc.xy(3, 1));
content.add(mLabel2 = new JLabel(mLocalizer.msg("and", "and")), cc.xy(5, 1));
content.add(mTimeToSp, cc.xy(7, 1));
if (from >= 0) {
setFromTime(from);
}
if (to >= 0) {
setToTime(to);
}
if (alignment == ALIGN_LEFT) {
layout.setAlignment(FlowLayout.LEFT);
} else if (alignment == ALIGN_RIGHT) {
layout.setAlignment(FlowLayout.RIGHT);
} else {
layout.setAlignment(FlowLayout.CENTER);
}
setLayout(layout);
add(content);
}