- java.lang.Object
-
- org.arakhne.afc.progress.DefaultProgression
-
- All Implemented Interfaces:
Progression
- Direct Known Subclasses:
SubProgressionModel
public class DefaultProgression extends Object implements Progression
An object that permits to indicates the progression of a task. The progression of the value is always ascendent.- Version:
- 17.0 2020-01-04 14:41:38
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- util
-
-
Field Summary
Fields Modifier and Type Field Description protected ListenerCollection<ProgressionListener>
listeners
Collection of listeners.
-
Constructor Summary
Constructors Constructor Description DefaultProgression()
Create a progress model in a indeterminate state.DefaultProgression(int min, int max)
Create a progress model with the specified indeterminate state.DefaultProgression(int value, int min, int max)
Create a progress model with the specified determinate state.DefaultProgression(int value, int min, int max, boolean adjusting)
Create a progress model with the specified determinate state.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addProgressionListener(ProgressionListener listener)
Add a listener on this model.(package private) void
disconnectSubTask(SubProgressionModel subTask, double value, boolean overwriteComment)
Set the parent value and disconnect this subtask from its parent.void
end()
Force this progression task to end its indicator.void
ensureNoSubTask()
Ensure that there is no opened subtask.protected void
fireStateChange()
Notify listeners about state change.protected void
fireValueChange()
Notify listeners about value change.String
getComment()
Replies the comment associated to the currect task.protected double
getFloatValue()
Replies the floating-point precision value.int
getMaximum()
Returns the model's maximum.int
getMinimum()
Returns the minimum acceptable value.double
getPercent()
Returns the model's current value in percent of pregression.double
getProgressionFactor()
Returns the model's current value in percent of pregression.Progression
getSubTask()
Replies the current subtask of this task model.Progression
getSuperTask()
Replies the super task of this task model.int
getTaskDepth()
Replies the depth level of this task.int
getValue()
Returns the model's current value.void
increment()
Increment the current value by 1.void
increment(int amount)
Increment the current value by the given amount.void
increment(int amount, String comment)
Increment the current value by the given amount.void
increment(String comment)
Increment the current value by 1.boolean
isAdjusting()
Returns true if the current changes to the value property are part of a series of changes.boolean
isIndeterminate()
Returns the value of theindeterminate
property.boolean
isRootModel()
Replies if is task model is a root model.void
removeProgressionListener(ProgressionListener listener)
Remove a listener on this model.void
setAdjusting(boolean adjusting)
This attribute indicates that any upcoming changes to the value of the model should be considered a single event.void
setComment(String comment)
Set the comment associated to the currect task.void
setIndeterminate(boolean newValue)
Sets theindeterminate
property of the task progression, which determines whether the progression is in determinate or indeterminate mode.void
setMaximum(int newMaximum)
Sets the model's maximum to newMaximum.void
setMinimum(int newMinimum)
Sets the model's minimum to newMinimum.void
setProperties(int value, int min, int max, boolean adjusting)
This method sets all of the model's data with a single method call.void
setProperties(int value, int min, int max, boolean adjusting, String comment)
This method sets all of the model's data with a single method call.void
setValue(int newValue)
Sets the model's current value tonewValue
ifnewValue
satisfies the model's constraints.void
setValue(int newValue, String comment)
Sets the model's current value tonewValue
ifnewValue
satisfies the model's constraints.(package private) void
setValue(SubProgressionModel subTask, double newValue, String comment)
Set the value with a float-point precision.Progression
subTask(int extent)
Enter into a subtask.Progression
subTask(int extent, boolean overwriteComment)
Enter into a subtask.Progression
subTask(int extent, int minValue, int maxValue)
Enter into a subtask.Progression
subTask(int extent, int minValue, int maxValue, boolean overwriteComment)
Enter into a subtask.
-
-
-
Field Detail
-
listeners
protected final ListenerCollection<ProgressionListener> listeners
Collection of listeners.
-
-
Constructor Detail
-
DefaultProgression
public DefaultProgression(int value, int min, int max, boolean adjusting)
Create a progress model with the specified determinate state.- Parameters:
value
- is the initial value of this model (betweenmin
andmax
).min
- is the minimal valuemax
- is the maximal valueadjusting
- indicates if this model is under adjustement or not.
-
DefaultProgression
public DefaultProgression(int value, int min, int max)
Create a progress model with the specified determinate state. The model is not adjusting.- Parameters:
value
- is the initial value of this model (betweenmin
andmax
).min
- is the minimal valuemax
- is the maximal value
-
DefaultProgression
public DefaultProgression(int min, int max)
Create a progress model with the specified indeterminate state. The model is not adjusting.- Parameters:
min
- is the minimal valuemax
- is the maximal value
-
DefaultProgression
public DefaultProgression()
Create a progress model in a indeterminate state. The model is not adjusting.
-
-
Method Detail
-
end
public void end()
Description copied from interface:Progression
Force this progression task to end its indicator.- Specified by:
end
in interfaceProgression
-
addProgressionListener
public void addProgressionListener(ProgressionListener listener)
Description copied from interface:Progression
Add a listener on this model.- Specified by:
addProgressionListener
in interfaceProgression
- Parameters:
listener
- is the listener to add.
-
removeProgressionListener
public void removeProgressionListener(ProgressionListener listener)
Description copied from interface:Progression
Remove a listener on this model.- Specified by:
removeProgressionListener
in interfaceProgression
- Parameters:
listener
- is the listener to remove.
-
isRootModel
public boolean isRootModel()
Description copied from interface:Progression
Replies if is task model is a root model.isRootMode() == (getTaskDepth()==0)
- Specified by:
isRootModel
in interfaceProgression
- Returns:
true
if this model is a root model, otherwisefalse
-
getSuperTask
public Progression getSuperTask()
Description copied from interface:Progression
Replies the super task of this task model.- Specified by:
getSuperTask
in interfaceProgression
- Returns:
- the super task or
null
this task was not a decomposition of a super task.
-
getTaskDepth
public int getTaskDepth()
Description copied from interface:Progression
Replies the depth level of this task. The root task (ie. a task without parent task) has always a depth of0
. A subtask of the root task has a depth of1
. A subtask of this subtask has a depth of2
, etc.isRootMode() == (getTaskDepth()==0)
- Specified by:
getTaskDepth
in interfaceProgression
- Returns:
- the depth of the task.
-
getSubTask
public final Progression getSubTask()
Description copied from interface:Progression
Replies the current subtask of this task model.- Specified by:
getSubTask
in interfaceProgression
- Returns:
- the current subtask or
null
this task was not decomposed.
-
ensureNoSubTask
public final void ensureNoSubTask()
Description copied from interface:Progression
Ensure that there is no opened subtask. If a subtask is existing, it is ended().- Specified by:
ensureNoSubTask
in interfaceProgression
-
fireStateChange
protected void fireStateChange()
Notify listeners about state change.
-
fireValueChange
protected void fireValueChange()
Notify listeners about value change.
-
getMaximum
public int getMaximum()
Description copied from interface:Progression
Returns the model's maximum.- Specified by:
getMaximum
in interfaceProgression
- Returns:
- the value of the maximum property.
- See Also:
Progression.setMaximum(int)
-
getMinimum
public int getMinimum()
Description copied from interface:Progression
Returns the minimum acceptable value.- Specified by:
getMinimum
in interfaceProgression
- Returns:
- the value of the minimum property
- See Also:
Progression.setMinimum(int)
-
getPercent
public double getPercent()
Description copied from interface:Progression
Returns the model's current value in percent of pregression.- Specified by:
getPercent
in interfaceProgression
- Returns:
- the model's value between 0 and 100
- See Also:
Progression.getValue()
,Progression.getProgressionFactor()
-
getProgressionFactor
public double getProgressionFactor()
Description copied from interface:Progression
Returns the model's current value in percent of pregression.- Specified by:
getProgressionFactor
in interfaceProgression
- Returns:
- the model's value between 0 and 1
- See Also:
Progression.getValue()
,Progression.getPercent()
-
getValue
public int getValue()
Description copied from interface:Progression
Returns the model's current value. Note that the upper limit on the model's value ismaximum
and the lower limit isminimum
.- Specified by:
getValue
in interfaceProgression
- Returns:
- the model's value
- See Also:
Progression.setValue(int)
-
getFloatValue
protected double getFloatValue()
Replies the floating-point precision value.- Returns:
- the floating-point precision value.
-
isAdjusting
public boolean isAdjusting()
Description copied from interface:Progression
Returns true if the current changes to the value property are part of a series of changes.- Specified by:
isAdjusting
in interfaceProgression
- Returns:
- the valueIsAdjustingProperty.
- See Also:
Progression.setAdjusting(boolean)
-
isIndeterminate
public boolean isIndeterminate()
Description copied from interface:Progression
Returns the value of theindeterminate
property.- Specified by:
isIndeterminate
in interfaceProgression
- Returns:
- the value of the
indeterminate
property - See Also:
Progression.setIndeterminate(boolean)
-
setIndeterminate
public void setIndeterminate(boolean newValue)
Description copied from interface:Progression
Sets theindeterminate
property of the task progression, which determines whether the progression is in determinate or indeterminate mode. For example an indeterminate progress bar continuously displays animation indicating that an operation of unknown length is occurring.- Specified by:
setIndeterminate
in interfaceProgression
- Parameters:
newValue
-true
if the progress bar should change to indeterminate mode;false
if it should revert to normal.- See Also:
Progression.isIndeterminate()
-
setMaximum
public void setMaximum(int newMaximum)
Description copied from interface:Progression
Sets the model's maximum to newMaximum. The other properties may be changed as well, to ensure thatminimum <= value <= maximum
- Specified by:
setMaximum
in interfaceProgression
- Parameters:
newMaximum
- the model's new maximum- See Also:
Progression.getMaximum()
-
setMinimum
public void setMinimum(int newMinimum)
Description copied from interface:Progression
Sets the model's minimum to newMinimum. The other properties may be changed as well, to ensure that:minimum <= value <= maximum
- Specified by:
setMinimum
in interfaceProgression
- Parameters:
newMinimum
- the model's new minimum- See Also:
Progression.getMinimum()
-
setProperties
public void setProperties(int value, int min, int max, boolean adjusting, String comment)
Description copied from interface:Progression
This method sets all of the model's data with a single method call. The method results in a single change event being generated. This is convenient when you need to adjust all the model data simultaneously and do not want individual change events to occur.- Specified by:
setProperties
in interfaceProgression
- Parameters:
value
- an int giving the current valuemin
- an int giving the minimum valuemax
- an int giving the maximum valueadjusting
- a boolean, true if a series of changes are in progresscomment
- is the comment associated to the current task, ornull
- See Also:
Progression.setValue(int)
,Progression.setMinimum(int)
,Progression.setMaximum(int)
,Progression.setComment(String)
,Progression.setAdjusting(boolean)
-
setProperties
public void setProperties(int value, int min, int max, boolean adjusting)
Description copied from interface:Progression
This method sets all of the model's data with a single method call. The method results in a single change event being generated. This is convenient when you need to adjust all the model data simultaneously and do not want individual change events to occur.- Specified by:
setProperties
in interfaceProgression
- Parameters:
value
- an int giving the current valuemin
- an int giving the minimum valuemax
- an int giving the maximum valueadjusting
- a boolean, true if a series of changes are in progress- See Also:
Progression.setValue(int)
,Progression.setMinimum(int)
,Progression.setMaximum(int)
,Progression.setComment(String)
,Progression.setAdjusting(boolean)
-
setValue
public void setValue(int newValue)
Description copied from interface:Progression
Sets the model's current value tonewValue
ifnewValue
satisfies the model's constraints. Those constraints are:minimum <= value <= maximum
Otherwise, ifnewValue
is less thanminimum
it's set tominimum
, if its greater thanmaximum
then it's set tomaximum
.- Specified by:
setValue
in interfaceProgression
- Parameters:
newValue
- the model's new value- See Also:
Progression.getValue()
-
setValue
public void setValue(int newValue, String comment)
Description copied from interface:Progression
Sets the model's current value tonewValue
ifnewValue
satisfies the model's constraints. Those constraints are:minimum <= value <= maximum
Otherwise, ifnewValue
is less thanminimum
it's set tominimum
, if its greater thanmaximum
then it's set tomaximum
.- Specified by:
setValue
in interfaceProgression
- Parameters:
newValue
- the model's new valuecomment
- is the comment to display.- See Also:
Progression.getValue()
-
setValue
void setValue(SubProgressionModel subTask, double newValue, String comment)
Set the value with a float-point precision. This method is invoked from a subtask.- Parameters:
subTask
- the subtask.newValue
- the new value.comment
- the new comment.
-
setAdjusting
public void setAdjusting(boolean adjusting)
Description copied from interface:Progression
This attribute indicates that any upcoming changes to the value of the model should be considered a single event. This attribute will be set to true at the start of a series of changes to the value, and will be set to false when the value has finished changing. Normally this allows a listener to only take action when the final value change in committed, instead of having to do updates for all intermediate values.- Specified by:
setAdjusting
in interfaceProgression
- Parameters:
adjusting
-true
if the upcoming changes to the value property are part of a series- See Also:
Progression.subTask(int)
-
subTask
public final Progression subTask(int extent, int minValue, int maxValue)
Description copied from interface:Progression
Enter into a subtask. When a sub task is created, it will progress as a sub part of the main task.The minimum value of the subtask in its parent will correspond to the current value of the main task. The maximum value of the sub task in its parent will correspond to the current value of the main task plus the given
extend
.If the
extend
plus the current value is exceeding the maximum value, it will be bounded to the maximum.- Specified by:
subTask
in interfaceProgression
- Parameters:
extent
- is the size of the sub task inside the main task.minValue
- is the minimum value inside the subtask.maxValue
- is the maximum value inside the subtask.- Returns:
- the subtask progression
-
subTask
public Progression subTask(int extent, int minValue, int maxValue, boolean overwriteComment)
Description copied from interface:Progression
Enter into a subtask. When a sub task is created, it will progress as a sub part of the main task.The minimum value of the subtask in its parent will correspond to the current value of the main task. The maximum value of the sub task in its parent will correspond to the current value of the main task plus the given
extend
.If the
extend
plus the current value is exceeding the maximum value, it will be bounded to the maximum.- Specified by:
subTask
in interfaceProgression
- Parameters:
extent
- is the size of the sub task inside the main task.minValue
- is the minimum value inside the subtask.maxValue
- is the maximum value inside the subtask.overwriteComment
- indicates if the comment of this task model may be overwritten by the comment of the subtask when it is disconnected.- Returns:
- the subtask progression
-
subTask
public final Progression subTask(int extent)
Description copied from interface:Progression
Enter into a subtask. When a sub task is created, it will progress as a sub part of the main task.The minimum value of the subtask in its parent will correspond to the current value of the main task. The maximum value of the sub task in its parent will correspond to the current value of the main task plus the given
extend
.If the
extend
plus the current value is exceeding the maximum value, it will be bounded to the maximum.The minimum and maximum values of the subtask should be manually set the the caller.
- Specified by:
subTask
in interfaceProgression
- Parameters:
extent
- is the size of the sub task inside the main task.- Returns:
- the subtask progression
-
subTask
public Progression subTask(int extent, boolean overwriteComment)
Description copied from interface:Progression
Enter into a subtask. When a sub task is created, it will progress as a sub part of the main task.The minimum value of the subtask in its parent will correspond to the current value of the main task. The maximum value of the sub task in its parent will correspond to the current value of the main task plus the given
extend
.If the
extend
plus the current value is exceeding the maximum value, it will be bounded to the maximum.The minimum and maximum values of the subtask should be manually set the the caller.
- Specified by:
subTask
in interfaceProgression
- Parameters:
extent
- is the size of the sub task inside the main task.overwriteComment
- indicates if the comment of this task model may be overwritten by the comment of the subtask when it is disconnected.- Returns:
- the subtask progression
-
disconnectSubTask
void disconnectSubTask(SubProgressionModel subTask, double value, boolean overwriteComment)
Set the parent value and disconnect this subtask from its parent. This method is invoked from a subtask.- Parameters:
subTask
- the subtask to disconnect.value
- the value of the task.overwriteComment
- indicates if the comment of this parent model may be overwritten by the child's comment.
-
getComment
public String getComment()
Description copied from interface:Progression
Replies the comment associated to the currect task.- Specified by:
getComment
in interfaceProgression
- Returns:
- the comment for the current task or
null
if the current task has not any comment.
-
setComment
public void setComment(String comment)
Description copied from interface:Progression
Set the comment associated to the currect task.If the given string is
null
or empty, the current task is assumed to not have a comment.- Specified by:
setComment
in interfaceProgression
- Parameters:
comment
- is the comment for the current task.
-
increment
public void increment(int amount)
Description copied from interface:Progression
Increment the current value by the given amount.This function is equivalent to:
this.setValue(this.getValue()+amount);
- Specified by:
increment
in interfaceProgression
- Parameters:
amount
- is the amount to add to the current value.
-
increment
public void increment(int amount, String comment)
Description copied from interface:Progression
Increment the current value by the given amount.This function is equivalent to:
this.setValue(this.getValue()+amount, comment);
- Specified by:
increment
in interfaceProgression
- Parameters:
amount
- is the amount to add to the current value.comment
- is the comment to display.
-
increment
public void increment()
Description copied from interface:Progression
Increment the current value by 1.This function is equivalent to:
this.setValue(this.getValue()+1);
- Specified by:
increment
in interfaceProgression
-
increment
public void increment(String comment)
Description copied from interface:Progression
Increment the current value by 1.This function is equivalent to:
this.setValue(this.getValue()+1, comment);
- Specified by:
increment
in interfaceProgression
- Parameters:
comment
- is the comment to display.
-
-