From: amwaterhouse Date: Fri, 23 Sep 2005 16:16:53 +0000 (+0000) Subject: Now an InternalFrame with menus X-Git-Tag: Release_2_06~15 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d4cf3b864ffb4d148389a3cdb788e43efd4e4b47;p=jalview.git Now an InternalFrame with menus --- diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index 26f1160..71891aa 100755 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -28,8 +28,12 @@ import java.awt.*; import java.awt.event.*; import java.util.*; -import javax.swing.JOptionPane; -import javax.swing.JInternalFrame; +import javax.swing.*; +import java.io.FileOutputStream; +import org.jibble.epsgraphics.EpsGraphics2D; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.awt.print.*; /** @@ -102,18 +106,28 @@ public class PCAPanel extends GPCAPanel implements Runnable return; } - JInternalFrame frame = new JInternalFrame(); - frame.setContentPane(this); - Desktop.addInternalFrame(frame, "Principal component analysis", + + Desktop.addInternalFrame(this, "Principal component analysis", 400, 400); rc = new RotatableCanvas(av); - add(rc, BorderLayout.CENTER); + this.getContentPane().add(rc, BorderLayout.CENTER); Thread worker = new Thread(this); worker.start(); } + public void bgcolour_actionPerformed(ActionEvent e) + { + Color col = JColorChooser.showDialog(this, "Select Background Colour", + rc.bgColour); + + if(col!=null) + rc.bgColour = col; + rc.repaint(); + } + + /** @@ -233,4 +247,204 @@ public class PCAPanel extends GPCAPanel implements Runnable { doDimensionChange(); } -} + + + public void outputValues_actionPerformed(ActionEvent e) + { + CutAndPasteTransfer cap = new CutAndPasteTransfer(); + Desktop.addInternalFrame(cap, "PCA details", 500, + 500); + + cap.setText(pca.getDetails()); + } + + public void showLabels_actionPerformed(ActionEvent e) + { + rc.showLabels(showLabels.getState()); + } + + public void print_actionPerformed(ActionEvent e) + { + PCAPrinter printer = new PCAPrinter(); + printer.start(); + } + + + class PCAPrinter extends Thread implements Printable + { + public void run() + { + PrinterJob printJob = PrinterJob.getPrinterJob(); + PageFormat pf = printJob.pageDialog(printJob.defaultPage()); + + printJob.setPrintable(this, pf); + + if (printJob.printDialog()) + { + try + { + printJob.print(); + } + catch (Exception PrintException) + { + PrintException.printStackTrace(); + } + } + } + + public int print(Graphics pg, PageFormat pf, int pi) + throws PrinterException + { + pg.translate( (int) pf.getImageableX(), (int) pf.getImageableY()); + + rc.drawBackground(pg, rc.bgColour); + rc.drawScene(pg); + if (rc.drawAxes == true) + { + rc.drawAxes(pg); + } + + if (pi == 0) + return Printable.PAGE_EXISTS; + else + return Printable.NO_SUCH_PAGE; + } + } + + + + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void eps_actionPerformed(ActionEvent e) + { + boolean accurateText = true; + + String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING", + "Prompt each time"); + + // If we need to prompt, and if the GUI is visible then + // Prompt for EPS rendering style + if (renderStyle.equalsIgnoreCase("Prompt each time") + && ! + (System.getProperty("java.awt.headless") != null + && System.getProperty("java.awt.headless").equals("true"))) + { + EPSOptions eps = new EPSOptions(); + renderStyle = eps.getValue(); + + if (renderStyle == null || eps.cancelled) + return; + + } + + if (renderStyle.equalsIgnoreCase("text")) + { + accurateText = false; + } + + int width = rc.getWidth(); + int height = rc.getHeight(); + + try + { + jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser( + jalview.bin.Cache.getProperty( + "LAST_DIRECTORY"), new String[] + {"eps"}, + new String[] + {"Encapsulated Postscript"}, + "Encapsulated Postscript"); + chooser.setFileView(new jalview.io.JalviewFileView()); + chooser.setDialogTitle("Create EPS file from PCA"); + chooser.setToolTipText("Save"); + + int value = chooser.showSaveDialog(this); + + if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) + { + return; + } + + jalview.bin.Cache.setProperty("LAST_DIRECTORY", + chooser.getSelectedFile().getParent()); + + FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); + EpsGraphics2D pg = new EpsGraphics2D("PCA", out, 0, 0, width, + height); + + pg.setAccurateTextMode(accurateText); + + rc.drawBackground(pg, rc.bgColour); + rc.drawScene(pg); + + if (rc.drawAxes == true) + { + rc.drawAxes(pg); + } + + + pg.flush(); + pg.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void png_actionPerformed(ActionEvent e) + { + int width = rc.getWidth(); + int height = rc.getHeight(); + + try + { + jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser( + jalview.bin.Cache.getProperty( + "LAST_DIRECTORY"), new String[] + {"png"}, + new String[] + {"Portable network graphics"}, + "Portable network graphics"); + + chooser.setFileView(new jalview.io.JalviewFileView()); + chooser.setDialogTitle("Create PNG image from PCA"); + chooser.setToolTipText("Save"); + + int value = chooser.showSaveDialog(this); + + if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) + { + return; + } + + jalview.bin.Cache.setProperty("LAST_DIRECTORY", + chooser.getSelectedFile().getParent()); + + FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); + + BufferedImage bi = new BufferedImage(width, height, + BufferedImage.TYPE_INT_RGB); + Graphics big = bi.getGraphics(); + + big.drawImage(rc.img,0,0,this); + + ImageIO.write(bi, "png", out); + out.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + } diff --git a/src/jalview/jbgui/GPCAPanel.java b/src/jalview/jbgui/GPCAPanel.java index 7fc21a9..a142d5b 100755 --- a/src/jalview/jbgui/GPCAPanel.java +++ b/src/jalview/jbgui/GPCAPanel.java @@ -23,7 +23,7 @@ import java.awt.event.*; import javax.swing.*; public class GPCAPanel - extends JPanel + extends JInternalFrame { JPanel jPanel2 = new JPanel(); JLabel jLabel1 = new JLabel(); @@ -34,6 +34,16 @@ public class GPCAPanel protected JComboBox zCombobox = new JComboBox(); FlowLayout flowLayout1 = new FlowLayout(); BorderLayout borderLayout1 = new BorderLayout(); + JMenuBar jMenuBar1 = new JMenuBar(); + JMenu fileMenu = new JMenu(); + JMenu saveMenu = new JMenu(); + JMenuItem eps = new JMenuItem(); + JMenuItem png = new JMenuItem(); + JMenuItem print = new JMenuItem(); + JMenuItem outputValues = new JMenuItem(); + JMenu viewMenu = new JMenu(); + protected JCheckBoxMenuItem showLabels = new JCheckBoxMenuItem(); + JMenuItem bgcolour = new JMenuItem(); public GPCAPanel() { @@ -52,12 +62,15 @@ public class GPCAPanel yCombobox.addItem("dim " + i); zCombobox.addItem("dim " + i); } + + + setJMenuBar(jMenuBar1); } private void jbInit() throws Exception { - this.setLayout(borderLayout1); + this.getContentPane().setLayout(borderLayout1); jPanel2.setLayout(flowLayout1); jLabel1.setFont(new java.awt.Font("Verdana", 0, 12)); jLabel1.setText("x="); @@ -91,13 +104,73 @@ public class GPCAPanel xCombobox_actionPerformed(e); } }); - this.add(jPanel2, BorderLayout.SOUTH); + fileMenu.setText("File"); + saveMenu.setText("Save as"); + eps.setText("EPS"); + eps.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + eps_actionPerformed(e); + } + }); + png.setText("PNG"); + png.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + png_actionPerformed(e); + } + }); + outputValues.setText("Output Values..."); + outputValues.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + outputValues_actionPerformed(e); + } + }); + print.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + print_actionPerformed(e); + } + }); + viewMenu.setText("View"); + showLabels.setText("Show Labels"); + showLabels.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + showLabels_actionPerformed(e); + } + }); + print.setText("Print"); + bgcolour.setText("Background Colour..."); + bgcolour.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + bgcolour_actionPerformed(e); + } + }); + this.getContentPane().add(jPanel2, BorderLayout.SOUTH); jPanel2.add(jLabel1, null); jPanel2.add(xCombobox, null); jPanel2.add(jLabel2, null); jPanel2.add(yCombobox, null); jPanel2.add(jLabel3, null); jPanel2.add(zCombobox, null); + jMenuBar1.add(fileMenu); + jMenuBar1.add(viewMenu); + fileMenu.add(saveMenu); + fileMenu.add(outputValues); + fileMenu.add(print); + saveMenu.add(eps); + saveMenu.add(png); + viewMenu.add(showLabels); + viewMenu.add(bgcolour); } protected void xCombobox_actionPerformed(ActionEvent e) @@ -111,4 +184,34 @@ public class GPCAPanel protected void zCombobox_actionPerformed(ActionEvent e) { } + + public void eps_actionPerformed(ActionEvent e) + { + + } + + public void png_actionPerformed(ActionEvent e) + { + + } + + public void outputValues_actionPerformed(ActionEvent e) + { + + } + + public void print_actionPerformed(ActionEvent e) + { + + } + + public void showLabels_actionPerformed(ActionEvent e) + { + + } + + public void bgcolour_actionPerformed(ActionEvent e) + { + + } }