Search in sources :

Example 1 with OVTK2Viewer

use of net.sourceforge.ondex.ovtk2.ui.OVTK2Viewer in project knetbuilder by Rothamsted.

the class VisualisationUtils method zoomIn.

/**
 * Zoom into picked nodes.
 *
 * @param viewer
 *            current active OVTK2Viewer
 */
public static void zoomIn(OVTK2Viewer viewer) {
    // get JUNG VisualizationViewer
    VisualizationViewer<ONDEXConcept, ONDEXRelation> vv = viewer.getVisualizationViewer();
    // local copy of pick state
    Set<ONDEXConcept> picked = new HashSet<ONDEXConcept>(viewer.getPickedNodes());
    if (picked.size() == 1) {
        // first scale it
        OVTK2GraphMouse mouse = (OVTK2GraphMouse) vv.getGraphMouse();
        mouse.getScaler().scale(vv, 1.1f, vv.getCenter());
        // move centre of graph to selection
        ONDEXConcept root = picked.iterator().next();
        Point2D q = vv.getGraphLayout().transform(root);
        Point2D lvc = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter());
        double dx = (lvc.getX() - q.getX());
        double dy = (lvc.getY() - q.getY());
        vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).translate(dx, dy);
        return;
    }
    // reset scaling for predictive behaviour
    vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity();
    vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity();
    double minX = Double.POSITIVE_INFINITY;
    double minY = Double.POSITIVE_INFINITY;
    double maxX = Double.NEGATIVE_INFINITY;
    double maxY = Double.NEGATIVE_INFINITY;
    // get boundaries of selected nodes
    for (ONDEXConcept node : picked) {
        Point2D pos = viewer.getVisualizationViewer().getGraphLayout().transform(node);
        if (pos.getX() < minX) {
            minX = pos.getX();
        }
        if (pos.getX() > maxX) {
            maxX = pos.getX();
        }
        if (pos.getY() < minY) {
            minY = pos.getY();
        }
        if (pos.getY() > maxY) {
            maxY = pos.getY();
        }
    }
    // System.out.println(minX + " " + maxX + " " + minY + " " + maxY);
    // centre graph
    Point2D screen_center = vv.getCenter();
    Point2D layout_bounds = new Point2D.Double(maxX - minX, maxY - minY);
    Point2D layout_center = new Point2D.Double(screen_center.getX() - (layout_bounds.getX() / 2) - minX, screen_center.getY() - (layout_bounds.getY() / 2) - minY);
    vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).translate(layout_center.getX(), layout_center.getY());
    // scale graph
    Point2D scale_bounds = new Point2D.Double(vv.getWidth() / layout_bounds.getX(), vv.getHeight() / layout_bounds.getY());
    float scale = (float) Math.min(scale_bounds.getX(), scale_bounds.getY());
    scale = 0.92f * scale;
    OVTK2GraphMouse mouse = (OVTK2GraphMouse) vv.getGraphMouse();
    mouse.getScaler().scale(vv, scale, vv.getCenter());
}
Also used : OVTK2GraphMouse(net.sourceforge.ondex.ovtk2.ui.mouse.OVTK2GraphMouse) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) Point2D(java.awt.geom.Point2D) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) HashSet(java.util.HashSet)

Example 2 with OVTK2Viewer

use of net.sourceforge.ondex.ovtk2.ui.OVTK2Viewer in project knetbuilder by Rothamsted.

