1 package org.kuali.student.common.ui.client.util;
2
3 import com.google.gwt.dom.client.Document;
4 import com.google.gwt.dom.client.NodeList;
5 import com.google.gwt.user.client.Window;
6 import com.google.gwt.user.client.ui.UIObject;
7 import com.google.gwt.user.client.ui.Widget;
8
9 public class PrintUtils {
10 private static int num = 0;
11
12
13
14
15 public static void print(UIObject uiObject){
16 String headTag = "";
17 StringBuilder styleTags = new StringBuilder("");
18 NodeList<com.google.gwt.dom.client.Element> head = Document.get().getElementsByTagName("head");
19 if(head.getItem(0) != null){
20 com.google.gwt.dom.client.Element e = head.getItem(0);
21 NodeList<com.google.gwt.dom.client.Element> styles = e.getElementsByTagName("style");
22 for(int i = 0; i < styles.getLength(); i++){
23 styleTags.append(styles.getItem(i).getString());
24
25 }
26 }
27 headTag = "<HEAD><TITLE>Print - " + Window.getTitle() + "</TITLE>" + styleTags + "</HEAD>";
28 openPrintWindow(uiObject.getElement().getString(), headTag, num);
29 num++;
30 }
31
32 private static native void openPrintWindow(String html, String headTag, int num)
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 ;
52
53 }