1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.datatransfer;
  27 
  28 import java.awt.datatransfer.DataFlavor;
  29 import java.awt.datatransfer.FlavorMap;
  30 import java.util.LinkedHashSet;
  31 import java.util.function.Supplier;
  32 
  33 /**
  34  * Contains services which desktop provides to the datatransfer system
  35  * to enrich it's functionality
  36  *
  37  * @author Petr Pchelko
  38  * @since 1.9
  39  */
  40 public interface DesktopDatatransferService {
  41 
  42     /**
  43      * If desktop is present - invokes a {@code Runnable} on
  44      * the event dispatch thread. Otherwise invokes a {@code run()}
  45      * method directly.
  46      *
  47      * @param r a {@code Runnable} to invoke
  48      */
  49     void invokeOnEventThread(Runnable r);
  50 
  51     /**
  52      * Get a platform-dependent default unicode encoding to use in
  53      * datatransfer system.
  54      *
  55      * @return default unicode encoding
  56      */
  57     String getDefaultUnicodeEncoding();
  58 
  59     /**
  60      * Takes an appropriate {@code FlavorMap} from the desktop.
  61      * If no appropriate table is found - uses a provided supplier to
  62      * instantiate a table. If the desktop is absent - creates and returns
  63      * a system singleton.
  64      *
  65      * @param supplier a constructor that should be used to create a new instance of
  66      *                 the {@code FlavorMap}
  67      * @return a {@code FlavorMap}
  68      */
  69     FlavorMap getFlavorMap(Supplier<FlavorMap> supplier);
  70 
  71     /**
  72      * Checks if desktop is present
  73      *
  74      * @return {@code true} is the desktop is present
  75      */
  76     boolean isDesktopPresent();
  77 
  78     /**
  79      * Returns platform-specific mappings for the specified native format.
  80      * If there are no platform-specific mappings for this native, the method
  81      * returns an empty {@code Set}
  82      *
  83      * @param nat a native format to return flavors for
  84      * @return set of platform-specific mappings for a native format
  85      */
  86     LinkedHashSet<DataFlavor> getPlatformMappingsForNative(String nat);
  87 
  88     /**
  89      * Returns platform-specific mappings for the specified flavor.
  90      * If there are no platform-specific mappings for this flavor, the method
  91      * returns an empty {@code Set}
  92      *
  93      * @param df {@code DataFlavor} to return mappings for
  94      * @return set of platform-specific mappings for a {@code DataFlavor}
  95      */
  96     LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df);
  97 
  98     /**
  99      * This method is called for text flavor mappings established while parsing
 100      * the default flavor mappings file. It stores the "eoln" and "terminators"
 101      * parameters which are not officially part of the MIME type. They are
 102      * MIME parameters specific to the flavormap.properties file format.
 103      */
 104     void registerTextFlavorProperties(String nat, String charset,
 105                                       String eoln, String terminators);
 106 }