📄 appointmentcontroller.java
字号:
Calendar cal = getRaplaLocale().createCalendar();
cal.setTime( appointment.getStart());
cal.set( Calendar.DAY_OF_WEEK_IN_MONTH, weekdayOfMonthValue.intValue());
startDate.setDate( cal.getTime());
}
}
if ( evt.getSource() == dayInMonth && repeating.isYearly())
{
Number dayOfMonthValue = dayInMonth.getNumber();
if ( dayOfMonthValue != null && repeating.isYearly())
{
Calendar cal = getRaplaLocale().createCalendar();
cal.setTime( appointment.getStart());
cal.set( Calendar.DAY_OF_MONTH, dayOfMonthValue.intValue());
startDate.setDate( cal.getTime());
}
}
mapToAppointment();
mapFromAppointment();
} finally {
listenerEnabled = true;
}
}
public void dateChanged(DateChangeEvent evt) {
if (!listenerEnabled)
return;
try {
listenerEnabled = false;
long duration = appointment.getEnd().getTime() - appointment.getStart().getTime();
if (evt.getSource() == startTime) {
Date newEnd = new Date(getStart().getTime() + duration);
endTime.setTime(newEnd);
getLogger().debug("endtime adjusted");
}
if (evt.getSource() == endTime) {
Date newEnd = getEnd();
if (getStart().after(newEnd)) {
newEnd = DateTools.addDay(newEnd);
endTime.setTime(newEnd);
getLogger().debug("enddate adjusted");
}
}
mapToAppointment();
mapFromAppointment();
} finally {
listenerEnabled = true;
}
}
private void mapToAppointment() {
int index = endingChooser.getSelectedIndex();
Number intervalValue = interval.getNumber();
if (intervalValue != null)
repeating.setInterval(intervalValue.intValue());
else
repeating.setInterval(1);
if (index == REPEAT_UNTIL) {
repeating.setEnd(DateTools.addDay(endDate.getDate()));
} else if (index == REPEAT_N_TIMES) {
Number numberValue = number.getNumber();
if (number != null)
repeating.setNumber(numberValue.intValue());
else
repeating.setNumber(1);
} else {
repeating.setEnd(null);
repeating.setNumber(-1);
}
appointment.move(getStart(),getEnd());
fireAppointmentChanged();
}
private void updateExceptionCount() {
int count = repeating.getExceptions().length;
if (count >0) {
exceptionButton.setForeground(Color.red);
} else {
exceptionButton.setForeground(UIManager.getColor("Label.foreground"));
}
String countValue = String.valueOf(count);
if ( count < 9 ) {
countValue =" " + countValue + " ";
}
exceptionButton.setText(getString("appointment.exceptions") + " (" + countValue + ")");
}
private void showEnding(int index) {
if (index == REPEAT_UNTIL) {
endDate.setVisible(true);
endDatePeriodPanel.setVisible(true);
numberPanel.setVisible(false);
}
if (index == REPEAT_N_TIMES) {
endDate.setVisible(false);
endDatePeriodPanel.setVisible(false);
numberPanel.setVisible(true);
}
if (index == REPEAT_FOREVER) {
endDate.setVisible(false);
endDatePeriodPanel.setVisible(false);
numberPanel.setVisible(false);
}
}
private void mapFromAppointment() {
if (exceptionDlg != null && exceptionDlg.isVisible())
exceptionDlg.dispose();
repeating = appointment.getRepeating();
if (repeating == null) {
return;
}
listenerEnabled = false;
try {
updateExceptionCount();
if (exceptionEditor != null)
exceptionEditor.mapFromAppointment();
interval.setNumber(new Integer(repeating.getInterval()));
startDate.setDate(appointment.getStart());
startDatePeriod.setDate(appointment.getStart());
startTime.setTime(appointment.getStart());
endTime.setTime(appointment.getEnd());
weekdayInMonthPanel.setVisible(repeating.isMonthly());
intervalPanel.setVisible( repeating.isDaily() || repeating.isWeekly());
dayInMonthPanel.setVisible( repeating.isYearly());
if ( repeating.getEnd() != null ) {
endDate.setDate(DateTools.subDay(repeating.getEnd()));
endDatePeriod.setDate(DateTools.cutDate(endDate.getDate()));
number.setNumber(new Integer(repeating.getNumber()));
if (!repeating.isFixedNumber()) {
endingChooser.setSelectedIndex(REPEAT_UNTIL);
showEnding(REPEAT_UNTIL);
} else {
endingChooser.setSelectedIndex(REPEAT_N_TIMES);
showEnding(REPEAT_N_TIMES);
}
} else {
endingChooser.setSelectedIndex(REPEAT_FOREVER);
showEnding(REPEAT_FOREVER);
}
startDatePeriod.setVisible( repeating.isDaily() || repeating.isWeekly());
endDatePeriod.setVisible( repeating.isDaily() || repeating.isWeekly());
if (repeating.isWeekly() ||repeating.isMonthly())
{
dayLabel.setVisible(false);
weekdayChooser.setVisible(true);
monthChooser.setVisible(false);
Calendar calendar = getRaplaLocale().createCalendar();
calendar.setTime(appointment.getStart());
weekdayChooser.selectWeekday(calendar.get(Calendar.DAY_OF_WEEK));
}
if (repeating.isYearly())
{
dayLabel.setVisible(false);
weekdayChooser.setVisible(false);
monthChooser.setVisible(true);
Calendar cal = getRaplaLocale().createCalendar();
cal.setTime(appointment.getStart());
monthChooser.selectMonth(cal.get(Calendar.MONTH) );
int numb = cal.get( Calendar.DAY_OF_MONTH);
dayInMonth.setNumber( new Integer( numb));
}
if (repeating.isMonthly())
{
Calendar cal = getRaplaLocale().createCalendar();
cal.setTime( appointment.getStart());
int numb = cal.get( Calendar.DAY_OF_WEEK_IN_MONTH);
weekdayInMonth.setNumber( new Integer( numb));
}
if (repeating.isDaily())
{
dayLabel.setVisible(true);
weekdayChooser.setVisible(false);
monthChooser.setVisible(false);
}
int daysBetween = (int) DateTools.countDays(appointment.getStart(),appointment.getEnd());
if (daysBetween == 0) {
dayChooser.setSelectedIndex(SAME_DAY);
days.setVisible(false);
} else if (daysBetween == 1) {
dayChooser.setSelectedIndex(NEXT_DAY);
days.setVisible(false);
} else {
dayChooser.setSelectedIndex(X_DAYS);
days.setNumber(new Integer(daysBetween));
days.setVisible(true);
}
} finally {
listenerEnabled = true;
}
getComponent().revalidate();
}
private void showExceptionDlg() throws RaplaException {
exceptionEditor = new ExceptionEditor();
exceptionEditor.initialize();
exceptionEditor.mapFromAppointment();
exceptionEditor.getComponent().setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
exceptionDlg = DialogUI.create(
getContext()
,getComponent()
,true
,exceptionEditor.getComponent()
,new String[] {
getString("back")
});
exceptionDlg.setTitle(getString("appointment.exceptions"));
exceptionDlg.start();
updateExceptionCount();
}
}
class ExceptionEditor implements ActionListener,ListSelectionListener {
JPanel content = new JPanel();
RaplaCalendar exceptionDate;
RaplaButton addButton = new RaplaButton(RaplaButton.SMALL);
RaplaButton removeButton = new RaplaButton(RaplaButton.SMALL);
JList specialExceptions = new JList();
JList generalExceptions = new JList(new String[] {"Feiertage","Dies academicus"});
public ExceptionEditor() {
// Create a TableLayout for the frame
double pre =TableLayout.PREFERRED;
double min =TableLayout.MINIMUM;
double fill =TableLayout.FILL;
double yborder = 8;
double size[][] =
{{pre,pre,0.1,50,100,0.9}, // Columns
{yborder,min,min,fill}}; // Rows
TableLayout tableLayout = new TableLayout(size);
content.setLayout(tableLayout);
}
public JComponent getComponent() {
return content;
}
public void initialize() {
addButton.setText(getString("add") );
addButton.setIcon( getIcon("icon.arrow_right"));
removeButton.setText( getString("remove"));
removeButton.setIcon( getIcon("icon.arrow_left"));
exceptionDate = createRaplaCalendar();
/*
this.add(new JLabel(getString("appointment.exception.general") + " "),"0,1");
this.add(new JScrollPane(generalExceptions
,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS
,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER)
,"1,1,1,3,t");
*/
JLabel label =new JLabel(getString("appointment.exception.days") + " ");
label.setHorizontalAlignment(SwingConstants.RIGHT);
content.add(label,"3,1,4,1,r,t");
content.add(exceptionDate,"5,1,l,t");
content.add(addButton,"4,2,f,t");
content.add(removeButton,"4,3,f,t");
content.add(new JScrollPane(specialExceptions
,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS
,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER)
,"5,2,5,3,t");
generalExceptions.setEnabled(false);
addButton.addActionListener(this);
removeButton.addActionListener(this);
specialExceptions.addListSelectionListener(this);
removeButton.setEnabled(false);
specialExceptions.setFixedCellWidth(200);
specialExceptions.setCellRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
if (value instanceof Date)
value = getRaplaLocale().formatDateLong((Date)value);
return super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
}
});
specialExceptions.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
if (evt.getClickCount()>1) {
removeException();
}
}
});
}
public void mapFromAppointment() {
if (appointment.getRepeating() == null)
specialExceptions.setListData(new Object[0]);
else
specialExceptions.setListData(appointment.getRepeating().getExceptions());
}
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() == addButton) {
addException();
}
if (evt.getSource() == removeButton) {
removeException();
}
}
private void addException() {
Date date = exceptionDate.getDate();
if (appointment.getRepeating().isException(date.getTime())) {
return;
}
appointment.getRepeating().addException(date);
specialExceptions.setListData(appointment.getRepeating().getExceptions());
fireAppointmentChanged();
}
private void removeException() {
if (specialExceptions.getSelectedValue() == null)
return;
appointment.getRepeating().removeException((Date)specialExceptions.getSelectedValue());
specialExceptions.setListData(appointment.getRepeating().getExceptions());
fireAppointmentChanged();
}
public void valueChanged(ListSelectionEvent e) {
if (e.getSource() == specialExceptions) {
removeButton.setEnabled(specialExceptions.getSelectedValue() != null);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -