Top Description Fields Constructors Methods
com.dlsc.preferencesfx.util

public abstract Class PreferencesBasedStorageHandler

extends Object
implements StorageHandler
Class Inheritance
All Implemented Interfaces
com.dlsc.preferencesfx.util.StorageHandler
Known Direct Subclasses
com.dlsc.preferencesfx.util.StorageHandlerImpl
Static Imports
com.dlsc.preferencesfx.util.Constants.DEFAULT_DIVIDER_POSITION, .Constants.DEFAULT_PREFERENCES_HEIGHT, .Constants.DEFAULT_PREFERENCES_POS_X, .Constants.DEFAULT_PREFERENCES_POS_Y, .Constants.DEFAULT_PREFERENCES_WIDTH, .Constants.DIVIDER_POSITION, .Constants.SELECTED_CATEGORY, .Constants.WINDOW_HEIGHT, .Constants.WINDOW_POS_X, .Constants.WINDOW_POS_Y, .Constants.WINDOW_WIDTH

Handles everything related to storing values of Setting using Preferences.
Authors
François Martin, Marco Sanfratello

Field Summary

Modifier and TypeField and Description
private static final Logger
private Preferences

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if successful, false if there was an exception.
clearPreferences
()

Implements com.dlsc.preferencesfx.util.StorageHandler.clearPreferences.

Clears the preferences.

protected abstract <
the type of object into which to deserialze the string
T
>
T

Returns:

the deserialized object
deserialize
(String
the string to deserialze
serialized
,
Class<T>
the class into which to deserialize the string
type
)

Deserializes an object from a string for storage.

protected abstract <
the type of objects in the list
T
>
List<T>

Returns:

deserialized list
deserializeList
(String
the string to deserialze
serialized
,
Class<T>
the class into which to deserialize the string
type
)

Deserializes a list of objects from a string for storage.

public Preferences
private String
getSerializedPreferencesValue(String breadcrumb, String serializedDefault)

private Class<?>
public String

Returns:

SHA-256 representation of breadcrumb
hash
(String
the string for which to calculate the hash
key
)

Generates a SHA-256 hash of a String.

public double

Returns:

the double value of the divider position. 0.2 if none is found
loadDividerPosition
()

Implements com.dlsc.preferencesfx.util.StorageHandler.loadDividerPosition.

Gets the stored divider position of the MasterDetailPane.

public Object

Returns:

the deserialized Object or the default Object if nothing is found
loadObject
(String
the key which is used to search the serialized Object
breadcrumb
,
Object
the Object which will be returned if nothing is found
defaultObject
)

Implements com.dlsc.preferencesfx.util.StorageHandler.loadObject.

Searches in the preferences after a serialized Object using the given key, deserializes and returns it.

public <
the type of object returned by this method
T
>
T

Returns:

the deserialized Object or the default Object if nothing is found
loadObject
(String
the key which is used to search the serialized Object
breadcrumb
,
Class<T>
the type of object used for deserialization
type
,
T
the Object which will be returned if nothing is found
defaultObject
)

Implements com.dlsc.preferencesfx.util.StorageHandler.loadObject.

Searches in the preferences after a serialized Object using the given key, deserializes and returns it.

public ObservableList<E>

Returns:

the deserialized ObservableList or the default ObservableList if nothing is found
loadObservableList
(String
the key which is used to search the serialized ArrayList
breadcrumb
,
ObservableList<E>
the default ObservableList which will be returned if nothing is found
defaultObservableList
)

Implements com.dlsc.preferencesfx.util.StorageHandler.loadObservableList.

Searches in the preferences after a serialized List using the given key, deserializes and returns it as ObservableList.

public <
the type inside the list returned by this method
T
>
ObservableList<T>

Returns:

the deserialized ObservableList or the default ObservableList if nothing is found
loadObservableList
(String
the key which is used to search the serialized ArrayList
breadcrumb
,
Class<T>
the of object used for deserialization the objects inside the list
type
,
ObservableList<T>
the default ObservableList which will be returned if nothing is found
defaultObservableList
)

