Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
243751d7
Commit
243751d7
authored
Oct 11, 2016
by
Piotr Gawron
Browse files
not compiling work in progress ;/
parent
fb0fffb8
Changes
13
Hide whitespace changes
Inline
Side-by-side
model-command/src/main/java/lcsb/mapviewer/commands/ClearColorModelCommand.java
0 → 100644
View file @
243751d7
package
lcsb.mapviewer.commands
;
import
java.awt.Color
;
import
java.util.ArrayList
;
import
lcsb.mapviewer.model.map.model.Model
;
public
class
ClearColorModelCommand
extends
ModelCommand
{
ColorModelCommand
colorModelCommand
;
/**
* Default constructor.
*
* @param model
* original model
*/
public
ClearColorModelCommand
(
Model
model
)
{
super
(
model
);
colorModelCommand
=
new
ColorModelCommand
(
model
,
new
ArrayList
<>(),
new
ColorExtractor
(
Color
.
WHITE
,
Color
.
WHITE
));
}
@Override
protected
void
undoImplementation
()
throws
CommandExecutionException
{
colorModelCommand
.
undo
();
}
@Override
protected
void
redoImplementation
()
throws
CommandExecutionException
{
colorModelCommand
.
redo
();
}
@Override
protected
void
executeImplementation
()
throws
CommandExecutionException
{
colorModelCommand
.
execute
();
}
}
model-command/src/main/java/lcsb/mapviewer/commands/ColorExtractor.java
0 → 100644
View file @
243751d7
package
lcsb.mapviewer.commands
;
import
java.awt.Color
;
import
lcsb.mapviewer.model.map.layout.ColorSchema
;
public
class
ColorExtractor
{
private
Color
minColor
;
private
Color
maxColor
;
public
ColorExtractor
(
Color
minColor
,
Color
maxColor
)
{
this
.
minColor
=
minColor
;
this
.
maxColor
=
maxColor
;
}
/**
* Extracts color from {@link ColorSchema} object.
*
* @return color from {@link ColorSchema} object
*/
public
Color
getNormalizedColor
(
ColorSchema
colorSchema
)
{
if
(
colorSchema
.
getColor
()
!=
null
)
{
return
colorSchema
.
getColor
();
}
else
{
return
getColorForValue
(
colorSchema
.
getValue
());
}
}
/**
* Returns color from red - green scale for the given normalized double value
* (from range -1,1).
*
* @param value
* double value that should be converted into color
* @return color for the double value
*/
protected
Color
getColorForValue
(
Double
value
)
{
if
(
value
>
0
)
{
double
ratio
=
(
1
-
value
);
return
new
Color
((
int
)
(
maxColor
.
getRed
()
*
ratio
),
(
int
)
(
maxColor
.
getGreen
()
*
ratio
),
(
int
)
(
maxColor
.
getBlue
()
*
ratio
));
}
if
(
value
<
0
)
{
double
ratio
=
1
+
value
;
return
new
Color
((
int
)
(
minColor
.
getRed
()
*
ratio
),
(
int
)
(
minColor
.
getGreen
()
*
ratio
),
(
int
)
(
minColor
.
getBlue
()
*
ratio
));
}
return
Color
.
WHITE
;
}
}
model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java
View file @
243751d7
...
...
@@ -47,6 +47,8 @@ public class ColorModelCommand extends ModelCommand {
*/
private
Collection
<
ColorSchema
>
schemas
;
private
ColorExtractor
colorExtractor
;
/**
* Default constructor.
*
...
...
@@ -55,9 +57,10 @@ public class ColorModelCommand extends ModelCommand {
* @param schemas
* set of color schemas used in this command to color model.
*/
public
ColorModelCommand
(
Model
model
,
Collection
<
ColorSchema
>
schemas
)
{
public
ColorModelCommand
(
Model
model
,
Collection
<
ColorSchema
>
schemas
,
ColorExtractor
colorExtractor
)
{
super
(
model
);
this
.
schemas
=
schemas
;
this
.
colorExtractor
=
colorExtractor
;
}
/**
...
...
@@ -75,7 +78,7 @@ public class ColorModelCommand extends ModelCommand {
throw
new
InvalidColorSchemaException
(
"At least two rows try to set color to reaction: "
+
reaction
.
getIdReaction
());
}
Color
color
=
schema
.
getNormalizedColor
();
Color
color
=
colorExtractor
.
getNormalizedColor
(
schema
);
for
(
AbstractNode
node
:
reaction
.
getNodes
())
{
node
.
getLine
().
setColor
(
color
);
if
(
schema
.
getLineWidth
()
!=
null
)
{
...
...
@@ -148,7 +151,7 @@ public class ColorModelCommand extends ModelCommand {
throw
new
InvalidColorSchemaException
(
"At least two rows try to set color to element: "
+
alias
.
getName
());
}
alias
.
setColor
(
schema
.
getNormalizedColor
());
alias
.
setColor
(
colorExtractor
.
getNormalizedColor
(
schema
));
}
}
...
...
@@ -263,7 +266,7 @@ public class ColorModelCommand extends ModelCommand {
for
(
ColorSchema
schema
:
schemas
)
{
for
(
Element
alias
:
model2
.
getElements
())
{
if
(
match
(
alias
,
schema
))
{
if
(
result
.
get
(
alias
)
!=
null
&&
!
result
.
get
(
alias
)
.
getNormalizedColor
().
equals
(
Color
.
WHITE
))
{
if
(
result
.
get
(
alias
)
!=
null
&&
!
colorExtractor
.
getNormalizedColor
(
result
.
get
(
alias
)
).
equals
(
Color
.
WHITE
))
{
throw
new
InvalidColorSchemaException
(
"Alias "
+
alias
.
getElementId
()
+
" is colored by more than one rule."
);
}
result
.
put
(
alias
,
schema
);
...
...
@@ -271,7 +274,7 @@ public class ColorModelCommand extends ModelCommand {
}
for
(
Reaction
reaction
:
model2
.
getReactions
())
{
if
(
match
(
reaction
,
schema
))
{
if
(
result
.
get
(
reaction
)
!=
null
&&
!
result
.
get
(
reaction
)
.
getNormalizedColor
(
).
equals
(
Color
.
WHITE
))
{
if
(
result
.
get
(
reaction
)
!=
null
&&
!
colorExtractor
.
getNormalizedColor
(
result
.
get
(
reaction
)).
equals
(
Color
.
WHITE
))
{
throw
new
InvalidColorSchemaException
(
"Reaction "
+
reaction
.
getIdReaction
()
+
" is colored by more than one rule."
);
}
result
.
put
(
reaction
,
schema
);
...
...
model/src/main/java/lcsb/mapviewer/model/map/layout/ColorSchema.java
View file @
243751d7
...
...
@@ -483,39 +483,6 @@ public abstract class ColorSchema implements Serializable {
this
.
types
.
add
(
clazz
);
}
/**
* Extracts color from {@link ColorSchema} object.
*
* @return color from {@link ColorSchema} object
*/
public
Color
getNormalizedColor
()
{
if
(
getColor
()
!=
null
)
{
return
getColor
();
}
else
{
return
getColorForValue
(
getValue
());
}
}
/**
* Returns color from red - green scale for the given normalized double value
* (from range -1,1).
*
* @param value
* double value that should be converted into color
* @return color for the double value
*/
protected
Color
getColorForValue
(
Double
value
)
{
if
(
value
>
0
)
{
int
val
=
(
int
)
((
1
-
value
)
*
MAX_SINGLE_COLOR_VALUE_IN_RGB_FORMAT
);
return
new
Color
(
val
,
MAX_SINGLE_COLOR_VALUE_IN_RGB_FORMAT
,
val
);
}
if
(
value
<
0
)
{
int
val
=
(
int
)
((
1
+
value
)
*
MAX_SINGLE_COLOR_VALUE_IN_RGB_FORMAT
);
return
new
Color
(
MAX_SINGLE_COLOR_VALUE_IN_RGB_FORMAT
,
val
,
val
);
}
return
Color
.
WHITE
;
}
/**
* @return the description
* @see #description
...
...
model/src/main/java/lcsb/mapviewer/model/user/ConfigurationElementEditType.java
0 → 100644
View file @
243751d7
package
lcsb.mapviewer.model.user
;
/**
* Defines how the {@link ConfigurationElementType} should be edited (what kind
* of values we are storing).
*
* @author Piotr Gawron
*
*/
public
enum
ConfigurationElementEditType
{
/**
* Double value.
*/
DOUBLE
,
/**
* Integer value.
*/
INTEGER
,
/**
* String value.
*/
STRING
,
/**
* Color value (for color picker).
*/
COLOR
,
/**
* Url value.
*/
URL
,
/**
* Email value.
*/
EMAIL
,
/**
* Password value.
*/
PASSWORD
,
}
model/src/main/java/lcsb/mapviewer/model/user/ConfigurationElementType.java
View file @
243751d7
package
lcsb.mapviewer.model.user
;
/**
* This enum defines all possible configuration parameter that are configurable
* by the user.
*
* @author Piotr Gawron
*
*/
public
enum
ConfigurationElementType
{
/**
* Email address used for sending email from the system.
*/
EMAIL_ADDRESS
(
"E-mail address"
,
"your.account@domain.com"
),
//
/**
* Login for the email account.
*/
EMAIL_LOGIN
(
"E-mail server login"
,
"your@login"
),
//
/**
* Password for the email account.
*/
EMAIL_PASSWORD
(
"E-mail server password"
,
"email.secret.password"
),
//
/**
* Addres of the imap server.
*/
EMAIL_IMAP_SERVER
(
"IMAP server"
,
"your.imap.domain.com"
),
//
/**
* Address of the smtp server.
*/
EMAIL_SMTP_SERVER
(
"SMTP server"
,
"your.smtp.domain.com"
),
//
/**
* Port used for smtp connection (sending emails).
*/
EMAIL_SMTP_PORT
(
"SMTP port"
,
"25"
),
//
/**
* Default map that should be presented if no map is selected by user side.
*/
DEFAULT_MAP
(
"Default Project Id"
,
"empty"
),
//
/**
* Logo presented in the system.
*/
LOGO_IMG
(
"Logo icon"
,
"udl.png"
),
//
/**
* Address connected to the logo.
*/
LOGO_LINK
(
"Logo link (after click)"
,
"http://wwwen.uni.lu/"
),
//
/**
* Maximum distance (in pixels) that is allowed during finding closest element
* on the map.
*/
SEARCH_DISTANCE
(
"Max distance for clicking on element (px)"
,
"10"
),
/**
* Email used for requesting an account (in client side).
*/
REQUEST_ACCOUNT_EMAIL
(
"Email used for requesting an account"
,
"your.email@domain.com"
),
/**
* Max number of results in search box.
*/
SEARCH_RESULT_NUMBER
(
"Max number of results in search box. "
,
"100"
),
/**
* Google Analytics tracking ID used for statistics. This tracking ID should
* look like "UA-000000-01". More information about tracking ID can be found
* <a href="https://support.google.com/analytics/answer/1032385?hl=en"> here
* </a>.
*/
GOOGLE_ANALYTICS_IDENTIFIER
(
"Google Analytics tracking ID used for statistics"
,
""
),
/**
* Description of the logo presented in the system.
*/
LOGO_TEXT
(
"Logo description"
,
"University of Luxembourg"
),
/**
* Domain allowed to connect via x-frame technology.
*/
X_FRAME_DOMAIN
(
"Domain allowed to connect via x-frame technology"
,
""
),
/**
* Relative directory (in webapps folder) where big files will be stored.
*/
BIG_FILE_STORAGE_DIR
(
"Path to store big files"
,
"minerva-big/"
),
/**
* File where legend 1/4 is stored.
*/
LENGEND_FILE_1
(
"Legend 1 image file"
,
"resources/images/legend_a.png"
),
/**
* File where legend 2/4 is stored.
*/
LENGEND_FILE_2
(
"Legend 2 image file"
,
"resources/images/legend_b.png"
),
/**
* File where legend 3/4 is stored.
*/
LENGEND_FILE_3
(
"Legend 3 image file"
,
"resources/images/legend_c.png"
),
/**
* File where legend 4/4 is stored.
*/
LENGEND_FILE_4
(
"Legend 4 image file"
,
"resources/images/legend_d.png"
),
/**
* File where legend 4/4 is stored.
*/
USER_MANUAL_FILE
(
"User manual file"
,
"resources/other/user_guide.pdf"
);
/**
* Default value of the configuration parameter (it will be used only when
* value doesn't exist in the DAO).
*/
private
String
defaultValue
=
""
;
/**
* Common name used for visualization (query user).
*/
private
String
commonName
=
""
;
/**
* Default constructor.
*
* @param commonName
* common name used for this parameter
* @param defaultVal
* default value assigned to this parameter
*/
ConfigurationElementType
(
String
commonName
,
String
defaultVal
)
{
this
.
defaultValue
=
defaultVal
;
this
.
commonName
=
commonName
;
}
/**
* @return the defaultValue
* @see #defaultValue
*/
public
String
getDefaultValue
()
{
return
defaultValue
;
}
/**
* @return the commonName
* @see #commonName
*/
public
String
getCommonName
()
{
return
commonName
;
}
}
package
lcsb.mapviewer.model.user
;
/**
* This enum defines all possible configuration parameter that are configurable
* by the user.
*
* @author Piotr Gawron
*
*/
public
enum
ConfigurationElementType
{
/**
* Email address used for sending email from the system.
*/
EMAIL_ADDRESS
(
"E-mail address"
,
"your.account@domain.com"
,
ConfigurationElementEditType
.
EMAIL
),
//
/**
* Login for the email account.
*/
EMAIL_LOGIN
(
"E-mail server login"
,
"your@login"
,
ConfigurationElementEditType
.
STRING
),
//
/**
* Password for the email account.
*/
EMAIL_PASSWORD
(
"E-mail server password"
,
"email.secret.password"
,
ConfigurationElementEditType
.
PASSWORD
),
//
/**
* Addres of the imap server.
*/
EMAIL_IMAP_SERVER
(
"IMAP server"
,
"your.imap.domain.com"
,
ConfigurationElementEditType
.
STRING
),
//
/**
* Address of the smtp server.
*/
EMAIL_SMTP_SERVER
(
"SMTP server"
,
"your.smtp.domain.com"
,
ConfigurationElementEditType
.
STRING
),
//
/**
* Port used for smtp connection (sending emails).
*/
EMAIL_SMTP_PORT
(
"SMTP port"
,
"25"
,
ConfigurationElementEditType
.
INTEGER
),
//
/**
* Default map that should be presented if no map is selected by user side.
*/
DEFAULT_MAP
(
"Default Project Id"
,
"empty"
,
ConfigurationElementEditType
.
STRING
),
//
/**
* Logo presented in the system.
*/
LOGO_IMG
(
"Logo icon"
,
"udl.png"
,
ConfigurationElementEditType
.
URL
),
//
/**
* Address connected to the logo.
*/
LOGO_LINK
(
"Logo link (after click)"
,
"http://wwwen.uni.lu/"
,
ConfigurationElementEditType
.
URL
),
//
/**
* Maximum distance (in pixels) that is allowed during finding closest element
* on the map.
*/
SEARCH_DISTANCE
(
"Max distance for clicking on element (px)"
,
"10"
,
ConfigurationElementEditType
.
DOUBLE
),
/**
* Email used for requesting an account (in client side).
*/
REQUEST_ACCOUNT_EMAIL
(
"Email used for requesting an account"
,
"your.email@domain.com"
,
ConfigurationElementEditType
.
EMAIL
),
/**
* Max number of results in search box.
*/
SEARCH_RESULT_NUMBER
(
"Max number of results in search box. "
,
"100"
,
ConfigurationElementEditType
.
INTEGER
),
/**
* Google Analytics tracking ID used for statistics. This tracking ID should
* look like "UA-000000-01". More information about tracking ID can be found
* <a href="https://support.google.com/analytics/answer/1032385?hl=en"> here
* </a>.
*/
GOOGLE_ANALYTICS_IDENTIFIER
(
"Google Analytics tracking ID used for statistics"
,
""
,
ConfigurationElementEditType
.
STRING
),
/**
* Description of the logo presented in the system.
*/
LOGO_TEXT
(
"Logo description"
,
"University of Luxembourg"
,
ConfigurationElementEditType
.
STRING
),
/**
* Domain allowed to connect via x-frame technology.
*/
X_FRAME_DOMAIN
(
"Domain allowed to connect via x-frame technology"
,
""
,
ConfigurationElementEditType
.
URL
),
/**
* Relative directory (in webapps folder) where big files will be stored.
*/
BIG_FILE_STORAGE_DIR
(
"Path to store big files"
,
"minerva-big/"
,
ConfigurationElementEditType
.
STRING
),
/**
* File where legend 1/4 is stored.
*/
LENGEND_FILE_1
(
"Legend 1 image file"
,
"resources/images/legend_a.png"
,
ConfigurationElementEditType
.
URL
),
/**
* File where legend 2/4 is stored.
*/
LENGEND_FILE_2
(
"Legend 2 image file"
,
"resources/images/legend_b.png"
,
ConfigurationElementEditType
.
URL
),
/**
* File where legend 3/4 is stored.
*/
LENGEND_FILE_3
(
"Legend 3 image file"
,
"resources/images/legend_c.png"
,
ConfigurationElementEditType
.
URL
),
/**
* File where legend 4/4 is stored.
*/
LENGEND_FILE_4
(
"Legend 4 image file"
,
"resources/images/legend_d.png"
,
ConfigurationElementEditType
.
URL
),
/**
* File where legend 4/4 is stored.
*/
USER_MANUAL_FILE
(
"User manual file"
,
"resources/other/user_guide.pdf"
,
ConfigurationElementEditType
.
URL
),
MIN_COLOR_VAL
(
"Overlay color for negative values"
,
"FF0000"
,
ConfigurationElementEditType
.
COLOR
),
MAX_COLOR_VAL
(
"Overlay color for postive values"
,
"0000FF"
,
ConfigurationElementEditType
.
COLOR
);
/**
* Default value of the configuration parameter (it will be used only when
* value doesn't exist in the DAO).
*/
private
String
defaultValue
=
""
;
/**
* Common name used for visualization (query user).
*/
private
String
commonName
=
""
;
/**
* How we want to edit specific param.
*/
private
ConfigurationElementEditType
editType
=
null
;
/**
* Default constructor.
*
* @param commonName
* common name used for this parameter
* @param editType
* type defining how we want to edit this configuration param
* @param defaultVal
* default value assigned to this parameter
*/
ConfigurationElementType
(
String
commonName
,
String
defaultVal
,
ConfigurationElementEditType
editType
)
{
this
.
defaultValue
=
defaultVal
;
this
.
commonName
=
commonName
;
this
.
editType
=
editType
;
}
/**
* @return the defaultValue
* @see #defaultValue
*/
public
String
getDefaultValue
()
{
return
defaultValue
;
}
/**
* @return the commonName
* @see #commonName
*/
public
String
getCommonName
()
{
return
commonName
;
}
/**
* @return the editType
* @see #editType
*/
public
ConfigurationElementEditType
getEditType
()
{
return
editType
;
}
}
model/src/test/java/lcsb/mapviewer/model/map/layout/ColorSchemaTest.java
View file @
243751d7
...
...
@@ -113,35 +113,6 @@ public class ColorSchemaTest {
}
}
@Test
public
void
testGetColorForValue
()
throws
Exception
{
try
{
ColorSchema
cs
=
new
GenericColorSchema
();
assertEquals
(
Color
.
GREEN
,
cs
.
getColorForValue
(
1.0
));
assertEquals
(
Color
.
RED
,
cs
.
getColorForValue
(-
1.0
));
assertEquals
(
Color
.
WHITE
,
cs
.
getColorForValue
(
0.0
));
}
catch
(
Exception
e
)
{