JDK-6607163 : Linux: Cannot copy image from Java to OpenOffice
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0,6,6u2
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux,linux_2.6
  • CPU: x86
  • Submitted: 2007-09-20
  • Updated: 2011-05-17
  • Resolved: 2011-05-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u10Fixed 7 b25Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
Java HotSpot(TM) Server VM (build 1.6.0_02-b05, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux thinkpad-x60 2.6.20-16-generic #2 SMP Fri Aug 31 00:55:27 UTC 2007 i686 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
Copy an image to the clipboard (using DataFlavor.imageFlavor). Paste the image into a Java application that takes images from the clipboard. It works fine. Paste into OpenOffice or the Gimp. Nothing is pasted.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the program below. Then try to paste into OpenOffice.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An image of a red square should be pasted into OpenOffice.
ACTUAL -
Nothing is pasted.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.image.*;
import javax.swing.*;

/**
 * This program demonstrates the transfer of images between a Java application and the system
 * clipboard.
 * @version 1.22 2007-08-16
 * @author Cay Horstmann
 */
public class ImageTransferTest2
{
   public static void main(String[] args)
   {
      EventQueue.invokeLater(new Runnable()
         {
            public void run()
            {
               JFrame frame = new JFrame();
               frame.setSize(100, 100);
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               frame.setVisible(true);
               BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
               Graphics g = image.getGraphics();
               g.setColor(Color.RED);
               g.fillRect(25, 25, 50, 50);
               Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
               ImageSelection selection = new ImageSelection(image);
               clipboard.setContents(selection, null);
            }
         });
   }
}

class ImageSelection implements Transferable
{
   /**
    * Constructs the selection.
    * @param image an image
    */
   public ImageSelection(Image image)
   {
      theImage = image;
   }

   public DataFlavor[] getTransferDataFlavors()
   {
      return new DataFlavor[] { DataFlavor.imageFlavor };
   }

   public boolean isDataFlavorSupported(DataFlavor flavor)
   {
      return flavor.equals(DataFlavor.imageFlavor);
   }

   public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException
   {
      if (flavor.equals(DataFlavor.imageFlavor))
      {
         return theImage;
      }
      else
      {
         throw new UnsupportedFlavorException(flavor);
      }
   }

   private Image theImage;
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Run Windows.

Comments
EVALUATION OOo doesn't support jpeg/png see 5041996. So, it looks like I have a complete fix for the problem :)
12-11-2007

EVALUATION I have discussed OOo issues with ###@###.### and it looks like there are some problems in OOo with copying images (see http://qa.openoffice.org/issues/show_bug.cgi?id=83376) Thus, for now I will think that the only problem we have in our code is the problem with type of targets which I've mentioned earlier.
07-11-2007

EVALUATION I've found the problem with TARGETS, java sets incorrect type for property which contains all targets we support (TARGETS instead of ATOM). After fixing this problem, we can paste image to GIMP, however OpenOffice doesn't work :( Need to find out what image formats OO expects.
31-10-2007

EVALUATION It looks like OO and Gimp just check TARGETS atom to see if appropriate format is available in clipboard. However we do not set this target :( SO, we need to implement this to be compatible with gtk and other toolkis (TARGETS atom is described in ICCCM 2.6.2)
27-10-2007