Example usage for java.awt.datatransfer DataFlavor DataFlavor

List of usage examples for java.awt.datatransfer DataFlavor DataFlavor

Introduction

In this page you can find the example usage for java.awt.datatransfer DataFlavor DataFlavor.

Prototype

public DataFlavor(String mimeType, String humanPresentableName) 

Source Link

Document

Constructs a DataFlavor that represents a MimeType .

Usage

From source file:org.jfree.chart.demo.PDFChartTransferable.java

public PDFChartTransferable(JFreeChart jfreechart, int i, int j, boolean flag) {
    pdfFlavor = new DataFlavor("application/pdf", "PDF");
    try {/*www . jav  a 2 s. c o  m*/
        chart = (JFreeChart) jfreechart.clone();
    } catch (CloneNotSupportedException clonenotsupportedexception) {
        chart = jfreechart;
    }
    width = i;
    height = j;
}

From source file:edu.ku.brc.specify.tasks.ReportsTask.java

/**
 * Constructor.//from w  ww. j a v a  2  s.  com
 */
public ReportsTask() {
    super(REPORTS, getResourceString(REPORTS));

    JasperReportsCache.clearCache();

    iconName = name;
    defaultFlavor = new DataFlavor(ReportsBaseTask.class, name);
    navMimeDefs = new ArrayList<Pair<String, String>>(2);
    navMimeDefs.add(new Pair<String, String>(name, REPORTS_MIME));
    navMimeDefs.add(new Pair<String, String>("Labels", LABELS_MIME));
}

From source file:org.eclipse.swt.snippets.Snippet319.java

