Skip to content
Snippets Groups Projects
Commit 643e0b8b authored by tcarver's avatar tcarver
Browse files

add svg support

parent 67487bb8
No related branches found
No related tags found
No related merge requests found
art 100755 → 100644
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
# necessary a symbolic link can be made to this script from # necessary a symbolic link can be made to this script from
# /usr/local/bin/ or elsewhere. # /usr/local/bin/ or elsewhere.
# $Header: //tmp/pathsoft/artemis/art,v 1.26 2009-09-21 15:45:47 tjc Exp $
# resolve links - $0 may be a link # resolve links - $0 may be a link
PRG=$0 PRG=$0
progname=`basename $0` progname=`basename $0`
...@@ -30,6 +28,9 @@ LIBDIR=/nfs/pathsoft/prod/javalibs ...@@ -30,6 +28,9 @@ LIBDIR=/nfs/pathsoft/prod/javalibs
CLASSPATH=$ARTEMIS_HOME:$ARTEMIS_HOME/lib/biojava.jar:$ARTEMIS_HOME/lib/jemAlign.jar:$ARTEMIS_HOME/lib/jakarta-regexp-1.2.jar:$ARTEMIS_HOME/lib/macos.jar:$ARTEMIS_HOME/lib/postgresql-8.4-701.jdbc3.jar:$CLASSPATH CLASSPATH=$ARTEMIS_HOME:$ARTEMIS_HOME/lib/biojava.jar:$ARTEMIS_HOME/lib/jemAlign.jar:$ARTEMIS_HOME/lib/jakarta-regexp-1.2.jar:$ARTEMIS_HOME/lib/macos.jar:$ARTEMIS_HOME/lib/postgresql-8.4-701.jdbc3.jar:$CLASSPATH
# batik jars
CLASSPATH=$CLASSPATH:$ARTEMIS_HOME/lib/batik/batik-awt-util.jar:$ARTEMIS_HOME/lib/batik/batik-dom.jar:$ARTEMIS_HOME/lib/batik/batik-ext.jar:$ARTEMIS_HOME/lib/batik/batik-svggen.jar:$ARTEMIS_HOME/lib/batik/batik-util.jar:$ARTEMIS_HOME/lib/batik/batik-xml.jar
# j2ssh jars # j2ssh jars
CLASSPATH=$CLASSPATH:$ARTEMIS_HOME/lib/j2ssh/commons-logging.jar:$ARTEMIS_HOME/lib/j2ssh/j2ssh-core.jar:$ARTEMIS_HOME/lib/j2ssh/ CLASSPATH=$CLASSPATH:$ARTEMIS_HOME/lib/j2ssh/commons-logging.jar:$ARTEMIS_HOME/lib/j2ssh/j2ssh-core.jar:$ARTEMIS_HOME/lib/j2ssh/
......
...@@ -68,6 +68,8 @@ import javax.swing.UIManager; ...@@ -68,6 +68,8 @@ import javax.swing.UIManager;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JFrame; import javax.swing.JFrame;
import org.apache.batik.svggen.SVGGraphics2D;
/** /**
* This component is used for displaying an Entry. * This component is used for displaying an Entry.
* *
...@@ -1890,8 +1892,19 @@ public class FeatureDisplay extends EntryGroupPanel ...@@ -1890,8 +1892,19 @@ public class FeatureDisplay extends EntryGroupPanel
// draw fwd bases // draw fwd bases
if(getScaleFactor() == 0) if(getScaleFactor() == 0)
g.drawString(forward_visible_bases, offset * getFontWidth(), {
yposition + getFontAscent() + 1); if(!(g instanceof SVGGraphics2D))
g.drawString(forward_visible_bases, offset * getFontWidth(),
yposition + getFontAscent() + 1);
else
{
// for svg graphics
for(int i=0;i<forward_visible_bases.length();i++)
g.drawString(String.valueOf(forward_visible_bases.charAt(i)),
(offset+i)*getFontWidth(),
yposition + getFontAscent() + 1);
}
}
else else
{ {
for(int base_index = 0; base_index < forward_sequence_length; for(int base_index = 0; base_index < forward_sequence_length;
...@@ -1914,8 +1927,19 @@ public class FeatureDisplay extends EntryGroupPanel ...@@ -1914,8 +1927,19 @@ public class FeatureDisplay extends EntryGroupPanel
// draw bwd bases // draw bwd bases
if(getScaleFactor() == 0) if(getScaleFactor() == 0)
g.drawString(reverse_visible_bases, offset * getFontWidth(), {
yposition + getFontAscent() + 1); if(!(g instanceof SVGGraphics2D))
g.drawString(reverse_visible_bases, offset * getFontWidth(),
yposition + getFontAscent() + 1);
else
{
// for svg graphics
for(int i=0;i<reverse_visible_bases.length();i++)
g.drawString(String.valueOf(reverse_visible_bases.charAt(i)),
(offset+i)*getFontWidth(),
yposition + getFontAscent() + 1);
}
}
else else
{ {
for(int base_index = 0; base_index < reverse_sequence_length; for(int base_index = 0; base_index < reverse_sequence_length;
...@@ -2200,8 +2224,15 @@ public class FeatureDisplay extends EntryGroupPanel ...@@ -2200,8 +2224,15 @@ public class FeatureDisplay extends EntryGroupPanel
else else
draw_x_position = (int)((offset + frame_start + 1) * getScaleValue()); draw_x_position = (int)((offset + frame_start + 1) * getScaleValue());
g.drawString(codons, draw_x_position, if(!(g instanceof SVGGraphics2D))
g.drawString(codons, draw_x_position,
draw_y_position + getFontAscent() + 1); draw_y_position + getFontAscent() + 1);
else
{
for(int i=0;i<codons.length();i++)
g.drawString(String.valueOf(codons.charAt(i)), draw_x_position+(i*getFontWidth() ),
draw_y_position + getFontAscent() + 1);
}
} }
/** /**
......
...@@ -51,6 +51,8 @@ import javax.swing.JMenuItem; ...@@ -51,6 +51,8 @@ import javax.swing.JMenuItem;
import javax.swing.JScrollBar; import javax.swing.JScrollBar;
import javax.swing.JPopupMenu; import javax.swing.JPopupMenu;
import org.apache.batik.svggen.SVGGraphics2D;
/** /**
* This class implements a simple plot component. * This class implements a simple plot component.
* @author Kim Rutherford * @author Kim Rutherford
...@@ -682,11 +684,17 @@ public abstract class Plot extends JPanel ...@@ -682,11 +684,17 @@ public abstract class Plot extends JPanel
if(offscreen == null || lastPaintHeight != height) if(offscreen == null || lastPaintHeight != height)
offscreen = createImage(width, height); offscreen = createImage(width, height);
Graphics og = offscreen.getGraphics(); final Graphics og;
og.setClip(0, 0, width, height); if(g instanceof SVGGraphics2D)
og.setColor(Color.WHITE); og = g;
og.fillRect(0, 0, width, height); else
{
og = offscreen.getGraphics();
og.setClip(0, 0, width, height);
og.setColor(Color.WHITE);
og.fillRect(0, 0, width, height);
}
// Redraw the graph on the canvas using the algorithm from the // Redraw the graph on the canvas using the algorithm from the
// constructor. // constructor.
...@@ -703,8 +711,12 @@ public abstract class Plot extends JPanel ...@@ -703,8 +711,12 @@ public abstract class Plot extends JPanel
numPlots = drawMultiValueGraph(og,lines); numPlots = drawMultiValueGraph(og,lines);
drawLabels(og,numPlots); drawLabels(og,numPlots);
g.drawImage(offscreen, 0, 0, null);
og.dispose(); if( !(g instanceof SVGGraphics2D) )
{
g.drawImage(offscreen, 0, 0, null);
og.dispose();
}
lastPaintHeight = height; lastPaintHeight = height;
} }
......
...@@ -29,9 +29,24 @@ import java.awt.print.Printable; ...@@ -29,9 +29,24 @@ import java.awt.print.Printable;
import java.awt.print.PrinterException; import java.awt.print.PrinterException;
import java.awt.print.PrinterJob; import java.awt.print.PrinterJob;
import java.awt.event.*; import java.awt.event.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import javax.swing.*; import javax.swing.*;
import java.io.*;
import org.apache.batik.dom.GenericDOMImplementation;
import org.apache.batik.svggen.SVGGeneratorContext;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.svggen.SVGGraphics2DIOException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import uk.ac.sanger.artemis.Options;
import uk.ac.sanger.artemis.editor.ScrollPanel; import uk.ac.sanger.artemis.editor.ScrollPanel;
/** /**
...@@ -66,15 +81,45 @@ public class PrintArtemis extends ScrollPanel implements Printable ...@@ -66,15 +81,45 @@ public class PrintArtemis extends ScrollPanel implements Printable
} }
/** /**
*
* Override paintComponent to draw entry * Override paintComponent to draw entry
*
*/ */
public void paintComponent(Graphics g) public void paintComponent(Graphics g2d)
{ {
// let UI delegate paint first (incl. background filling) // let UI delegate paint first (incl. background filling)
super.paintComponent(g); super.paintComponent(g2d);
Graphics2D g2d = (Graphics2D)g.create();
// feature list
if(featListDisplay.isSelected())
{
FeatureList flist = entry.getFeatureList();
Point ploc = flist.getViewport().getViewPosition();
try
{
int translateX = 0;
if(selectDisplay.isSelected())
translateX += entry.getSelectionInfoDisplay().getHeight();
if(groupsDisplay.isSelected())
translateX += entry.getEntryGroupDisplay().getHeight();
if(plotsDisplay.isSelected())
translateX += entry.getBasePlotGroup().getHeight();
if(jamDisplay.isSelected() && entry.getBamPanel() != null && entry.getBamPanel().isVisible())
translateX += entry.getBamPanel().getHeight()-1;
if(vcfDisplay.isSelected() && entry.getVcfView() != null && entry.getVcfView().isVisible())
translateX += entry.getVcfPanel().getHeight();
if(onelineDisplay.isSelected())
translateX += entry.getOneLinePerEntryDisplay().getHeight();
if(featDisplay.isSelected())
translateX += entry.getFeatureDisplay().getHeight();
if(baseDisplay.isSelected())
translateX += entry.getBaseDisplay().getHeight();
translateX-=2+ploc.y;
g2d.translate(0,translateX);
flist.paintComponent(g2d);
g2d.translate(0,-translateX);
}
catch(IllegalArgumentException e){} // thrown if the list is not visible
}
// selection info // selection info
if(selectDisplay.isSelected()) if(selectDisplay.isSelected())
...@@ -128,24 +173,9 @@ public class PrintArtemis extends ScrollPanel implements Printable ...@@ -128,24 +173,9 @@ public class PrintArtemis extends ScrollPanel implements Printable
entry.getBaseDisplay().paintComponent(g2d); entry.getBaseDisplay().paintComponent(g2d);
g2d.translate(0,entry.getBaseDisplay().getHeight()); g2d.translate(0,entry.getBaseDisplay().getHeight());
} }
// feature list
if(featListDisplay.isSelected())
{
FeatureList flist = entry.getFeatureList();
Point ploc = flist.getViewport().getViewPosition();
try
{
BufferedImage offScreen = new BufferedImage(flist.getViewport().getWidth(),
flist.getViewport().getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics og = offScreen.getGraphics();
og.translate(0,-ploc.y);
flist.paintComponent(og);
g2d.drawImage(offScreen, 0, 0, null);
}
catch(IllegalArgumentException e){} // thrown if the list is not visible
}
} }
/** /**
...@@ -153,7 +183,7 @@ public class PrintArtemis extends ScrollPanel implements Printable ...@@ -153,7 +183,7 @@ public class PrintArtemis extends ScrollPanel implements Printable
* Set the size of the image * Set the size of the image
* *
*/ */
private void setImageSize() private Dimension getImageSize()
{ {
height = 0; height = 0;
width = entry.getFeatureDisplay().getDisplayWidth(); width = entry.getFeatureDisplay().getDisplayWidth();
...@@ -185,9 +215,14 @@ public class PrintArtemis extends ScrollPanel implements Printable ...@@ -185,9 +215,14 @@ public class PrintArtemis extends ScrollPanel implements Printable
if(featListDisplay.isSelected()) if(featListDisplay.isSelected())
height += entry.getFeatureList().getViewport().getExtentSize().height; height += entry.getFeatureList().getViewport().getExtentSize().height;
setPreferredSize(new Dimension(width,height)); return new Dimension(width,height);
} }
private void setImageSize()
{
setPreferredSize(getImageSize());
}
/** /**
* *
* Display a print preview page * Display a print preview page
...@@ -391,6 +426,15 @@ public class PrintArtemis extends ScrollPanel implements Printable ...@@ -391,6 +426,15 @@ public class PrintArtemis extends ScrollPanel implements Printable
f.setVisible(true); f.setVisible(true);
} }
private String[] getImageFormats()
{
final String fmts[] = javax.imageio.ImageIO.getWriterFormatNames();
final String tmpFmts[] = new String[fmts.length+1];
System.arraycopy(fmts, 0, tmpFmts, 0, fmts.length);
tmpFmts[tmpFmts.length-1] = "svg";
return tmpFmts;
}
/** /**
* *
* Print to a jpeg or png file * Print to a jpeg or png file
...@@ -399,7 +443,7 @@ public class PrintArtemis extends ScrollPanel implements Printable ...@@ -399,7 +443,7 @@ public class PrintArtemis extends ScrollPanel implements Printable
public void print() public void print()
{ {
// file chooser // file chooser
StickyFileChooser fc = new StickyFileChooser(); final StickyFileChooser fc = new StickyFileChooser();
File fselect = new File(fc.getCurrentDirectory()+ File fselect = new File(fc.getCurrentDirectory()+
System.getProperty("file.separator")+ System.getProperty("file.separator")+
"artemis.png"); "artemis.png");
...@@ -413,9 +457,27 @@ public class PrintArtemis extends ScrollPanel implements Printable ...@@ -413,9 +457,27 @@ public class PrintArtemis extends ScrollPanel implements Printable
YBox.add(labFormat); YBox.add(labFormat);
Box bacross = Box.createHorizontalBox(); Box bacross = Box.createHorizontalBox();
JComboBox formatSelect = final JComboBox formatSelect = new JComboBox(getImageFormats());
new JComboBox(javax.imageio.ImageIO.getWriterFormatNames());
formatSelect.setSelectedItem("png"); formatSelect.setSelectedItem("png");
formatSelect.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
String selected;
if(fc.getSelectedFile() != null)
{
selected = fc.getSelectedFile().getAbsolutePath();
String fmts[] = getImageFormats();
for(int i=0; i<fmts.length; i++)
selected = selected.replaceAll("."+fmts[i]+"$", "");
}
else
selected = "artemis";
fc.setSelectedFile(new File(selected+"."+
formatSelect.getSelectedItem()));
}
});
Dimension d = formatSelect.getPreferredSize(); Dimension d = formatSelect.getPreferredSize();
formatSelect.setMaximumSize(d); formatSelect.setMaximumSize(d);
...@@ -488,6 +550,13 @@ public class PrintArtemis extends ScrollPanel implements Printable ...@@ -488,6 +550,13 @@ public class PrintArtemis extends ScrollPanel implements Printable
// remove file extension // remove file extension
String fsave = fc.getSelectedFile().getAbsolutePath().toLowerCase(); String fsave = fc.getSelectedFile().getAbsolutePath().toLowerCase();
if(fsave.endsWith(".svg"))
{
createSVG(fc.getSelectedFile());
return;
}
if(fsave.endsWith(".png") || if(fsave.endsWith(".png") ||
fsave.endsWith(".jpg") || fsave.endsWith(".jpg") ||
fsave.endsWith(".jpeg") ) fsave.endsWith(".jpeg") )
...@@ -514,6 +583,45 @@ public class PrintArtemis extends ScrollPanel implements Printable ...@@ -514,6 +583,45 @@ public class PrintArtemis extends ScrollPanel implements Printable
} }
} }
private void createSVG(final File fout)
{
final DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
final Document doc = domImpl.createDocument(
"http://www.w3.org/2000/svg", "svg", null);
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(doc);
ctx.setComment("Generated by Artemis with Batik SVG Generator");
final SVGGraphics2D svgG = new SVGGraphics2D(ctx, true);
svgG.setFont(Options.getOptions().getFont());
final FontMetrics fm = svgG.getFontMetrics();
final Dimension d = getImageSize();
svgG.setSVGCanvasSize( new Dimension(
d.width+fm.stringWidth(" "), d.height+fm.getHeight()) );
paintComponent(svgG);
try
{
final Writer out = new OutputStreamWriter(
new FileOutputStream(fout), "UTF-8");
svgG.stream(out, true);
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
catch (SVGGraphics2DIOException e)
{
e.printStackTrace();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
return;
}
protected void doPrintActions() protected void doPrintActions()
{ {
final PrinterJob pj=PrinterJob.getPrinterJob(); final PrinterJob pj=PrinterJob.getPrinterJob();
...@@ -575,7 +683,7 @@ public class PrintArtemis extends ScrollPanel implements Printable ...@@ -575,7 +683,7 @@ public class PrintArtemis extends ScrollPanel implements Printable
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException
{ {
setImageSize(); setImageSize();
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D)g.create();
// RepaintManager.currentManager(this).setDoubleBufferingEnabled(false); // RepaintManager.currentManager(this).setDoubleBufferingEnabled(false);
Dimension d = this.getSize(); //get size of document Dimension d = this.getSize(); //get size of document
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment