Search in sources :

Example 56 with ConstellationColor

use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.

the class BlazeContextMenu method selectItem.

@Override
public void selectItem(final String item, final Graph graph, final GraphElementType elementType, final int elementId, final Vector3f unprojected) {
    Blaze clickedBlaze = null;
    int clickedVertexId = Graph.NOT_FOUND;
    BitSet selectedVertices = null;
    Plugin plugin = null;
    PluginParameters parameters = null;
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        final int blazeAttributeId = VisualConcept.VertexAttribute.BLAZE.get(rg);
        if (blazeAttributeId != Graph.NOT_FOUND) {
            clickedBlaze = rg.getObjectValue(blazeAttributeId, elementId);
        }
        final int selectedAttributeId = VisualConcept.VertexAttribute.SELECTED.get(rg);
        if (selectedAttributeId == Graph.NOT_FOUND || !rg.getBooleanValue(selectedAttributeId, elementId)) {
            clickedVertexId = elementId;
        } else {
            selectedVertices = new BitSet();
            final int vertexCount = rg.getVertexCount();
            for (int vertexPosition = 0; vertexPosition < vertexCount; vertexPosition++) {
                final int vertexId = rg.getVertex(vertexPosition);
                if (rg.getBooleanValue(selectedAttributeId, vertexId)) {
                    selectedVertices.set(vertexId);
                }
            }
        }
    } finally {
        rg.release();
    }
    if (clickedBlaze == null) {
        clickedBlaze = BlazeUtilities.DEFAULT_BLAZE;
    }
    switch(item) {
        case ADD_CUSTOM_BLAZE:
            final ConstellationColor defaultColor = clickedBlaze == null ? BlazeUtilities.DEFAULT_BLAZE.getColor() : clickedBlaze.getColor();
            final Pair<Boolean, ConstellationColor> colorResult = BlazeUtilities.colorDialog(defaultColor);
            if (colorResult.getKey()) {
                plugin = PluginRegistry.get(VisualGraphPluginRegistry.ADD_CUSTOM_BLAZE);
                parameters = DefaultPluginParameters.getDefaultParameters(plugin);
                parameters.setObjectValue(BlazeUtilities.COLOR_PARAMETER_ID, colorResult.getValue());
            }
            break;
        case UNSET_BLAZE:
            plugin = PluginRegistry.get(VisualGraphPluginRegistry.REMOVE_BLAZE);
            parameters = DefaultPluginParameters.getDefaultParameters(plugin);
            break;
        default:
            final ConstellationColor color = ConstellationColor.getColorValue(item);
            plugin = PluginRegistry.get(VisualGraphPluginRegistry.ADD_CUSTOM_BLAZE);
            parameters = DefaultPluginParameters.getDefaultParameters(plugin);
            parameters.setObjectValue(BlazeUtilities.COLOR_PARAMETER_ID, color);
            break;
    }
    if (plugin != null && parameters != null) {
        parameters.getParameters().get(BlazeUtilities.VERTEX_ID_PARAMETER_ID).setIntegerValue(clickedVertexId);
        parameters.getParameters().get(BlazeUtilities.VERTEX_IDS_PARAMETER_ID).setObjectValue(selectedVertices);
        PluginExecution.withPlugin(plugin).withParameters(parameters).executeLater(graph);
    }
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Blaze(au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze) BitSet(java.util.BitSet) DefaultPluginParameters(au.gov.asd.tac.constellation.plugins.parameters.DefaultPluginParameters) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 57 with ConstellationColor

use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.

the class ColorIOProvider method readObject.

/**
 * Deserialise an object from a JsonNode.
 * <p>
 * Refer to base class for detailed description.
 *
 * @param attributeId The id of the attribute being read.
 * @param elementId The id of the element being read.
 * @param jnode The JsonNode to read from.
 * @param graph The graph that the resulting object will be placed in. Provided in case
 * the object requires some graph data.
 * @param vertexMap (not used) A mapping from a vertex id in the file to the vertex id
 * in the graph.
 * @param transactionMap (not used) A mapping from a transaction id in the file to the
 * transaction id in the graph.
 * @param byteReader (not used) The byte reader containing ancillary data (e.g. images)
 * that doesn't easily fit into a JSON document.
 * @param cache A cache that can be used to dedup identical instances of the
 * same immutable objects.
 * @throws java.io.IOException If there's a problem reading the document.
 */
