jdk/src/share/classes/javax/swing/plaf/basic/BasicTransferable.java
author darcy
Wed, 02 Jul 2014 23:03:27 -0700
changeset 25565 ce603b34c98d
parent 5506 202f599c92aa
permissions -rw-r--r--
8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.* 8042849: Fix raw and unchecked warnings in com.sun.java.swing Reviewed-by: pchelko, alexsch
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.datatransfer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.plaf.UIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * A transferable implementation for the default data transfer of some Swing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
class BasicTransferable implements Transferable, UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    protected String plainData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    protected String htmlData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static DataFlavor[] htmlFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static DataFlavor[] stringFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static DataFlavor[] plainFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            htmlFlavors = new DataFlavor[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            htmlFlavors[0] = new DataFlavor("text/html;class=java.lang.String");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            htmlFlavors[1] = new DataFlavor("text/html;class=java.io.Reader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            htmlFlavors[2] = new DataFlavor("text/html;charset=unicode;class=java.io.InputStream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            plainFlavors = new DataFlavor[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            plainFlavors[0] = new DataFlavor("text/plain;class=java.lang.String");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            plainFlavors[1] = new DataFlavor("text/plain;class=java.io.Reader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            plainFlavors[2] = new DataFlavor("text/plain;charset=unicode;class=java.io.InputStream");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            stringFlavors = new DataFlavor[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            stringFlavors[0] = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType+";class=java.lang.String");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            stringFlavors[1] = DataFlavor.stringFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        } catch (ClassNotFoundException cle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            System.err.println("error initializing javax.swing.plaf.basic.BasicTranserable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public BasicTransferable(String plainData, String htmlData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        this.plainData = plainData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        this.htmlData = htmlData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Returns an array of DataFlavor objects indicating the flavors the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * can be provided in.  The array should be ordered according to preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * for providing the data (from most richly descriptive to least descriptive).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @return an array of data flavors in which this data can be transferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public DataFlavor[] getTransferDataFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        DataFlavor[] richerFlavors = getRicherFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        int nRicher = (richerFlavors != null) ? richerFlavors.length : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        int nHTML = (isHTMLSupported()) ? htmlFlavors.length : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        int nPlain = (isPlainSupported()) ? plainFlavors.length: 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        int nString = (isPlainSupported()) ? stringFlavors.length : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        int nFlavors = nRicher + nHTML + nPlain + nString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        DataFlavor[] flavors = new DataFlavor[nFlavors];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        // fill in the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        int nDone = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (nRicher > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            System.arraycopy(richerFlavors, 0, flavors, nDone, nRicher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            nDone += nRicher;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (nHTML > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            System.arraycopy(htmlFlavors, 0, flavors, nDone, nHTML);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            nDone += nHTML;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (nPlain > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            System.arraycopy(plainFlavors, 0, flavors, nDone, nPlain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            nDone += nPlain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (nString > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            System.arraycopy(stringFlavors, 0, flavors, nDone, nString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            nDone += nString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return flavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Returns whether or not the specified data flavor is supported for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param flavor the requested flavor for the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @return boolean indicating whether or not the data flavor is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public boolean isDataFlavorSupported(DataFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        DataFlavor[] flavors = getTransferDataFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        for (int i = 0; i < flavors.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            if (flavors[i].equals(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Returns an object which represents the data to be transferred.  The class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * of the object returned is defined by the representation class of the flavor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param flavor the requested flavor for the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @see DataFlavor#getRepresentationClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @exception IOException                if the data is no longer available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *              in the requested flavor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @exception UnsupportedFlavorException if the requested data flavor is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *              not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        DataFlavor[] richerFlavors = getRicherFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (isRicherFlavor(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            return getRicherData(flavor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        } else if (isHTMLFlavor(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            String data = getHTMLData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            data = (data == null) ? "" : data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            if (String.class.equals(flavor.getRepresentationClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            } else if (Reader.class.equals(flavor.getRepresentationClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                return new StringReader(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            } else if (InputStream.class.equals(flavor.getRepresentationClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                return new StringBufferInputStream(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            // fall through to unsupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        } else if (isPlainFlavor(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            String data = getPlainData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            data = (data == null) ? "" : data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            if (String.class.equals(flavor.getRepresentationClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            } else if (Reader.class.equals(flavor.getRepresentationClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                return new StringReader(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            } else if (InputStream.class.equals(flavor.getRepresentationClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                return new StringBufferInputStream(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            // fall through to unsupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        } else if (isStringFlavor(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            String data = getPlainData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            data = (data == null) ? "" : data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        throw new UnsupportedFlavorException(flavor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    // --- richer subclass flavors ----------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    protected boolean isRicherFlavor(DataFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        DataFlavor[] richerFlavors = getRicherFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        int nFlavors = (richerFlavors != null) ? richerFlavors.length : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        for (int i = 0; i < nFlavors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            if (richerFlavors[i].equals(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Some subclasses will have flavors that are more descriptive than HTML
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * or plain text.  If this method returns a non-null value, it will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * placed at the start of the array of supported flavors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    protected DataFlavor[] getRicherFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    protected Object getRicherData(DataFlavor flavor) throws UnsupportedFlavorException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    // --- html flavors ----------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Returns whether or not the specified data flavor is an HTML flavor that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param flavor the requested flavor for the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @return boolean indicating whether or not the data flavor is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    protected boolean isHTMLFlavor(DataFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        DataFlavor[] flavors = htmlFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        for (int i = 0; i < flavors.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            if (flavors[i].equals(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Should the HTML flavors be offered?  If so, the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * getHTMLData should be implemented to provide something reasonable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    protected boolean isHTMLSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return htmlData != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Fetch the data in a text/html format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    protected String getHTMLData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return htmlData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    // --- plain text flavors ----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Returns whether or not the specified data flavor is an plain flavor that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param flavor the requested flavor for the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @return boolean indicating whether or not the data flavor is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    protected boolean isPlainFlavor(DataFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        DataFlavor[] flavors = plainFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        for (int i = 0; i < flavors.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (flavors[i].equals(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Should the plain text flavors be offered?  If so, the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * getPlainData should be implemented to provide something reasonable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    protected boolean isPlainSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return plainData != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Fetch the data in a text/plain format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    protected String getPlainData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return plainData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    // --- string flavorss --------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Returns whether or not the specified data flavor is a String flavor that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param flavor the requested flavor for the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @return boolean indicating whether or not the data flavor is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    protected boolean isStringFlavor(DataFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        DataFlavor[] flavors = stringFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        for (int i = 0; i < flavors.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            if (flavors[i].equals(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
}