Reading features files readded as ref to FeatureRenderer is required
authoramwaterhouse <Andrew Waterhouse>
Fri, 3 Feb 2006 17:41:43 +0000 (17:41 +0000)
committeramwaterhouse <Andrew Waterhouse>
Fri, 3 Feb 2006 17:41:43 +0000 (17:41 +0000)
src/jalview/gui/AlignFrame.java

index 5685e42..de2d3d1 100755 (executable)
@@ -770,6 +770,8 @@ public class AlignFrame
     }\r
     catch (Exception ex)\r
     {\r
+      ex.printStackTrace();\r
+        System.out.println("Exception whilst pasting: "+ex);\r
         // could be anything being pasted in here\r
     }\r
 \r
@@ -1123,6 +1125,8 @@ public class AlignFrame
    if(alignPanel.overviewPanel!=null)\r
      alignPanel.overviewPanel.updateOverviewImage();\r
 \r
+   viewport.alignment.adjustSequenceAnnotations();\r
+\r
    alignPanel.repaint();\r
  }\r
 \r
@@ -2533,17 +2537,73 @@ public void showTranslation_actionPerformed(ActionEvent e)
  */\r
 public boolean parseGroupsFile(String file)\r
 {\r
-  AnnotationReader ar = new AnnotationReader();\r
+    try\r
+    {\r
+      BufferedReader in = new BufferedReader(new FileReader(file));\r
+      SequenceI seq = null;\r
+      String line, type, desc, token;\r
+\r
+      int index, start, end;\r
+      StringTokenizer st;\r
+      SequenceFeature sf;\r
+      int lineNo = 0;\r
+      while ( (line = in.readLine()) != null)\r
+      {\r
+        lineNo++;\r
+        st = new StringTokenizer(line, "\t");\r
+        if (st.countTokens() == 2)\r
+        {\r
+          type = st.nextToken();\r
+          UserColourScheme ucs = new UserColourScheme(st.nextToken());\r
+          alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(type, ucs.findColour("A"));\r
+          continue;\r
+        }\r
+\r
+        while (st.hasMoreElements())\r
+        {\r
+          desc = st.nextToken();\r
+          token = st.nextToken();\r
+          if (!token.equals("ID_NOT_SPECIFIED"))\r
+          {\r
+            index = viewport.alignment.findIndex(viewport.alignment.findName(token));\r
+            st.nextToken();\r
+          }\r
+          else\r
+          {\r
+            index = Integer.parseInt(st.nextToken());\r
+          }\r
+\r
+          start = Integer.parseInt(st.nextToken());\r
+          end = Integer.parseInt(st.nextToken());\r
+\r
+          seq = viewport.alignment.getSequenceAt(index);\r
+          start = seq.findIndex(start) - 1;\r
+          end = seq.findIndex(end) - 1;\r
+\r
+          type = st.nextToken();\r
+\r
+          if (alignPanel.seqPanel.seqCanvas.getFeatureRenderer().getColour(type) == null)\r
+          {\r
+            // Probably the old style groups file\r
+            UserColourScheme ucs = new UserColourScheme(type);\r
+            alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour(type, ucs.findColour("A"));\r
+          }\r
+\r
+          sf = new SequenceFeature(type, desc, "", start, end);\r
+\r
+          seq.getDatasetSequence().addSequenceFeature(sf);\r
+        }\r
+      }\r
+    }\r
+    catch (Exception ex)\r
+    {\r
+      System.out.println("Error parsing groups file: " + ex);\r
+      return false;\r
+    }\r
 \r
-  if (ar.readGroupsFile(alignPanel.seqPanel.seqCanvas.getFeatureRenderer(),\r
-                        viewport.alignment, file))\r
-  {\r
     viewport.showSequenceFeatures = true;\r
     alignPanel.repaint();\r
     return true;\r
-  }\r
-  else\r
-    return false;\r
 }\r
 \r
 public void dragEnter(DropTargetDragEvent evt)\r
@@ -2603,23 +2663,48 @@ public void drop(DropTargetDropEvent evt)
 \r
     if (files != null)\r
     {\r
-      AnnotationReader ar = new AnnotationReader();\r
       try\r
       {\r
+        boolean isAnnotation = false;\r
+\r
         for (int i = 0; i < files.size(); i++)\r
         {\r
           String file = files.get(i).toString();\r
-          if(! ar.readAnnotationFile(viewport.alignment, file) )\r
-            parseGroupsFile(file);\r
-          else\r
+\r
+          isAnnotation = new AnnotationReader().readAnnotationFile(viewport.alignment, file);\r
+\r
+          if( !isAnnotation )\r
           {\r
+            boolean isGroupsFile = parseGroupsFile(file);\r
+            if (!isGroupsFile)\r
+            {\r
+              String protocol = "File";\r
+              String format = jalview.io.IdentifyFile.Identify(file, protocol);\r
+              SequenceI[] sequences = new FormatAdapter().readFile(file, protocol, format);\r
 \r
+              FastaFile ff = new FastaFile();\r
+              Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();\r
+              c.setContents(new StringSelection(ff.print(sequences)), this);\r
+\r
+              this.paste(false);\r
+\r
+            }\r
           }\r
         }\r
 \r
-        alignPanel.annotationPanel.adjustPanelHeight();\r
-        alignPanel.annotationScroller.validate();\r
-        alignPanel.repaint();\r
+        if(isAnnotation)\r
+        {\r
+          int height = alignPanel.annotationPanel.adjustPanelHeight();\r
+          alignPanel.annotationScroller.setPreferredSize(\r
+              new Dimension(alignPanel.annotationScroller.getWidth(),\r
+                            height));\r
+\r
+          alignPanel.annotationSpaceFillerHolder.setPreferredSize(new Dimension(\r
+              alignPanel.annotationSpaceFillerHolder.getWidth(),\r
+              height));\r
+\r
+          alignPanel.addNotify();\r
+        }\r
       }\r
       catch (Exception ex)\r
       {\r