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

From: Bart Jourquin <bart.jourquin_at_fucam.ac.be>
Date: Tue, 29 May 2007 18:10:11 +0200

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?

Bart

 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);
        getMapBean().paintAll(g);
        ImageSelection imgSel = new ImageSelection(image);


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

    // 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
Belgium
Tel. : +32 65 323293
Fax. : +32 65 315691
http://www.fucam.ac.be/jourquin
--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Tue May 29 2007 - 12:14:21 EDT

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