public class ReadStateModule extends Object implements DynamicTreeModule, TreeIconProvider, TreeLabelProvider
TreeModule
used track which Document
s 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.Modifier and Type | Class and Description |
---|---|
static interface |
ReadStateModule.ReadTracker
This interface represents an installed read tracker.
|
DynamicTreeModule.TreeCallback
Constructor and Description |
---|
ReadStateModule() |
Modifier and Type | Method and Description |
---|---|
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.
|
public static boolean isRead(Document doc)
doc
- the document to checkpublic static void setRead(Document doc)
public static void setUnread(Document doc)
public static ReadStateModule.ReadTracker installReadTracker(PageView pageView, long duration, TimeUnit timeUnit)
PageView
and marks documents, which have
been shown for at least the given duration, as read.pageView
- the PageView to monitorduration
- the duration after which a shown document is marked as readtimeUnit
- the unit of the durationpublic Icon getIcon(TreePath path)
getIcon
in interface TreeIconProvider
public void updateLabel(TreePath path, StyledDocument doc) throws BadLocationException
updateLabel
in interface TreeLabelProvider
BadLocationException
protected void updateLabelForReadDocument(TreePath path, StyledDocument doc) throws BadLocationException
readLabelPrefix
(unless it is null
) and apply the readLabelStyle
(unless it is null
).BadLocationException
protected void updateLabelForUnreadDocument(TreePath path, StyledDocument doc) throws BadLocationException
unreadLabelPrefix
(unless it is
null
) and apply the unreadLabelStyle
(unless it is null
).BadLocationException
public Disposable registerTreeCallback(TreePath treePath, DynamicTreeModule.TreeCallback callback)
DynamicTreeModule
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
.registerTreeCallback
in interface DynamicTreeModule
treePath
- path to the domain object which this callback is supplied fornull
, if the disposal is implemented by other means (e.g. a soft
reference).public Icon getReadIcon()
public void setReadIcon(Icon readIcon)
null
, if read documents
shall not be marked.public Icon getUnreadIcon()
public void setUnreadIcon(Icon unreadIcon)
null
, if unread documents
shall not be marked.public AttributeSet getReadLabelStyle()
null
if no style is to be appliedpublic void setReadLabelStyle(AttributeSet readLabelStyle)
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)
.public AttributeSet getUnreadLabelStyle()
null
if no style is to be appliedpublic void setUnreadLabelStyle(AttributeSet unreadLabelStyle)
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)
.public String getReadLabelPrefix()
null
(or the empty
string) to keep the label as-is.null
if no prefix is to be appliedpublic void setReadLabelPrefix(String readLabelPrefix)
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)
.public String getUnreadLabelPrefix()
null
(or the empty
string) to keep the label as-is.null
if no prefix is to be appliedpublic void setUnreadLabelPrefix(String unreadLabelPrefix)
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)
.Copyright © 2024 levigo holding gmbh. All rights reserved.