topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday April 16, 2024, 12:16 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Bug: Cannot copy _both_ file path and image  (Read 4711 times)

eekboom

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 6
    • View Profile
    • Donate to Member
Bug: Cannot copy _both_ file path and image
« on: December 07, 2011, 10:24 PM »
I configured in the options to have Screenshot Captor copy both the file path and the image itself to the clipboard.
(Should be possible from my understanding of the windows clipboard, right?)
[attach=#2][/attach]

However it only ever copies the file path in that case:
[attach=#1][/attach]

ralfs

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 79
    • View Profile
    • Donate to Member
Re: Bug: Cannot copy _both_ file path and image
« Reply #1 on: December 08, 2011, 10:31 AM »
I think these options can't be performed at the same time because windows clipboard only can hold one item (picture or text).
Ralf

eekboom

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 6
    • View Profile
    • Donate to Member
Re: Bug: Cannot copy _both_ file path and image
« Reply #2 on: December 08, 2011, 11:06 AM »
I think these options can't be performed at the same time because windows clipboard only can hold one item (picture or text).
That's just wrong. (Even for text there are already four different formats in the clipboard, see the screenshot of the clipboard viewer in my previous post).
I just verified that the clipboard can also hold image and text formats at the same time: I wrote a small Java program that does exactly that.
When I run the code,
then paste into Paint.NET I get an image:
[attach=#1][/attach]
Paste into Word gets the text:
[attach=#2][/attach]

BTW my use case is: I am frequently using two issue trackers: YouTrack which has an option "Attach Image from Clipboard" and Jira where I need to upload a file. It would be nice to have the screenshot in both formats automatically, so that I can immediately use it on either bug tracker.

Main:
package de.eekboom.cliptest;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.image.BufferedImage;

public class Main {
    public static void main(String[] args) {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        BufferedImage bufferedImage = createImage();

        TextAndImageContent content = new TextAndImageContent("Text & Image in Clipboard", bufferedImage);

        clipboard.setContents(content, null);
    }

    private static BufferedImage createImage() {
        BufferedImage bufferedImage = new BufferedImage(80, 40, BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics = bufferedImage.createGraphics();
        graphics.setPaint(Color.RED);
        graphics.fillOval(5, 5, 70, 30);
        return bufferedImage;
    }
}

Helper class:
package de.eekboom.cliptest;

import java.awt.datatransfer.*;
import java.awt.image.BufferedImage;
import java.io.IOException;

public class TextAndImageContent implements Transferable, ClipboardOwner {
    private final String text;
    private final BufferedImage image;

    private static final DataFlavor[] flavors = {
            DataFlavor.stringFlavor,
            DataFlavor.imageFlavor
    };

    public TextAndImageContent(String text, BufferedImage image) {
        this.text = text;
        this.image = image;
    }

    @Override
    public DataFlavor[] getTransferDataFlavors() {
        return (DataFlavor[])flavors.clone();
    }

    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor) {
        for (DataFlavor supportedFlavor : flavors) {
            if (flavor.equals(supportedFlavor)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
        if (flavor.equals(DataFlavor.stringFlavor)) {
            return text;
        }
        if (flavor.equals(DataFlavor.imageFlavor)) {
            return image;
        }
        return null;
    }

    @Override
    public void lostOwnership(Clipboard clipboard, Transferable contents) {
    }

}

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,612
    • View Profile
    • Donate to Member
Re: Bug: Cannot copy _both_ file path and image
« Reply #3 on: December 08, 2011, 12:10 PM »
and Jira where I need to upload a file
Even rather old Jira versions (4.0) have a nice page where you can paste an image (jpg/png)  from the clipboard to be attached to the issue.

eekboom

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 6
    • View Profile
    • Donate to Member
Re: Bug: Cannot copy _both_ file path and image
« Reply #4 on: December 09, 2011, 06:05 AM »
Right, thanks, I only just now noticed. In my defense: I think our client only updated to that Jira version recently.

Still the issue remains.
At the very least it is a usability bug: If there are two _checkboxes_ which I can both check, then it should work (and it is easy to implement as I demonstrated).
Otherwise there should be a radio group with two mutually exclusive radio buttons.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Bug: Cannot copy _both_ file path and image
« Reply #5 on: December 25, 2011, 11:55 AM »
Fair comments.. and as eekboom says, I should be able to put BOTH on the clipboard at the same time. I shall try.