Implements com.dlsc.preferencesfx.util.StorageHandler.loadObservableList.

Searches in the storage after a serialized List using the given key, deserializes and returns it as ObservableList.

public String

Returns:

the breadcrumb string of the selected category. null if none is found
loadSelectedCategory
()

Implements com.dlsc.preferencesfx.util.StorageHandler.loadSelectedCategory.

Gets the last selected category in TreeSearchView.

public double

Returns:

the double value of the window height. 700 if none is found
loadWindowHeight
()

Implements com.dlsc.preferencesfx.util.StorageHandler.loadWindowHeight.

Searches for the window height of the PreferencesFxDialog.

public double

Returns:

the double value of the horizontal window position
loadWindowPosX
()

Implements com.dlsc.preferencesfx.util.StorageHandler.loadWindowPosX.

Searches for the horizontal window position.

public double

Returns:

the double value of the vertical window position
loadWindowPosY
()

Implements com.dlsc.preferencesfx.util.StorageHandler.loadWindowPosY.

Searches for the vertical window position.

public double

Returns:

the double value of the window width. 1000 if none is found
loadWindowWidth
()

Implements com.dlsc.preferencesfx.util.StorageHandler.loadWindowWidth.

Searches for the window width of the PreferencesFxDialog.

public void
saveDividerPosition(double
the divider position to be stored
dividerPosition
)

Implements com.dlsc.preferencesfx.util.StorageHandler.saveDividerPosition.

Stores the given divider position of the MasterDetailPane.

public void
saveObject(String
the key which is used to save the serialized Object
breadcrumb
,
Object
the Object which will be saved
object
)

Implements com.dlsc.preferencesfx.util.StorageHandler.saveObject.

Serializes a given Object and saves it to the preferences using the given key.

public void
saveSelectedCategory(String
the category path as a breadcrumb string
breadcrumb
)

Implements com.dlsc.preferencesfx.util.StorageHandler.saveSelectedCategory.

Stores the last selected category in TreeSearchView.

public void
saveWindowHeight(double
the height of the window to be stored
windowHeight
)

Implements com.dlsc.preferencesfx.util.StorageHandler.saveWindowHeight.

Stores the window height of the PreferencesFxDialog.

public void
saveWindowPosX(double
the double value of the window position in horizontal orientation
windowPosX
)

Implements com.dlsc.preferencesfx.util.StorageHandler.saveWindowPosX.

Stores the position of the PreferencesFxDialog in horizontal orientation.

public void
saveWindowPosY(double
the double value of the window position in vertical orientation
windowPosY
)

Implements com.dlsc.preferencesfx.util.StorageHandler.saveWindowPosY.

Stores the position of the PreferencesFxDialog in vertical orientation.

public void
saveWindowWidth(double
the width of the window to be stored
windowWidth
)

Implements com.dlsc.preferencesfx.util.StorageHandler.saveWindowWidth.

Stores the window width of the PreferencesFxDialog.

protected abstract String

Returns:

string representation of the object for storage
serialize
(Object
the object to serialize
object
)

Serializes an object to a string for storage.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGGERback to summary
private static final Logger LOGGER
preferencesback to summary
private Preferences preferences

Constructor Detail

PreferencesBasedStorageHandlerback to summary
public PreferencesBasedStorageHandler(Class<?> saveClass)

Method Detail

clearPreferencesback to summary
public boolean clearPreferences()

Implements com.dlsc.preferencesfx.util.StorageHandler.clearPreferences.

Clears the preferences.

Returns:boolean

true if successful, false if there was an exception.

deserializeback to summary
protected abstract <T> T deserialize(String serialized, Class<T> type)

Deserializes an object from a string for storage.

Subclasses may use any way to deserialize the object. This should be the inverse operation of serialize(Object).

