Class NavigationHistory
- java.lang.Object
-
- nl.siegmann.epublib.browsersupport.NavigationHistory
-
- All Implemented Interfaces:
NavigationEventListener
public class NavigationHistory extends java.lang.Object implements NavigationEventListener
A history of the user's locations with the epub.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classNavigationHistory.Location
-
Field Summary
Fields Modifier and Type Field Description private intcurrentPosprivate intcurrentSizeprivate static longDEFAULT_HISTORY_WAIT_TIMEstatic intDEFAULT_MAX_HISTORY_SIZEprivate longhistoryWaitTimeprivate longlastUpdateTimeprivate java.util.List<NavigationHistory.Location>locationsprivate intmaxHistorySizeprivate Navigatornavigator
-
Constructor Summary
Constructors Constructor Description NavigationHistory(Navigator navigator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLocation(java.lang.String href)voidaddLocation(NavigationHistory.Location location)Adds the location after the current position.voidaddLocation(Resource resource)private voidcheckHistorySize()Removes all elements that are too much for the maxHistorySize out of the history.java.lang.StringgetCurrentHref()intgetCurrentPos()intgetCurrentSize()longgetHistoryWaitTime()If the time between a navigation event is less than the historyWaitTime then the new location is not added to the history.private java.lang.StringgetLocationHref(int pos)intgetMaxHistorySize()voidinitBook(Book book)booleanmove(int delta)Moves the current positions delta positions.voidnavigationPerformed(NavigationEvent navigationEvent)If this is not the source of the navigationEvent then the addLocation will be called with the href of the currentResource in the navigationEvent.voidsetHistoryWaitTime(long historyWaitTime)voidsetMaxHistorySize(int maxHistorySize)
-
-
-
Field Detail
-
DEFAULT_MAX_HISTORY_SIZE
public static final int DEFAULT_MAX_HISTORY_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_HISTORY_WAIT_TIME
private static final long DEFAULT_HISTORY_WAIT_TIME
- See Also:
- Constant Field Values
-
lastUpdateTime
private long lastUpdateTime
-
locations
private java.util.List<NavigationHistory.Location> locations
-
navigator
private Navigator navigator
-
currentPos
private int currentPos
-
currentSize
private int currentSize
-
maxHistorySize
private int maxHistorySize
-
historyWaitTime
private long historyWaitTime
-
-
Constructor Detail
-
NavigationHistory
public NavigationHistory(Navigator navigator)
-
-
Method Detail
-
getCurrentPos
public int getCurrentPos()
-
getCurrentSize
public int getCurrentSize()
-
initBook
public void initBook(Book book)
-
getHistoryWaitTime
public long getHistoryWaitTime()
If the time between a navigation event is less than the historyWaitTime then the new location is not added to the history. When a user is rapidly viewing many pages using the slider we do not want all of them to be added to the history.- Returns:
- the time we wait before adding the page to the history
-
setHistoryWaitTime
public void setHistoryWaitTime(long historyWaitTime)
-
addLocation
public void addLocation(Resource resource)
-
addLocation
public void addLocation(NavigationHistory.Location location)
Adds the location after the current position. If the currentposition is not the end of the list then the elements between the current element and the end of the list will be discarded. Does nothing if the new location matches the current location.
If this nr of locations becomes larger then the historySize then the first item(s) will be removed.- Parameters:
location-
-
checkHistorySize
private void checkHistorySize()
Removes all elements that are too much for the maxHistorySize out of the history.
-
addLocation
public void addLocation(java.lang.String href)
-
getLocationHref
private java.lang.String getLocationHref(int pos)
-
move
public boolean move(int delta)
Moves the current positions delta positions. move(-1) to go one position back in history.
move(1) to go one position forward.- Parameters:
delta-- Returns:
- Whether we actually moved. If the requested value is illegal it will return false, true otherwise.
-
navigationPerformed
public void navigationPerformed(NavigationEvent navigationEvent)
If this is not the source of the navigationEvent then the addLocation will be called with the href of the currentResource in the navigationEvent.- Specified by:
navigationPerformedin interfaceNavigationEventListener
-
getCurrentHref
public java.lang.String getCurrentHref()
-
setMaxHistorySize
public void setMaxHistorySize(int maxHistorySize)
-
getMaxHistorySize
public int getMaxHistorySize()
-
-