eTextReader
Class User

java.lang.Object
  extended by eTextReader.User

public class User
extends java.lang.Object

This class stores attributes about a user. This class is a singleton, and a reference to the only instance can be obtained using the static method getUser (). If the user changes, then the method setUser(String) should be called, which will update the attributes to reflect the new user

Changes to information about the user are made using the various setXXX methods in this class. Other objects can learn about changes made through these methods by registering as a property change listener. The available properties are enumerated in the enum Property.

Author:
mcfall

Nested Class Summary
(package private)  class User.HighlighterEntry<K,V>
          Provides a simple implementation of the Map.Entry interface, allowing storage of a key and value pair
static class User.Property
           
 
Field Summary
private  java.util.Map<Notation.AnnotationType,javax.swing.KeyStroke> acceleratorMap
          The keystrokes used as accelerators to create new annotations
private  java.beans.PropertyChangeSupport changeSupport
           
(package private)  DBClient client
           
private  java.lang.String course
          The course associated with the currently loaded textbook
private  OEBPackageFile currentBook
          Maintains a reference to which book is currently open in the browser Debatable as to whether or not this should be a single value, but we're going to go with it
private static java.awt.Color[] defaultHighlightColors
           
private static java.lang.String[] defaultHighlightNames
           
private  float fontSize
          The current font size for the user
private  java.util.Map<java.lang.String,java.awt.Color> highlighterColors
          The set of colors used for highlighters; map is indexed by highlighter name
(package private) static User instance
           
private  boolean notationsEnabled
          Are notations currently enabled for this user?
private  java.util.Hashtable<ApplicationPreferences,java.lang.Object> preferences
          The set of application preferences associated with the current user
private  boolean userHadApplicationPreferences
          Whether a set of application preferences were loaded from the database, or a set was loaded from the database
private  java.lang.String userName
          The user name of the currently logged in user
private  ViewingPrefs viewPreferences
          The set of viewing preferences for the user
private  java.util.Set<java.lang.Integer> visitedLinks
          The links that this user has currently followed
 
Constructor Summary
protected User()
          Constructs a User instance.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a listener to receive property change events for all properties maintained by this object
 void addPropertyChangeListener(User.Property propertyName, java.beans.PropertyChangeListener listener)
          Adds a listener for changes to a specific property, as specified by the propertyName parameter The possible property names are:
 boolean annotationVisisted(int id)
          Determines whether or not the annotation identified by the given id has been previously visited by the current user
 void fireIndexedPropertyChange(User.Property propertyName, int index, boolean oldValue, boolean newValue)
           
 void fireIndexedPropertyChange(User.Property propertyName, int index, int oldValue, int newValue)
           
 void fireIndexedPropertyChange(User.Property propertyName, int index, java.lang.Object oldValue, java.lang.Object newValue)
           
 void firePropertyChange(java.beans.PropertyChangeEvent evt)
           
 void firePropertyChange(User.Property propertyName, boolean oldValue, boolean newValue)
           
 void firePropertyChange(User.Property propertyName, int oldValue, int newValue)
           
 void firePropertyChange(User.Property propertyName, java.lang.Object oldValue, java.lang.Object newValue)
           
 javax.swing.KeyStroke getAccelerator(Notation.AnnotationType annotationType)
          Retrieves the accelerator key used to create a new annotation of the given type
 java.lang.Object getApplicationPreference(ApplicationPreferences preferenceType)
          Return the value of the given preference
 java.util.Hashtable<ApplicationPreferences,java.lang.Object> getApplicationPreferences()
          Returns a Hashtable containing all of the application preferences
 java.lang.String getCourse()
          Return the course associated with the currently open book
 OEBPackageFile getCurrentBook()
           
static java.awt.Color[] getDefaultHighlightColors()
           
static java.lang.String[] getDefaultHighlightNames()
           
 float getFontSize()
          Returns the current font size for the user
 java.awt.Color getHighlighterColor(java.lang.String highlighterName)
           
 java.util.Set<java.util.Map.Entry<java.lang.String,java.awt.Color>> getHighlighters()
          Retrieves the set of highlighters
 java.beans.PropertyChangeListener[] getPropertyChangeListeners()
           
 java.beans.PropertyChangeListener[] getPropertyChangeListeners(User.Property propertyName)
           
static User getUser()
          Returns a User object representing the current user
 java.lang.String getUserName()
          Retrieves the user name of the current user
 ViewingPrefs getViewPreferences()
           
 boolean hasListeners(User.Property propertyName)
           
 boolean isNotationsEnabled()
          Determines whether or not notations are enabled for the current user
 boolean isUserHadApplicationPreferences()
           
private  boolean loadApplicationPreferences()
          Loads the user's application preferences from the database; keys that do not have values are loaded with the default values
private  void loadHighlighters()
          Retrieves the highlighter colors from the database for the current user.
private  void loadViewPreferences()
          Loads the current user's viewing preferences out of the database, and stores them for later use
 void recordAnnotationVisited(int id)
          Records the fact that the specified annotation has been visited by the current user.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void removePropertyChangeListener(User.Property propertyName, java.beans.PropertyChangeListener listener)
           
 void setAccelerator(ApplicationPreferences key, javax.swing.KeyStroke accelerator)
           
 void setAccelerator(Notation.AnnotationType annotationType, javax.swing.KeyStroke keystroke)
           
 void setCourse(java.lang.String course)
          Sets the course associated with the currently open book.
 void setCurrentBook(OEBPackageFile currentBook)
           
 void setFontSize(float fontSize)
          Changes the font size for the current user, in both this object and in the database Fires a property change message with a key of Property.FONT_SIZE
 void setNotationsEnabled(boolean notationsEnabled)
          Enables or disables notations for the current user, in both this object and the database.
 void setUser(java.lang.String userName)
          Changes the identify of the current user.
 boolean updateHighlighters(java.util.List<HighlighterUpdateInfo> updated)
          Updates the highlighter information for each element in the updated list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

static User instance

changeSupport

private java.beans.PropertyChangeSupport changeSupport

defaultHighlightNames

private static java.lang.String[] defaultHighlightNames

defaultHighlightColors

private static java.awt.Color[] defaultHighlightColors

highlighterColors

private java.util.Map<java.lang.String,java.awt.Color> highlighterColors
The set of colors used for highlighters; map is indexed by highlighter name


acceleratorMap

private java.util.Map<Notation.AnnotationType,javax.swing.KeyStroke> acceleratorMap
The keystrokes used as accelerators to create new annotations


userName

private java.lang.String userName
The user name of the currently logged in user


course

private java.lang.String course
The course associated with the currently loaded textbook


visitedLinks

private java.util.Set<java.lang.Integer> visitedLinks
The links that this user has currently followed


viewPreferences

private ViewingPrefs viewPreferences
The set of viewing preferences for the user


preferences

private java.util.Hashtable<ApplicationPreferences,java.lang.Object> preferences
The set of application preferences associated with the current user


userHadApplicationPreferences

private boolean userHadApplicationPreferences
Whether a set of application preferences were loaded from the database, or a set was loaded from the database


currentBook

private OEBPackageFile currentBook
Maintains a reference to which book is currently open in the browser Debatable as to whether or not this should be a single value, but we're going to go with it


notationsEnabled

private boolean notationsEnabled
Are notations currently enabled for this user?


fontSize

private float fontSize
The current font size for the user


client

DBClient client
Constructor Detail

User

protected User()
Constructs a User instance. Method is protected to disallow direct construction of User objects. Instead, use the getUser() method to access the single instance

Method Detail

getUser

public static User getUser()
Returns a User object representing the current user

Returns:
the current user object

getHighlighterColor

public java.awt.Color getHighlighterColor(java.lang.String highlighterName)

updateHighlighters

public boolean updateHighlighters(java.util.List<HighlighterUpdateInfo> updated)
Updates the highlighter information for each element in the updated list. EACH change to a highlighter causes a PropertyChangeEvent to be fired, with the property being HIGHLIGHTER_INFO, the old value being a Map.Entry object containing the old highlighter information, and the new value being a Map.Entry
Parameters:
updated -
Returns:

setUser

public void setUser(java.lang.String userName)
Changes the identify of the current user. All properties in this object are updated to reflect the new user's identity. The only property change event that will be fired will have a key of Property.USER

Parameters:
userName -

loadApplicationPreferences

private boolean loadApplicationPreferences()
Loads the user's application preferences from the database; keys that do not have values are loaded with the default values

Returns:
true if a set of preferences were found in the database, false otherwise

setAccelerator

public void setAccelerator(Notation.AnnotationType annotationType,
                           javax.swing.KeyStroke keystroke)

setAccelerator

public void setAccelerator(ApplicationPreferences key,
                           javax.swing.KeyStroke accelerator)

loadViewPreferences

private void loadViewPreferences()
Loads the current user's viewing preferences out of the database, and stores them for later use


loadHighlighters

private void loadHighlighters()
Retrieves the highlighter colors from the database for the current user. If no highlighters exist for that user, then the defaults are set


getHighlighters

public java.util.Set<java.util.Map.Entry<java.lang.String,java.awt.Color>> getHighlighters()
Retrieves the set of highlighters

Returns:
A set of Name, Color pairs, in alphabetical order by the name

getUserName

public java.lang.String getUserName()
Retrieves the user name of the current user

Returns:

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a listener to receive property change events for all properties maintained by this object

Parameters:
listener -

addPropertyChangeListener

public void addPropertyChangeListener(User.Property propertyName,
                                      java.beans.PropertyChangeListener listener)
Adds a listener for changes to a specific property, as specified by the propertyName parameter The possible property names are:

Parameters:
propertyName -
listener -

fireIndexedPropertyChange

public void fireIndexedPropertyChange(User.Property propertyName,
                                      int index,
                                      boolean oldValue,
                                      boolean newValue)

fireIndexedPropertyChange

public void fireIndexedPropertyChange(User.Property propertyName,
                                      int index,
                                      int oldValue,
                                      int newValue)

fireIndexedPropertyChange

public void fireIndexedPropertyChange(User.Property propertyName,
                                      int index,
                                      java.lang.Object oldValue,
                                      java.lang.Object newValue)

firePropertyChange

public void firePropertyChange(java.beans.PropertyChangeEvent evt)

firePropertyChange

public void firePropertyChange(User.Property propertyName,
                               boolean oldValue,
                               boolean newValue)

firePropertyChange

public void firePropertyChange(User.Property propertyName,
                               int oldValue,
                               int newValue)

firePropertyChange

public void firePropertyChange(User.Property propertyName,
                               java.lang.Object oldValue,
                               java.lang.Object newValue)

getPropertyChangeListeners

public java.beans.PropertyChangeListener[] getPropertyChangeListeners()

getPropertyChangeListeners

public java.beans.PropertyChangeListener[] getPropertyChangeListeners(User.Property propertyName)

hasListeners

public boolean hasListeners(User.Property propertyName)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(User.Property propertyName,
                                         java.beans.PropertyChangeListener listener)

getDefaultHighlightColors

public static java.awt.Color[] getDefaultHighlightColors()

getDefaultHighlightNames

public static java.lang.String[] getDefaultHighlightNames()

getCurrentBook

public OEBPackageFile getCurrentBook()

setCurrentBook

public void setCurrentBook(OEBPackageFile currentBook)

getViewPreferences

public ViewingPrefs getViewPreferences()

isNotationsEnabled

public boolean isNotationsEnabled()
Determines whether or not notations are enabled for the current user

Returns:
true if notations should be displayed for the current user, false otherwise

setNotationsEnabled

public void setNotationsEnabled(boolean notationsEnabled)
Enables or disables notations for the current user, in both this object and the database. A property change will be fired with a key of Property.NOTATIONS_ENABLED

Parameters:
notationsEnabled -

getFontSize

public float getFontSize()
Returns the current font size for the user

Returns:

setFontSize

public void setFontSize(float fontSize)
Changes the font size for the current user, in both this object and in the database Fires a property change message with a key of Property.FONT_SIZE

Parameters:
fontSize -

getAccelerator

public javax.swing.KeyStroke getAccelerator(Notation.AnnotationType annotationType)
Retrieves the accelerator key used to create a new annotation of the given type

Parameters:
annotationType - the type of annotation that is being created
Returns:
a KeyStroke object that is the accelerator, or null if no accelerator exists

getApplicationPreferences

public java.util.Hashtable<ApplicationPreferences,java.lang.Object> getApplicationPreferences()
Returns a Hashtable containing all of the application preferences

Returns:

getApplicationPreference

public java.lang.Object getApplicationPreference(ApplicationPreferences preferenceType)
Return the value of the given preference

Parameters:
preferenceType -
Returns:
an Object which is the value for the given preference

getCourse

public java.lang.String getCourse()
Return the course associated with the currently open book

Returns:

setCourse

public void setCourse(java.lang.String course)
Sets the course associated with the currently open book. Fires a property change message with a key of Property.COURSE

Parameters:
course - the identifier for the new course

annotationVisisted

public boolean annotationVisisted(int id)
Determines whether or not the annotation identified by the given id has been previously visited by the current user

Parameters:
id - the id of an annotation.

recordAnnotationVisited

public void recordAnnotationVisited(int id)
Records the fact that the specified annotation has been visited by the current user. It is only recorded locally, as it is assumed that the database log keeps track of this information. A PropertyChange event is generated with key LINKS_VISISTED and new value being the integer ID of the link that was visited. The old value is null, since it is not really meaningful.

Parameters:
id - the id of an annotation

isUserHadApplicationPreferences

public boolean isUserHadApplicationPreferences()