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: MevCitationDialog.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.5 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/05/02 19:50:13 $ |
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.print.Book; |
2 |
26 Feb 07 |
jari |
27 |
import java.awt.print.PageFormat; |
2 |
26 Feb 07 |
jari |
28 |
import java.awt.print.Printable; |
2 |
26 Feb 07 |
jari |
29 |
import java.awt.print.PrinterException; |
2 |
26 Feb 07 |
jari |
30 |
import java.awt.print.PrinterJob; |
2 |
26 Feb 07 |
jari |
31 |
|
2 |
26 Feb 07 |
jari |
32 |
import javax.swing.BorderFactory; |
2 |
26 Feb 07 |
jari |
33 |
import javax.swing.JButton; |
2 |
26 Feb 07 |
jari |
34 |
import javax.swing.JDialog; |
2 |
26 Feb 07 |
jari |
35 |
import javax.swing.JEditorPane; |
2 |
26 Feb 07 |
jari |
36 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
37 |
import javax.swing.JScrollPane; |
2 |
26 Feb 07 |
jari |
38 |
import javax.swing.border.BevelBorder; |
2 |
26 Feb 07 |
jari |
39 |
|
2 |
26 Feb 07 |
jari |
40 |
import org.tigr.util.awt.GBA; |
2 |
26 Feb 07 |
jari |
41 |
|
2 |
26 Feb 07 |
jari |
42 |
public class MevCitationDialog extends JDialog implements java.awt.print.Printable{ |
2 |
26 Feb 07 |
jari |
43 |
|
2 |
26 Feb 07 |
jari |
44 |
private String text; |
2 |
26 Feb 07 |
jari |
45 |
private JEditorPane ed; |
2 |
26 Feb 07 |
jari |
46 |
|
2 |
26 Feb 07 |
jari |
47 |
public MevCitationDialog(Frame parent) { |
2 |
26 Feb 07 |
jari |
48 |
this(parent, ""); |
2 |
26 Feb 07 |
jari |
49 |
} |
2 |
26 Feb 07 |
jari |
50 |
|
2 |
26 Feb 07 |
jari |
51 |
public MevCitationDialog(Frame parent, String labelText) { |
2 |
26 Feb 07 |
jari |
52 |
super(parent, "Contribution Acknowledgements :)", false); |
2 |
26 Feb 07 |
jari |
53 |
EventListener listener = new EventListener(); |
2 |
26 Feb 07 |
jari |
54 |
this.text = labelText; |
2 |
26 Feb 07 |
jari |
55 |
GBA gba = new GBA(); |
2 |
26 Feb 07 |
jari |
56 |
Font font = new Font("serif", Font.PLAIN, 12); |
2 |
26 Feb 07 |
jari |
57 |
|
2 |
26 Feb 07 |
jari |
58 |
ed = new JEditorPane("text/html", labelText); |
2 |
26 Feb 07 |
jari |
59 |
ed.setEditable(false); |
2 |
26 Feb 07 |
jari |
60 |
ed.setMargin(new Insets(10,10,10,10)); |
2 |
26 Feb 07 |
jari |
61 |
ed.setBackground(new Color(234,233,191)); |
2 |
26 Feb 07 |
jari |
62 |
ed.setCaretPosition(0); |
2 |
26 Feb 07 |
jari |
63 |
JScrollPane scrollPane = new JScrollPane(ed, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
2 |
26 Feb 07 |
jari |
64 |
JPanel referencesPanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
65 |
referencesPanel.setBackground(new Color(234,233,191)); |
2 |
26 Feb 07 |
jari |
66 |
gba.add(referencesPanel, scrollPane, 0, 0, 1, 1, 1, 1, GBA.B, GBA.C); |
2 |
26 Feb 07 |
jari |
67 |
|
2 |
26 Feb 07 |
jari |
68 |
JButton printButton = new JButton("Print"); |
2 |
26 Feb 07 |
jari |
69 |
printButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); |
2 |
26 Feb 07 |
jari |
70 |
printButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
71 |
printButton.setActionCommand("print-command"); |
2 |
26 Feb 07 |
jari |
72 |
printButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
73 |
|
2 |
26 Feb 07 |
jari |
74 |
JButton closeButton = new JButton(" Close "); |
2 |
26 Feb 07 |
jari |
75 |
closeButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); |
2 |
26 Feb 07 |
jari |
76 |
closeButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
77 |
closeButton.setActionCommand("close-command"); |
2 |
26 Feb 07 |
jari |
78 |
closeButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
79 |
closeButton.setSize(120,30); |
2 |
26 Feb 07 |
jari |
80 |
closeButton.setPreferredSize(new Dimension(120, 30)); |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
JPanel buttonPanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
83 |
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 |
85 |
gba.add(buttonPanel, closeButton, 0, 0, 1, 1, 1, 1, GBA.NONE, GBA.C); |
2 |
26 Feb 07 |
jari |
86 |
|
2 |
26 Feb 07 |
jari |
87 |
getContentPane().setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
88 |
gba.add(getContentPane(), referencesPanel, 0, 0, 1, 2, 1, 1, GBA.B, GBA.C); |
2 |
26 Feb 07 |
jari |
89 |
gba.add(getContentPane(), buttonPanel, 0, 2, 1, 1, 0, 0, GBA.NONE, GBA.C); |
2 |
26 Feb 07 |
jari |
90 |
|
2 |
26 Feb 07 |
jari |
91 |
setSize(500, 300); |
2 |
26 Feb 07 |
jari |
92 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
93 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
94 |
show(); |
2 |
26 Feb 07 |
jari |
95 |
} |
2 |
26 Feb 07 |
jari |
96 |
|
2 |
26 Feb 07 |
jari |
97 |
public static String createCitationText() { |
2 |
26 Feb 07 |
jari |
98 |
String html = ""; |
2 |
26 Feb 07 |
jari |
99 |
|
2 |
26 Feb 07 |
jari |
100 |
html += "<html><body>"; |
2 |
26 Feb 07 |
jari |
101 |
html += "<h2>Referencing MeV</h2>"; |
2 |
26 Feb 07 |
jari |
102 |
html += "<h3>Users of this program should cite:</h3>"; |
2 |
26 Feb 07 |
jari |
103 |
|
2 |
26 Feb 07 |
jari |
104 |
html += "Saeed AI, Sharov V, White J, Li J, Liang W, Bhagabati N, Braisted J, Klapa M, Currier T, Thiagarajan M, Sturn A, Snuffin M, Rezantsev A, Popov D, Ryltsov A, Kostukovich E, Borisovsky I, Liu Z, Vinsavich A, Trush V, Quackenbush J. TM4: a free, open-source system for microarray data management and analysis. Biotechniques. 2003 Feb;34(2):374-8."; |
2 |
26 Feb 07 |
jari |
105 |
html += "</body></html>"; |
2 |
26 Feb 07 |
jari |
106 |
|
2 |
26 Feb 07 |
jari |
107 |
return html; |
2 |
26 Feb 07 |
jari |
108 |
} |
2 |
26 Feb 07 |
jari |
109 |
|
2 |
26 Feb 07 |
jari |
110 |
public static void main(String [] args){ |
2 |
26 Feb 07 |
jari |
111 |
MevCitationDialog d = new MevCitationDialog(new Frame(), MevCitationDialog.createCitationText()); |
2 |
26 Feb 07 |
jari |
112 |
} |
2 |
26 Feb 07 |
jari |
113 |
|
2 |
26 Feb 07 |
jari |
114 |
public int print(java.awt.Graphics g, java.awt.print.PageFormat format, int page) throws java.awt.print.PrinterException { |
2 |
26 Feb 07 |
jari |
115 |
if(page > 2) |
2 |
26 Feb 07 |
jari |
116 |
return Printable.NO_SUCH_PAGE; |
2 |
26 Feb 07 |
jari |
117 |
Graphics2D g2d = (Graphics2D)g; |
2 |
26 Feb 07 |
jari |
118 |
g2d.clip(new java.awt.geom.Rectangle2D.Double(0, 0, format.getImageableWidth(), format.getImageableHeight())); |
2 |
26 Feb 07 |
jari |
119 |
g2d.translate(format.getImageableX(), -(page) * format.getImageableHeight()); |
2 |
26 Feb 07 |
jari |
120 |
g2d.scale(1.0,1.0); |
2 |
26 Feb 07 |
jari |
121 |
g2d.drawString("Test String", 0,20); |
2 |
26 Feb 07 |
jari |
122 |
ed.paint(g); |
2 |
26 Feb 07 |
jari |
123 |
return Printable.PAGE_EXISTS; |
2 |
26 Feb 07 |
jari |
124 |
} |
2 |
26 Feb 07 |
jari |
125 |
|
2 |
26 Feb 07 |
jari |
126 |
private Book makeBook(PageFormat page, int numPages){ |
2 |
26 Feb 07 |
jari |
127 |
Book book = new Book(); |
2 |
26 Feb 07 |
jari |
128 |
book.append(this, page, numPages); |
2 |
26 Feb 07 |
jari |
129 |
return book; |
2 |
26 Feb 07 |
jari |
130 |
} |
2 |
26 Feb 07 |
jari |
131 |
|
2 |
26 Feb 07 |
jari |
132 |
private class EventListener implements ActionListener, KeyListener { |
2 |
26 Feb 07 |
jari |
133 |
|
2 |
26 Feb 07 |
jari |
134 |
public void actionPerformed(ActionEvent event) { |
2 |
26 Feb 07 |
jari |
135 |
String command = event.getActionCommand(); |
2 |
26 Feb 07 |
jari |
136 |
if (command.equals("close-command")) { |
2 |
26 Feb 07 |
jari |
137 |
dispose(); |
2 |
26 Feb 07 |
jari |
138 |
} |
2 |
26 Feb 07 |
jari |
139 |
else if(command.equals("print-command")){ |
2 |
26 Feb 07 |
jari |
140 |
PrinterJob pj = PrinterJob.getPrinterJob(); |
2 |
26 Feb 07 |
jari |
141 |
pj.setPrintable(MevCitationDialog.this, pj.defaultPage()); |
2 |
26 Feb 07 |
jari |
142 |
int numPages = ed.getHeight(); |
2 |
26 Feb 07 |
jari |
143 |
numPages /= pj.defaultPage().getImageableY(); |
2 |
26 Feb 07 |
jari |
144 |
|
2 |
26 Feb 07 |
jari |
145 |
pj.setPageable(makeBook(pj.defaultPage(), numPages)); |
2 |
26 Feb 07 |
jari |
146 |
if (pj.printDialog()) { |
2 |
26 Feb 07 |
jari |
147 |
try { |
2 |
26 Feb 07 |
jari |
148 |
pj.print(); |
2 |
26 Feb 07 |
jari |
149 |
} catch (PrinterException pe) { |
2 |
26 Feb 07 |
jari |
150 |
System.out.println(pe); |
2 |
26 Feb 07 |
jari |
151 |
} |
2 |
26 Feb 07 |
jari |
152 |
} |
2 |
26 Feb 07 |
jari |
153 |
|
2 |
26 Feb 07 |
jari |
154 |
} |
2 |
26 Feb 07 |
jari |
155 |
} |
2 |
26 Feb 07 |
jari |
156 |
|
2 |
26 Feb 07 |
jari |
157 |
|
2 |
26 Feb 07 |
jari |
158 |
|
2 |
26 Feb 07 |
jari |
159 |
public void keyPressed(KeyEvent event) { |
2 |
26 Feb 07 |
jari |
160 |
if (event.getKeyCode() == KeyEvent.VK_ENTER) { |
2 |
26 Feb 07 |
jari |
161 |
dispose(); |
2 |
26 Feb 07 |
jari |
162 |
} |
2 |
26 Feb 07 |
jari |
163 |
} |
2 |
26 Feb 07 |
jari |
164 |
|
2 |
26 Feb 07 |
jari |
165 |
public void keyReleased(KeyEvent event) {;} |
2 |
26 Feb 07 |
jari |
166 |
public void keyTyped(KeyEvent event) {;} |
2 |
26 Feb 07 |
jari |
167 |
} |
2 |
26 Feb 07 |
jari |
168 |
} |