Commit 243751d7 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

not compiling work in progress ;/

parent fb0fffb8
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();
}
}
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;
}
}
...@@ -47,6 +47,8 @@ public class ColorModelCommand extends ModelCommand { ...@@ -47,6 +47,8 @@ public class ColorModelCommand extends ModelCommand {
*/ */
private Collection<ColorSchema> schemas; private Collection<ColorSchema> schemas;
private ColorExtractor colorExtractor;
/** /**
* Default constructor. * Default constructor.
* *
...@@ -55,9 +57,10 @@ public class ColorModelCommand extends ModelCommand { ...@@ -55,9 +57,10 @@ public class ColorModelCommand extends ModelCommand {
* @param schemas * @param schemas
* set of color schemas used in this command to color model. * 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); super(model);
this.schemas = schemas; this.schemas = schemas;
this.colorExtractor = colorExtractor;
} }
/** /**
...@@ -75,7 +78,7 @@ public class ColorModelCommand extends ModelCommand { ...@@ -75,7 +78,7 @@ public class ColorModelCommand extends ModelCommand {
throw new InvalidColorSchemaException("At least two rows try to set color to reaction: " + reaction.getIdReaction()); 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()) { for (AbstractNode node : reaction.getNodes()) {
node.getLine().setColor(color); node.getLine().setColor(color);
if (schema.getLineWidth() != null) { if (schema.getLineWidth() != null) {
...@@ -148,7 +151,7 @@ public class ColorModelCommand extends ModelCommand { ...@@ -148,7 +151,7 @@ public class ColorModelCommand extends ModelCommand {
throw new InvalidColorSchemaException("At least two rows try to set color to element: " + alias.getName()); 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 { ...@@ -263,7 +266,7 @@ public class ColorModelCommand extends ModelCommand {
for (ColorSchema schema : schemas) { for (ColorSchema schema : schemas) {
for (Element alias : model2.getElements()) { for (Element alias : model2.getElements()) {
if (match(alias, schema)) { 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."); throw new InvalidColorSchemaException("Alias " + alias.getElementId() + " is colored by more than one rule.");
} }
result.put(alias, schema); result.put(alias, schema);
...@@ -271,7 +274,7 @@ public class ColorModelCommand extends ModelCommand { ...@@ -271,7 +274,7 @@ public class ColorModelCommand extends ModelCommand {
} }
for (Reaction reaction : model2.getReactions()) { for (Reaction reaction : model2.getReactions()) {
if (match(reaction, schema)) { 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."); throw new InvalidColorSchemaException("Reaction " + reaction.getIdReaction() + " is colored by more than one rule.");
} }
result.put(reaction, schema); result.put(reaction, schema);
......
...@@ -483,39 +483,6 @@ public abstract class ColorSchema implements Serializable { ...@@ -483,39 +483,6 @@ public abstract class ColorSchema implements Serializable {
this.types.add(clazz); 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 * @return the description
* @see #description * @see #description
......
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,
}
package lcsb.mapviewer.model.user; package lcsb.mapviewer.model.user;
/** /**
* This enum defines all possible configuration parameter that are configurable * This enum defines all possible configuration parameter that are configurable
* by the user. * by the user.
* *
* @author Piotr Gawron * @author Piotr Gawron
* *
*/ */
public enum ConfigurationElementType { public enum ConfigurationElementType {
/** /**
* Email address used for sending email from the system. * Email address used for sending email from the system.
*/ */
EMAIL_ADDRESS("E-mail address", "your.account@domain.com"), // EMAIL_ADDRESS("E-mail address", "your.account@domain.com", ConfigurationElementEditType.EMAIL), //
/** /**
* Login for the email account. * Login for the email account.
*/ */
EMAIL_LOGIN("E-mail server login", "your@login"), // EMAIL_LOGIN("E-mail server login", "your@login", ConfigurationElementEditType.STRING), //
/** /**
* Password for the email account. * Password for the email account.
*/ */
EMAIL_PASSWORD("E-mail server password", "email.secret.password"), // EMAIL_PASSWORD("E-mail server password", "email.secret.password", ConfigurationElementEditType.PASSWORD), //
/** /**
* Addres of the imap server. * Addres of the imap server.
*/ */
EMAIL_IMAP_SERVER("IMAP server", "your.imap.domain.com"), // EMAIL_IMAP_SERVER("IMAP server", "your.imap.domain.com", ConfigurationElementEditType.STRING), //
/** /**
* Address of the smtp server. * Address of the smtp server.
*/ */
EMAIL_SMTP_SERVER("SMTP server", "your.smtp.domain.com"), // EMAIL_SMTP_SERVER("SMTP server", "your.smtp.domain.com", ConfigurationElementEditType.STRING), //
/** /**
* Port used for smtp connection (sending emails). * Port used for smtp connection (sending emails).
*/ */
EMAIL_SMTP_PORT("SMTP port", "25"), // EMAIL_SMTP_PORT("SMTP port", "25", ConfigurationElementEditType.INTEGER), //
/** /**
* Default map that should be presented if no map is selected by user side. * Default map that should be presented if no map is selected by user side.
*/ */
DEFAULT_MAP("Default Project Id", "empty"), // DEFAULT_MAP("Default Project Id", "empty", ConfigurationElementEditType.STRING), //
/** /**
* Logo presented in the system. * Logo presented in the system.
*/ */
LOGO_IMG("Logo icon", "udl.png"), // LOGO_IMG("Logo icon", "udl.png", ConfigurationElementEditType.URL), //
/** /**
* Address connected to the logo. * Address connected to the logo.
*/ */
LOGO_LINK("Logo link (after click)", "http://wwwen.uni.lu/"), // LOGO_LINK("Logo link (after click)", "http://wwwen.uni.lu/", ConfigurationElementEditType.URL), //
/** /**
* Maximum distance (in pixels) that is allowed during finding closest element * Maximum distance (in pixels) that is allowed during finding closest element
* on the map. * on the map.
*/ */
SEARCH_DISTANCE("Max distance for clicking on element (px)", "10"), SEARCH_DISTANCE("Max distance for clicking on element (px)", "10", ConfigurationElementEditType.DOUBLE),
/** /**
* Email used for requesting an account (in client side). * Email used for requesting an account (in client side).
*/ */
REQUEST_ACCOUNT_EMAIL("Email used for requesting an account", "your.email@domain.com"), REQUEST_ACCOUNT_EMAIL("Email used for requesting an account", "your.email@domain.com", ConfigurationElementEditType.EMAIL),
/** /**
* Max number of results in search box. * Max number of results in search box.
*/ */
SEARCH_RESULT_NUMBER("Max number of results in search box. ", "100"), SEARCH_RESULT_NUMBER("Max number of results in search box. ", "100", ConfigurationElementEditType.INTEGER),
/** /**
* Google Analytics tracking ID used for statistics. This tracking ID should * Google Analytics tracking ID used for statistics. This tracking ID should
* look like "UA-000000-01". More information about tracking ID can be found * 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 href="https://support.google.com/analytics/answer/1032385?hl=en"> here
* </a>. * </a>.
*/ */
GOOGLE_ANALYTICS_IDENTIFIER("Google Analytics tracking ID used for statistics", ""), GOOGLE_ANALYTICS_IDENTIFIER("Google Analytics tracking ID used for statistics", "", ConfigurationElementEditType.STRING),
/** /**
* Description of the logo presented in the system. * Description of the logo presented in the system.
*/ */
LOGO_TEXT("Logo description", "University of Luxembourg"), LOGO_TEXT("Logo description", "University of Luxembourg", ConfigurationElementEditType.STRING),
/** /**
* Domain allowed to connect via x-frame technology. * Domain allowed to connect via x-frame technology.
*/ */
X_FRAME_DOMAIN("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. * Relative directory (in webapps folder) where big files will be stored.
*/ */
BIG_FILE_STORAGE_DIR("Path to store big files", "minerva-big/"), BIG_FILE_STORAGE_DIR("Path to store big files", "minerva-big/", ConfigurationElementEditType.STRING),
/** /**
* File where legend 1/4 is stored. * File where legend 1/4 is stored.
*/ */
LENGEND_FILE_1("Legend 1 image file", "resources/images/legend_a.png"), LENGEND_FILE_1("Legend 1 image file", "resources/images/legend_a.png", ConfigurationElementEditType.URL),
/** /**
* File where legend 2/4 is stored. * File where legend 2/4 is stored.
*/ */
LENGEND_FILE_2("Legend 2 image file", "resources/images/legend_b.png"), LENGEND_FILE_2("Legend 2 image file", "resources/images/legend_b.png", ConfigurationElementEditType.URL),
/** /**
* File where legend 3/4 is stored. * File where legend 3/4 is stored.
*/ */
LENGEND_FILE_3("Legend 3 image file", "resources/images/legend_c.png"), LENGEND_FILE_3("Legend 3 image file", "resources/images/legend_c.png", ConfigurationElementEditType.URL),
/** /**
* File where legend 4/4 is stored. * File where legend 4/4 is stored.
*/ */
LENGEND_FILE_4("Legend 4 image file", "resources/images/legend_d.png"), LENGEND_FILE_4("Legend 4 image file", "resources/images/legend_d.png", ConfigurationElementEditType.URL),
/** /**
* File where legend 4/4 is stored. * File where legend 4/4 is stored.
*/ */
USER_MANUAL_FILE("User manual file", "resources/other/user_guide.pdf"); USER_MANUAL_FILE("User manual file", "resources/other/user_guide.pdf", ConfigurationElementEditType.URL),
MIN_COLOR_VAL("Overlay color for negative values", "FF0000", ConfigurationElementEditType.COLOR),
/**
* Default value of the configuration parameter (it will be used only when MAX_COLOR_VAL("Overlay color for postive values", "0000FF", ConfigurationElementEditType.COLOR);
* value doesn't exist in the DAO).
*/ /**
private String defaultValue = ""; * Default value of the configuration parameter (it will be used only when
* value doesn't exist in the DAO).
/** */
* Common name used for visualization (query user). private String defaultValue = "";
*/
private String commonName = ""; /**
* Common name used for visualization (query user).
/** */
* Default constructor. private String commonName = "";
*
* @param commonName /**
* common name used for this parameter * How we want to edit specific param.
* @param defaultVal */
* default value assigned to this parameter private ConfigurationElementEditType editType = null;
*/
ConfigurationElementType(String commonName, String defaultVal) { /**
this.defaultValue = defaultVal; * Default constructor.
this.commonName = commonName; *
} * @param commonName
* common name used for this parameter
/** * @param editType
* @return the defaultValue * type defining how we want to edit this configuration param
* @see #defaultValue * @param defaultVal
*/ * default value assigned to this parameter
public String getDefaultValue() { */
return defaultValue; ConfigurationElementType(String commonName, String defaultVal, ConfigurationElementEditType editType) {
} this.defaultValue = defaultVal;
this.commonName = commonName;
/** this.editType = editType;
* @return the commonName }
* @see #commonName
*/ /**
public String getCommonName() { * @return the defaultValue
return commonName; * @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;
}
}
...@@ -113,35 +113,6 @@ public class ColorSchemaTest { ...@@ -113,35 +113,6 @@ public class ColorSchemaTest {
} }
} }