Search in sources :

Example 1 with WorkspaceListener

use of org.gephi.project.api.WorkspaceListener 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)

Example 2 with WorkspaceListener

use of org.gephi.project.api.WorkspaceListener in project gephi by gephi.

the class DataTableTopComponent method initEvents.

private void initEvents() {
    //Workspace Listener
    pc.addWorkspaceListener(new WorkspaceListener() {

        @Override
        public void initialize(Workspace workspace) {
            //Prepare DataTablesEvent listener
            Lookup.getDefault().lookup(DataTablesController.class).setDataTablesEventListener(DataTableTopComponent.this);
            if (workspace.getLookup().lookup(DataTablesModel.class) == null) {
                workspace.add(new DataTablesModel(workspace));
            }
        }

        @Override
        public void select(Workspace workspace) {
            activateWorkspace(workspace);
            setAutoRefreshEnabled(true);
        }

        @Override
        public void unselect(Workspace workspace) {
            deactivateAll();
            setAutoRefreshEnabled(false);
        }

        @Override
        public void close(Workspace workspace) {
        }

        @Override
        public void disable() {
            clearAll();
            //No more workspaces active, disable the DataTablesEvent listener
            Lookup.getDefault().lookup(DataTablesController.class).setDataTablesEventListener(null);
            setAutoRefreshEnabled(false);
        }
    });
    if (pc.getCurrentWorkspace() != null) {
        activateWorkspace(pc.getCurrentWorkspace());
        setAutoRefreshEnabled(true);
    }
    observersTimer = new java.util.Timer("DataLaboratoryGraphObservers");
    observersTimer.schedule(new TimerTask() {

        @Override
        public void run() {
            if (!autoRefreshEnabled) {
                return;
            }
            if (dataTablesObservers != null) {
                if (dataTablesObservers.hasChanges()) {
                    //Execute refresh
                    graphChanged();
                }
            }
        }
    }, 0, //Check graph and tables for changes every 100 ms
    AUTO_REFRESH_RATE_MILLISECONDS);
    //Filter
    if (dynamicFiltering) {
        filterTextField.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void insertUpdate(DocumentEvent e) {
                refreshAppliedFilter();
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                refreshAppliedFilter();
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
            }
        });
    } else {
        filterTextField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                refreshAppliedFilter();
            }
        });
    }
    columnComboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshAppliedFilter();
        }
    });
    initKeyEventContextMenuActionMappings();
}
Also used : DocumentListener(javax.swing.event.DocumentListener) WorkspaceListener(org.gephi.project.api.WorkspaceListener) TimerTask(java.util.TimerTask) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) DocumentEvent(javax.swing.event.DocumentEvent) Workspace(org.gephi.project.api.Workspace)

Example 3 with WorkspaceListener

use of org.gephi.project.api.WorkspaceListener in project gephi by gephi.

the class VizController method initInstances.

public void initInstances() {
    vizConfig = new VizConfig();
    graphIO = new StandardGraphIO();
    engine = new CompatibilityEngine();
    vizEventManager = new StandardVizEventManager();
    scheduler = new CompatibilityScheduler();
    limits = new GraphLimits();
    dataBridge = new DataBridge();
    textManager = new TextManager();
    screenshotMaker = new ScreenshotMaker();
    currentModel = new VizModel(true);
    selectionManager = new SelectionManager();
    if (vizConfig.isUseGLJPanel()) {
    //No more supported
    } else if (Utilities.isMac()) {
        drawable = createCanvas();
    } else {
        drawable = createNewtCanvas();
    }
    drawable.initArchitecture();
    engine.initArchitecture();
    ((CompatibilityScheduler) scheduler).initArchitecture();
    ((StandardGraphIO) graphIO).initArchitecture();
    dataBridge.initArchitecture();
    textManager.initArchitecture();
    screenshotMaker.initArchitecture();
    vizEventManager.initArchitecture();
    selectionManager.initArchitecture();
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    pc.addWorkspaceListener(new WorkspaceListener() {

        @Override
        public void initialize(Workspace workspace) {
            if (workspace.getLookup().lookup(VizModel.class) == null) {
                workspace.add(new VizModel(workspace));
            }
        }

        @Override
        public void select(Workspace workspace) {
            engine.reinit();
        }

        @Override
        public void unselect(Workspace workspace) {
        }

        @Override
        public void close(Workspace workspace) {
        }

        @Override
        public void disable() {
            engine.reinit();
        }
    });
    if (pc.getCurrentWorkspace() != null) {
        engine.reinit();
    }
}
Also used : SelectionManager(org.gephi.visualization.api.selection.SelectionManager) CompatibilityEngine(org.gephi.visualization.opengl.CompatibilityEngine) TextManager(org.gephi.visualization.text.TextManager) StandardVizEventManager(org.gephi.visualization.events.StandardVizEventManager) CompatibilityScheduler(org.gephi.visualization.scheduler.CompatibilityScheduler) ProjectController(org.gephi.project.api.ProjectController) WorkspaceListener(org.gephi.project.api.WorkspaceListener) StandardGraphIO(org.gephi.visualization.swing.StandardGraphIO) ScreenshotMaker(org.gephi.visualization.screenshot.ScreenshotMaker) VizConfig(org.gephi.visualization.apiimpl.VizConfig) DataBridge(org.gephi.visualization.bridge.DataBridge) Workspace(org.gephi.project.api.Workspace)

Aggregations

Workspace (org.gephi.project.api.Workspace)3 WorkspaceListener (org.gephi.project.api.WorkspaceListener)3 ProjectController (org.gephi.project.api.ProjectController)2 BorderLayout (java.awt.BorderLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 TimerTask (java.util.TimerTask)1 JPanel (javax.swing.JPanel)1 DocumentEvent (javax.swing.event.DocumentEvent)1 DocumentListener (javax.swing.event.DocumentListener)1 ToolController (org.gephi.tools.api.ToolController)1 SelectionManager (org.gephi.visualization.api.selection.SelectionManager)1 VizConfig (org.gephi.visualization.apiimpl.VizConfig)1 DataBridge (org.gephi.visualization.bridge.DataBridge)1 StandardVizEventManager (org.gephi.visualization.events.StandardVizEventManager)1 CompatibilityEngine (org.gephi.visualization.opengl.CompatibilityEngine)1 CompatibilityScheduler (org.gephi.visualization.scheduler.CompatibilityScheduler)1 ScreenshotMaker (org.gephi.visualization.screenshot.ScreenshotMaker)1 StandardGraphIO (org.gephi.visualization.swing.StandardGraphIO)1 TextManager (org.gephi.visualization.text.TextManager)1