RE: [OpenMap Users] Copy map bean to clipboard fails on Linux

From: Lepkowski, Thomas <>
Date: Tue, 29 May 2007 14:05:28 -0400

Linux is an OS kernel, whereas Windows is an OS and windowing tool wrapped-up together. It's the windowing tool that does the clipboard trick. Gnome, a popular windowing tool for Linux probably has hooks to it own clipboard mechanism. ...But if your app is for a wide audience, you'll need to handle several different windowing tools out there. You might find success writing your own *nix system -level program that acts like a singleton that holds one object (the object clipped). This kind of thing would look and quack like a clipboard. Something along these lines might help. Maybe Linux (and the various windowing tool) have evolved since the last time I looked.


From: [] On Behalf Of Bart Jourquin
Sent: Tuesday, May 29, 2007 12:10 PM
To: OpenMap
Subject: [OpenMap Users] Copy map bean to clipboard fails on Linux

Hi all,

I've implemented the following code to put the current displayed map on the map bean into the clipboard. This code works fine on Windows, but not on Linux (I cannot paste into another app). Any idea?


void copyMapToClipboard() {
        // Get image from mapBean
        int width = getMapBean().getWidth();
        int height = getMapBean().getHeight();
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Graphics g = ge.createGraphics(image);
        g.setClip(0, 0, width, height);
        ImageSelection imgSel = new ImageSelection(image);

        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(imgSel, null);

    // This class is used to hold an image while on the clipboard.
    public static class ImageSelection implements Transferable {
        private Image image;

        public ImageSelection(Image image) {
            this.image = image;

        // Returns supported flavors
        public DataFlavor[] getTransferDataFlavors() {
            return new DataFlavor[] { DataFlavor.imageFlavor };

        // Returns true if flavor is supported
        public boolean isDataFlavorSupported(DataFlavor flavor) {
            return DataFlavor.imageFlavor.equals(flavor);

        // Returns image
        public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
            if (!DataFlavor.imageFlavor.equals(flavor)) {
                throw new UnsupportedFlavorException(flavor);
            return image;

Prof Dr Bart Jourquin
F.U.Ca.M. - G.T.M.
Chaussée de Binche, 151a
B7000 Mons
Tel. : +32 65 323293
Fax. : +32 65 315691
[To unsubscribe to this list send an email to ""
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Tue May 29 2007 - 14:08:18 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:08 EDT