the class FileMenuAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent ae) {
    String cmd = ae.getActionCommand();
    final OVTK2Desktop desktop = OVTK2Desktop.getInstance();
    final OVTK2ResourceAssesor resources = OVTK2Desktop.getDesktopResources();
    // for coping with plug-in Attribute data types
    try {
        Thread.currentThread().setContextClassLoader(OVTK2PluginLoader.getInstance().ucl);
    } catch (FileNotFoundException e) {
        ErrorDialog.show(e);
    } catch (MalformedURLException e) {
        ErrorDialog.show(e);
    }
    // new empty graph in OVTK2Viewer
    if (cmd.equals("new")) {
        // name of new graph
        String name = String.valueOf(OVTK2Viewer.instances);
        // get a empty new graph
        ONDEXGraph graph = DesktopUtils.initGraph(name);
        // put new graph into viewer
        OVTK2Viewer viewer = DesktopUtils.initViewer(graph);
        // set viewer as active viewer
        resources.setSelectedViewer(viewer);
        // display viewer centred
        desktop.display(viewer, Position.centered);
        // close possible welcome dialog
        WelcomeDialog.getInstance(desktop).setVisible(false);
    } else // open data from file into new OVTK2Viewer
    if (cmd.equals("open")) {
        // ask user what file to open
        File file = DesktopUtils.showOpenDialog(new String[] { "oxl", "gz", "xml" });
        if (file != null) {
            DesktopUtils.openFile(file);
            OVTK2Menu menu = (OVTK2Menu) desktop.getMainFrame().getJMenuBar();
            String path = file.getAbsolutePath();
            // hook into FileHistory class
            menu.fileHistory.insertPathname(path);
            // close possible welcome dialog
            WelcomeDialog.getInstance(desktop).setVisible(false);
        }
    } else // uses import wizard to parse delimited files
    if (cmd.equals("importwizard")) {
        if (resources.getSelectedViewer() != null) {
            final ImportWizard iw = new ImportWizard(ConfigTool.loadFromFile(Config.ovtkDir + File.separator + "iw_config.xml"));
            // add to JDesktopPane
            desktop.getDesktopPane().add(iw);
            iw.setVisible(true);
            // busy waiting for ImportWizard to close
            Thread thread = new Thread() {

                public void run() {
                    synchronized (this) {
                        while (iw.isVisible()) {
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException e) {
                            }
                        }
                        Vector<Object> r = iw.getReturnContent();
                        if (r.size() > 0) {
                            // get current viewer
                            OVTK2Viewer viewer = (OVTK2Viewer) resources.getSelectedViewer();
                            viewer.getONDEXJUNGGraph().updateLastState();
                            // graph to export
                            ONDEXGraph aog = viewer.getONDEXJUNGGraph();
                            // start loading of data
                            new WizardImport(aog, r, null);
                        }
                    }
                }
            };
            // for coping with plug-in Attribute data types
            try {
                thread.setContextClassLoader(OVTK2PluginLoader.getInstance().ucl);
            } catch (FileNotFoundException e) {
                ErrorDialog.show(e);
            } catch (MalformedURLException e) {
                ErrorDialog.show(e);
            }
            thread.start();
        } else {
            JOptionPane.showInternalMessageDialog(OVTK2Desktop.getInstance().getDesktopPane(), "No graph loaded or available. Cannot continue with operation.", "Graph not found", JOptionPane.ERROR_MESSAGE);
        }
    } else // save data to file from active OVTK2Viewer
    if (cmd.equals("save")) {
        if (resources.getSelectedViewer() != null) {
            // ask user which file to save to
            final File file = DesktopUtils.showSaveDialog(new String[] { "oxl", "xml", "gz" });
            if (file != null) {
                // get current viewer
                OVTK2Viewer viewer = (OVTK2Viewer) resources.getSelectedViewer();
                viewer.getONDEXJUNGGraph().updateLastState();
                // trigger export
                DesktopUtils.saveFile(file, viewer);
            }
        } else {
            JOptionPane.showInternalMessageDialog(OVTK2Desktop.getInstance().getDesktopPane(), "No graph loaded or available. Cannot continue with operation.", "Graph not found", JOptionPane.ERROR_MESSAGE);
        }
    } else // save graph as an image
    if (cmd.equals("image")) {
        if (resources.getSelectedViewer() != null) {
            File dir = (Config.lastSavedFile == null) ? new File(System.getProperty("user.dir")) : new File(Config.lastSavedFile);
            DialogExport chooser = new DialogExport(dir);
            // chooser.addFormat("graphml");
            int i = chooser.showSaveDialog((OVTK2Viewer) resources.getSelectedViewer());
            if (i == JFileChooser.APPROVE_OPTION) {
                File file = chooser.getFile();
                Config.lastSavedFile = file.getAbsolutePath();
                OVTK2Viewer viewer = (OVTK2Viewer) resources.getSelectedViewer();
                new SVGExport(viewer, file, chooser.getSelectedFormat());
            // ImageWriterUtil<ONDEXConcept, ONDEXRelation> iw = new
            // ImageWriterUtil<ONDEXConcept,
            // ONDEXRelation>(resources.getSelectedViewer());
            // iw.writeImage(file, chooser.getSelectedFormat(),
            // chooser.getScaleFactor());
            }
        } else {
            JOptionPane.showInternalMessageDialog(OVTK2Desktop.getInstance().getDesktopPane(), "No graph loaded or available. Cannot continue with operation.", "Graph not found", JOptionPane.ERROR_MESSAGE);
        }
    } else // import
    if (cmd.equals("import")) {
        // list of file extensions of all loaded plugins
        ArrayList<String> extensions = new ArrayList<String>();
        // get extensions of importer plugins
        final Map<String, OVTK2IO> ext2io = new Hashtable<String, OVTK2IO>();
        try {
            Set<String> names = OVTK2PluginLoader.getInstance().getAvailableIOIDs();
            for (String name : names) {
                try {
                    OVTK2IO io = OVTK2PluginLoader.getInstance().loadIO(name);
                    if (io == null) {
                        continue;
                    }
                    if (io.isImport()) {
                        extensions.add(io.getExt());
                        ext2io.put(io.getExt(), io);
                    }
                } catch (Exception e) {
                    ErrorDialog.show(e);
                }
            }
        } catch (FileNotFoundException e) {
            ErrorDialog.show(e);
        } catch (MalformedURLException e) {
            ErrorDialog.show(e);
        }
        // handle error
        if (extensions.size() == 0) {
            JOptionPane.showInternalMessageDialog(desktop.getDesktopPane(), "No importer plugins have been loaded.", "No importer found", JOptionPane.ERROR_MESSAGE);
            return;
        }
        // show file open dialog
        final File file = DesktopUtils.showOpenDialog(extensions.toArray(new String[0]));
        if (file != null) {
            final String ext = file.getName().substring(file.getName().lastIndexOf(".") + 1).toLowerCase();
            // name of new graph
            String name = file.getName();
            // get new empty graph
            final ONDEXGraph aog = DesktopUtils.initGraph(name);
            // case of Prolog import
            if (ext.equals("pro")) {
                IndeterminateProcessAdapter p = new IndeterminateProcessAdapter() {

                    public void task() {
                        // for coping with plug-in Attribute data types
                        try {
                            Thread.currentThread().setContextClassLoader(OVTK2PluginLoader.getInstance().ucl);
                        } catch (FileNotFoundException e) {
                            ErrorDialog.show(e);
                        } catch (MalformedURLException e) {
                            ErrorDialog.show(e);
                        }
                        // location of ondex meta data
                        String ondexDir = System.getProperty("ondex.dir");
                        File metadata = new File(ondexDir + File.separator + "xml" + File.separator + "ondex_metadata.xml");
                        // load meta data
                        try {
                            OXLImport i = new OXLImport(aog, metadata, true);
                            i.start();
                        } catch (Exception e) {
                            ErrorDialog.show(e);
                        }
                        // new prolog import
                        OVTK2IO prolog = ext2io.get(ext);
                        prolog.setGraph(aog);
                        try {
                            // start import process
                            prolog.start(file);
                        } catch (Exception e) {
                            ErrorDialog.show(e);
                        }
                        // display the graph
                        DesktopUtils.displayGraphOnDesktop(aog);
                        // check if appearance attributes present
                        AttributeName an = aog.getMetaData().getAttributeName("shape");
                        if (aog.getConceptsOfAttributeName(an).size() > 0) {
                            int option = JOptionPane.showInternalConfirmDialog(desktop.getDesktopPane(), "Detected appearance attributes. Do you like to load appearance now?", "Load appearance...", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
                            if (option == JOptionPane.YES_OPTION) {
                                FileMenuAction.getInstance().actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "loadappearance"));
                            }
                        }
                    }
                };
                // start processing and monitoring
                p.start();
                OVTKProgressMonitor.start(OVTK2Desktop.getInstance().getMainFrame(), "Importing " + file, p);
                // close possible welcome dialog
                WelcomeDialog.getInstance(desktop).setVisible(false);
            } else // all other cases
            if (ext2io.containsKey(ext)) {
                IndeterminateProcessAdapter p = new IndeterminateProcessAdapter() {

                    public void task() {
                        // for coping with plug-in Attribute data types
                        try {
                            Thread.currentThread().setContextClassLoader(OVTK2PluginLoader.getInstance().ucl);
                        } catch (FileNotFoundException e) {
                            ErrorDialog.show(e);
                        } catch (MalformedURLException e) {
                            ErrorDialog.show(e);
                        }
                        // new generic import
                        OVTK2IO io = ext2io.get(ext);
                        io.setGraph(aog);
                        try {
                            // start import process
                            io.start(file);
                        } catch (Exception e) {
                            ErrorDialog.show(e);
                        }
                        // display the graph
                        DesktopUtils.displayGraphOnDesktop(aog);
                    }
                };
                // start processing and monitoring
                p.start();
                OVTKProgressMonitor.start(OVTK2Desktop.getInstance().getMainFrame(), "Importing " + file, p);
                // close possible welcome dialog
                WelcomeDialog.getInstance(desktop).setVisible(false);
            } else // extension not found
            {
                JOptionPane.showInternalMessageDialog(desktop.getDesktopPane(), "No importer for this file extension available: " + ext, "No importer matching", JOptionPane.ERROR_MESSAGE);
            }
        }
    } else // export
    if (cmd.equals("export")) {
        if (resources.getSelectedViewer() != null) {
            File dir = (Config.lastSavedFile == null) ? new File(System.getProperty("user.dir")) : new File(Config.lastSavedFile);
            DialogExport chooser = new DialogExport(dir);
            chooser.removeAllFormats();
            // get current viewer
            final OVTK2Viewer viewer = (OVTK2Viewer) resources.getSelectedViewer();
            // get extensions of exporter plugins
            final Map<String, OVTK2IO> ext2io = new Hashtable<String, OVTK2IO>();
            try {
                Set<String> names = OVTK2PluginLoader.getInstance().getAvailableIOIDs();
                for (String name : names) {
                    try {
                        OVTK2IO io = OVTK2PluginLoader.getInstance().loadIO(name);
                        if (io == null) {
                            continue;
                        }
                        if (!io.isImport()) {
                            chooser.addFormat(io.getExt());
                            ext2io.put(io.getExt(), io);
                        }
                    } catch (Exception e) {
                        ErrorDialog.show(e);
                    }
                }
            } catch (FileNotFoundException e) {
                ErrorDialog.show(e);
            } catch (MalformedURLException e) {
                ErrorDialog.show(e);
            }
            // handle error
            if (ext2io.size() == 0) {
                JOptionPane.showInternalMessageDialog(desktop.getDesktopPane(), "No exporter plugins have been loaded.", "No exporter found", JOptionPane.ERROR_MESSAGE);
                return;
            }
            int i = chooser.showSaveDialog((OVTK2Viewer) resources.getSelectedViewer());
            if (i == JFileChooser.APPROVE_OPTION) {
                final File file = chooser.getFile();
                if (file.exists() && Boolean.parseBoolean(Config.config.getProperty("Overwrite.Set"))) {
                    int answer = JOptionPane.showInternalConfirmDialog(OVTK2Desktop.getInstance().getDesktopPane(), Config.language.getProperty("Dialog.Save.Warning.Text"), Config.language.getProperty("Dialog.Save.Warning.Title"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                    if (answer == JOptionPane.NO_OPTION)
                        return;
                }
                Config.lastSavedFile = file.getAbsolutePath();
                final String selection = chooser.getSelectedFormat();
                IndeterminateProcessAdapter p = new IndeterminateProcessAdapter() {

                    public void task() {
                        // for coping with plug-in Attribute data types
                        try {
                            Thread.currentThread().setContextClassLoader(OVTK2PluginLoader.getInstance().ucl);
                        } catch (FileNotFoundException e) {
                            ErrorDialog.show(e);
                        } catch (MalformedURLException e) {
                            ErrorDialog.show(e);
                        }
                        // graph to export
                        ONDEXGraph aog = viewer.getONDEXJUNGGraph();
                        // new generic export
                        OVTK2IO io = ext2io.get(selection);
                        io.setGraph(aog);
                        try {
                            // start export process
                            io.start(file);
                        } catch (Exception e) {
                            ErrorDialog.show(e);
                        }
                    }
                };
                // start processing and monitoring
                p.start();
                OVTKProgressMonitor.start(OVTK2Desktop.getInstance().getMainFrame(), "Exporting file", p);
            }
        } else {
            JOptionPane.showInternalMessageDialog(OVTK2Desktop.getInstance().getDesktopPane(), "No graph loaded or available. Cannot continue with operation.", "Graph not found", JOptionPane.ERROR_MESSAGE);
        }
    } else // print visible graph
    if (cmd.equals("print")) {
        if (resources.getSelectedViewer() != null) {
            // setup new print job
            final PrinterJob printJob = PrinterJob.getPrinterJob();
            printJob.setPrintable((OVTK2Viewer) resources.getSelectedViewer());
            if (printJob.printDialog()) {
                IndeterminateProcessAdapter p = new IndeterminateProcessAdapter() {

                    public void task() {
                        try {
                            // start print job
                            printJob.print();
                        } catch (Exception ex) {
                            ErrorDialog.show(ex);
                        }
                    }
                };
                // start processing and monitoring
                p.start();
                OVTKProgressMonitor.start(OVTK2Desktop.getInstance().getMainFrame(), "Printing...", p);
            }
        } else {
            JOptionPane.showInternalMessageDialog(OVTK2Desktop.getInstance().getDesktopPane(), "No graph loaded or available. Cannot continue with operation.", "Graph not found", JOptionPane.ERROR_MESSAGE);
        }
    } else // check for unsaved data before exit
    if (cmd.equals("exit")) {
        // if there is at least one open graph ask to really exit
        if (resources.getSelectedViewer() != null) {
            int option = JOptionPane.showInternalConfirmDialog(desktop.getDesktopPane(), Config.language.getProperty("Dialog.Exit.Warning.Text"), Config.language.getProperty("Dialog.Exit.Warning.Title"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
            if (option == JOptionPane.NO_OPTION) {
                return;
            }
        }
        // save entries for next session
        OVTK2Menu menu = (OVTK2Menu) desktop.getMainFrame().getJMenuBar();
        menu.fileHistory.saveHistoryEntries();
        Config.saveConfig();
        System.exit(0);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Set(java.util.Set) WizardImport(net.sourceforge.ondex.ovtk2.io.WizardImport) ActionEvent(java.awt.event.ActionEvent) OVTK2ResourceAssesor(net.sourceforge.ondex.ovtk2.ui.OVTK2ResourceAssesor) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) PrinterJob(java.awt.print.PrinterJob) AttributeName(net.sourceforge.ondex.core.AttributeName) OVTK2Viewer(net.sourceforge.ondex.ovtk2.ui.OVTK2Viewer) ONDEXGraph(net.sourceforge.ondex.core.ONDEXGraph) IndeterminateProcessAdapter(net.sourceforge.ondex.tools.threading.monitoring.IndeterminateProcessAdapter) SVGExport(net.sourceforge.ondex.ovtk2.util.SVGExport) OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) Hashtable(java.util.Hashtable) OXLImport(net.sourceforge.ondex.ovtk2.io.OXLImport) MalformedURLException(java.net.MalformedURLException) FileNotFoundException(java.io.FileNotFoundException) ImportWizard(net.sourceforge.ondex.ovtk2.io.importwizard.ImportWizard) OVTK2IO(net.sourceforge.ondex.ovtk2.io.OVTK2IO) OVTK2Menu(net.sourceforge.ondex.ovtk2.ui.menu.OVTK2Menu) File(java.io.File) Map(java.util.Map) DialogExport(net.sourceforge.ondex.ovtk2.ui.dialog.DialogExport)

Example 3 with OVTK2Viewer

use of net.sourceforge.ondex.ovtk2.ui.OVTK2Viewer in project knetbuilder by Rothamsted.

the class LayoutMenuAction method internalFrameClosing.

@Override
public void internalFrameClosing(InternalFrameEvent e) {
    OVTK2Desktop desktop = OVTK2Desktop.getInstance();
    if (e.getInternalFrame() instanceof OVTK2LayoutOptions) {
        desktop.locations.remove(e.getInternalFrame());
        options = null;
    } else if (e.getInternalFrame() instanceof OVTK2Viewer) {
        int count = 0;
        for (JInternalFrame jif : desktop.getDesktopPane().getAllFrames()) {
            if (jif instanceof OVTK2Viewer)
                count++;
        }
        // last OVTK2Viewer is closing
        if (count == 1) {
            close(options);
        }
    }
}
Also used : OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) OVTK2Viewer(net.sourceforge.ondex.ovtk2.ui.OVTK2Viewer) JInternalFrame(javax.swing.JInternalFrame) RegisteredJInternalFrame(net.sourceforge.ondex.ovtk2.ui.RegisteredJInternalFrame) OVTK2LayoutOptions(net.sourceforge.ondex.ovtk2.ui.OVTK2LayoutOptions)

Example 4 with OVTK2Viewer

use of net.sourceforge.ondex.ovtk2.ui.OVTK2Viewer in project knetbuilder by Rothamsted.

the class ToolMenuAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent ae) {
    String cmd = ae.getActionCommand();
    OVTK2Desktop desktop = OVTK2Desktop.getInstance();
    OVTK2ResourceAssesor resources = OVTK2Desktop.getDesktopResources();
    OVTK2Viewer viewer = (OVTK2Viewer) resources.getSelectedViewer();
    // for coping with plug-in Attribute data types
    try {
        Thread.currentThread().setContextClassLoader(OVTK2PluginLoader.getInstance().ucl);
    } catch (FileNotFoundException e) {
        ErrorDialog.show(e);
    } catch (MalformedURLException e) {
        ErrorDialog.show(e);
    }
    // show launcher
    if (cmd.equals("launcher")) {
        Thread thread = new Thread() {

            public void run() {
                try {
                    PluginUtils.initPluginRegistry();
                    Class<?> cls = Thread.currentThread().getContextClassLoader().loadClass("net.sourceforge.ondex.workflow2.gui.WorkflowTool");
                    Constructor<?> ct = cls.getConstructor(GraphAdaptor.class);
                    JFrame workflowTool = (JFrame) ct.newInstance(new LoadGraphAdaptor());
                    new LauncherFrame(workflowTool, JInternalFrameSelector.NONE, "Ondex Integrator");
                    workflowTool.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                    ErrorDialog.show(true, new PluginUtils.MissingPluginException("Launcher plugin is not installed or could not be initialized", e), Thread.currentThread());
                } catch (ExceptionInInitializerError e) {
                    ErrorDialog.show(true, new PluginUtils.MissingPluginException("Launcher plugin is not installed "), Thread.currentThread());
                }
            }
        };
        try {
            // for coping with plug-in Attribute data types
            try {
                thread.setContextClassLoader(OVTK2PluginLoader.getInstance().ucl);
            } catch (FileNotFoundException e) {
                ErrorDialog.show(e);
            }
            thread.start();
        } catch (Exception e) {
            ErrorDialog.show(true, new PluginUtils.MissingPluginException("Launcher plugin is not installed or could not be initialized", e), Thread.currentThread());
        }
    } else // show stats window
    if (cmd.equals("stats")) {
        if (viewer != null) {
            StatsFrame frame = new StatsFrame(viewer);
            // handle closing of all stats windows
            frame.addInternalFrameListener(this);
            if (!stats.containsKey(viewer))
                stats.put(viewer, new ArrayList<StatsFrame>());
            stats.get(viewer).add(frame);
            desktop.display(frame, Position.centered);
        }
    }
    // settings for mapping rtset to color
    if (cmd.equals("rtcolor")) {
        DialogRelationTypeColor dialog = new DialogRelationTypeColor();
        desktop.display(dialog, Position.centered);
    } else // settings for mapping cv to color
    if (cmd.equals("cvcolor")) {
        DialogDataSourceColor dialog = new DialogDataSourceColor();
        desktop.display(dialog, Position.centered);
    } else // settings for mapping cc to color
    if (cmd.equals("cccolor")) {
        DialogConceptClassColor dialog = new DialogConceptClassColor();
        desktop.display(dialog, Position.centered);
    } else // settings for mapping cc to shape
    if (cmd.equals("ccshape")) {
        DialogConceptClassShape dialog = new DialogConceptClassShape();
        desktop.display(dialog, Position.centered);
    } else // init command line
    if (cmd.equals("console")) {
        initCommandLine(desktop);
    } else // show editor for user defined popups
    if (cmd.equals("popupeditor")) {
        PopupItemEditPanel editPanel = new PopupItemEditPanel();
        ItemEditor itemEditor = new ItemEditor("Popup Editor", editPanel, editPanel);
        itemEditor.setVisible(true);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ItemEditor(net.sourceforge.ondex.ovtk2.ui.popup.custom.itemeditor.ItemEditor) LauncherFrame(net.sourceforge.ondex.ovtk2.util.LauncherFrame) OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) OVTK2ResourceAssesor(net.sourceforge.ondex.ovtk2.ui.OVTK2ResourceAssesor) FileNotFoundException(java.io.FileNotFoundException) PopupItemEditPanel(net.sourceforge.ondex.ovtk2.ui.popup.custom.PopupItemEditPanel) StatsFrame(net.sourceforge.ondex.ovtk2.ui.stats.StatsFrame) PropertyVetoException(java.beans.PropertyVetoException) MalformedURLException(java.net.MalformedURLException) FileNotFoundException(java.io.FileNotFoundException) DialogDataSourceColor(net.sourceforge.ondex.ovtk2.ui.dialog.DialogDataSourceColor) LoadGraphAdaptor(net.sourceforge.ondex.ovtk2.ui.console.LoadGraphAdaptor) JFrame(javax.swing.JFrame) DialogRelationTypeColor(net.sourceforge.ondex.ovtk2.ui.dialog.DialogRelationTypeColor) DialogConceptClassColor(net.sourceforge.ondex.ovtk2.ui.dialog.DialogConceptClassColor) DialogConceptClassShape(net.sourceforge.ondex.ovtk2.ui.dialog.DialogConceptClassShape) OVTK2Viewer(net.sourceforge.ondex.ovtk2.ui.OVTK2Viewer)

Example 5 with OVTK2Viewer

use of net.sourceforge.ondex.ovtk2.ui.OVTK2Viewer in project knetbuilder by Rothamsted.

the class AppearanceMenuAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent ae) {
    String cmd = ae.getActionCommand();
    OVTK2Desktop desktop = OVTK2Desktop.getInstance();
    OVTK2ResourceAssesor resources = OVTK2Desktop.getDesktopResources();
    OVTK2Viewer viewer = (OVTK2Viewer) resources.getSelectedViewer();
    // triggers all events to load saved appearance
    if (cmd.equals(LOADAPPEARANCE)) {
        if (viewer != null) {
            AppearanceSynchronizer.loadAppearance(desktop, viewer);
        }
    } else // toggle node Attribute colour parsing
    if (cmd.equals(NODECOLOR)) {
        if (viewer != null) {
            JCheckBoxMenuItem item = (JCheckBoxMenuItem) ae.getSource();
            if (item.isSelected())
                AppearanceSynchronizer.loadNodeColor(viewer.getONDEXJUNGGraph(), viewer.getNodeColors(), viewer.getNodeDrawPaint());
            else {
                viewer.getNodeColors().setFillPaintSelection(NodeFillPaintSelection.CONCEPTCLASS);
                viewer.getNodeColors().updateAll();
                viewer.getNodeDrawPaint().setDrawPaintSelection(NodeDrawPaintSelection.NONE);
                viewer.getNodeDrawPaint().updateAll();
            }
            // notify model of change
            viewer.getVisualizationViewer().getModel().fireStateChanged();
        }
    } else // toggle node shape Attribute parsing
    if (cmd.equals(NODESHAPE)) {
        if (viewer != null) {
            JCheckBoxMenuItem item = (JCheckBoxMenuItem) ae.getSource();
            if (item.isSelected())
                AppearanceSynchronizer.loadNodeShape(viewer.getONDEXJUNGGraph(), viewer.getNodeShapes());
            else {
                viewer.getNodeShapes().setNodeShapeSelection(NodeShapeSelection.NONE);
                viewer.getNodeShapes().setNodeSizes(new Transformer<ONDEXConcept, Integer>() {

                    @Override
                    public Integer transform(ONDEXConcept input) {
                        return Config.defaultNodeSize;
                    }
                });
                viewer.getNodeShapes().setNodeAspectRatios(new Transformer<ONDEXConcept, Float>() {

                    @Override
                    public Float transform(ONDEXConcept input) {
                        return 1.0f;
                    }
                });
                viewer.getNodeShapes().updateAll();
            }
            // notify model of change
            viewer.getVisualizationViewer().getModel().fireStateChanged();
        }
    } else // toggle edge Attribute colour parsing
    if (cmd.equals(EDGECOLOR)) {
        if (viewer != null) {
            JCheckBoxMenuItem item = (JCheckBoxMenuItem) ae.getSource();
            if (item.isSelected())
                AppearanceSynchronizer.loadEdgeColor(viewer.getONDEXJUNGGraph(), viewer.getEdgeColors());
            else {
                viewer.getEdgeColors().setEdgeColorSelection(EdgeColorSelection.RELATIONTYPE);
                viewer.getEdgeColors().updateAll();
            }
            // notify model of change
            viewer.getVisualizationViewer().getModel().fireStateChanged();
        }
    } else // toggle edge size Attribute parsing
    if (cmd.equals(EDGESIZE)) {
        if (viewer != null) {
            JCheckBoxMenuItem item = (JCheckBoxMenuItem) ae.getSource();
            if (item.isSelected())
                AppearanceSynchronizer.loadEdgeSize(viewer.getONDEXJUNGGraph(), viewer.getEdgeStrokes());
            else
                viewer.getEdgeStrokes().setEdgeSizes(null);
            // notify model of change
            viewer.getVisualizationViewer().getModel().fireStateChanged();
        }
    } else // toggle mouse over for current viewer
    if (cmd.equals(SHOWMOUSEOVER)) {
        if (viewer != null) {
            JCheckBoxMenuItem item = (JCheckBoxMenuItem) ae.getSource();
            OVTK2GraphMouse mouse = (OVTK2GraphMouse) viewer.getVisualizationViewer().getGraphMouse();
            OVTK2PickingMousePlugin picking = mouse.getOVTK2PickingMousePlugin();
            if (picking != null)
                picking.setShowMouseOver(item.isSelected());
        }
    } else // sync node positions to Attribute
    if (cmd.equals(SAVEAPPEARANCE)) {
        if (viewer != null) {
            AppearanceSynchronizer.saveAppearance(viewer);
        }
    } else // toggle edge arrows
    if (cmd.equals("edgearrow")) {
        if (viewer != null) {
            boolean selected = ((JCheckBoxMenuItem) ae.getSource()).isSelected();
            viewer.getEdgeArrows().setShowArrow(selected);
            // notify model of change
            viewer.getVisualizationViewer().getModel().fireStateChanged();
        }
    } else // toggle node label visibility
    if (cmd.equals("nodelabels")) {
        if (viewer != null) {
            boolean selected = ((JCheckBoxMenuItem) ae.getSource()).isSelected();
            viewer.setShowNodeLabels(selected);
        }
    } else // toggle edge label visibility
    if (cmd.equals("edgelabels")) {
        if (viewer != null) {
            boolean selected = ((JCheckBoxMenuItem) ae.getSource()).isSelected();
            viewer.setShowEdgeLabels(selected);
        }
    } else // toggle both label visibility
    if (cmd.equals("bothlabels")) {
        if (viewer != null) {
            boolean selected = ((JCheckBoxMenuItem) ae.getSource()).isSelected();
            viewer.setShowNodeLabels(selected);
            viewer.setShowEdgeLabels(selected);
        }
    } else // centre graph
    if (cmd.equals("center")) {
        if (viewer != null) {
            viewer.center();
        }
    } else // toggle anti-aliased painting
    if (cmd.equals("antialiased")) {
        if (viewer != null) {
            boolean selected = ((JCheckBoxMenuItem) ae.getSource()).isSelected();
            viewer.setAntiAliased(selected);
        }
    } else // updates all graphical graph settings
    if (cmd.equals("update")) {
        if (viewer != null) {
            viewer.updateViewer(null);
        }
    } else // change colour selection strategy
    if (cmd.startsWith("Menu.Appearance.Default.")) {
        if (viewer != null) {
            boolean selected = ((JRadioButtonMenuItem) ae.getSource()).isSelected();
            if (selected) {
                if (cmd.equals(COLOR_CONCEPT_BY_SOURCE))
                    viewer.getNodeColors().setFillPaintSelection(ONDEXNodeFillPaint.NodeFillPaintSelection.DATASOURCE);
                else if (cmd.equals(COLOR_CONCEPT_BY_CLASS))
                    viewer.getNodeColors().setFillPaintSelection(ONDEXNodeFillPaint.NodeFillPaintSelection.CONCEPTCLASS);
                else if (cmd.equals(COLOR_CONCEPT_BY_EVIDENCE))
                    viewer.getNodeColors().setFillPaintSelection(ONDEXNodeFillPaint.NodeFillPaintSelection.EVIDENCETYPE);
                else if (cmd.equals(COLOR_RELATION_BY_TYPE))
                    viewer.getEdgeColors().setEdgeColorSelection(ONDEXEdgeColors.EdgeColorSelection.RELATIONTYPE);
                else if (cmd.equals(COLOR_RELATION_BY_EVIDECE))
                    viewer.getEdgeColors().setEdgeColorSelection(ONDEXEdgeColors.EdgeColorSelection.EVIDENCETYPE);
                else if (cmd.equals(SHAPE_QUAD))
                    viewer.getEdgeShapes().setEdgeShape(EdgeShape.QUAD);
                else if (cmd.equals(SHAPE_CUBIC))
                    viewer.getEdgeShapes().setEdgeShape(EdgeShape.CUBIC);
                else if (cmd.equals(SHAPE_BENT))
                    viewer.getEdgeShapes().setEdgeShape(EdgeShape.BENT);
                else if (cmd.equals(SHAPE_LINE))
                    viewer.getEdgeShapes().setEdgeShape(EdgeShape.LINE);
                else
                    System.err.println("Command is not understood " + cmd);
                viewer.updateViewer(null);
            }
        }
    }
}
Also used : OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) OVTK2ResourceAssesor(net.sourceforge.ondex.ovtk2.ui.OVTK2ResourceAssesor) OVTK2PickingMousePlugin(net.sourceforge.ondex.ovtk2.ui.mouse.OVTK2PickingMousePlugin) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) OVTK2GraphMouse(net.sourceforge.ondex.ovtk2.ui.mouse.OVTK2GraphMouse) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) OVTK2Viewer(net.sourceforge.ondex.ovtk2.ui.OVTK2Viewer)