@Override
public void readObject(final int attributeId, final int elementId, final JsonNode jnode, final GraphWriteMethods graph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, ImmutableObjectCache cache) throws IOException {
    if (!jnode.isNull() && jnode.isObject()) {
        final ConstellationColor attributeValue = readColorObject(jnode);
        graph.setObjectValue(attributeId, elementId, cache.deduplicate(attributeValue));
    } else {
        // legacy
        final String attributeValue = jnode.isNull() ? null : jnode.textValue();
        graph.setStringValue(attributeId, elementId, cache.deduplicate(attributeValue));
    }
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor)

Example 58 with ConstellationColor

use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.

the class GraphLabelV0 method fromString.

public static GraphLabelV0 fromString(String graphLabelString) {
    String thisLabel = null;
    ConstellationColor thisColor = null;
    Float thisRadius = null;
    if (StringUtils.isNotBlank(graphLabelString)) {
        Set<Character> splitChar = new HashSet<>();
        splitChar.add(';');
        List<String> graphLabelComponents = StringUtilities.splitLabelsWithEscapeCharacters(graphLabelString.substring(graphLabelString.indexOf(':') + 1, graphLabelString.lastIndexOf(']')), splitChar);
        char[] metaChar = { ' ', ';', '[', ']' };
        thisLabel = StringUtilities.unescapeString(graphLabelComponents.get(0), metaChar);
        String[] rgba = graphLabelComponents.get(1).split(",");
        thisColor = ConstellationColor.getColorValue(Float.valueOf(rgba[0]), Float.valueOf(rgba[1]), Float.valueOf(rgba[2]), Float.valueOf(rgba[3]));
        thisRadius = Float.valueOf(graphLabelComponents.get(2));
    }
    return new GraphLabelV0(thisLabel, thisColor, thisRadius);
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) HashSet(java.util.HashSet)

Example 59 with ConstellationColor

use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.

the class BlazeV0 method valueOf.

public static BlazeV0 valueOf(final String s) {
    if (s != null && s.length() > 0) {
        final Matcher m = BLAZE_PATTERN.matcher(s);
        if (m.matches()) {
            final int angle = Integer.valueOf(m.group(1));
            final ConstellationColor color = ConstellationColor.getColorValue(m.group(2));
            if (color == null) {
                throw new IllegalBlazeFormatException("Undefined colour for blaze.");
            }
            final String iconLabel = m.group(3);
            final boolean iconEnabled = Boolean.valueOf(m.group(4));
            return new BlazeV0(angle, color, iconLabel, iconEnabled);
        }
    }
    return null;
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) Matcher(java.util.regex.Matcher)

Example 60 with ConstellationColor

use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.

the class ColorAttributeInteraction method getDisplayNodes.

@Override
public List<Node> getDisplayNodes(final Object attrVal, final double width, final double height) {
    final ConstellationColor colorValue = (ConstellationColor) attrVal;
    final double rectWidth;
    if (width == -1) {
        rectWidth = height == -1 ? DEFAULT_NODE_SIZE : height;
    } else {
        rectWidth = width;
    }
    final double rectHeight = height == -1 ? rectWidth : height;
    final Rectangle rect = new Rectangle(rectWidth, rectHeight);
    rect.setFill(colorValue.getJavaFXColor());
    rect.setStroke(Color.LIGHTGREY);
    return Arrays.asList(rect);
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) Rectangle(javafx.scene.shape.Rectangle)

Aggregations

ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)67 ArrayList (java.util.ArrayList)13 Test (org.testng.annotations.Test)11 Color (java.awt.Color)9 BitSet (java.util.BitSet)9 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)8 IOException (java.io.IOException)7 Graph (au.gov.asd.tac.constellation.graph.Graph)6 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)6 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)6 List (java.util.List)6 File (java.io.File)5 HashMap (java.util.HashMap)5 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)4 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)4 Camera (au.gov.asd.tac.constellation.utilities.camera.Camera)4 Matrix44f (au.gov.asd.tac.constellation.utilities.graphics.Matrix44f)4 VisualAccess (au.gov.asd.tac.constellation.utilities.visual.VisualAccess)4 GLRenderableUpdateTask (au.gov.asd.tac.constellation.visual.opengl.renderer.GLRenderable.GLRenderableUpdateTask)4 TextureUnits (au.gov.asd.tac.constellation.visual.opengl.renderer.TextureUnits)4