//# 0 errors, 83 messages
//#
/*
    //#StringTransferable.java:1:1: class: com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable
    //#StringTransferable.java:1:1: method: com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable.com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable__static_init
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.addons.ui_swing.dialogs.actioneditor;

import com.dmdirc.logger.ErrorLevel;
import com.dmdirc.logger.Logger;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;

/**
 * String transfer handler.
 */
public class StringTransferable implements Transferable {

    /** Local tranfer flavour. */
    private DataFlavor localStringFlavor;
    /** Serial transfer flavour. */
    private final DataFlavor serialStringFlavor;
    /** Transferred string. */
    private final String data;

    /**
     * Creates a new string transferable object.
     * 
     * @param data String to transger
     */
    public StringTransferable(final String data) {
        super();
    //#StringTransferable.java:50: method: void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable.com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)
    //#input(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): "unable to create data flavor: "._tainted
    //#input(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): com.dmdirc.logger.ErrorLevel.LOW
    //#input(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): data
    //#input(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): this
    //#output(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): new DataFlavor(StringTransferable#1) num objects
    //#output(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): new DataFlavor(StringTransferable#3) num objects
    //#output(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): this.data
    //#output(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): this.localStringFlavor
    //#output(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): this.serialStringFlavor
    //#new obj(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): new DataFlavor(StringTransferable#1)
    //#new obj(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): new DataFlavor(StringTransferable#3)
    //#presumption(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): init'ed(com.dmdirc.logger.ErrorLevel.LOW)
    //#post(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): this.data == data
    //#post(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): init'ed(this.data)
    //#post(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): this.localStringFlavor in Addr_Set{null,&new DataFlavor(StringTransferable#1)}
    //#post(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): this.serialStringFlavor == &new DataFlavor(StringTransferable#3)
    //#post(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): new DataFlavor(StringTransferable#1) num objects <= 1
    //#post(void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)): new DataFlavor(StringTransferable#3) num objects == 1

        this.data = data;

        try {
            localStringFlavor = new DataFlavor(
                    DataFlavor.javaJVMLocalObjectMimeType +
                    ";class=java.lang.String");
        } catch (ClassNotFoundException e) {
            Logger.userError(ErrorLevel.LOW, "unable to create data flavor: " +
    //#StringTransferable.java:59: Warning: method not available - call not analyzed
    //#    call on void com.dmdirc.logger.Logger:userError(ErrorLevel, String)
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable
    //#    method: void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)
    //#    unanalyzed callee: void com.dmdirc.logger.Logger:userError(ErrorLevel, String)
                    e.getMessage());
        }
        serialStringFlavor = new DataFlavor(String.class, "String");
    }
    //#StringTransferable.java:63: end of method: void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable.com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)

    /** {@inheritDoc} */
    @Override
    public DataFlavor[] getTransferDataFlavors() {
        return new DataFlavor[]{localStringFlavor, serialStringFlavor,};
    //#StringTransferable.java:68: method: DataFlavor[] com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable.getTransferDataFlavors()
    //#input(DataFlavor[] getTransferDataFlavors()): this
    //#input(DataFlavor[] getTransferDataFlavors()): this.localStringFlavor
    //#input(DataFlavor[] getTransferDataFlavors()): this.serialStringFlavor
    //#output(DataFlavor[] getTransferDataFlavors()): new DataFlavor[](getTransferDataFlavors#1) num objects
    //#output(DataFlavor[] getTransferDataFlavors()): return_value.length
    //#output(DataFlavor[] getTransferDataFlavors()): return_value[0]
    //#output(DataFlavor[] getTransferDataFlavors()): return_value[1]
    //#output(DataFlavor[] getTransferDataFlavors()): return_value
    //#new obj(DataFlavor[] getTransferDataFlavors()): new DataFlavor[](getTransferDataFlavors#1)
    //#pre[2] (DataFlavor[] getTransferDataFlavors()): init'ed(this.localStringFlavor)
    //#post(DataFlavor[] getTransferDataFlavors()): return_value == &new DataFlavor[](getTransferDataFlavors#1)
    //#post(DataFlavor[] getTransferDataFlavors()): new DataFlavor[](getTransferDataFlavors#1) num objects == 1
    //#post(DataFlavor[] getTransferDataFlavors()): return_value.length == 2
    //#post(DataFlavor[] getTransferDataFlavors()): return_value[0] == this.localStringFlavor
    //#post(DataFlavor[] getTransferDataFlavors()): init'ed(return_value[0])
    //#post(DataFlavor[] getTransferDataFlavors()): return_value[1] == this.serialStringFlavor
    //#post(DataFlavor[] getTransferDataFlavors()): init'ed(return_value[1])
    //#StringTransferable.java:68: end of method: DataFlavor[] com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable.getTransferDataFlavors()
    }

