All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jhotdraw8.draw.input.MultiClipboardOutputFormat Maven / Gradle / Ivy

The newest version!
/*
 * @(#)MultiClipboardOutputFormat.java
 * Copyright © 2023 The authors and contributors of JHotDraw. MIT License.
 */
package org.jhotdraw8.draw.input;

import javafx.scene.input.DataFormat;
import org.jhotdraw8.draw.figure.Drawing;
import org.jhotdraw8.draw.figure.Figure;
import org.jspecify.annotations.Nullable;

import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.function.Supplier;

/**
 * MultiClipboardOutputFormat.
 *
 * @author Werner Randelshofer
 */
public class MultiClipboardOutputFormat implements ClipboardOutputFormat {
    private @Nullable Supplier[] formatSuppliers;

    private ClipboardOutputFormat[] formats;

    @SafeVarargs
    @SuppressWarnings("varargs")
    public MultiClipboardOutputFormat(Supplier... formatSuppliers) {
        this.formatSuppliers = formatSuppliers;
    }

    public MultiClipboardOutputFormat(ClipboardOutputFormat... formats) {
        this.formats = formats;
    }

    private void createFormats() {
        if (formatSuppliers != null) {
            int n = formatSuppliers.length;
            formats = new ClipboardOutputFormat[n];
            for (int i = 0; i < n; i++) {
                formats[i] = formatSuppliers[i].get();
            }
            formatSuppliers = null;
        }
    }

    @Override
    public void write(Map out, Drawing drawing, Collection
selection) throws IOException { createFormats(); for (ClipboardOutputFormat f : formats) { f.write(out, drawing, selection); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy