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


Java SystemFlavorMap.addUnencodedNativeForFlavor方法代码示例

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


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

示例1: 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

示例2: 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

示例3: addType

import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
private static void addType(Map result, String atom, String mimeType, String description, String className)
{
   try
   {
      DataFlavor df = new DataFlavor(mimeType, description);
      SystemFlavorMap map =  (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
      map.addUnencodedNativeForFlavor(df, atom);

      ClassLoader loader = Thread.currentThread().getContextClassLoader();
      Class cls = loader == null ? Class.forName(className) : loader.loadClass(className);
      ExportFileType type = (ExportFileType) cls.newInstance();

      result.put(df,type);
   }
   catch (Throwable x)
   {
      System.err.println("Unable to install flavor for mime type '"+mimeType+"' (this is expected if not using JDK 1.4)");
   }
}
 
开发者ID:phuseman,项目名称:r2cat,代码行数:20,代码来源:VectorGraphicsTransferable.java

示例4: addUnicodeClasses

import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
public static void addUnicodeClasses(SystemFlavorMap fm,
                                     String nat,
                                     String subType) {
    for (int i = 0; i < unicodeTextClasses.length; i++) {
        String type = "text/" + subType; //$NON-NLS-1$
        String params = ";class=\"" +  //$NON-NLS-1$
                unicodeTextClasses[i].getName() + "\""; //$NON-NLS-1$
        DataFlavor f = new DataFlavor(type + params, type);
        fm.addFlavorForUnencodedNative(nat, f);
        fm.addUnencodedNativeForFlavor(f, nat);
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:13,代码来源:TextFlavor.java

示例5: addCharsetClasses

import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
public static void addCharsetClasses(SystemFlavorMap fm, 
                                     String nat,
                                     String subType, 
                                     String charset) {
    for (int i = 0; i < charsetTextClasses.length; i++) {
        String type = "text/" + subType; //$NON-NLS-1$
        String params = ";class=\"" +  //$NON-NLS-1$
                charsetTextClasses[i].getName() + "\"" +  //$NON-NLS-1$
                ";charset=\"" + charset + "\""; //$NON-NLS-1$ //$NON-NLS-2$
        DataFlavor f = new DataFlavor(type + params, type);
        fm.addFlavorForUnencodedNative(nat, f);
        fm.addUnencodedNativeForFlavor(f, nat);
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:15,代码来源:TextFlavor.java

示例6: main

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

        final String nativeString = "NATIVE";
        final DataFlavor dataFlavor = new DataFlavor();

        final SystemFlavorMap fm =
                (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();

        fm.addUnencodedNativeForFlavor(dataFlavor, nativeString);
        fm.addUnencodedNativeForFlavor(dataFlavor, nativeString);

        final java.util.List natives =
                fm.getNativesForFlavor(dataFlavor);
        boolean found = false;

        for (final Iterator i = natives.iterator(); i.hasNext(); ) {
            if (nativeString.equals(i.next())) {
                if (found) {
                    throw new RuntimeException("getNativesForFlavor() returns:" +
                            natives);
                } else {
                    found = true;
                }
            }
        }

        if (!found) {
            throw new RuntimeException("getNativesForFlavor() returns:" +
                    natives);
        }

        fm.addFlavorForUnencodedNative(nativeString, dataFlavor);
        fm.addFlavorForUnencodedNative(nativeString, dataFlavor);

        final java.util.List flavors =
                fm.getFlavorsForNative(nativeString);
        found = false;

        for (final Iterator i = flavors.iterator(); i.hasNext(); ) {
            if (dataFlavor.equals(i.next())) {
                if (found) {
                    throw new RuntimeException("getFlavorsForNative() returns:" +
                            flavors);
                } else {
                    found = true;
                }
            }
        }

        if (!found) {
            throw new RuntimeException("getFlavorsForNative() returns:" +
                    natives);
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:55,代码来源:DuplicateMappingTest.java

示例7: doTest

import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
public void doTest() {
    flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();

    // Get SystemFlavorMap Maps of String Natives and DataFlavors
    mapFlavors = flavorMap.getNativesForFlavors(null);
    mapNatives = flavorMap.getFlavorsForNatives(null);

    hashFlavors = new Hashtable(mapFlavors);
    hashNatives = new Hashtable(mapNatives);

    // Test addUnencodedNativeForFlavor(DataFlavor flav, String nat);
    //
    // Enumerate through all the system defined DataFlavors,
    // and for each DataFlavor, define it again to the SystemFlavorMap
    // with a slightly modified Mime Type.
    //
    // As a list of String natives will be returned for each DataFlavor,
    // the method addUnencodedNativeForFlavor will be called for each
    // String native in the list.
    //
    // For verification, a seperate Hashtable (Map) will be maintained with changes.
    DataFlavor key;
    hashVerify = new Hashtable();

    for (Enumeration e = hashFlavors.keys() ; e.hasMoreElements() ;) {
        key = (DataFlavor)e.nextElement();

        java.util.List listNatives = flavorMap.getNativesForFlavor(key);
        Vector vectorNatives = new Vector(listNatives);

        // Construct a new DataFlavor from an existing DataFlavor's MimeType
        // Example:
        // Original MimeType: "text/plain; class=java.io.Reader; charset=Unicode"
        // Modified MimeType: "text/plain-TEST; class=java.io.Reader; charset=Unicode"

        StringBuffer mimeType = new StringBuffer(key.getMimeType());
        mimeType.insert(mimeType.indexOf(";"),"-TEST");

        DataFlavor testFlavor = new DataFlavor(mimeType.toString(), "Test DataFlavor");

        for (ListIterator i = vectorNatives.listIterator() ; i.hasNext() ;) {
            String element = (String)i.next();
            flavorMap.addUnencodedNativeForFlavor(testFlavor, element);
        }

        //Added following 4 lines - Aruna Samji - 07/22/2003
        Vector existingNatives = new Vector(flavorMap.getNativesForFlavor(testFlavor));
        existingNatives.addAll(vectorNatives);
        vectorNatives = existingNatives;
        hashVerify.put(testFlavor, vectorNatives);
    }

    // Assertions: After establishing "new" mappings, verify that the defined
    //             DataFlavors can be retrieved.
    verifyNewMappings();
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:57,代码来源:AddNativeTest.java

示例8: doTest

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

    flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();

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

    // Setup One-way Mappings
    System.out.println("One-way Mappings Test");
    flavorMap.addFlavorForUnencodedNative(test_native, test_flavor1);
    flavorMap.addFlavorForUnencodedNative(test_native, test_flavor2);

    // Confirm mapping with getFlavorsForNative
    comp1 = new Vector(Arrays.asList(test_flavors_set1));
    comp2 = new Vector(flavorMap.getFlavorsForNative(test_native));

    if ( !comp1.equals(comp2)) {
        throw new RuntimeException("\n*** After setting up one-way mapping" +
            "\nwith addFlavorForUnencodedNative(String nat, DataFlavor flav)" +
            "\nthe mappings returned from getFlavorsForNative() do not match" +
            "\noriginal mappings.");
    }
    else
       System.out.println("One-way: Test Passes");

    // Setup Two-way Mapping
    System.out.println("Two-way Mappings Test");
    flavorMap.addUnencodedNativeForFlavor(test_flavor1, test_native);
    flavorMap.addUnencodedNativeForFlavor(test_flavor2, test_native);

    // Confirm mapping with getNativesForFlavor
    comp1 = new Vector(Arrays.asList(test_natives_set));
    comp2 = new Vector(flavorMap.getNativesForFlavor(test_flavor1));
    comp3 = new Vector(flavorMap.getNativesForFlavor(test_flavor2));

    if ( !(comp1.equals(comp2)) || !(comp1.equals(comp3))) {
        throw new RuntimeException("\n*** After setting up two-way mapping" +
            "\nwith addUnencodedNativeForFlavor(DataFlavor flav, String nat)" +
            "\nthe mappings returned from getNativesForFlavor() do not match" +
            "\noriginal mappings.");
    }
    else
       System.out.println("Two-way (String native): Test Passes");

    // Check first native mapping
    comp1 = new Vector(Arrays.asList(test_flavors_set1));
    comp2 = new Vector(flavorMap.getFlavorsForNative(test_native));

    if ( !comp1.equals(comp2)) {
        throw new RuntimeException("\n*** After setting up two-way mapping" +
            "\nwith addFlavorForUnencodedNative(String nat, DataFlavor flav)" +
            "\nthe mappings returned from getFlavorsForNative() do not match" +
            "\noriginal mappings.");
    }
    else
       System.out.println("Two-way (DataFlavor): Test Passes");

    // Modify an existing mapping test
    System.out.println("Modify Existing Mappings Test");
    flavorMap.addFlavorForUnencodedNative(test_native, test_flavor3);
    flavorMap.addFlavorForUnencodedNative(test_native, test_flavor4);

    // Confirm mapping with getFlavorsForNative
    comp1 = new Vector(Arrays.asList(test_flavors_set2));
    comp2 = new Vector(flavorMap.getFlavorsForNative(test_native));

    if ( !comp1.equals(comp2)) {
        throw new RuntimeException("\n*** After modifying an existing mapping" +
            "\nwith addFlavorForUnencodedNative(String nat, DataFlavor flav)" +
            "\nthe mappings returned from getFlavorsForNative() do not match" +
            "\nupdated mappings.");
    } else
       System.out.println("Modify Existing Mappings: Test Passes");
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:78,代码来源:AddFlavorForNativeTest.java

示例9: doTest

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

    flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();

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

    // Setup One-way Mappings
    System.out.println("One-way Mappings Test");
    flavorMap.addUnencodedNativeForFlavor(test_flav, test_native1);
    flavorMap.addUnencodedNativeForFlavor(test_flav, test_native2);

    // Confirm mapping with getNativesForFlavor
    comp1 = new Vector(Arrays.asList(test_natives_set1));
    comp2 = new Vector(flavorMap.getNativesForFlavor(test_flav));

    if ( !comp1.equals(comp2)) {
        throw new RuntimeException("\n*** After setting up one-way mapping" +
            "\nwith addUnencodedNativeForFlavor(DataFlavor flav, String nat)" +
            "\nthe mappings returned from getNativesForFlavor() do not match" +
            "\noriginal mappings.");
    }
    else
       System.out.println("One-way: Test Passes");

    // Setup Two-way Mapping
    System.out.println("Two-way Mappings Test");
    flavorMap.addFlavorForUnencodedNative(test_native1, test_flav);
    flavorMap.addFlavorForUnencodedNative(test_native2, test_flav);

    // Confirm mapping with getFlavorsForNative
    comp1 = new Vector(Arrays.asList(test_flavors_set));
    comp2 = new Vector(flavorMap.getFlavorsForNative(test_native1));
    comp3 = new Vector(flavorMap.getFlavorsForNative(test_native2));

    if ( !(comp1.equals(comp2)) || !(comp1.equals(comp3))) {
        throw new RuntimeException("\n*** After setting up two-way mapping" +
            "\nwith addFlavorForUnencodedNative(String nat, DataFlavor flav)" +
            "\nthe mappings returned from getFlavorsForNative() do not match" +
            "\noriginal mappings.");
    }
    else
       System.out.println("Two-way (DataFlavor): Test Passes");

    // Check first native mapping
    comp1 = new Vector(Arrays.asList(test_natives_set1));
    comp2 = new Vector(flavorMap.getNativesForFlavor(test_flav));

    if ( !comp1.equals(comp2)) {
        throw new RuntimeException("\n*** After setting up two-way mapping" +
            "\nwith addUnencodedNativeForFlavor(DataFlavor flav, String nat)" +
            "\nthe mappings returned from getNativesForFlavor() do not match" +
            "\noriginal mappings.");
    }
    else
       System.out.println("Two-way (String native): Test Passes");

    // Modify an existing mapping test
    System.out.println("Modify Existing Mappings Test");
    flavorMap.addUnencodedNativeForFlavor(test_flav, test_native3);
    flavorMap.addUnencodedNativeForFlavor(test_flav, test_native4);

    // Confirm mapping with getNativesForFlavor
    comp1 = new Vector(Arrays.asList(test_natives_set2));
    comp2 = new Vector(flavorMap.getNativesForFlavor(test_flav));

    if ( !comp1.equals(comp2)) {
        throw new RuntimeException("\n*** After modifying an existing mapping" +
            "\nwith addUnencodedNativeForFlavor(DataFlavor flav, String nat)" +
            "\nthe mappings returned from getNativesForFlavor() do not match" +
            "\nupdated mappings.");
    }
    else
       System.out.println("Modify Existing Mappings: Test Passes");

}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:80,代码来源:AddNativeForFlavorTest.java

示例10: appendSystemFlavorMap

import java.awt.datatransfer.SystemFlavorMap; //导入方法依赖的package包/类
protected void appendSystemFlavorMap(SystemFlavorMap fm, 
                                     DataFlavor flav,
                                     String nat) {
    fm.addFlavorForUnencodedNative(nat, flav);
    fm.addUnencodedNativeForFlavor(flav, nat);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:7,代码来源:DTK.java


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