jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTransferable.java
author anashaty
Fri, 14 Nov 2014 17:53:46 +0300
changeset 27768 3a3e044d7e48
parent 25859 3317bb8137f4
permissions -rw-r--r--
8059739: Dragged and Dropped data is corrupted for two data types Reviewed-by: serb, pchelko
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
27768
3a3e044d7e48 8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents: 25859
diff changeset
    27
import sun.datatransfer.DataFlavorUtil;
3a3e044d7e48 8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents: 25859
diff changeset
    28
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.datatransfer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.UIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * A transferable implementation for the default data transfer of some Swing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
class BasicTransferable implements Transferable, UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    protected String plainData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    protected String htmlData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static DataFlavor[] htmlFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static DataFlavor[] stringFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static DataFlavor[] plainFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            htmlFlavors = new DataFlavor[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            htmlFlavors[0] = new DataFlavor("text/html;class=java.lang.String");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            htmlFlavors[1] = new DataFlavor("text/html;class=java.io.Reader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            htmlFlavors[2] = new DataFlavor("text/html;charset=unicode;class=java.io.InputStream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            plainFlavors = new DataFlavor[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            plainFlavors[0] = new DataFlavor("text/plain;class=java.lang.String");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            plainFlavors[1] = new DataFlavor("text/plain;class=java.io.Reader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            plainFlavors[2] = new DataFlavor("text/plain;charset=unicode;class=java.io.InputStream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            stringFlavors = new DataFlavor[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            stringFlavors[0] = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType+";class=java.lang.String");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            stringFlavors[1] = DataFlavor.stringFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        } catch (ClassNotFoundException cle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            System.err.println("error initializing javax.swing.plaf.basic.BasicTranserable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public BasicTransferable(String plainData, String htmlData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        this.plainData = plainData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        this.htmlData = htmlData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Returns an array of DataFlavor objects indicating the flavors the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * can be provided in.  The array should be ordered according to preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * for providing the data (from most richly descriptive to least descriptive).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @return an array of data flavors in which this data can be transferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public DataFlavor[] getTransferDataFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        DataFlavor[] richerFlavors = getRicherFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        int nRicher = (richerFlavors != null) ? richerFlavors.length : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        int nHTML = (isHTMLSupported()) ? htmlFlavors.length : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        int nPlain = (isPlainSupported()) ? plainFlavors.length: 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        int nString = (isPlainSupported()) ? stringFlavors.length : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        int nFlavors = nRicher + nHTML + nPlain + nString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        DataFlavor[] flavors = new DataFlavor[nFlavors];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        // fill in the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        int nDone = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (nRicher > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            System.arraycopy(richerFlavors, 0, flavors, nDone, nRicher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            nDone += nRicher;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (nHTML > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            System.arraycopy(htmlFlavors, 0, flavors, nDone, nHTML);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            nDone += nHTML;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (nPlain > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            System.arraycopy(plainFlavors, 0, flavors, nDone, nPlain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            nDone += nPlain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (nString > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            System.arraycopy(stringFlavors, 0, flavors, nDone, nString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            nDone += nString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return flavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Returns whether or not the specified data flavor is supported for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @param flavor the requested flavor for the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @return boolean indicating whether or not the data flavor is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public boolean isDataFlavorSupported(DataFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        DataFlavor[] flavors = getTransferDataFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        for (int i = 0; i < flavors.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            if (flavors[i].equals(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Returns an object which represents the data to be transferred.  The class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * of the object returned is defined by the representation class of the flavor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param flavor the requested flavor for the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @see DataFlavor#getRepresentationClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @exception IOException                if the data is no longer available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *              in the requested flavor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @exception UnsupportedFlavorException if the requested data flavor is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *              not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        DataFlavor[] richerFlavors = getRicherFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (isRicherFlavor(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            return getRicherData(flavor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        } else if (isHTMLFlavor(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            String data = getHTMLData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            data = (data == null) ? "" : data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            if (String.class.equals(flavor.getRepresentationClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            } else if (Reader.class.equals(flavor.getRepresentationClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                return new StringReader(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            } else if (InputStream.class.equals(flavor.getRepresentationClass())) {
27768
3a3e044d7e48 8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents: 25859
diff changeset
   150
                return createInputStream(flavor, data);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            // fall through to unsupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        } else if (isPlainFlavor(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            String data = getPlainData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            data = (data == null) ? "" : data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            if (String.class.equals(flavor.getRepresentationClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            } else if (Reader.class.equals(flavor.getRepresentationClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                return new StringReader(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            } else if (InputStream.class.equals(flavor.getRepresentationClass())) {
27768
3a3e044d7e48 8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents: 25859
diff changeset
   161
                return createInputStream(flavor, data);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            // fall through to unsupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        } else if (isStringFlavor(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            String data = getPlainData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            data = (data == null) ? "" : data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        throw new UnsupportedFlavorException(flavor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
27768
3a3e044d7e48 8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents: 25859
diff changeset
   173
    private InputStream createInputStream(DataFlavor flavor, String data)
3a3e044d7e48 8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents: 25859
diff changeset
   174
            throws IOException, UnsupportedFlavorException {
3a3e044d7e48 8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents: 25859
diff changeset
   175
        String cs = DataFlavorUtil.getTextCharset(flavor);
3a3e044d7e48 8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents: 25859
diff changeset
   176
        if (cs == null) {
3a3e044d7e48 8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents: 25859
diff changeset
   177
            throw new UnsupportedFlavorException(flavor);
3a3e044d7e48 8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents: 25859
diff changeset
   178
        }
3a3e044d7e48 8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents: 25859
diff changeset
   179
        return new ByteArrayInputStream(data.getBytes(cs));
3a3e044d7e48 8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents: 25859
diff changeset
   180
    }
3a3e044d7e48 8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents: 25859
diff changeset
   181
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    // --- richer subclass flavors ----------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    protected boolean isRicherFlavor(DataFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        DataFlavor[] richerFlavors = getRicherFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        int nFlavors = (richerFlavors != null) ? richerFlavors.length : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        for (int i = 0; i < nFlavors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            if (richerFlavors[i].equals(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Some subclasses will have flavors that are more descriptive than HTML
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * or plain text.  If this method returns a non-null value, it will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * placed at the start of the array of supported flavors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    protected DataFlavor[] getRicherFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    protected Object getRicherData(DataFlavor flavor) throws UnsupportedFlavorException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    // --- html flavors ----------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Returns whether or not the specified data flavor is an HTML flavor that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param flavor the requested flavor for the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @return boolean indicating whether or not the data flavor is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    protected boolean isHTMLFlavor(DataFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        DataFlavor[] flavors = htmlFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        for (int i = 0; i < flavors.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            if (flavors[i].equals(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Should the HTML flavors be offered?  If so, the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * getHTMLData should be implemented to provide something reasonable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    protected boolean isHTMLSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return htmlData != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Fetch the data in a text/html format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    protected String getHTMLData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return htmlData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    // --- plain text flavors ----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Returns whether or not the specified data flavor is an plain flavor that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @param flavor the requested flavor for the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @return boolean indicating whether or not the data flavor is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    protected boolean isPlainFlavor(DataFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        DataFlavor[] flavors = plainFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        for (int i = 0; i < flavors.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (flavors[i].equals(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Should the plain text flavors be offered?  If so, the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * getPlainData should be implemented to provide something reasonable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    protected boolean isPlainSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return plainData != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Fetch the data in a text/plain format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    protected String getPlainData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return plainData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    // --- string flavorss --------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * Returns whether or not the specified data flavor is a String flavor that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param flavor the requested flavor for the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @return boolean indicating whether or not the data flavor is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    protected boolean isStringFlavor(DataFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        DataFlavor[] flavors = stringFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        for (int i = 0; i < flavors.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            if (flavors[i].equals(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
}