Search in sources :

Example 1 with ONDEXJUNGGraph

use of net.sourceforge.ondex.ovtk2.graph.ONDEXJUNGGraph in project knetbuilder by Rothamsted.

the class OVTK2DefaultModalGraphMouse method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    // current graph
    ONDEXJUNGGraph graph = this.viewer.getONDEXJUNGGraph();
    // gain access to current plugin
    OVTK2AnnotatingGraphMousePlugin plugin = (OVTK2AnnotatingGraphMousePlugin) this.annotatingPlugin;
    // keeps track of annotations
    AnnotationManager manager = plugin.getAnnotationMananger();
    // pass annotations to AnnotationControls
    if (cmd.equals("load") && graph.getAnnotations() != null && graph.getAnnotations().containsKey(KEY)) {
        // get current annotation from graph
        String xml = graph.getAnnotations().get(KEY);
        if (xml == null || xml.trim().length() == 0)
            return;
        // will contain de-serialised annotations
        Set<Annotation> annos = new HashSet<Annotation>();
        // configure XML input
        System.setProperty("ondex.javax.xml.stream.XMLInputFactory", "com.ctc.wstx.stax.WstxInputFactory");
        XMLInputFactory2 xmlInput = (XMLInputFactory2) XMLInputFactory2.newFactory("ondex.javax.xml.stream.XMLInputFactory", this.getClass().getClassLoader());
        xmlInput.configureForSpeed();
        // parse from a String
        final ByteArrayInputStream inStream = new ByteArrayInputStream(xml.getBytes());
        try {
            // configure Parser
            XMLStreamReader2 xmlReadStream = (XMLStreamReader2) xmlInput.createXMLStreamReader(inStream, CharsetNames.CS_UTF8);
            // de-serialise annotations from XML
            AnnotationXMLReader.read(xmlReadStream, annos);
            xmlReadStream.close();
        } catch (XMLStreamException e1) {
            ErrorDialog.show(e1);
        }
        // add all annotations to manager
        for (Annotation anno : annos) {
            manager.add(anno.getLayer(), anno);
        }
        // update visualisation
        viewer.getVisualizationViewer().fireStateChanged();
        viewer.getVisualizationViewer().repaint();
    } else // get annotations from AnnotationControls
    if (cmd.equals("save")) {
        // annotations of lower layer
        AnnotationPaintable lower = manager.getAnnotationPaintable(Annotation.Layer.LOWER);
        // annotations of upper layer
        AnnotationPaintable upper = manager.getAnnotationPaintable(Annotation.Layer.UPPER);
        // all annotations of lower layer
        Set<Annotation> annos = new HashSet<Annotation>(lower.getAnnotations());
        // all annotations of upper layer
        annos.addAll(upper.getAnnotations());
        // configure XML output
        System.setProperty("ondex.javax.xml.stream.XMLOutputFactory", "com.ctc.wstx.stax.WstxOutputFactory");
        XMLOutputFactory2 xmlOutput = (XMLOutputFactory2) XMLOutputFactory2.newFactory("ondex.javax.xml.stream.XMLOutputFactory", this.getClass().getClassLoader());
        xmlOutput.configureForSpeed();
        xmlOutput.setProperty(XMLOutputFactory2.IS_REPAIRING_NAMESPACES, false);
        // output goes into a String
        final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        try {
            // configure writer
            XMLStreamWriter2 xmlWriteStream = (XMLStreamWriter2) xmlOutput.createXMLStreamWriter(outStream, CharsetNames.CS_UTF8);
            // serialise Annotations to XML
            AnnotationXMLWriter.write(xmlWriteStream, annos);
            xmlWriteStream.flush();
            xmlWriteStream.close();
            // set annotation data to graph
            graph.getAnnotations().put(KEY, outStream.toString());
        } catch (XMLStreamException e1) {
            ErrorDialog.show(e1);
        }
    }
}
Also used : AnnotationManager(edu.uci.ics.jung.visualization.annotations.AnnotationManager) HashSet(java.util.HashSet) Set(java.util.Set) AnnotationPaintable(edu.uci.ics.jung.visualization.annotations.AnnotationPaintable) XMLStreamReader2(org.codehaus.stax2.XMLStreamReader2) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Annotation(edu.uci.ics.jung.visualization.annotations.Annotation) XMLOutputFactory2(org.codehaus.stax2.XMLOutputFactory2) XMLStreamWriter2(org.codehaus.stax2.XMLStreamWriter2) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLInputFactory2(org.codehaus.stax2.XMLInputFactory2) ONDEXJUNGGraph(net.sourceforge.ondex.ovtk2.graph.ONDEXJUNGGraph) HashSet(java.util.HashSet)

