📄 defaultdateselectionmodel.java
字号:
} /* (non-Javadoc) * @see net.sf.nachocalendar.model.DateSelectionModel#setValueIsAdjusting(boolean) */ public void setValueIsAdjusting(boolean b) { // empty method } /* (non-Javadoc) * @see net.sf.nachocalendar.model.DateSelectionModel#getValueIsAdjusting() */ public boolean getValueIsAdjusting() { // empty method return false; } } private static class SingleInterval implements DateSelectionModel { private Date from, to, lead; /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#addSelectionInterval(java.util.Date, * java.util.Date) */ public void addSelectionInterval(Date from, Date to) { if ((from == null) || (to == null)) { this.from = null; this.to = null; return; } if (from.after(to)) { this.from = to; this.to = from; } else { this.from = from; this.to = to; } lead = to; } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#clearSelection() */ public void clearSelection() { from = null; to = null; } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#isSelectedDate(java.util.Date) */ public boolean isSelectedDate(Date date) { if ((from == null) || (to == null)) return false; if (date == null) return false; if (CalendarUtils.isSameDay(date,from) || CalendarUtils.isSameDay(date, to)) return true; if ((date.before(from)) || date.after(to)) return false; return true; } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#isSelectionEmpty() */ public boolean isSelectionEmpty() { return ((from == null) || (to == null)); } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#removeSelectionInterval(java.util.Date, * java.util.Date) */ public void removeSelectionInterval(Date from, Date to) { } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#addDateSelectionListener(net.sf.nachocalendar.event.DateSelectionListener) */ public void addDateSelectionListener(DateSelectionListener listener) { } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#removeDateSelectionListener(net.sf.nachocalendar.event.DateSelectionListener) */ public void removeDateSelectionListener(DateSelectionListener listener) { } /** * @return */ public int getSelectionMode() { return SINGLE_INTERVAL_SELECTION; } /** * @param selectionMode */ public void setSelectionMode(int selectionMode) { } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#getLeadSelectionDate() */ public Date getLeadSelectionDate() { return lead; } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#setLeadSelectionDate(java.util.Date) */ public void setLeadSelectionDate(Date date) { lead = date; } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#getSelectedDate() */ public Object getSelectedDate() { return lead; } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#getSelectedDates() */ public Object[] getSelectedDates() { return getDates(from, to); } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#setSelectedDate(java.lang.Object) */ public void setSelectedDate(Object date) { try { from = CalendarUtils.convertToDate(date); to = from; } catch (ParseException e) { e.printStackTrace(); } } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#setSelectedDates(java.lang.Object[]) */ public void setSelectedDates(Object[] dates) { if ((dates == null) || (dates.length < 1)) { from = null; to = null; return; } try { from = CalendarUtils.convertToDate(dates[0]); to = CalendarUtils.convertToDate(dates[dates.length - 1]); } catch (ParseException e) { e.printStackTrace(); } } /* (non-Javadoc) * @see net.sf.nachocalendar.model.DateSelectionModel#setValueIsAdjusting(boolean) */ public void setValueIsAdjusting(boolean b) { // empty method } /* (non-Javadoc) * @see net.sf.nachocalendar.model.DateSelectionModel#getValueIsAdjusting() */ public boolean getValueIsAdjusting() { // empty method return false; } } private static class MultipleInterval implements DateSelectionModel { private List selection; private Calendar calendar; private Date leadSelection; MultipleInterval() { selection = new ArrayList(); calendar = new GregorianCalendar(); } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#addSelectionInterval(java.util.Date, * java.util.Date) */ public void addSelectionInterval(Date from, Date to) { if ((from == null) || (to == null)) return; Date d1 = null; Date d2 = null; if (from.before(to)) { d1 = from; d2 = to; } else { d1 = to; d2 = from; } calendar.setTime(d1); do { selection.add(calendar.getTime()); calendar.add(Calendar.DAY_OF_YEAR, 1); } while ((d2.after(calendar.getTime())) || (CalendarUtils.isSameDay(d2, calendar.getTime()))); leadSelection = to; } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#clearSelection() */ public void clearSelection() { selection.clear(); } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#isSelectedDate(java.util.Date) */ public boolean isSelectedDate(Date date) { if (selection.isEmpty()) return false; if (date == null) return false; Iterator it = selection.iterator(); while (it.hasNext()) { Date d = (Date) it.next(); if (CalendarUtils.isSameDay(d, date)) return true; } return false; } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#isSelectionEmpty() */ public boolean isSelectionEmpty() { return selection.isEmpty(); } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#removeSelectionInterval(java.util.Date, * java.util.Date) */ public void removeSelectionInterval(Date from, Date to) { if ((from == null) || (to == null)) return; if ((from == null) || (to == null)) return; Object[] dates = getDates(from, to); for (int i = 0; i < dates.length; i++) { Iterator it = selection.iterator(); Date d = (Date) dates[i]; while (it.hasNext()) { Date dd = (Date) it.next(); if (CalendarUtils.isSameDay(d, dd)) { selection.remove(dd); break; } } } leadSelection = to; } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#addDateSelectionListener(net.sf.nachocalendar.event.DateSelectionListener) */ public void addDateSelectionListener(DateSelectionListener listener) { } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#removeDateSelectionListener(net.sf.nachocalendar.event.DateSelectionListener) */ public void removeDateSelectionListener(DateSelectionListener listener) { } /** * @return */ public int getSelectionMode() { return MULTIPLE_INTERVAL_SELECTION; } /** * @param selectionMode */ public void setSelectionMode(int selectionMode) { } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#getLeadSelectionDate() */ public Date getLeadSelectionDate() { return leadSelection; } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#setLeadSelectionDate(java.util.Date) */ public void setLeadSelectionDate(Date date) { leadSelection = date; } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#getSelectedDate() */ public Object getSelectedDate() { if (selection.isEmpty()) return null; return leadSelection; } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#getSelectedDates() */ public Object[] getSelectedDates() { Collections.sort(selection); return selection.toArray(); } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#setSelectedDate(java.lang.Object) */ public void setSelectedDate(Object date) { selection.clear(); if (date != null) { try { selection.add(CalendarUtils.convertToDate(date)); } catch (ParseException e) { e.printStackTrace(); } } } /* * (non-Javadoc) * * @see net.sf.nachocalendar.model.DateSelectionModel#setSelectedDates(java.lang.Object[]) */ public void setSelectedDates(Object[] dates) { selection.clear(); if ((dates == null) || (dates.length < 1)) return; for (int i = 0; i < dates.length; i++) { try { selection.add(CalendarUtils.convertToDate(dates[i])); } catch (ParseException e) { e.printStackTrace(); } } } /* (non-Javadoc) * @see net.sf.nachocalendar.model.DateSelectionModel#setValueIsAdjusting(boolean) */ public void setValueIsAdjusting(boolean b) { // empty method } /* (non-Javadoc) * @see net.sf.nachocalendar.model.DateSelectionModel#getValueIsAdjusting() */ public boolean getValueIsAdjusting() { // empty method return false; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -