Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TULIP-CPS
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
NUI
TULIP-CPS
Commits
9bec379f
Commit
9bec379f
authored
Mar 22, 2017
by
Nico Mack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented Templating to CPS module
parent
13665e57
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1497 additions
and
93 deletions
+1497
-93
.gitignore
.gitignore
+2
-1
CPS/pom.xml
CPS/pom.xml
+1
-1
CPS/src/lu/list/itis/dkd/tui/bootstrapping/VariableBootstrapper.java
...list/itis/dkd/tui/bootstrapping/VariableBootstrapper.java
+64
-0
CPS/src/lu/list/itis/dkd/tui/cps/utility/Externalization.java
...src/lu/list/itis/dkd/tui/cps/utility/Externalization.java
+3
-0
CPS/src/lu/list/itis/dkd/tui/cps/utility/externalization.properties
.../list/itis/dkd/tui/cps/utility/externalization.properties
+2
-1
CPS/src/lu/list/itis/dkd/tui/cps/variable/NumericalVariable.java
.../lu/list/itis/dkd/tui/cps/variable/NumericalVariable.java
+13
-12
CPS/src/lu/list/itis/dkd/tui/cps/variable/tangible/TangibleNumericalVariable.java
.../tui/cps/variable/tangible/TangibleNumericalVariable.java
+3
-5
CPS/src/lu/list/itis/dkd/tui/widget/GaugeWidget.java
CPS/src/lu/list/itis/dkd/tui/widget/GaugeWidget.java
+97
-0
CPS/src/lu/list/itis/dkd/tui/widget/SelectorWidget.java
CPS/src/lu/list/itis/dkd/tui/widget/SelectorWidget.java
+192
-0
CPS/src/lu/list/itis/dkd/tui/widget/ValueWidget.java
CPS/src/lu/list/itis/dkd/tui/widget/ValueWidget.java
+85
-50
CPS/src/lu/list/itis/dkd/tui/widget/builder/BaseGaugeWidgetBuilder.java
...t/itis/dkd/tui/widget/builder/BaseGaugeWidgetBuilder.java
+84
-0
CPS/src/lu/list/itis/dkd/tui/widget/builder/BaseValueWidgetBuilder.java
...t/itis/dkd/tui/widget/builder/BaseValueWidgetBuilder.java
+49
-22
CPS/src/lu/list/itis/dkd/tui/widget/builder/GaugeWidgetBuilder.java
.../list/itis/dkd/tui/widget/builder/GaugeWidgetBuilder.java
+51
-0
CPS/src/lu/list/itis/dkd/tui/widget/builder/SelectorWidgetBuilder.java
...st/itis/dkd/tui/widget/builder/SelectorWidgetBuilder.java
+96
-0
CPS/src/lu/list/itis/dkd/tui/widget/builder/ValueWidgetBuilder.java
.../list/itis/dkd/tui/widget/builder/ValueWidgetBuilder.java
+18
-1
CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcGraph.java
CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcGraph.java
+279
-0
CPS/src/lu/list/itis/dkd/tui/widget/corona/ValueCorona.java
CPS/src/lu/list/itis/dkd/tui/widget/corona/ValueCorona.java
+94
-0
CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ArcGraphBuilder.java
...t/itis/dkd/tui/widget/corona/builder/ArcGraphBuilder.java
+210
-0
CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/BaseValueCoronaBuilder.java
...dkd/tui/widget/corona/builder/BaseValueCoronaBuilder.java
+85
-0
CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ValueCoronaBuilder.java
...tis/dkd/tui/widget/corona/builder/ValueCoronaBuilder.java
+69
-0
No files found.
.gitignore
View file @
9bec379f
*.metadata
*.classpath
CPS/target
\ No newline at end of file
CPS/target
/.DS_Store
CPS/pom.xml
View file @
9bec379f
...
...
@@ -47,7 +47,7 @@
<dependency>
<groupId>
lu.list.itis.dkd.tui
</groupId>
<artifactId>
tulip
</artifactId>
<version>
2.
3.1
</version>
<version>
2.
4.0
</version>
</dependency>
<dependency>
<groupId>
maven2.dk.ange
</groupId>
...
...
CPS/src/lu/list/itis/dkd/tui/bootstrapping/VariableBootstrapper.java
0 → 100644
View file @
9bec379f
/**
* Copyright Luxembourg Institute of Science and Technology, 2017. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package
lu.list.itis.dkd.tui.bootstrapping
;
import
lu.list.itis.dkd.tui.cps.utility.Externalization
;
import
lu.list.itis.dkd.tui.cps.variable.BooleanVariable
;
import
lu.list.itis.dkd.tui.cps.variable.Variable
;
import
lu.list.itis.dkd.tui.cps.variable.tangible.TangibleNumericalVariable
;
import
lu.list.itis.dkd.tui.exception.BuildException
;
import
org.jdom2.Element
;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public
class
VariableBootstrapper
{
public
static
Variable
buildVariableFromElement
(
Element
variableNode
,
BootstrapContext
context
,
BootstrapCallback
callback
)
throws
BuildException
{
Variable
variable
=
null
;
if
(
variableNode
==
null
)
return
null
;
String
name
=
BootstrappingUtils
.
getContentAsString
(
variableNode
,
Externalization
.
NAME_ATTRIBUTE
,
BootstrappingUtils
.
MANDATORY
,
null
,
context
);
String
type
=
BootstrappingUtils
.
getContentAsString
(
variableNode
,
Externalization
.
TYPE_NODE
,
BootstrappingUtils
.
MANDATORY
,
null
,
context
);
switch
(
type
)
{
case
Externalization
.
NUMERIC_TYPE
:
String
unit
=
BootstrappingUtils
.
getContentAsString
(
variableNode
,
Externalization
.
UNIT_ATTRIBUTE
,
BootstrappingUtils
.
OPTIONAL
,
Externalization
.
EMPTY_STRING
,
context
);
double
minValue
=
BootstrappingUtils
.
getContentAsDouble
(
variableNode
,
Externalization
.
MINIMUM_ATTRIBUTE
,
BootstrappingUtils
.
OPTIONAL
,
-
Double
.
MAX_VALUE
,
context
);
double
maxValue
=
BootstrappingUtils
.
getContentAsDouble
(
variableNode
,
Externalization
.
MAXIMUM_ATTRIBUTE
,
BootstrappingUtils
.
OPTIONAL
,
Double
.
MAX_VALUE
,
context
);
double
scale
=
BootstrappingUtils
.
getContentAsDouble
(
variableNode
,
Externalization
.
SCALE_ATTRIBUTE
,
BootstrappingUtils
.
OPTIONAL
,
1.0
,
context
);
double
numericValue
=
BootstrappingUtils
.
getContentAsDouble
(
variableNode
,
Externalization
.
INITIAL_ATTRIBUTE
,
BootstrappingUtils
.
OPTIONAL
,
0.0
,
context
);
TangibleNumericalVariable
tangibleVariable
=
new
TangibleNumericalVariable
(
name
,
unit
,
numericValue
);
tangibleVariable
.
setMinValue
(
minValue
);
tangibleVariable
.
setMaxValue
(
maxValue
);
tangibleVariable
.
setScale
(
scale
);
variable
=
tangibleVariable
;
break
;
case
Externalization
.
LOGIC_TYPE
:
boolean
booleanValue
=
BootstrappingUtils
.
getContentAsBoolean
(
variableNode
,
Externalization
.
INITIAL_ATTRIBUTE
,
BootstrappingUtils
.
OPTIONAL
,
false
,
context
);
BooleanVariable
booleanVariable
=
new
BooleanVariable
(
name
,
booleanValue
);
variable
=
booleanVariable
;
break
;
default
:
throw
new
BuildException
(
"Don't know how to build a Variable of type "
+
type
);
}
return
variable
;
}
}
CPS/src/lu/list/itis/dkd/tui/cps/utility/Externalization.java
View file @
9bec379f
...
...
@@ -59,10 +59,13 @@ public class Externalization extends NLS {
public
static
String
MAXIMUM_ATTRIBUTE
;
public
static
String
SCALE_ATTRIBUTE
;
public
static
String
DECIMALS_ATTRIBUTE
;
public
static
String
TYPE_NODE
;
public
static
final
String
EMPTY_STRING
=
""
;
public
static
final
String
LOGIC_TYPE
=
"logic"
;
public
static
final
String
NUMERIC_TYPE
=
"numeric"
;
static
{
// initialize resource bundle
NLS
.
initializeMessages
(
BUNDLE_NAME
,
Externalization
.
class
);
...
...
CPS/src/lu/list/itis/dkd/tui/cps/utility/externalization.properties
View file @
9bec379f
...
...
@@ -25,4 +25,5 @@ IMPORT_ELEMENT=import
FUNCTION_ATTRIBUTE
=
function
FROM_ATTRIBUTE
=
from
SYSTEM_ELEMENT
=
system
UNIT_ATTRIBUTE
=
unit
\ No newline at end of file
UNIT_ATTRIBUTE
=
unit
TYPE_NODE
=
type
\ No newline at end of file
CPS/src/lu/list/itis/dkd/tui/cps/variable/NumericalVariable.java
View file @
9bec379f
...
...
@@ -26,7 +26,6 @@ import lu.list.itis.dkd.tui.cps.InputChangeListener;
import
lu.list.itis.dkd.tui.cps.InputEvent
;
import
lu.list.itis.dkd.tui.cps.utility.Externalization
;
import
org.jdom2.Element
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -71,7 +70,7 @@ public class NumericalVariable extends Variable {
format
.
setDecimalSeparatorAlwaysShown
(
false
);
format
.
setGroupingUsed
(
false
);
minValue
=
Double
.
MIN
_VALUE
;
minValue
=
-
Double
.
MAX
_VALUE
;
maxValue
=
Double
.
MAX_VALUE
;
scale
=
1
;
}
...
...
@@ -84,15 +83,17 @@ public class NumericalVariable extends Variable {
* The root element of the variable containing, as text on child elements, all the
* necessary information to initialize the variable.
*/
public
NumericalVariable
(
Element
rootElement
)
{
super
(
Externalization
.
NUMERIC_TYPE
,
rootElement
.
getChildText
(
"name"
),
rootElement
.
getChildText
(
"unit"
));
//$NON-NLS-1$ //$NON-NLS-2$
this
.
value
=
Double
.
parseDouble
(
rootElement
.
getChildText
(
"value"
));
//$NON-NLS-1$
format
=
new
DecimalFormat
();
format
.
setDecimalSeparatorAlwaysShown
(
false
);
format
.
setGroupingUsed
(
false
);
}
// public NumericalVariable(Element rootElement) {
// super(Externalization.NUMERIC_TYPE, rootElement.getChildText("name"),
// rootElement.getChildText("unit")); //$NON-NLS-1$ //$NON-NLS-2$
// String valueContent = Strings.nullToEmpty(rootElement.getChildText("value")); //$NON-NLS-1$
// this.value = (valueContent.length() > 0) ? Double.parseDouble(valueContent) : 0.0;
//
// format = new DecimalFormat();
// format.setDecimalSeparatorAlwaysShown(false);
// format.setGroupingUsed(false);
//
// }
/**
* {@inheritDoc}<br>
...
...
@@ -104,7 +105,7 @@ public class NumericalVariable extends Variable {
public
String
toString
()
{
StringBuilder
builder
=
new
StringBuilder
(
format
.
format
(
value
));
if
((
unit
!=
null
)
&&
(
unit
.
length
()
>
0
))
{
builder
.
append
(
"
["
).
append
(
unit
).
append
(
"]"
);
//$NON-NLS-1$ //$NON-NLS-2
$
builder
.
append
(
"
"
).
append
(
unit
);
//$NON-NLS-1
$
}
return
builder
.
toString
();
}
...
...
CPS/src/lu/list/itis/dkd/tui/cps/variable/tangible/TangibleNumericalVariable.java
View file @
9bec379f
...
...
@@ -29,8 +29,6 @@ import lu.list.itis.dkd.tui.event.ContextEventListener;
import
lu.list.itis.dkd.tui.exception.UnsupportedInformationException
;
import
lu.list.itis.dkd.tui.utility.Point
;
import
org.jdom2.Element
;
/**
* Class extending the {@link NumericalVariable} by implementing an interface,
* {@link ContextEventListener} which enables the variable to directly listen to changes pushed by a
...
...
@@ -65,9 +63,9 @@ public class TangibleNumericalVariable extends NumericalVariable implements Cont
* The root element of the variable containing, as text on child elements, all the
* necessary information to initialize the variable.
*/
public
TangibleNumericalVariable
(
Element
rootElement
)
{
super
(
rootElement
);
}
//
public TangibleNumericalVariable(Element rootElement) {
//
super(rootElement);
//
}
/** {@inheritDoc} */
@Override
...
...
CPS/src/lu/list/itis/dkd/tui/widget/GaugeWidget.java
0 → 100755
View file @
9bec379f
package
lu.list.itis.dkd.tui.widget
;
import
lu.list.itis.dkd.tui.content.InformationReceiver
;
import
lu.list.itis.dkd.tui.cps.InputChangeListener
;
import
lu.list.itis.dkd.tui.cps.InputEvent
;
import
lu.list.itis.dkd.tui.cps.variable.Variable
;
import
lu.list.itis.dkd.tui.cps.variable.tangible.TangibleNumericalVariable
;
import
lu.list.itis.dkd.tui.widget.builder.GaugeWidgetBuilder
;
import
lu.list.itis.dkd.tui.widget.corona.Gauge
;
import
lu.list.itis.dkd.tui.widget.tether.Tetherable
;
import
com.google.common.base.Preconditions
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* @author nmack
* @date 27 Apr 2015
*
* <br>
* $Log: GaugeWidget.java,v $
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public
class
GaugeWidget
extends
TetherableWidget
implements
InputChangeListener
,
InformationReceiver
<
Double
>
{
private
TangibleNumericalVariable
variable
;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
GaugeWidget
.
class
.
getSimpleName
());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public
GaugeWidget
(
GaugeWidgetBuilder
builder
)
{
super
(
builder
);
Preconditions
.
checkState
(
builder
.
variable
!=
null
,
"The variable may not be null!"
);
//$NON-NLS-1$
this
.
variable
=
builder
.
variable
;
this
.
variable
.
addListener
(
this
);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public
void
inputChanged
(
InputEvent
input
)
{
if
(!
this
.
isTethered
())
{
Variable
source
=
(
Variable
)
input
.
getSource
();
double
value
=
(
Double
)
source
.
getValue
();
LOGGER
.
trace
(
"{} = {}"
,
source
.
getName
(),
value
);
//$NON-NLS-1$
this
.
setInformation
((
Double
)
source
.
getValue
());
}
}
// ---------------------------------------------------------------------------
@Override
public
void
separateFrom
(
Tetherable
tethered
)
{
super
.
separateFrom
(
tethered
);
if
(!
this
.
isTethered
())
{
InputEvent
event
=
new
InputEvent
(
this
.
variable
);
this
.
inputChanged
(
event
);
}
}
// ---------------------------------------------------------------------------
@Override
public
void
setInformation
(
Double
information
)
{
getCoronas
(
Gauge
.
class
).
forEach
(
corona
->
((
InformationReceiver
<
Double
>)
corona
).
setInformation
(
information
));
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
CPS/src/lu/list/itis/dkd/tui/widget/SelectorWidget.java
0 → 100755
View file @
9bec379f
package
lu.list.itis.dkd.tui.widget
;
import
lu.list.itis.dkd.tui.adapter.TangibleObject
;
import
lu.list.itis.dkd.tui.widget.builder.SelectorWidgetBuilder
;
import
lu.list.itis.dkd.tui.widget.corona.FadingCorona
;
import
lu.list.itis.dkd.tui.widget.corona.SelectableCorona
;
import
lu.list.itis.dkd.tui.widget.state.StateManager
;
import
com.google.common.base.Preconditions
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public
class
SelectorWidget
extends
ValueWidget
{
/** Total number of positions to chose from */
protected
int
numberOfPositions
;
/** The currently selected position */
protected
int
currentPosition
=
NONE
;
// ***************************************************************************
// * Constants *
// ***************************************************************************
public
static
int
NONE
=
-
1
;
private
static
double
TWO_PI
=
2
*
Math
.
PI
;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Constructor setting the {@link Map} instance that manages all layers.
*
* @param map
* The map that manages all layers.
*/
// ---------------------------------------------------------------------------
public
SelectorWidget
(
SelectorWidgetBuilder
<?>
builder
)
{
super
(
builder
);
this
.
numberOfPositions
=
this
.
getNumberOfPositions
();
if
(
builder
.
preselect
!=
NONE
)
{
this
.
selectPosition
(
builder
.
preselect
);
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
private
int
getNumberOfPositions
()
{
List
<
SelectableCorona
>
selectableCoronas
=
getCoronas
(
SelectableCorona
.
class
);
HashSet
<
Integer
>
alreadySeen
=
new
HashSet
<>();
for
(
SelectableCorona
corona
:
selectableCoronas
)
{
Integer
index
=
corona
.
getIndex
();
Preconditions
.
checkArgument
(!
alreadySeen
.
contains
(
index
),
"Duplicate Index detected for selectable Corona!"
);
//$NON-NLS-1$
alreadySeen
.
add
(
index
);
}
return
selectableCoronas
.
size
();
}
// ---------------------------------------------------------------------------
private
int
getCurrentPosition
(
float
angle
)
{
double
segment
=
TWO_PI
/
numberOfPositions
;
int
current
=
0
;
// detect in which segment the current rotation is
for
(
int
position
=
0
;
position
<
numberOfPositions
;
position
++)
{
double
minrot
=
(
position
-
0.5
)
*
segment
;
double
maxrot
=
(
position
+
0.5
)
*
segment
;
if
((
angle
>=
minrot
)
&&
(
angle
<
maxrot
))
{
current
=
position
;
break
;
}
}
return
current
;
}
// ---------------------------------------------------------------------------
private
void
selectPosition
(
int
position
)
{
if
(
position
!=
currentPosition
)
{
this
.
getCoronas
(
SelectableCorona
.
class
).
forEach
(
selectable
->
selectable
.
setSelected
(
selectable
.
getIndex
()
==
position
));
if
(
variable
!=
null
)
{
variable
.
setValue
(
position
);
}
currentPosition
=
position
;
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
public
void
setSelectedPosition
(
int
position
)
{
currentPosition
=
position
;
}
// ---------------------------------------------------------------------------
public
int
getSelectedPosition
()
{
return
currentPosition
;
}
// ---------------------------------------------------------------------------
/**
* Method invoked when a handle of the widget was moved. This default implementation will set
* the position and angle fields to the corresponding values.
*
* @param tuioObject
* The TuioObject that was triggering the move
*/
// ---------------------------------------------------------------------------
@Override
public
void
actionMove
(
TangibleObject
tuioObject
)
{
super
.
actionMove
(
tuioObject
);
int
position
=
getCurrentPosition
(
tuioObject
.
getAngle
());
int
widgetId
=
tuioObject
.
getObjectId
();
this
.
getCoronas
(
FadingCorona
.
class
).
forEach
(
corona
->
corona
.
fadeIn
());
StateManager
manager
=
states
.
get
(
widgetId
);
if
(
manager
.
isRotating
())
{
if
(
position
!=
currentPosition
)
{
this
.
selectPosition
(
position
);
}
}
}
// ---------------------------------------------------------------------------
/**
* Method invoked when the tangible is detected on the table surface for the first time. The
* {@link TangibleWidget} instance is set to be active.
*
* @param tuioObject
* The TuioObject that was triggering the drop action.
*/
// ---------------------------------------------------------------------------
@Override
public
void
actionDrop
(
TangibleObject
tuioObject
)
{
super
.
actionDrop
(
tuioObject
);
this
.
selectPosition
(
currentPosition
);
}
// ---------------------------------------------------------------------------
/**
* Method invoked when the tangible is removed from the table surface. The
* {@link TangibleWidget} instance will be set to no longer be active.
*
* @param tuioObject
* The TuioObject that was triggering the drop action.
*/
// ---------------------------------------------------------------------------
@Override
public
void
actionLift
(
TangibleObject
tuioObject
)
{
super
.
actionLift
(
tuioObject
);
if
(!
this
.
isPersistent
(
tuioObject
.
getObjectId
()))
{
this
.
selectPosition
(
NONE
);
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
\ No newline at end of file
CPS/src/lu/list/itis/dkd/tui/widget/ValueWidget.java
View file @
9bec379f
...
...
@@ -25,16 +25,21 @@ import lu.list.itis.dkd.dbc.annotation.Nullable;
import
lu.list.itis.dkd.tui.adapter.TangibleObject
;
import
lu.list.itis.dkd.tui.content.InformationProvider
;
import
lu.list.itis.dkd.tui.content.InformationReceiver
;
import
lu.list.itis.dkd.tui.cps.utility.Externalization
;
import
lu.list.itis.dkd.tui.cps.variable.tangible.TangibleNumericalVariable
;
import
lu.list.itis.dkd.tui.utility.Point
;
import
lu.list.itis.dkd.tui.widget.builder.BaseValueWidgetBuilder
;
import
lu.list.itis.dkd.tui.widget.builder.ValueWidgetBuilder
;
import
lu.list.itis.dkd.tui.widget.corona.ConditionalCorona
;
import
lu.list.itis.dkd.tui.widget.corona.Corona
;
import
lu.list.itis.dkd.tui.widget.tether.DataFeed
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.awt.Graphics2D
;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.Type
;
import
java.util.List
;
/**
* A simple widget that holds an integer value and may modify the value base on a rotation.
...
...
@@ -44,29 +49,37 @@ import java.lang.reflect.Type;
* @version 1.3.0
*/
@NonNullByDefault
public
final
class
ValueWidget
extends
Bas
eWidget
implements
InformationProvider
<
String
>
{
public
class
ValueWidget
extends
Tetherabl
eWidget
implements
InformationProvider
<
String
>
{
/** The minimum value to be stored by the widget. */
pr
ivate
double
lowerBound
;
pr
otected
double
lowerBound
;
/** The maximum value to be stored by the widget. */
pr
ivate
double
upperBound
;
pr
otected
double
upperBound
;
/** The lower bound of the angle the widget can be turned to. */
pr
ivate
double
lowerStopAngle
;
pr
otected
double
lowerStopAngle
;
/** The upper bound of the angle the widget can be turned to. */
pr
ivate
double
upperStopAngle
;
pr
otected
double
upperStopAngle
;
/** The value of the angle that is considered as one step. */
pr
ivate
double
stepSize
;
pr
otected
double
stepSize
;
/** The variable holding the value to be stored and manipulated by the widget. */
pr
ivate
TangibleNumericalVariable
variable
;
pr
otected
TangibleNumericalVariable
variable
;
/** The base value to be set for the variable. */
pr
ivate
final
double
base
Value
;
pr
otected
double
initial
Value
;
/** Whether the value held by the widget is to be modified on a rotation of a handle. */
private
boolean
modifyValueOnRotation
=
false
;
protected
boolean
modifyValueOnRotation
=
false
;
/** Internal flag specifying whether this widgets rotation is constrainted or not! */
protected
boolean
constrainted
;
/**
* Field holding the current angular position of the constrainted (lowerStopAngle |
* upperStopAngle) angle.
*/
protected
double
dialAngle
;
private
double
stepAngle
;
private
double
steps
;
// private double delta;
private
double
dialAngle
;
public
static
final
String
DEFAULT_VARIABLE
=
"Value"
;
//$NON-NLS-1$
private
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ValueWidget
.
class
.
getSimpleName
());
/**
* Constructor setting all fields by calling the super constructor.
...
...
@@ -74,7 +87,7 @@ public final class ValueWidget extends BaseWidget implements InformationProvider
* @param builder
* The builder instance defining all parameters.
*/
public
ValueWidget
(
BaseValueWidgetBuilder
<
ValueWidgetBuilder
>
builder
)
{
public
ValueWidget
(
BaseValueWidgetBuilder
<
?
>
builder
)
{
super
(
builder
);
this
.
lowerBound
=
builder
.
lowerBound
;
...
...
@@ -82,26 +95,38 @@ public final class ValueWidget extends BaseWidget implements InformationProvider
this
.
lowerStopAngle
=
builder
.
lowerStopAngle
;
this
.
upperStopAngle
=
builder
.
upperStopAngle
;
this
.
stepSize
=
builder
.
stepSize
;
this
.
variable
=
builder
.
variable
;
this
.
modifyValueOnRotation
=
builder
.
modifyValueOnRotation
;
/**
* Remember the base value of the variable and then set it to 0d as the value should be nill
* if the widget is not on the table (active). This should only be the case for non-dynamic
* value widgets
*/
if
(
builder
.
variable
==
null
)
{
String
variableName
=
((
this
.
name
!=
null
)
&&
(
this
.
name
.
length
()
>
0
))
?
this
.
name
:
DEFAULT_VARIABLE
;
this
.
variable
=
new
TangibleNumericalVariable
(
variableName
,
Externalization
.
EMPTY_STRING
,
0
);
}
else
{
this
.
variable
=
builder
.
variable
;
}
if
(!
modifyValueOnRotation
)
{
this
.
base
Value
=
getVariable
().
getInformation
();
this
.
initial
Value
=
getVariable
().
getInformation
();
getVariable
().
setValue
(
0
d
);
}
else
{
// this.baseValue = Double.NaN;
this
.
base
Value
=
getVariable
().
getInformation
();
this
.
initial
Value
=
getVariable
().
getInformation
();
}
dialAngle
=
lowerStopAngle
;
steps
=
(
upperBound
-
lowerBound
+
1
)
/
stepSize
;
stepAngle
=
(
upperStopAngle
-
lowerStopAngle
)
/
steps
;
// delta = Double.NaN;
constrainted
=
!(
Double
.
isNaN
(
lowerStopAngle
)
||
Double
.
isNaN
(
upperStopAngle
));
if
(
constrainted
)
{
dialAngle
=
lowerStopAngle
;
steps
=
(
upperBound
-
lowerBound
+
1
)
/
stepSize
;
stepAngle
=
(
upperStopAngle
-
lowerStopAngle
)
/
steps
;
}
}
@SuppressWarnings
(
"unchecked"
)
private
void
updateTethers
(
Double
value
)
{
@SuppressWarnings
(
"rawtypes"
)