Hi Cameron,

Yes, you will need an extension for ULCFrame.

Please see the snippet at the end of this mail

In the snippet you can add code for letting the user specify the file name
and location for the image to be saved.

In fact you can make PrintableFrame implement java.awt.print.Printable
Interface to directly print it to a printer as described in
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=263262

I hope this helps.

Thanks and regards,

Janak

PS:
Sorry for the delay in replying. Last week there was some problem with our
mail server and the dev list mails did not get forwarded.

>-----Original Message-----
>From: [EMAIL PROTECTED]
>[mailto:[EMAIL PROTECTED] Behalf Of Cameron Taggart
>Sent: Wednesday, May 10, 2006 11:17 PM
>To: [email protected]
>Subject: [ULC-developer] capture/print window
>
>
>Users need to print the forms that they are viewing once in a while.
>Anyone done this already.   I searched the mailing list archive and
>Google for printing or capturing an image of a JFrame.  I came up with
>these links.
>
>
>Java Technology Forums - How to print JFrame with its title bar and border?
>http://forum.java.sun.com/thread.jspa?forumID=57&threadID=263262
>
>ULC Community - Contributions > Utilities > Printing
>http://ulc-community.canoo.com/snipsnap/space/Contributions/Utiliti
es/Printing

How do I print a JTable?
http://www.jguru.com/faq/view.jsp?EID=1251266


The 1st link looks the most promising.  It says to use java.awt.Robot
(http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Robot.html) to
capture a BufferedImage.  Once the BufferedImage is captured, I'm sure
it can be turned into a PNG and sent to the user or even a PDF as the
second link describes.

Would this functionality need to be packaged up as a ULC extension?

cheers,
Cameron
-------------------------------


import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.ULCButton;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.event.ActionEvent;
import com.ulcjava.base.application.event.IActionListener;
import com.ulcjava.base.client.UIFrame;
import com.ulcjava.base.development.DevelopmentRunner;
import com.ulcjava.base.shared.internal.Anything;

public class PrintableFrameSnippet extends AbstractApplication {

        public void start() {

                final ULCPrintableFrame frame = new ULCPrintableFrame(
                                "PrintableFrameSnippet");
                frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);

                ULCButton button = new ULCButton("Print Fame");
                button.addActionListener(new IActionListener() {
                        public void actionPerformed(ActionEvent event) {
                                frame.printFrame();
                        }
                });

                frame.add(button);
                frame.setSize(300, 200);
                frame.setVisible(true);
        }

        public static void main(String[] args) {
                
DevelopmentRunner.setApplicationClass(PrintableFrameSnippet.class);
                DevelopmentRunner.main(args);
        }

        public static class ULCPrintableFrame extends ULCFrame {
                public ULCPrintableFrame(String title) {
                        super(title);
                }

                protected String typeString() {
                        return UIPrintableFrame.class.getName();
                }

                public void printFrame() {
                        sendUI("printFrame");
                }
        }

        public static class UIPrintableFrame extends UIFrame {
                protected Object createBasicObject(Anything args) {
                        String title = args.get("title", "");
                        return new PrintableFrame(title);
                }

                public void handleRequest(String request, Anything args) {
                        if (request.equals("printFrame")) {
                                getBasicPrintableFrame().printFrame();
                        } else {
                                super.handleRequest(request, args);
                        }
                }

                private PrintableFrame getBasicPrintableFrame() {
                        return (PrintableFrame) getBasicFrame();
                }

                public static class PrintableFrame extends JFrame {
                        public PrintableFrame(String title) {
                                super(title);
                        }

                        public void printFrame() {
                                Robot r;
                                try {
                                        r = new Robot();
                                        Rectangle rect = getBounds();
                                        BufferedImage image = 
r.createScreenCapture(rect);
                                        try {
                                                // Save as PNG
                                                File file = new 
File("c:\\PrintFrame.png");
                                                ImageIO.write(image, "png", 
file);
                                        } catch (IOException e1) {
                                        }

                                } catch (AWTException e1) {
                                        e1.printStackTrace();
                                }

                        }
                }
        }
}

_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to