From 528dcd143968fc270232e4cec64a79b447aa5ec6 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 3 Jul 2015 11:07:23 +0100 Subject: [PATCH] JAL-892 1 second delay for correct initial rendering; code tidy up --- src/jalview/ext/varna/RnaModel.java | 13 +--- src/jalview/gui/AppVarna.java | 134 +++++++++++++++++++--------------- src/jalview/gui/AppVarnaBinding.java | 75 ++----------------- src/jalview/gui/Jalview2XML.java | 83 +++++++++++---------- 4 files changed, 125 insertions(+), 180 deletions(-) diff --git a/src/jalview/ext/varna/RnaModel.java b/src/jalview/ext/varna/RnaModel.java index 44c6cf6..b39ea94 100644 --- a/src/jalview/ext/varna/RnaModel.java +++ b/src/jalview/ext/varna/RnaModel.java @@ -1,10 +1,10 @@ package jalview.ext.varna; -import fr.orsay.lri.varna.models.rna.RNA; - import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.SequenceI; +import fr.orsay.lri.varna.models.rna.RNA; + /** * Data bean wrapping the data items that define one RNA view */ @@ -20,18 +20,13 @@ public class RnaModel public final RNA rna; - // path to a file holding VARNA session state XML - public final String varnaSession; - public RnaModel(String t, AlignmentAnnotation aa, SequenceI s, RNA r, - boolean g, - String sessionFile) + boolean g) { title = t; ann = aa; seq = s; - gapped = g; rna = r; - varnaSession = sessionFile; + gapped = g; } } \ No newline at end of file diff --git a/src/jalview/gui/AppVarna.java b/src/jalview/gui/AppVarna.java index beb4980..dcb2a7d 100644 --- a/src/jalview/gui/AppVarna.java +++ b/src/jalview/gui/AppVarna.java @@ -20,9 +20,24 @@ */ package jalview.gui; +import jalview.analysis.AlignSeq; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.RnaViewerModel; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.ext.varna.RnaModel; +import jalview.structure.SecondaryStructureListener; +import jalview.structure.SelectionListener; +import jalview.structure.SelectionSource; +import jalview.structure.StructureSelectionManager; +import jalview.structure.VamsasSource; +import jalview.util.Comparison; +import jalview.util.MessageManager; +import jalview.util.ShiftList; + import java.awt.BorderLayout; import java.awt.Color; -import java.lang.reflect.InvocationTargetException; import java.util.Collection; import java.util.Hashtable; import java.util.LinkedHashMap; @@ -47,22 +62,6 @@ import fr.orsay.lri.varna.models.annotations.HighlightRegionAnnotation; import fr.orsay.lri.varna.models.rna.ModeleBase; import fr.orsay.lri.varna.models.rna.RNA; -import jalview.analysis.AlignSeq; -import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.ColumnSelection; -import jalview.datamodel.RnaViewerModel; -import jalview.datamodel.SequenceGroup; -import jalview.datamodel.SequenceI; -import jalview.ext.varna.RnaModel; -import jalview.structure.SecondaryStructureListener; -import jalview.structure.SelectionListener; -import jalview.structure.SelectionSource; -import jalview.structure.StructureSelectionManager; -import jalview.structure.VamsasSource; -import jalview.util.Comparison; -import jalview.util.MessageManager; -import jalview.util.ShiftList; - public class AppVarna extends JInternalFrame implements SelectionListener, SecondaryStructureListener, InterfaceVARNASelectionListener, VamsasSource @@ -189,17 +188,16 @@ public class AppVarna extends JInternalFrame implements SelectionListener, setTitle(theTitle); String gappedTitle = sname + " (with gaps)"; - RnaModel gappedModel = new RnaModel(gappedTitle, aa, seq, null, true, - null); + RnaModel gappedModel = new RnaModel(gappedTitle, aa, seq, null, true); addModel(gappedModel, gappedTitle); String trimmedTitle = "trimmed " + sname; - RnaModel trimmedModel = new RnaModel(trimmedTitle, aa, seq, null, - false, null); + RnaModel trimmedModel = new RnaModel(trimmedTitle, aa, seq, null, false); addModel(trimmedModel, trimmedTitle); vab.setSelectedIndex(0); } + /** * Constructor that links the viewer to a parent panel (but has no structures * yet - use addModel to add them) @@ -405,14 +403,6 @@ public class AppVarna extends JInternalFrame implements SelectionListener, if (rnaModel.seq == sequence) { int highlightPos = rnaModel.gapped ? index : position - 1; - // int highlightPos = index; - // ShiftList shift = offsets.get(rna); - // if (shift != null) - // { - // System.err.print("Orig pos:" + index); - // highlightPos = shift.shift(index); - // System.err.println("\nFinal pos:" + index); - // } mouseOverHighlighter.highlightRegion(rna, highlightPos, highlightPos); vab.updateSelectedRNA(rna); } @@ -600,34 +590,6 @@ public class AppVarna extends JInternalFrame implements SelectionListener, } /* - * loaded from project file with Varna session data - */ - if (model.varnaSession != null) - { - try - { - FullBackup fromSession = vab.vp.loadSession(model.varnaSession); - vab.addStructure(fromSession.rna, fromSession.config); - RNA rna = fromSession.rna; - // copy the model, but now including the RNA object - RnaModel newModel = new RnaModel(model.title, model.ann, model.seq, - rna, model.gapped, model.varnaSession); - if (!model.gapped) - { - registerOffset(rna, buildOffset(model.seq)); - } - models.put(rna, newModel); - // capture rna selection state when saved - selectionHighlighter = new VarnaHighlighter(rna); - return fromSession.rna; - } catch (ExceptionLoadingFailed e) - { - e.printStackTrace(); - return null; - } - } - - /* * opened on request in Jalview session */ RNA rna = new RNA(modelName); @@ -651,7 +613,7 @@ public class AppVarna extends JInternalFrame implements SelectionListener, rna = trimRNA(rna, modelName); } models.put(rna, new RnaModel(modelName, model.ann, model.seq, rna, - model.gapped, null)); + model.gapped)); vab.addStructure(rna); return rna; } @@ -701,10 +663,64 @@ public class AppVarna extends JInternalFrame implements SelectionListener, /** * Set the selected index in the model selection list * - * @param selectedR + * @param selectedIndex */ public void setInitialSelection(final int selectedIndex) { + /* + * empirically it needs a second for Varna/AWT to finish loading/drawing + * models for this to work; SwingUtilities.invokeLater _not_ a solution; + * explanation and/or better solution welcome! + */ + synchronized (this) + { + try + { + wait(1000); + } catch (InterruptedException e) + { + // meh + } + } vab.setSelectedIndex(selectedIndex); } + + + /** + * Add a model with associated Varna session file + * + * @param rna + * @param modelName + */ + public RNA addModelSession(RnaModel model, String modelName, + String sessionFile) + { + if (!model.ann.isValidStruc()) + { + throw new IllegalArgumentException("Invalid RNA structure annotation"); + } + + try + { + FullBackup fromSession = vab.vp.loadSession(sessionFile); + vab.addStructure(fromSession.rna, fromSession.config); + RNA rna = fromSession.rna; + // copy the model, but now including the RNA object + RnaModel newModel = new RnaModel(model.title, model.ann, model.seq, + rna, model.gapped); + if (!model.gapped) + { + registerOffset(rna, buildOffset(model.seq)); + } + models.put(rna, newModel); + // capture rna selection state when saved + selectionHighlighter = new VarnaHighlighter(rna); + return fromSession.rna; + } catch (ExceptionLoadingFailed e) + { + System.err + .println("Error restoring Varna session: " + e.getMessage()); + return null; + } + } } diff --git a/src/jalview/gui/AppVarnaBinding.java b/src/jalview/gui/AppVarnaBinding.java index 956c2e1..25af7d1 100644 --- a/src/jalview/gui/AppVarnaBinding.java +++ b/src/jalview/gui/AppVarnaBinding.java @@ -20,6 +20,11 @@ */ package jalview.gui; +import jalview.datamodel.SequenceI; +import jalview.ext.varna.JalviewVarnaBinding; +import jalview.structure.AtomSpec; +import jalview.util.MessageManager; + import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; @@ -59,38 +64,10 @@ import fr.orsay.lri.varna.models.FullBackup; import fr.orsay.lri.varna.models.VARNAConfig; import fr.orsay.lri.varna.models.rna.RNA; -import jalview.datamodel.SequenceI; -import jalview.ext.varna.JalviewVarnaBinding; -import jalview.structure.AtomSpec; -import jalview.util.MessageManager; - public class AppVarnaBinding extends JalviewVarnaBinding { public VARNAPanel vp; - // remove unused (commented out) fields? - // protected JPanel _tools = new JPanel(); - // - // private JPanel _input = new JPanel(); - // - // private JPanel _strPanel = new JPanel(); - // - // private JTextField _str = new JTextField(); - // - // private JTextField _seq = new JTextField(); - // - // private JLabel _strLabel = new JLabel( - // MessageManager.getString("label.str")); - // - // private JButton _updateButton = new JButton( - // MessageManager.getString("action.update")); - // - // private JButton _deleteButton = new JButton( - // MessageManager.getString("action.delete")); - // - // private JButton _duplicateButton = new JButton( - // MessageManager.getString("action.snapshot")); - // protected JPanel _listPanel = new JPanel(); private ReorderableJList _sideList = null; @@ -165,48 +142,6 @@ public class AppVarnaBinding extends JalviewVarnaBinding vp.setBackground(_backgroundColor); - // MC commented out stuff not added to panel - remove? - // Font textFieldsFont = Font.decode("MonoSpaced-PLAIN-12"); - // - // _seq.setFont(textFieldsFont); - // if (!rnaList.isEmpty()) - // { - // _seq.setText(rnaList.get(0).getSeq()); - // } - - // _updateButton.addActionListener(new ActionListener() - // { - // public void actionPerformed(ActionEvent e) - // { - // FullBackup sel = (FullBackup) _sideList.getSelectedValue(); - // sel.rna.setSequence("A"); - // } - // }); - // - // _strLabel.setPreferredSize(new Dimension(marginTools, 15)); - // _strLabel.setHorizontalTextPosition(JLabel.LEFT); - // _str.setFont(textFieldsFont); - // _strPanel.setLayout(new BorderLayout()); - // _strPanel.add(_strLabel, BorderLayout.WEST); - // _strPanel.add(_str, BorderLayout.CENTER); - // - // _input.setLayout(new GridLayout(1, 0)); - // _input.add(_strPanel); - // - // JPanel goPanel = new JPanel(); - // goPanel.setLayout(new BorderLayout()); - // - // _tools.setLayout(new BorderLayout()); - // _tools.add(_input, BorderLayout.CENTER); - // _tools.add(goPanel, BorderLayout.EAST); - // - // goPanel.add(_updateButton, BorderLayout.CENTER); - // - // JPanel ops = new JPanel(); - // ops.setLayout(new GridLayout(1, 2)); - // ops.add(_deleteButton); - // ops.add(_duplicateButton); - JLabel j = new JLabel( MessageManager.getString("label.structures_manager"), JLabel.CENTER); diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 62c9cad..be56292 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -20,45 +20,6 @@ */ package jalview.gui; -import java.awt.Rectangle; -import java.io.BufferedReader; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.lang.reflect.InvocationTargetException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.IdentityHashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.Vector; -import java.util.jar.JarEntry; -import java.util.jar.JarInputStream; -import java.util.jar.JarOutputStream; - -import javax.swing.JInternalFrame; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; - -import org.exolab.castor.xml.Marshaller; -import org.exolab.castor.xml.Unmarshaller; - import jalview.api.structures.JalviewStructureDisplayI; import jalview.bin.Cache; import jalview.datamodel.AlignedCodonFrame; @@ -128,6 +89,45 @@ import jalview.ws.params.ArgumentI; import jalview.ws.params.AutoCalcSetting; import jalview.ws.params.WsParamSetI; +import java.awt.Rectangle; +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.Vector; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; +import java.util.jar.JarOutputStream; + +import javax.swing.JInternalFrame; +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; + +import org.exolab.castor.xml.Marshaller; +import org.exolab.castor.xml.Unmarshaller; + /** * Write out the current jalview desktop state as a Jalview XML stream. * @@ -3344,9 +3344,8 @@ public class Jalview2XML String sessionState = ss.getViewerState(); String tempStateFile = copyJarEntry(jprovider, sessionState, "varna"); - RnaModel rna = new RnaModel(rnaTitle, ann, seq, null, gapped, - tempStateFile); - appVarna.addModel(rna, rnaTitle); + RnaModel rna = new RnaModel(rnaTitle, ann, seq, null, gapped); + appVarna.addModelSession(rna, rnaTitle, tempStateFile); } appVarna.setInitialSelection(viewer.getSelectedRna()); } -- 1.7.10.2