Drop support only works on the second drop

Hi,
I created an ImageComponent that accepts drops and displays images. The problem I'm facing is that the drop is only accepted on the second try. For some reason the getDataFlavors() method on the TransferSupport returns an empty array on the first drop.
I'm dropping a JPG file from the desktop on my ImageComponent. I'm running it in debug mode with the latest version of Eclipse on Mac OS X 10.6.
I hope someone can help me solve this problem.
Thanks in advance,
Stef
Here is my source code:
public class ImageComponent extends JComponent {
     private static final long serialVersionUID = 1L;
     private BufferedImage image;
     private final Vector<ImageChangeListener> listeners = new Vector<ImageChangeListener>();
     public ImageComponent() {
          setTransferHandler(new ImageTransferHandler());
     public synchronized void addImageChangeListener(ImageChangeListener listener) {
          listeners.add(listener);
     public synchronized void removeImageChangeListener(ImageChangeListener listener) {
          listeners.remove(listener);
     public void setImage(BufferedImage image) {
          this.image = image;
          paint(getGraphics());
     @Override
     public Dimension getPreferredSize() {
          if (image != null) {
               BufferedImage scaledImage = Utils.scaleImage(image, getWidth(), getHeight());
               return new Dimension(scaledImage.getWidth(), scaledImage.getHeight());
          } else {
               return super.getPreferredSize();
     @Override
     public void paint(Graphics g) {
          if (g != null) {
               g.clearRect(0, 0, getWidth(), getHeight());
               super.paint(g);
               if (image != null) {
                    BufferedImage scaledImage = Utils.scaleImage(image, getWidth(), getHeight());
                    int x = ((getWidth() - scaledImage.getWidth()) / 2);
                    int y = ((getHeight() - scaledImage.getHeight()) / 2);
                    g.drawImage(scaledImage, x, y, null);
     private void fireImageChange() {
          ImageChangeEvent event = new ImageChangeEvent(this, image);
          for (ImageChangeListener listener : listeners) {
               listener.imageChanged(event);
          setImage(image);
     private class ImageTransferHandler extends TransferHandler {
          @Override
          public boolean canImport(TransferSupport support) {
               for (DataFlavor dataFlavor : support.getDataFlavors()) { // Returns an empty array on the first drop
                    System.out.println(dataFlavor);
               return support.isDataFlavorSupported(DataFlavor.javaFileListFlavor); // returns false on the first drop, true on consecutive drops
          @Override
          public boolean importData(TransferSupport support) {
               if (canImport(support)) {
                    BufferedImage newImage = readFirstImage(support);
                    if (newImage != null) {
                         setImage(newImage);
                         fireImageChange();
                         return true;
                    } else {
                         return false;
               } else {
                    return false;
          private BufferedImage readFirstImage(TransferSupport support) {
               try {
                    List<File> fileList = (List<File>) support.getTransferable().getTransferData(
                              DataFlavor.javaFileListFlavor);
                    if (fileList != null && fileList.size() > 0) {
                         File file = fileList.get(0);
                         return ImageIO.read(file);
                    } else {
                         return null;
               catch (IIOException exception) {
                    return null;
               catch (IOException exception) {
                    exception.printStackTrace();
                    return null;
               catch (UnsupportedFlavorException exception) {
                    return null;
               catch (Exception e) {
                    return null;
}

I'm on a relatively new system, where I haven't set much up, but I don't get any package-name completion which highlights the point that this is shell (and shell config) dependent.  What shell are you using?  Have you done anything to configure completion?  Do you have any pacman related aliases (or functions)?
I do, by default bash settings it seems, get filename completion with pacman -R, so the options are files in the current directory.
EDIT: (duh) just installing bash-completion now - new results momentarily - but more on point, this further highlghts the shell + config dependent nature of this.  EDIT2: works as expected with bash-completion installed.
Last edited by Trilby (2013-07-15 21:58:12)

Similar Messages

  • [Solved] Autocmplete on -R only works on the second package argument

    Hey guys,
    So when using pacman (or yaourt) to remove a package the autocomplete doesn't seem to work for the first package.
    For example, autocompleting the removal of "chromium"
    pacman -R chro[TAB]
    Does nothing, however if I type
    pacman -R firefox chro[TAB]
    It will properly autocomplete.
    Autocomplete also works when specifying the options as
    pacman -R -ns chro[TAB]
    I saw this thread which describes the same issue, however the solution isn't a proper one as it just completes executables in the $PATH.
    Last edited by EvanPurkhiser (2013-07-16 00:43:26)

    I'm on a relatively new system, where I haven't set much up, but I don't get any package-name completion which highlights the point that this is shell (and shell config) dependent.  What shell are you using?  Have you done anything to configure completion?  Do you have any pacman related aliases (or functions)?
    I do, by default bash settings it seems, get filename completion with pacman -R, so the options are files in the current directory.
    EDIT: (duh) just installing bash-completion now - new results momentarily - but more on point, this further highlghts the shell + config dependent nature of this.  EDIT2: works as expected with bash-completion installed.
    Last edited by Trilby (2013-07-15 21:58:12)

  • 'On open' only works in the same folder?

    I'm running an 'On open' script but it only works when the folder to be processed that placed onto the AS is in the same folder.
    Is there a workaround?

    I'm not familiar with ImageMagick, but there are a couple of issues with your script.
    1) The on open handler takes the files dropped on the application as it's arguments, but you are using the Finder's currently selected items.
    2) File paths that might contain spaces should be quoted, or your shell script will break when it tries to do something with the space delimited items.
    If you are just trying to create a text string that contains all of the (selected or dropped) items, something like the following should work (I just used a dialog to show what the shell script would be - you should test before using mogrify on original files):
    Finder selection:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    set upath to ""
    tell application "Finder" to repeat with f in (get selection)
    set chosenfile to quoted form of POSIX path of (f as text)
    set upath to upath & chosenfile & space
    end repeat
    display dialog "do shell script " & "/opt/local/bin/mogrify -format jpg " & upath & "*.psd"
    beep 2
    </pre>
    on open handler:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    on open TheItems
    set upath to ""
    repeat with f in TheItems
    set chosenfile to quoted form of POSIX path of (f as text)
    set upath to upath & chosenfile & space
    end repeat
    display dialog "do shell script " & "/opt/local/bin/mogrify -format jpg " & upath & "*.psd"
    beep 2
    end open
    </pre>

  • I have the portable BOSE sound dock and after updating my ipod to ios7 the remote control of the dock only works for the volume but doesnt work for skipping songs....Is there a solution to this?

    I have the portable BOSE sound dock and after updating my ipod to ios7 the remote control of the dock only works for the volume but doesnt work for skipping songs....Is there a solution to this?

    Have you went to Bose"s support site?
    Sometimes this works
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                 
    iOS: How to back up                                                                
    - Restore to factory settings/new iOS device.             
    However, sometimes an iOS update breaks compatibility and you will have to wait for an firmware update for the Bose or an iOS update.

  • I don't know what's wrong with my camara it's all black and the front only works not the back

    I don't know what's wrong with my camara it's all black and the front only works not the back

    Try This...
    Close All Open Apps... Sign Out of your Account... Perform a Reset... Try again...
    Reset  ( No Data will be Lost )
    Press and Hold the Sleep/Wake Button and the Home Button at the Same Time...
    Wait for the Apple logo to Appear...
    Usually takes about 15 - 20 Seconds... ( But can take Longer...)
    Release the Buttons...

  • IPad2 charger stop to work after the second charging

    My iPad2 charger doesn't work after the second charging. In local resseler didn't want to change with new one. What I have to do to use my new iPad2? I have iPad2 30 days but I can not use it.

    If, as you say, the local reseller is not being helpful... Then Contact Apple.
    Apple Contact USA
    http://www.apple.com/contact/
    Contacting Apple World Wide for Support and Service
    http://support.apple.com/kb/HE57

  • My ringer only works for the phone ringer. It is silent on all other functions. Anyone experience this before? All settings are correct.

    My ringer only works on the phone. All other functions are silent and the ringer increase button does not add volume.

    Had this happen today and 2X past as you discribed. A reboot (turn phone off and on) restored all sounds for me. The first time I can't associate w/ a cause but the second and third were just after listening to a podcast using the apple podcast app - the only app available for that. That's my story and for now I'm sticking to it.

  • TS3274 I went to an Apple store yesterday and the guy there did something and now the ipad only works in the vertical (portrait) position and not the horizontal (landscape) position.  How can we make it work in both positions?

    I went to an Apple store yesterday and the guy there did something and now the ipad only works in the vertical (portrait) position and not the horizontal (landscape) position.  How can we make it work in both positions?

    Just in case you are not running iOS 7 and don't have the control center feature.....
    If you see a lock icon in the upper right corner of the screen - then the screen orientation is locked.
    Try the side switch above the volume rocker first and see if that unlocks the screen. If that doesn't do it and you are running iOS 5 or 6, double tap the home button and swipe to the right and look for the lock icon all the way to the left.
    If you are running iOS 7, swipe up from the bottom of the screen to get to the control center and the lock icon is in the row of icons at the top all the way to the right.
    If the screen is unlocked but still will not rotate, reset the iPad.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the button

  • Blackberry Curve 8530 track pad only works on the main screen

    I have a blackberry curve 8530 and the track pad will only work on the main screen.  I have removed the battery and let it sit for 2 minutes before re-installing it again, the track pad started working but only for about 30 seconds and it back to the same thing.
    Any suggestion? 
    Thanks You

    Suggest that you get your handset serviced by an expert this will solve your problem..

  • Does iMessage only work with the newest iPod Touch generation?

    Does iMessage only work with the newest iPod Touch generation or does it work with older ones as well?

    Any iPod Touch device that can be upgraded to iOS 5 will have iMessage. This means if you have a 3rd or 4th generation iPod Touch it will support iMessage.
    See this article on what features your iPod Touch supports
    http://support.apple.com/kb/HT4962

  • With my i phone 4 , the Push notifications doesn't work for apps like (fb viber , whatsapp etc ) it only works for the official apps like message  even when im using the phone, has  this probleme with the iOs 6.0.1 and also with the iOs 6.1

    With my i phone 4 , the Push notifications doesn't work for apps like (fb viber , whatsapp etc ) it only works for the official apps like message  even when im using the phone, has  this probleme with the iOs 6.0.1 and also with the iOs 6.1

    This isn't an issue. Notice the screen prior to the one that shows usage has an iCloud section and a Manage Storage button. For this button to activate ios needs to download a few kb from icloud. Switching back to this screen forces ios to download those few kb.

  • Flash Player only works for the account that downloaded it

    I downloaded flash player and did not specify any special preferences, however, it doesn't work for the 2 other accounts on the computer.  It only runs for the Administrator account from which i downloaded it. I'm running XP professional. Can someone tell me how to fix this?

    hi, i had already deleted cookies, temp internet files, etc;
    i only have the IE pop up blocker and blocking level set at Medium;
    it's the latest version of FP 10.0.45.2.
    I installed this version a couple of weeks ago and it worked ok for all accounts (the other 2 accounts are not admin) for a week. Then, it stopped working for all accounts, i reinstalled it (some trial and error involved), then when it finally reinstalled, only works for the one account. i just tried to reinstall from one of the other accounts and error mssg said  "failed to register"
    Date: Sun, 6 Jun 2010 11:20:59 -0600
    From: [email protected]
    To: [email protected]
    Subject: Flash Player only works for the account that downloaded it
    Hi ol, I would go to Tools, click on Internet Options and clear the Temp files. Delete Cookies, Delete Files, including the off line content. I would do this using all accounts. Also check the history files while you are there and delete those also unless you have done so recently.
    What version of Flash Player do you have Installed?
    Do you use any adblock or pop up blocker software?
    Thanks,
    eidnolb
    >

  • I purchased a new vehicle with a USP port but my nano model A199 will not work, only works with the aux plug which will not allow me to view the songs on the vehicle touchscreen. Is there a download I can get to put into this nano?

    I purchased a new vehicle and the older ipod nano I have will not work through the USP  port, only works through the aux plug. Is there a download i can get toput into the nano that will then allow me to use the USP port instead of the aux port?

    Check with your dealer and see if there is a special cable available for connecting your iPod. It should have a dock connector on one end and USB and miniplug on the other.

  • Including image in SharePoint survey answer and hiding elements only work on the first page

    Hi All,
    I would like to add some text/remove some text etc on a sharepoint survey page.
       Which i have done using jquery/jscript.
    But unfortunately it only works on the first page.
    Any ideas how i can get it to work on all the pages?
    See a sample here on how you can add the scripts:
        http://sharepointkings.blogspot.com.au/2011/05/include-image-in-sharepoint-survey.html
    Cheers

    Hi Patrick, does the first page use the same ASPX file as the other pages? If not, you will need to add your jquery/jscript to the other page as well.
    Dimitri Ayrapetov (MCSE: SharePoint)

  • The CustomDatumExample.java only works if the Employee object has 2 attributes.

    The CustomDatumExample.java only works
    if the Employee object has 2 attributes -
    (EmpName and EmpNo). If I try to add
    another attribute to the Employee object I get java.lang.ArrayIndexOutOfBoundsException: 2 on the getAttr3 method.
    Anyone know why? Thanks.
    Employee object
    CREATE TYPE employee AS OBJECT
    (empname VARCHAR2(50), empno INTEGER,
    attr3 VARCHAR2(50));
    Custom object class
    public class Employee implements CustomDatum, CustomDatumFactory
    public static final String SQLNAME = "EMPLOYEE";
    public static final int SQLTYPECODE = OracleTypes.STRUCT;
    MutableStruct _struct;
    static int[] _sqlType =
    12, 4
    static CustomDatumFactory[] _factory = new CustomDatumFactory[3];
    static final Employee _EmployeeFactory = new Employee();
    public static CustomDatumFactory getFactory()
    return _EmployeeFactory;
    /* constructor */
    public Employee()
    struct = new MutableStruct(new Object[3], sqlType, _factory);
    /* CustomDatum interface */
    public Datum toDatum(OracleConnection c) throws SQLException
    return struct.toDatum(c, SQL_NAME);
    /* CustomDatumFactory interface */
    public CustomDatum create(Datum d, int sqlType) throws SQLException
    if (d == null) return null;
    Employee o = new Employee();
    o._struct = new MutableStruct((STRUCT) d, sqlType, factory);
    return o;
    /* accessor methods */
    public String getEmpname() throws SQLException
    { return (String) _struct.getAttribute(0); }
    public void setEmpname(String empname) throws SQLException
    { _struct.setAttribute(0, empname); }
    public Integer getEmpno() throws SQLException
    { return (Integer) _struct.getAttribute(1); }
    public void setEmpno(Integer empno) throws SQLException
    { _struct.setAttribute(1, empno); }
    public String getAttr3() throws SQLException
    { return (String) _struct.getAttribute(2); }
    public void setAttr3(String attr3) throws SQLException
    { _struct.setAttribute(2, attr3); }
    }

    You also need to add an appropriate element to the _sqlType array.
    In practice, it is easiest to have JPublisher regenerate the CustomDatum class when you have changed your object type definition:
    jpub -user=scott/tiger -sql=EMPLOYEE:Employee

Maybe you are looking for

  • Backup disk image cannot be mounted.

    I have tried and tried to get Time Machine up and running with no success. It has given me several error messages...the latest of which is "The backup disk image could not be mounted." I can see the disk in my "shared" finder window, make changes but

  • Scanning and Copy never start on Office Jest 6700

    When I go to copy or scan on my Office Jet 6700. I am unable to do so. Te scanner/copier says that it is "Starting Copying..." or "Starting Scanning" but it does nothing...I have tried turing off and on, unpluging, reseting to factory settings, etc.

  • Invoice reports

    hi mm guru's, can any body help me for the report of invoiced documents. my requirement is the report should contain--- vendor's list,GL  accounts carried out at LIV and amount to be paid to vendor. please help me out. regards, rahul

  • How to send information/warning message from CRM to B2B application

    Hi, I need to send information/warning mesage from CRM to B2B application. I am using FM CRM_MESSAGE_COLLECT to send the required message to application log first and then implemented a BADI called CRM_ISA_BASKET_MSGS for reading that message to disp

  • Question about Delegate Control to Desktop Support

    I am working on delegating control to a newly formed/reclassified position in my company. This role will primarily provide Desktop Support. They will have little to no need to log into servers. I have already gave them admin rights to the end users m