JAL-3253-applet headless branch - just experimenting.
[jalview.git] / src / jalview / gui / AlignFrame.java
index bac06e9..d73d893 100644 (file)
@@ -131,6 +131,7 @@ import java.awt.event.MouseEvent;
 import java.awt.print.PageFormat;
 import java.awt.print.PrinterJob;
 import java.beans.PropertyChangeEvent;
+import java.beans.PropertyVetoException;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.PrintWriter;
@@ -170,6 +171,17 @@ public class AlignFrame extends GAlignFrame
         IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
 {
 
+  public class IFrame extends JInternalFrame
+  {
+    public AlignFrame alignframe;
+
+    IFrame(AlignFrame alignframe)
+    {
+      this.alignframe = alignframe;
+    }
+
+  }
+
   public static final int DEFAULT_WIDTH = 700;
 
   public static final int DEFAULT_HEIGHT = 500;
@@ -291,15 +303,25 @@ public class AlignFrame extends GAlignFrame
   public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
           int height, String sequenceSetId, String viewId)
   {
+    super();
+
+    System.out.println("AlignFrame 1");
+
     setSize(width, height);
 
+    System.out.println("GAlignFrame 2");
+
     if (al.getDataset() == null)
     {
       al.setDataset(null);
     }
 
+    System.out.println("GAlignFrame 3");
+
     viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
 
+    System.out.println("GAlignFrame 4");
+
     init();
   }
 
@@ -343,8 +365,12 @@ public class AlignFrame extends GAlignFrame
    */
   void init()
   {
+
+    System.out.println("AlignFrame 8");
     boolean newPanel = (alignPanel == null);
     viewport.setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
+
+    System.out.println("AlignFrame 9");
     if (newPanel)
     {
       if (Platform.isJS())
@@ -360,9 +386,13 @@ public class AlignFrame extends GAlignFrame
         boolean showAnnotation = Jalview.getInstance().getShowAnnotation();
         viewport.setShowAnnotation(showAnnotation);
       }
+      System.out.println("AlignFrame 11");
       alignPanel = new AlignmentPanel(this, viewport);
+      System.out.println("GAlignFrame 12");
     }
+    System.out.println("GAlignFrame 13");
     addAlignmentPanel(alignPanel, newPanel);
+    System.out.println("GAlignFrame 14");
 
     // setBackground(Color.white); // BH 2019
                  
@@ -782,11 +812,14 @@ public class AlignFrame extends GAlignFrame
 
     int aSize = alignPanels.size();
 
+    System.out.println("AlignFrame 21");
+
     tabbedPane.setVisible(aSize > 1 || ap.av.getViewName() != null);
 
+    System.out.println("AlignFrame 23");
     if (aSize == 1 && ap.av.getViewName() == null)
     {
-      this.getContentPane().add(ap, BorderLayout.CENTER);
+      getContentPane().add(ap, BorderLayout.CENTER);
     }
     else
     {
@@ -824,9 +857,10 @@ public class AlignFrame extends GAlignFrame
     tabbedPane.setVisible(true);
     AlignmentPanel first = alignPanels.get(0);
     tabbedPane.addTab(first.av.getViewName(), first);
-    this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
+    getContentPane().add(tabbedPane, BorderLayout.CENTER);
   }
 
+
   public AlignViewport getViewport()
   {
     return viewport;
@@ -858,7 +892,8 @@ public class AlignFrame extends GAlignFrame
                 }
               }
             });
-    addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
+    iframe.addInternalFrameListener(
+            new javax.swing.event.InternalFrameAdapter()
     {
       @Override
       public void internalFrameClosed(
@@ -1058,12 +1093,12 @@ public class AlignFrame extends GAlignFrame
       // file is reloaded.
       if (FileFormat.Jalview.equals(currentFileFormat))
       {
-        JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
+        AlignFrame[] frames = Desktop.getAlignFrames();
         for (int i = 0; i < frames.length; i++)
         {
           if (frames[i] instanceof AlignFrame && frames[i] != this
-                  && ((AlignFrame) frames[i]).fileName != null
-                  && ((AlignFrame) frames[i]).fileName.equals(fileName))
+                  && frames[i].fileName != null
+                  && frames[i].fileName.equals(fileName))
           {
             try
             {
@@ -1077,7 +1112,7 @@ public class AlignFrame extends GAlignFrame
         }
         Desktop.getInstance().closeAssociatedWindows();
 
-        FileLoader loader = new FileLoader();
+        FileLoader loader = new FileLoader(!Jalview.isHeadlessMode());
         DataSourceType protocol = fileName.startsWith("http:")
                 ? DataSourceType.URL
                 : DataSourceType.FILE;
@@ -1130,6 +1165,7 @@ public class AlignFrame extends GAlignFrame
     }
   }
 
+
   @Override
   public void addFromText_actionPerformed(ActionEvent e)
   {
@@ -1255,7 +1291,7 @@ public class AlignFrame extends GAlignFrame
 
     if (FileFormat.Jalview.equals(format))
     {
-      String shortName = title;
+      String shortName = getTitle();
       if (shortName.indexOf(File.separatorChar) > -1)
       {
         shortName = shortName.substring(
@@ -1544,7 +1580,7 @@ public class AlignFrame extends GAlignFrame
       {
         if (closeAllTabs)
         {
-          if (this.isClosed())
+          if (isClosed())
           {
             // really close all the windows - otherwise wait till
             // setClosed(true) is called
@@ -1567,7 +1603,7 @@ public class AlignFrame extends GAlignFrame
          * this will raise an INTERNAL_FRAME_CLOSED event and this method will
          * be called recursively, with the frame now in 'closed' state
          */
-        this.setClosed(true);
+        iframe.setClosed(true);
       }
     } catch (Exception ex)
     {
@@ -2319,13 +2355,13 @@ public class AlignFrame extends GAlignFrame
         // title a concatenation of operations.
         if (!externalPaste)
         {
-          if (title.startsWith("Copied sequences"))
+          if (getTitle().startsWith("Copied sequences"))
           {
-            newtitle = title;
+            newtitle = getTitle();
           }
           else
           {
-            newtitle = newtitle.concat("- from " + title);
+            newtitle = newtitle.concat("- from " + getTitle());
           }
         }
         else
@@ -2375,17 +2411,18 @@ public class AlignFrame extends GAlignFrame
       // TODO: maintain provenance of an alignment, rather than just make the
       // title a concatenation of operations.
       {
-        if (title.startsWith("Copied sequences"))
+        if (getTitle().startsWith("Copied sequences"))
         {
-          newtitle = title;
+          newtitle = getTitle();
         }
         else
         {
-          newtitle = newtitle.concat("- from " + title);
+          newtitle = newtitle.concat("- from " + getTitle());
         }
       }
 
-      Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+      Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
+              DEFAULT_HEIGHT);
 
     } catch (Exception ex)
     {
@@ -2444,7 +2481,7 @@ public class AlignFrame extends GAlignFrame
                    {
                      try
                      {
-                       AlignFrame.this.setClosed(true);
+            AlignFrame.this.getIFrame().setClosed(true);
                      } catch (Exception ex)
                      {
                      }
@@ -3773,7 +3810,7 @@ public class AlignFrame extends GAlignFrame
       frameTitle += viewport.getViewName() + " of ";
     }
 
-    frameTitle += this.title;
+    frameTitle += this.getTitle();
 
     Desktop.addInternalFrame(tp, frameTitle, 600, 500);
   }
@@ -4850,7 +4887,7 @@ public class AlignFrame extends GAlignFrame
           }
           else
           {
-            new FileLoader().loadFile(viewport, file, sourceType, format);
+            new FileLoader(!Jalview.isHeadlessMode()).loadFile(viewport, file, sourceType, format);
           }
         }
       }
@@ -5660,12 +5697,13 @@ public class AlignFrame extends GAlignFrame
     }
     AlignmentI cdna = new Alignment(
             cdnaSeqs.toArray(new SequenceI[cdnaSeqs.size()]));
-    GAlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
+    AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
             AlignFrame.DEFAULT_HEIGHT);
     cdna.alignAs(alignment);
     String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
-            + this.title;
-    Desktop.addInternalFrame(alignFrame, newtitle, AlignFrame.DEFAULT_WIDTH,
+            + getTitle();
+    Desktop.addInternalFrame(alignFrame, newtitle,
+            AlignFrame.DEFAULT_WIDTH,
             AlignFrame.DEFAULT_HEIGHT);
   }
 
@@ -5899,6 +5937,41 @@ public class AlignFrame extends GAlignFrame
     alignPanel.getSeqPanel().selection(sel, csel, hidden, null);
   }
 
+  public void setSelected(boolean b) throws PropertyVetoException
+  {
+    if (iframe != null)
+    {
+      iframe.setSelected(b);
+    }
+  }
+
+  @Override
+  protected JInternalFrame getInternalFrame()
+  {
+    return new IFrame(this);
+  }
+
+  public void dispose()
+  {
+    if (iframe != null)
+    {
+      iframe.dispose();
+    }
+  }
+
+  public void setMaximum(boolean b) throws PropertyVetoException
+  {
+    if (iframe != null)
+    {
+      iframe.setMaximum(b);
+    }
+  }
+
+  public boolean isClosed()
+  {
+    return (iframe != null && iframe.isClosed());
+  }
+
 }
 
 class PrintThread extends Thread