Search in sources :

Example 6 with Blaze

use of au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze 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 7 with Blaze

use of au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze in project constellation by constellation-app.

the class BlazeUtilities method getSelection.

/**
 * Selected vertices, and the color of the blaze of the first selected
 * vertex with a blaze.
 *
 * @param graph the graph on which to get selected blazes.
 * @param blazeColor if null then the color of the first blaze detected will
 * be returned.
 *
 * @return the specified blaze color, or the color of the first blaze found.
 */
public static Pair<BitSet, ConstellationColor> getSelection(final Graph graph, ConstellationColor blazeColor) {
    final BitSet vertices = new BitSet();
    final ReadableGraph readableGraph = graph.getReadableGraph();
    try {
        final int vertexBlazeAttributeId = VisualConcept.VertexAttribute.BLAZE.get(readableGraph);
        final int vertexSelectedAttributeId = VisualConcept.VertexAttribute.SELECTED.get(readableGraph);
        final int vertexCount = readableGraph.getVertexCount();
        for (int vertexPosition = 0; vertexPosition < vertexCount; vertexPosition++) {
            final int vertexId = readableGraph.getVertex(vertexPosition);
            final boolean selected = readableGraph.getBooleanValue(vertexSelectedAttributeId, vertexId);
            if (selected) {
                vertices.set(vertexId);
                if (blazeColor == null && vertexBlazeAttributeId != Graph.NOT_FOUND) {
                    final Blaze blaze = (Blaze) readableGraph.getObjectValue(vertexBlazeAttributeId, vertexId);
                    if (blaze != null) {
                        blazeColor = blaze.getColor();
                    }
                }
            }
        }
        if (blazeColor == null) {
            blazeColor = BlazeUtilities.DEFAULT_BLAZE.getColor();
        }
    } finally {
        readableGraph.release();
    }
    return new Pair<>(vertices, blazeColor);
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Blaze(au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze) BitSet(java.util.BitSet) Pair(javafx.util.Pair)

Example 8 with Blaze

use of au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze in project constellation by constellation-app.

the class BlazeAttributeInteractionNGTest method testGetDisplayNodes.

/**
 * Test of getDisplayNodes method, of class BlazeAttributeInteraction.
 */
@Test
public void testGetDisplayNodes() {
    System.out.println("getDisplayNodes");
    final BlazeAttributeInteraction instance = new BlazeAttributeInteraction();
    final Blaze blaze = new Blaze(87, ConstellationColor.CYAN);
    final List<Node> result1 = instance.getDisplayNodes(blaze, -1, 2);
    assertEquals(result1.size(), 1);
    final Rectangle result1Node = (Rectangle) result1.get(0);
    assertEquals(result1Node.getFill(), Color.CYAN);
    assertEquals(result1Node.getHeight(), 2.0);
    assertEquals(result1Node.getWidth(), 2.0);
    final List<Node> result2 = instance.getDisplayNodes(blaze, -1, -1);
    assertEquals(result2.size(), 1);
    final Rectangle result2Node = (Rectangle) result2.get(0);
    assertEquals(result2Node.getFill(), Color.CYAN);
    // height and width should be the default node size
    assertEquals(result2Node.getHeight(), 50.0);
    assertEquals(result2Node.getWidth(), 50.0);
    final List<Node> result3 = instance.getDisplayNodes(blaze, 3, 2);
    assertEquals(result3.size(), 1);
    final Rectangle result3Node = (Rectangle) result3.get(0);
    assertEquals(result3Node.getFill(), Color.CYAN);
    assertEquals(result3Node.getHeight(), 2.0);
    assertEquals(result3Node.getWidth(), 3.0);
}
Also used : Blaze(au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze) Node(javafx.scene.Node) Rectangle(javafx.scene.shape.Rectangle) Test(org.testng.annotations.Test)

Example 9 with Blaze

use of au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze in project constellation by constellation-app.

the class BlazeAttributeInteractionNGTest method testGetDisplayText.

/**
 * Test of getDisplayText method, of class BlazeAttributeInteraction.
 */
@Test
public void testGetDisplayText() {
    System.out.println("getDisplayText");
    final BlazeAttributeInteraction instance = new BlazeAttributeInteraction();
    final String nullResult = instance.getDisplayText(null);
    assertNull(nullResult);
    final Blaze blaze = new Blaze(87, ConstellationColor.BANANA);
    final String validResult = instance.getDisplayText(blaze);
    assertEquals(validResult, "Colour: Banana; Angle: 87");
}
Also used : Blaze(au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze) Test(org.testng.annotations.Test)

Example 10 with Blaze

use of au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze in project constellation by constellation-app.

the class BlazeAttributeInteraction method getDisplayNodes.

@Override
public List<Node> getDisplayNodes(final Object attrVal, final double width, final double height) {
    final Blaze blazeValue = ((Blaze) 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(blazeValue.getColor().getJavaFXColor());
    rect.setStroke(Color.LIGHTGREY);
    return Arrays.asList(rect);
}
Also used : Blaze(au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze) Rectangle(javafx.scene.shape.Rectangle)

Aggregations

Blaze (au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze)12 Test (org.testng.annotations.Test)4 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)3 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)2 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)2 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)2 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)2 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)2 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)2 Camera (au.gov.asd.tac.constellation.utilities.camera.Camera)2 BitSet (java.util.BitSet)2 Rectangle (javafx.scene.shape.Rectangle)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)1 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)1 BooleanAttributeDescription (au.gov.asd.tac.constellation.graph.attribute.BooleanAttributeDescription)1 FloatAttributeDescription (au.gov.asd.tac.constellation.graph.attribute.FloatAttributeDescription)1 StringAttributeDescription (au.gov.asd.tac.constellation.graph.attribute.StringAttributeDescription)1 InteractiveGraphPluginRegistry (au.gov.asd.tac.constellation.graph.interaction.InteractiveGraphPluginRegistry)1 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)1