Methods Summary |
---|
protected java.lang.String | getHTMLData()Fetch the data in a text/html format
return htmlData;
|
protected java.lang.String | getPlainData()Fetch the data in a text/plain format.
return plainData;
|
protected java.lang.Object | getRicherData(java.awt.datatransfer.DataFlavor flavor)
return null;
|
protected java.awt.datatransfer.DataFlavor[] | getRicherFlavors()Some subclasses will have flavors that are more descriptive than HTML
or plain text. If this method returns a non-null value, it will be
placed at the start of the array of supported flavors.
return null;
|
public java.lang.Object | getTransferData(java.awt.datatransfer.DataFlavor flavor)Returns an object which represents the data to be transferred. The class
of the object returned is defined by the representation class of the flavor.
DataFlavor[] richerFlavors = getRicherFlavors();
if (isRicherFlavor(flavor)) {
return getRicherData(flavor);
} else if (isHTMLFlavor(flavor)) {
String data = getHTMLData();
data = (data == null) ? "" : data;
if (String.class.equals(flavor.getRepresentationClass())) {
return data;
} else if (Reader.class.equals(flavor.getRepresentationClass())) {
return new StringReader(data);
} else if (InputStream.class.equals(flavor.getRepresentationClass())) {
return new StringBufferInputStream(data);
}
// fall through to unsupported
} else if (isPlainFlavor(flavor)) {
String data = getPlainData();
data = (data == null) ? "" : data;
if (String.class.equals(flavor.getRepresentationClass())) {
return data;
} else if (Reader.class.equals(flavor.getRepresentationClass())) {
return new StringReader(data);
} else if (InputStream.class.equals(flavor.getRepresentationClass())) {
return new StringBufferInputStream(data);
}
// fall through to unsupported
} else if (isStringFlavor(flavor)) {
String data = getPlainData();
data = (data == null) ? "" : data;
return data;
}
throw new UnsupportedFlavorException(flavor);
|
public java.awt.datatransfer.DataFlavor[] | getTransferDataFlavors()Returns an array of DataFlavor objects indicating the flavors the data
can be provided in. The array should be ordered according to preference
for providing the data (from most richly descriptive to least descriptive).
DataFlavor[] richerFlavors = getRicherFlavors();
int nRicher = (richerFlavors != null) ? richerFlavors.length : 0;
int nHTML = (isHTMLSupported()) ? htmlFlavors.length : 0;
int nPlain = (isPlainSupported()) ? plainFlavors.length: 0;
int nString = (isPlainSupported()) ? stringFlavors.length : 0;
int nFlavors = nRicher + nHTML + nPlain + nString;
DataFlavor[] flavors = new DataFlavor[nFlavors];
// fill in the array
int nDone = 0;
if (nRicher > 0) {
System.arraycopy(richerFlavors, 0, flavors, nDone, nRicher);
nDone += nRicher;
}
if (nHTML > 0) {
System.arraycopy(htmlFlavors, 0, flavors, nDone, nHTML);
nDone += nHTML;
}
if (nPlain > 0) {
System.arraycopy(plainFlavors, 0, flavors, nDone, nPlain);
nDone += nPlain;
}
if (nString > 0) {
System.arraycopy(stringFlavors, 0, flavors, nDone, nString);
nDone += nString;
}
return flavors;
|
public boolean | isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)Returns whether or not the specified data flavor is supported for
this object.
DataFlavor[] flavors = getTransferDataFlavors();
for (int i = 0; i < flavors.length; i++) {
if (flavors[i].equals(flavor)) {
return true;
}
}
return false;
|
protected boolean | isHTMLFlavor(java.awt.datatransfer.DataFlavor flavor)Returns whether or not the specified data flavor is an HTML flavor that
is supported.
DataFlavor[] flavors = htmlFlavors;
for (int i = 0; i < flavors.length; i++) {
if (flavors[i].equals(flavor)) {
return true;
}
}
return false;
|
protected boolean | isHTMLSupported()Should the HTML flavors be offered? If so, the method
getHTMLData should be implemented to provide something reasonable.
return htmlData != null;
|
protected boolean | isPlainFlavor(java.awt.datatransfer.DataFlavor flavor)Returns whether or not the specified data flavor is an plain flavor that
is supported.
DataFlavor[] flavors = plainFlavors;
for (int i = 0; i < flavors.length; i++) {
if (flavors[i].equals(flavor)) {
return true;
}
}
return false;
|
protected boolean | isPlainSupported()Should the plain text flavors be offered? If so, the method
getPlainData should be implemented to provide something reasonable.
return plainData != null;
|
protected boolean | isRicherFlavor(java.awt.datatransfer.DataFlavor flavor)
DataFlavor[] richerFlavors = getRicherFlavors();
int nFlavors = (richerFlavors != null) ? richerFlavors.length : 0;
for (int i = 0; i < nFlavors; i++) {
if (richerFlavors[i].equals(flavor)) {
return true;
}
}
return false;
|
protected boolean | isStringFlavor(java.awt.datatransfer.DataFlavor flavor)Returns whether or not the specified data flavor is a String flavor that
is supported.
DataFlavor[] flavors = stringFlavors;
for (int i = 0; i < flavors.length; i++) {
if (flavors[i].equals(flavor)) {
return true;
}
}
return false;
|