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);
}
}
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);
}
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);
}
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");
}
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);
}
Aggregations