mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/dialogs/dialogHelpUtil/HelpWindowDialog.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2003, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4  */
2 26 Feb 07 jari 5 /*
2 26 Feb 07 jari 6  * $RCSfile: HelpWindowDialog.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.1 $
2 26 Feb 07 jari 8  * $Date: 2006/03/29 14:20:32 $
2 26 Feb 07 jari 9  * $Author: wwang67 $
2 26 Feb 07 jari 10  * $State: Exp $
2 26 Feb 07 jari 11  */
2 26 Feb 07 jari 12 package org.tigr.microarray.mev.cluster.gui.impl.dialogs.dialogHelpUtil;
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import java.awt.Color;
2 26 Feb 07 jari 15 import java.awt.Dimension;
2 26 Feb 07 jari 16 import java.awt.Font;
2 26 Feb 07 jari 17 import java.awt.Frame;
2 26 Feb 07 jari 18 import java.awt.Graphics2D;
2 26 Feb 07 jari 19 import java.awt.GridBagLayout;
2 26 Feb 07 jari 20 import java.awt.Insets;
2 26 Feb 07 jari 21 import java.awt.Toolkit;
2 26 Feb 07 jari 22 import java.awt.event.ActionEvent;
2 26 Feb 07 jari 23 import java.awt.event.ActionListener;
2 26 Feb 07 jari 24 import java.awt.event.KeyEvent;
2 26 Feb 07 jari 25 import java.awt.event.KeyListener;
2 26 Feb 07 jari 26 import java.awt.event.ActionListener;
2 26 Feb 07 jari 27 import java.io.IOException;
2 26 Feb 07 jari 28 import java.net.URL;
2 26 Feb 07 jari 29 import java.awt.print.Book;
2 26 Feb 07 jari 30 import java.awt.print.PageFormat;
2 26 Feb 07 jari 31 import java.awt.print.Printable;
2 26 Feb 07 jari 32 import java.awt.print.PrinterException;
2 26 Feb 07 jari 33 import java.awt.print.PrinterJob;
2 26 Feb 07 jari 34 import javax.swing.BorderFactory;
2 26 Feb 07 jari 35 import javax.swing.JButton;
2 26 Feb 07 jari 36 import javax.swing.JDialog;
2 26 Feb 07 jari 37 import javax.swing.JOptionPane;
2 26 Feb 07 jari 38 import javax.swing.JEditorPane;
2 26 Feb 07 jari 39 import javax.swing.JPanel;
2 26 Feb 07 jari 40 import javax.swing.JScrollPane;
2 26 Feb 07 jari 41 import javax.swing.border.BevelBorder;
2 26 Feb 07 jari 42 import javax.swing.event.HyperlinkEvent;
2 26 Feb 07 jari 43 import javax.swing.event.HyperlinkListener;
2 26 Feb 07 jari 44 import org.tigr.util.BrowserLauncher;
2 26 Feb 07 jari 45 import org.tigr.util.awt.GBA;
2 26 Feb 07 jari 46
2 26 Feb 07 jari 47 public class HelpWindowDialog extends JDialog implements java.awt.print.Printable,HyperlinkListener{
2 26 Feb 07 jari 48     
2 26 Feb 07 jari 49     private String text;
2 26 Feb 07 jari 50     private JEditorPane ed;
2 26 Feb 07 jari 51     
2 26 Feb 07 jari 52     public HelpWindowDialog(Frame parent) {
2 26 Feb 07 jari 53         this(parent, "");
2 26 Feb 07 jari 54     }
2 26 Feb 07 jari 55     
2 26 Feb 07 jari 56     public HelpWindowDialog(Frame parent, String labelText) {
2 26 Feb 07 jari 57         super(parent, "Hint to File Format", false);
2 26 Feb 07 jari 58         EventListener listener = new EventListener();
2 26 Feb 07 jari 59         this.text = labelText;
2 26 Feb 07 jari 60         GBA gba = new GBA();
2 26 Feb 07 jari 61         Font font = new Font("serif", Font.PLAIN, 12);
2 26 Feb 07 jari 62         
2 26 Feb 07 jari 63         ed = new JEditorPane("text/html", labelText);
2 26 Feb 07 jari 64         ed.setEditable(false);
2 26 Feb 07 jari 65         ed.setMargin(new Insets(10,10,10,10));
2 26 Feb 07 jari 66         ed.setBackground(new Color(234,233,191));
2 26 Feb 07 jari 67         ed.setCaretPosition(0);
2 26 Feb 07 jari 68         ed.addHyperlinkListener(this);
2 26 Feb 07 jari 69         JScrollPane scrollPane = new JScrollPane(ed, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
2 26 Feb 07 jari 70         JPanel referencesPanel = new JPanel(new GridBagLayout());
2 26 Feb 07 jari 71         referencesPanel.setBackground(new Color(234,233,191));
2 26 Feb 07 jari 72         gba.add(referencesPanel, scrollPane, 0, 0, 1, 1, 1, 1, GBA.B, GBA.C);
2 26 Feb 07 jari 73         
2 26 Feb 07 jari 74         JButton printButton = new JButton("Print");
2 26 Feb 07 jari 75         printButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
2 26 Feb 07 jari 76         printButton.setFocusPainted(false);
2 26 Feb 07 jari 77         printButton.setActionCommand("print-command");
2 26 Feb 07 jari 78         printButton.addActionListener(listener);
2 26 Feb 07 jari 79         
2 26 Feb 07 jari 80         JButton closeButton = new JButton("  Close  ");
2 26 Feb 07 jari 81         closeButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
2 26 Feb 07 jari 82         closeButton.setFocusPainted(false);
2 26 Feb 07 jari 83         closeButton.setActionCommand("close-command");
2 26 Feb 07 jari 84         closeButton.addActionListener(listener);
2 26 Feb 07 jari 85         closeButton.setSize(120,30);
2 26 Feb 07 jari 86         closeButton.setPreferredSize(new Dimension(120, 30));
2 26 Feb 07 jari 87         
2 26 Feb 07 jari 88         JPanel buttonPanel = new JPanel(new GridBagLayout());
2 26 Feb 07 jari 89         buttonPanel.setBorder(BorderFactory.createEmptyBorder(5,0,5,0));
2 26 Feb 07 jari 90      //   gba.add(buttonPanel, printButton, 0, 0, 1, 1, 0,0, GBA.NONE, GBA.C);
2 26 Feb 07 jari 91         gba.add(buttonPanel, closeButton, 0, 0, 1, 1, 1, 1, GBA.NONE, GBA.C);
2 26 Feb 07 jari 92         
2 26 Feb 07 jari 93         getContentPane().setLayout(new GridBagLayout());
2 26 Feb 07 jari 94         gba.add(getContentPane(), referencesPanel, 0, 0, 1, 2, 1, 1, GBA.B, GBA.C);
2 26 Feb 07 jari 95         gba.add(getContentPane(), buttonPanel, 0, 2, 1, 1, 0, 0, GBA.NONE, GBA.C);
2 26 Feb 07 jari 96         
2 26 Feb 07 jari 97         setSize(550, 650);
2 26 Feb 07 jari 98         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
2 26 Feb 07 jari 99         setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2);
2 26 Feb 07 jari 100         show();
2 26 Feb 07 jari 101     }
2 26 Feb 07 jari 102     public static String createText(String st) {
2 26 Feb 07 jari 103         String html = "";
2 26 Feb 07 jari 104         if(st=="Mev"){
2 26 Feb 07 jari 105         html += "<html><body>";
2 26 Feb 07 jari 106         html += "<p><font size = +1><b>MEV(Multiple Experiment Viewer Format)</b></font><br><br>";
2 26 Feb 07 jari 107         html +="<a href=\"http://www.tm4.org/mevfile_external.pdf\"";
2 26 Feb 07 jari 108         html +=">";
2 26 Feb 07 jari 109         html += "MEV(Multiple Experiment Viewer Format)";
2 26 Feb 07 jari 110         html +="</a>";
2 26 Feb 07 jari 111         html +="is a tab delimited text file format which allows a header";
2 26 Feb 07 jari 112         html +="for identification of columns and comments are preceded by the pound (#) sign.";
2 26 Feb 07 jari 113         html +="The first nine columns are a unique identifier, slide row, slide column,";
2 26 Feb 07 jari 114         html +="meta row, meta column, sub row, sub column, intensity 1, intensity 2.  The unique";
2 26 Feb 07 jari 115         html +="identifier is used to match up corresponding annotation which is supplied from";
2 26 Feb 07 jari 116         html +="annotation files which contain spot annotation for each element on the slide.";       
2 26 Feb 07 jari 117         html += "</body></html>";
2 26 Feb 07 jari 118         }
2 26 Feb 07 jari 119         if(st=="Tav"){
2 26 Feb 07 jari 120           html += "<html><body>";
2 26 Feb 07 jari 121             html += "<p><font size = +1><b>Tav(TIGR Array Viewer)</b></font><br><br>";
2 26 Feb 07 jari 122             html +="<a href=\"http://www.tm4.org/tav_files.pdf\"";
2 26 Feb 07 jari 123             html +=">";
2 26 Feb 07 jari 124             html += "Tav(TIGR Array Viewer)";
2 26 Feb 07 jari 125             html +="</a>";
2 26 Feb 07 jari 126             html +="is similar to the mev format but differs in that it does not permit";
2 26 Feb 07 jari 127             html +="a header row or comment rows and there is no unique ID column.  Each tav file contains";
2 26 Feb 07 jari 128             html +="annotation following the columns for intensity and other spot specific information.";  
2 26 Feb 07 jari 129             html += "</body></html>";  
2 26 Feb 07 jari 130         }
2 26 Feb 07 jari 131         if(st=="GEOaffy"){
2 26 Feb 07 jari 132           html += "<html><body>";
2 26 Feb 07 jari 133             html += "<p><font size = +1><b>GEO SOFT Affymetrix File Format</b></font><br><br>";
2 26 Feb 07 jari 134             html +="<a href=\"http://www.ncbi.nlm.nih.gov/projects/geo/info/soft2.html#SOFTsubmissionexamples\"";
2 26 Feb 07 jari 135             html +=">";
2 26 Feb 07 jari 136             html += "GEO  Simple Omnibus Format in Text (SOFT) file format";
2 26 Feb 07 jari 137             html +="</a>";
2 26 Feb 07 jari 138             html +="is a kind of flexible tab delimited file format for Affymetrix data.";
2 26 Feb 07 jari 139             html +="Users can check the file format in details from web link."; 
2 26 Feb 07 jari 140             html += "</body></html>";  
2 26 Feb 07 jari 141         }
2 26 Feb 07 jari 142         if(st=="GEOtwo"){
2 26 Feb 07 jari 143           html += "<html><body>";
2 26 Feb 07 jari 144             html += "<p><font size = +1><b>GEO SOFT Two Channel File Format</b></font><br><br>";
2 26 Feb 07 jari 145             html +="<a href=\"http://www.ncbi.nlm.nih.gov/projects/geo/info/soft2.html#SOFTsubmissionexamples\"";
2 26 Feb 07 jari 146             html +=">";
2 26 Feb 07 jari 147             html += "GEO  Simple Omnibus Format in Text (SOFT) file format";
2 26 Feb 07 jari 148             html +="</a>";
2 26 Feb 07 jari 149             html +="is a kind of flexible tab delimited file format for Affymetrix data.";
2 26 Feb 07 jari 150             html +="Users can check the file format in details from web link."; 
2 26 Feb 07 jari 151             html += "</body></html>";  
2 26 Feb 07 jari 152         }
2 26 Feb 07 jari 153         if(st=="GenePix"){
2 26 Feb 07 jari 154           html += "<html><body>";
2 26 Feb 07 jari 155             html += "<p><font size = +1><b>GenePix File Format</b></font><br><br>";
2 26 Feb 07 jari 156             html +="<a href=\"http://www.moleculardevices.com/pages/software/gn_genepix_file_formats.html\"";
2 26 Feb 07 jari 157             html +=">";
2 26 Feb 07 jari 158             html += "GenePix File Format";
2 26 Feb 07 jari 159             html +="</a>";
2 26 Feb 07 jari 160             html +=" is a standard file format. Please get detail information from web link.";
2 26 Feb 07 jari 161             html += "</body></html>";  
2 26 Feb 07 jari 162         }
2 26 Feb 07 jari 163         if(st=="Agilent"){
2 26 Feb 07 jari 164           html += "<html><body>";
2 26 Feb 07 jari 165             html += "<p><font size = +1><b>Agilent File Format</b></font><br><br>";
2 26 Feb 07 jari 166             html +="<a href=\"\"";
2 26 Feb 07 jari 167             html +=">";
2 26 Feb 07 jari 168             html += "Agilent File Format";
2 26 Feb 07 jari 169             html +="</a>";
2 26 Feb 07 jari 170             html +=" is a standard file format. Please get detail information from web link.";
2 26 Feb 07 jari 171             html += "</body></html>";  
2 26 Feb 07 jari 172         }
2 26 Feb 07 jari 173         return html;
2 26 Feb 07 jari 174     }
2 26 Feb 07 jari 175     
2 26 Feb 07 jari 176     public static void main(String [] args){
2 26 Feb 07 jari 177         //HelpWindowDialog d = new HelpWindowDialog(new Frame(), HelpWindowDialog.createText("Mev"));
2 26 Feb 07 jari 178         //System.exit(0);
2 26 Feb 07 jari 179     }
2 26 Feb 07 jari 180     
2 26 Feb 07 jari 181     public int print(java.awt.Graphics g, java.awt.print.PageFormat format, int page) throws java.awt.print.PrinterException {
2 26 Feb 07 jari 182         if(page > 2)
2 26 Feb 07 jari 183             return Printable.NO_SUCH_PAGE;
2 26 Feb 07 jari 184         Graphics2D g2d = (Graphics2D)g;
2 26 Feb 07 jari 185          g2d.clip(new java.awt.geom.Rectangle2D.Double(0, 0, format.getImageableWidth(), format.getImageableHeight()));
2 26 Feb 07 jari 186   g2d.translate(format.getImageableX(), -(page) * format.getImageableHeight());   
2 26 Feb 07 jari 187         g2d.scale(1.0,1.0);
2 26 Feb 07 jari 188         g2d.drawString("Test String", 0,20);   
2 26 Feb 07 jari 189         ed.paint(g);
2 26 Feb 07 jari 190         return Printable.PAGE_EXISTS;      
2 26 Feb 07 jari 191     }
2 26 Feb 07 jari 192     
2 26 Feb 07 jari 193     private Book makeBook(PageFormat page, int numPages){
2 26 Feb 07 jari 194         Book book = new Book();
2 26 Feb 07 jari 195         book.append(this, page, numPages);
2 26 Feb 07 jari 196         return book;
2 26 Feb 07 jari 197     }
2 26 Feb 07 jari 198     
2 26 Feb 07 jari 199     private class EventListener implements ActionListener, KeyListener {
2 26 Feb 07 jari 200         
2 26 Feb 07 jari 201         public void actionPerformed(ActionEvent event) {
2 26 Feb 07 jari 202             String command = event.getActionCommand();
2 26 Feb 07 jari 203             if (command.equals("close-command")) {
2 26 Feb 07 jari 204                 dispose();
2 26 Feb 07 jari 205             }
2 26 Feb 07 jari 206             else if(command.equals("print-command")){
2 26 Feb 07 jari 207                 PrinterJob pj = PrinterJob.getPrinterJob();
2 26 Feb 07 jari 208                 pj.setPrintable(HelpWindowDialog.this, pj.defaultPage());
2 26 Feb 07 jari 209                 int numPages = ed.getHeight();
2 26 Feb 07 jari 210                 numPages /= pj.defaultPage().getImageableY();
2 26 Feb 07 jari 211                 
2 26 Feb 07 jari 212                 pj.setPageable(makeBook(pj.defaultPage(), numPages));
2 26 Feb 07 jari 213                 if (pj.printDialog()) {
2 26 Feb 07 jari 214                     try {
2 26 Feb 07 jari 215                         pj.print();
2 26 Feb 07 jari 216                     } catch (PrinterException pe) {
2 26 Feb 07 jari 217                         System.out.println(pe);                       
2 26 Feb 07 jari 218                     }
2 26 Feb 07 jari 219                 }
2 26 Feb 07 jari 220                 
2 26 Feb 07 jari 221             }
2 26 Feb 07 jari 222         }
2 26 Feb 07 jari 223         
2 26 Feb 07 jari 224         
2 26 Feb 07 jari 225         
2 26 Feb 07 jari 226         public void keyPressed(KeyEvent event) {
2 26 Feb 07 jari 227             if (event.getKeyCode() == KeyEvent.VK_ENTER) {
2 26 Feb 07 jari 228                 dispose();
2 26 Feb 07 jari 229             }
2 26 Feb 07 jari 230         }
2 26 Feb 07 jari 231         
2 26 Feb 07 jari 232         public void keyReleased(KeyEvent event) {;}
2 26 Feb 07 jari 233         public void keyTyped(KeyEvent event) {;}
2 26 Feb 07 jari 234     }
2 26 Feb 07 jari 235
2 26 Feb 07 jari 236   public void hyperlinkUpdate(HyperlinkEvent e) {
2 26 Feb 07 jari 237     // TODO Auto-generated method stub
2 26 Feb 07 jari 238     HyperlinkEvent.EventType type=e.getEventType();
2 26 Feb 07 jari 239     URL url=e.getURL();
2 26 Feb 07 jari 240     if(type==HyperlinkEvent.EventType.ACTIVATED){
2 26 Feb 07 jari 241       try {
2 26 Feb 07 jari 242         //BrowserLauncher.openURL("http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=pubmed&dopt=Abstract&list_uids=9843981&query_hl=4&itool=pubmed_docsum" );
2 26 Feb 07 jari 243         BrowserLauncher.openURL(url.toString());
2 26 Feb 07 jari 244       } catch( IOException ex ) {
2 26 Feb 07 jari 245         //e.printStackTrace();
2 26 Feb 07 jari 246         
2 26 Feb 07 jari 247       }
2 26 Feb 07 jari 248     }
2 26 Feb 07 jari 249   }
2 26 Feb 07 jari 250 }