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
d3a27161
Commit
d3a27161
authored
Apr 19, 2017
by
Nico Mack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ShapeGraph Corona. Fixed Issue with Vector results in
PythonExecutor
parent
9157f698
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
413 additions
and
4 deletions
+413
-4
CPS/pom.xml
CPS/pom.xml
+1
-1
CPS/src/lu/list/itis/dkd/tui/cps/system/executor/PythonExecutor.java
...list/itis/dkd/tui/cps/system/executor/PythonExecutor.java
+30
-2
CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcGraph.java
CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcGraph.java
+1
-1
CPS/src/lu/list/itis/dkd/tui/widget/corona/ShapeGraph.java
CPS/src/lu/list/itis/dkd/tui/widget/corona/ShapeGraph.java
+198
-0
CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ShapeGraphBuilder.java
...itis/dkd/tui/widget/corona/builder/ShapeGraphBuilder.java
+183
-0
No files found.
CPS/pom.xml
View file @
d3a27161
...
...
@@ -93,7 +93,7 @@
<version>
0.9.5.2
</version>
<scope>
runtime
</scope>
</dependency>
</dependencies>
</dependencies>
<repositories>
<repository>
...
...
CPS/src/lu/list/itis/dkd/tui/cps/system/executor/PythonExecutor.java
View file @
d3a27161
...
...
@@ -103,13 +103,20 @@ public class PythonExecutor extends Executor {
@Override
public
boolean
eval
(
String
script
)
{
boolean
success
=
true
;
this
.
executionErrors
.
reset
();
long
elapsed
=
System
.
currentTimeMillis
();
engine
.
exec
(
script
);
elapsed
=
System
.
currentTimeMillis
()
-
elapsed
;
if
(
LOGGER
.
isInfoEnabled
())
{
LOGGER
.
info
(
"Eval took {} ms | {}"
,
elapsed
,
script
);
//$NON-NLS-1$
}
return
true
;
if
(
this
.
executionErrors
.
size
()
>
0
)
{
LOGGER
.
error
(
"Eval returned an error: {}"
,
this
.
executionErrors
.
toString
());
//$NON-NLS-1$
success
=
false
;
}
return
success
;
}
@Override
...
...
@@ -132,7 +139,28 @@ public class PythonExecutor extends Executor {
}
}
variable
.
setValueFromObject
((
result
!=
null
)
?
result
.
__tojava__
(
Double
.
class
)
:
null
);
if
((
variable
instanceof
VectorVariable
)
&&
(
result
!=
null
))
{
VectorVariable
<?>
vector
=
(
VectorVariable
<?>)
variable
;
vector
.
suspendListenerNotification
(
true
);
vector
.
clear
();
if
(
Double
.
class
.
isAssignableFrom
(
vector
.
getClassOfValues
()))
{
for
(
PyObject
item
:
result
.
asIterable
())
{
vector
.
add
(
item
.
__tojava__
(
Double
.
class
));
}
}
else
if
(
Integer
.
class
.
isAssignableFrom
(
vector
.
getClassOfValues
()))
{
for
(
PyObject
item
:
result
.
asIterable
())
{
vector
.
add
(
item
.
__tojava__
(
Integer
.
class
));
}
}
else
{
for
(
PyObject
item
:
result
.
asIterable
())
{
vector
.
add
(
item
.
__tojava__
(
Object
.
class
));
}
}
vector
.
suspendListenerNotification
(
false
);
vector
.
notifyInputChangeListeners
();
}
else
{
variable
.
setValueFromObject
((
result
!=
null
)
?
result
.
__tojava__
(
Double
.
class
)
:
null
);
}
return
variable
;
}
}
CPS/src/lu/list/itis/dkd/tui/widget/corona/ArcGraph.java
View file @
d3a27161
...
...
@@ -263,7 +263,7 @@ public class ArcGraph extends ValueCorona {
balisticTimeline
.
play
();
if
(
textFont
!=
null
)
{
StringBuilder
labelBuilder
=
new
StringBuilder
(
this
.
variable
.
getName
()).
append
(
" "
);
//$NON-NLS-1$
StringBuilder
labelBuilder
=
new
StringBuilder
(
this
.
variable
.
get
Display
Name
()).
append
(
" "
);
//$NON-NLS-1$
labelBuilder
.
append
(
this
.
variable
.
toString
());
this
.
label
=
labelBuilder
.
toString
();
this
.
labelMetrics
=
textFont
.
getLineMetrics
(
label
.
toString
(),
new
FontRenderContext
(
null
,
true
,
true
));
...
...
CPS/src/lu/list/itis/dkd/tui/widget/corona/ShapeGraph.java
0 → 100644
View file @
d3a27161
/**
* 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.widget.corona
;
import
lu.list.itis.dkd.tui.utility.ColorPair
;
import
lu.list.itis.dkd.tui.utility.Point
;
import
lu.list.itis.dkd.tui.widget.corona.builder.ShapeGraphBuilder
;
import
org.pushingpixels.trident.Timeline
;
import
org.pushingpixels.trident.Timeline.RepeatBehavior
;
import
java.awt.AlphaComposite
;
import
java.awt.BasicStroke
;
import
java.awt.Graphics2D
;
import
java.awt.Shape
;
import
java.awt.Stroke
;
import
java.awt.geom.AffineTransform
;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public
class
ShapeGraph
extends
ValueCorona
{
/** The minimum value to be stored by the widget. */
protected
double
lowerBound
;
/** The maximum value to be stored by the widget. */
protected
double
upperBound
;
/** The lower bound of the angle the widget can be turned to. */
protected
ColorPair
fillColour
;
protected
ColorPair
strokeColour
;
protected
int
strokeWidth
;
protected
Shape
graphShape
;
protected
Timeline
blinkingTimeline
;
protected
Timeline
balisticTimeline
;
private
double
shownValue
;
private
float
angle
;
private
float
opacity
;
private
double
scale
;
private
Stroke
borderStroke
;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param builder
*/
public
ShapeGraph
(
ShapeGraphBuilder
builder
)
{
super
(
builder
);
this
.
lowerBound
=
builder
.
lowerBound
;
this
.
upperBound
=
builder
.
upperBound
;
this
.
fillColour
=
builder
.
fillColour
;
this
.
strokeColour
=
builder
.
strokeColour
;
this
.
strokeWidth
=
builder
.
strokeWidth
;
this
.
graphShape
=
builder
.
graphShape
;
borderStroke
=
(
builder
.
strokeWidth
>
0
)
?
new
BasicStroke
(
builder
.
strokeWidth
)
:
null
;
this
.
setInformation
(
this
.
variable
.
getMinValue
());
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
private
void
startBlinking
()
{
if
((
blinkingTimeline
!=
null
)
&&
(!
blinkingTimeline
.
isDone
()))
blinkingTimeline
.
cancel
();
blinkingTimeline
=
new
Timeline
(
this
);
blinkingTimeline
.
addPropertyToInterpolate
(
"opacity"
,
1.0f
,
0.0f
);
//$NON-NLS-1$
blinkingTimeline
.
setDuration
(
500
);
blinkingTimeline
.
playLoop
(
RepeatBehavior
.
REVERSE
);
}
// ---------------------------------------------------------------------------
private
void
stopBlinking
()
{
if
((
blinkingTimeline
!=
null
)
&&
(!
blinkingTimeline
.
isDone
()))
blinkingTimeline
.
cancel
();
this
.
opacity
=
1.0f
;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
public
void
setShownValue
(
double
value
)
{
shownValue
=
value
;
if
(
variable
!=
null
)
{
double
size
=
lowerBound
+
(
upperBound
-
lowerBound
)
*
(
shownValue
-
this
.
variable
.
getMinValue
())
/
(
this
.
variable
.
getMaxValue
()
-
this
.
variable
.
getMinValue
());
if
(
size
==
upperBound
)
this
.
startBlinking
();
else
this
.
stopBlinking
();
scale
=
size
/
lowerBound
;
}
}
// ---------------------------------------------------------------------------
@Override
public
void
paint
(
Graphics2D
canvas
)
{
if
(!
active
)
return
;
Graphics2D
localCanvas
=
(
Graphics2D
)
canvas
.
create
();
centre
.
toScreenCoordinates
();
if
(
initialTranslation
!=
null
)
initialTranslation
.
toScreenCoordinates
();
Point
drawAt
=
centre
.
add
(
initialTranslation
);
if
(
this
.
rotateWithHandle
)
{
angle
=
(
float
)
(
drawAt
.
getAngle
()
%
TWO_PI
);
}
AffineTransform
translation
=
new
AffineTransform
();
translation
.
translate
(
drawAt
.
x
,
drawAt
.
y
);
translation
.
rotate
(
angle
);
translation
.
scale
(
scale
,
scale
);
localCanvas
.
setTransform
(
translation
);
if
(
this
.
opacity
<
1.0f
)
localCanvas
.
setComposite
(
AlphaComposite
.
SrcOver
.
derive
(
this
.
opacity
));
if
(
graphShape
!=
null
)
{
if
(
fillColour
!=
null
)
{
localCanvas
.
setPaint
(
fillColour
.
getColor
());
localCanvas
.
fill
(
graphShape
);
}
if
(
strokeColour
!=
null
)
{
localCanvas
.
setPaint
(
strokeColour
.
getColor
());
if
(
borderStroke
!=
null
)
{
localCanvas
.
setStroke
(
borderStroke
);
localCanvas
.
draw
(
graphShape
);
}
}
}
if
(
this
.
opacity
<
1.0f
)
localCanvas
.
setComposite
(
AlphaComposite
.
SrcOver
.
derive
(
1.0f
));
localCanvas
.
dispose
();
}
// ---------------------------------------------------------------------------
@Override
public
void
setInformation
(
Object
information
)
{
if
(
variable
!=
null
)
{
double
value
=
this
.
variable
.
getValue
();
if
((
balisticTimeline
!=
null
)
&&
(!
balisticTimeline
.
isDone
()))
balisticTimeline
.
cancel
();
balisticTimeline
=
new
Timeline
(
this
);
balisticTimeline
.
addPropertyToInterpolate
(
"shownValue"
,
shownValue
,
value
);
//$NON-NLS-1$
balisticTimeline
.
setDuration
(
500
);
balisticTimeline
.
play
();
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
CPS/src/lu/list/itis/dkd/tui/widget/corona/builder/ShapeGraphBuilder.java
0 → 100644
View file @
d3a27161
package
lu.list.itis.dkd.tui.widget.corona.builder
;
import
lu.list.itis.dkd.dbc.annotation.Nullable
;
import
lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback
;
import
lu.list.itis.dkd.tui.bootstrapping.BootstrapContext
;
import
lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils
;
import
lu.list.itis.dkd.tui.bootstrapping.ShapeBootstrapper
;
import
lu.list.itis.dkd.tui.exception.BuildException
;
import
lu.list.itis.dkd.tui.utility.ColorPair
;
import
lu.list.itis.dkd.tui.utility.Externalization
;
import
lu.list.itis.dkd.tui.utility.Point
;
import
lu.list.itis.dkd.tui.widget.corona.ShapeGraph
;
import
org.jdom2.Element
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.awt.Color
;
import
java.awt.Shape
;
/**
* @author nmack
* @date 08 Jan 2016
*
* <br>
* $Log: ArcGraphBuilder.java,v $
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public
class
ShapeGraphBuilder
extends
ValueCoronaBuilder
<
ShapeGraphBuilder
>
{
public
double
lowerBound
;
public
double
upperBound
;
public
ColorPair
fillColour
;
public
ColorPair
strokeColour
;
public
int
strokeWidth
;
public
Shape
graphShape
;
// public SVGIcon graphImage;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ShapeGraphBuilder
.
class
.
getSimpleName
());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public
ShapeGraphBuilder
(
Point
centre
)
{
super
(
centre
);
}
/**
* @param rootElement
* @throws BuildException
*/
public
ShapeGraphBuilder
(
Element
rootElement
)
throws
BuildException
{
super
(
rootElement
);
this
.
buildFromBootstrap
(
rootElement
,
null
,
null
);
/** Mandatory fields */
}
/**
* @param rootElement
* @throws BuildException
*/
public
ShapeGraphBuilder
(
Element
rootElement
,
BootstrapContext
context
,
BootstrapCallback
callback
)
throws
BuildException
{
super
(
rootElement
,
context
,
callback
);
this
.
buildFromBootstrap
(
rootElement
,
context
,
callback
);
/** Mandatory fields */
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
private
void
buildFromBootstrap
(
@Nullable
Element
rootElement
,
BootstrapContext
context
,
BootstrapCallback
callback
)
throws
BuildException
{
lowerBound
=
BootstrappingUtils
.
getContentAsDouble
(
rootElement
,
Externalization
.
LOWER_BOUND_NODE
,
BootstrappingUtils
.
MANDATORY
,
null
,
context
);
upperBound
=
BootstrappingUtils
.
getContentAsDouble
(
rootElement
,
Externalization
.
UPPER_BOUND_NODE
,
BootstrappingUtils
.
MANDATORY
,
null
,
context
);
/** Optional fields */
strokeWidth
=
BootstrappingUtils
.
getContentAsInteger
(
rootElement
,
Externalization
.
STROKE_WIDTH_NODE
,
BootstrappingUtils
.
OPTIONAL
,
1
,
context
);
fillColour
=
buildColorPair
(
rootElement
.
getChild
(
Externalization
.
FILL_COLOUR_ELEMENT
),
context
);
strokeColour
=
buildColorPair
(
rootElement
.
getChild
(
Externalization
.
STROKE_COLOUR_ELEMENT
),
context
);
graphShape
=
ShapeBootstrapper
.
getShape
(
rootElement
.
getChild
(
Externalization
.
SHAPE_NODE
),
context
,
callback
);
// String graphImagePath = BootstrappingUtils.getContentAsString(rootElement,
// Externalization.IMAGE_ELEMENT, BootstrappingUtils.OPTIONAL, null, context);
// if (!Strings.isNullOrEmpty(graphImagePath)) {
// this.graphImage = this.loadSVGResource(graphImagePath);
// }
}
// ---------------------------------------------------------------------------
// private SVGIcon loadSVGResource(String resourcePath) {
// SVGIcon icon = null;
// try {
// URI uri = SVGCache.getSVGUniverse().loadSVG(new BufferedReader(new
// InputStreamReader(getClass().getResource(resourcePath).openStream())), "shape");
// //$NON-NLS-1$
// icon = new SVGIcon();
// icon.setSvgURI(uri);
// icon.setAntiAlias(true);
// } catch (IOException e) {
// LOGGER.error("Failed to load SVG resource {}!", resourcePath); //$NON-NLS-1$
// }
// return icon;
// }
// ---------------------------------------------------------------------------
private
ColorPair
buildColorPair
(
Element
rootElement
,
BootstrapContext
context
)
throws
BuildException
{
Color
selectedColour
=
BootstrappingUtils
.
getContentAsColour
(
rootElement
,
Externalization
.
SELECTED_ELEMENT
,
BootstrappingUtils
.
MANDATORY
,
null
,
context
);
Color
deselectedColour
=
BootstrappingUtils
.
getContentAsColour
(
rootElement
,
Externalization
.
DESELECTED_ELEMENT
,
BootstrappingUtils
.
MANDATORY
,
null
,
context
);
return
new
ColorPair
(
selectedColour
,
deselectedColour
);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
public
ShapeGraphBuilder
withFillColours
(
Color
selectedColour
,
Color
deselectedColour
)
{
fillColour
=
new
ColorPair
(
selectedColour
,
deselectedColour
);
return
this
;
}
// ---------------------------------------------------------------------------
public
ShapeGraphBuilder
withStrokeColours
(
Color
selectedColour
,
Color
deselectedColour
)
{
strokeColour
=
new
ColorPair
(
selectedColour
,
deselectedColour
);
return
this
;
}
// ---------------------------------------------------------------------------
public
ShapeGraphBuilder
withStrokeWidth
(
int
width
)
{
this
.
strokeWidth
=
width
;
return
this
;
}
// ---------------------------------------------------------------------------
public
ShapeGraphBuilder
withGraphShape
(
Shape
shape
)
{
graphShape
=
shape
;
return
this
;
}
// // ---------------------------------------------------------------------------
//
// public ShapeGraphBuilder withGraphImage(SVGIcon image) {
// graphImage = image;
// return this;
// }
//
// ---------------------------------------------------------------------------
@Override
public
ShapeGraph
build
()
throws
BuildException
{
return
new
ShapeGraph
(
this
);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment