use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.
the class TableVisualisation method addColumn.
public void addColumn(final String columnName, final int percentWidth) {
final TableColumn<C, Object> column = new TableColumn<>(columnName);
tableColumns.put(columnName, column);
column.prefWidthProperty().bind(table.widthProperty().multiply(percentWidth / 100.0));
column.setCellValueFactory(cellData -> new SimpleObjectProperty<>(translator.getCellData(cellData.getValue(), columnName)));
column.setCellFactory(columnData -> new TableCell<C, Object>() {
@Override
public void updateItem(final Object item, final boolean empty) {
super.updateItem(item, empty);
if (item != null) {
this.setText(translator.getCellText(this.getTableRow().getItem(), item, columnName));
final ConstellationColor color = translator.getCellColor(this.getTableRow().getItem(), item, columnName);
this.setBackground(new Background(new BackgroundFill(color.getJavaFXColor(), CornerRadii.EMPTY, Insets.EMPTY)));
}
}
});
column.setSortable(true);
table.getColumns().add(column);
}
use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.
the class LayerByTimePlugin method read.
@Override
public void read(final GraphReadMethods rg, final PluginInteraction interaction, final PluginParameters parameters) throws PluginException, InterruptedException {
// We have the dtAttr from the original wg: we should have been passed the label, but never mind.
// We need to get the label from the original, so we can get the dtAttr for the copy.
final String dtAttrOrig = parameters.getParameters().get(DATETIME_ATTRIBUTE_PARAMETER_ID).getStringValue();
if (dtAttrOrig == null) {
interaction.notify(PluginNotificationLevel.ERROR, "A date-time attribute must be specified.");
return;
}
final int dtAttrOrigId = rg.getAttribute(GraphElementType.TRANSACTION, dtAttrOrig);
if (dtAttrOrigId == Graph.NOT_FOUND) {
interaction.notify(PluginNotificationLevel.ERROR, "A valid date-time attribute must be specified.");
return;
}
Graph copy;
try {
final Plugin copyGraphPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
final PluginParameters copyParams = copyGraphPlugin.createParameters();
copyParams.getParameters().get(CopyToNewGraphPlugin.NEW_SCHEMA_NAME_PARAMETER_ID).setStringValue(rg.getSchema().getFactory().getName());
copyParams.getParameters().get(CopyToNewGraphPlugin.COPY_ALL_PARAMETER_ID).setBooleanValue(true);
copyParams.getParameters().get(CopyToNewGraphPlugin.COPY_KEYS_PARAMETER_ID).setBooleanValue(false);
PluginExecution.withPlugin(copyGraphPlugin).withParameters(copyParams).executeNow(rg);
copy = (Graph) copyParams.getParameters().get(CopyToNewGraphPlugin.NEW_GRAPH_OUTPUT_PARAMETER_ID).getObjectValue();
} catch (final PluginException ex) {
copy = null;
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
if (copy == null) {
// The copy failed, drop out now.
return;
}
final Attribute dt = new GraphAttribute(rg, dtAttrOrigId);
final WritableGraph wgcopy = copy.getWritableGraph("Layer by time", true);
try {
final int dtAttr = wgcopy.getAttribute(GraphElementType.TRANSACTION, dt.getName());
final boolean useIntervals = parameters.getParameters().get(LAYER_BY_PARAMETER_ID).getStringValue().equals(INTERVAL_METHOD);
final ZonedDateTime[] startEnd = parameters.getParameters().get(DATE_RANGE_PARAMETER_ID).getDateTimeRangeValue().getZonedStartEnd();
final ZonedDateTime start = startEnd[0];
final ZonedDateTime end = startEnd[1];
final boolean isTransactionLayers = parameters.getParameters().get(TRANSACTION_AS_LAYER_PARAMETER_ID).getBooleanValue();
// Establish new attributes.
// Create and store graph attributes.
final LayerName defaultName = new LayerName(Graph.NOT_FOUND, "Default");
final int timeLayerAttr = wgcopy.addAttribute(GraphElementType.TRANSACTION, LayerNameAttributeDescription.ATTRIBUTE_NAME, LAYER_NAME, "time layer", defaultName, null);
wgcopy.addAttribute(GraphElementType.GRAPH, IntegerAttributeDescription.ATTRIBUTE_NAME, NLAYERS, "The number of layers to layer by time", 1, null);
final int txColorAttr = wgcopy.getAttribute(GraphElementType.TRANSACTION, "color");
final int txGuideline = wgcopy.addAttribute(GraphElementType.TRANSACTION, BooleanAttributeDescription.ATTRIBUTE_NAME, "layer_guideline", "This transaction is a layer guideline", false, null);
final ConstellationColor guidelineColor = ConstellationColor.getColorValue(0.25F, 0.25F, 0.25F, 1F);
wgcopy.addAttribute(GraphElementType.VERTEX, IntegerAttributeDescription.ATTRIBUTE_NAME, ORIGINAL_ID_LABEL, "Original Node Id", -1, null);
final List<Float> values = new ArrayList<>();
final Map<Integer, List<Float>> remappedLayers = new HashMap<>();
final Map<Integer, String> displayNames = new HashMap<>();
if (useIntervals) {
final int intervalUnit = LAYER_INTERVALS.get(parameters.getParameters().get(UNIT_PARAMETER_ID).getStringValue());
final int intervalAmount = parameters.getParameters().get(AMOUNT_PARAMETER_ID).getIntegerValue();
buildIntervals(wgcopy, values, remappedLayers, displayNames, dtAttr, start.toInstant(), end.toInstant(), intervalUnit, intervalAmount);
} else {
final int calendarUnit = BIN_CALENDAR_UNITS.get(parameters.getParameters().get(UNIT_PARAMETER_ID).getStringValue());
final int binAmount = parameters.getParameters().get(AMOUNT_PARAMETER_ID).getIntegerValue();
buildBins(wgcopy, values, remappedLayers, displayNames, dtAttr, start.toInstant(), end.toInstant(), calendarUnit, binAmount);
}
final boolean keepTxColors = parameters.getParameters().get(KEEP_TX_COLORS_PARAMETER_ID).getBooleanValue();
final boolean drawTxGuides = parameters.getParameters().get(DRAW_TX_GUIDES_PARAMETER_ID).getBooleanValue();
// Modify the copied graph to show our layers.
int z = 0;
float step = getWidth(wgcopy) / values.size();
for (final Entry<Integer, List<Float>> entry : remappedLayers.entrySet()) {
for (final Entry<Float, List<Integer>> currentLayer : transactionLayers.entrySet()) {
if (entry.getValue().contains(currentLayer.getKey())) {
for (final int txId : currentLayer.getValue()) {
final float origLayer = currentLayer.getKey();
int newLayer = 0;
if (entry.getValue().contains(origLayer)) {
// Overwrite value
newLayer = entry.getKey();
}
final LayerName dn = new LayerName(newLayer, displayNames.get(newLayer));
wgcopy.setObjectValue(timeLayerAttr, txId, dn);
final float normLayer = newLayer / (remappedLayers.keySet().size() * 1F);
if (!keepTxColors) {
final Color heatmap = new Color(Color.HSBtoRGB((1 - normLayer) * 2F / 3F, 0.5F, 1));
final ConstellationColor color = ConstellationColor.getColorValue(heatmap.getRed() / 255F, heatmap.getGreen() / 255F, heatmap.getBlue() / 255F, 1F);
wgcopy.setObjectValue(txColorAttr, txId, color);
}
if (isTransactionLayers) {
transactionsAsLayers(wgcopy, txId, z, step);
} else {
nodesAsLayers(wgcopy, txId, newLayer);
}
}
}
}
if (isTransactionLayers) {
srcVxMap = dstVxMap;
dstVxMap = new HashMap<>();
z += step;
}
}
// Remove any outstanding transactions flagged for deletion
for (int txId = txToDelete.nextSetBit(0); txId >= 0; txId = txToDelete.nextSetBit(txId + 1)) {
wgcopy.removeTransaction(txId);
}
// Get rid of all of the nodes that don't have any transactions.
// By definition, the duplicates will have transactions between them, including the original layer
// (because we just deleted transactions that belong in different layers, leaving only the transactions
// that belong in the original layer).
final List<Integer> vertices = new ArrayList<>();
for (int position = 0; position < wgcopy.getVertexCount(); position++) {
final int vertexId = wgcopy.getVertex(position);
final int nTx = wgcopy.getVertexTransactionCount(vertexId);
if (nTx == 0) {
vertices.add(vertexId);
}
}
vertices.stream().forEach(wgcopy::removeVertex);
if (drawTxGuides) {
interaction.setProgress(5, 6, "Draw guide lines", false);
// We have to do this after the "remove node without transactions" step because we're adding more transactions.
if (!isTransactionLayers && remappedLayers.keySet().size() > 1) {
nodeIdToLayers.keySet().stream().forEach(origNodeId -> {
int prevNodeId = -1;
final BitSet layers = nodeIdToLayers.get(origNodeId);
for (int layer = layers.nextSetBit(0); layer >= 0; layer = layers.nextSetBit(layer + 1)) {
final int nodeId = layer == 0 ? origNodeId : nodeDups.get(String.format("%s/%s", origNodeId, layer));
if (prevNodeId != -1) {
final int sTxId = wgcopy.addTransaction(prevNodeId, nodeId, false);
wgcopy.setBooleanValue(txGuideline, sTxId, true);
wgcopy.setObjectValue(txColorAttr, sTxId, guidelineColor);
final LayerName dn = new LayerName(1107, "Guideline");
wgcopy.setObjectValue(timeLayerAttr, sTxId, dn);
}
prevNodeId = nodeId;
}
});
}
}
} finally {
wgcopy.commit();
}
}
use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.
the class AttributeEditorPanel method createAttributeTitlePane.
/**
* Creates individual TitledPane within header title panes.
*
* @param attribute the attribute to display.
* @param values the different values available for the attribute.
* @param longestTitledWidth the width of the longest title in the pane.
* @param hidden is the pane currently hidden.
* @return a new TitledPane.
*/
public TitledPane createAttributeTitlePane(final AttributeData attribute, final Object[] values, final double longestTitledWidth, final boolean hidden) {
final String attributeTitle = attribute.getAttributeName();
final int spacing = 5;
final int buttonSize = 45;
final GridPane gridPane = new GridPane();
gridPane.setHgap(spacing);
final double titleWidth = longestTitledWidth + spacing;
final AttributeTitledPane attributePane;
if (!attribute.isKey()) {
attributePane = new AttributeTitledPane(e -> deleteAttributeAction(attribute.getElementType(), attributeTitle), e -> modifyAttributeAction(attribute));
} else {
attributePane = new AttributeTitledPane();
}
attributePane.setHidden(hidden);
gridPane.prefWidthProperty().bind(attributePane.widthProperty());
if (attribute.getDataType().equals(ZonedDateTimeAttributeDescription.ATTRIBUTE_NAME)) {
attributePane.addMenuItem("Update time-zone of selection", e -> updateTimeZoneAction(attribute));
}
final boolean multiValue = values != null && values.length > 1;
if (attribute.isKey()) {
final String colour;
if (hidden) {
final ConstellationColor hiddenColour = ConstellationColor.fromHtmlColor(prefs.get(AttributePreferenceKey.HIDDEN_ATTRIBUTE_COLOUR, HIDDEN_ATTRIBUTE_COLOUR));
final ConstellationColor keyColour = ConstellationColor.fromHtmlColor(prefs.get(AttributePreferenceKey.PRIMARY_KEY_ATTRIBUTE_COLOUR, PRIMARY_KEY_ATTRIBUTE_COLOUR));
colour = (ConstellationColor.getColorValue(hiddenColour.getRed() * 0.5F + keyColour.getRed() * 0.5F, hiddenColour.getGreen() * 0.5F + keyColour.getGreen() * 0.5F, hiddenColour.getBlue() * 0.5F + keyColour.getBlue() * 0.5F, 1F)).getHtmlColor();
} else {
colour = prefs.get(AttributePreferenceKey.PRIMARY_KEY_ATTRIBUTE_COLOUR, PRIMARY_KEY_ATTRIBUTE_COLOUR);
}
attributePane.setStyle(JavafxStyleManager.CSS_BASE_STYLE_PREFIX + colour + SeparatorConstants.SEMICOLON);
} else if (!attribute.isSchema()) {
final String colour;
if (hidden) {
final ConstellationColor hiddenColour = ConstellationColor.fromHtmlColor(prefs.get(AttributePreferenceKey.HIDDEN_ATTRIBUTE_COLOUR, HIDDEN_ATTRIBUTE_COLOUR));
final ConstellationColor customColour = ConstellationColor.fromHtmlColor(prefs.get(AttributePreferenceKey.CUSTOM_ATTRIBUTE_COLOUR, CUSTOM_ATTRIBUTE_COLOUR));
colour = (ConstellationColor.getColorValue(hiddenColour.getRed() * 0.5F + customColour.getRed() * 0.5F, hiddenColour.getGreen() * 0.5F + customColour.getGreen() * 0.5F, hiddenColour.getBlue() * 0.5F + customColour.getBlue() * 0.5F, 1F)).getHtmlColor();
} else {
colour = prefs.get(AttributePreferenceKey.CUSTOM_ATTRIBUTE_COLOUR, CUSTOM_ATTRIBUTE_COLOUR);
}
attributePane.setStyle(JavafxStyleManager.CSS_BASE_STYLE_PREFIX + colour + SeparatorConstants.SEMICOLON);
} else if (hidden) {
final String hiddenColour = prefs.get(AttributePreferenceKey.HIDDEN_ATTRIBUTE_COLOUR, HIDDEN_ATTRIBUTE_COLOUR);
attributePane.setStyle(JavafxStyleManager.CSS_BASE_STYLE_PREFIX + hiddenColour + SeparatorConstants.SEMICOLON);
} else {
final String schemaColour = prefs.get(AttributePreferenceKey.SCHEMA_ATTRIBUTE_COLOUR, SCHEMA_ATTRIBUTE_COLOUR);
attributePane.setStyle(JavafxStyleManager.CSS_BASE_STYLE_PREFIX + schemaColour + SeparatorConstants.SEMICOLON);
}
if (!multiValue) {
attributePane.setCollapsible(false);
} else {
createMultiValuePane(attribute, attributePane, values);
}
final Text attributeTitleText = createAttributeTitleLabel(attributeTitle);
attributeTitleText.getStyleClass().add("attributeName");
attributeTitleText.setTextAlignment(TextAlignment.RIGHT);
// Value TextField
final Node attributeValueNode = createAttributeValueNode(values, attribute, attributePane, multiValue);
// Edit Button
final Button editButton = new Button("Edit");
editButton.setAlignment(Pos.CENTER);
editButton.setMinWidth(buttonSize);
final AttributeValueEditorFactory<?> editorFactory = AttributeValueEditorFactory.getEditFactory(attribute.getDataType());
if (editorFactory == null || values == null) {
editButton.setDisable(true);
} else {
editButton.setOnMouseClicked(event -> getEditValueHandler(attribute, editorFactory, values));
attributeValueNode.setOnMouseClicked(event -> {
if (event.getButton() == MouseButton.PRIMARY && event.isStillSincePress()) {
getEditValueHandler(attribute, editorFactory, values);
}
});
}
// If we don't do anything here, right-clicking on the Node will produce two context menus:
// the one the Node has by default, and the one we added to the AttributeTitledPane.
// We'll consume the context menu event so it doesn't bubble up to the TitledPane.
// Ditto for the button.
attributeValueNode.addEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, Event::consume);
editButton.addEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, Event::consume);
// Title
final ColumnConstraints titleConstraint = new ColumnConstraints(titleWidth);
titleConstraint.setHalignment(HPos.RIGHT);
// Value
final ColumnConstraints valueConstraint = new ColumnConstraints();
valueConstraint.setHalignment(HPos.CENTER);
valueConstraint.setHgrow(Priority.ALWAYS);
valueConstraint.setFillWidth(true);
// EditButton
final ColumnConstraints editConstraint = new ColumnConstraints(buttonSize);
editConstraint.setHalignment(HPos.RIGHT);
gridPane.getColumnConstraints().addAll(titleConstraint, valueConstraint, editConstraint);
gridPane.add(attributeTitleText, 0, 0);
gridPane.add(attributeValueNode, 1, 0);
gridPane.add(editButton, 2, 0);
attributePane.setAlignment(Pos.CENTER_RIGHT);
attributePane.setGraphic(gridPane);
attributePane.setTooltip(new Tooltip(attribute.getAttributeDescription()));
attributePane.setExpanded(attribute.isKeepExpanded());
attributePane.setOnDragDetected(event -> {
final Dragboard db = attributePane.startDragAndDrop(TransferMode.COPY);
final ClipboardContent content = new ClipboardContent();
final String data = String.format("%s:%s", attribute.getElementType().getShortLabel(), attribute.getAttributeName());
content.put(ATTRIBUTE_NAME_DATA_FORMAT, data);
content.putString(String.format("Attribute.Name=%s", data));
db.setContent(content);
event.consume();
});
return attributePane;
}
use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.
the class ColorPropertyEditor method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
if ("OK".equals(e.getActionCommand())) {
final Color color = chooser.getColor();
final ConstellationColor cv = ConstellationColor.fromJavaColor(color);
setValue(cv);
}
}
use of au.gov.asd.tac.constellation.utilities.color.ConstellationColor in project constellation by constellation-app.
the class ColorPropertyEditor method paintValue.
@Override
public void paintValue(final Graphics g, final Rectangle r) {
final ConstellationColor cv = (ConstellationColor) getValue();
if (cv != null) {
final Color gcolor = g.getColor();
final Color color = new Color(cv.getRed(), cv.getGreen(), cv.getBlue(), cv.getAlpha());
int px = 0;
g.drawRect(r.x, r.y + r.height / 2 - 5, 10, 10);
g.setColor(color);
g.fillRect(r.x + 1, r.y + r.height / 2 - 4, 9, 9);
px = 18;
final String text = cv.getName() != null ? cv.getName() : String.format("r=%s g=%s b=%s a=%s", formatFloat(cv.getRed()), formatFloat(cv.getGreen()), formatFloat(cv.getBlue()), formatFloat(cv.getAlpha()));
((Graphics2D) g).setRenderingHints(IconUtilities.getHints());
final FontMetrics fm = g.getFontMetrics();
g.setColor(gcolor);
g.drawString(text, r.x + px, r.y + (r.height - fm.getHeight()) / 2 + fm.getAscent());
} else {
final int px = 0;
((Graphics2D) g).setRenderingHints(IconUtilities.getHints());
final FontMetrics fm = g.getFontMetrics();
g.setColor(MULTIPLE_COLOR);
g.drawString("«multiple selection»", r.x + px, r.y + (r.height - fm.getHeight()) / 2 + fm.getAscent());
}
}
Aggregations