Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
e129f75d
Commit
e129f75d
authored
Apr 01, 2019
by
Piotr Gawron
Browse files
reaction colors are encoded properly so COPASI can read it
parent
31199bb0
Changes
4
Hide whitespace changes
Inline
Side-by-side
commons/src/main/java/lcsb/mapviewer/common/comparator/FloatComparator.java
0 → 100644
View file @
e129f75d
package
lcsb.mapviewer.common.comparator
;
import
java.util.Comparator
;
import
lcsb.mapviewer.common.Configuration
;
/**
* Comparator used for {@link Float} class.
*
* @author Piotr Gawron
*
*/
public
class
FloatComparator
implements
Comparator
<
Float
>
{
/**
* Epsilon value used for comparison of doubles.
*/
private
double
epsilon
;
/**
* Default constructor.
*/
public
FloatComparator
()
{
this
(
Configuration
.
EPSILON
);
}
/**
* Constructor that requires {@link #epsilon} parameter.
*
* @param epsilon
* {@link #epsilon}
*/
public
FloatComparator
(
double
epsilon
)
{
this
.
epsilon
=
epsilon
;
}
@Override
public
int
compare
(
Float
arg0
,
Float
arg1
)
{
if
(
arg0
==
null
)
{
if
(
arg1
==
null
)
{
return
0
;
}
else
{
return
1
;
}
}
else
if
(
arg1
==
null
)
{
return
-
1
;
}
if
(
Math
.
abs
(
arg0
-
arg1
)
<
epsilon
)
{
return
0
;
}
else
{
return
arg0
.
compareTo
(
arg1
);
}
}
}
converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionExporter.java
View file @
e129f75d
...
...
@@ -293,10 +293,10 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
LocalStyle
style
=
new
LocalStyle
();
style
.
setGroup
(
new
RenderGroup
());
renderInformation
.
addLocalStyle
(
style
);
style
.
getGroup
().
setStroke
(
node
.
getLine
().
getType
().
name
());
ColorDefinition
color
=
getColorDefinition
(
node
.
getLine
().
getColor
());
style
.
getGroup
().
setStroke
Width
(
node
.
getLine
().
getWidth
());
style
.
getGroup
().
setStroke
(
color
.
getId
());
style
.
getGroup
().
setFill
(
color
.
getId
());
style
.
getGroup
().
setStrokeWidth
(
node
.
getLine
().
getWidth
());
style
.
getGroup
().
setStrokeDashArray
(
strokeToArray
(
node
.
getLine
().
getType
().
getStroke
()));
return
style
;
...
...
converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/reaction/SbmlReactionParser.java
View file @
e129f75d
...
...
@@ -30,6 +30,7 @@ import org.sbml.jsbml.ext.render.LocalStyle;
import
org.sbml.jsbml.ext.render.RenderGroup
;
import
org.w3c.dom.Node
;
import
lcsb.mapviewer.common.XmlParser
;
import
lcsb.mapviewer.common.exception.InvalidArgumentException
;
import
lcsb.mapviewer.common.exception.InvalidStateException
;
import
lcsb.mapviewer.common.exception.InvalidXmlSchemaException
;
...
...
@@ -247,21 +248,16 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
private
void
applyStyleToReactionNode
(
ReactionNode
modifier
,
LocalStyle
style
,
boolean
reverse
)
{
RenderGroup
group
=
style
.
getGroup
();
if
(
group
.
isSet
Fill
())
{
Color
color
=
getColorByColorDefinition
(
group
.
get
Fill
());
if
(
group
.
isSet
Stroke
())
{
Color
color
=
getColorByColorDefinition
(
group
.
get
Stroke
());
modifier
.
getLine
().
setColor
(
color
);
}
if
(
group
.
isSetStrokeWidth
())
{
modifier
.
getLine
().
setWidth
(
group
.
getStrokeWidth
());
}
if
(
group
.
isSetStroke
())
{
try
{
LineType
type
=
LineType
.
valueOf
(
group
.
getStroke
());
modifier
.
getLine
().
setType
(
type
);
}
catch
(
Exception
e
)
{
logger
.
warn
(
new
ElementUtils
().
getElementTag
(
modifier
.
getReaction
())
+
"Problematic line type: "
+
group
.
getStroke
(),
e
);
}
if
(
group
.
isSetStrokeDashArray
())
{
LineType
type
=
LineType
.
getTypeByDashArray
(
group
.
getStrokeDashArray
());
modifier
.
getLine
().
setType
(
type
);
}
if
(
group
.
isSetEndHead
())
{
try
{
...
...
@@ -413,8 +409,8 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
public
void
applyStyleToReaction
(
Reaction
reactionWithLayout
,
LocalStyle
style
)
{
RenderGroup
group
=
style
.
getGroup
();
if
(
group
.
getFill
()
!=
null
)
{
Color
color
=
getColorByColorDefinition
(
group
.
get
Fill
());
if
(
group
.
isSetStroke
()
)
{
Color
color
=
getColorByColorDefinition
(
group
.
get
Stroke
());
for
(
AbstractNode
node
:
reactionWithLayout
.
getNodes
())
{
node
.
getLine
().
setColor
(
color
);
}
...
...
@@ -424,15 +420,10 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
node
.
getLine
().
setWidth
(
group
.
getStrokeWidth
());
}
}
if
(
group
.
isSetStroke
())
{
try
{
LineType
type
=
LineType
.
valueOf
(
group
.
getStroke
());
for
(
AbstractNode
node
:
reactionWithLayout
.
getNodes
())
{
node
.
getLine
().
setType
(
type
);
}
}
catch
(
Exception
e
)
{
logger
.
warn
(
new
ElementUtils
().
getElementTag
(
reactionWithLayout
)
+
"Problematic line type: "
+
group
.
getStroke
(),
e
);
if
(
group
.
isSetStrokeDashArray
())
{
LineType
type
=
LineType
.
getTypeByDashArray
(
group
.
getStrokeDashArray
());
for
(
AbstractNode
node
:
reactionWithLayout
.
getNodes
())
{
node
.
getLine
().
setType
(
type
);
}
}
if
(
group
.
isSetEndHead
())
{
...
...
model/src/main/java/lcsb/mapviewer/model/graphics/LineType.java
View file @
e129f75d
...
...
@@ -2,7 +2,9 @@ package lcsb.mapviewer.model.graphics;
import
java.awt.BasicStroke
;
import
java.awt.Stroke
;
import
java.util.List
;
import
lcsb.mapviewer.common.comparator.FloatComparator
;
import
lcsb.mapviewer.common.geometry.CompositeStroke
;
/**
...
...
@@ -21,7 +23,7 @@ public enum LineType {
* Solid bold line.
*/
SOLID_BOLD
(
3
),
/**
* Dash-dot-dot line:
*
...
...
@@ -30,7 +32,7 @@ public enum LineType {
* </pre>
*/
DASH_DOT_DOT
(
1
,
new
float
[]
{
11.0f
,
3.0f
,
1.0f
,
3.0f
,
1.0f
,
3.0f
}),
/**
* Dash-dot line:
*
...
...
@@ -132,4 +134,25 @@ public enum LineType {
public
Stroke
getStroke
()
{
return
stroke
;
}
public
static
LineType
getTypeByDashArray
(
List
<
Short
>
strokeDashArray
)
{
FloatComparator
doubleComparator
=
new
FloatComparator
();
for
(
LineType
type
:
LineType
.
values
())
{
if
(
type
.
getStroke
()
instanceof
BasicStroke
)
{
BasicStroke
basicStroke
=
(
BasicStroke
)
type
.
getStroke
();
if
(
basicStroke
.
getDashArray
()
!=
null
&&
strokeDashArray
.
size
()
==
basicStroke
.
getDashArray
().
length
)
{
boolean
match
=
true
;
for
(
int
i
=
0
;
i
<
strokeDashArray
.
size
();
i
++)
{
if
(
doubleComparator
.
compare
(
basicStroke
.
getDashArray
()[
i
],
(
float
)
strokeDashArray
.
get
(
i
))
!=
0
)
{
match
=
false
;
}
}
if
(
match
)
{
return
type
;
}
}
}
}
return
LineType
.
SOLID
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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