📄 appointmentcontroller.java
字号:
}
if (evt.getSource() == endDate) {
Date newEnd = raplaLocale.toDate(endDate.getDate(),endTime.getTime());
if (appointment.getStart().after(newEnd)) {
Date newStart = new Date(newEnd.getTime() - (duration% DateTools.MILLISECONDS_PER_DAY));
startDate.setDate(newStart);
startTime.setTime(newStart);
getLogger().debug("startdate adjusted");
}
}
} finally {
listenerEnabled = true;
}
mapToAppointment();
}
private void mapFromAppointment() {
listenerEnabled = false;
try {
startDate.setDate(appointment.getStart());
endDate.setDate(appointment.getEnd());
startTime.setTime(appointment.getStart());
endTime.setTime(appointment.getEnd());
} finally {
listenerEnabled = true;
}
}
private void mapToAppointment() {
RaplaLocale raplaLocale = getRaplaLocale();
Date start = raplaLocale.toDate(startDate.getDate(),startTime.getTime());
Date end = raplaLocale.toDate(endDate.getDate(),endTime.getTime());
appointment.move(start,end);
fireAppointmentChanged();
}
}
class RepeatingEditor implements ActionListener,DateChangeListener,ChangeListener, Disposable {
JPanel content = new JPanel();
JPanel intervalPanel = new JPanel();
JPanel weekdayInMonthPanel = new JPanel();
JPanel dayInMonthPanel = new JPanel();
RaplaNumber interval = new RaplaNumber(null,RaplaNumber.ONE,null,false);
RaplaNumber weekdayInMonth = new RaplaNumber(null,RaplaNumber.ONE,new Integer(5),false);
RaplaNumber dayInMonth = new RaplaNumber(null,RaplaNumber.ONE,new Integer(31),false);
WeekdayChooser weekdayChooser = new WeekdayChooser();
JLabel dayLabel = new JLabel();
JLabel startTimeLabel = new JLabel();
RaplaTime startTime;
JLabel endTimeLabel = new JLabel();
JPanel endTimePanel = new JPanel();
RaplaTime endTime;
public final int SAME_DAY = 0,NEXT_DAY = 1,X_DAYS = 2;
JComboBox dayChooser;
RaplaNumber days = new RaplaNumber(null,new Integer(2),null,false);
JLabel startDateLabel = new JLabel();
RaplaCalendar startDate;
PeriodChooser startDatePeriod;
JComboBox endingChooser;
public final int REPEAT_UNTIL = 0, REPEAT_N_TIMES = 1, REPEAT_FOREVER = 2;
RaplaCalendar endDate;
JPanel numberPanel = new JPanel();
RaplaNumber number = new RaplaNumber(null,RaplaNumber.ONE,null,false);
JPanel endDatePeriodPanel = new JPanel();
PeriodChooser endDatePeriod;
RaplaButton exceptionButton = new RaplaButton();
ExceptionEditor exceptionEditor;
DialogUI exceptionDlg;
MonthChooser monthChooser = new MonthChooser();
boolean listenerEnabled = true;
public RepeatingEditor() throws RaplaException {
startDatePeriod = new PeriodChooser(getContext(),PeriodChooser.START_ONLY);
endDatePeriod = new PeriodChooser(getContext(),PeriodChooser.END_ONLY);
// Create a TableLayout for the frame
double pre =TableLayout.PREFERRED;
double fill =TableLayout.FILL;
double size[][] =
{{ pre,5,pre,5,fill}, // Columns
{ ROW_SIZE,18,ROW_SIZE,5,ROW_SIZE,15,ROW_SIZE,6,ROW_SIZE, 0 }}; // Rows
TableLayout tableLayout = new TableLayout(size);
content.setLayout(tableLayout);
}
public Locale getLocale() {
return getI18n().getLocale();
}
public JComponent getComponent() {
return content;
}
public void initialize() {
// Interval / Weekday
interval.setColumns(2);
weekdayInMonth.setColumns( 2);
dayInMonth.setColumns( 2 );
intervalPanel.setLayout(new BoxLayout(intervalPanel,BoxLayout.X_AXIS));
intervalPanel.add(new JLabel(getString("repeating.interval.pre") + " "));
intervalPanel.add(Box.createHorizontalStrut(3));
intervalPanel.add(interval);
intervalPanel.add(Box.createHorizontalStrut(3));
intervalPanel.add( new JLabel(getString("repeating.interval.post")));
dayInMonthPanel.setLayout(new BoxLayout(dayInMonthPanel,BoxLayout.X_AXIS));
//dayInMonthPanel.add(new JLabel("Am"));
dayInMonthPanel.add(Box.createHorizontalStrut(35));
dayInMonthPanel.add(dayInMonth);
dayInMonthPanel.add(Box.createHorizontalStrut(3));
dayInMonthPanel.add( new JLabel(getString("repeating.interval.post")));
weekdayInMonthPanel.setLayout(new BoxLayout(weekdayInMonthPanel,BoxLayout.X_AXIS));
//weekdayInMonthPanel.add(new JLabel("Am"));
weekdayInMonthPanel.add(Box.createHorizontalStrut(35));
weekdayInMonthPanel.add( weekdayInMonth);
weekdayInMonthPanel.add(Box.createHorizontalStrut(3));
weekdayInMonthPanel.add( new JLabel(getString("repeating.interval.post")));
interval.addChangeListener(this);
weekdayInMonth.addChangeListener( this);
dayInMonth.addChangeListener( this);
weekdayChooser.setLocale(getLocale());
weekdayChooser.addActionListener(this);
monthChooser.setLocale(getLocale());
monthChooser.addActionListener(this);
dayLabel.setText(getString("day") + " ");
dayLabel.setVisible(false);
// StartTime
startTimeLabel.setText(getString("start_time"));
startTime = createRaplaTime();
startTime.addDateChangeListener(this);
// EndTime duration
endTimeLabel.setText(getString("end_time"));
endTime = createRaplaTime();
endTime.addDateChangeListener(this);
dayChooser = new JComboBox(new String[] {
getString("appointment.same_day")
,getString("appointment.next_day")
,getString("appointment.day_x")
});
dayChooser.addActionListener(this);
days.setColumns(2);
endTimePanel.setLayout(new TableLayout(new double[][] {
{TableLayout.PREFERRED,5,TableLayout.PREFERRED,TableLayout.FILL}
,{ROW_SIZE}
}));
//endTimePanel.add(endTime,"0,0,l,f");
endTimePanel.add(dayChooser,"0,0");
endTimePanel.add(days,"2,0");
days.setVisible(false);
days.addChangeListener(this);
// start-date (with period-box)
startDatePeriod.addActionListener(this);
startDateLabel.setText(getString("repeating.start_date"));
startDate = createRaplaCalendar();
startDate.addDateChangeListener(this);
// end-date (with period-box)/n-times/forever
endDatePeriod.addActionListener(this);
endDate = createRaplaCalendar();
endDate.addDateChangeListener(this);
endingChooser = new JComboBox(new String[] {
getString("repeating.end_date")
,getString("repeating.n_times")
,getString("repeating.forever")
});
endingChooser.addActionListener(this);
number.setColumns(3);
number.setNumber(new Integer(1));
number.addChangeListener(this);
numberPanel.setLayout(new BorderLayout());
numberPanel.add(number,BorderLayout.WEST);
numberPanel.setVisible(false);
intervalPanel.setVisible( false );
weekdayInMonthPanel.setVisible( false);
dayInMonthPanel.setVisible( false);
// exception
exceptionButton.setText(getString("appointment.exceptions") + " (0)");
exceptionButton.addActionListener(this);
content.add(intervalPanel,"0,0,l,f");
content.add(weekdayInMonthPanel,"0,0,l,f");
content.add(dayInMonthPanel,"0,0,l,f");
content.add(weekdayChooser,"2,0,f,f");
content.add(monthChooser,"2,0,f,f");
content.add(dayLabel,"2,0,l,f");
content.add(startTimeLabel,"0,2,l,f");
content.add(startTime,"2,2,f,f");
content.add(exceptionButton,"4,0,r,t");
content.add(endTimeLabel,"0,4,l,f");
content.add(endTime,"2,4,f,f");
content.add(endTimePanel,"4,4,4,4,l,f");
content.add(startDateLabel,"0,6,l,f");
content.add(startDate,"2,6,l,f");
content.add(startDatePeriod,"4,6,f,f");
content.add(endingChooser,"0,8,l,f");
content.add(endDate,"2,8,l,f");
content.add(endDatePeriodPanel,"4,8,f,f");
// We must surround the endDatePeriod with a panel to
// separate visiblity of periods from visibility of the panel
endDatePeriodPanel.setLayout(new BorderLayout());
endDatePeriodPanel.add(endDatePeriod,BorderLayout.CENTER);
content.add(numberPanel,"2,8,f,f");
//content.add(exceptionLabel,"0,10,l,c");
//content.add(exceptionPanel,"2,10,4,10,l,c");
}
public void dispose() {
endDatePeriod.removeActionListener( this );
startDatePeriod.removeActionListener( this );
}
private Date getStart() {
Date start = getRaplaLocale().toDate(startDate.getDate(),startTime.getTime());
/*
if (repeating.isWeekly() || repeating.isMonthly()) {
Calendar calendar = getRaplaLocale().createCalendar();
calendar.setTime(start);
calendar.set(Calendar.DAY_OF_WEEK, weekdayChooser.getSelectedWeekday() );
if (calendar.getTime().before(start)) {
calendar.add(Calendar.DAY_OF_WEEK,7);
}
start = calendar.getTime();
}
if (repeating.isYearly()) {
Calendar calendar = getRaplaLocale().createCalendar();
calendar.setTime(start);
calendar.set(Calendar.MONTH, monthChooser.getSelectedMonth() );
calendar.set(Calendar.DAY_OF_MONTH, dayInMonth.getNumber().intValue() );
start = calendar.getTime();
}
*/
return start;
}
private Date getEnd() {
Date end = getRaplaLocale().toDate(getStart(),endTime.getTime());
if (dayChooser.getSelectedIndex() == NEXT_DAY)
end = DateTools.addDay(end);
if (dayChooser.getSelectedIndex() == X_DAYS)
end = DateTools.addDays(end,days.getNumber().intValue());
return end;
}
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == exceptionButton) {
try {
showExceptionDlg();
} catch (RaplaException ex) {
showException(ex,content);
}
return;
}
if (!listenerEnabled)
return;
try {
listenerEnabled = false;
if (evt.getSource() == weekdayChooser) {
Calendar calendar = getRaplaLocale().createCalendar();
calendar.setTime(startDate.getDate());
calendar.set(Calendar.DAY_OF_WEEK, weekdayChooser.getSelectedWeekday());
startDate.setDate(calendar.getTime());
}
if (evt.getSource() == monthChooser) {
Calendar calendar = getRaplaLocale().createCalendar();
calendar.setTime(startDate.getDate());
calendar.set(Calendar.MONTH, monthChooser.getSelectedMonth() );
calendar.set(Calendar.DAY_OF_MONTH, dayInMonth.getNumber().intValue() );
startDate.setDate(calendar.getTime());
}
if (evt.getSource() == dayChooser) {
if (dayChooser.getSelectedIndex() == SAME_DAY) {
if (getEnd().before(getStart())) {
endTime.setTime(getStart());
getLogger().debug("endtime adjusted");
}
}
}
if (evt.getSource() == startDatePeriod && startDatePeriod.getPeriod()!= null) {
Calendar calendar = getRaplaLocale().createCalendar();
calendar.setTime(startDatePeriod.getPeriod().getStart());
if ( repeating.isWeekly()
|| repeating.isMonthly()
) {
calendar.set(Calendar.DAY_OF_WEEK, weekdayChooser.getSelectedWeekday());
if (calendar.getTime().before(startDatePeriod.getPeriod().getStart())) {
calendar.add(Calendar.DAY_OF_WEEK,7);
}
}
getLogger().debug("startdate adjusted to period");
startDate.setDate(calendar.getTime());
endDatePeriod.setSelectedPeriod(startDatePeriod.getPeriod());
}
if (evt.getSource() == endDatePeriod && endDatePeriod.getDate()!= null) {
endDate.setDate(DateTools.subDay(endDatePeriod.getDate()));
getLogger().debug("enddate adjusted to period");
}
mapToAppointment();
mapFromAppointment();
} finally {
listenerEnabled = true;
}
}
public void stateChanged(ChangeEvent evt) {
if (!listenerEnabled)
return;
try {
listenerEnabled = false;
if ( evt.getSource() == weekdayInMonth && repeating.isMonthly())
{
Number weekdayOfMonthValue = weekdayInMonth.getNumber();
if ( weekdayOfMonthValue != null && repeating.isMonthly())
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -