Search in sources :

Example 1 with ToolController

use of org.gephi.tools.api.ToolController in project gephi by gephi.

the class GraphTopComponent method initToolPanels.

private void initToolPanels() {
    final ToolController tc = Lookup.getDefault().lookup(ToolController.class);
    if (tc != null) {
        if (VizController.getInstance().getVizConfig().isToolbar()) {
            JPanel westPanel = new JPanel(new BorderLayout(0, 0));
            if (UIUtils.isAquaLookAndFeel()) {
                westPanel.setBackground(UIManager.getColor("NbExplorerView.background"));
            }
            toolbar = tc.getToolbar();
            if (toolbar != null) {
                westPanel.add(toolbar, BorderLayout.CENTER);
            }
            selectionToolbar = new SelectionToolbar();
            actionsToolbar = new ActionsToolbar();
            westPanel.add(selectionToolbar, BorderLayout.NORTH);
            westPanel.add(actionsToolbar, BorderLayout.SOUTH);
            add(westPanel, BorderLayout.WEST);
        }
        if (VizController.getInstance().getVizConfig().isPropertiesbar()) {
            propertiesBar = tc.getPropertiesBar();
            if (propertiesBar != null) {
                add(propertiesBar, BorderLayout.NORTH);
            }
        }
    }
    //Workspace events
    ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
    projectController.addWorkspaceListener(new WorkspaceListener() {

        @Override
        public void initialize(Workspace workspace) {
        }

        @Override
        public void select(Workspace workspace) {
            if (toolbar != null) {
                toolbar.setEnabled(true);
            }
            if (propertiesBar != null) {
                propertiesBar.setEnabled(true);
            }
            if (actionsToolbar != null) {
                actionsToolbar.setEnabled(true);
            }
            if (selectionToolbar != null) {
                selectionToolbar.setEnabled(true);
            }
        }

        @Override
        public void unselect(Workspace workspace) {
        }

        @Override
        public void close(Workspace workspace) {
        }

        @Override
        public void disable() {
            if (toolbar != null) {
                toolbar.setEnabled(false);
            }
            if (tc != null) {
                //Unselect any selected tool
                tc.select(null);
            }
            if (propertiesBar != null) {
                propertiesBar.setEnabled(false);
            }
            if (actionsToolbar != null) {
                actionsToolbar.setEnabled(false);
            }
            if (selectionToolbar != null) {
                selectionToolbar.setEnabled(false);
            }
        }
    });
    boolean hasWorkspace = projectController.getCurrentWorkspace() != null;
    if (toolbar != null) {
        toolbar.setEnabled(hasWorkspace);
    }
    if (propertiesBar != null) {
        propertiesBar.setEnabled(hasWorkspace);
    }
    if (actionsToolbar != null) {
        actionsToolbar.setEnabled(hasWorkspace);
    }
    if (selectionToolbar != null) {
        selectionToolbar.setEnabled(hasWorkspace);
    }
}
Also used : JPanel(javax.swing.JPanel) WorkspaceListener(org.gephi.project.api.WorkspaceListener) BorderLayout(java.awt.BorderLayout) ToolController(org.gephi.tools.api.ToolController) ProjectController(org.gephi.project.api.ProjectController) Workspace(org.gephi.project.api.Workspace)

Aggregations

BorderLayout (java.awt.BorderLayout)1 JPanel (javax.swing.JPanel)1 ProjectController (org.gephi.project.api.ProjectController)1 Workspace (org.gephi.project.api.Workspace)1 WorkspaceListener (org.gephi.project.api.WorkspaceListener)1 ToolController (org.gephi.tools.api.ToolController)1