Added support for SVG Export
authorCharles Ofoegbu <tcnofoegbu@dundee.ac.uk>
Wed, 12 Nov 2014 17:54:32 +0000 (17:54 +0000)
committerCharles Ofoegbu <tcnofoegbu@dundee.ac.uk>
Wed, 12 Nov 2014 17:54:32 +0000 (17:54 +0000)
.gitignore
lib/jfreesvg-2.1.jar [new file with mode: 0644]
src/MCview/PDBViewer.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignmentPanel.java
src/jalview/gui/AppJmol.java
src/jalview/gui/Desktop.java
src/jalview/gui/PCAPanel.java
src/jalview/jbgui/GAlignFrame.java
src/jalview/util/ImageMaker.java

index 9841761..7b4e5bc 100644 (file)
@@ -2,5 +2,5 @@
 /dist
 /classes
 .externalToolBuilders/Jalview Release indices [Builder].launch
-/.DS_Store
+.DS_Store
 /.com.apple.timemachine.supported
diff --git a/lib/jfreesvg-2.1.jar b/lib/jfreesvg-2.1.jar
new file mode 100644 (file)
index 0000000..91d453c
Binary files /dev/null and b/lib/jfreesvg-2.1.jar differ
index a297892..d3535c0 100755 (executable)
  */
 package MCview;
 
-import java.io.*;
-
-import java.awt.event.*;
-import javax.swing.*;
-
-import jalview.datamodel.*;
-import jalview.gui.*;
-import jalview.io.*;
-import jalview.schemes.*;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignmentPanel;
+import jalview.gui.Desktop;
+import jalview.gui.OOMWarning;
+import jalview.gui.UserDefinedColours;
+import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
+import jalview.schemes.BuriedColourScheme;
+import jalview.schemes.HelixColourScheme;
+import jalview.schemes.HydrophobicColourScheme;
+import jalview.schemes.StrandColourScheme;
+import jalview.schemes.TaylorColourScheme;
+import jalview.schemes.TurnColourScheme;
+import jalview.schemes.UserColourScheme;
+import jalview.schemes.ZappoColourScheme;
 import jalview.util.MessageManager;
 import jalview.ws.ebi.EBIFetchClient;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.PrintWriter;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JColorChooser;
+import javax.swing.JInternalFrame;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JRadioButtonMenuItem;
+import javax.swing.SwingUtilities;
+
 public class PDBViewer extends JInternalFrame implements Runnable
 {
 
@@ -123,7 +155,9 @@ public class PDBViewer extends JInternalFrame implements Runnable
               .getAbsolutePath());
 
       if (pdbentry.getFile() != null)
+      {
         pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
+      }
     } catch (Exception ex)
     {
       pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
@@ -466,7 +500,7 @@ public class PDBViewer extends JInternalFrame implements Runnable
    */
   public void eps_actionPerformed(ActionEvent e)
   {
-    makePDBImage(jalview.util.ImageMaker.EPS);
+    makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
   }
 
   /**
@@ -477,27 +511,36 @@ public class PDBViewer extends JInternalFrame implements Runnable
    */
   public void png_actionPerformed(ActionEvent e)
   {
-    makePDBImage(jalview.util.ImageMaker.PNG);
+    makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
   }
 
-  void makePDBImage(int type)
+  void makePDBImage(jalview.util.ImageMaker.TYPE type)
   {
     int width = pdbcanvas.getWidth();
     int height = pdbcanvas.getHeight();
 
     jalview.util.ImageMaker im;
 
-    if (type == jalview.util.ImageMaker.PNG)
+    if (type == jalview.util.ImageMaker.TYPE.PNG)
     {
-      im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
+      im = new jalview.util.ImageMaker(this,
+              jalview.util.ImageMaker.TYPE.PNG,
               "Make PNG image from view", width, height, null, null);
     }
-    else
+    else if (type == jalview.util.ImageMaker.TYPE.EPS)
     {
-      im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
+      im = new jalview.util.ImageMaker(this,
+              jalview.util.ImageMaker.TYPE.EPS,
               "Make EPS file from view", width, height, null,
               this.getTitle());
     }
+    else
+    {
+
+      im = new jalview.util.ImageMaker(this,
+              jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
+              width, height, null, this.getTitle());
+    }
 
     if (im.getGraphics() != null)
     {
index d9c0c6a..8b47302 100644 (file)
@@ -377,7 +377,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                         .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
                         .getKeyCode() <= KeyEvent.VK_NUMPAD9))
                 && Character.isDigit(evt.getKeyChar()))