Aggregations

OVTK2Viewer (net.sourceforge.ondex.ovtk2.ui.OVTK2Viewer)26 OVTK2Desktop (net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop)24 PropertyVetoException (java.beans.PropertyVetoException)17 ONDEXConcept (net.sourceforge.ondex.core.ONDEXConcept)16 OVTK2ResourceAssesor (net.sourceforge.ondex.ovtk2.ui.OVTK2ResourceAssesor)14 ONDEXRelation (net.sourceforge.ondex.core.ONDEXRelation)11 FileNotFoundException (java.io.FileNotFoundException)9 ActionEvent (java.awt.event.ActionEvent)8 MalformedURLException (java.net.MalformedURLException)8 ONDEXJUNGGraph (net.sourceforge.ondex.ovtk2.graph.ONDEXJUNGGraph)7 AttributeName (net.sourceforge.ondex.core.AttributeName)6 IndeterminateProcessAdapter (net.sourceforge.ondex.tools.threading.monitoring.IndeterminateProcessAdapter)6 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)5 OVTK2GraphMouse (net.sourceforge.ondex.ovtk2.ui.mouse.OVTK2GraphMouse)5 File (java.io.File)4 JInternalFrame (javax.swing.JInternalFrame)4 RegisteredJInternalFrame (net.sourceforge.ondex.ovtk2.ui.RegisteredJInternalFrame)4 ArrayList (java.util.ArrayList)3 ONDEXGraph (net.sourceforge.ondex.core.ONDEXGraph)3 OVTK2PropertiesAggregator (net.sourceforge.ondex.ovtk2.ui.OVTK2PropertiesAggregator)3