Subversion Repositories eFlore/Applications.coel

Rev

Rev 1415 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
310 jp_milcent 1
package org.tela_botanica.client.util;
2
 
3
import com.google.gwt.user.client.Element;
4
import com.google.gwt.user.client.ui.UIObject;
5
 
6
/**
7
 * <pre>
8
 * Generic printing class
9
 * can be used to print the Window it self, DOM.Elements, UIObjects (Widgets) and plain HTML
10
 *
11
 * Usage:
12
 *      You must insert this iframe in your host page:
13
 *              <iframe id="__printingFrame" style="width:0;height:0;border:0"></iframe>
14
 *
15
 *      Window:
16
 *              Print.it();
17
 *
18
 *      Objects/HTML:
19
 *              Print.it(RootPanel.get("myId"));
20
 *              Print.it(DOM.getElementById("myId"));
21
 
22
 *              Print.it("Just <b>Print.it()</b>!");
23
 *
24
 *      Objects/HTML using styles:
25
 *              Print.it("<link rel='StyleSheet' type='text/css' media='paper' href='/paperStyle.css'>", RootPanel.get('myId'));
26
 *              Print.it("<style type='text/css' media='paper'> .newPage {page-break-after: always; } </style>","Hi<p class='newPage'></p>By");
27
 * </pre>
28
 */
29
public class Print {
30
 
31
    public static native void it() /*-{
32
        $wnd.print();
33
    }-*/;
34
 
35
    public static native void it(String html) /*-{
36
        var frame = $doc.getElementById('__printingFrame');
37
        if (!frame) {
38
            $wnd.alert("Error: Can't find printing frame.");
39
            return;
40
        }
41
        frame = frame.contentWindow;
42
        var doc = frame.document;
43
        doc.open();
44
        doc.write(html);
45
        doc.close();
46
        frame.focus();
47
        frame.print();
48
    }-*/;
49
 
50
    public static void it(UIObject obj) {
51
        it("", obj.getElement().toString());
52
    }
53
 
54
    public static void it(Element element) {
55
        it("", element.toString());
56
    }
57
 
58
    public static void it(String style, String it) {
59
        it("<it><header>"+style+"</header><body>"+it+"</body></it>");
60
    }
61
 
62
    public static void it(String style, UIObject obj) {
63
        it(style, obj.getElement().toString());
64
    }
65
 
66
    public static void it(String style, Element element) {
67
        it(style, element.toString());
68
    }
69
}