public void go() {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 319");
    shell.setBounds(10, 10, 600, 200);/*from  w  ww . j a v a 2  s . c  o  m*/

    /* Create SWT controls and add drag source */
    final Label swtLabel = new Label(shell, SWT.BORDER);
    swtLabel.setBounds(10, 10, 580, 50);
    swtLabel.setText("SWT drag source");
    DragSource dragSource = new DragSource(swtLabel, DND.DROP_COPY);
    dragSource.setTransfer(new MyTypeTransfer());
    dragSource.addDragListener(new DragSourceAdapter() {
        @Override
        public void dragSetData(DragSourceEvent event) {
            MyType object = new MyType();
            object.name = "content dragged from SWT";
            object.time = System.currentTimeMillis();
            event.data = object;
        }
    });

    /* Create AWT/Swing controls */
    Composite embeddedComposite = new Composite(shell, SWT.EMBEDDED);
    embeddedComposite.setBounds(10, 100, 580, 50);
    embeddedComposite.setLayout(new FillLayout());
    Frame frame = SWT_AWT.new_Frame(embeddedComposite);
    final JLabel jLabel = new JLabel("AWT/Swing drop target");
    frame.add(jLabel);

    /* Register the custom data flavour */
    final DataFlavor flavor = new DataFlavor(MIME_TYPE, "MyType custom flavor");
    /*
     * Note that according to jre/lib/flavormap.properties, the preferred way to
     * augment the default system flavor map is to specify the AWT.DnD.flavorMapFileURL
     * property in an awt.properties file.
     *
     * This snippet uses the alternate approach below in order to provide a simple
     * stand-alone snippet that demonstrates the functionality.  This implementation
     * works well, but if the instanceof check below fails for some reason when used
     * in a different context then the drop will not be accepted.
     */
    FlavorMap map = SystemFlavorMap.getDefaultFlavorMap();
    if (map instanceof SystemFlavorMap) {
        SystemFlavorMap systemMap = (SystemFlavorMap) map;
        systemMap.addFlavorForUnencodedNative(MIME_TYPE, flavor);
    }

    /* add drop target */
    DropTargetListener dropTargetListener = new DropTargetAdapter() {
        @Override
        public void drop(DropTargetDropEvent dropTargetDropEvent) {
            try {
                dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY);
                ByteArrayInputStream inStream = (ByteArrayInputStream) dropTargetDropEvent.getTransferable()
                        .getTransferData(flavor);
                int available = inStream.available();
                byte[] bytes = new byte[available];
                inStream.read(bytes);
                MyType object = restoreFromByteArray(bytes);
                String string = object.name + ": " + new Date(object.time).toString();
                jLabel.setText(string);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    new DropTarget(jLabel, dropTargetListener);

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:edu.ku.brc.af.tasks.BaseTask.java

/**
 * @param navBox// ww  w  .  j  a v a  2  s .c  o  m
 * @param labelText
 * @param iconNameArg
 * @param cmdAction
 * @param delCmdAction
 * @param flavorClass
 * @param dragFlavor
 * @param dropFlavor
 * @return
 */
public static NavBoxItemIFace makeDnDNavBtn(final NavBox navBox, final String labelText,
        final String iconNameArg, final CommandAction cmdAction, final CommandAction delCmdAction,
        final Class<?> flavorClass, final String dragFlavor, final String dropFlavor) {
    RolloverCommand roc = (RolloverCommand) makeDnDNavBtn(navBox, labelText, null, iconNameArg, cmdAction,
            delCmdAction, true, -1, false);
    roc.addDragDataFlavor(new DataFlavor(Workbench.class, dragFlavor));
    roc.addDropDataFlavor(new DataFlavor(flavorClass, dropFlavor));
    return (NavBoxItemIFace) roc;
}

From source file:edu.ku.brc.specify.tasks.WorkbenchTask.java

@Override
public void initialize() {
    if (!isInitialized) {
        super.initialize(); // sets isInitialized to false

        int wbTblId = Workbench.getClassTableId();

        RolloverCommand roc = null;/*from  w w w.  j  a v a  2  s  .  co  m*/
        NavBox navBox = new NavBox(getResourceString("Actions"));
        //if (!AppContextMgr.isSecurityOn() || getPermissions().canAdd())
        if (isPermitted()) {
            makeDnDNavBtn(navBox, getResourceString("WB_IMPORTDATA"), "Import16",
                    getResourceString("WB_IMPORTDATA_TT"),
                    new CommandAction(WORKBENCH, IMPORT_DATA_FILE, wbTblId), null, false, false);// true means make it draggable
            makeDnDNavBtn(navBox, getResourceString("WB_IMPORT_CARDS"), "ImportImages",
                    getResourceString("WB_IMPORTCARDS_TT"),
                    new CommandAction(WORKBENCH, WB_IMPORTCARDS, wbTblId), null, false, false);// true means make it draggable
            //makeDnDNavBtn(navBox, getResourceString("WB_IMPORT_IMGINDX"),  "ImportImages", getResourceString("WB_IMPORTIMGINDX_TT"), new CommandAction(WORKBENCH, WB_IMPORT_IMGINDEX, wbTblId),   null, false, false);// true means make it draggable

            roc = (RolloverCommand) makeDnDNavBtn(navBox, getResourceString("WB_NEW_DATASET"), "NewDataSet",
                    getResourceString("WB_NEW_DATASET_TT"),
                    new CommandAction(WORKBENCH, NEW_WORKBENCH, wbTblId), null, false, false);// true means make it draggable
            roc.addDropDataFlavor(DATASET_FLAVOR);
        }

        //if (!AppContextMgr.isSecurityOn() || getPermissions().canModify())
        if (isPermitted()) {
            roc = (RolloverCommand) makeDnDNavBtn(navBox, getResourceString("WB_EXPORT_DATA"), "Export16",
                    getResourceString("WB_EXPORT_DATA_TT"),
                    new CommandAction(WORKBENCH, EXPORT_DATA_FILE, wbTblId), null, true, false);// true means make it draggable
            roc.addDropDataFlavor(DATASET_FLAVOR);
            roc.addDragDataFlavor(new DataFlavor(Workbench.class, EXPORT_DATA_FILE));
            enableNavBoxList.add((NavBoxItemIFace) roc);

            roc = (RolloverCommand) makeDnDNavBtn(navBox, getResourceString("WB_EXPORT_TEMPLATE"),
                    "ExportExcel16", getResourceString("WB_EXPORT_TEMPLATE_TT"),
                    new CommandAction(WORKBENCH, EXPORT_TEMPLATE, wbTblId), null, true, false);// true means make it draggable
            roc.addDropDataFlavor(DATASET_FLAVOR);
            roc.addDragDataFlavor(new DataFlavor(Workbench.class, EXPORT_TEMPLATE));
            enableNavBoxList.add((NavBoxItemIFace) roc);

            makeDnDNavBtn(navBox, getResourceString("WB_EXPORTFROMDBTOWB"), "Export16",
                    getResourceString("WB_EXPORTFROMDBTOWB_TT"),
                    new CommandAction(WORKBENCH, EXPORT_RS_TO_WB, wbTblId), null, false, false);// true means make it draggable
        }

        navBoxes.add(navBox);

        workbenchNavBox = datasetNavBoxMgr.createWorkbenchNavBox(WORKBENCH);

        // Then add
        if (commands != null && (!AppContextMgr.isSecurityOn() || canViewReports())) {
            NavBox reportsNavBox = new NavBox(getResourceString("Reports"));

            navBoxes.add(reportsNavBox);
            for (AppResourceIFace ap : AppContextMgr.getInstance().getResourceByMimeType("jrxml/report")) {
                Properties params = ap.getMetaDataMap();
                String tableid = params.getProperty("tableid");

                if (StringUtils.isNotEmpty(tableid)
                        && Integer.parseInt(tableid) == Workbench.getClassTableId()) {
                    params.put("title", ap.getDescription());
                    params.put("file", ap.getName());
                    //log.debug("["+ap.getDescription()+"]["+ap.getName()+"]");
                    String iconNameStr = params.getProperty("icon");
                    if (StringUtils.isEmpty(iconNameStr)) {
                        iconNameStr = name;
                    }
                    commands.add(new TaskCommandDef(ap.getDescription(), iconNameStr, params));
                }

            }

            for (TaskCommandDef tcd : commands) {
                // XXX won't be needed when we start validating the XML
                String tableIdStr = tcd.getParams().getProperty("tableid");
                if (tableIdStr != null) {
                    CommandAction cmdAction = new CommandAction(WORKBENCH, PRINT_REPORT,
                            Workbench.getClassTableId());
                    cmdAction.addStringProperties(tcd.getParams());
                    cmdAction.getProperties().put("icon", IconManager.getIcon(tcd.getIconName()));

                    NavBoxItemIFace nbi = makeDnDNavBtn(reportsNavBox, tcd.getName(), tcd.getIconName(),
                            cmdAction, null, true, false);// true means make it draggable
                    reportsList.add(nbi);
                    enableNavBoxList.add(nbi);

                    roc = (RolloverCommand) nbi;
                    roc.addDropDataFlavor(DATASET_FLAVOR);
                    roc.addDragDataFlavor(new DataFlavor(Workbench.class, "Report"));
                    roc.setToolTip(getResourceString("WB_PRINTREPORT_TT"));

                } else {
                    log.error("Interaction Command is missing the table id");
                }
            }

            CommandAction cmdAction = new CommandAction(WORKBENCH, WB_BARCHART, Workbench.getClassTableId());
            cmdAction.getProperties().put("icon", IconManager.getIcon("Bar_Chart", IconManager.STD_ICON_SIZE));

            roc = (RolloverCommand) makeDnDNavBtn(reportsNavBox, getResourceString("CHART"), "Bar_Chart",
                    cmdAction, null, true, false);
            enableNavBoxList.add((NavBoxItemIFace) roc);
            roc.addDropDataFlavor(DATASET_FLAVOR);
            roc.addDragDataFlavor(new DataFlavor(Workbench.class, "Report"));
            roc.setToolTip(getResourceString("WB_BARCHART_TT"));

            cmdAction = new CommandAction(WORKBENCH, WB_TOP10_REPORT, Workbench.getClassTableId());
            cmdAction.getProperties().put("icon", IconManager.getIcon("Pie_Chart", IconManager.STD_ICON_SIZE));

            roc = (RolloverCommand) makeDnDNavBtn(reportsNavBox, getResourceString("WB_TOP10"), "Pie_Chart",
                    cmdAction, null, true, false);
            enableNavBoxList.add((NavBoxItemIFace) roc);// true means make it draggable
            roc.addDropDataFlavor(DATASET_FLAVOR);
            roc.addDragDataFlavor(new DataFlavor(Workbench.class, "Report"));
            roc.setToolTip(getResourceString("WB_TOP10_TT"));
        }

        // Add these last and in order
        // TEMPLATES navBoxes.addElement(templateNavBox);
        navBoxes.add(workbenchNavBox);

        updateNavBoxUI(workbenchNavBox.getCount());
    }
    //AppPreferences.getRemote().putInt("MAX_ROWS", MAX_ROWS);
    MAX_ROWS = AppPreferences.getRemote().getInt("MAX_ROWS", MAX_ROWS);
    isShowDefault = true;
}

From source file:ec.util.chart.swing.Charts.java

private static DataFlavor registerSystemFlavor(String nat, String mimeType, String humanPresentableName) {
    DataFlavor result = null;//from  w ww .  j a  va2  s  .c o m
    try {
        result = SystemFlavorMap.decodeDataFlavor(nat);
    } catch (ClassNotFoundException ex) {
    }
    if (result == null) {
        result = new DataFlavor(mimeType, humanPresentableName);
        SystemFlavorMap map = (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
        map.addUnencodedNativeForFlavor(result, nat);
        map.addFlavorForUnencodedNative(nat, result);
        return result;
    }
    return result;
}

From source file:org.ut.biolab.medsavant.client.view.component.GeneSelectionPanel.java

public GeneSelectionPanel(boolean dragSource, boolean dragTarget) {
    super(new Object[0][0], COLUMN_NAMES, COLUMN_CLASSES, new int[0]);
    setFontSize(10);/*from   w  w  w .j  a v a  2s.co  m*/
    geneSetFlavor = new DataFlavor(Set.class, "GeneSet");

    getTable().setDragEnabled(dragSource || dragTarget);
    getTable().setDropMode(DropMode.ON);

    exportEnabled = dragSource;
    importEnabled = dragTarget;

    if (dragSource || dragTarget) {
        getTable().setTransferHandler(new GeneSetTransferHandler());
        getTable().setFillsViewportHeight(true);
    }
}