Search in sources :

Example 1 with DiagramExtras

use of com.intellij.diagram.extras.DiagramExtras in project intellij-plugins by JetBrains.

the class AngularUiRouterDiagramProvider method getExtras.

@NotNull
@Override
public DiagramExtras<DiagramObject> getExtras() {
    return new DiagramExtras<DiagramObject>() {

        @Override
        public List<AnAction> getExtraActions() {
            return Collections.singletonList(new MyEditSourceAction());
        }

        @Nullable
        @Override
        public Object getData(String dataId, List<DiagramNode<DiagramObject>> list, DiagramBuilder builder) {
            if (CommonDataKeys.PSI_ELEMENT.is(dataId) && list.size() == 1) {
                final SmartPsiElementPointer target = list.get(0).getIdentifyingElement().getNavigationTarget();
                return target == null ? null : target.getElement();
            } else if (JSModulesDiagramUtils.DIAGRAM_BUILDER.is(dataId)) {
                return builder;
            }
            return null;
        }

        @Nullable
        @Override
        public Layouter getCustomLayouter(Graph2D graph, Project project) {
            final GraphSettingsProvider settingsProvider = GraphSettingsProvider.getInstance(project);
            final GraphSettings settings = settingsProvider.getSettings(graph);
            final SmartOrganicLayouter layouter = settings.getOrganicLayouter();
            layouter.setNodeEdgeOverlapAvoided(true);
            layouter.setNodeSizeAware(true);
            layouter.setMinimalNodeDistance(60);
            layouter.setNodeOverlapsAllowed(false);
            layouter.setSmartComponentLayoutEnabled(true);
            layouter.setConsiderNodeLabelsEnabled(true);
            layouter.setDeterministic(true);
            final List<CanonicMultiStageLayouter> list = new ArrayList<>();
            list.add(layouter);
            list.add(settings.getBalloonLayouter());
            list.add(settings.getCircularLayouter());
            list.add(settings.getDirectedOrthogonalLayouter());
            //list.add(settings.getGroupLayouter());
            list.add(settings.getHVTreeLayouter());
            list.add(settings.getOrthogonalLayouter());
            for (CanonicMultiStageLayouter current : list) {
                final ParallelEdgeLayouter parallelEdgeLayouter = GraphManager.getGraphManager().createParallelEdgeLayouter();
                parallelEdgeLayouter.setLineDistance(40);
                parallelEdgeLayouter.setUsingAdaptiveLineDistances(false);
                current.appendStage(parallelEdgeLayouter);
                current.setParallelEdgeLayouterEnabled(false);
            }
            return layouter;
        }

        @NotNull
        @Override
        public JComponent createNodeComponent(DiagramNode<DiagramObject> node, DiagramBuilder builder, Point basePoint, JPanel wrapper) {
            final DiagramNodeContainer container = new DiagramNodeContainer(node, builder, basePoint);
            if (!GraphViewUtil.isPrintMode()) {
                if (!node.getIdentifyingElement().getErrors().isEmpty()) {
                    container.setBorder(ERROR_BORDER);
                } else if (!node.getIdentifyingElement().getWarnings().isEmpty()) {
                    container.setBorder(WARNING_BORDER);
                } else {
                    container.setBorder(NORMAL_BORDER);
                }
            }
            if (!node.getIdentifyingElement().getChildrenList().isEmpty())
                container.getHeader().setBorder(JBUI.Borders.customLine(Gray._190, 0, 0, 1, 0));
            return container;
        }
    };
}
Also used : CanonicMultiStageLayouter(com.intellij.openapi.graph.layout.CanonicMultiStageLayouter) GraphSettingsProvider(com.intellij.openapi.graph.settings.GraphSettingsProvider) ParallelEdgeLayouter(com.intellij.openapi.graph.layout.ParallelEdgeLayouter) YPoint(com.intellij.openapi.graph.geom.YPoint) Project(com.intellij.openapi.project.Project) GraphSettings(com.intellij.openapi.graph.settings.GraphSettings) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) DiagramNodeContainer(com.intellij.diagram.components.DiagramNodeContainer) DiagramExtras(com.intellij.diagram.extras.DiagramExtras) List(java.util.List) SmartOrganicLayouter(com.intellij.openapi.graph.layout.organic.SmartOrganicLayouter) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DiagramNodeContainer (com.intellij.diagram.components.DiagramNodeContainer)1 DiagramExtras (com.intellij.diagram.extras.DiagramExtras)1 YPoint (com.intellij.openapi.graph.geom.YPoint)1 CanonicMultiStageLayouter (com.intellij.openapi.graph.layout.CanonicMultiStageLayouter)1 ParallelEdgeLayouter (com.intellij.openapi.graph.layout.ParallelEdgeLayouter)1 SmartOrganicLayouter (com.intellij.openapi.graph.layout.organic.SmartOrganicLayouter)1 GraphSettings (com.intellij.openapi.graph.settings.GraphSettings)1 GraphSettingsProvider (com.intellij.openapi.graph.settings.GraphSettingsProvider)1 Project (com.intellij.openapi.project.Project)1 SmartPsiElementPointer (com.intellij.psi.SmartPsiElementPointer)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1