Example 2 with ONDEXJUNGGraph

use of net.sourceforge.ondex.ovtk2.graph.ONDEXJUNGGraph in project knetbuilder by Rothamsted.

the class VisualisationExtension method showContextMembers.

/**
 * Shows all of the members of context(s) selected in the viewer
 *
 * @param viewer
 */
public static void showContextMembers(OVTK2PropertiesAggregator viewer) {
    ONDEXJUNGGraph graph = viewer.getONDEXJUNGGraph();
    for (ONDEXConcept contextConcept : viewer.getPickedNodes().toArray(new ONDEXConcept[0])) {
        graph.setVisibility(graph.getConceptsOfTag(contextConcept), true);
        graph.setVisibility(graph.getRelationsOfTag(contextConcept), true);
    }
}
Also used : ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) ONDEXJUNGGraph(net.sourceforge.ondex.ovtk2.graph.ONDEXJUNGGraph)

Example 3 with ONDEXJUNGGraph

use of net.sourceforge.ondex.ovtk2.graph.ONDEXJUNGGraph in project knetbuilder by Rothamsted.

the class VisualisationExtension method showConnectingRelations.

/**
 * Makes all of the relations visible, if their target and source are
 * currently visible
 */
public static void showConnectingRelations(OVTK2PropertiesAggregator viewer) {
    ONDEXJUNGGraph graph = viewer.getONDEXJUNGGraph();
    for (ONDEXRelation r : graph.getRelations()) {
        ONDEXConcept c1 = r.getFromConcept();
        ONDEXConcept c2 = r.getToConcept();
        if (graph.isVisible(c1) && graph.isVisible(c2)) {
            graph.setVisibility(r, true);
        }
    }
    viewer.updateViewer(null);
}
Also used : ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) ONDEXJUNGGraph(net.sourceforge.ondex.ovtk2.graph.ONDEXJUNGGraph) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation)

Example 4 with ONDEXJUNGGraph

use of net.sourceforge.ondex.ovtk2.graph.ONDEXJUNGGraph in project knetbuilder by Rothamsted.

the class VisualizationHandler method processingFinished.

/*
	 * (non-Javadoc)
	 * 
	 * @see net.sourceforge.ondex.ovtk2.ui.scripting.ProcessingCheckpoint#
	 * processingFinished()
	 */
public synchronized void processingFinished() {
    try {
        for (Entry<OVTK2PropertiesAggregator, ONDEXJUNGGraph> ent : graphs.entrySet()) {
            OVTK2ResourceAssesor resources = OVTK2Desktop.getDesktopResources();
            // put graph into viewer
            // OVTK2PropertiesAggregator viewer =
            // DesktopUtils.initViewer(ent.getValue());
            OVTK2PropertiesAggregator viewer = ent.getKey();
            // set viewer as active viewer
            resources.setSelectedViewer(viewer);
            // decide when to display viewer immediately
            if (Math.max(ent.getValue().getConcepts().size(), ent.getValue().getRelations().size()) < 2000) {
                // we can display everything here
                viewer.getONDEXJUNGGraph().setEverythingVisible();
            // make sure layout is set
            // VisualisationUtils.relayout(viewer);
            }
            // update all visual attributes of graph
            viewer.updateViewer(null);
            if (viewer instanceof OVTK2Viewer) {
                ((OVTK2Viewer) viewer).getMetaGraph().updateMetaData();
                try {
                    ((OVTK2Viewer) viewer).setSelected(true);
                } catch (PropertyVetoException e) {
                    ErrorDialog.show(e);
                }
            }
            // update UI
            viewer.getVisualizationViewer().fireStateChanged();
            viewer.getVisualizationViewer().repaint();
        // hack to show meta graph
        // JCheckBoxMenuItem item = new JCheckBoxMenuItem();
        // item.setSelected(true);
        // desktop.actionPerformed(new ActionEvent(item,
        // ActionEvent.ACTION_PERFORMED, "metagraph"));
        // ((ActionListener)v).actionPerformed(new
        // ActionEvent(this,0,"refresh"));
        // v.getJUNGGraph().addActionListener((ActionListener)v);
        }
        graphs.clear();
    // OVTK2PropertiesAggregator v =
    // OVTK2Desktop.getInstance().getDesktopResources().getSelectedViewer();
    // v.setMaximizable(true);
    // v.setIconifiable(true);
    // if(state.containsKey(v))
    // v.setIcon(state.remove(v));
    // OVTK-206
    // VisualisationUtils.relayout(v);
    // v.center();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) OVTK2ResourceAssesor(net.sourceforge.ondex.ovtk2.ui.OVTK2ResourceAssesor) OVTK2PropertiesAggregator(net.sourceforge.ondex.ovtk2.ui.OVTK2PropertiesAggregator) ONDEXJUNGGraph(net.sourceforge.ondex.ovtk2.graph.ONDEXJUNGGraph) OVTK2Viewer(net.sourceforge.ondex.ovtk2.ui.OVTK2Viewer) PropertyVetoException(java.beans.PropertyVetoException)

Example 5 with ONDEXJUNGGraph

use of net.sourceforge.ondex.ovtk2.graph.ONDEXJUNGGraph in project knetbuilder by Rothamsted.

the class ONDEXMetaGraphPanel method initVisviewer.

/**
 * Creates JUNG visualization of metagraph.
 */
private void initVisviewer() {
    ONDEXJUNGGraph jung = viewer.getONDEXJUNGGraph();
    // new metagraph viewer
    layout = new KKLayout<ONDEXMetaConcept, ONDEXMetaRelation>(meta);
    visviewer = new VisualizationViewer<ONDEXMetaConcept, ONDEXMetaRelation>(layout, preferredSize);
    visviewer.setDoubleBuffered(true);
    visviewer.setBackground(Color.white);
    // set label position and label transformer
    visviewer.getRenderer().getVertexLabelRenderer().setPosition(Position.AUTO);
    visviewer.getRenderContext().setVertexLabelTransformer(new ONDEXMetaConceptLabels(jung));
    visviewer.getRenderContext().setEdgeLabelTransformer(new ONDEXMetaRelationLabels(jung));
    // set visible attribute renderer
    visviewer.getRenderContext().setEdgeDrawPaintTransformer(new ONDEXMetaRelationColors(jung, visviewer.getPickedEdgeState()));
    visviewer.getRenderContext().setVertexShapeTransformer(new ONDEXMetaConceptShapes(jung));
    // visviewer.getRenderContext().setVertexDrawPaintTransformer(
    // new ONDEXMetaConceptColors( aog));
    visviewer.getRenderContext().setVertexFillPaintTransformer(new ONDEXMetaConceptColors(jung, visviewer.getPickedVertexState()));
    visviewer.getRenderContext().setEdgeArrowPredicate(new ONDEXMetaRelationArrows(jung));
    visviewer.getRenderContext().setEdgeStrokeTransformer(new ONDEXMetaRelationStrokes(jung));
    // set antialiasing painting on
    Map<?, ?> temp = visviewer.getRenderingHints();
    // copying necessary because of typesafety
    Iterator<?> it = temp.keySet().iterator();
    while (it.hasNext()) {
        RenderingHints.Key key = (RenderingHints.Key) it.next();
        hints.put(key, temp.get(key));
    }
    hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    visviewer.setRenderingHints(hints);
    // standard mouse support
    DefaultModalGraphMouse<ONDEXMetaConcept, ONDEXMetaRelation> graphMouse = new DefaultModalGraphMouse<ONDEXMetaConcept, ONDEXMetaRelation>();
    // Trying out our new popup menu mouse producer...
    PopupVertexEdgeMenuMousePlugin<ONDEXMetaConcept, ONDEXMetaRelation> myPlugin = new PopupVertexEdgeMenuMousePlugin<ONDEXMetaConcept, ONDEXMetaRelation>();
    // Add some popup menus for the edges and vertices to our mouse
    // producer.
    JPopupMenu edgeMenu = new MetaRelationMenu(viewer);
    JPopupMenu vertexMenu = new MetaConceptMenu(viewer);
    myPlugin.setEdgePopup(edgeMenu);
    myPlugin.setVertexPopup(vertexMenu);
    // Add our new producer to the mouse
    graphMouse.add(myPlugin);
    visviewer.setGraphMouse(graphMouse);
    visviewer.addKeyListener(graphMouse.getModeKeyListener());
    // zoom pane and mouse menu in the corner
    GraphZoomScrollPane scrollPane = new GraphZoomScrollPane(visviewer);
    JMenuBar menu = new JMenuBar();
    menu.add(graphMouse.getModeMenu());
    scrollPane.setCorner(menu);
    // set graph mode to picking
    graphMouse.setMode(Mode.PICKING);
    // button panel
    JPanel buttons = new JPanel();
    BoxLayout buttons_layout = new BoxLayout(buttons, BoxLayout.LINE_AXIS);
    buttons.setLayout(buttons_layout);
    // metadata legend button
    JButton legend = new JButton(Config.language.getProperty("MetaGraph.MetaDataLegend"));
    legend.addActionListener(this);
    legend.setActionCommand("legend");
    buttons.add(legend);
    // metadata legend button
    JButton mainGraph = new JButton(Config.language.getProperty("MetaGraph.ShowMainGraph"));
    mainGraph.addActionListener(this);
    mainGraph.setActionCommand("mainGraph");
    buttons.add(mainGraph);
    // make sure that the layout has actually finished
    while (!layout.done()) {
        layout.step();
    }
    // add to content pane
    this.add(scrollPane, BorderLayout.CENTER);
    this.add(buttons, BorderLayout.SOUTH);
    this.revalidate();
    this.scaleToFit();
    this.addComponentListener(this);
}
Also used : JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) RenderingHints(java.awt.RenderingHints) ONDEXJUNGGraph(net.sourceforge.ondex.ovtk2.graph.ONDEXJUNGGraph) MetaConceptMenu(net.sourceforge.ondex.ovtk2.ui.popup.MetaConceptMenu) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) PopupVertexEdgeMenuMousePlugin(net.sourceforge.ondex.ovtk2.ui.popup.PopupVertexEdgeMenuMousePlugin) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) JPopupMenu(javax.swing.JPopupMenu) MetaRelationMenu(net.sourceforge.ondex.ovtk2.ui.popup.MetaRelationMenu) JMenuBar(javax.swing.JMenuBar)

Aggregations

ONDEXJUNGGraph (net.sourceforge.ondex.ovtk2.graph.ONDEXJUNGGraph)51 ONDEXConcept (net.sourceforge.ondex.core.ONDEXConcept)38 ONDEXRelation (net.sourceforge.ondex.core.ONDEXRelation)27 HashSet (java.util.HashSet)18 AttributeName (net.sourceforge.ondex.core.AttributeName)14 ONDEXGraphMetaData (net.sourceforge.ondex.core.ONDEXGraphMetaData)10 ConceptClass (net.sourceforge.ondex.core.ConceptClass)9 Attribute (net.sourceforge.ondex.core.Attribute)8 JComboBox (javax.swing.JComboBox)7 ActionEvent (java.awt.event.ActionEvent)6 HashMap (java.util.HashMap)6 JCheckBox (javax.swing.JCheckBox)6 JLabel (javax.swing.JLabel)6 PropertyVetoException (java.beans.PropertyVetoException)5 Set (java.util.Set)5 ActionListener (java.awt.event.ActionListener)4 JTextField (javax.swing.JTextField)4 ONDEXGraph (net.sourceforge.ondex.core.ONDEXGraph)4 RelationType (net.sourceforge.ondex.core.RelationType)4 Container (java.awt.Container)3