当前位置: 首页>>代码示例>>Java>>正文


Java SystemFlavorMap类代码示例

本文整理汇总了Java中java.awt.datatransfer.SystemFlavorMap的典型用法代码示例。如果您正苦于以下问题:Java SystemFlavorMap类的具体用法?Java SystemFlavorMap怎么用?Java SystemFlavorMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SystemFlavorMap类属于java.awt.datatransfer包,在下文中一共展示了SystemFlavorMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test1

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
/**
 * Verifies that the encoded native is not added if there are other
 * natives mapped to this DataFlavor.
 */
public static void test1() throws ClassNotFoundException {
    final DataFlavor flavor =
            new DataFlavor("text/plain-TEST; charset=Unicode");

    final java.util.List natives = fm.getNativesForFlavor(flavor);

    if (natives.size() > 1) {
        for (final Iterator i = natives.iterator(); i.hasNext(); ) {
            String element = (String) i.next();
            if (SystemFlavorMap.isJavaMIMEType(element)) {
                throw new RuntimeException("getFlavorsForNative() returns: "
                        + natives);
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:GetNativesForFlavorTest.java

示例2: test4

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
/**
 * Verifies that the encoded native is added only for DataFlavors
 * that has no mappings and that DataFlavor is properly encoded.
 */
public static void test4() throws ClassNotFoundException {
    final DataFlavor flavor =
            new DataFlavor("unknown/unknown");

    final java.util.List natives = fm.getNativesForFlavor(flavor);

    if (natives.size() == 1) {
        String element = (String) natives.get(0);
        if (SystemFlavorMap.isJavaMIMEType(element)) {
            final DataFlavor decodedFlavor =
                    SystemFlavorMap.decodeDataFlavor(element);
            if (!flavor.equals(decodedFlavor)) {
                System.err.println("DataFlavor is not properly incoded:");
                System.err.println("    encoded flavor: " + flavor);
                System.err.println("    decoded flavor: " + decodedFlavor);
                throw new RuntimeException("getFlavorsForNative() returns:"
                        + natives);
            }
        }
    } else {
        throw new RuntimeException("getFlavorsForNative() returns:"
                + natives);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:GetNativesForFlavorTest.java

示例3: initMappings

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
public void initMappings() {
    //initialize mapping variables used in this test
    flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();

    //create a DataFlavor with valid parameters (mimeType, humanPresentableName)
    test_flav = new DataFlavor("text/plain; charset=ascii","ASCII Flavor");

    //create a String native
    test_nat = "TEXT_TEST";

    //create a DataFlavor array
    test_flavors = new DataFlavor[] {test_flav};

    //create a String native array
    test_natives = new String[] {test_nat};
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:InvalidMapArgumentsTest.java

示例4: doTest

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
public void doTest() throws Exception {
    // Initialize DataFlavors and arrays used for test data
    initMappings();

    boolean passed = true;
    flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();

    // Get all the native strings and preferred DataFlavor mappings
    hash = new Hashtable(flavorMap.getFlavorsForNatives(null));
    hashSize = hash.size();

    // GetNativesForFlavor using unknown DataFlavor (verify 2-way mapping)
    //
    // If a new DataFlavor is specified, the method should establish a mapping
    // in both directions between specified DataFlavor and an encoded
    // version of its MIME type as its native.
    System.out.println("GetNativesForFlavor using new DataFlavor");

    comp1 = new Vector(Arrays.asList(test_natives_set));
    comp2 = new Vector(flavorMap.getNativesForFlavor(test_flavor1));

    comp3 = new Vector(Arrays.asList(test_flavors_set));
    comp4 = new Vector(flavorMap.getFlavorsForNative(test_encoded));

    if ( !comp1.equals(comp2) || !comp3.equals(comp4) ) {
        throw new RuntimeException("\n*** After passing a new DataFlavor" +
            "\nwith getNativesForFlavor(DataFlavor flav)" +
            "\nthe mapping in both directions was not established.");
    }
    else
       System.out.println("GetNativesForFlavor using new DataFlavor: Test Passes");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:GetNativesForNewFlavorTest.java

示例5: initMappings

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
public void initMappings() throws Exception {
    //initialize mapping variables used in this test
    //create a DataFlavor from Button class
    test_flavor1 = new DataFlavor(Class.forName("java.awt.Button"), "Button");

    //create an Encoded String native using Button class MIME Type
    String buttonMIME = test_flavor1.getMimeType();
    test_encoded = SystemFlavorMap.encodeJavaMIMEType(buttonMIME);

    //create a DataFlavor from the Encoded String native
    test_flavor2 = SystemFlavorMap.decodeDataFlavor(test_encoded);

    //create and initialize DataFlavor arrays
    test_flavors_set = new DataFlavor[] {test_flavor1};

    //create and initialize String native arrays
    test_natives_set = new String[] {test_encoded};
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:GetNativesForNewFlavorTest.java

示例6: initMappings

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
public void initMappings() throws Exception {
   //initialize mapping variables used in this test
  //create an Unencoded String native
  test_native1 = "TEST1";

  //create a DataFlavor from Button class
  test_flavor1 = new DataFlavor(Class.forName("java.awt.Button"), "Button");

  //create an Encoded String native using Button class MIME Type
  String buttonMIME = test_flavor1.getMimeType();
  test_encoded = SystemFlavorMap.encodeJavaMIMEType(buttonMIME);

  //create a DataFlavor from the Encoded String native
  test_flavor2 = SystemFlavorMap.decodeDataFlavor(test_encoded);

  //create and initialize DataFlavor arrays
  test_flavors_set = new DataFlavor[] {test_flavor2};

  //create and initialize String native arrays
  test_natives_set = new String[] {test_encoded};
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:GetFlavorsForNewNativeTest.java

示例7: main

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

        final DataFlavor dataFlavor = new DataFlavor(TEST_MIME_TYPE);
        SystemFlavorMap systemFlavorMap = (SystemFlavorMap) SystemFlavorMap.
                getDefaultFlavorMap();
        systemFlavorMap.addUnencodedNativeForFlavor(dataFlavor, "TEXT");
        systemFlavorMap.addFlavorForUnencodedNative("TEXT", dataFlavor);

        TransferHandler transferHandler = new TransferHandler("Test Handler");

        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        transferHandler.exportToClipboard(new JLabel("Test"), clipboard,
                TransferHandler.COPY);

        Object clipboardData = clipboard.getData(dataFlavor);

        if (!(clipboardData instanceof MyStringReader)) {
            throw new RuntimeException("Wrong clipboard data!");
        }
    }
 
开发者ID:campolake,项目名称:openjdk9,代码行数:21,代码来源:ConstructFlavoredObjectTest.java

示例8: DropTarget

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
/**
 * Creates a <code>DropTarget</code> object.
 *
 * @exception HeadlessException If GraphicsEnvironment.isHeadless()
 * returns true.
 */
public DropTarget (Component c, int i, DropTargetListener dtl, boolean b,
                   FlavorMap fm)
{
  if (GraphicsEnvironment.isHeadless ())
    throw new HeadlessException ();

  setComponent(c);
  setDefaultActions(i);
  dropTargetListener = dtl;

  if (fm == null)
    flavorMap = SystemFlavorMap.getDefaultFlavorMap();
  else
    flavorMap = fm;

  setActive (b);

  if (c != null)
    c.setDropTarget(this);
}
 
开发者ID:vilie,项目名称:javify,代码行数:27,代码来源:DropTarget.java

示例9: createDataFlavor

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
public static DataFlavor createDataFlavor(@NotNull final String mimeType, @Nullable final Class<?> klass, final boolean register) {
  try {
    final DataFlavor flavor =
      klass != null ? new DataFlavor(mimeType + ";class=" + klass.getName(), null, klass.getClassLoader()) : new DataFlavor(mimeType);

    if (register) {
      final FlavorMap map = SystemFlavorMap.getDefaultFlavorMap();
      if (map instanceof SystemFlavorMap) {
        ((SystemFlavorMap)map).addUnencodedNativeForFlavor(flavor, mimeType);
      }
    }

    return flavor;
  }
  catch (ClassNotFoundException e) {
    LOG.error(e);
    //noinspection ConstantConditions
    return null;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:FileCopyPasteUtil.java

示例10: DropTarget

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
/**
 * Creates a <code>DropTarget</code> object.
 *
 * @exception HeadlessException If GraphicsEnvironment.isHeadless()
 * returns true.
 */
public DropTarget (Component c, int i, DropTargetListener dtl, boolean b,
                   FlavorMap fm)
{
  if (GraphicsEnvironment.isHeadless ())
    throw new HeadlessException ();

  setComponent(c);
  setDefaultActions(i);
  dropTargetListener = dtl;
  
  if (fm == null)
    flavorMap = SystemFlavorMap.getDefaultFlavorMap();
  else
    flavorMap = fm;
  
  setActive (b);
  
  if (c != null)
    c.setDropTarget(this);
}
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:27,代码来源:DropTarget.java

示例11: SwingClipboard

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
public SwingClipboard() {
    super(SwingOptions.getClipbaordPollingMillis());
    if (!SwingUtilities.isEventDispatchThread()) {
        throw new IllegalStateException("The clipboard must be created in the event dispatcher thread");
    }

    this.systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

    final FlavorMap map = SystemFlavorMap.getDefaultFlavorMap();
    if (map instanceof SystemFlavorMap) {
        final SystemFlavorMap systemMap = (SystemFlavorMap) map;
        systemMap.addFlavorForUnencodedNative(TransferContainer.MIME_TYPE, TRANSFER_CONTAINER_FLAVOR);
        systemMap.addUnencodedNativeForFlavor(TRANSFER_CONTAINER_FLAVOR, TransferContainer.MIME_TYPE);
    }

    checkContentChanged();
}
 
开发者ID:jo-source,项目名称:jo-widgets,代码行数:18,代码来源:SwingClipboard.java

示例12: getNativesForFlavors

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
private static List<String> getNativesForFlavors(DataFlavor[] flavors) {
    ArrayList<String> natives = new ArrayList<String>();
    
    SystemFlavorMap flavorMap = 
        (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
    
    for (int i = 0; i < flavors.length; i++) {
        List<String> list = flavorMap.getNativesForFlavor(flavors[i]);
        for (Iterator<String> it = list.iterator(); it.hasNext(); ) {
            String nativeFormat = it.next();
            if (!natives.contains(nativeFormat)) {
                natives.add(nativeFormat);
            }
        }
    }
    return natives;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:18,代码来源:DataSource.java

示例13: DataSnapshot

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
/**
 * @param dataObject
 */
public DataSnapshot(DataProvider data) {
    nativeFormats = data.getNativeFormats();
    text = data.getText();
    fileList = data.getFileList();
    url = data.getURL();
    html = data.getHTML();
    rawBitmap = data.getRawBitmap();
    
    serializedObjects = Collections.synchronizedMap(new HashMap<Class<?>, byte[]>());
    
    for (int i = 0; i < nativeFormats.length; i++) {
        DataFlavor df = null;
        try {
            df = SystemFlavorMap.decodeDataFlavor(nativeFormats[i]);
        } catch (ClassNotFoundException e) {}
        if (df != null) {
            Class<?> clazz = df.getRepresentationClass();
            byte[] bytes = data.getSerializedObject(clazz);
            if (bytes != null) {
                serializedObjects.put(clazz, bytes);
            }
        }
    }
    // TODO: refine the list of native formats
}
 
开发者ID:shannah,项目名称:cn1,代码行数:29,代码来源:DataSnapshot.java

示例14: isNativeFormatAvailable

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
public boolean isNativeFormatAvailable(String nativeFormat) {
    if (nativeFormat == null) {
        return false;
    }
    if (nativeFormat.equals(FORMAT_TEXT)) {
        return (text != null);
    }
    if (nativeFormat.equals(FORMAT_FILE_LIST)) {
        return (fileList != null);
    }
    if (nativeFormat.equals(FORMAT_URL)) {
        return (url != null);
    }
    if (nativeFormat.equals(FORMAT_HTML)) {
        return (html != null);
    }
    if (nativeFormat.equals(FORMAT_IMAGE)) {
        return (rawBitmap != null);
    }
    try {
        DataFlavor df = SystemFlavorMap.decodeDataFlavor(nativeFormat);
        return serializedObjects.containsKey(df.getRepresentationClass());
    } catch (Exception e) {
        return false;
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:27,代码来源:DataSnapshot.java

示例15: getSerializedObject

import java.awt.datatransfer.SystemFlavorMap; //导入依赖的package包/类
private Object getSerializedObject(DataFlavor f)
        throws IOException, UnsupportedFlavorException {
    String nativeFormat = SystemFlavorMap.encodeDataFlavor(f);
    if ((nativeFormat == null) || 
            !data.isNativeFormatAvailable(nativeFormat)) {
        throw new UnsupportedFlavorException(f);
    }
    byte bytes[] = data.getSerializedObject(f.getRepresentationClass());
    if (bytes == null) {
        // awt.4F=Data is not available
        throw new IOException(Messages.getString("awt.4F")); //$NON-NLS-1$
    }
    ByteArrayInputStream str = new ByteArrayInputStream(bytes);
    try {
        return new ObjectInputStream(str).readObject();
    } catch (ClassNotFoundException ex) {
        throw new IOException(ex.getMessage());
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:DataProxy.java


注:本文中的java.awt.datatransfer.SystemFlavorMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。