Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Devrim Gunyel
core
Commits
3a8d4e6f
Commit
3a8d4e6f
authored
Nov 12, 2019
by
Piotr Gawron
Browse files
color definitions are supported
parent
40e94d06
Changes
4
Hide whitespace changes
Inline
Side-by-side
commons/src/main/java/lcsb/mapviewer/common/geometry/ColorParser.java
View file @
3a8d4e6f
...
...
@@ -56,7 +56,7 @@ public class ColorParser {
throw
new
InvalidArgumentException
(
"Invalid color value: "
+
string
+
". Correct format: #xxxxxx (where x is a hex value)"
);
}
if
(
string
.
charAt
(
0
)
!=
'#'
)
{
string
=
"#"
+
string
;
}
...
...
@@ -86,10 +86,15 @@ public class ColorParser {
throw
new
InvalidArgumentException
(
"Invalid color value: "
+
string
+
". Correct format: #xxxxxx (where x is a hex value)"
);
}
else
{
return
new
Color
(
Integer
.
valueOf
(
string
.
substring
(
COLOR_SUBSTRING_START_RED
,
COLOR_SUBSTRING_START_GREEN
),
HEX_BASE
),
Integer
.
valueOf
(
string
.
substring
(
COLOR_SUBSTRING_START_GREEN
,
COLOR_SUBSTRING_START_BLUE
),
HEX_BASE
),
Integer
.
valueOf
(
string
.
substring
(
COLOR_SUBSTRING_START_BLUE
,
COLOR_STRING_LENGTH_WITHOUT_ALPHA
),
HEX_BASE
));
try
{
return
new
Color
(
Integer
.
valueOf
(
string
.
substring
(
COLOR_SUBSTRING_START_RED
,
COLOR_SUBSTRING_START_GREEN
),
HEX_BASE
),
Integer
.
valueOf
(
string
.
substring
(
COLOR_SUBSTRING_START_GREEN
,
COLOR_SUBSTRING_START_BLUE
),
HEX_BASE
),
Integer
.
valueOf
(
string
.
substring
(
COLOR_SUBSTRING_START_BLUE
,
COLOR_STRING_LENGTH_WITHOUT_ALPHA
),
HEX_BASE
));
}
catch
(
NumberFormatException
e
)
{
throw
new
InvalidArgumentException
(
"Invalid color value: "
+
string
+
". Correct format: #xxxxxx (where x is a hex value)"
);
}
}
}
...
...
@@ -112,12 +117,17 @@ public class ColorParser {
throw
new
InvalidArgumentException
(
"Invalid color value: "
+
string
+
". Correct format: #xxxxxxxx (where x is a hex value)"
);
}
else
{
return
new
Color
(
Integer
.
valueOf
(
string
.
substring
(
COLOR_SUBSTRING_START_RED
,
COLOR_SUBSTRING_START_GREEN
),
HEX_BASE
),
Integer
.
valueOf
(
string
.
substring
(
COLOR_SUBSTRING_START_GREEN
,
COLOR_SUBSTRING_START_BLUE
),
HEX_BASE
),
Integer
.
valueOf
(
string
.
substring
(
COLOR_SUBSTRING_START_BLUE
,
COLOR_STRING_LENGTH_WITHOUT_ALPHA
),
HEX_BASE
),
Integer
.
valueOf
(
string
.
substring
(
COLOR_STRING_LENGTH_WITHOUT_ALPHA
,
COLOR_STRING_LENGTH_WITH_ALPHA
),
HEX_BASE
)
);
try
{
return
new
Color
(
Integer
.
valueOf
(
string
.
substring
(
COLOR_SUBSTRING_START_RED
,
COLOR_SUBSTRING_START_GREEN
),
HEX_BASE
),
Integer
.
valueOf
(
string
.
substring
(
COLOR_SUBSTRING_START_GREEN
,
COLOR_SUBSTRING_START_BLUE
),
HEX_BASE
),
Integer
.
valueOf
(
string
.
substring
(
COLOR_SUBSTRING_START_BLUE
,
COLOR_STRING_LENGTH_WITHOUT_ALPHA
),
HEX_BASE
),
Integer
.
valueOf
(
string
.
substring
(
COLOR_STRING_LENGTH_WITHOUT_ALPHA
,
COLOR_STRING_LENGTH_WITH_ALPHA
),
HEX_BASE
));
}
catch
(
NumberFormatException
e
)
{
throw
new
InvalidArgumentException
(
"Invalid color value: "
+
string
+
". Correct format: #xxxxxxxx (where x is a hex value)"
);
}
}
}
...
...
converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java
View file @
3a8d4e6f
...
...
@@ -724,13 +724,13 @@ public class SbgnmlXmlParser {
Style
style
=
RenderUtil
.
getStyle
(
renderInformation
,
glyph
);
if
(
style
!=
null
)
{
try
{
element
.
setFillColor
(
colorParser
.
parse
(
style
.
getG
().
getFill
()));
element
.
setFillColor
(
extractColor
(
style
.
getG
().
getFill
()));
}
catch
(
InvalidArgumentException
e
)
{
logger
.
warn
(
new
LogMarker
(
ProjectLogEntryType
.
PARSING_ISSUE
,
element
),
"Invalid fill color: "
+
style
.
getG
().
getFill
());
}
try
{
element
.
setBorderColor
(
colorParser
.
parse
(
style
.
getG
().
getStroke
()));
element
.
setBorderColor
(
extractColor
(
style
.
getG
().
getStroke
()));
}
catch
(
InvalidArgumentException
e
)
{
logger
.
warn
(
new
LogMarker
(
ProjectLogEntryType
.
PARSING_ISSUE
,
element
),
"Invalid border color: "
+
style
.
getG
().
getStroke
());
...
...
@@ -746,6 +746,29 @@ public class SbgnmlXmlParser {
}
}
private
Color
extractColor
(
String
fill
)
{
Color
color
=
getRenderColor
(
fill
);
if
(
color
==
null
)
{
color
=
colorParser
.
parse
(
fill
);
}
return
color
;
}
private
Color
getRenderColor
(
String
color
)
{
ColorDefinition
colorDefinition
=
RenderUtil
.
getColorDefinition
(
renderInformation
,
color
);
if
(
colorDefinition
!=
null
)
{
return
colorParser
.
parse
(
colorDefinition
.
getValue
());
}
LinearGradient
gradient
=
RenderUtil
.
getGradient
(
renderInformation
,
color
);
if
(
gradient
!=
null
)
{
if
(
gradient
.
getStop
().
size
()
>
0
)
{
return
colorParser
.
parse
(
gradient
.
getStop
().
get
(
0
).
getStopColor
());
}
}
return
null
;
}
private
void
assignRenderInformation
(
PolylineData
line
,
Arc
glyph
)
{
if
(
renderInformation
!=
null
)
{
Style
style
=
RenderUtil
.
getStyle
(
renderInformation
,
glyph
);
...
...
@@ -756,10 +779,9 @@ public class SbgnmlXmlParser {
private
void
assignRenderInformation
(
PolylineData
line
,
Style
style
)
{
if
(
style
!=
null
)
{
try
{
Color
color
=
colorParser
.
parse
(
style
.
getG
().
getStroke
());
line
.
setColor
(
color
);
line
.
setColor
(
extractColor
(
style
.
getG
().
getStroke
()));
}
catch
(
InvalidArgumentException
e
)
{
logger
.
warn
(
"Invalid
border
color: "
+
style
.
getG
().
getStroke
());
logger
.
warn
(
"Invalid
line
color: "
+
style
.
getG
().
getStroke
());
}
if
(
style
.
getG
().
getStrokeWidth
()
!=
null
)
{
double
lineWidth
=
(
double
)
style
.
getG
().
getStrokeWidth
();
...
...
converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/AllSbgnmlTests.java
View file @
3a8d4e6f
...
...
@@ -15,3 +15,4 @@ import org.junit.runners.Suite.SuiteClasses;
public
class
AllSbgnmlTests
{
}
converter-SBGNML/src/test/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParserTest2.java
View file @
3a8d4e6f
...
...
@@ -2,6 +2,7 @@ package lcsb.mapviewer.converter.model.sbgnml;
import
static
org
.
junit
.
Assert
.*;
import
java.awt.Color
;
import
java.awt.geom.Point2D
;
import
org.apache.logging.log4j.LogManager
;
...
...
@@ -115,6 +116,16 @@ public class SbgnmlXmlParserTest2 extends SbgnmlTestFunctions {
assertEquals
(
0
,
protein
.
getModificationResidues
().
size
());
}
@Test
public
void
testParseColors
()
throws
Exception
{
Converter
converter
=
new
SbgnmlXmlConverter
();
Model
model
=
converter
.
createModel
(
new
ConverterParams
()
.
filename
(
"testFiles/sbgnmlCellDesignerInompatible/neuronal_muscle_signalling_color.sbgn"
));
assertFalse
(
model
.
getElementByElementId
(
"glyph0"
).
getFillColor
().
equals
(
Color
.
WHITE
));
assertTrue
(
super
.
getWarnings
().
size
()
<=
1
);
}
@Test
public
void
testProblematicProduct
()
throws
Exception
{
Converter
converter
=
new
SbgnmlXmlConverter
();
...
...
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