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: AcknowlegementDialog.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.11 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/08/10 18:43:45 $ |
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.WindowAdapter; |
2 |
26 Feb 07 |
jari |
27 |
import java.awt.event.WindowEvent; |
2 |
26 Feb 07 |
jari |
28 |
import java.awt.print.Book; |
2 |
26 Feb 07 |
jari |
29 |
import java.awt.print.PageFormat; |
2 |
26 Feb 07 |
jari |
30 |
import java.awt.print.Printable; |
2 |
26 Feb 07 |
jari |
31 |
import java.awt.print.PrinterException; |
2 |
26 Feb 07 |
jari |
32 |
import java.awt.print.PrinterJob; |
2 |
26 Feb 07 |
jari |
33 |
import java.io.BufferedReader; |
2 |
26 Feb 07 |
jari |
34 |
import java.io.InputStream; |
2 |
26 Feb 07 |
jari |
35 |
import java.io.InputStreamReader; |
2 |
26 Feb 07 |
jari |
36 |
|
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.JEditorPane; |
2 |
26 Feb 07 |
jari |
41 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
42 |
import javax.swing.JScrollPane; |
2 |
26 Feb 07 |
jari |
43 |
import javax.swing.border.BevelBorder; |
2 |
26 Feb 07 |
jari |
44 |
|
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 AcknowlegementDialog extends JDialog implements java.awt.print.Printable{ |
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 AcknowlegementDialog(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 AcknowlegementDialog(Frame parent, String labelText) { |
2 |
26 Feb 07 |
jari |
57 |
super(parent, "Contribution Acknowledgement", false); |
2 |
26 Feb 07 |
jari |
58 |
EventListener listener = new EventListener(); |
2 |
26 Feb 07 |
jari |
59 |
addWindowListener(listener); |
2 |
26 Feb 07 |
jari |
60 |
this.text = labelText; |
2 |
26 Feb 07 |
jari |
61 |
GBA gba = new GBA(); |
2 |
26 Feb 07 |
jari |
62 |
Font font = new Font("serif", Font.PLAIN, 12); |
2 |
26 Feb 07 |
jari |
63 |
|
2 |
26 Feb 07 |
jari |
64 |
ed = new JEditorPane("text/html", labelText); |
2 |
26 Feb 07 |
jari |
65 |
ed.setEditable(false); |
2 |
26 Feb 07 |
jari |
66 |
ed.setMargin(new Insets(10,10,10,10)); |
2 |
26 Feb 07 |
jari |
67 |
ed.setBackground(new Color(234,233,191)); |
2 |
26 Feb 07 |
jari |
68 |
ed.setCaretPosition(0); |
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 |
// 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(750, 500); |
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 |
|
2 |
26 Feb 07 |
jari |
103 |
public static String createAcknowlegementText() { |
2 |
26 Feb 07 |
jari |
104 |
String thisLine, html; |
2 |
26 Feb 07 |
jari |
105 |
html = ""; |
2 |
26 Feb 07 |
jari |
106 |
try { |
2 |
26 Feb 07 |
jari |
107 |
InputStream is = AcknowlegementDialog.class.getResourceAsStream("/org/tigr/microarray/mev/Acknowledgements.html"); |
2 |
26 Feb 07 |
jari |
108 |
BufferedReader br = new BufferedReader(new InputStreamReader(is)); |
2 |
26 Feb 07 |
jari |
109 |
while ((thisLine = br.readLine()) != null) { |
2 |
26 Feb 07 |
jari |
110 |
html+=thisLine; |
2 |
26 Feb 07 |
jari |
111 |
} |
2 |
26 Feb 07 |
jari |
112 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
113 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
114 |
} |
2 |
26 Feb 07 |
jari |
115 |
return html; |
2 |
26 Feb 07 |
jari |
116 |
} |
2 |
26 Feb 07 |
jari |
117 |
|
2 |
26 Feb 07 |
jari |
118 |
public static void main(String [] args){ |
2 |
26 Feb 07 |
jari |
119 |
AcknowlegementDialog d = new AcknowlegementDialog(new Frame(), AcknowlegementDialog.createAcknowlegementText()); |
2 |
26 Feb 07 |
jari |
//System.exit(0); |
2 |
26 Feb 07 |
jari |
121 |
} |
2 |
26 Feb 07 |
jari |
122 |
|
2 |
26 Feb 07 |
jari |
123 |
public int print(java.awt.Graphics g, java.awt.print.PageFormat format, int page) throws java.awt.print.PrinterException { |
2 |
26 Feb 07 |
jari |
124 |
if(page > 2) |
2 |
26 Feb 07 |
jari |
125 |
return Printable.NO_SUCH_PAGE; |
2 |
26 Feb 07 |
jari |
126 |
Graphics2D g2d = (Graphics2D)g; |
2 |
26 Feb 07 |
jari |
127 |
g2d.clip(new java.awt.geom.Rectangle2D.Double(0, 0, format.getImageableWidth(), format.getImageableHeight())); |
2 |
26 Feb 07 |
jari |
128 |
g2d.translate(format.getImageableX(), -(page) * format.getImageableHeight()); |
2 |
26 Feb 07 |
jari |
129 |
g2d.scale(1.0,1.0); |
2 |
26 Feb 07 |
jari |
130 |
g2d.drawString("Test String", 0,20); |
2 |
26 Feb 07 |
jari |
131 |
ed.paint(g); |
2 |
26 Feb 07 |
jari |
132 |
return Printable.PAGE_EXISTS; |
2 |
26 Feb 07 |
jari |
133 |
} |
2 |
26 Feb 07 |
jari |
134 |
|
2 |
26 Feb 07 |
jari |
135 |
private Book makeBook(PageFormat page, int numPages){ |
2 |
26 Feb 07 |
jari |
136 |
Book book = new Book(); |
2 |
26 Feb 07 |
jari |
137 |
book.append(this, page, numPages); |
2 |
26 Feb 07 |
jari |
138 |
return book; |
2 |
26 Feb 07 |
jari |
139 |
} |
2 |
26 Feb 07 |
jari |
140 |
|
2 |
26 Feb 07 |
jari |
141 |
private class EventListener extends WindowAdapter implements ActionListener, KeyListener { |
2 |
26 Feb 07 |
jari |
142 |
|
2 |
26 Feb 07 |
jari |
143 |
public void actionPerformed(ActionEvent event) { |
2 |
26 Feb 07 |
jari |
144 |
String command = event.getActionCommand(); |
2 |
26 Feb 07 |
jari |
145 |
if (command.equals("close-command")) { |
2 |
26 Feb 07 |
jari |
146 |
dispose(); |
2 |
26 Feb 07 |
jari |
147 |
} |
2 |
26 Feb 07 |
jari |
148 |
else if(command.equals("print-command")){ |
2 |
26 Feb 07 |
jari |
149 |
PrinterJob pj = PrinterJob.getPrinterJob(); |
2 |
26 Feb 07 |
jari |
150 |
pj.setPrintable(AcknowlegementDialog.this, pj.defaultPage()); |
2 |
26 Feb 07 |
jari |
151 |
int numPages = ed.getHeight(); |
2 |
26 Feb 07 |
jari |
152 |
numPages /= pj.defaultPage().getImageableY(); |
2 |
26 Feb 07 |
jari |
153 |
|
2 |
26 Feb 07 |
jari |
154 |
pj.setPageable(makeBook(pj.defaultPage(), numPages)); |
2 |
26 Feb 07 |
jari |
155 |
if (pj.printDialog()) { |
2 |
26 Feb 07 |
jari |
156 |
try { |
2 |
26 Feb 07 |
jari |
157 |
pj.print(); |
2 |
26 Feb 07 |
jari |
158 |
} catch (PrinterException pe) { |
2 |
26 Feb 07 |
jari |
159 |
System.out.println(pe); |
2 |
26 Feb 07 |
jari |
160 |
} |
2 |
26 Feb 07 |
jari |
161 |
} |
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 |
public void windowClosing(WindowEvent we) { |
2 |
26 Feb 07 |
jari |
168 |
AcknowlegementDialog.this.dispose(); |
2 |
26 Feb 07 |
jari |
169 |
} |
2 |
26 Feb 07 |
jari |
170 |
|
2 |
26 Feb 07 |
jari |
171 |
|
2 |
26 Feb 07 |
jari |
172 |
public void keyPressed(KeyEvent event) { |
2 |
26 Feb 07 |
jari |
173 |
if (event.getKeyCode() == KeyEvent.VK_ENTER) { |
2 |
26 Feb 07 |
jari |
174 |
dispose(); |
2 |
26 Feb 07 |
jari |
175 |
} |
2 |
26 Feb 07 |
jari |
176 |
} |
2 |
26 Feb 07 |
jari |
177 |
|
2 |
26 Feb 07 |
jari |
178 |
public void keyReleased(KeyEvent event) {;} |
2 |
26 Feb 07 |
jari |
179 |
public void keyTyped(KeyEvent event) {;} |
2 |
26 Feb 07 |
jari |
180 |
} |
2 |
26 Feb 07 |
jari |
181 |
} |