import java.awt.event.*;\r
\r
import java.util.*;\r
-import javax.swing.JOptionPane;\r
-import javax.swing.JInternalFrame;\r
+import javax.swing.*;\r
+import java.io.FileOutputStream;\r
+import org.jibble.epsgraphics.EpsGraphics2D;\r
+import javax.imageio.ImageIO;\r
+import java.awt.image.BufferedImage;\r
+import java.awt.print.*;\r
\r
\r
/**\r
return;\r
}\r
\r
- JInternalFrame frame = new JInternalFrame();\r
- frame.setContentPane(this);\r
- Desktop.addInternalFrame(frame, "Principal component analysis",\r
+\r
+ Desktop.addInternalFrame(this, "Principal component analysis",\r
400, 400);\r
\r
\r
rc = new RotatableCanvas(av);\r
- add(rc, BorderLayout.CENTER);\r
+ this.getContentPane().add(rc, BorderLayout.CENTER);\r
Thread worker = new Thread(this);\r
worker.start();\r
}\r
\r
+ public void bgcolour_actionPerformed(ActionEvent e)\r
+ {\r
+ Color col = JColorChooser.showDialog(this, "Select Background Colour",\r
+ rc.bgColour);\r
+\r
+ if(col!=null)\r
+ rc.bgColour = col;\r
+ rc.repaint();\r
+ }\r
+\r
+\r
\r
\r
/**\r
{\r
doDimensionChange();\r
}\r
-}\r
+\r
+\r
+ public void outputValues_actionPerformed(ActionEvent e)\r
+ {\r
+ CutAndPasteTransfer cap = new CutAndPasteTransfer();\r
+ Desktop.addInternalFrame(cap, "PCA details", 500,\r
+ 500);\r
+\r
+ cap.setText(pca.getDetails());\r
+ }\r
+\r
+ public void showLabels_actionPerformed(ActionEvent e)\r
+ {\r
+ rc.showLabels(showLabels.getState());\r
+ }\r
+\r
+ public void print_actionPerformed(ActionEvent e)\r
+ {\r
+ PCAPrinter printer = new PCAPrinter();\r
+ printer.start();\r
+ }\r
+\r
+\r
+ class PCAPrinter extends Thread implements Printable\r
+ {\r
+ public void run()\r
+ {\r
+ PrinterJob printJob = PrinterJob.getPrinterJob();\r
+ PageFormat pf = printJob.pageDialog(printJob.defaultPage());\r
+\r
+ printJob.setPrintable(this, pf);\r
+\r
+ if (printJob.printDialog())\r
+ {\r
+ try\r
+ {\r
+ printJob.print();\r
+ }\r
+ catch (Exception PrintException)\r
+ {\r
+ PrintException.printStackTrace();\r
+ }\r
+ }\r
+ }\r
+\r
+ public int print(Graphics pg, PageFormat pf, int pi)\r
+ throws PrinterException\r
+ {\r
+ pg.translate( (int) pf.getImageableX(), (int) pf.getImageableY());\r
+\r
+ rc.drawBackground(pg, rc.bgColour);\r
+ rc.drawScene(pg);\r
+ if (rc.drawAxes == true)\r
+ {\r
+ rc.drawAxes(pg);\r
+ }\r
+\r
+ if (pi == 0)\r
+ return Printable.PAGE_EXISTS;\r
+ else\r
+ return Printable.NO_SUCH_PAGE;\r
+ }\r
+ }\r
+\r
+\r
+\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void eps_actionPerformed(ActionEvent e)\r
+ {\r
+ boolean accurateText = true;\r
+\r
+ String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING",\r
+ "Prompt each time");\r
+\r
+ // If we need to prompt, and if the GUI is visible then\r
+ // Prompt for EPS rendering style\r
+ if (renderStyle.equalsIgnoreCase("Prompt each time")\r
+ && !\r
+ (System.getProperty("java.awt.headless") != null\r
+ && System.getProperty("java.awt.headless").equals("true")))\r
+ {\r
+ EPSOptions eps = new EPSOptions();\r
+ renderStyle = eps.getValue();\r
+\r
+ if (renderStyle == null || eps.cancelled)\r
+ return;\r
+\r
+ }\r
+\r
+ if (renderStyle.equalsIgnoreCase("text"))\r
+ {\r
+ accurateText = false;\r
+ }\r
+\r
+ int width = rc.getWidth();\r
+ int height = rc.getHeight();\r
+\r
+ try\r
+ {\r
+ jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(\r
+ jalview.bin.Cache.getProperty(\r
+ "LAST_DIRECTORY"), new String[]\r
+ {"eps"},\r
+ new String[]\r
+ {"Encapsulated Postscript"},\r
+ "Encapsulated Postscript");\r
+ chooser.setFileView(new jalview.io.JalviewFileView());\r
+ chooser.setDialogTitle("Create EPS file from PCA");\r
+ chooser.setToolTipText("Save");\r
+\r
+ int value = chooser.showSaveDialog(this);\r
+\r
+ if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION)\r
+ {\r
+ return;\r
+ }\r
+\r
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY",\r
+ chooser.getSelectedFile().getParent());\r
+\r
+ FileOutputStream out = new FileOutputStream(chooser.getSelectedFile());\r
+ EpsGraphics2D pg = new EpsGraphics2D("PCA", out, 0, 0, width,\r
+ height);\r
+\r
+ pg.setAccurateTextMode(accurateText);\r
+\r
+ rc.drawBackground(pg, rc.bgColour);\r
+ rc.drawScene(pg);\r
+\r
+ if (rc.drawAxes == true)\r
+ {\r
+ rc.drawAxes(pg);\r
+ }\r
+\r
+\r
+ pg.flush();\r
+ pg.close();\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void png_actionPerformed(ActionEvent e)\r
+ {\r
+ int width = rc.getWidth();\r
+ int height = rc.getHeight();\r
+\r
+ try\r
+ {\r
+ jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(\r
+ jalview.bin.Cache.getProperty(\r
+ "LAST_DIRECTORY"), new String[]\r
+ {"png"},\r
+ new String[]\r
+ {"Portable network graphics"},\r
+ "Portable network graphics");\r
+\r
+ chooser.setFileView(new jalview.io.JalviewFileView());\r
+ chooser.setDialogTitle("Create PNG image from PCA");\r
+ chooser.setToolTipText("Save");\r
+\r
+ int value = chooser.showSaveDialog(this);\r
+\r
+ if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION)\r
+ {\r
+ return;\r
+ }\r
+\r
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY",\r
+ chooser.getSelectedFile().getParent());\r
+\r
+ FileOutputStream out = new FileOutputStream(chooser.getSelectedFile());\r
+\r
+ BufferedImage bi = new BufferedImage(width, height,\r
+ BufferedImage.TYPE_INT_RGB);\r
+ Graphics big = bi.getGraphics();\r
+\r
+ big.drawImage(rc.img,0,0,this);\r
+\r
+ ImageIO.write(bi, "png", out);\r
+ out.close();\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ }\r
+\r
+ }\r
import javax.swing.*;\r
\r
public class GPCAPanel\r
- extends JPanel\r
+ extends JInternalFrame\r
{\r
JPanel jPanel2 = new JPanel();\r
JLabel jLabel1 = new JLabel();\r
protected JComboBox zCombobox = new JComboBox();\r
FlowLayout flowLayout1 = new FlowLayout();\r
BorderLayout borderLayout1 = new BorderLayout();\r
+ JMenuBar jMenuBar1 = new JMenuBar();\r
+ JMenu fileMenu = new JMenu();\r
+ JMenu saveMenu = new JMenu();\r
+ JMenuItem eps = new JMenuItem();\r
+ JMenuItem png = new JMenuItem();\r
+ JMenuItem print = new JMenuItem();\r
+ JMenuItem outputValues = new JMenuItem();\r
+ JMenu viewMenu = new JMenu();\r
+ protected JCheckBoxMenuItem showLabels = new JCheckBoxMenuItem();\r
+ JMenuItem bgcolour = new JMenuItem();\r
\r
public GPCAPanel()\r
{\r
yCombobox.addItem("dim " + i);\r
zCombobox.addItem("dim " + i);\r
}\r
+\r
+\r
+ setJMenuBar(jMenuBar1);\r
}\r
\r
private void jbInit()\r
throws Exception\r
{\r
- this.setLayout(borderLayout1);\r
+ this.getContentPane().setLayout(borderLayout1);\r
jPanel2.setLayout(flowLayout1);\r
jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));\r
jLabel1.setText("x=");\r
xCombobox_actionPerformed(e);\r
}\r
});\r
- this.add(jPanel2, BorderLayout.SOUTH);\r
+ fileMenu.setText("File");\r
+ saveMenu.setText("Save as");\r
+ eps.setText("EPS");\r
+ eps.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ eps_actionPerformed(e);\r
+ }\r
+ });\r
+ png.setText("PNG");\r
+ png.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ png_actionPerformed(e);\r
+ }\r
+ });\r
+ outputValues.setText("Output Values...");\r
+ outputValues.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ outputValues_actionPerformed(e);\r
+ }\r
+ });\r
+ print.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ print_actionPerformed(e);\r
+ }\r
+ });\r
+ viewMenu.setText("View");\r
+ showLabels.setText("Show Labels");\r
+ showLabels.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ showLabels_actionPerformed(e);\r
+ }\r
+ });\r
+ print.setText("Print");\r
+ bgcolour.setText("Background Colour...");\r
+ bgcolour.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ bgcolour_actionPerformed(e);\r
+ }\r
+ });\r
+ this.getContentPane().add(jPanel2, BorderLayout.SOUTH);\r
jPanel2.add(jLabel1, null);\r
jPanel2.add(xCombobox, null);\r
jPanel2.add(jLabel2, null);\r
jPanel2.add(yCombobox, null);\r
jPanel2.add(jLabel3, null);\r
jPanel2.add(zCombobox, null);\r
+ jMenuBar1.add(fileMenu);\r
+ jMenuBar1.add(viewMenu);\r
+ fileMenu.add(saveMenu);\r
+ fileMenu.add(outputValues);\r
+ fileMenu.add(print);\r
+ saveMenu.add(eps);\r
+ saveMenu.add(png);\r
+ viewMenu.add(showLabels);\r
+ viewMenu.add(bgcolour);\r
}\r
\r
protected void xCombobox_actionPerformed(ActionEvent e)\r
protected void zCombobox_actionPerformed(ActionEvent e)\r
{\r
}\r
+\r
+ public void eps_actionPerformed(ActionEvent e)\r
+ {\r
+\r
+ }\r
+\r
+ public void png_actionPerformed(ActionEvent e)\r
+ {\r
+\r
+ }\r
+\r
+ public void outputValues_actionPerformed(ActionEvent e)\r
+ {\r
+\r
+ }\r
+\r
+ public void print_actionPerformed(ActionEvent e)\r
+ {\r
+\r
+ }\r
+\r
+ public void showLabels_actionPerformed(ActionEvent e)\r
+ {\r
+\r
+ }\r
+\r
+ public void bgcolour_actionPerformed(ActionEvent e)\r
+ {\r
+\r
+ }\r
}\r