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

processing.app.syntax.HtmlSelection Maven / Gradle / Ivy

Go to download

Processing is a programming language, development environment, and online community. This PDE package contains the Processing IDE.

There is a newer version: 3.3.7
Show newest version
package processing.app.syntax;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;


public class HtmlSelection implements Transferable {

  private static List flavors;

  static {
    try {
      flavors = new ArrayList();
      flavors.add(DataFlavor.stringFlavor);
      flavors.add(new DataFlavor("text/html;class=java.lang.String"));
      flavors.add(new DataFlavor("text/html;class=java.io.Reader"));
      flavors.add(new DataFlavor("text/html;charset=unicode;class=java.io.InputStream"));
    } catch (ClassNotFoundException ex) {
      ex.printStackTrace();
    }
  }

  private String html;

  
  public HtmlSelection(String html) {
    this.html = html;
  }

  
  public DataFlavor[] getTransferDataFlavors() {
    return flavors.toArray(new DataFlavor[flavors.size()]);
  }

  
  public boolean isDataFlavorSupported(DataFlavor flavor) {
    return flavors.contains(flavor);
  }

  
  public Object getTransferData(DataFlavor flavor)
    throws UnsupportedFlavorException {
    if (flavor.equals(DataFlavor.stringFlavor)) {
      return html;
    } else if (String.class.equals(flavor.getRepresentationClass())) {
      return html;
    } else if (Reader.class.equals(flavor.getRepresentationClass())) {
      return new StringReader(html);
    } else if (InputStream.class.equals(flavor.getRepresentationClass())) {
      return new StringReader(html);
    }
    throw new UnsupportedFlavorException(flavor);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy