Java Examples In A Nutshell (3rd Edition) [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Java Examples In A Nutshell (3rd Edition) [Electronic resources] - نسخه متنی

O'Reilly Media, Inc

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید








14.5 A Transferable Shape


In order to support data transfer of custom data types, we
need to implement the
Transferable interface. Example 14-4 does that for the PolyLine
class (a java.awt.Shape implementation) defined in
Example 12-16.
Transferable is a simple interface to implement,
and this example is short. Note that the example also defines a
DataFlavor for transferring
PolyLine objects.

Example 14-4. TransferablePolyLine.java

package je3.datatransfer;
import java.awt.datatransfer.*;
import je3.graphics.PolyLine;
/**
* This class implements the Transferable interface for PolyLine objects.
* It also defines a DataFlavor used to describe this data type.
*/
public class TransferablePolyLine implements Transferable {
public static DataFlavor FLAVOR=
new DataFlavor(PolyLine.class,"PolyLine");
static DataFlavor[ ] FLAVORS = new DataFlavor[ ] { FLAVOR };
PolyLine line; // This is the PolyLine we wrap.
public TransferablePolyLine(PolyLine line) { this.line = line; }
/** Return the supported flavor */
public DataFlavor[ ] getTransferDataFlavors( ) { return FLAVORS; }
/** Check for the one flavor we support */
public boolean isDataFlavorSupported(DataFlavor f)
{return f.equals(FLAVOR);}
/** Return the wrapped PolyLine, if the flavor is right */
public Object getTransferData(DataFlavor f)
throws UnsupportedFlavorException
{
if (!f.equals(FLAVOR)) throw new UnsupportedFlavorException(f);
return line;
}
}


/ 285