use of au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawNodeLabelsAction in project constellation by constellation-app.
the class VisualGraphTopComponent method init.
/**
* Initialise the TopComponent state.
*/
private void init() {
displayPanel.add(visualManager.getVisualComponent(), BorderLayout.CENTER);
DropTargetAdapter dta = new DropTargetAdapter() {
@Override
public void dragEnter(DropTargetDragEvent dtde) {
dtde.acceptDrag(DnDConstants.ACTION_COPY);
}
@Override
public void drop(DropTargetDropEvent dtde) {
final Transferable transferable = dtde.getTransferable();
if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
try {
dtde.acceptDrop(DnDConstants.ACTION_COPY);
// files will be list of file which extends from object type
@SuppressWarnings("unchecked") final List<File> files = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
for (final File file : files) {
try (final InputStream in = StringUtils.endsWithIgnoreCase(file.getName(), FileExtensionConstants.GZIP) ? new GZIPInputStream(new FileInputStream(file)) : new FileInputStream(file)) {
final RecordStore recordStore = RecordStoreUtilities.fromTsv(in);
PluginExecution.withPlugin(new ImportRecordFile(recordStore)).executeLater(graph);
}
}
} catch (final UnsupportedFlavorException | IOException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
dtde.rejectDrop();
}
} else {
dtde.rejectDrop();
}
}
};
displayPanel.setDropTarget(new DropTarget(displayPanel, DnDConstants.ACTION_COPY, dta, true));
content.add(getActionMap());
savable = new MySavable();
saveAs = new MySaveAs();
content.add(saveAs);
content.add(graphNode.getDataObject());
content.add(graph);
content.add(graphNode);
associateLookup(new AbstractLookup(content));
setActivatedNodes(new Node[] { graphNode });
getActionMap().put("cut-to-clipboard", new CutToClipboardAction(graphNode));
getActionMap().put("copy-to-clipboard", new CopyToClipboardAction(graphNode));
getActionMap().put("paste-from-clipboard", new PasteFromClipboardAction(graphNode));
// The actions below are per-graph.
// NetBeans creates a single instance of an action and uses it globally, which doesn't do us any good,
// because we want to have different toggle states on different graphs, for instance.
// Therefore, we'll ignore NetBeans and create our own per-graph action instances.
expandCompositesAction = new ExpandAllCompositesAction(graphNode);
contractCompositesAction = new ContractAllCompositesAction(graphNode);
drawNodesAction = new DrawNodesAction(graphNode);
drawConnectionsAction = new DrawConnectionsAction(graphNode);
drawNodeLabelsAction = new DrawNodeLabelsAction(graphNode);
drawConnectionLabelsAction = new DrawConnectionLabelsAction(graphNode);
drawBlazesAction = new DrawBlazesAction(graphNode);
final ButtonGroup drawButtonGroup = new ButtonGroup();
drawLinksAction = new DrawLinksAction(graphNode, drawButtonGroup);
drawEdgesAction = new DrawEdgesAction(graphNode, drawButtonGroup);
drawTransactionsAction = new DrawTransactionsAction(graphNode, drawButtonGroup);
final ButtonGroup displayModeButtonGroup = new ButtonGroup();
display3dAction = new Toggle3DAction(graphNode, displayModeButtonGroup);
final ButtonGroup addModeButtonGroup = new ButtonGroup();
toggleSelectModeAction = new ToggleSelectionModeAction(graphNode, addModeButtonGroup);
final ButtonGroup directedModeButtonGroup = new ButtonGroup();
toggleDrawDirectedAction = new ToggleDrawDirectedAction(graphNode, directedModeButtonGroup);
toggleGraphVisibilityAction = new ToggleGraphVisibilityAction(graphNode);
final JToolBar sidebar = new JToolBar(SwingConstants.VERTICAL);
sidebar.setFloatable(false);
sidebar.setRollover(true);
sidebar.add(display3dAction.getToolbarPresenter());
sidebar.addSeparator();
sidebar.add(drawLinksAction.getToolbarPresenter());
sidebar.add(drawEdgesAction.getToolbarPresenter());
sidebar.add(drawTransactionsAction.getToolbarPresenter());
sidebar.addSeparator();
sidebar.add(drawNodesAction.getToolbarPresenter());
sidebar.add(drawConnectionsAction.getToolbarPresenter());
sidebar.add(drawNodeLabelsAction.getToolbarPresenter());
sidebar.add(drawConnectionLabelsAction.getToolbarPresenter());
sidebar.add(drawBlazesAction.getToolbarPresenter());
sidebar.addSeparator();
sidebar.add(toggleGraphVisibilityAction.getToolbarPresenter());
sidebar.addSeparator();
sidebar.add(expandCompositesAction.getToolbarPresenter());
sidebar.add(contractCompositesAction.getToolbarPresenter());
sidebar.addSeparator();
sidebar.add(toggleSelectModeAction.getToolbarPresenter());
sidebar.add(toggleDrawDirectedAction.getToolbarPresenter());
// Add this so the side bar isn't too long.
// Without this, the side bar has a height that extends past the icons and stops other TopComponents
// from growing past it.
sidebar.setMinimumSize(new Dimension(0, 0));
// Set the modification counters to whatever they are now.
// This causes any setup changes to be ignored.
final ReadableGraph rg = graph.getReadableGraph();
try {
graphModificationCountBase = rg.getGlobalModificationCounter();
graphModificationCount = graphModificationCountBase;
} finally {
rg.release();
}
// Initial update so that the sidebar actions are updated to match the graph.
visualUpdate();
this.add(sidebar, BorderLayout.WEST);
// Listen to graph changes so we can update our modified flag. This will determine
// whether or not we need to enable saving of the graph.
graph.addGraphChangeListener(this);
final InputMap keys = getInputMap(VisualGraphTopComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
final KeyStroke key = KeyStroke.getKeyStroke("Control W");
final CloseAction ca = new CloseAction(graphNode);
keys.put(key, ca);
// Set the icon.
final Schema schema = graph.getSchema();
final Image image = getBufferedImageForSchema(schema, false);
VisualGraphTopComponent.this.setIcon(getNebulaIcon(image));
final UpdateComponent<GraphReadMethods> visualUpdateComponent = new UpdateComponent<GraphReadMethods>() {
@Override
protected boolean update(GraphReadMethods updateState) {
visualUpdate();
return true;
}
};
visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.DRAW_FLAGS));
visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.VISIBLE_ABOVE_THRESHOLD));
visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.DISPLAY_MODE_3D));
visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.DRAWING_MODE));
visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.DRAW_DIRECTED_TRANSACTIONS));
visualUpdateComponent.dependOn(graphUpdateController.createAttributeUpdateComponent(VisualConcept.GraphAttribute.CONNECTION_MODE));
graphUpdateManager.setManaged(true);
}
Aggregations