use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.
the class CreateVertexTypePlugin method edit.
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
final String name = parameters.getStringValue(NAME_PARAMETER_ID);
if (name == null) {
throw new IllegalArgumentException("A name must be supplied");
}
final String description = parameters.getStringValue(DESCRIPTION_PARAMETER_ID);
if (description == null) {
throw new IllegalArgumentException("A description must be supplied");
}
final ConstellationColor color = parameters.getColorValue(COLOR_PARAMETER_ID);
final String fgIconName = parameters.getStringValue(FG_ICON_PARAMETER_ID);
final ConstellationIcon foregroundIcon = IconManager.getIcon(fgIconName);
final String bgIconName = parameters.getStringValue(BG_ICON_PARAMETER_ID);
final ConstellationIcon backgroundIcon = IconManager.getIcon(bgIconName);
final String dregex = parameters.getStringValue(DETECTION_REGEX_PARAMETER_ID);
final Pattern detectionRegex = dregex != null ? Pattern.compile(dregex, Pattern.CASE_INSENSITIVE) : null;
final String vregex = parameters.getStringValue(VALIDATION_REGEX_PARAMETER_ID);
final Pattern validationRegex = vregex != null ? Pattern.compile(vregex, Pattern.CASE_INSENSITIVE) : null;
final String stype = parameters.getStringValue(SUPER_TYPE_PARAMETER_ID);
final SchemaVertexType superType = stype != null ? SchemaVertexTypeUtilities.getType(stype) : null;
final String otype = parameters.getStringValue(OVERRIDDEN_TYPE_PARAMETER_ID);
final SchemaVertexType overridenType = otype != null ? SchemaVertexTypeUtilities.getType(otype) : null;
final boolean incomplete = parameters.getBooleanValue(INCOMPLETE_PARAMETER_ID);
final Map<String, String> properties = null;
final SchemaVertexType svt = new SchemaVertexType(name, description, color, foregroundIcon, backgroundIcon, detectionRegex, validationRegex, superType, overridenType, properties, incomplete);
SchemaVertexTypeUtilities.addCustomType(svt, true);
}
use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.
the class Scatter3dArranger method getFloatValueFromObject.
private float getFloatValueFromObject(final Object attributeValue, final boolean logarithmic) {
if (attributeValue == null) {
return 0.0F;
}
if (attributeValue instanceof Float) {
return scaleValue((float) attributeValue, logarithmic);
}
if (attributeValue instanceof Double) {
return scaleValue((float) attributeValue, logarithmic);
}
if (attributeValue instanceof String) {
String val = (String) attributeValue;
float finalVal = 0.0F;
float multiplier = 1;
for (int i = 0; i < val.length(); i++) {
char ch = val.charAt(i);
float chVal = (float) ch;
finalVal += ((float) chVal) * multiplier;
multiplier /= 26;
}
return scaleValue(finalVal, logarithmic);
}
if (attributeValue instanceof Integer) {
float ret = (Integer) attributeValue;
return scaleValue(ret, logarithmic);
}
if (attributeValue instanceof ConstellationColor) {
ConstellationColor color = (ConstellationColor) attributeValue;
float red = color.getRed() / 256;
float green = color.getGreen() / 256;
float blue = color.getBlue() / 256;
return scaleValue((red + green + blue) * 100, logarithmic);
}
if (attributeValue instanceof ZonedDateTime) {
ZonedDateTime c = (ZonedDateTime) attributeValue;
float year = c.getYear();
float month = c.getMonthValue();
float monthDay = c.getDayOfMonth();
float hour = c.getHour();
float minute = c.getMinute();
return scaleValue((year - 2010) + month / 12 + monthDay / (366) + hour / (366 * 24) + minute / (366 * 24 * 60), logarithmic);
}
if (attributeValue instanceof RawData) {
String s = ((RawData) attributeValue).toString();
return getFloatValueFromObject(s, logarithmic);
}
return 0.0F;
}
use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.
the class AttributeEditorPanel method createColourMenuItem.
private MenuItem createColourMenuItem(final String itemName, final String correspondingPreference, final Color color) {
final HBox schemaMenuNode = new HBox(CELL_ITEM_SPACING);
final MenuItem schemaMenuItem = new MenuItem(null, schemaMenuNode);
final Rectangle schemaMenuRect = new Rectangle(20, 20);
final Text schemaMenuText = new Text(itemName);
schemaMenuText.setStyle("-fx-fill: white; -fx-font-smoothing-type:lcd;");
schemaMenuNode.getChildren().addAll(schemaMenuRect, schemaMenuText);
schemaMenuRect.setFill(color);
schemaMenuRect.setStroke(Color.LIGHTGREY);
schemaMenuItem.setOnAction(e -> {
final EditOperation editOperation = value -> prefs.put(correspondingPreference, ((ConstellationColor) value).getHtmlColor());
// return type of createEditor will actually be AbstractEditor<ConstellationColor>
@SuppressWarnings("unchecked") final AbstractEditor<ConstellationColor> editor = ((AbstractEditorFactory<ConstellationColor>) AttributeValueEditorFactory.getEditFactory(ColorAttributeDescription.ATTRIBUTE_NAME)).createEditor(editOperation, String.format("for %s", itemName), ConstellationColor.fromFXColor(color));
final AttributeEditorDialog dialog = new AttributeEditorDialog(false, editor);
dialog.showDialog();
});
return schemaMenuItem;
}
use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.
the class AdvancedSearchPlugin method searchAsColor.
/**
* This function checks to see if a graph elements color attribute matches
* the criteria specified by the ColourCriteriaValues.
*
* @param values the color criteriaValues
* @param attributeInt the int of the attribute
* @param currElement the currentElement
* @param graph the current graph
* @return
*/
private boolean searchAsColor(final FindCriteriaValues values, final int attributeInt, final int currElement, final GraphWriteMethods graph) {
final ColourCriteriaValues colorValues = (ColourCriteriaValues) values;
final ConstellationColor color = graph.getObjectValue(attributeInt, currElement);
boolean matches = false;
// if the color of the attribute matches the users color matches = true
if (colorValues.getFilter().equals(IS) && colorValues.getColorValue().equals(color)) {
matches = true;
// if the color of the attribute doesnt match the users color matches = true
} else if (colorValues.getFilter().equals(IS_NOT) && !colorValues.getColorValue().equals(color)) {
matches = true;
}
return matches;
}
use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.
the class NebulaDataObject method open.
@Override
public void open() {
final Properties props = new Properties();
try (final FileReader reader = new FileReader(getPrimaryFile().getPath())) {
props.load(reader);
} catch (final IOException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
// Generate a color for the nebula marker.
// First, see if the user has specified a color in the nebula file.
Color c = null;
final String cname = props.getProperty("colour") != null ? props.getProperty("colour") : props.getProperty("color");
if (cname != null) {
ConstellationColor cv = ConstellationColor.fromHtmlColor(cname);
if (cv == null) {
cv = ConstellationColor.getColorValue(cname);
}
if (cv != null) {
c = cv.getJavaColor();
}
}
// Therefore, we track the random colors as we create them,
if (c == null) {
c = NEBULA_COLOR.get(getPrimaryFile().getPath());
}
// Otherwise, create a random color for this nebula.
if (c == null) {
final float h = new SecureRandom().nextFloat();
c = Color.getHSBColor(h, 0.5F, 0.95F);
NEBULA_COLOR.put(getPrimaryFile().getPath(), c);
}
for (final Enumeration<DataObject> i = getFolder().children(); i.hasMoreElements(); ) {
final DataObject dobj = i.nextElement();
if (dobj instanceof GraphDataObject) {
final GraphDataObject gdo = (GraphDataObject) dobj;
gdo.setNebulaDataObject(this);
gdo.setNebulaColor(c);
GraphOpener.getDefault().openGraph(gdo);
}
}
// Because we haven't registered an editor, a TopComponent won't open for this file (which is good).
// However, the recent files stuff works by watching for opening TopComponents (which is bad).
// So, do it manually.
// FileObject.getPath() returns a path containing "/"; we need to convert it to local separators for RecentFiles.
final String path = new File(getPrimaryFile().getPath()).getAbsolutePath();
RecentFiles.addFile(path);
}
Aggregations