United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6607163 Linux: Cannot copy image from Java to OpenOffice
JDK-6607163 : Linux: Cannot copy image from Java to OpenOffice

Details
Type:
Bug
Submit Date:
2007-09-20
Status:
Closed
Updated Date:
2011-05-17
Project Name:
JDK
Resolved Date:
2011-05-17
Component:
client-libs
OS:
linux,linux_2.6
Sub-Component:
java.awt
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0,6,6u2
Fixed Versions:

Related Reports
Backport:
Duplicate:
Duplicate:
Duplicate:

Sub Tasks

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

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)
                                     
2007-10-27
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.
                                     
2007-10-31
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.
                                     
2007-11-07
EVALUATION

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



Hardware and Software, Engineered to Work Together