Example #1
0
  public StringBuffer getTransferData(Transferable t) {
    StringBuffer xferData = null;
    Object dropped;
    DataFlavor dtf;

    dtf = testAllFlavors(t);

    JConfig.log().logVerboseDebug("dtf == " + dtf);

    try {
      if (dtf == _htmlFlavor || dtf == _utf8HtmlFlavor || dtf == _thtmlFlavor) {
        /*
         * Annoying.
         */
        if (JConfig.queryConfiguration("debug.uber", "false").equals("true") && JConfig.debugging)
          System.out.println("Ick: " + t.getTransferData(DataFlavor.getTextPlainUnicodeFlavor()));
      }
      dropped = t.getTransferData(dtf);
    } catch (IOException ioe) {
      try {
        dropped = t.getTransferData(DataFlavor.stringFlavor);
      } catch (Exception e) {
        JConfig.log().logDebug("I/O Exception: " + ioe);
        return null;
      }
    } catch (UnsupportedFlavorException ufe) {
      try {
        dropped = t.getTransferData(DataFlavor.stringFlavor);
      } catch (Exception e) {
        JConfig.log().logDebug("Unsupported flavor: " + dtf);
        return null;
      }
    }

    if (dropped != null) {
      if (dropped instanceof InputStream) {
        JConfig.log().logVerboseDebug("Dropped an InputStream");
        xferData = getInputStreamData(t, dtf, (InputStream) dropped);
      } else if (dropped instanceof Reader) {
        JConfig.log().logVerboseDebug("Dropped a Reader");
        xferData = getDataFromReader(new BufferedReader((Reader) dropped));
      } else if (dropped instanceof java.net.URL) {
        JConfig.log().logVerboseDebug("Dropped a URL");
        JConfig.log().logVerboseDebug("Got: " + dropped.toString());

        xferData = new StringBuffer(dropped.toString());
      } else if (dropped instanceof String) {
        JConfig.log().logVerboseDebug("Dropped a String");
        xferData = new StringBuffer((String) dropped);
      }

      return (xferData);
    }
    return null;
  }
Example #2
0
  private void setupFlavors() {
    //  If it's NOT Windows
    _windows = System.getProperty("os.name").indexOf("indows") != -1;

    //  Deprecated, generally unused, but deprecation didn't provide
    // a useful alternative w/o rewriting a lot of code, so I'm keeping it for now.
    if (_plainFlavor == null) {
      //      _plainFlavor = DataFlavor.plainTextFlavor;
      _plainFlavor = DataFlavor.getTextPlainUnicodeFlavor();
    }

    _isoFlavor = getDataFlavor(_isoFlavor, "isoFlavor");
    _ascFlavor = getDataFlavor(_ascFlavor, "ascFlavor");
    _pl2Flavor = getDataFlavor(_pl2Flavor, "pl2Flavor");
    _htmlFlavor = getDataFlavor(_htmlFlavor, "htmlFlavor");
    _utf8HtmlFlavor = getDataFlavor(_htmlFlavor, "UTF8Html");
    _thtmlFlavor = getDataFlavor(_htmlFlavor, "thtmlFlavor");
    _urlFlavor = getDataFlavor(_urlFlavor, "urlFlavor");
  }
  void quickSwapActionPerformed(java.awt.event.ActionEvent evt) {
    String currentlySelectedText = notepad.bigEdit.getSelectedText();
    String textAlreadyOnClipboard = "";
    try {
      textAlreadyOnClipboard =
          (String)
              Toolkit.getDefaultToolkit()
                  .getSystemClipboard()
                  .getData(DataFlavor.getTextPlainUnicodeFlavor());
    } catch (UnsupportedFlavorException | IOException ex) {
      System.err.println("Clipboard error. " + ex);
    }

    StringSelection stringSelection = new StringSelection(currentlySelectedText);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(stringSelection, null);

    notepad.bigEdit.replaceSelection(textAlreadyOnClipboard);
  }
 static {
   DataFlavor df1 = null;
   DataFlavor df2 = null;
   try {
     df1 =
         new DataFlavor(
             DataFlavor.javaJVMLocalObjectMimeType
                 + ";class=net.sf.jabref.groups.TransferableEntrySelection");
     df2 = DataFlavor.getTextPlainUnicodeFlavor();
   } catch (ClassNotFoundException e) {
     // never happens
   }
   flavorInternal = df1;
   flavorExternal = df2;
   flavors =
       new DataFlavor[] {
         TransferableEntrySelection.flavorInternal, TransferableEntrySelection.flavorExternal
       };
 }