com.levigo.jadice.demo.flextree
Class ReadStateModule

java.lang.Object
  extended by com.levigo.jadice.demo.flextree.ReadStateModule
All Implemented Interfaces:
DynamicTreeModule, TreeIconProvider, TreeLabelProvider, TreeModule

public class ReadStateModule
extends Object
implements DynamicTreeModule, TreeIconProvider, TreeLabelProvider

A TreeModule used track which Documents in a tree have been seen/read by the user. Documents may be marked as read/unread manually using setRead(Document)/ setUnread(Document). However, it is preferable to automate the process of marking them read by installing a read tracker using installReadTracker(PageView, long, TimeUnit) which will automatically mark a document read after it has been displayed for some time within a PageView. Thanks go out to our customer CP for the inspiration to this module.


Nested Class Summary
static interface ReadStateModule.ReadTracker
          This interface represents an installed read tracker.
 
Nested classes/interfaces inherited from interface com.levigo.util.swing.flextree.DynamicTreeModule
DynamicTreeModule.TreeCallback
 
Constructor Summary
ReadStateModule()
           
 
Method Summary
 Icon getIcon(TreePath path)
           
 Icon getReadIcon()
          Get the icon to apply to read documents.
 String getReadLabelPrefix()
          Get the prefix to add to the label for read documents.
 AttributeSet getReadLabelStyle()
          Get the styling to apply to the node's label for read documents.
 Icon getUnreadIcon()
          Get the icon to apply to unread documents.
 String getUnreadLabelPrefix()
          Get the prefix to add to the label for unread documents.
 AttributeSet getUnreadLabelStyle()
          Get the styling to apply to the node's label for unread documents.
static ReadStateModule.ReadTracker installReadTracker(PageView pageView, long duration, TimeUnit timeUnit)
          Install a read tracker that monitors the given PageView and marks documents, which have been shown for at least the given duration, as read.
static boolean isRead(Document doc)
          Determine whether the given document is considered to be read.
 Disposable registerTreeCallback(TreePath treePath, DynamicTreeModule.TreeCallback callback)
          This method is called in order to supply the tree module with a DynamicTreeModule.TreeCallback for the given treePath.
static void setRead(Document doc)
          Mark the given document as having been read.
 void setReadIcon(Icon readIcon)
          Set the icon to apply to read documents.
 void setReadLabelPrefix(String readLabelPrefix)
          Set the prefix to add to the label for read documents.
 void setReadLabelStyle(AttributeSet readLabelStyle)
          Set the styling to apply to the node's label for read documents.
static void setUnread(Document doc)
          Mark the given document as unread.
 void setUnreadIcon(Icon unreadIcon)
          Set the icon to apply to unread documents.
 void setUnreadLabelPrefix(String unreadLabelPrefix)
          Set the prefix to add to the label for unread documents.
 void setUnreadLabelStyle(AttributeSet unreadLabelStyle)
          Set the styling to apply to the node's label for unread documents.
 void updateLabel(TreePath path, StyledDocument doc)
           
protected  void updateLabelForReadDocument(TreePath path, StyledDocument doc)
          Apply the label decoration and style for read documents.
protected  void updateLabelForUnreadDocument(TreePath path, StyledDocument doc)
          Apply the label decoration and style for unread documents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadStateModule

public ReadStateModule()
Method Detail

isRead

public static boolean isRead(Document doc)
Determine whether the given document is considered to be read.

Parameters:
doc - the document to check
Returns:
true, if the document is considered to be read, false otherwise.

setRead

public static void setRead(Document doc)
Mark the given document as having been read.

Parameters:
doc -

setUnread

public static void setUnread(Document doc)
Mark the given document as unread.

Parameters:
doc -

installReadTracker

public static ReadStateModule.ReadTracker installReadTracker(PageView pageView,
                                                             long duration,
                                                             TimeUnit timeUnit)
Install a read tracker that monitors the given PageView and marks documents, which have been shown for at least the given duration, as read.

Parameters:
pageView - the PageView to monitor
duration - the duration after which a shown document is marked as read
timeUnit - the unit of the duration
Returns:
the installed ReadTracker

getIcon

public Icon getIcon(TreePath path)
Specified by:
getIcon in interface TreeIconProvider

updateLabel

public void updateLabel(TreePath path,
                        StyledDocument doc)
                 throws BadLocationException
Specified by:
updateLabel in interface TreeLabelProvider
Throws:
BadLocationException

updateLabelForReadDocument

protected void updateLabelForReadDocument(TreePath path,
                                          StyledDocument doc)
                                   throws BadLocationException
Apply the label decoration and style for read documents. Override this method in order to gain finer control over the changes applied to the label. By default this method will insert the readLabelPrefix (unless it is null ) and apply the readLabelStyle (unless it is null).

Parameters:
path -
doc -
Throws:
BadLocationException

updateLabelForUnreadDocument

protected void updateLabelForUnreadDocument(TreePath path,
                                            StyledDocument doc)
                                     throws BadLocationException
Apply the label decoration and style for unread documents. Override this method in order to gain finer control over the changes applied to the label. By default this method will insert the unreadLabelPrefix (unless it is null) and apply the unreadLabelStyle (unless it is null).

Parameters:
path -
doc -
Throws:
BadLocationException

registerTreeCallback

public Disposable registerTreeCallback(TreePath treePath,
                                       DynamicTreeModule.TreeCallback callback)
Description copied from interface: DynamicTreeModule
This method is called in order to supply the tree module with a DynamicTreeModule.TreeCallback for the given treePath. Using this callback the module can notify the FlexTree, that the object or data, that the node for the given path represents, changed in some way, that makes it necessary to update the node's derived properties. This method may return an instance of Disposable, called upon the disposal of the representation node. This mechanism is used to properly shut down any listeners set up to bridge changes from some domain object to the DynamicTreeModule.TreeCallback. Supplying a Disposable isn't mandatory, however. If some other mechanism for de-registration is applied (e.g. soft-references), implementors may return null.

Specified by:
registerTreeCallback in interface DynamicTreeModule
Parameters:
treePath - path to the domain object which this callback is supplied for
Returns:
an object that is to be notified upon the disposal of the representation node or null, if the disposal is implemented by other means (e.g. a soft reference).

getReadIcon

public Icon getReadIcon()
Get the icon to apply to read documents.

Returns:
the icon

setReadIcon

public void setReadIcon(Icon readIcon)
Set the icon to apply to read documents. May be set to null, if read documents shall not be marked.

Parameters:
readIcon -

getUnreadIcon

public Icon getUnreadIcon()
Get the icon to apply to unread documents.

Returns:
the icon

setUnreadIcon

public void setUnreadIcon(Icon unreadIcon)
Set the icon to apply to unread documents. May be set to null, if unread documents shall not be marked.

Parameters:
unreadIcon -

getReadLabelStyle

public AttributeSet getReadLabelStyle()
Get the styling to apply to the node's label for read documents.

Returns:
the style or null if no style is to be applied

setReadLabelStyle

public void setReadLabelStyle(AttributeSet readLabelStyle)
Set the styling to apply to the node's label for read documents. Set to null to keep the styling as-is. You can use a SimpleAttributeSet in conjunction with the StyleConstants to construct an appropriate AttributeSet like this:
 final SimpleAttributeSet readLabelStyle = new SimpleAttributeSet();
 StyleConstants.setItalic(readLabelStyle, true);
 
If you desire more control over the label decoration, consider overriding updateLabelForReadDocument(TreePath, StyledDocument).

Parameters:
readLabelStyle -

getUnreadLabelStyle

public AttributeSet getUnreadLabelStyle()
Get the styling to apply to the node's label for unread documents.

Returns:
the style or null if no style is to be applied

setUnreadLabelStyle

public void setUnreadLabelStyle(AttributeSet unreadLabelStyle)
Set the styling to apply to the node's label for unread documents. Set to null to keep the styling as-is. You can use a SimpleAttributeSet in conjunction with the StyleConstants to construct an appropriate AttributeSet like this:
 final SimpleAttributeSet unreadLabelStyle = new SimpleAttributeSet();
 StyleConstants.setItalic(unreadLabelStyle, true);
 
If you desire more control over the label decoration, consider overriding updateLabelForUnreadDocument(TreePath, StyledDocument).

Parameters:
unreadLabelStyle -

getReadLabelPrefix

public String getReadLabelPrefix()
Get the prefix to add to the label for read documents. Set to null (or the empty string) to keep the label as-is.

Returns:
the prefix or null if no prefix is to be applied

setReadLabelPrefix

public void setReadLabelPrefix(String readLabelPrefix)
Set the prefix to add to the label for read documents. Set to null (or the empty string) to keep the label as-is. If you desire more control over the label decoration, consider overriding updateLabelForReadDocument(TreePath, StyledDocument).

Parameters:
readLabelPrefix -

getUnreadLabelPrefix

public String getUnreadLabelPrefix()
Get the prefix to add to the label for unread documents. Set to null (or the empty string) to keep the label as-is.

Returns:
the prefix or null if no prefix is to be applied

setUnreadLabelPrefix

public void setUnreadLabelPrefix(String unreadLabelPrefix)
Set the prefix to add to the label for unread documents. Set to null (or the empty string) to keep the label as-is. If you desire more control over the label decoration, consider overriding updateLabelForUnreadDocument(TreePath, StyledDocument).

Parameters:
unreadLabelPrefix -


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.