示例#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
  /**
   * @return the clipboard content as a String (DataFlavor.stringFlavor) Code snippet adapted from
   *     jEdit (Registers.java), http://www.jedit.org. Returns null if clipboard is empty.
   */
  public static String getClipboardStringContent(Clipboard clipboard) {
    // Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    try {
      String selection =
          (String) (clipboard.getContents(null).getTransferData(DataFlavor.stringFlavor));
      if (selection == null) return null;

      boolean trailingEOL =
          (selection.endsWith("\n") || selection.endsWith(System.getProperty("line.separator")));

      // Some Java versions return the clipboard contents using the native line separator,
      // so have to convert it here , see jEdit's "registers.java"
      BufferedReader in = new BufferedReader(new StringReader(selection));
      StringBuffer buf = new StringBuffer();
      String line;
      while ((line = in.readLine()) != null) {
        buf.append(line);
        buf.append('\n');
      }
      // remove trailing \n
      if (!trailingEOL) buf.setLength(buf.length() - 1);
      return buf.toString();
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
示例#3
0
 /**
  * @return an instanciation of the given content-type class name, or null if class wasn't found
  */
 public static ContentType getContentTypeFromClassName(String contentTypeClassName) {
   if (contentTypeClassName == null)
     contentTypeClassName = getAvailableContentTypes()[DEFAULT_CONTENT_TYPE_INDEX];
   ContentType ct = null;
   try {
     Class clazz = Class.forName(contentTypeClassName);
     ct = (ContentType) clazz.newInstance();
   } catch (ClassNotFoundException cnfex) {
     if (jpicedt.Log.DEBUG) cnfex.printStackTrace();
     JPicEdt.getMDIManager()
         .showMessageDialog(
             "The pluggable content-type you asked for (class "
                 + cnfex.getLocalizedMessage()
                 + ") isn't currently installed, using default instead...",
             Localizer.currentLocalizer().get("msg.LoadingContentTypeClass"),
             JOptionPane.ERROR_MESSAGE);
   } catch (Exception ex) {
     if (jpicedt.Log.DEBUG) ex.printStackTrace();
     JPicEdt.getMDIManager()
         .showMessageDialog(
             ex.getLocalizedMessage(),
             Localizer.currentLocalizer().get("msg.LoadingContentTypeClass"),
             JOptionPane.ERROR_MESSAGE);
   }
   return ct;
 }
示例#4
0
  private void doit() {
    DataFlavor xfer_flavors[];
    Object content = null;

    // now let's create a DataHandler
    dh = new DataHandler(fds);
    dh.setCommandMap(cmdMap);
    System.out.println("DCHTest2: DataHandler created");

    // get the dataflavors
    xfer_flavors = dh.getTransferDataFlavors();
    System.out.println(
        "DCHTest2: dh.getTransferDF returned " + xfer_flavors.length + " data flavors.");

    // get the content:
    try {
      content = dh.getContent();
    } catch (Exception e) {
      e.printStackTrace();
    }
    if (content == null) System.out.println("DCHTest2: no content to be had!!!");
    else
      System.out.println(
          "DCHTest2: got content of the following type: " + content.getClass().getName());
  }
示例#5
0
 private void insertString(int pos, String str) {
   Document doc = getDocument();
   try {
     doc.insertString(pos, str, null);
   } catch (Exception e) {
     Debug.error(me + "insertString: Problem while trying to insert at pos\n%s", e.getMessage());
   }
 }
示例#6
0
 public FileList() {
   super("FileList", true, true, true);
   try {
     jbInit();
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
示例#7
0
  /** set the mailcap file in the CMD Map */
  public void setMailcap(String mailcap) {

    try {
      cmdMap = new MailcapCommandMap(mailcap);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
示例#8
0
 public Method getGetter(String name) {
   Method getMethod = null;
   try {
     getMethod = this.getClass().getMethod(name, (Class[]) null);
   } catch (Exception ea) {
     ea.printStackTrace();
   }
   return getMethod;
 }
示例#9
0
 public EditorPanel getEditorPanelWithInstance() {
   EditorPanel thePanel = null;
   try {
     thePanel = new KeywordPanel();
     thePanel.edit(this);
   } catch (Exception ea) {
     ea.printStackTrace();
   }
   return (thePanel);
 }
示例#10
0
 // TODO not used
 public void appendString(String str) {
   Document doc = getDocument();
   try {
     int start = doc.getLength();
     doc.insertString(doc.getLength(), str, null);
     int end = doc.getLength();
     // end = parseLine(start, end, patHistoryBtnStr);
   } catch (Exception e) {
     Debug.error(me + "appendString: Problem while trying to append\n%s", e.getMessage());
   }
 }
示例#11
0
 /**
  * This method is activated on the Keystrokes we are listening to in this implementation. Here it
  * listens for Copy and Paste ActionCommands. Selections comprising non-adjacent cells result in
  * invalid selection and then copy action cannot be performed. Paste is done by aligning the upper
  * left corner of the selection with the 1st element in the current selection of the JTable.
  */
 public void actionPerformed(ActionEvent e) {
   if (e.getActionCommand().compareTo("Copy") == 0) {
     StringBuffer sbf = new StringBuffer();
     // Check to ensure we have selected only a contiguous block of
     // cells
     int numcols = jTable1.getSelectedColumnCount();
     int numrows = jTable1.getSelectedRowCount();
     int[] rowsselected = jTable1.getSelectedRows();
     int[] colsselected = jTable1.getSelectedColumns();
     if (!((numrows - 1 == rowsselected[rowsselected.length - 1] - rowsselected[0]
             && numrows == rowsselected.length)
         && (numcols - 1 == colsselected[colsselected.length - 1] - colsselected[0]
             && numcols == colsselected.length))) {
       JOptionPane.showMessageDialog(
           null, "Invalid Copy Selection", "Invalid Copy Selection", JOptionPane.ERROR_MESSAGE);
       return;
     }
     for (int i = 0; i < numrows; i++) {
       for (int j = 0; j < numcols; j++) {
         sbf.append(jTable1.getValueAt(rowsselected[i], colsselected[j]));
         if (j < numcols - 1) sbf.append("\t");
       }
       sbf.append("\n");
     }
     stsel = new StringSelection(sbf.toString());
     system = Toolkit.getDefaultToolkit().getSystemClipboard();
     system.setContents(stsel, stsel);
   }
   if (e.getActionCommand().compareTo("Paste") == 0) {
     System.out.println("Trying to Paste");
     int startRow = (jTable1.getSelectedRows())[0];
     int startCol = (jTable1.getSelectedColumns())[0];
     try {
       String trstring =
           (String) (system.getContents(this).getTransferData(DataFlavor.stringFlavor));
       System.out.println("String is:" + trstring);
       StringTokenizer st1 = new StringTokenizer(trstring, "\n");
       for (int i = 0; st1.hasMoreTokens(); i++) {
         rowstring = st1.nextToken();
         StringTokenizer st2 = new StringTokenizer(rowstring, "\t");
         for (int j = 0; st2.hasMoreTokens(); j++) {
           value = (String) st2.nextToken();
           if (startRow + i < jTable1.getRowCount() && startCol + j < jTable1.getColumnCount())
             jTable1.setValueAt(value, startRow + i, startCol + j);
           System.out.println(
               "Putting " + value + "at row = " + startRow + i + "column = " + startCol + j);
         }
       }
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   }
 }
 public static String getHomePath() {
   String home = System.getProperty("HOME");
   if (home == null) {
     try {
       String thisPath = SystemUtils.class.getResource("SystemUtils.class").getPath();
       String thisPkg = SystemUtils.class.getPackage().getName();
       home = thisPath.substring(0, thisPath.indexOf(thisPkg.substring(0, thisPkg.indexOf('.'))));
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   if (home == null) home = "";
   return home;
 }
示例#13
0
  public Method getSetter(String name, Class argName) {
    Class[] paramList = new Class[1];
    Method setMethod = null;
    try {

      // 	System.out.println("setter " + name + "  "
      // 															 + paramList + " " + argName);
      if (argName == DefaultPersistibleList.class) argName = Collection.class;
      // 	System.out.println("setter " + name + "  "
      // 															 + paramList + " " + argName);
      paramList[0] = argName;
      setMethod = this.getClass().getMethod(name, paramList);
    } catch (Exception ea) {
      ea.printStackTrace();
    }
    return setMethod;
  }
示例#14
0
    @Override
    protected Transferable createTransferable(JComponent c) {
      JTextPane aTextPane = (JTextPane) c;

      SikuliEditorKit kit = ((SikuliEditorKit) aTextPane.getEditorKit());
      Document doc = aTextPane.getDocument();
      int sel_start = aTextPane.getSelectionStart();
      int sel_end = aTextPane.getSelectionEnd();

      StringWriter writer = new StringWriter();
      try {
        _copiedImgs.clear();
        kit.write(writer, doc, sel_start, sel_end - sel_start, _copiedImgs);
        return new StringSelection(writer.toString());
      } catch (Exception e) {
        Debug.error(me + "createTransferable: Problem creating text to copy\n%s", e.getMessage());
      }
      return null;
    }
示例#15
0
 private void indent(int startLine, int endLine, int level) {
   Document doc = getDocument();
   String strIndent = "";
   if (level > 0) {
     for (int i = 0; i < level; i++) {
       strIndent += "  ";
     }
   } else {
     Debug.error("negative indentation not supported yet!!");
   }
   for (int i = startLine; i < endLine; i++) {
     try {
       int off = getLineStartOffset(i);
       if (level > 0) {
         doc.insertString(off, strIndent, null);
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
示例#16
0
    @Override
    protected void done() {
      // Turn off indeterminate.
      progressBar.setIndeterminate(false);

      // Check for exceptions, and display them if necessary.
      try {
        get();
      } catch (Exception e) {
        StringWriter stack_trace = new StringWriter();
        e.printStackTrace(new PrintWriter(stack_trace));

        MessageBox.messageBox(
            mainFrame,
            "Error while " + task,
            "The following error occurred while "
                + task
                + ": "
                + e.getMessage()
                + "\n\nStack trace: "
                + stack_trace,
            MessageBox.ERROR);
      }
    }
  /**
   * Create a new reader.
   *
   * @param in the input
   * @param out the output
   * @param bindings the key bindings to use
   * @param term the terminal to use
   */
  public ConsoleReader(InputStream in, Writer out, InputStream bindings, Terminal term)
      throws IOException {
    this.terminal = term;
    setInput(in);
    this.out = out;

    if (bindings == null) {
      try {
        String bindingFile =
            System.getProperty(
                "jline.keybindings",
                new File(System.getProperty("user.home", ".jlinebindings.properties"))
                    .getAbsolutePath());

        if (new File(bindingFile).isFile()) {
          bindings = new FileInputStream(new File(bindingFile));
        }
      } catch (Exception e) {
        // swallow exceptions with option debugging
        if (debugger != null) {
          e.printStackTrace(debugger);
        }
      }
    }

    if (bindings == null) {
      bindings = terminal.getDefaultBindings();
    }

    this.keybindings = new short[Character.MAX_VALUE * 2];

    Arrays.fill(this.keybindings, UNKNOWN);

    /**
     * Loads the key bindings. Bindings file is in the format:
     *
     * <p>keycode: operation name
     */
    if (bindings != null) {
      Properties p = new Properties();
      p.load(bindings);
      bindings.close();

      for (Iterator i = p.keySet().iterator(); i.hasNext(); ) {
        String val = (String) i.next();

        try {
          Short code = new Short(val);
          String op = (String) p.getProperty(val);

          Short opval = (Short) KEYMAP_NAMES.get(op);

          if (opval != null) {
            keybindings[code.shortValue()] = opval.shortValue();
          }
        } catch (NumberFormatException nfe) {
          consumeException(nfe);
        }
      }

      // hardwired arrow key bindings
      // keybindings[VK_UP] = PREV_HISTORY;
      // keybindings[VK_DOWN] = NEXT_HISTORY;
      // keybindings[VK_LEFT] = PREV_CHAR;
      // keybindings[VK_RIGHT] = NEXT_CHAR;
    }
  }