2914 }
2915
2916 private static int adjustIndex(int index, JList<?> list) {
2917 return index < list.getModel().getSize() ? index : -1;
2918 }
2919
2920 private static final TransferHandler defaultTransferHandler = new ListTransferHandler();
2921
2922 @SuppressWarnings("serial") // Superclass is a JDK-implementation class
2923 static class ListTransferHandler extends TransferHandler implements UIResource {
2924
2925 /**
2926 * Create a Transferable to use as the source for a data transfer.
2927 *
2928 * @param c The component holding the data to be transfered. This
2929 * argument is provided to enable sharing of TransferHandlers by
2930 * multiple components.
2931 * @return The representation of the data to be transfered.
2932 *
2933 */
2934 protected Transferable createTransferable(JComponent c) {
2935 if (c instanceof JList) {
2936 JList<?> list = (JList) c;
2937 Object[] values = list.getSelectedValues();
2938
2939 if (values == null || values.length == 0) {
2940 return null;
2941 }
2942
2943 StringBuilder plainStr = new StringBuilder();
2944 StringBuilder htmlStr = new StringBuilder();
2945
2946 htmlStr.append("<html>\n<body>\n<ul>\n");
2947
2948 for (int i = 0; i < values.length; i++) {
2949 Object obj = values[i];
2950 String val = ((obj == null) ? "" : obj.toString());
2951 plainStr.append(val + "\n");
2952 htmlStr.append(" <li>" + val + "\n");
2953 }
|
2914 }
2915
2916 private static int adjustIndex(int index, JList<?> list) {
2917 return index < list.getModel().getSize() ? index : -1;
2918 }
2919
2920 private static final TransferHandler defaultTransferHandler = new ListTransferHandler();
2921
2922 @SuppressWarnings("serial") // Superclass is a JDK-implementation class
2923 static class ListTransferHandler extends TransferHandler implements UIResource {
2924
2925 /**
2926 * Create a Transferable to use as the source for a data transfer.
2927 *
2928 * @param c The component holding the data to be transfered. This
2929 * argument is provided to enable sharing of TransferHandlers by
2930 * multiple components.
2931 * @return The representation of the data to be transfered.
2932 *
2933 */
2934 @SuppressWarnings("deprecation")
2935 protected Transferable createTransferable(JComponent c) {
2936 if (c instanceof JList) {
2937 JList<?> list = (JList) c;
2938 Object[] values = list.getSelectedValues();
2939
2940 if (values == null || values.length == 0) {
2941 return null;
2942 }
2943
2944 StringBuilder plainStr = new StringBuilder();
2945 StringBuilder htmlStr = new StringBuilder();
2946
2947 htmlStr.append("<html>\n<body>\n<ul>\n");
2948
2949 for (int i = 0; i < values.length; i++) {
2950 Object obj = values[i];
2951 String val = ((obj == null) ? "" : obj.toString());
2952 plainStr.append(val + "\n");
2953 htmlStr.append(" <li>" + val + "\n");
2954 }
|