this.advancedComponentsSeparator = new JSeparator();
// Create date and time labels and spinners bound to TIME controller property
Date time = new Date(Camera.convertTimeToTimeZone(controller.getTime(), TimeZone.getDefault().getID()));
this.dateLabel = new JLabel();
final SpinnerDateModel dateSpinnerModel = new SpinnerDateModel();
dateSpinnerModel.setValue(time);
this.dateSpinner = new JSpinner(dateSpinnerModel);
String datePattern = ((SimpleDateFormat)DateFormat.getDateInstance(DateFormat.SHORT)).toPattern();
if (datePattern.indexOf("yyyy") == -1) {
datePattern = datePattern.replace("yy", "yyyy");
}
JSpinner.DateEditor dateEditor = new JSpinner.DateEditor(this.dateSpinner, datePattern);
this.dateSpinner.setEditor(dateEditor);
SwingTools.addAutoSelectionOnFocusGain(dateEditor.getTextField());
this.timeLabel = new JLabel();
final SpinnerDateModel timeSpinnerModel = new SpinnerDateModel();
timeSpinnerModel.setValue(time);
this.timeSpinner = new JSpinner(timeSpinnerModel);
// From http://en.wikipedia.org/wiki/12-hour_clock#Use_by_country
String [] twelveHoursCountries = {
"AU", // Australia
"BD", // Bangladesh
"CA", // Canada (excluding Quebec, in French)
"CO", // Colombia
"EG", // Egypt
"HN", // Honduras
"JO", // Jordan
"MX", // Mexico
"MY", // Malaysia
"NI", // Nicaragua
"NZ", // New Zealand
"PH", // Philippines
"PK", // Pakistan
"SA", // Saudi Arabia
"SV", // El Salvador
"US", // United States
"VE"}; // Venezuela
SimpleDateFormat timeInstance;
if ("en".equals(Locale.getDefault().getLanguage())) {
if (Arrays.binarySearch(twelveHoursCountries, Locale.getDefault().getCountry()) >= 0) {
timeInstance = (SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US); // 12 hours notation
} else {
timeInstance = (SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT, Locale.UK); // 24 hours notation
}
} else {
timeInstance = (SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT);
}
JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(this.timeSpinner, timeInstance.toPattern());
this.timeSpinner.setEditor(timeEditor);
SwingTools.addAutoSelectionOnFocusGain(timeEditor.getTextField());
final PropertyChangeListener timeChangeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
Date date = new Date(Camera.convertTimeToTimeZone(controller.getTime(), TimeZone.getDefault().getID()));
dateSpinnerModel.setValue(date);
timeSpinnerModel.setValue(date);
}
};
controller.addPropertyChangeListener(VideoController.Property.TIME, timeChangeListener);
final ChangeListener dateTimeChangeListener = new ChangeListener() {
public void stateChanged(ChangeEvent ev) {
controller.removePropertyChangeListener(VideoController.Property.TIME, timeChangeListener);
// Merge date and time
GregorianCalendar dateCalendar = new GregorianCalendar();
dateCalendar.setTime((Date)dateSpinnerModel.getValue());
GregorianCalendar timeCalendar = new GregorianCalendar();
timeCalendar.setTime((Date)timeSpinnerModel.getValue());
Calendar utcCalendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
utcCalendar.set(GregorianCalendar.YEAR, dateCalendar.get(GregorianCalendar.YEAR));
utcCalendar.set(GregorianCalendar.MONTH, dateCalendar.get(GregorianCalendar.MONTH));
utcCalendar.set(GregorianCalendar.DAY_OF_MONTH, dateCalendar.get(GregorianCalendar.DAY_OF_MONTH));
utcCalendar.set(GregorianCalendar.HOUR_OF_DAY, timeCalendar.get(GregorianCalendar.HOUR_OF_DAY));
utcCalendar.set(GregorianCalendar.MINUTE, timeCalendar.get(GregorianCalendar.MINUTE));
utcCalendar.set(GregorianCalendar.SECOND, timeCalendar.get(GregorianCalendar.SECOND));
controller.setTime(utcCalendar.getTimeInMillis());
controller.addPropertyChangeListener(VideoController.Property.TIME, timeChangeListener);
}
};
dateSpinnerModel.addChangeListener(dateTimeChangeListener);
timeSpinnerModel.addChangeListener(dateTimeChangeListener);
this.dayNightLabel = new JLabel();
final ImageIcon dayIcon = new ImageIcon(PhotoPanel.class.getResource("resources/day.png"));
final ImageIcon nightIcon = new ImageIcon(PhotoPanel.class.getResource("resources/night.png"));
PropertyChangeListener dayNightListener = new PropertyChangeListener() {