    /** {@inheritDoc} */
    @Override
    public boolean isDataFlavorSupported(final DataFlavor flavor) {
        if (localStringFlavor.equals(flavor)) {
    //#StringTransferable.java:74: method: bool com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable.isDataFlavorSupported(DataFlavor)
    //#input(bool isDataFlavorSupported(DataFlavor)): flavor
    //#input(bool isDataFlavorSupported(DataFlavor)): this
    //#input(bool isDataFlavorSupported(DataFlavor)): this.localStringFlavor
    //#input(bool isDataFlavorSupported(DataFlavor)): this.serialStringFlavor
    //#output(bool isDataFlavorSupported(DataFlavor)): return_value
    //#pre[3] (bool isDataFlavorSupported(DataFlavor)): this.localStringFlavor != null
    //#pre[4] (bool isDataFlavorSupported(DataFlavor)): (soft) this.serialStringFlavor != null
    //#post(bool isDataFlavorSupported(DataFlavor)): init'ed(return_value)
    //#test_vector(bool isDataFlavorSupported(DataFlavor)): java.awt.datatransfer.DataFlavor:equals(...)@74: {0}, {1}
    //#test_vector(bool isDataFlavorSupported(DataFlavor)): java.awt.datatransfer.DataFlavor:equals(...)@78: {0}, {1}
            return true;
        }

        if (serialStringFlavor.equals(flavor)) {
            return true;
        }

        return false;
    //#StringTransferable.java:82: end of method: bool com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable.isDataFlavorSupported(DataFlavor)
    }

    /** 
     * {@inheritDoc}
     * 
     * @return String to transfer
     */
    @Override
    public Object getTransferData(final DataFlavor flavor) throws UnsupportedFlavorException {
        if (!isDataFlavorSupported(flavor)) {
    //#StringTransferable.java:92: method: Object com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable.getTransferData(DataFlavor)
    //#input(Object getTransferData(DataFlavor)): __Descendant_Table[com/dmdirc/addons/ui_swing/dialogs/actioneditor/StringTransferable]
    //#input(Object getTransferData(DataFlavor)): __Descendant_Table[others]
    //#input(Object getTransferData(DataFlavor)): __Dispatch_Table.isDataFlavorSupported(Ljava/awt/datatransfer/DataFlavor;)Z
    //#input(Object getTransferData(DataFlavor)): flavor
    //#input(Object getTransferData(DataFlavor)): this
    //#input(Object getTransferData(DataFlavor)): this.__Tag
    //#input(Object getTransferData(DataFlavor)): this.data
    //#input(Object getTransferData(DataFlavor)): this.localStringFlavor
    //#input(Object getTransferData(DataFlavor)): this.serialStringFlavor
    //#output(Object getTransferData(DataFlavor)): return_value
    //#pre[3] (Object getTransferData(DataFlavor)): this.__Tag == com/dmdirc/addons/ui_swing/dialogs/actioneditor/StringTransferable
    //#pre[5] (Object getTransferData(DataFlavor)): this.localStringFlavor != null
    //#pre[6] (Object getTransferData(DataFlavor)): (soft) this.serialStringFlavor != null
    //#presumption(Object getTransferData(DataFlavor)): java.awt.datatransfer.DataFlavor:equals(...)@74 != 0 | java.awt.datatransfer.DataFlavor:equals(...)@78 != 0
    //#post(Object getTransferData(DataFlavor)): return_value == this.data
    //#post(Object getTransferData(DataFlavor)): init'ed(return_value)
    //#unanalyzed(Object getTransferData(DataFlavor)): Effects-of-calling:java.awt.datatransfer.DataFlavor:equals
            throw new UnsupportedFlavorException(flavor);
        }

        return data;
    //#StringTransferable.java:96: end of method: Object com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable.getTransferData(DataFlavor)
    }
}
    //#output(com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable__static_init): __Descendant_Table[com/dmdirc/addons/ui_swing/dialogs/actioneditor/StringTransferable]
    //#output(com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable__static_init): __Dispatch_Table.getTransferData(Ljava/awt/datatransfer/DataFlavor;)Ljava/lang/Object;
    //#output(com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable__static_init): __Dispatch_Table.getTransferDataFlavors()[Ljava/awt/datatransfer/DataFlavor;
    //#output(com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable__static_init): __Dispatch_Table.isDataFlavorSupported(Ljava/awt/datatransfer/DataFlavor;)Z
    //#post(com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable__static_init): __Descendant_Table[com/dmdirc/addons/ui_swing/dialogs/actioneditor/StringTransferable] == &__Dispatch_Table
    //#post(com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable__static_init): __Dispatch_Table.getTransferData(Ljava/awt/datatransfer/DataFlavor;)Ljava/lang/Object; == &getTransferData
    //#post(com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable__static_init): __Dispatch_Table.getTransferDataFlavors()[Ljava/awt/datatransfer/DataFlavor; == &getTransferDataFlavors
    //#post(com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable__static_init): __Dispatch_Table.isDataFlavorSupported(Ljava/awt/datatransfer/DataFlavor;)Z == &isDataFlavorSupported
    //#StringTransferable.java:: end of method: com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable.com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable__static_init
    //#StringTransferable.java:: end of class: com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable
