Dont export annotations if not visible
[jalview.git] / src / jalview / gui / AlignFrame.java
index 48758cd..1eb72e9 100755 (executable)
@@ -36,8 +36,6 @@ import jalview.schemes.*;
 import jalview.commands.*;
 import jalview.ws.*;
 import java.awt.dnd.*;
-import javax.swing.event.ChangeListener;
-import javax.swing.event.ChangeEvent;
 
 /**
  * DOCUMENT ME!
@@ -310,7 +308,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
               SequenceGroup sg = viewport.getSelectionGroup();
               if (toggleSeqs)
               {
-                if (sg != null && sg.getSize(false) != viewport.alignment.getHeight())
+                if (sg != null && sg.getSize() != viewport.alignment.getHeight())
                 {
                   hideSelSequences_actionPerformed(null);
                   hide = true;
@@ -472,6 +470,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
     idRightAlign.setSelected(av.rightAlignIds);
     renderGapsMenuItem.setSelected(av.renderGaps);
     wrapMenuItem.setSelected(av.wrapAlignment);
+    scaleAbove.setVisible(av.wrapAlignment);
+    scaleLeft.setVisible(av.wrapAlignment);
+    scaleRight.setVisible(av.wrapAlignment);
     annotationPanelMenuItem.setState(av.showAnnotation);
     viewBoxesMenuItem.setSelected(av.showBoxes);
     viewTextMenuItem.setSelected(av.showText);
@@ -825,6 +826,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
     alignPanel.makeEPS(f);
   }
 
+
+  public void pageSetup_actionPerformed(ActionEvent e)
+  {
+    PrinterJob printJob = PrinterJob.getPrinterJob();
+    PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
+  }
+
   /**
    * DOCUMENT ME!
    *
@@ -833,7 +841,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
   public void printMenuItem_actionPerformed(ActionEvent e)
   {
     //Putting in a thread avoids Swing painting problems
-    PrintThread thread = new PrintThread();
+    PrintThread thread = new PrintThread(alignPanel);
     thread.start();
   }
 
@@ -846,8 +854,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
   public void exportAnnotations_actionPerformed(ActionEvent e)
   {
     new AnnotationExporter().exportAnnotations(
-      alignPanel,
-      viewport.alignment.getAlignmentAnnotation()
+        alignPanel,
+        viewport.showAnnotation ? viewport.alignment.getAlignmentAnnotation() : null,
+        viewport.alignment.getGroups()
         );
   }
 
@@ -1082,14 +1091,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
       {
         SequenceI seq = viewport.alignment.getSequenceAt(i);
 
-        if (!sg.getSequences(false).contains(seq))
+        if (!sg.getSequences(null).contains(seq))
         {
           continue;
         }
 
         SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
 
-        if (sg.getSequences(false).contains(temp))
+        if (sg.getSequences(null).contains(temp))
         {
           continue;
         }
@@ -1104,14 +1113,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
       {
         SequenceI seq = viewport.alignment.getSequenceAt(i);
 
-        if (!sg.getSequences(false).contains(seq))
+        if (!sg.getSequences(null).contains(seq))
         {
           continue;
         }
 
         SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
 
-        if (sg.getSequences(false).contains(temp))
+        if (sg.getSequences(null).contains(temp))
         {
           continue;
         }
@@ -1156,6 +1165,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
 
     try
     {
+      jalview.gui.Desktop.internalCopy = true;
       //Its really worth setting the clipboard contents
       //to empty before setting the large StringSelection!!
       Toolkit.getDefaultToolkit().getSystemClipboard()
@@ -1435,7 +1445,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
 
     Vector seqs = new Vector();
     SequenceI seq;
-    for (int i = 0; i < sg.getSize(false); i++)
+    for (int i = 0; i < sg.getSize(); i++)
     {
       seq = sg.getSequenceAt(i);
       seqs.addElement(seq);
@@ -1443,7 +1453,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
 
 
    // If the cut affects all sequences, remove highlighted columns
-   if (sg.getSize(false) == viewport.alignment.getHeight())
+   if (sg.getSize() == viewport.alignment.getHeight())
    {
      viewport.getColumnSelection().removeElements(sg.getStartRes(),
          sg.getEndRes() + 1);
@@ -1608,7 +1618,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
 
       SequenceI [] seqs;
       if(viewport.getSelectionGroup()!=null)
-        seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
+        seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences);
       else
         seqs = viewport.alignment.getSequencesArray();
 
@@ -1671,7 +1681,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
     SequenceI[] seqs;
     if (viewport.getSelectionGroup() != null)
     {
-      seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
+      seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences);
       start = viewport.getSelectionGroup().getStartRes();
       end = viewport.getSelectionGroup().getEndRes();
     }
@@ -1683,7 +1693,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
         new RemoveGapColCommand("Remove Gapped Columns",
                                 seqs,
                                 start, end,
-                                viewport.getGapCharacter());
+                                viewport.alignment);
 
     addHistoryItem(removeGapCols);
 
@@ -1715,7 +1725,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
     SequenceI[] seqs;
     if (viewport.getSelectionGroup() != null)
     {
-      seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
+      seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.hiddenRepSequences);
       start = viewport.getSelectionGroup().getStartRes();
       end = viewport.getSelectionGroup().getEndRes();
     }
@@ -1728,9 +1738,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
     int startRes = seq.findPosition(viewport.startRes);
 
     addHistoryItem(new RemoveGapsCommand("Remove Gaps",
-                                           seqs,
-                                           start, end,
-                     viewport.getGapCharacter()));
+                                         seqs,
+                                         start, end,
+                                         viewport.alignment));
 
     viewport.setStartRes(seq.findIndex(startRes)-1);
 
@@ -2230,7 +2240,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
         if (cs instanceof ClustalxColourScheme)
         {
           sg.cs = new ClustalxColourScheme(
-              sg.getSequences(true), sg.getWidth());
+              sg.getSequences(viewport.hiddenRepSequences), sg.getWidth());
         }
         else if (cs instanceof UserColourScheme)
         {
@@ -2255,7 +2265,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
                 viewport.getIgnoreGapsConsensus());
 
          sg.cs.setConsensus(AAFrequency.calculate(
-             sg.getSequences(true), sg.getStartRes(),
+             sg.getSequences(viewport.hiddenRepSequences), sg.getStartRes(),
              sg.getEndRes()+1));
        }
         else
@@ -2266,7 +2276,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
         {
           Conservation c = new Conservation("Group",
                                             ResidueProperties.propHash, 3,
-                                            sg.getSequences(true),
+                                            sg.getSequences(viewport.hiddenRepSequences),
                                             sg.getStartRes(),
                                             sg.getEndRes()+1);
           c.calculate();
@@ -2518,7 +2528,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
   public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
   {
     if ( (viewport.getSelectionGroup() == null) ||
-        (viewport.getSelectionGroup().getSize(false) < 2))
+        (viewport.getSelectionGroup().getSize() < 2))
     {
       JOptionPane.showInternalMessageDialog(this,
                                             "You must select at least 2 sequences.",
@@ -2541,8 +2551,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
   public void PCAMenuItem_actionPerformed(ActionEvent e)
   {
     if ( ( (viewport.getSelectionGroup() != null) &&
-          (viewport.getSelectionGroup().getSize(false) < 4) &&
-          (viewport.getSelectionGroup().getSize(false) > 0)) ||
+          (viewport.getSelectionGroup().getSize() < 4) &&
+          (viewport.getSelectionGroup().getSize() > 0)) ||
         (viewport.getAlignment().getHeight() < 4))
     {
       JOptionPane.showInternalMessageDialog(this,
@@ -2622,7 +2632,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
     TreePanel tp;
 
     if (viewport.getSelectionGroup() != null) {
-      if (viewport.getSelectionGroup().getSize(false) < 3) {
+      if (viewport.getSelectionGroup().getSize() < 3) {
         JOptionPane.showMessageDialog(Desktop.desktop,
                                       "You need to have more than two sequences selected to build a tree!",
                                       "Not enough sequences",
@@ -2634,9 +2644,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
       SequenceGroup sg = viewport.getSelectionGroup();
 
       /* Decide if the selection is a column region */
-      while (s < sg.getSize(false))
+      while (s < sg.getSize())
       {
-        if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
+        if ( ( (SequenceI) sg.getSequences(null).elementAt(s++)).getLength() <
             sg.getEndRes())
         {
           JOptionPane.showMessageDialog(Desktop.desktop,
@@ -2779,7 +2789,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
     AlignmentView msa = null;
 
     if ( (viewport.getSelectionGroup() != null) &&
-        (viewport.getSelectionGroup().getSize(false) > 1))
+        (viewport.getSelectionGroup().getSize() > 1))
     {
       // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
       /*SequenceGroup seqs = viewport.getSelectionGroup();
@@ -2821,7 +2831,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
    AlignmentView seqs = null;
 
     if ( (viewport.getSelectionGroup() != null) &&
-        (viewport.getSelectionGroup().getSize(false) > 0))
+        (viewport.getSelectionGroup().getSize() > 0))
     {
       seqs = viewport.getAlignmentView(true);
     }
@@ -2931,28 +2941,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
     return tp;
   }
 
-  class PrintThread
-      extends Thread
-  {
-    public void run()
-    {
-      PrinterJob printJob = PrinterJob.getPrinterJob();
-      PageFormat pf = printJob.pageDialog(printJob.defaultPage());
-      printJob.setPrintable(alignPanel, pf);
-
-      if (printJob.printDialog())
-      {
-        try
-        {
-          printJob.print();
-        }
-        catch (Exception PrintException)
-        {
-          PrintException.printStackTrace();
-        }
-      }
-    }
-  }
 
   /**
    * Generates menu items and listener event actions for web service clients
@@ -3287,7 +3275,7 @@ public void drop(DropTargetDropEvent evt)
       }
 
       boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
-          alignment, file);
+          alignment, file, protocol);
 
       if (!isAnnotation)
       {
@@ -3355,3 +3343,34 @@ public void drop(DropTargetDropEvent evt)
     return viewport;
   }
 }
+
+class PrintThread extends Thread
+{
+  AlignmentPanel ap;
+  public PrintThread(AlignmentPanel ap)
+  {
+   this.ap = ap;
+  }
+  static PageFormat pf;
+  public void run()
+  {
+    PrinterJob printJob = PrinterJob.getPrinterJob();
+
+    if (pf != null)
+      printJob.setPrintable(ap, pf);
+    else
+      printJob.setPrintable(ap);
+
+    if (printJob.printDialog())
+    {
+      try
+      {
+        printJob.print();
+      }
+      catch (Exception PrintException)
+      {
+        PrintException.printStackTrace();
+      }
+    }
+  }
+}