2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: PaperReferencesDialog.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.8 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/05/05 19:40:59 $ |
2 |
26 Feb 07 |
jari |
* $Author: eleanorahowe $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.microarray.mev; |
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.BufferedReader; |
2 |
26 Feb 07 |
jari |
28 |
import java.io.IOException; |
2 |
26 Feb 07 |
jari |
29 |
import java.io.InputStream; |
2 |
26 Feb 07 |
jari |
30 |
import java.io.InputStreamReader; |
2 |
26 Feb 07 |
jari |
31 |
import java.net.URL; |
2 |
26 Feb 07 |
jari |
32 |
import java.awt.print.Book; |
2 |
26 Feb 07 |
jari |
33 |
import java.awt.print.PageFormat; |
2 |
26 Feb 07 |
jari |
34 |
import java.awt.print.Printable; |
2 |
26 Feb 07 |
jari |
35 |
import java.awt.print.PrinterException; |
2 |
26 Feb 07 |
jari |
36 |
import java.awt.print.PrinterJob; |
2 |
26 Feb 07 |
jari |
37 |
import javax.swing.BorderFactory; |
2 |
26 Feb 07 |
jari |
38 |
import javax.swing.JButton; |
2 |
26 Feb 07 |
jari |
39 |
import javax.swing.JDialog; |
2 |
26 Feb 07 |
jari |
40 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
41 |
import javax.swing.JEditorPane; |
2 |
26 Feb 07 |
jari |
42 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
43 |
import javax.swing.JScrollPane; |
2 |
26 Feb 07 |
jari |
44 |
import javax.swing.border.BevelBorder; |
2 |
26 Feb 07 |
jari |
45 |
import javax.swing.event.HyperlinkEvent; |
2 |
26 Feb 07 |
jari |
46 |
import javax.swing.event.HyperlinkListener; |
2 |
26 Feb 07 |
jari |
47 |
import org.tigr.util.BrowserLauncher; |
2 |
26 Feb 07 |
jari |
48 |
import org.tigr.util.awt.GBA; |
2 |
26 Feb 07 |
jari |
49 |
|
2 |
26 Feb 07 |
jari |
50 |
public class PaperReferencesDialog extends JDialog implements java.awt.print.Printable,HyperlinkListener{ |
2 |
26 Feb 07 |
jari |
51 |
|
2 |
26 Feb 07 |
jari |
52 |
private String text; |
2 |
26 Feb 07 |
jari |
53 |
private JEditorPane ed; |
2 |
26 Feb 07 |
jari |
54 |
|
2 |
26 Feb 07 |
jari |
55 |
public PaperReferencesDialog(Frame parent) { |
2 |
26 Feb 07 |
jari |
56 |
this(parent, ""); |
2 |
26 Feb 07 |
jari |
57 |
} |
2 |
26 Feb 07 |
jari |
58 |
|
2 |
26 Feb 07 |
jari |
59 |
public PaperReferencesDialog(Frame parent, String labelText) { |
2 |
26 Feb 07 |
jari |
60 |
super(parent, "Papers / Publications Reference", false); |
2 |
26 Feb 07 |
jari |
61 |
EventListener listener = new EventListener(); |
2 |
26 Feb 07 |
jari |
62 |
this.text = labelText; |
2 |
26 Feb 07 |
jari |
63 |
GBA gba = new GBA(); |
2 |
26 Feb 07 |
jari |
64 |
Font font = new Font("serif", Font.PLAIN, 12); |
2 |
26 Feb 07 |
jari |
65 |
|
2 |
26 Feb 07 |
jari |
66 |
ed = new JEditorPane("text/html", labelText); |
2 |
26 Feb 07 |
jari |
67 |
ed.setEditable(false); |
2 |
26 Feb 07 |
jari |
68 |
ed.setMargin(new Insets(10,10,10,10)); |
2 |
26 Feb 07 |
jari |
69 |
ed.setBackground(new Color(234,233,191)); |
2 |
26 Feb 07 |
jari |
70 |
ed.setCaretPosition(0); |
2 |
26 Feb 07 |
jari |
71 |
ed.addHyperlinkListener(this); |
2 |
26 Feb 07 |
jari |
72 |
JScrollPane scrollPane = new JScrollPane(ed, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
2 |
26 Feb 07 |
jari |
73 |
JPanel referencesPanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
74 |
referencesPanel.setBackground(new Color(234,233,191)); |
2 |
26 Feb 07 |
jari |
75 |
gba.add(referencesPanel, scrollPane, 0, 0, 1, 1, 1, 1, GBA.B, GBA.C); |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
77 |
JButton printButton = new JButton("Print"); |
2 |
26 Feb 07 |
jari |
78 |
printButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); |
2 |
26 Feb 07 |
jari |
79 |
printButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
80 |
printButton.setActionCommand("print-command"); |
2 |
26 Feb 07 |
jari |
81 |
printButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
82 |
|
2 |
26 Feb 07 |
jari |
83 |
JButton closeButton = new JButton(" Close "); |
2 |
26 Feb 07 |
jari |
84 |
closeButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); |
2 |
26 Feb 07 |
jari |
85 |
closeButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
86 |
closeButton.setActionCommand("close-command"); |
2 |
26 Feb 07 |
jari |
87 |
closeButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
88 |
closeButton.setSize(120,30); |
2 |
26 Feb 07 |
jari |
89 |
closeButton.setPreferredSize(new Dimension(120, 30)); |
2 |
26 Feb 07 |
jari |
90 |
|
2 |
26 Feb 07 |
jari |
91 |
JPanel buttonPanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
92 |
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5,0,5,0)); |
2 |
26 Feb 07 |
jari |
// gba.add(buttonPanel, printButton, 0, 0, 1, 1, 0,0, GBA.NONE, GBA.C); |
2 |
26 Feb 07 |
jari |
94 |
gba.add(buttonPanel, closeButton, 0, 0, 1, 1, 1, 1, GBA.NONE, GBA.C); |
2 |
26 Feb 07 |
jari |
95 |
|
2 |
26 Feb 07 |
jari |
96 |
getContentPane().setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
97 |
gba.add(getContentPane(), referencesPanel, 0, 0, 1, 2, 1, 1, GBA.B, GBA.C); |
2 |
26 Feb 07 |
jari |
98 |
gba.add(getContentPane(), buttonPanel, 0, 2, 1, 1, 0, 0, GBA.NONE, GBA.C); |
2 |
26 Feb 07 |
jari |
99 |
|
2 |
26 Feb 07 |
jari |
100 |
setSize(550, 650); |
2 |
26 Feb 07 |
jari |
101 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
102 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
103 |
show(); |
2 |
26 Feb 07 |
jari |
104 |
} |
2 |
26 Feb 07 |
jari |
105 |
public static String createReferencesText() { |
2 |
26 Feb 07 |
jari |
106 |
String thisLine, html; |
2 |
26 Feb 07 |
jari |
107 |
html = ""; |
2 |
26 Feb 07 |
jari |
108 |
try { |
2 |
26 Feb 07 |
jari |
109 |
InputStream is = AcknowlegementDialog.class.getResourceAsStream("PaperReferences.html"); |
2 |
26 Feb 07 |
jari |
110 |
BufferedReader br = new BufferedReader(new InputStreamReader(is)); |
2 |
26 Feb 07 |
jari |
111 |
while ((thisLine = br.readLine()) != null) { |
2 |
26 Feb 07 |
jari |
112 |
html+=thisLine; |
2 |
26 Feb 07 |
jari |
113 |
} |
2 |
26 Feb 07 |
jari |
114 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
115 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
116 |
} |
2 |
26 Feb 07 |
jari |
117 |
return html; |
2 |
26 Feb 07 |
jari |
118 |
} |
2 |
26 Feb 07 |
jari |
119 |
|
2 |
26 Feb 07 |
jari |
120 |
public static void main(String [] args){ |
2 |
26 Feb 07 |
jari |
121 |
PaperReferencesDialog d = new PaperReferencesDialog(new Frame(), PaperReferencesDialog.createReferencesText()); |
2 |
26 Feb 07 |
jari |
//System.exit(0); |
2 |
26 Feb 07 |
jari |
123 |
} |
2 |
26 Feb 07 |
jari |
124 |
|
2 |
26 Feb 07 |
jari |
125 |
public int print(java.awt.Graphics g, java.awt.print.PageFormat format, int page) throws java.awt.print.PrinterException { |
2 |
26 Feb 07 |
jari |
126 |
if(page > 2) |
2 |
26 Feb 07 |
jari |
127 |
return Printable.NO_SUCH_PAGE; |
2 |
26 Feb 07 |
jari |
128 |
Graphics2D g2d = (Graphics2D)g; |
2 |
26 Feb 07 |
jari |
129 |
g2d.clip(new java.awt.geom.Rectangle2D.Double(0, 0, format.getImageableWidth(), format.getImageableHeight())); |
2 |
26 Feb 07 |
jari |
130 |
g2d.translate(format.getImageableX(), -(page) * format.getImageableHeight()); |
2 |
26 Feb 07 |
jari |
131 |
g2d.scale(1.0,1.0); |
2 |
26 Feb 07 |
jari |
132 |
g2d.drawString("Test String", 0,20); |
2 |
26 Feb 07 |
jari |
133 |
ed.paint(g); |
2 |
26 Feb 07 |
jari |
134 |
return Printable.PAGE_EXISTS; |
2 |
26 Feb 07 |
jari |
135 |
} |
2 |
26 Feb 07 |
jari |
136 |
|
2 |
26 Feb 07 |
jari |
137 |
private Book makeBook(PageFormat page, int numPages){ |
2 |
26 Feb 07 |
jari |
138 |
Book book = new Book(); |
2 |
26 Feb 07 |
jari |
139 |
book.append(this, page, numPages); |
2 |
26 Feb 07 |
jari |
140 |
return book; |
2 |
26 Feb 07 |
jari |
141 |
} |
2 |
26 Feb 07 |
jari |
142 |
|
2 |
26 Feb 07 |
jari |
143 |
private class EventListener implements ActionListener, KeyListener { |
2 |
26 Feb 07 |
jari |
144 |
|
2 |
26 Feb 07 |
jari |
145 |
public void actionPerformed(ActionEvent event) { |
2 |
26 Feb 07 |
jari |
146 |
String command = event.getActionCommand(); |
2 |
26 Feb 07 |
jari |
147 |
if (command.equals("close-command")) { |
2 |
26 Feb 07 |
jari |
148 |
dispose(); |
2 |
26 Feb 07 |
jari |
149 |
} |
2 |
26 Feb 07 |
jari |
150 |
else if(command.equals("print-command")){ |
2 |
26 Feb 07 |
jari |
151 |
PrinterJob pj = PrinterJob.getPrinterJob(); |
2 |
26 Feb 07 |
jari |
152 |
pj.setPrintable(PaperReferencesDialog.this, pj.defaultPage()); |
2 |
26 Feb 07 |
jari |
153 |
int numPages = ed.getHeight(); |
2 |
26 Feb 07 |
jari |
154 |
numPages /= pj.defaultPage().getImageableY(); |
2 |
26 Feb 07 |
jari |
155 |
|
2 |
26 Feb 07 |
jari |
156 |
pj.setPageable(makeBook(pj.defaultPage(), numPages)); |
2 |
26 Feb 07 |
jari |
157 |
if (pj.printDialog()) { |
2 |
26 Feb 07 |
jari |
158 |
try { |
2 |
26 Feb 07 |
jari |
159 |
pj.print(); |
2 |
26 Feb 07 |
jari |
160 |
} catch (PrinterException pe) { |
2 |
26 Feb 07 |
jari |
161 |
System.out.println(pe); |
2 |
26 Feb 07 |
jari |
162 |
} |
2 |
26 Feb 07 |
jari |
163 |
} |
2 |
26 Feb 07 |
jari |
164 |
|
2 |
26 Feb 07 |
jari |
165 |
} |
2 |
26 Feb 07 |
jari |
166 |
} |
2 |
26 Feb 07 |
jari |
167 |
|
2 |
26 Feb 07 |
jari |
168 |
|
2 |
26 Feb 07 |
jari |
169 |
|
2 |
26 Feb 07 |
jari |
170 |
public void keyPressed(KeyEvent event) { |
2 |
26 Feb 07 |
jari |
171 |
if (event.getKeyCode() == KeyEvent.VK_ENTER) { |
2 |
26 Feb 07 |
jari |
172 |
dispose(); |
2 |
26 Feb 07 |
jari |
173 |
} |
2 |
26 Feb 07 |
jari |
174 |
} |
2 |
26 Feb 07 |
jari |
175 |
|
2 |
26 Feb 07 |
jari |
176 |
public void keyReleased(KeyEvent event) {;} |
2 |
26 Feb 07 |
jari |
177 |
public void keyTyped(KeyEvent event) {;} |
2 |
26 Feb 07 |
jari |
178 |
} |
2 |
26 Feb 07 |
jari |
179 |
|
2 |
26 Feb 07 |
jari |
180 |
public void hyperlinkUpdate(HyperlinkEvent e) { |
2 |
26 Feb 07 |
jari |
// TODO Auto-generated method stub |
2 |
26 Feb 07 |
jari |
182 |
HyperlinkEvent.EventType type=e.getEventType(); |
2 |
26 Feb 07 |
jari |
183 |
URL url=e.getURL(); |
2 |
26 Feb 07 |
jari |
184 |
if(type==HyperlinkEvent.EventType.ACTIVATED){ |
2 |
26 Feb 07 |
jari |
185 |
try { |
2 |
26 Feb 07 |
jari |
//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 |
187 |
BrowserLauncher.openURL(url.toString()); |
2 |
26 Feb 07 |
jari |
188 |
} catch( IOException ex ) { |
2 |
26 Feb 07 |
jari |
//e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
190 |
|
2 |
26 Feb 07 |
jari |
191 |
} |
2 |
26 Feb 07 |
jari |
192 |
} |
2 |
26 Feb 07 |
jari |
193 |
} |
2 |
26 Feb 07 |
jari |
194 |
} |