How to place multi-flavored text on system clipboard (for native apps)

2001-12-05 Thread Joel Kamentz

I'm running 1.3.1 on win2k.  I want to put multiple versions (plain text, html, ?) of 
the same content on the system clipboard for use by native apps.

Creating a StringSelection for plain text works fine.  However, creating a DataFlavor 
of type text/html doesn't work.  I've tried making my own transferable and returning 
StringReaders, String objects, and InputStreams and nothing seems to work.

Has anyone done this already?

Joel
___
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing



System Clipboard

2001-02-08 Thread Harkishin Nachnani

Hi all
I have an application in which I need to copy some data into the clipboard.
This data is a part of the string:
"key1=value1|key2=value2|key3=value3". So basically I want to copy "value1"
to the clipboard. I have a String Tokenizer on "|" and "=" The strange part
is that it shows me a different value "key1=v" in the clipboard. So when I
try to paste this into the same swing application, I get the desired value
"value1" but when I try to paste it in NOTEPAD, I get "key1=v".
Is that possible ??? Different values from the clipboard for 2 different
applications.
Following is the code...Please give it a try and see the magic for yourself.
Please Help

Regards
Harkishin





//CODE

import java.util.*;
import javax.swing.*;
import java.awt.datatransfer.*;
import java.awt.*;
import java.awt.event.*;


public class screenpop
{
public static void main(String[] args)
{
String data = "key1=value1|key2=value2|key3=value3";
StringTokenizer st = new StringTokenizer(data,"|="); //to
separate the tokens starting with "=" and "|"
int count = st.countTokens();   //get the
count to initialize the size of the array
String[] arr = new String[count/2];
int i=0; String str = "";
while (st.hasMoreTokens())
{
   str = st.nextToken();
//don't store the keywords 
   arr[i] = st.nextToken();
//store the values in a String array
   System.out.println(str + " = " + arr[i]);
   i++;
//get the next keyword, value pair
}   

Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection ss = new StringSelection(arr[0]); //Copy
"value1" to the clipboard
cb.setContents(ss,ss);
System.out.println(arr[0] + " copied to the clipboard, press
edit paste or cntrl + V in notepad ");


}

}
___
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing