⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 systemflavormap.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * <code>DataFlavor</code> in the List returned by     * <code>getFlavorsForNative</code> for the specified native.     * <p>     * If a specified native is previously unknown to the data transfer     * subsystem, and that native has been properly encoded, then invoking this     * method will establish a mapping in both directions between the specified     * native and a <code>DataFlavor</code> whose MIME type is a decoded     * version of the native.     *     * @param natives an array of <code>String</code>s which will be the     *        key set of the returned <code>Map</code>. If <code>null</code> is     *        specified, a mapping of all supported <code>String</code> natives     *        to their most preferred <code>DataFlavor</code>s will be     *        returned.     * @return a <code>java.util.Map</code> of <code>String</code> natives to     *         <code>DataFlavor</code>s     *     * @see #getFlavorsForNative     * @see #encodeJavaMIMEType     */    public synchronized Map getFlavorsForNatives(String[] natives) {        // Use getFlavorsForNative to generate extra flavors for text natives        if (natives == null) {            List native_list = getNativesForFlavor(null);            natives = new String[native_list.size()];            native_list.toArray(natives);        }        HashMap retval = new HashMap(natives.length, 1.0f);        for (int i = 0; i < natives.length; i++) {            List flavors = getFlavorsForNative(natives[i]);            DataFlavor flav = (flavors.isEmpty())                ? null : (DataFlavor)flavors.get(0);            retval.put(natives[i], flav);        }        return retval;    }    /**     * Adds a mapping from the specified <code>DataFlavor</code> (and all     * <code>DataFlavor</code>s equal to the specified <code>DataFlavor</code>)     * to the specified <code>String</code> native.     * Unlike <code>getNativesForFlavor</code>, the mapping will only be     * established in one direction, and the native will not be encoded. To     * establish a two-way mapping, call     * <code>addFlavorForUnencodedNative</code> as well. The new mapping will      * be of lower priority than any existing mapping.     * This method has no effect if a mapping from the specified or equal     * <code>DataFlavor</code> to the specified <code>String</code> native     * already exists.     *     * @param flav the <code>DataFlavor</code> key for the mapping     * @param nat the <code>String</code> native value for the mapping     * @throws NullPointerException if flav or nat is <code>null</code>     *     * @see #addFlavorForUnencodedNative     * @since 1.4     */    public synchronized void addUnencodedNativeForFlavor(DataFlavor flav,                                                         String nat) {        if (flav == null || nat == null) {            throw new NullPointerException("null arguments not permitted");        }                List natives = (List)flavorToNative.get(flav);        if (natives == null) {            natives = new ArrayList(1);            flavorToNative.put(flav, natives);        } else if (natives.contains(nat)) {            return;        }        natives.add(nat);        getNativesForFlavorCache.remove(flav);        getNativesForFlavorCache.remove(null);    }    /**     * Discards the current mappings for the specified <code>DataFlavor</code>     * and all <code>DataFlavor</code>s equal to the specified     * <code>DataFlavor</code>, and creates new mappings to the      * specified <code>String</code> natives.     * Unlike <code>getNativesForFlavor</code>, the mappings will only be     * established in one direction, and the natives will not be encoded. To     * establish two-way mappings, call <code>setFlavorsForNative</code>     * as well. The first native in the array will represent the highest     * priority mapping. Subsequent natives will represent mappings of     * decreasing priority.     * <p>     * If the array contains several elements that reference equal     * <code>String</code> natives, this method will establish new mappings     * for the first of those elements and ignore the rest of them.     * <p>      * It is recommended that client code not reset mappings established by the     * data transfer subsystem. This method should only be used for     * application-level mappings.     *     * @param flav the <code>DataFlavor</code> key for the mappings     * @param natives the <code>String</code> native values for the mappings     * @throws NullPointerException if flav or natives is <code>null</code>     *         or if natives contains <code>null</code> elements     *     * @see #setFlavorsForNative     * @since 1.4     */    public synchronized void setNativesForFlavor(DataFlavor flav,                                                 String[] natives) {        if (flav == null || natives == null) {            throw new NullPointerException("null arguments not permitted");        }        flavorToNative.remove(flav);        for (int i = 0; i < natives.length; i++) {            addUnencodedNativeForFlavor(flav, natives[i]);        }        disabledMappingGenerationKeys.add(flav);        // Clear the cache to handle the case of empty natives.        getNativesForFlavorCache.remove(flav);        getNativesForFlavorCache.remove(null);    }    /**     * Adds a mapping from a single <code>String</code> native to a single     * <code>DataFlavor</code>. Unlike <code>getFlavorsForNative</code>, the     * mapping will only be established in one direction, and the native will     * not be encoded. To establish a two-way mapping, call     * <code>addUnencodedNativeForFlavor</code> as well. The new mapping will     * be of lower priority than any existing mapping.     * This method has no effect if a mapping from the specified     * <code>String</code> native to the specified or equal     * <code>DataFlavor</code> already exists.     *     * @param nat the <code>String</code> native key for the mapping     * @param flav the <code>DataFlavor</code> value for the mapping     * @throws NullPointerException if nat or flav is <code>null</code>     *     * @see #addUnencodedNativeForFlavor     * @since 1.4     */    public synchronized void addFlavorForUnencodedNative(String nat,                                                         DataFlavor flav) {        if (nat == null || flav == null) {            throw new NullPointerException("null arguments not permitted");        }        List flavors = (List)nativeToFlavor.get(nat);        if (flavors == null) {            flavors = new ArrayList(1);            nativeToFlavor.put(nat, flavors);        } else if (flavors.contains(flav)) {            return;        }        flavors.add(flav);        getFlavorsForNativeCache.remove(nat);        getFlavorsForNativeCache.remove(null);    }    /**     * Discards the current mappings for the specified <code>String</code>     * native, and creates new mappings to the specified     * <code>DataFlavor</code>s. Unlike <code>getFlavorsForNative</code>, the     * mappings will only be established in one direction, and the natives need     * not be encoded. To establish two-way mappings, call     * <code>setNativesForFlavor</code> as well. The first     * <code>DataFlavor</code> in the array will represent the highest priority     * mapping. Subsequent <code>DataFlavor</code>s will represent mappings of     * decreasing priority.     * <p>     * If the array contains several elements that reference equal     * <code>DataFlavor</code>s, this method will establish new mappings     * for the first of those elements and ignore the rest of them.     * <p>     * It is recommended that client code not reset mappings established by the     * data transfer subsystem. This method should only be used for     * application-level mappings.     *     * @param nat the <code>String</code> native key for the mappings     * @param flavors the <code>DataFlavor</code> values for the mappings     * @throws NullPointerException if nat or flavors is <code>null</code>     *         or if flavors contains <code>null</code> elements     *     * @see #setNativesForFlavor     * @since 1.4     */    public synchronized void setFlavorsForNative(String nat,                                                 DataFlavor[] flavors) {        if (nat == null || flavors == null) {            throw new NullPointerException("null arguments not permitted");        }        nativeToFlavor.remove(nat);        for (int i = 0; i < flavors.length; i++) {            addFlavorForUnencodedNative(nat, flavors[i]);        }        disabledMappingGenerationKeys.add(nat);        // Clear the cache to handle the case of empty flavors.        getFlavorsForNativeCache.remove(nat);        getFlavorsForNativeCache.remove(null);    }    /**     * Encodes a MIME type for use as a <code>String</code> native. The format     * of an encoded representation of a MIME type is implementation-dependent.     * The only restrictions are:     * <ul>     * <li>The encoded representation is <code>null</code> if and only if the     * MIME type <code>String</code> is <code>null</code>.</li>     * <li>The encoded representations for two non-<code>null</code> MIME type     * <code>String</code>s are equal if and only if these <code>String</code>s     * are equal according to <code>String.equals(Object)</code>.</li>     * </ul>     * <p>     * Sun's reference implementation of this method returns the specified MIME     * type <code>String</code> prefixed with <code>JAVA_DATAFLAVOR:</code>.     *     * @param mimeType the MIME type to encode     * @return the encoded <code>String</code>, or <code>null</code> if     *         mimeType is <code>null</code>     */    public static String encodeJavaMIMEType(String mimeType) {        return (mimeType != null)            ? JavaMIME + mimeType            : null;    }    /**     * Encodes a <code>DataFlavor</code> for use as a <code>String</code>     * native. The format of an encoded <code>DataFlavor</code> is      * implementation-dependent. The only restrictions are:     * <ul>     * <li>The encoded representation is <code>null</code> if and only if the     * specified <code>DataFlavor</code> is <code>null</code> or its MIME type     * <code>String</code> is <code>null</code>.</li>     * <li>The encoded representations for two non-<code>null</code>     * <code>DataFlavor</code>s with non-<code>null</code> MIME type     * <code>String</code>s are equal if and only if the MIME type     * <code>String</code>s of these <code>DataFlavor</code>s are equal     * according to <code>String.equals(Object)</code>.</li>     * </ul>     * <p>     * Sun's reference implementation of this method returns the MIME type     * <code>String</code> of the specified <code>DataFlavor</code> prefixed     * with <code>JAVA_DATAFLAVOR:</code>.     *     * @param flav the <code>DataFlavor</code> to encode     * @return the encoded <code>String</code>, or <code>null</code> if     *         flav is <code>null</code> or has a <code>null</code> MIME type     */    public static String encodeDataFlavor(DataFlavor flav) {        return (flav != null)            ? SystemFlavorMap.encodeJavaMIMEType(flav.getMimeType())            : null;    }    /**     * Returns whether the specified <code>String</code> is an encoded Java     * MIME type.     *     * @param str the <code>String</code> to test     * @return <code>true</code> if the <code>String</code> is encoded;     *         <code>false</code> otherwise     */    public static boolean isJavaMIMEType(String str) {        return (str != null && str.startsWith(JavaMIME, 0));    }    /**     * Decodes a <code>String</code> native for use as a Java MIME type.     *     * @param nat the <code>String</code> to decode     * @return the decoded Java MIME type, or <code>null</code> if nat is not     *         an encoded <code>String</code> native     */    public static String decodeJavaMIMEType(String nat) {        return (isJavaMIMEType(nat))            ? nat.substring(JavaMIME.length(), nat.length()).trim()            : null;    }    /**     * Decodes a <code>String</code> native for use as a     * <code>DataFlavor</code>.     *     * @param nat the <code>String</code> to decode     * @return the decoded <code>DataFlavor</code>, or <code>null</code> if     *         nat is not an encoded <code>String</code> native     */    public static DataFlavor decodeDataFlavor(String nat)        throws ClassNotFoundException    {        String retval_str = SystemFlavorMap.decodeJavaMIMEType(nat);        return (retval_str != null)            ? new DataFlavor(retval_str)            : null;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -