import java.awt.event.*;\r
import java.awt.print.*;\r
\r
+import com.sun.image.codec.jpeg.*;\r
+import java.io.*;\r
+import java.awt.image.*;\r
+\r
+\r
public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListener, Printable\r
{\r
\r
repaint();\r
}\r
\r
-\r
-\r
public int print(Graphics pg, PageFormat pf, int pi) throws PrinterException\r
{\r
- if(av.getWrapAlignment())\r
- {\r
- return PrintWrappedAlignment(pg, pf, pi);\r
- }\r
-\r
pg.translate((int)pf.getImageableX(), (int)pf.getImageableY());\r
\r
- int pwidth = (int)pf.getImageableWidth();\r
- int pheight = (int)pf.getImageableHeight();\r
+ int pwidth = (int) pf.getImageableWidth();\r
+ int pheight = (int) pf.getImageableHeight();\r
+\r
+ if (av.getWrapAlignment())\r
+ return printWrappedAlignment(pg, pwidth,pheight, pi);\r
+ else\r
+ return printUnwrapped(pg,pwidth, pheight,pi);\r
+ }\r
+\r
+ public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi) throws PrinterException\r
+ {\r
+\r
int idWidth = (int)idPanel.idCanvas.getLabelWidth().getWidth();\r
\r
\r
return Printable.PAGE_EXISTS;\r
}\r
\r
- class VPanel extends javax.swing.JPanel\r
- {\r
- Image image;\r
- public VPanel(Image i)\r
- {\r
- image = i;\r
- repaint();\r
- }\r
- public void paintComponent(Graphics g)\r
- {\r
- if(image!=null)\r
- g.drawImage(image,0,0,this);\r
- }\r
\r
- }\r
-\r
- public int PrintWrappedAlignment(Graphics pg, PageFormat pf, int pi)\r
+ public int printWrappedAlignment(Graphics pg, int pwidth, int pheight, int pi) throws PrinterException\r
{\r
- pg.translate((int)pf.getImageableX(), (int)pf.getImageableY());\r
\r
- int pwidth = (int)pf.getImageableWidth();\r
- int pheight = (int)pf.getImageableHeight();\r
int idWidth = (int)idPanel.idCanvas.getLabelWidth().getWidth();\r
\r
if( seqPanel.seqCanvas.getWidth() < pwidth-idWidth)\r
pwidth = seqPanel.seqCanvas.getWidth() + idWidth;\r
\r
+\r
pg.setColor(Color.white);\r
pg.fillRect(0,0,pwidth, pheight);\r
pg.setFont( av.getFont() );\r
int chunkWidth = (pwidth-idWidth)/av.charWidth;\r
\r
int noChunksOnPage = pheight / chunkHeight;\r
- int totalChunks = endy / chunkHeight;\r
+ int totalChunks = da.getWidth() / chunkWidth;\r
\r
if ( pi*noChunksOnPage > totalChunks )\r
return Printable.NO_SUCH_PAGE;\r
seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth-idWidth, pheight, pi*noChunksOnPage*chunkWidth);\r
\r
\r
- return Printable.NO_SUCH_PAGE;//.PAGE_EXISTS;\r
+ return Printable.PAGE_EXISTS;\r
\r
}\r
+\r
+ public void makeJPG(int width, int height)\r
+ {\r
+ try\r
+ {\r
+\r
+ BufferedImage bi = new BufferedImage(width, height,\r
+ BufferedImage.TYPE_INT_RGB);\r
+ Graphics pg = bi.getGraphics();\r
+\r
+ try\r
+ {\r
+ if (av.getWrapAlignment())\r
+ printWrappedAlignment(pg, width, height, 0);\r
+ else\r
+ printUnwrapped(pg, width, height, 0);\r
+ }\r
+ catch (Exception ex)\r
+ {}\r
+\r
+ javax.swing.JFileChooser chooser = new javax.swing.JFileChooser(jalview.bin.Cache.getProperty(\r
+ "LAST_DIRECTORY"));\r
+ chooser.setDialogTitle("Create JPG image from alignment");\r
+ chooser.setToolTipText("Save");\r
+\r
+ int value = chooser.showSaveDialog(this);\r
+ if (value == javax.swing.JFileChooser.APPROVE_OPTION)\r
+ {\r
+\r
+ FileOutputStream out = new FileOutputStream(chooser.getSelectedFile());\r
+ JPEGImageEncoder jie = JPEGCodec.createJPEGEncoder(out);\r
+ JPEGEncodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(bi);\r
+ param.setQuality(1.0f, true);\r
+\r
+ jie.encode(bi, param);\r
+ out.close();\r
+ }\r
+\r
+ }\r
+ catch (IOException ex)\r
+ {\r
+ System.out.println("ex Writing image ");\r
+ }\r
+ }\r
+\r
}\r
\r
\r
JMenuItem pasteNew = new JMenuItem();\r
JMenuItem pasteThis = new JMenuItem();\r
protected JCheckBoxMenuItem applyToAllGroups = new JCheckBoxMenuItem();\r
+ JMenuItem createJPG = new JMenuItem();\r
public GAlignFrame()\r
{\r
\r
colourMenu.setText("Colour");\r
calculateMenu.setText("Calculate");\r
alignMenu.setText("Web Service");\r
+ groupsMenuItem.setEnabled(false);\r
groupsMenuItem.setText("Groups");\r
groupsMenuItem.addActionListener(new java.awt.event.ActionListener()\r
{\r
applyToAllGroups_actionPerformed(e);\r
}\r
});\r
+ createJPG.addActionListener(new java.awt.event.ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ createJPG_actionPerformed(e);\r
+ }\r
+ });\r
+ createJPG.setText("Save as JPG Image");\r
alignFrameMenuBar.add(fileMenu);\r
alignFrameMenuBar.add(editMenu);\r
alignFrameMenuBar.add(searchMenu);\r
fileMenu.add(saveAlignmentMenu);\r
fileMenu.add(outputTextboxMenu);\r
fileMenu.add(htmlMenuItem);\r
+ fileMenu.add(createJPG);\r
fileMenu.add(printMenuItem);\r
fileMenu.addSeparator();\r
fileMenu.add(closeMenuItem);\r
\r
}\r
\r
+ protected void createJPG_actionPerformed(ActionEvent e)\r
+ {\r
+\r
+ }\r
+\r
\r
\r
}\r