fable.gui
Class FableManager

java.lang.Object
  extended by fable.gui.FableManager

public class FableManager
extends java.lang.Object

FableManager is the overall Manager class that takes requests from the GUI.

For operations that change the ADT, the FableManager will delegate changes to the ADT For operations that do not change the ADT e.g. Sort, Search etc. the FableManager will return results directly.

FableManager also deals with SWT threading and censorship issues.

Author:
Christopher Moh
Specification Fields

Field Summary
static int searchArticle
           
static int searchKeywords
           
 
Constructor Summary
FableManager(java.lang.String fbmlFile, Display display)
          Creates a FableManager from an fbmlFile and the given GUI display.
 
Method Summary
 boolean accountVerified()
          Checks if the master password was authenticated and not revoked (logged out) at most 10 minutes ago
 void accountVerify(boolean value)
          Sets account verification (meaning that master password was entered)
 void activateCensor()
          Activates the censor
 Feed addCustomFeed(FableComponent root, java.lang.String title)
          Adds a new custom feed
 Feed addCustomFeed(FableComponent root, java.lang.String title, PseudoFeed articles)
          Creates a custom feed with some articles inside
 void addFeed(FableComponent parent, java.net.URL url, java.lang.String title, int refreshTime, int cacheTime)
          Adds a feed given a URL and a title
 boolean addToCustomFeed(Feed feed, PseudoFeed articles)
          Adds articles to a custom feed
 void changeCacheTime(FableComponent f, int newCacheTime)
          Change the cache time of a feed or folder, as well as all of its children
 void changeCustomArticleProperties(Article oldArticle, Article newArticle)
          Edit the properties of a custom article
 boolean changeParent(FableComponent feedOrFolder, FableComponent newParent)
          Change parent of a feed or a folder
 void changeRefreshRate(FableComponent f, int newInterval)
          Change the Refresh Rate of a feed or folder, as well as all of its children.
 void checkRefreshStatus()
          Checks the refresh status of all feeds, and if needs to refresh, queues up a refresh operation on the refresh thread
 void close()
          Closes the FableManager.
 void createFolder(FableComponent parentFolder, java.lang.String name)
          Creates a new folder with a particular name
 void deactivateCensor()
          De-activates the censor
 boolean deleteArticleFromCustomFeed(Article a)
          Removes an article from custom feed
 boolean exportDocument(PseudoFeed feed, java.lang.String title, java.lang.String fileName, java.lang.String fileType)
          Exports a document describing some articles
 void exportFBML(java.lang.String fileName)
          Export everything into an FBML file.
 java.util.List<FeedsterSearchData> feedsterSearch(java.lang.String keyString)
          Returns Feedster search data
 PseudoFeed filterFeed(PseudoFeed feed, FilterStrategy f)
          Filters a feed according to a given strategy
 PseudoFeed getAllArticles(FableComponent f)
          Gets all articles rooted at a particular Folder/Feed
 FableCensor getCensor()
          Returns the censor
 Display getDisplay()
          Returns the GUI display
 java.lang.String getEmailBody(PseudoFeed x)
          Produces an email body from a pseudofeed
 FableComponent getFableComponent(java.lang.String ID)
          Returns the FableComponent given an ID.
 java.lang.String getHTML(FableComponent article)
          Returns the HTML content of an article
 java.lang.String getID(FableComponent f)
          Returns the ID of a particular component.
 java.lang.String getManual()
          Returns the manual's url address
 FableComponent getParent(FableComponent fc)
          Gets the parent of a fableComponent
 int getPosition(FableComponent fc)
          Gets the position of a fableComponent with respect to its parent (is it the 0th, 1st, 2nd, etc.
 FableComponent getRoot()
          Returns the root folder of the Fable hierachy
 java.lang.String getTutorial()
          Returns the quick start in html form
 int getUnReadCount(FableComponent f)
          Returns the number of unread articles rooted at this particular fableComponent
 void importFBML(java.lang.String fileName)
          Imports everything from an FBML file WARNING: This OVERWRITES the existing settings, INCLUDING CENSORSHIP
 void importFeed(Feed feed, FableComponent parent)
          Imports a feed and slowly loads its articles if possible
 boolean isCensorActivated()
          Checks if the censor is activated
 boolean isCustomArticle(Article a)
          Check if an article is a custom article
 boolean isMarkedAs(Article a, Mark m)
          Checks if an article is marked with a particular mark
 boolean isThreadRunning()
          Checks if any thread is running
 void markReadAs(FableComponent fc, boolean mark)
          Mark all children (directly or indirectly) articles as read or unread
 void markStarredAs(FableComponent fc, boolean mark)
          Mark all articles rooted at a particular Component to be mark as starred
 void moveDown(FableComponent feedOrFolder)
          Move a feed or folder downwards in the hierachy
 void moveUp(FableComponent feedOrFolder)
          Move a feed or folder upwards in the hierachy
 java.util.List<Feed> readOPML(java.lang.String fileName)
          Returns a list of feeds in a particular OPML file
 boolean refreshArticle(FableComponent article)
          Refreshes an article
 void refreshFeedOrFolder(FableComponent f)
          Refreshes feeds/folders rooted at that particular feed/folder
 void removeFeedOrFolder(FableComponent f)
          Removes folders / feeds completely.
 void renameFableComponent(FableComponent f, java.lang.String newName)
          Renames a particular fableComponent
 PseudoFeed searchFeed(PseudoFeed articles, java.lang.String keyString, boolean sameSearch, int searchType)
          Searches a list of articles
 boolean sendMail(java.lang.String from, java.lang.String mailAddr, java.lang.String title, java.lang.String body, boolean sendAsText, java.lang.String attachment)
          Sends mail
 void setCensor(FableCensor censor)
          Sets the censor
 void setName(FableComponent feedOrFolder, java.lang.String newName)
          Change the name of a fableComponent
 boolean setPosition(FableComponent fc, int newPosition)
          Sets the position of a fableComponent with relation to its parent
 void writeFBML()
          Call this method just before closing the GUI to write data to the FBMLfile
 void writeOPML(java.util.List<Feed> f, java.lang.String fileName)
          Write a list of feeds to OPML
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

searchKeywords

public static int searchKeywords

searchArticle

public static int searchArticle
Constructor Detail

FableManager

public FableManager(java.lang.String fbmlFile,
                    Display display)
Creates a FableManager from an fbmlFile and the given GUI display. The display links back to the GUI

Requires:
fbmlFile, display != null
Effects:
Initializes the manager
Modifies:
this
Method Detail

writeFBML

public void writeFBML()
Call this method just before closing the GUI to write data to the FBMLfile


close

public void close()
Closes the FableManager. This should only be called when the user closes the program!


getRoot

public FableComponent getRoot()
Returns the root folder of the Fable hierachy

Returns:
this.root

getDisplay

public Display getDisplay()
Returns the GUI display

Returns:
The GUI display

isThreadRunning

public boolean isThreadRunning()
Checks if any thread is running

Returns:
true if either the addThread or refreshThread is running, false otherwise

getCensor

public FableCensor getCensor()
Returns the censor

Returns:
null if no censor exists, otherwise returns this.censor

setCensor

public void setCensor(FableCensor censor)
Sets the censor

Parameters:
censor - New censor
Requires:
censor != null
Effects:
Sets this.censor to censor
Modifies:
censor

activateCensor

public void activateCensor()
Activates the censor

Effects:
Turns censorship on
Modifies:
censorshipStatus

deactivateCensor

public void deactivateCensor()
De-activates the censor

Effects:
Turns censorship off
Modifies:
censorshipStatus

isCensorActivated

public boolean isCensorActivated()
Checks if the censor is activated

Returns:
censorshipStatus

accountVerified

public boolean accountVerified()
Checks if the master password was authenticated and not revoked (logged out) at most 10 minutes ago

Returns:
activationStatus

accountVerify

public void accountVerify(boolean value)
Sets account verification (meaning that master password was entered)

Parameters:
value - true if the master password was entered, false if we should disable a previous verification
Effects:
Authenticate the account if value == true, UnAuthenticate it otherwise, i.e. set activationStatus to value
Modifies:
activationStatus

addFeed

public void addFeed(FableComponent parent,
                    java.net.URL url,
                    java.lang.String title,
                    int refreshTime,
                    int cacheTime)
Adds a feed given a URL and a title

Parameters:
parent - Parent component
url - URL address of the new feed
title - The name of this feed
refreshTime - refresh rate of this feed
cacheTime - cache rate of this feed
Requires:
parent, url, title != null, refreshTime, cacheTime > 0
Effects:
Adds a feed to parent with the given url, title, refresh and cache time
Modifies:
parent

createFolder

public void createFolder(FableComponent parentFolder,
                         java.lang.String name)
Creates a new folder with a particular name

Parameters:
parentFolder - The parent folder of this folder
name - The name of this folder
Requires:
parentFolder, name != null
Effects:
parentFolder now has a new child folder with name name
Modifies:
parentFolder

removeFeedOrFolder

public void removeFeedOrFolder(FableComponent f)
Removes folders / feeds completely. All children will also be removed. They are also detached from the GUI so they no longer listen to events

Parameters:
f - The feed or folder to remove
Requires:
f != null
Effects:
removes f and all its descendents from the main hierarachy and detaches them from the GUI
Modifies:
f and all its descendents

getUnReadCount

public int getUnReadCount(FableComponent f)
Returns the number of unread articles rooted at this particular fableComponent

Parameters:
f - The FableComponent to check from
Returns:
the number of unread articles rooted at f
Requires:
f != null

getAllArticles

public PseudoFeed getAllArticles(FableComponent f)
Gets all articles rooted at a particular Folder/Feed

Parameters:
f - Folder or Feed which is root of all the articles to obtain
Returns:
A PseudoFeed representing all articles
Requires:
f != null

refreshFeedOrFolder

public void refreshFeedOrFolder(FableComponent f)
Refreshes feeds/folders rooted at that particular feed/folder

Parameters:
f - feed/folder to refresh
Requires:
f != null
Effects:
Does a manual refresh of all feeds that are descendents of f
Modifies:
f and all its descendents

checkRefreshStatus

public void checkRefreshStatus()
Checks the refresh status of all feeds, and if needs to refresh, queues up a refresh operation on the refresh thread

Effects:
Refreshes all feeds that are descendents of the root folder if it is time for them to be auto-refreshed
Modifies:
All feeds that are descendents of the root folder

changeRefreshRate

public void changeRefreshRate(FableComponent f,
                              int newInterval)
Change the Refresh Rate of a feed or folder, as well as all of its children.

Parameters:
f - Feed or folder for which all children are to be changed
newInterval - The new refresh rate
Requires:
f != null, newInterval > 0
Effects:
Changes all descendent feeds of f to have refresh time newInterval
Modifies:
f and all its descendents

changeCacheTime

public void changeCacheTime(FableComponent f,
                            int newCacheTime)
Change the cache time of a feed or folder, as well as all of its children

Parameters:
f - Feed or folder for which all children are to be changed
newCacheTime - The new cache time
Requires:
f != null, newCacheTime > 0
Effects:
Changes all the descendent Feeds of f to have newCacheTime as its cache time
Modifies:
f and all its descendents

renameFableComponent

public void renameFableComponent(FableComponent f,
                                 java.lang.String newName)
Renames a particular fableComponent

Parameters:
f - FableComponent to rename
newName - New Name
Requires:
f != null, newName != null
Effects:
changes the name of f to newName
Modifies:
f

setName

public void setName(FableComponent feedOrFolder,
                    java.lang.String newName)
Change the name of a fableComponent

Parameters:
feedOrFolder - The fableComponent to be changed
newName - The new name
Requires:
feedOrFolder != null, newName != null
Effects:
changes the name of feedOrFolder to newName
Modifies:
feedOrFolder

getParent

public FableComponent getParent(FableComponent fc)
Gets the parent of a fableComponent

Parameters:
fc - Returns the parent of a FableComponent
Returns:
parent of FableComponent
Requires:
fc != null

changeParent

public boolean changeParent(FableComponent feedOrFolder,
                            FableComponent newParent)
Change parent of a feed or a folder

Parameters:
feedOrFolder - The feed or folder to change
newParent - The new parent of the feed or folder
Requires:
feedOrFolder, newParent != null
Effects:
feedOrFolder.getParent() == newParent and newParent has feedOrFolder as a child
Modifies:
feedOrFolder, newParent

moveUp

public void moveUp(FableComponent feedOrFolder)
Move a feed or folder upwards in the hierachy

Parameters:
feedOrFolder - feed or folder to move upwards
Requires:
feedOrFolder != null
Effects:
moves feedOrFolder upwards if possible
Modifies:
feedOrFolder

moveDown

public void moveDown(FableComponent feedOrFolder)
Move a feed or folder downwards in the hierachy

Parameters:
feedOrFolder - feed or folder to move downwards
Requires:
feedOrFolder != null
Effects:
moves feedOrFolder downwards if possible
Modifies:
feedOrFolder

getPosition

public int getPosition(FableComponent fc)
Gets the position of a fableComponent with respect to its parent (is it the 0th, 1st, 2nd, etc. child)

Parameters:
fc - FableComponent to check for
Returns:
Position of FableComponent
Requires:
fc != null

setPosition

public boolean setPosition(FableComponent fc,
                           int newPosition)
Sets the position of a fableComponent with relation to its parent

Parameters:
fc - FableComponent
newPosition - new Position with relation to its parent
Returns:
true if position is changed, false otherwise
Requires:
fc != null
Effects:
fc's position with relation to its parent is changed to newPosition
Modifies:
fc

filterFeed

public PseudoFeed filterFeed(PseudoFeed feed,
                             FilterStrategy f)
Filters a feed according to a given strategy

Parameters:
feed - PseudoFeed to filter
f - FilterStrategy
Returns:
A PseudoFeed of filtered articles
Requires:
feed, f != null

searchFeed

public PseudoFeed searchFeed(PseudoFeed articles,
                             java.lang.String keyString,
                             boolean sameSearch,
                             int searchType)
Searches a list of articles

Parameters:
articles - A list of all feeds to search for, in the form of a PseudoFeed
keyString - The string to search for
sameSearch - true if this is continuance of the last search (for incremental searching), false if this is a completely new search
searchType - To determine if we search keywords only, or the whole article. Searching the whole article ALSO searches keywords. This should either be FableManager.searchKeywords or FableManager.searchArticle
Returns:
A PseudoFeed containing the relevant articles. If there is an error during the search, the PseudoFeed is empty
Requires:
articles, keyString != null

markReadAs

public void markReadAs(FableComponent fc,
                       boolean mark)
Mark all children (directly or indirectly) articles as read or unread

Parameters:
fc - component to mark as read
true - or false depending on whether to mark as read or unread (true == read)
Requires:
fc != null
Effects:
All articles of fc are marked as read (if mark == true) or unread (if mark == false)
Modifies:
fc and all its descendents

markStarredAs

public void markStarredAs(FableComponent fc,
                          boolean mark)
Mark all articles rooted at a particular Component to be mark as starred

Parameters:
fc - FableComponent to mark
mark - true if article(s) are to be mark as starred, false if unstarred
Requires:
fc != null
Effects:
All descendent articles of fc are marked as starred (if mark == true) and unstarred (if mark == false)
Modifies:
fc and all its descendents

isMarkedAs

public boolean isMarkedAs(Article a,
                          Mark m)
Checks if an article is marked with a particular mark

Parameters:
a - Article to check
m - Mark to check
Returns:
true if the mark is true, false otherwise
Requires:
a != null

getHTML

public java.lang.String getHTML(FableComponent article)
Returns the HTML content of an article

Parameters:
article - Article to check HTML content of
Returns:
String representation of the HTML content
Requires:
article != null
Effects:
refreshes article so that the latest content is present in it
Modifies:
article

refreshArticle

public boolean refreshArticle(FableComponent article)
Refreshes an article

Parameters:
article - Article to refresh
Requires:
article != null
Effects:
Article's content and keywords are refreshed from the web, if possible
Modifies:
article
Returns:
true if article can be refreshed, false otherwise

getID

public java.lang.String getID(FableComponent f)
Returns the ID of a particular component. This ID is only valid as long as the tree structure does NOT change!

Parameters:
f - Component to get ID from
Returns:
ID Unique ID of the component. Returns null if the component does not belong to the tree structure!
Requires:
f != null

getFableComponent

public FableComponent getFableComponent(java.lang.String ID)
Returns the FableComponent given an ID. If the tree structure is not changed, getFableComponent(getID(x)) == x

Parameters:
ID - ID string obtained previously via getID
Returns:
FableComponent of the given ID, or null if ID is not valid
Requires:
ID != null

readOPML

public java.util.List<Feed> readOPML(java.lang.String fileName)
Returns a list of feeds in a particular OPML file

Parameters:
fileName - OPML file name
Returns:
a list of feeds in the OPML file
Requires:
fileName != null

writeOPML

public void writeOPML(java.util.List<Feed> f,
                      java.lang.String fileName)
Write a list of feeds to OPML

Parameters:
f - List of feeds
fileName - OPML filename
Requires:
f, fileName != null, all Feeds in f != null

importFeed

public void importFeed(Feed feed,
                       FableComponent parent)
Imports a feed and slowly loads its articles if possible

Parameters:
feed - Feed to load
parent - parent of the Feed
Requires:
feed, parent != null
Effects:
parent has an additional child which is feed and feed's parent is parent.
Modifies:
parent, feed

exportFBML

public void exportFBML(java.lang.String fileName)
Export everything into an FBML file. This FBML file only holds feeds and hierachy and settings, no articles

Parameters:
fileName - file to export FBML to
Requires:
fileName != null

importFBML

public void importFBML(java.lang.String fileName)
Imports everything from an FBML file WARNING: This OVERWRITES the existing settings, INCLUDING CENSORSHIP

Parameters:
fileName - Filename to import from
Requires:
fileName != null
Effects:
Changes this.censor to censor in the FBML file, changes all the children of this.root to the children of the root of the FBML file
Modifies:
root, censor

exportDocument

public boolean exportDocument(PseudoFeed feed,
                              java.lang.String title,
                              java.lang.String fileName,
                              java.lang.String fileType)
Exports a document describing some articles

Parameters:
feed - PseudoFeed containing articles to export
title - Title of document
fileName - file name to export to
fileType - file type to export to. Currently only supports ExportDocumentManager.PDF_FORM
Returns:
true if file can be exported, false otherwise
Requires:
feed, title, fileName != null

addCustomFeed

public Feed addCustomFeed(FableComponent root,
                          java.lang.String title)
Adds a new custom feed

Parameters:
root - Root of the custom feed
title - title of the custom feed
Returns:
The Feed that represents this custom Feed, or null if this feed cannot be created
Requires:
root, title != null
Effects:
Adds a blank custom feed (that is returned) to root
Modifies:
root

addCustomFeed

public Feed addCustomFeed(FableComponent root,
                          java.lang.String title,
                          PseudoFeed articles)
Creates a custom feed with some articles inside

Parameters:
root - parent of the new custom feed
title - Title of the new custom feed
articles - Articles to put in the new Custom Feed
Returns:
The custom Feed created, or null if it cannot be created
Requires:
root, title, articles != null
Effects:
Adds a new custom Feed (that is returned) with the required articles to root
Modifies:
root

addToCustomFeed

public boolean addToCustomFeed(Feed feed,
                               PseudoFeed articles)
Adds articles to a custom feed

Parameters:
feed - Feed to add articles to
articles - PseudoFeed containing the articles to be added to feed
Returns:
true if feed can be added, false otherwise
Requires:
feed, articles != null, for all Articles in articles.getChildren(), Articles != null
Effects:
Adds all articles in articles.getChildren() to feed
Modifies:
feed

isCustomArticle

public boolean isCustomArticle(Article a)
Check if an article is a custom article

Parameters:
a - Article
Returns:
true if article belongs to a custom feed, false otherwise
Requires:
a != null

deleteArticleFromCustomFeed

public boolean deleteArticleFromCustomFeed(Article a)
Removes an article from custom feed

Parameters:
a - Article to delete
Returns:
true if article can be deleted, false otherwise
Requires:
a != null
Effects:
Removes a from its parent.
Modifies:
a's parent

changeCustomArticleProperties

public void changeCustomArticleProperties(Article oldArticle,
                                          Article newArticle)
Edit the properties of a custom article

Parameters:
oldArticle - The custom article
newArticle - A new article representing the fields that this article should be changed to
Requires:
oldArticle, newArticle != null
Effects:
Changes the properties of oldArticle to match newArticle
Modifies:
oldArticle

feedsterSearch

public java.util.List<FeedsterSearchData> feedsterSearch(java.lang.String keyString)
Returns Feedster search data

Parameters:
keyString - String to search for
Returns:
List of feeds and titles that the search string matches
Requires:
keyString != null

getEmailBody

public java.lang.String getEmailBody(PseudoFeed x)
Produces an email body from a pseudofeed

Parameters:
x - PseudoFeed to produce body from
Returns:
The email body
Requires:
x != null

sendMail

public boolean sendMail(java.lang.String from,
                        java.lang.String mailAddr,
                        java.lang.String title,
                        java.lang.String body,
                        boolean sendAsText,
                        java.lang.String attachment)
Sends mail

Parameters:
from - Name of person its sent from
mailAddr - Mail Address of person to send to
title - Email subject
body - Email body
sendAsText - Sends as text if true, as html if false
attachment - null if there is no attachment, else attachment is a string representing the file name of the attachment
Returns:
true if mail can be sent, false otherwise
Requires:
from, mailAddr, title, body != null

getTutorial

public java.lang.String getTutorial()
Returns the quick start in html form

Returns:
tutorial

getManual

public java.lang.String getManual()
Returns the manual's url address

Returns:
manual