+        {
           alignPanel.seqPanel.numberPressed(evt.getKeyChar());
+        }
 
         switch (evt.getKeyCode())
         {
@@ -389,32 +391,48 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
         case KeyEvent.VK_DOWN:
           if (evt.isAltDown() || !viewport.cursorMode)
+          {
             moveSelectedSequences(false);
+          }
           if (viewport.cursorMode)
+          {
             alignPanel.seqPanel.moveCursor(0, 1);
+          }
           break;
 
         case KeyEvent.VK_UP:
           if (evt.isAltDown() || !viewport.cursorMode)
+          {
             moveSelectedSequences(true);
+          }
           if (viewport.cursorMode)
+          {
             alignPanel.seqPanel.moveCursor(0, -1);
+          }
 
           break;
 
         case KeyEvent.VK_LEFT:
           if (evt.isAltDown() || !viewport.cursorMode)
+          {
             slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
+          }
           else
+          {
             alignPanel.seqPanel.moveCursor(-1, 0);
+          }
 
           break;
 
         case KeyEvent.VK_RIGHT:
           if (evt.isAltDown() || !viewport.cursorMode)
+          {
             slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
+          }
           else
+          {
             alignPanel.seqPanel.moveCursor(1, 0);
+          }
           break;
 
         case KeyEvent.VK_SPACE:
@@ -551,14 +569,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         {
         case KeyEvent.VK_LEFT:
           if (evt.isAltDown() || !viewport.cursorMode)
+          {
             viewport.firePropertyChange("alignment", null, viewport
                     .getAlignment().getSequences());
+          }
           break;
 
         case KeyEvent.VK_RIGHT:
           if (evt.isAltDown() || !viewport.cursorMode)
+          {
             viewport.firePropertyChange("alignment", null, viewport
                     .getAlignment().getSequences());
+          }
           break;
         }
       }
@@ -1236,6 +1258,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     alignPanel.makeEPS(f);
   }
 
+  public void createSVG(File f)
+  {
+    alignPanel.makeSVG(f);
+  }
   @Override
   public void pageSetup_actionPerformed(ActionEvent e)
   {
@@ -1458,7 +1484,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   protected void undoMenuItem_actionPerformed(ActionEvent e)
   {
     if (viewport.historyList.empty())
+    {
       return;
+    }
     CommandI command = (CommandI) viewport.historyList.pop();
     viewport.redoList.push(command);
     command.undoCommand(getViewAlignments());
@@ -1611,37 +1639,53 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
     {
       if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
+      {
         invertGroup.add(viewport.getAlignment().getSequenceAt(i));
+      }
     }
 
     SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
 
     SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
     for (int i = 0; i < invertGroup.size(); i++)
+    {
       seqs2[i] = (SequenceI) invertGroup.elementAt(i);
+    }
 
     SlideSequencesCommand ssc;
     if (right)
+    {
       ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
               size, viewport.getGapCharacter());
+    }
     else
+    {
       ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
               size, viewport.getGapCharacter());
+    }
 
     int groupAdjustment = 0;
     if (ssc.getGapsInsertedBegin() && right)
     {
       if (viewport.cursorMode)
+      {
         alignPanel.seqPanel.moveCursor(size, 0);
+      }
       else
+      {
         groupAdjustment = size;
+      }
     }
     else if (!ssc.getGapsInsertedBegin() && !right)
     {
       if (viewport.cursorMode)
+      {
         alignPanel.seqPanel.moveCursor(-size, 0);
+      }
       else
+      {
         groupAdjustment = -size;
+      }
     }
 
     if (groupAdjustment != 0)
@@ -1662,7 +1706,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
 
     if (!appendHistoryItem)
+    {
       addHistoryItem(ssc);
+    }
 
     repaint();
   }
@@ -1997,7 +2043,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           {
             AlignmentAnnotation sann[] = sequences[i].getAnnotation();
             if (sann == null)
+            {
               continue;
+            }
             for (int avnum = 0; avnum < alview.length; avnum++)
             {
               if (alview[avnum] != alignment)
@@ -4643,7 +4691,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               if (ds.getSequences() == null
                       || !ds.getSequences().contains(
                               sprods[s].getDatasetSequence()))
+              {
                 ds.addSequence(sprods[s].getDatasetSequence());
+              }
               sprods[s].updatePDBIds();
             }
             Alignment al = new Alignment(sprods);
index cdac5b4..d2670f4 100644 (file)
  */
 package jalview.gui;
 
-import java.beans.*;
-import java.io.*;
-
-import java.awt.*;
-import java.awt.event.*;
-import java.awt.print.*;
-import javax.swing.*;
-
 import jalview.api.AlignmentViewPanel;
 import jalview.bin.Cache;
-import jalview.datamodel.*;
-import jalview.jbgui.*;
-import jalview.schemes.*;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SearchResults;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.jbgui.GAlignmentPanel;
+import jalview.schemes.ResidueProperties;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
 
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.event.AdjustmentEvent;
+import java.awt.event.AdjustmentListener;
+import java.awt.print.PageFormat;
+import java.awt.print.Printable;
+import java.awt.print.PrinterException;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+
+import javax.swing.SwingUtilities;
+
 /**
  * DOCUMENT ME!
  * 
@@ -179,7 +195,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
     int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300);
     int maxwidth = Math.max(20,
-            Math.min(afwidth - 200, (int) 2 * afwidth / 3));
+            Math.min(afwidth - 200, 2 * afwidth / 3));
     return calculateIdWidth(maxwidth);
   }
 
@@ -841,7 +857,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
     // / How many sequences and residues can we fit on a printable page?
     int totalRes = (pwidth - idWidth) / av.getCharWidth();
 
-    int totalSeq = (int) ((pheight - scaleHeight) / av.getCharHeight()) - 1;
+    int totalSeq = (pheight - scaleHeight) / av.getCharHeight() - 1;
 
     int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1;
 
@@ -954,10 +970,10 @@ public class AlignmentPanel extends GAlignmentPanel implements
       int offset = -alabels.scrollOffset;
       pg.translate(0, offset);
       pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3);
-      alabels.drawComponent((Graphics2D) pg, idWidth);
+      alabels.drawComponent(pg, idWidth);
       pg.translate(idWidth + 3, 0);
       annotationPanel.renderer.drawComponent(annotationPanel, av,
-              (Graphics2D) pg, -1, startRes, endRes + 1);
+              pg, -1, startRes, endRes + 1);
       pg.translate(0, -offset);
     }
 
@@ -1113,14 +1129,17 @@ public class AlignmentPanel extends GAlignmentPanel implements
     return idwidth.intValue() + 4;
   }
 
-  void makeAlignmentImage(int type, File file)
+  void makeAlignmentImage(jalview.util.ImageMaker.TYPE type, File file)
   {
     long progress = System.currentTimeMillis();
     boolean headless = (System.getProperty("java.awt.headless") != null && System
             .getProperty("java.awt.headless").equals("true"));
     if (alignFrame != null && !headless)
     {
-      alignFrame.setProgressBar(MessageManager.formatMessage("status.saving_file", new String[]{(type == jalview.util.ImageMaker.PNG ? MessageManager.getString("label.png_image") : MessageManager.getString("label.eps_file"))}), progress);
+      alignFrame.setProgressBar(MessageManager.formatMessage(
+              "status.saving_file",
+              new String[]
+              { type.getLabel() }), progress);
     }
     try
     {
@@ -1164,16 +1183,22 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
         jalview.util.ImageMaker im;
         final String imageAction, imageTitle;
-        if (type == jalview.util.ImageMaker.PNG)
+        if (type == jalview.util.ImageMaker.TYPE.PNG)
         {
           imageAction = "Create PNG image from alignment";
           imageTitle = null;
         }
-        else
+        else if (type == jalview.util.ImageMaker.TYPE.EPS)
         {
           imageAction = "Create EPS file from alignment";
           imageTitle = alignFrame.getTitle();
         }
+        else
+        {
+          imageAction = "Create SVG file from alignment";
+          imageTitle = alignFrame.getTitle();
+        }
+
         im = new jalview.util.ImageMaker(this, type, imageAction, width,
                 height, file, imageTitle);
         if (av.getWrapAlignment())
@@ -1217,7 +1242,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
    */
   public void makeEPS(File epsFile)
   {
-    makeAlignmentImage(jalview.util.ImageMaker.EPS, epsFile);
+    makeAlignmentImage(jalview.util.ImageMaker.TYPE.EPS, epsFile);
   }
 
   /**
@@ -1225,9 +1250,13 @@ public class AlignmentPanel extends GAlignmentPanel implements
    */
   public void makePNG(File pngFile)
   {
-    makeAlignmentImage(jalview.util.ImageMaker.PNG, pngFile);
+    makeAlignmentImage(jalview.util.ImageMaker.TYPE.PNG, pngFile);
   }
 
+  public void makeSVG(File svgFile)
+  {
+    makeAlignmentImage(jalview.util.ImageMaker.TYPE.SVG, svgFile);
+  }
   public void makePNGImageMap(File imgMapFile, String imageName)
   {
     // /////ONLY WORKS WITH NONE WRAPPED ALIGNMENTS
index 998db4b..5d4b910 100644 (file)
  */
 package jalview.gui;
 
-import java.util.*;
-import java.awt.*;
-
-import javax.swing.*;
-import javax.swing.event.*;
-
-import java.awt.event.*;
-import java.io.*;
-
-import jalview.jbgui.GStructureViewer;
-import jalview.api.SequenceStructureBinding;
 import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
-import jalview.datamodel.*;
-import jalview.gui.ViewSelectionMenu.ViewSetProvider;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceI;
 import jalview.ext.jmol.JalviewJmolBinding;
-import jalview.io.*;
-import jalview.schemes.*;
+import jalview.gui.ViewSelectionMenu.ViewSetProvider;
+import jalview.io.AppletFormatAdapter;
+import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
+import jalview.jbgui.GStructureViewer;
+import jalview.schemes.BuriedColourScheme;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.HelixColourScheme;
+import jalview.schemes.HydrophobicColourScheme;
+import jalview.schemes.PurinePyrimidineColourScheme;
+import jalview.schemes.StrandColourScheme;
+import jalview.schemes.TaylorColourScheme;
+import jalview.schemes.TurnColourScheme;
+import jalview.schemes.ZappoColourScheme;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JColorChooser;
+import javax.swing.JInternalFrame;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JSplitPane;
+import javax.swing.event.InternalFrameAdapter;
+import javax.swing.event.InternalFrameEvent;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
+
 public class AppJmol extends GStructureViewer implements Runnable,
         ViewSetProvider, JalviewStructureDisplayI
 
@@ -70,6 +106,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
    * @param bounds
    * @deprecated defaults to AppJmol(String[] files, ... , viewid);
    */
+  @Deprecated
   public AppJmol(String file, String id, SequenceI[] seq,
           AlignmentPanel ap, String loadStatus, Rectangle bounds)
   {
@@ -79,6 +116,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
   /**
    * @deprecated
    */
+  @Deprecated
   public AppJmol(String file, String id, SequenceI[] seq,
           AlignmentPanel ap, String loadStatus, Rectangle bounds,
           String viewid)
@@ -643,7 +681,9 @@ public class AppJmol extends GStructureViewer implements Runnable,
         for (int i = 0; i < chainMenu.getItemCount(); i++)
         {
           if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
+          {
             ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
+          }
         }
         centerViewer();
         allChainsSelected = false;
@@ -660,7 +700,9 @@ public class AppJmol extends GStructureViewer implements Runnable,
         public void itemStateChanged(ItemEvent evt)
         {
           if (!allChainsSelected)
+          {
             centerViewer();
+          }
         }
       });
 
@@ -953,7 +995,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
    */
   public void eps_actionPerformed(ActionEvent e)
   {
-    makePDBImage(jalview.util.ImageMaker.EPS);
+    makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
   }
 
   /**
@@ -964,27 +1006,36 @@ public class AppJmol extends GStructureViewer implements Runnable,
    */
   public void png_actionPerformed(ActionEvent e)
   {
-    makePDBImage(jalview.util.ImageMaker.PNG);
+    makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
   }
 
-  void makePDBImage(int type)
+  void makePDBImage(jalview.util.ImageMaker.TYPE type)
   {
     int width = getWidth();
     int height = getHeight();
 
     jalview.util.ImageMaker im;
 
-    if (type == jalview.util.ImageMaker.PNG)
+    if (type == jalview.util.ImageMaker.TYPE.PNG)
     {
-      im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
+      im = new jalview.util.ImageMaker(this,
+              jalview.util.ImageMaker.TYPE.PNG,
               "Make PNG image from view", width, height, null, null);
     }
-    else
+    else if (type == jalview.util.ImageMaker.TYPE.EPS)
     {
-      im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
+      im = new jalview.util.ImageMaker(this,
+              jalview.util.ImageMaker.TYPE.EPS,
               "Make EPS file from view", width, height, null,
               this.getTitle());
     }
+    else
+    {
+
+      im = new jalview.util.ImageMaker(this,
+              jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
+              width, height, null, this.getTitle());
+    }
 
     if (im.getGraphics() != null)
     {
index 63f0caa..faffd89 100644 (file)
@@ -2152,7 +2152,9 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       if (showMemoryUsage && g != null && df != null)
       {
         if (percentUsage < 20)
+        {
           g.setColor(Color.red);
+        }
         FontMetrics fm = g.getFontMetrics();
         if (fm != null)
         {
@@ -2762,7 +2764,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   {
     invalidate();
     File of;
-    ImageMaker im = new jalview.util.ImageMaker(this, ImageMaker.EPS, "View of Desktop", getWidth(), getHeight(), of=new File("Jalview_snapshot"+System.currentTimeMillis()+".eps"), "View of desktop");
+    ImageMaker im = new jalview.util.ImageMaker(this, ImageMaker.TYPE.EPS,
+            "View of Desktop", getWidth(), getHeight(), of = new File(
+                    "Jalview_snapshot" + System.currentTimeMillis()
+                            + ".eps"), "View of desktop");
     try {
       paintAll(im.getGraphics());
       im.writeImage();
index 3483cc4..d2d6a98 100644 (file)
  */
 package jalview.gui;
 
-import java.util.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.awt.print.*;
-
-import javax.swing.*;
-
-import jalview.datamodel.*;
-import jalview.jbgui.*;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentView;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.SeqCigar;
+import jalview.datamodel.SequenceI;
+import jalview.jbgui.GPCAPanel;
 import jalview.schemes.ResidueProperties;
 import jalview.util.MessageManager;
 import jalview.viewmodel.PCAModel;
 
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.print.PageFormat;
+import java.awt.print.Printable;
+import java.awt.print.PrinterException;
+import java.awt.print.PrinterJob;
+import java.util.Hashtable;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JButton;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JColorChooser;
+import javax.swing.JLabel;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JProgressBar;
+import javax.swing.JRadioButtonMenuItem;
+
 /**
  * DOCUMENT ME!
  * 
@@ -135,9 +155,9 @@ public class PCAPanel extends GPCAPanel implements Runnable,
             @Override
             public void actionPerformed(ActionEvent e)
             {
-              if (!pcaModel.getScore_matrix().equals((String) sm))
+              if (!pcaModel.getScore_matrix().equals(sm))
               {
-                pcaModel.setScore_matrix((String) sm);
+                pcaModel.setScore_matrix(sm);
                 Thread worker = new Thread(us);
                 worker.start();
               }
@@ -445,7 +465,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
    */
   public void eps_actionPerformed(ActionEvent e)
   {
-    makePCAImage(jalview.util.ImageMaker.EPS);
+    makePCAImage(jalview.util.ImageMaker.TYPE.EPS);
   }
 
   /**
@@ -456,27 +476,36 @@ public class PCAPanel extends GPCAPanel implements Runnable,
    */
   public void png_actionPerformed(ActionEvent e)
   {
-    makePCAImage(jalview.util.ImageMaker.PNG);
+    makePCAImage(jalview.util.ImageMaker.TYPE.PNG);
   }
 
-  void makePCAImage(int type)
+  void makePCAImage(jalview.util.ImageMaker.TYPE type)
   {
     int width = rc.getWidth();
     int height = rc.getHeight();
 
     jalview.util.ImageMaker im;
 
-    if (type == jalview.util.ImageMaker.PNG)
+    if (type == jalview.util.ImageMaker.TYPE.PNG)
     {
-      im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
+      im = new jalview.util.ImageMaker(this,
+              jalview.util.ImageMaker.TYPE.PNG,
               "Make PNG image from PCA", width, height, null, null);
     }
-    else
+    else if (type == jalview.util.ImageMaker.TYPE.EPS)
     {
-      im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
+      im = new jalview.util.ImageMaker(this,
+              jalview.util.ImageMaker.TYPE.EPS,
               "Make EPS file from PCA", width, height, null,
               this.getTitle());
     }
+    else
+    {
+      im = new jalview.util.ImageMaker(this,
+              jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
+              width, height, null, this.getTitle());
+
+    }
 
     if (im.getGraphics() != null)
     {
index afb0dc1..5146128 100755 (executable)
@@ -210,6 +210,8 @@ public class GAlignFrame extends JInternalFrame
 
   JMenuItem createPNG = new JMenuItem();
 
+  JMenuItem createSVG = new JMenuItem();
+
   protected JMenuItem font = new JMenuItem();
 
   public JCheckBoxMenuItem seqLimits = new JCheckBoxMenuItem();
@@ -1488,6 +1490,7 @@ public class GAlignFrame extends JInternalFrame
     createPNG.setActionCommand(MessageManager
             .getString("label.save_png_image"));
     createPNG.setText("PNG");
+
     font.setText(MessageManager.getString("action.font"));
     font.addActionListener(new java.awt.event.ActionListener()
     {
@@ -1518,6 +1521,17 @@ public class GAlignFrame extends JInternalFrame
         createEPS(null);
       }
     });
+
+    createSVG.setText("SVG");
+    createSVG.addActionListener(new java.awt.event.ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        createSVG(null);
+      }
+    });
+
     LoadtreeMenuItem.setActionCommand(MessageManager
             .getString("label.load_tree_for_sequence_set"));
     LoadtreeMenuItem.setText(MessageManager
@@ -2225,6 +2239,7 @@ public class GAlignFrame extends JInternalFrame
     jMenu2.add(htmlMenuItem);
     jMenu2.add(epsFile);
     jMenu2.add(createPNG);
+    jMenu2.add(createSVG);
     addSequenceMenu.add(addFromFile);
     addSequenceMenu.add(addFromText);
     addSequenceMenu.add(addFromURL);
@@ -2708,6 +2723,10 @@ public class GAlignFrame extends JInternalFrame
   {
   }
 
+  public void createSVG(java.io.File f)
+  {
+
+  }
   protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
   {
 
index c93f8e8..1953a60 100755 (executable)
  */
 package jalview.util;
 
-import java.io.*;
-import javax.imageio.*;
+import jalview.gui.EPSOptions;
+import jalview.io.JalviewFileChooser;
 
-import java.awt.*;
-import java.awt.image.*;
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileOutputStream;
 
-import org.jibble.epsgraphics.*;
-import jalview.gui.*;
-import jalview.io.*;
+import javax.imageio.ImageIO;
+
+import org.jfree.graphics2d.svg.SVGGraphics2D;
+import org.jibble.epsgraphics.EpsGraphics2D;
 
 public class ImageMaker
 {
-  public static final int EPS = 0;
-
-  public static final int PNG = 1;
-
-  int type = -1;
+  // public static final int EPS = 0;
+  //
+  // public static final int PNG = 1;
+  //
+  // public static final int SVG = 2;
+  //
+  // int type = -1;
 
   EpsGraphics2D pg;
 
+  SVGGraphics2D g2;
+
   Graphics graphics;
 
   FileOutputStream out;
 
   BufferedImage bi;
 
-  public ImageMaker(Component parent, int type, String title, int width,
-          int height, File file, String EPStitle)
+  TYPE type;
+
+  public enum TYPE
+  {
+    EPS("EPS", MessageManager.getString("label.eps_file"), getEPSChooser()), PNG(
+            "PNG", MessageManager.getString("label.png_image"),
+            getPNGChooser()), SVG("SVG", "SVG", getSVGChooser());
+
+    private JalviewFileChooser chooser;
+
+    private String name;
+
+    private String label;
+
+    TYPE(String name, String label, JalviewFileChooser chooser)
+    {
+      this.name = name;
+      this.label = label;
+      this.chooser = chooser;
+    }
+
+    public String getName()
+    {
+      return name;
+    }
+
+    public JalviewFileChooser getChooser()
+    {
+      return chooser;
+    }
+
+    public String getLabel()
+    {
+      return label;
+    }
+
+  }
+
+
+  public ImageMaker(Component parent, TYPE type, String title, int width,
+          int height, File file, String fileTitle)
   {
     this.type = type;
 
     if (file == null)
     {
       JalviewFileChooser chooser;
-      chooser = type == EPS ? getEPSChooser() : getPNGChooser();
+      // chooser = type == EPS ? getEPSChooser() : getPNGChooser();
+      chooser = type.getChooser();
 
       chooser.setFileView(new jalview.io.JalviewFileView());
       chooser.setDialogTitle(title);
@@ -76,19 +126,23 @@ public class ImageMaker
       try
       {
         out = new FileOutputStream(file);
-
-        if (type == EPS)
+        if (type == TYPE.SVG)
+        {
+          setupSVG(width, height, fileTitle);
+        }
+        else if (type == TYPE.EPS)
         {
-          setupEPS(width, height, EPStitle);
+          setupEPS(width, height, fileTitle);
         }
-        else
+        else if (type == TYPE.PNG)
         {
           setupPNG(width, height);
         }
+      
       } catch (Exception ex)
       {
         System.out.println("Error creating "
-                + (type == EPS ? "EPS" : "PNG") + " file.");
+ + type.getName() + " file.");
       }
     }
   }
@@ -98,14 +152,7 @@ public class ImageMaker
     return graphics;
   }
 
-  void setupPNG(int width, int height)
-  {
-    bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
-    graphics = bi.getGraphics();
-    Graphics2D ig2 = (Graphics2D) graphics;
-    ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-            RenderingHints.VALUE_ANTIALIAS_ON);
-  }
+
 
   public void writeImage()
   {
@@ -117,6 +164,11 @@ public class ImageMaker
         pg.flush();
         pg.close();
         break;
+      case SVG:
+        String svg = ((SVGGraphics2D) getGraphics()).getSVGDocument();
+        out.write(svg.getBytes());
+        out.close();
+        break;
       case PNG:
         ImageIO.write(bi, "png", out);
         out.close();
@@ -158,7 +210,7 @@ public class ImageMaker
     try
     {
       pg = new EpsGraphics2D(title, out, 0, 0, width, height);
-      Graphics2D ig2 = (Graphics2D) pg;
+      Graphics2D ig2 = pg;
       ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
               RenderingHints.VALUE_ANTIALIAS_ON);
 
@@ -170,7 +222,22 @@ public class ImageMaker
     }
   }
 
-  JalviewFileChooser getPNGChooser()
+  void setupPNG(int width, int height)
+  {
+    bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+    graphics = bi.getGraphics();
+    Graphics2D ig2 = (Graphics2D) graphics;
+    ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+            RenderingHints.VALUE_ANTIALIAS_ON);
+  }
+
+  void setupSVG(int width, int height, String title)
+  {
+    g2 = new SVGGraphics2D(width, height);
+    graphics = g2;
+  }
+
+  static JalviewFileChooser getPNGChooser()
   {
     return new jalview.io.JalviewFileChooser(
             jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
@@ -178,11 +245,19 @@ public class ImageMaker
             { "Portable network graphics" }, "Portable network graphics");
   }
 
-  JalviewFileChooser getEPSChooser()
+  static JalviewFileChooser getEPSChooser()
   {
     return new jalview.io.JalviewFileChooser(
             jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
             { "eps" }, new String[]
             { "Encapsulated Postscript" }, "Encapsulated Postscript");
   }
+
+  static JalviewFileChooser getSVGChooser()
+  {
+    return new jalview.io.JalviewFileChooser(
+            jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
+            { "svg" }, new String[]
+            { "Scalable Vector Graphics" }, "Scalable Vector Graphics");
+  }
 }