713 * flavor has one of the three specified representations, then one of those
714 * flavors will be chosen non-deterministically.
715 *
716 * @param availableFlavors an array of available <code>DataFlavor</code>s
717 * @return the best (highest fidelity) flavor according to the rules
718 * specified above, or <code>null</code>,
719 * if <code>availableFlavors</code> is <code>null</code>,
720 * has zero length, or contains no text flavors
721 * @since 1.3
722 */
723 public static final DataFlavor selectBestTextFlavor(
724 DataFlavor[] availableFlavors) {
725 if (availableFlavors == null || availableFlavors.length == 0) {
726 return null;
727 }
728
729 if (textFlavorComparator == null) {
730 textFlavorComparator = new TextFlavorComparator();
731 }
732
733 DataFlavor bestFlavor =
734 (DataFlavor)Collections.max(Arrays.asList(availableFlavors),
735 textFlavorComparator);
736
737 if (!bestFlavor.isFlavorTextType()) {
738 return null;
739 }
740
741 return bestFlavor;
742 }
743
744 private static Comparator<DataFlavor> textFlavorComparator;
745
746 static class TextFlavorComparator
747 extends DataTransferer.DataFlavorComparator {
748
749 /**
750 * Compares two <code>DataFlavor</code> objects. Returns a negative
751 * integer, zero, or a positive integer as the first
752 * <code>DataFlavor</code> is worse than, equal to, or better than the
753 * second.
754 * <p>
|
713 * flavor has one of the three specified representations, then one of those
714 * flavors will be chosen non-deterministically.
715 *
716 * @param availableFlavors an array of available <code>DataFlavor</code>s
717 * @return the best (highest fidelity) flavor according to the rules
718 * specified above, or <code>null</code>,
719 * if <code>availableFlavors</code> is <code>null</code>,
720 * has zero length, or contains no text flavors
721 * @since 1.3
722 */
723 public static final DataFlavor selectBestTextFlavor(
724 DataFlavor[] availableFlavors) {
725 if (availableFlavors == null || availableFlavors.length == 0) {
726 return null;
727 }
728
729 if (textFlavorComparator == null) {
730 textFlavorComparator = new TextFlavorComparator();
731 }
732
733 DataFlavor bestFlavor = Collections.max(Arrays.asList(availableFlavors),
734 textFlavorComparator);
735
736 if (!bestFlavor.isFlavorTextType()) {
737 return null;
738 }
739
740 return bestFlavor;
741 }
742
743 private static Comparator<DataFlavor> textFlavorComparator;
744
745 static class TextFlavorComparator
746 extends DataTransferer.DataFlavorComparator {
747
748 /**
749 * Compares two <code>DataFlavor</code> objects. Returns a negative
750 * integer, zero, or a positive integer as the first
751 * <code>DataFlavor</code> is worse than, equal to, or better than the
752 * second.
753 * <p>
|