コード例 #1
0
 @Override
 public boolean importData(JComponent comp, Transferable t) {
   DataFlavor htmlFlavor = DataFlavor.stringFlavor;
   if (canImport(comp, t.getTransferDataFlavors())) {
     try {
       String transferString = (String) t.getTransferData(htmlFlavor);
       EditorPane targetTextPane = (EditorPane) comp;
       for (Map.Entry<String, String> entry : _copiedImgs.entrySet()) {
         String imgName = entry.getKey();
         String imgPath = entry.getValue();
         File destFile = targetTextPane.copyFileToBundle(imgPath);
         String newName = destFile.getName();
         if (!newName.equals(imgName)) {
           String ptnImgName = "\"" + imgName + "\"";
           newName = "\"" + newName + "\"";
           transferString = transferString.replaceAll(ptnImgName, newName);
           Debug.info(ptnImgName + " exists. Rename it to " + newName);
         }
       }
       targetTextPane.insertString(transferString);
     } catch (Exception e) {
       Debug.error(me + "importData: Problem pasting text\n%s", e.getMessage());
     }
     return true;
   }
   return false;
 }
コード例 #2
0
 // <editor-fold defaultstate="collapsed" desc="content insert append">
 public void insertString(String str) {
   int sel_start = getSelectionStart();
   int sel_end = getSelectionEnd();
   if (sel_end != sel_start) {
     try {
       getDocument().remove(sel_start, sel_end - sel_start);
     } catch (BadLocationException e) {
       Debug.error(me + "insertString: Problem while trying to insert\n%s", e.getMessage());
     }
   }
   int pos = getCaretPosition();
   insertString(pos, str);
   int new_pos = getCaretPosition();
   int end = parseRange(pos, new_pos);
   setCaretPosition(end);
 }