diff options
| author | Paul Buetow <paul@buetow.org> | 2009-02-18 23:01:21 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2009-02-18 23:01:21 +0000 |
| commit | 89c679eb813611a2ede208b4c8e27c7f596b3be7 (patch) | |
| tree | f44c19435286e78b9e8002990e1b55183a4fbc49 /sources/shared/CalendarEvent.java | |
| parent | 177f346a9bbe455dc12fd26dfa2c586585c28c1e (diff) | |
added copyright to header
Diffstat (limited to 'sources/shared/CalendarEvent.java')
| -rw-r--r-- | sources/shared/CalendarEvent.java | 648 |
1 files changed, 326 insertions, 322 deletions
diff --git a/sources/shared/CalendarEvent.java b/sources/shared/CalendarEvent.java index 9a54237..8558d91 100644 --- a/sources/shared/CalendarEvent.java +++ b/sources/shared/CalendarEvent.java @@ -1,3 +1,7 @@ +/* NetCalendar 2006, 2009 (c) Dipl.-Inform. (FH) Paul C. Buetow + * http://netcalendar.buetow.org - netcalendar@dev.buetow.org + */ + /** * */ @@ -14,326 +18,326 @@ import java.io.*; * */ public class CalendarEvent implements Serializable { - private static final long serialVersionUID = 1L; - private MyDate date; - private CalendarCategory category; - private String sCategoryName; - private String sDescription; - private String sPlace; - private boolean bYearly; - private int iEventID; - - static private int iEventIDCount = 0; - - /** - * Simple constructor, creates an event object and increments iEventIDCount by one. - * @param category Specifies the event's category. - */ - public CalendarEvent(CalendarCategory category) { - setCategory(category); - setEventID(iEventIDCount++); - setYearly(false); - } - - /** - * Simple constructor, creates an event object and increments iEventIDCount by one. - * @param sCategoryName Specifies the event's category name. - */ - public CalendarEvent(String sCategoryName) { - setCategoryName(sCategoryName.trim()); - setEventID(iEventIDCount++); - setYearly(false); - } - - /** - * This method sets the event's date. - * @param date Specifies the event's date. - */ - public void setDate(Date date) { - if (date instanceof MyDate) - this.date = (MyDate) date; - else - this.date = new MyDate(date); - } - - /** - * This method sets the event's category. - * @param category Specifies the event's category. - */ - public void setCategory(CalendarCategory category) { - this.category = category; - setCategoryName(category.getName()); - } - - /** - * This event returns the event's calendar category. - * @return Returns the event's calenda category. - */ - public CalendarCategory getCategory() { - return category; - } - - /** - * This methos sets thhe event's category name. - * @param sCategoryName Specifies the event's category name. - */ - public void setCategoryName(String sCategoryName) { - this.sCategoryName = sCategoryName.trim(); - } - - /** - * This method sets the event's descriptions tring. - * @param sDescription Specifies the event's description string. - */ - public void setDescription(String sDescription) { - this.sDescription = sDescription.trim(); - } - - /** - * This method sets the event's place string. - * @param sPlace Specifies the event's place string. - */ - public void setPlace(String sPlace) { - this.sPlace = sPlace.trim(); - } - - /** - * This method sets the event's ID number. - * @param iEventID specifies the event's ID number. - */ - public void setEventID(int iEventID) { - this.iEventID = iEventID; - } - - /** - * This method specifies if this event occurs yearly or not. - * @param bYearly Specifies if this event occury yearly or not. - */ - public void setYearly(boolean bYearly) { - this.bYearly = bYearly; - } - - /** - * This method returns the event's category name. - * @return Returns the event's category name. - */ - public String getCategoryName() { - return sCategoryName; - } - - /** - * This method returns the event's description string. - * @return Returns the event's description string. - */ - public String getDescription() { - return sDescription; - } - - /** - * This method returns the event's place string. - * @return Returns the event's place string. - */ - public String getPlace() { - return sPlace; - } - - /** - * This method returns the event's ID. - * @return Returns the event's ID. - */ - public int getID() { - return iEventID; - } - - /** - * This method returns the event's date object. - * @return Returns the event's date object. - */ - public MyDate getDate() { - return date; - } - - /** - * This method returns the event's ID number. - * @return Returns the event's ID number. - */ - public int getEventID() { - return iEventID; - } - - /** - * This method checks if this event occurs yearly or not. - * @return Returns true if the event occurs yearly, else it returns false. - */ - public boolean isYearly() { - return bYearly; - } - - /** - * Checks if the current event matches all available data of the event agains - * a given regular expression pattern. - * @param pattern Specifies the pattern to match against. - * @return Returns true if one element of the event matches. - */ - public boolean matches(Pattern pattern) { - if (pattern == null) - return false; - - else if (matchesDescription(pattern)) - return true; - - else if (matchesPlace(pattern)) - return true; - - else if (matchesCategoryName(pattern)) - return true; - - return matchesDateString(pattern); - } - - /** - * Checks if the current event's name matches agains a regular expression pattern. - * @param pattern Specifies the pattern to be matched against. - * @return Returns true if the event matches, else false will be returned. If the pattern is null, true will be returned. - */ - public boolean matchesCategoryName(Pattern pattern) { - if (pattern == null) - return true; - - return pattern.matcher(getCategoryName()).find(); - } - - /** - * Checks if the current event's description string matches agains a regular expression pattern. - * @param pattern Specifies the pattern to match against. - * @return Returns true if the event matches, else false will be returned. If the pattern is null, true will be returned. - */ - public boolean matchesDescription(Pattern pattern) { - if (pattern == null) - return true; - - return pattern.matcher(getDescription()).find(); - } - - /** - * Checks if the current event's place string matches agains a regular expression pattern. - * @param pattern Specifies the pattern to match against. - * @return Returns true if the event matches, else false will be returned. If the pattern is null, true will be returned. - */ - public boolean matchesPlace(Pattern pattern) { - if (pattern == null) - return true; - - return pattern.matcher(getPlace()).find(); - } - - /** - * Checks if the current event's category name matches agains a regular expression pattern - * @param pattern Specifies the pattern to match against. - * @return Returns true if the event matches, else false will be returned. If the pattern is null, true will be returned. - */ - public boolean matchesCategory(Pattern pattern) { - if (pattern == null) - return true; - - return pattern.matcher(getCategoryName()).find(); - } - - /** - * Checks if the current event's date string matches agains a regular expression pattern - * @param pattern Specifies the pattern to match against. - * @return Returns true if the event matches, else false will be returned. If the pattern is null, true will be returned. - */ - public boolean matchesDateString(Pattern pattern) { - if (pattern == null) - return true; - - return pattern.matcher(getDate().toString()).find(); - } - - /** - * Needed for ojbect serialization (sending part)- - * @param objectOutputStream Specifies the output stream to use. - * @throws IOException - */ - private void writeObject(ObjectOutputStream objectOutputStream) - throws IOException { - objectOutputStream.writeInt(iEventID); - objectOutputStream.writeBoolean(isYearly()); - objectOutputStream.writeObject(getDate()); - objectOutputStream.writeObject(getCategoryName()); - objectOutputStream.writeObject(getDescription()); - objectOutputStream.writeObject(getPlace()); - } - - /** - * Needed for object serialization (receiving part). - * @param objectInputStream Specifies the input stream to use. - * @throws IOException - * @throws ClassNotFoundException - */ - private void readObject(ObjectInputStream objectInputStream) - throws IOException, ClassNotFoundException { - setEventID(objectInputStream.readInt()); - setYearly(objectInputStream.readBoolean()); - setDate((Date) objectInputStream.readObject()); - setCategoryName((String) objectInputStream.readObject()); - setDescription((String) objectInputStream.readObject()); - setPlace((String) objectInputStream.readObject()); - - if (getEventID() < 0 ) - setEventID(iEventIDCount++); - } - - /** - * Removes the calendar event from its current category and sets the - * category reference to null. - */ - public void removeFromCurrentCategory() { - CalendarCategory category = getCategory(); - category.removeEvent(this); - } - - /** - * This method flushes the calendar event to the database at the filesystem. - * @param bufferedWriter Specifies the buffered writer to write to. - */ - protected void flush(BufferedWriter bufferedWriter) throws IOException { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(getDate()); - int iYear = calendar.get(Calendar.YEAR); - // if (iYear < 11) iYear += 2000; - int iMonth = calendar.get(Calendar.MONTH) + 1; - int iDays = calendar.get(Calendar.DAY_OF_MONTH); - int iHours= calendar.get(Calendar.HOUR); - int iMinutes = calendar.get(Calendar.MINUTE); - - String sPlace = getPlace(); - if (!sPlace.equals("")) - sPlace = ";;" + sPlace; - - String sYearly = isYearly() ? "yearly" : MyDate.addZerosToFront(iYear, 4); - String sEventLine = - MyDate.addZerosToFront(iMonth, 2) + "/" - + MyDate.addZerosToFront(iDays, 2) + "\t" - + sYearly + "-" - + MyDate.addZerosToFront(iHours, 2) + ":" - + MyDate.addZerosToFront(iMinutes, 2) + " " - + getDescription() - + sPlace + "\n"; - - bufferedWriter.write(sEventLine); - } - - /** - * This method is needed for a text representation of the object. - * @return Returns object represented as a String. - */ - public String toString() { - return "#" + getEventID() + " " + getDate() + "\n" - + "Yearly : " + isYearly() + "\n" - + "Category : " + getCategoryName() + "\n" - + "Description: " + getDescription() + "\n" - + "Place : " + getPlace() + "\n"; - } + private static final long serialVersionUID = 1L; + private MyDate date; + private CalendarCategory category; + private String sCategoryName; + private String sDescription; + private String sPlace; + private boolean bYearly; + private int iEventID; + + static private int iEventIDCount = 0; + + /** + * Simple constructor, creates an event object and increments iEventIDCount by one. + * @param category Specifies the event's category. + */ + public CalendarEvent(CalendarCategory category) { + setCategory(category); + setEventID(iEventIDCount++); + setYearly(false); + } + + /** + * Simple constructor, creates an event object and increments iEventIDCount by one. + * @param sCategoryName Specifies the event's category name. + */ + public CalendarEvent(String sCategoryName) { + setCategoryName(sCategoryName.trim()); + setEventID(iEventIDCount++); + setYearly(false); + } + + /** + * This method sets the event's date. + * @param date Specifies the event's date. + */ + public void setDate(Date date) { + if (date instanceof MyDate) + this.date = (MyDate) date; + else + this.date = new MyDate(date); + } + + /** + * This method sets the event's category. + * @param category Specifies the event's category. + */ + public void setCategory(CalendarCategory category) { + this.category = category; + setCategoryName(category.getName()); + } + + /** + * This event returns the event's calendar category. + * @return Returns the event's calenda category. + */ + public CalendarCategory getCategory() { + return category; + } + + /** + * This methos sets thhe event's category name. + * @param sCategoryName Specifies the event's category name. + */ + public void setCategoryName(String sCategoryName) { + this.sCategoryName = sCategoryName.trim(); + } + + /** + * This method sets the event's descriptions tring. + * @param sDescription Specifies the event's description string. + */ + public void setDescription(String sDescription) { + this.sDescription = sDescription.trim(); + } + + /** + * This method sets the event's place string. + * @param sPlace Specifies the event's place string. + */ + public void setPlace(String sPlace) { + this.sPlace = sPlace.trim(); + } + + /** + * This method sets the event's ID number. + * @param iEventID specifies the event's ID number. + */ + public void setEventID(int iEventID) { + this.iEventID = iEventID; + } + + /** + * This method specifies if this event occurs yearly or not. + * @param bYearly Specifies if this event occury yearly or not. + */ + public void setYearly(boolean bYearly) { + this.bYearly = bYearly; + } + + /** + * This method returns the event's category name. + * @return Returns the event's category name. + */ + public String getCategoryName() { + return sCategoryName; + } + + /** + * This method returns the event's description string. + * @return Returns the event's description string. + */ + public String getDescription() { + return sDescription; + } + + /** + * This method returns the event's place string. + * @return Returns the event's place string. + */ + public String getPlace() { + return sPlace; + } + + /** + * This method returns the event's ID. + * @return Returns the event's ID. + */ + public int getID() { + return iEventID; + } + + /** + * This method returns the event's date object. + * @return Returns the event's date object. + */ + public MyDate getDate() { + return date; + } + + /** + * This method returns the event's ID number. + * @return Returns the event's ID number. + */ + public int getEventID() { + return iEventID; + } + + /** + * This method checks if this event occurs yearly or not. + * @return Returns true if the event occurs yearly, else it returns false. + */ + public boolean isYearly() { + return bYearly; + } + + /** + * Checks if the current event matches all available data of the event agains + * a given regular expression pattern. + * @param pattern Specifies the pattern to match against. + * @return Returns true if one element of the event matches. + */ + public boolean matches(Pattern pattern) { + if (pattern == null) + return false; + + else if (matchesDescription(pattern)) + return true; + + else if (matchesPlace(pattern)) + return true; + + else if (matchesCategoryName(pattern)) + return true; + + return matchesDateString(pattern); + } + + /** + * Checks if the current event's name matches agains a regular expression pattern. + * @param pattern Specifies the pattern to be matched against. + * @return Returns true if the event matches, else false will be returned. If the pattern is null, true will be returned. + */ + public boolean matchesCategoryName(Pattern pattern) { + if (pattern == null) + return true; + + return pattern.matcher(getCategoryName()).find(); + } + + /** + * Checks if the current event's description string matches agains a regular expression pattern. + * @param pattern Specifies the pattern to match against. + * @return Returns true if the event matches, else false will be returned. If the pattern is null, true will be returned. + */ + public boolean matchesDescription(Pattern pattern) { + if (pattern == null) + return true; + + return pattern.matcher(getDescription()).find(); + } + + /** + * Checks if the current event's place string matches agains a regular expression pattern. + * @param pattern Specifies the pattern to match against. + * @return Returns true if the event matches, else false will be returned. If the pattern is null, true will be returned. + */ + public boolean matchesPlace(Pattern pattern) { + if (pattern == null) + return true; + + return pattern.matcher(getPlace()).find(); + } + + /** + * Checks if the current event's category name matches agains a regular expression pattern + * @param pattern Specifies the pattern to match against. + * @return Returns true if the event matches, else false will be returned. If the pattern is null, true will be returned. + */ + public boolean matchesCategory(Pattern pattern) { + if (pattern == null) + return true; + + return pattern.matcher(getCategoryName()).find(); + } + + /** + * Checks if the current event's date string matches agains a regular expression pattern + * @param pattern Specifies the pattern to match against. + * @return Returns true if the event matches, else false will be returned. If the pattern is null, true will be returned. + */ + public boolean matchesDateString(Pattern pattern) { + if (pattern == null) + return true; + + return pattern.matcher(getDate().toString()).find(); + } + + /** + * Needed for ojbect serialization (sending part)- + * @param objectOutputStream Specifies the output stream to use. + * @throws IOException + */ + private void writeObject(ObjectOutputStream objectOutputStream) + throws IOException { + objectOutputStream.writeInt(iEventID); + objectOutputStream.writeBoolean(isYearly()); + objectOutputStream.writeObject(getDate()); + objectOutputStream.writeObject(getCategoryName()); + objectOutputStream.writeObject(getDescription()); + objectOutputStream.writeObject(getPlace()); + } + + /** + * Needed for object serialization (receiving part). + * @param objectInputStream Specifies the input stream to use. + * @throws IOException + * @throws ClassNotFoundException + */ + private void readObject(ObjectInputStream objectInputStream) + throws IOException, ClassNotFoundException { + setEventID(objectInputStream.readInt()); + setYearly(objectInputStream.readBoolean()); + setDate((Date) objectInputStream.readObject()); + setCategoryName((String) objectInputStream.readObject()); + setDescription((String) objectInputStream.readObject()); + setPlace((String) objectInputStream.readObject()); + + if (getEventID() < 0 ) + setEventID(iEventIDCount++); + } + + /** + * Removes the calendar event from its current category and sets the + * category reference to null. + */ + public void removeFromCurrentCategory() { + CalendarCategory category = getCategory(); + category.removeEvent(this); + } + + /** + * This method flushes the calendar event to the database at the filesystem. + * @param bufferedWriter Specifies the buffered writer to write to. + */ + protected void flush(BufferedWriter bufferedWriter) throws IOException { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(getDate()); + int iYear = calendar.get(Calendar.YEAR); + // if (iYear < 11) iYear += 2000; + int iMonth = calendar.get(Calendar.MONTH) + 1; + int iDays = calendar.get(Calendar.DAY_OF_MONTH); + int iHours= calendar.get(Calendar.HOUR); + int iMinutes = calendar.get(Calendar.MINUTE); + + String sPlace = getPlace(); + if (!sPlace.equals("")) + sPlace = ";;" + sPlace; + + String sYearly = isYearly() ? "yearly" : MyDate.addZerosToFront(iYear, 4); + String sEventLine = + MyDate.addZerosToFront(iMonth, 2) + "/" + + MyDate.addZerosToFront(iDays, 2) + "\t" + + sYearly + "-" + + MyDate.addZerosToFront(iHours, 2) + ":" + + MyDate.addZerosToFront(iMinutes, 2) + " " + + getDescription() + + sPlace + "\n"; + + bufferedWriter.write(sEventLine); + } + + /** + * This method is needed for a text representation of the object. + * @return Returns object represented as a String. + */ + public String toString() { + return "#" + getEventID() + " " + getDate() + "\n" + + "Yearly : " + isYearly() + "\n" + + "Category : " + getCategoryName() + "\n" + + "Description: " + getDescription() + "\n" + + "Place : " + getPlace() + "\n"; + } } |
