Java Reference
In-Depth Information
Example 13−2: Scribble.java (continued)
}
/**
* Get the coordinates of the current moveto or lineto as doubles
**/
public int currentSegment(double[] coords) {
int retval;
if (Double.isNaN(points[i])) {
coords[0] = points[i+1];
coords[1] = points[i+2];
retval = SEG_MOVETO;
}
else {
coords[0] = points[i];
coords[1] = points[i+1];
retval = SEG_LINETO;
}
if (transform != null) transform.transform(coords, 0, coords, 0,1);
return retval;
}
}
//====== The following methods implement the Transferable interface =====
// This is the custom DataFlavor for Scribble objects
public static DataFlavor scribbleDataFlavor =
new DataFlavor(Scribble.class, "Scribble");
// This is a list of the flavors we know how to work with
public static DataFlavor[] supportedFlavors = {
scribbleDataFlavor,
DataFlavor.stringFlavor
};
/** Return the data formats or "flavors" we know how to transfer */
public DataFlavor[] getTransferDataFlavors() {
return (DataFlavor[]) supportedFlavors.clone();
}
/** Check whether we support a given flavor */
public boolean isDataFlavorSupported(DataFlavor flavor) {
return (flavor.equals(scribbleDataFlavor) ||
flavor.equals(DataFlavor.stringFlavor));
}
/**
* Return the scribble data in the requested format, or throw an exception
* if we don't support the requested format
**/
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException
{
if (flavor.equals(scribbleDataFlavor)) { return this; }
else if (flavor.equals(DataFlavor.stringFlavor)) { return toString(); }
else throw new UnsupportedFlavorException(flavor);
}
}
Search WWH ::




Custom Search