Search in sources :

Example 1 with ToggleDrawDirectedAction

use of au.gov.asd.tac.constellation.graph.interaction.plugins.draw.ToggleDrawDirectedAction 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);
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) DrawConnectionsAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawConnectionsAction) PasteFromClipboardAction(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.PasteFromClipboardAction) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) DrawTransactionsAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawTransactionsAction) CutToClipboardAction(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CutToClipboardAction) ArrayList(java.util.ArrayList) List(java.util.List) DrawLinksAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawLinksAction) ExpandAllCompositesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.composite.ExpandAllCompositesAction) DrawNodesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawNodesAction) DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) AbstractLookup(org.openide.util.lookup.AbstractLookup) FileInputStream(java.io.FileInputStream) DropTargetAdapter(java.awt.dnd.DropTargetAdapter) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap) DropTarget(java.awt.dnd.DropTarget) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent) File(java.io.File) ContractAllCompositesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.composite.ContractAllCompositesAction) CloseAction(au.gov.asd.tac.constellation.graph.interaction.plugins.io.CloseAction) DrawNodeLabelsAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawNodeLabelsAction) GZIPInputStream(java.util.zip.GZIPInputStream) DrawEdgesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawEdgesAction) GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) ToggleDrawDirectedAction(au.gov.asd.tac.constellation.graph.interaction.plugins.draw.ToggleDrawDirectedAction) DrawConnectionLabelsAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawConnectionLabelsAction) Toggle3DAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.Toggle3DAction) ToggleGraphVisibilityAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.ToggleGraphVisibilityAction) ToggleSelectionModeAction(au.gov.asd.tac.constellation.graph.interaction.plugins.draw.ToggleSelectionModeAction) CopyToClipboardAction(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToClipboardAction) GZIPInputStream(java.util.zip.GZIPInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Transferable(java.awt.datatransfer.Transferable) UpdateComponent(au.gov.asd.tac.constellation.plugins.update.UpdateComponent) IOException(java.io.IOException) JToolBar(javax.swing.JToolBar) Dimension(java.awt.Dimension) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) ButtonGroup(javax.swing.ButtonGroup) DrawBlazesAction(au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawBlazesAction)

Aggregations

GraphReadMethods (au.gov.asd.tac.constellation.graph.GraphReadMethods)1 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 CopyToClipboardAction (au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToClipboardAction)1 CutToClipboardAction (au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CutToClipboardAction)1 PasteFromClipboardAction (au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.PasteFromClipboardAction)1 ContractAllCompositesAction (au.gov.asd.tac.constellation.graph.interaction.plugins.composite.ContractAllCompositesAction)1 ExpandAllCompositesAction (au.gov.asd.tac.constellation.graph.interaction.plugins.composite.ExpandAllCompositesAction)1 DrawBlazesAction (au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawBlazesAction)1 DrawConnectionLabelsAction (au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawConnectionLabelsAction)1 DrawConnectionsAction (au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawConnectionsAction)1 DrawEdgesAction (au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawEdgesAction)1 DrawLinksAction (au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawLinksAction)1 DrawNodeLabelsAction (au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawNodeLabelsAction)1 DrawNodesAction (au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawNodesAction)1 DrawTransactionsAction (au.gov.asd.tac.constellation.graph.interaction.plugins.display.DrawTransactionsAction)1 Toggle3DAction (au.gov.asd.tac.constellation.graph.interaction.plugins.display.Toggle3DAction)1 ToggleGraphVisibilityAction (au.gov.asd.tac.constellation.graph.interaction.plugins.display.ToggleGraphVisibilityAction)1 ToggleDrawDirectedAction (au.gov.asd.tac.constellation.graph.interaction.plugins.draw.ToggleDrawDirectedAction)1 ToggleSelectionModeAction (au.gov.asd.tac.constellation.graph.interaction.plugins.draw.ToggleSelectionModeAction)1 CloseAction (au.gov.asd.tac.constellation.graph.interaction.plugins.io.CloseAction)1