Therefore the following must hold true for any x of type X:

  Objects.equals(x, deserialize(serialize(x), X.class)
Parameters
<T>
the type of object into which to deserialze the string
serialized:String

the string to deserialze

type:Class<T>

the class into which to deserialize the string

Returns:T

the deserialized object

deserializeListback to summary
protected abstract <T> List<T> deserializeList(String serialized, Class<T> type)

Deserializes a list of objects from a string for storage.

Subclasses may use any way to deserialize the list. This should be the inverse operation of serialize(Object).

Therefore the following must hold true for any x of type List<X>:

  Objects.equals(x, deserializeList(serialize(x), X.class)
Parameters
<T>
the type of objects in the list
serialized:String

the string to deserialze

type:Class<T>

the class into which to deserialize the string

Returns:List<T>

deserialized list

getPreferencesback to summary
public Preferences getPreferences()
getSerializedPreferencesValueback to summary
private String getSerializedPreferencesValue(String breadcrumb, String serializedDefault)
getTypeFromListback to summary
private Class<?> getTypeFromList(ObservableList<?> list)
hashback to summary
public String hash(String key)

Generates a SHA-256 hash of a String. Since Preferences#MAX_KEY_LENGTH is 80, if the breadcrumb is over 80 characters, it will lead to an exception while saving. This method generates a SHA-256 hash of the breadcrumb to save / load as the key in Preferences, since those are guaranteed to be maximum 64 chars long.

Parameters
key:String

the string for which to calculate the hash

Returns:String

SHA-256 representation of breadcrumb

loadDividerPositionback to summary
public double loadDividerPosition()

Implements com.dlsc.preferencesfx.util.StorageHandler.loadDividerPosition.

Gets the stored divider position of the MasterDetailPane.

Returns:double

the double value of the divider position. 0.2 if none is found

loadObjectback to summary
public Object loadObject(String breadcrumb, Object defaultObject)

Implements com.dlsc.preferencesfx.util.StorageHandler.loadObject.

Searches in the preferences after a serialized Object using the given key, deserializes and returns it. Returns a default Object if nothing is found.

Parameters
breadcrumb:String

the key which is used to search the serialized Object

defaultObject:Object

the Object which will be returned if nothing is found

Returns:Object

the deserialized Object or the default Object if nothing is found

loadObjectback to summary
public <T> T loadObject(String breadcrumb, Class<T> type, T defaultObject)

Implements com.dlsc.preferencesfx.util.StorageHandler.loadObject.

Searches in the preferences after a serialized Object using the given key, deserializes and returns it. Returns a default Object if nothing is found.

Parameters
<T>
the type of object returned by this method
breadcrumb:String

the key which is used to search the serialized Object

type:Class<T>

the type of object used for deserialization

defaultObject:T

the Object which will be returned if nothing is found

Returns:T

the deserialized Object or the default Object if nothing is found

loadObservableListback to summary
public ObservableList<E> loadObservableList(String breadcrumb, ObservableList<E> defaultObservableList)

Implements com.dlsc.preferencesfx.util.StorageHandler.loadObservableList.

Searches in the preferences after a serialized List using the given key, deserializes and returns it as ObservableList.

Parameters
breadcrumb:String

the key which is used to search the serialized ArrayList

defaultObservableList:ObservableList<E>

the default ObservableList which will be returned if nothing is found

Returns:ObservableList<E>

the deserialized ObservableList or the default ObservableList if nothing is found

loadObservableListback to summary
public <T> ObservableList<T> loadObservableList(String breadcrumb, Class<T> type, ObservableList<T> defaultObservableList)

Implements com.dlsc.preferencesfx.util.StorageHandler.loadObservableList.

Searches in the storage after a serialized List using the given key, deserializes and returns it as ObservableList.

Parameters
<T>
the type inside the list returned by this method
breadcrumb:String

the key which is used to search the serialized ArrayList

type:Class<T>

Doc from com.dlsc.preferencesfx.util.StorageHandler.loadObservableList.

the of object used for deserialization the objects inside the list

defaultObservableList:ObservableList<T>

the default ObservableList which will be returned if nothing is found

Returns:ObservableList<T>

the deserialized ObservableList or the default ObservableList if nothing is found

loadSelectedCategoryback to summary
public String loadSelectedCategory()

Implements com.dlsc.preferencesfx.util.StorageHandler.loadSelectedCategory.

Gets the last selected category in TreeSearchView.

Returns:String

the breadcrumb string of the selected category. null if none is found

loadWindowHeightback to summary
public double loadWindowHeight()

Implements com.dlsc.preferencesfx.util.StorageHandler.loadWindowHeight.

Searches for the window height of the PreferencesFxDialog.

Returns:double

the double value of the window height. 700 if none is found

loadWindowPosXback to summary
public double loadWindowPosX()

Implements com.dlsc.preferencesfx.util.StorageHandler.loadWindowPosX.

Searches for the horizontal window position.

Returns:double

the double value of the horizontal window position

loadWindowPosYback to summary
public double loadWindowPosY()

Implements com.dlsc.preferencesfx.util.StorageHandler.loadWindowPosY.

Searches for the vertical window position.

Returns:double

the double value of the vertical window position

loadWindowWidthback to summary
public double loadWindowWidth()

Implements com.dlsc.preferencesfx.util.StorageHandler.loadWindowWidth.

Searches for the window width of the PreferencesFxDialog.

Returns:double

the double value of the window width. 1000 if none is found

saveDividerPositionback to summary
public void saveDividerPosition(double dividerPosition)

Implements com.dlsc.preferencesfx.util.StorageHandler.saveDividerPosition.

Stores the given divider position of the MasterDetailPane.

Parameters
dividerPosition:double

the divider position to be stored

saveObjectback to summary
public void saveObject(String breadcrumb, Object object)

Implements com.dlsc.preferencesfx.util.StorageHandler.saveObject.

Serializes a given Object and saves it to the preferences using the given key.

Parameters
breadcrumb:String

the key which is used to save the serialized Object

object:Object

the Object which will be saved

saveSelectedCategoryback to summary
public void saveSelectedCategory(String breadcrumb)

Implements com.dlsc.preferencesfx.util.StorageHandler.saveSelectedCategory.

Stores the last selected category in TreeSearchView.

Parameters
breadcrumb:String

the category path as a breadcrumb string

saveWindowHeightback to summary
public void saveWindowHeight(double windowHeight)

Implements com.dlsc.preferencesfx.util.StorageHandler.saveWindowHeight.

Stores the window height of the PreferencesFxDialog.

Parameters
windowHeight:double

the height of the window to be stored

saveWindowPosXback to summary
public void saveWindowPosX(double windowPosX)

Implements com.dlsc.preferencesfx.util.StorageHandler.saveWindowPosX.

Stores the position of the PreferencesFxDialog in horizontal orientation.

Parameters
windowPosX:double

the double value of the window position in horizontal orientation

saveWindowPosYback to summary
public void saveWindowPosY(double windowPosY)

Implements com.dlsc.preferencesfx.util.StorageHandler.saveWindowPosY.

Stores the position of the PreferencesFxDialog in vertical orientation.

Parameters
windowPosY:double

the double value of the window position in vertical orientation

saveWindowWidthback to summary
public void saveWindowWidth(double windowWidth)

Implements com.dlsc.preferencesfx.util.StorageHandler.saveWindowWidth.

Stores the window width of the PreferencesFxDialog.

Parameters
windowWidth:double

the width of the window to be stored

serializeback to summary
protected abstract String serialize(Object object)

Serializes an object to a string for storage.

Subclasses may use any way to serialize the object. This should be the inverse operation of deserialize(String, Class).

Therefore the following must hold true for any x of type X:

  Objects.equals(x, deserialize(serialize(x), X.class)
Parameters
object:Object

the object to serialize

Returns:String

string representation of the object for storage