Example #1
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;
    }
  }
Example #2
0
  public static String getSysClipboardText() {
    String ret = "";
    Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();

    Transferable clipTf = sysClip.getContents(null);

    if (clipTf != null) {

      if (clipTf.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
          ret = (String) clipTf.getTransferData(DataFlavor.stringFlavor);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    if (ret.length() > 1) {
      if (ret.substring(ret.length() - 1).equals("\n")
          || ret.substring(ret.length() - 1).equals("\r")) {
        ret = ret.substring(0, ret.length() - 1);
      }
    }

    return ret;
  }
 /**
  * Manages mouse clicks
  *
  * @param e the event
  * @see javax.swing.text.DefaultCaret#mouseClicked(java.awt.event.MouseEvent)
  */
 public void mouseClicked(MouseEvent e) {
   if (SwingUtilities.isMiddleMouseButton(e) && e.getClickCount() == 1) {
     /** * PASTE USING MIDDLE BUTTON ** */
     JTextComponent c = (JTextComponent) e.getSource();
     if (c != null) {
       Toolkit tk = c.getToolkit();
       Clipboard buffer = tk.getSystemSelection();
       if (buffer != null) {
         Transferable trans = buffer.getContents(null);
         if (trans.isDataFlavorSupported(DataFlavor.stringFlavor)) {
           try {
             String pastedText = (String) trans.getTransferData(DataFlavor.stringFlavor);
             ((JTextPane) getConsole().getConfiguration().getInputCommandView())
                 .replaceSelection(pastedText);
           } catch (UnsupportedFlavorException e1) {
             e1.printStackTrace();
           } catch (IOException e1) {
             e1.printStackTrace();
           }
         }
       }
     }
   } else if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 1) {
     /** * SEND THE FOCUS TO THE INPUT COMMAND VIEW ** */
     ((JTextPane) getConsole().getConfiguration().getInputCommandView()).requestFocus();
     ((JTextPane) getConsole().getConfiguration().getInputCommandView())
         .getCaret()
         .setVisible(true);
   } else {
     /** * DELEGATE TO THE SYSTEM ** */
     super.mouseClicked(e);
   }
 }
Example #4
0
  private static void GetProxy()
      throws InterruptedException, AWTException, UnsupportedFlavorException, IOException {
    Robot robot = new Robot();
    Thread.sleep(5000);
    for (int i = 1; i <= 50; ++i) {

      robot.keyPress(KeyEvent.VK_CONTROL);
      robot.keyPress(KeyEvent.VK_A);

      robot.keyRelease(KeyEvent.VK_CONTROL);
      robot.keyRelease(KeyEvent.VK_A);

      Thread.sleep(1000);
      robot.keyPress(KeyEvent.VK_CONTROL);
      robot.keyPress(KeyEvent.VK_C);
      robot.keyRelease(KeyEvent.VK_CONTROL);
      robot.keyRelease(KeyEvent.VK_C);

      Thread.sleep(500);
      Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
      Transferable t = cb.getContents(null);
      String readText = (String) t.getTransferData(DataFlavor.stringFlavor);
      // System.out.println(readText);
      String filePath = "F:\\Proxys\\";
      String fileName = "proxy" + Integer.toString(i) + ".txt";
      writeFile(filePath, fileName, readText);
      robot.keyPress(KeyEvent.VK_CONTROL);
      robot.keyPress(KeyEvent.VK_TAB);
      robot.keyRelease(KeyEvent.VK_CONTROL);
      robot.keyRelease(KeyEvent.VK_TAB);
      Thread.sleep(1000);
    }
  }
  /** Get the clipboard contents. */
  public static Object getClipboard() {
    Object result = contents;
    try {
      Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
      Transferable trans = cb.getContents(requestor);

      // get clipboard content
      try {
        Object sysContent = trans.getTransferData(DataFlavor.stringFlavor);
        if (sysContent != null) {
          if (sysContent instanceof String) {
            String str = (String) sysContent;
            // for empty string: take contents of ClipboardHelper
            if (str.trim().length() == 0) {
              result = contents;
            } else {
              result = str;
            }
          }
        }
      } catch (java.io.IOException e) {
        // e.printStackTrace();
        result = contents;
      } catch (UnsupportedFlavorException e) {
        // e.printStackTrace();
        result = contents;
      }
    } catch (Throwable t) {
      // we're in Communicator or something again....
    }
    return result;
  }
Example #6
0
 /**
  * Returns the clipboard text.
  *
  * @return text
  */
 static final String clip() {
   // copy selection to clipboard
   final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
   final Transferable tr = clip.getContents(null);
   if (tr != null) {
     for (final Object o : BaseXLayout.contents(tr)) return o.toString();
   }
   return "";
 }
Example #7
0
 public static String pastefromClipboard() {
   Clipboard C = Toolkit.getDefaultToolkit().getSystemClipboard();
   Transferable T = C.getContents(null);
   try {
     return (String) T.getTransferData(DataFlavor.stringFlavor);
   } catch (UnsupportedFlavorException | IOException E) {
     if (dologging) Logger.getLogger(ActionHandler.class.getName()).error(E);
   }
   return null;
 }
Example #8
0
 public static String getClipboardText() {
   Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
   Transferable content = clipboard.getContents(null);
   if (content == null || !content.isDataFlavorSupported(DataFlavor.stringFlavor)) return null;
   try {
     return (String) content.getTransferData(DataFlavor.stringFlavor);
   } catch (UnsupportedFlavorException e) {
     return null;
   } catch (IOException e) {
     return null;
   }
 }
 @Override
 public String retrieve() {
   try {
     Clipboard clipboard = Lookup.getDefault().lookup(Clipboard.class);
     Transferable contents = clipboard.getContents(null);
     return (String) contents.getTransferData(DataFlavor.stringFlavor);
   } catch (UnsupportedFlavorException ex) {
     return null;
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   }
 }
Example #10
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 Image getImageFromClipboard() throws UnsupportedFlavorException, IOException {
   Image result = null;
   Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
   // odd: the Object param of getContents is not currently used
   Transferable contents = clipboard.getContents(null);
   boolean hasTransferablePhoto =
       (contents != null) && contents.isDataFlavorSupported(DataFlavor.imageFlavor);
   if (hasTransferablePhoto) {
     result = (Image) contents.getTransferData(DataFlavor.imageFlavor);
   }
   return result;
 }
Example #12
0
 /**
  * Returns the clipboard text.
  *
  * @return text
  */
 private static String clip() {
   // copy selection to clipboard
   final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
   final Transferable tr = clip.getContents(null);
   if (tr != null) {
     final ArrayList<Object> contents = BaseXLayout.contents(tr);
     if (!contents.isEmpty()) return contents.get(0).toString();
   } else {
     Util.debug("Clipboard has no contents.");
   }
   return null;
 }
Example #13
0
  // Called from native widget when paste key is pressed and we
  // already own the selection (prevents Motif from hanging while
  // waiting for the selection)
  //
  // NOTE: This method is called by privileged threads.
  //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
  public void pasteFromClipboard() {
    Clipboard clipboard = target.getToolkit().getSystemClipboard();

    Transferable content = clipboard.getContents(this);
    if (content != null) {
      try {
        String data = (String) (content.getTransferData(DataFlavor.stringFlavor));
        insertReplaceText(data);

      } catch (Exception e) {
      }
    }
  }
Example #14
0
  public boolean canDoClipBoardAction(Action action) {
    if (action == GUIPrism.getClipboardPlugin().getPasteAction()) {
      Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
      return (clipboard.getContents(null) != null);
    } else if (action == GUIPrism.getClipboardPlugin().getCutAction()
        || action == GUIPrism.getClipboardPlugin().getCopyAction()
        || action == GUIPrism.getClipboardPlugin().getDeleteAction()) {
      return (editor.getSelectedText() != null);
    } else if (action == GUIPrism.getClipboardPlugin().getSelectAllAction()) {
      return true;
    }

    return handler.canDoClipBoardAction(action);
  }
  public boolean clipBoardHasString() {

    Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable t = clip.getContents(this);
    try {
      String s = (String) t.getTransferData(DataFlavor.stringFlavor);
      if (s != null) {
        return true;
      }
    } catch (Exception e) {
      MesquiteMessage.printStackTrace(e);
    }
    return false;
  }
Example #16
0
 void paste() {
   Clipboard cb = this.getToolkit().getSystemClipboard();
   Transferable t = cb.getContents(this);
   if (t == null) {
     this.getToolkit().beep();
     return;
   }
   try {
     String temp = (String) t.getTransferData(DataFlavor.stringFlavor);
     insertText(temp);
   } catch (Exception e) {
     this.getToolkit().beep();
   }
 }
Example #17
0
 private void lookup() {
   Transferable content = clipboard.getContents(this);
   if (content == null) {
     return;
   }
   try {
     String s = (String) content.getTransferData(DataFlavor.stringFlavor);
     if (!this.value.equals(s)) {
       this.value = s;
       lookup(s, false);
     }
   } catch (Exception e) {
   }
 }
 /**
  * Get the String residing on the clipboard.
  *
  * @return any text found on the Clipboard; if none found, return an empty String.
  */
 public String getClipboardContents() {
   String result = "";
   Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
   // odd: the Object param of getContents is not currently used
   Transferable contents = clipboard.getContents(null);
   if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
     try {
       result = (String) contents.getTransferData(DataFlavor.stringFlavor);
     } catch (UnsupportedFlavorException | IOException e) {
       // highly unlikely since we are using a standard DataFlavor
       LOGGER.info("problem with getting clipboard contents", e);
     }
   }
   return result;
 }
 private String getTextFromSystemClipboard() {
   String result = "";
   Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
   Transferable contents = clipboard.getContents(null);
   boolean hasTransferableText =
       (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
   if (hasTransferableText) {
     try {
       result = (String) contents.getTransferData(DataFlavor.stringFlavor);
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   }
   return result;
 }
Example #20
0
  @Override
  public Object getClipboard(final Class<?> cls) {
    if (cls == String.class) {

      final Clipboard cb = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
      final Transferable content = cb.getContents(this);

      String value = "illegal value";
      try {
        value = ((String) content.getTransferData(DataFlavor.stringFlavor));
      } catch (final Throwable e) {
        LOG.error("invalid clipboard operation " + e);
      }
      return value;
    } else {
      return null;
    }
  }
Example #21
0
 public void onPaste(ActionEvent ae) {
   Object sourceObj = ae.getSource();
   if (sourceObj instanceof JButton) {
     JButton pasteButton = (JButton) sourceObj;
     JTextField textField = (JTextField) pasteButton.getClientProperty(TEXT_FIELD_PROPERTY);
     Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
     // odd: the Object param of getContents is not currently used
     Transferable contents = clipboard.getContents(null);
     boolean hasTransferableText =
         (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
     if (hasTransferableText) {
       try {
         textField.setText((String) contents.getTransferData(DataFlavor.stringFlavor));
       } catch (UnsupportedFlavorException | IOException ignored) {
       }
     }
   }
 }
Example #22
0
  /** Inserts the clipboard contents into the text. */
  public void paste() {
    if (editable) {
      Clipboard clipboard = getToolkit().getSystemClipboard();
      try {
        // The MacOS MRJ doesn't convert \r to \n,
        // so do it here
        String selection =
            ((String) clipboard.getContents(this).getTransferData(DataFlavor.stringFlavor))
                .replace('\r', '\n');

        int repeatCount = inputHandler.getRepeatCount();
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < repeatCount; i++) buf.append(selection);
        selection = buf.toString();
        setSelectedText(selection);
      } catch (Exception e) {
        getToolkit().beep();
        System.err.println("Clipboard does not" + " contain a string");
      }
    }
  }
 /**
  * Get the String residing on the clipboard.
  *
  * @return any text found on the Clipboard; if none found, return an empty String.
  */
 public String getClipboardContents() {
   String result = "";
   Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
   // odd: the Object param of getContents is not currently used
   Transferable contents = clipboard.getContents(null);
   boolean hasTransferableText =
       (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
   if (hasTransferableText) {
     try {
       result = (String) contents.getTransferData(DataFlavor.stringFlavor);
     } catch (UnsupportedFlavorException ex) {
       // highly unlikely since we are using a standard DataFlavor
       System.out.println(ex);
       ex.printStackTrace();
     } catch (IOException ex) {
       System.out.println(ex);
       ex.printStackTrace();
     }
   }
   return result;
 }
Example #24
0
  private void dumpFlavorsOld(Transferable t) {
    DataFlavor[] dfa = t.getTransferDataFlavors();

    if (dfa != null) {
      if (dfa.length == 0) {
        JConfig.log().logVerboseDebug("Trying a second attack...");
        try {
          Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
          Transferable t2 = sysClip.getContents(null);
          StringBuffer stBuff;

          stBuff = getTransferData(t2);
          JConfig.log().logVerboseDebug("Check out: " + stBuff);
        } catch (Exception e) {
          JConfig.log().handleException("Caught: " + e, e);
        }
        JConfig.log().logVerboseDebug("Done trying a second attack...");
      }
    }
    dumpDataFlavors(dfa);
  }
  private ArrayList<Integer> getValuesFromClipboard() {
    ArrayList<Integer> dataValues = new ArrayList<Integer>();

    try {
      log.debug("Clipboard contents: " + system.getName());
      String trstring =
          (String) (system.getContents(this).getTransferData(DataFlavor.stringFlavor));
      System.out.println("String is:" + trstring);
      StringTokenizer st1 = new StringTokenizer(trstring, "\n");

      String rowstring;
      for (int i = 0; st1.hasMoreTokens(); i++) {
        rowstring = st1.nextToken();

        String[] values = rowstring.split("\t");
        if (values.length == 0) {
          values = rowstring.split(",");
        }
        if (values.length == 0) {
          values = rowstring.split(" ");
        }

        if (values.length == 1) {
          Integer v = Integer.valueOf(values[0]);
          dataValues.add(v);
        } else if (values.length == 2) {
          Integer v = Integer.valueOf(values[1]);
          dataValues.add(v);
        } else {
          log.error("Unable to extract data from clipboard");
          return null;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      log.error("Unable to extract data from clipboard");
    }

    return dataValues;
  }
Example #26
0
  /**
   * Get the String residing on the clipboard.
   *
   * @return any text found on the Clipboard; if none found, return an empty String.
   */
  public void openClipboardContents() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    // odd: the Object param of getContents is not currently used
    Transferable contents = clipboard.getContents(null);
    boolean hasTransferableText =
        (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
    if (hasTransferableText) {
      TextDocument entry_document = new TextDocument();
      final InputStreamProgressListener progress_listener = getInputStreamProgressListener();

      entry_document.addInputStreamProgressListener(progress_listener);

      final EntryInformation artemis_entry_information = Options.getArtemisEntryInformation();

      final uk.ac.sanger.artemis.io.Entry new_embl_entry =
          EntryFileDialog.getEntryFromFile(this, entry_document, artemis_entry_information, false);

      if (new_embl_entry == null) // the read failed
      return;

      try {
        final Entry entry = new Entry(new_embl_entry);
        EntryEdit last_entry_edit = makeEntryEdit(entry);
        addEntryEdit(last_entry_edit);
        getStatusLabel().setText("");
        last_entry_edit.setVisible(true);
      } catch (OutOfRangeException e) {
        new MessageDialog(
            this,
            "read failed: one of the features in "
                + " cut and paste has an out of range "
                + "location: "
                + e.getMessage());
      } catch (NoSequenceException e) {
        new MessageDialog(this, "read failed: " + " cut and paste contains no sequence");
      }
    }
  }
 public void loadFlameFromClipboardButton_clicked() {
   List<Flame> newFlames = null;
   try {
     Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
     Transferable clipData = clipboard.getContents(clipboard);
     if (clipData != null) {
       if (clipData.isDataFlavorSupported(DataFlavor.stringFlavor)) {
         String xml = (String) (clipData.getTransferData(DataFlavor.stringFlavor));
         newFlames = new FlameReader(prefs).readFlamesfromXML(xml);
       }
     }
     if (newFlames == null || newFlames.size() < 1) {
       throw new Exception("There is currently no valid flame in the clipboard");
     } else {
       for (Flame newFlame : newFlames) {
         project.getFlames().add(validateDancingFlame(newFlame));
       }
       refreshProjectFlames();
       enableControls();
     }
   } catch (Throwable ex) {
     errorHandler.handleError(ex);
   }
 }
  /**
   * 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.
   *
   * @param e
   */
  public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().compareTo("Copy") == 0) {
      StringBuffer sbf = new StringBuffer();

      // Check to ensure we have selected only a continguous block of cells
      int numcols = jTable1.getSelectedColumnCount();
      int numrows = jTable1.getSelectedRowCount();
      int[] rowsselected = jTable1.getSelectedRows();
      int[] colsselected = jTable1.getSelectedColumns();

      if (rowsselected.length == 0 || colsselected.length == 0) {
        AppUtility.msgError(frame, "You have to select cells to copy !!");
        return;
      }

      String temp = "";
      for (int l = 0; l < numrows; l++) {
        for (int m = 0; m < numcols; m++) {
          if (jTable1.getValueAt(rowsselected[l], colsselected[m]) != null) {

            sbf.append(jTable1.getValueAt(rowsselected[l], colsselected[m]));

          } else {
            sbf.append("");
          }
          if (m < 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) {

      jTable1
          .getParent()
          .getParent()
          .getParent()
          .setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
      String table = "";

      if (debug) {
        System.out.println("Trying to Paste");
      }
      int startRow = 0; // (jTable1.getSelectedRows())[0];
      int startCol = 0; // (jTable1.getSelectedColumns())[0];

      while (jTable1.getRowCount() > 0) {
        ((DefaultTableModel) jTable1.getModel()).removeRow(0);
      }

      try {
        String trstring =
            (String) (system.getContents(this).getTransferData(DataFlavor.stringFlavor));
        if (debug) {
          System.out.println("String is: " + trstring);
        }
        StringTokenizer st1 = new StringTokenizer(trstring, "\n");

        if (insertRowsWhenPasting) {

          for (int i = 0; i < st1.countTokens(); i++) {
            ((DefaultTableModel) jTable1.getModel()).addRow(new Object[] {null, null});
          }
        }

        for (int i = 0; st1.hasMoreTokens(); i++) {

          rowstring = st1.nextToken();
          StringTokenizer st2 = new StringTokenizer(rowstring, "\t");

          for (int j = 0; st2.hasMoreTokens(); j++) {
            value = st2.nextToken();
            if (j < jTable1.getColumnCount()) {
              jTable1.setValueAt(value, i, j);
            }

            if (debug) {
              System.out.println(
                  "Putting " + value + "at row=" + (startRow + i) + "column=" + (startCol + j));
            }
          }
        }
      } catch (Exception ex) {
        ex.printStackTrace();

        ((DefaultTableModel) jTable1.getModel()).addRow(new Object[] {null, null});
      }

      jTable1
          .getParent()
          .getParent()
          .getParent()
          .setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    }
  }
  /**
   * Paste the contents of the clipboard into the console buffer
   *
   * @return true if clipboard contents pasted
   */
  public boolean paste() throws IOException {
    Clipboard clipboard;
    try { // May throw ugly exception on system without X
      clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    } catch (Exception e) {
      return false;
    }

    if (clipboard == null) {
      return false;
    }

    Transferable transferable = clipboard.getContents(null);

    if (transferable == null) {
      return false;
    }

    try {
      Object content = transferable.getTransferData(DataFlavor.plainTextFlavor);

      /*
       * This fix was suggested in bug #1060649 at
       * http://sourceforge.net/tracker/index.php?func=detail&aid=1060649&group_id=64033&atid=506056
       * to get around the deprecated DataFlavor.plainTextFlavor, but it
       * raises a UnsupportedFlavorException on Mac OS X
       */
      if (content == null) {
        try {
          content = new DataFlavor().getReaderForText(transferable);
        } catch (Exception e) {
        }
      }

      if (content == null) {
        return false;
      }

      String value;

      if (content instanceof Reader) {
        // TODO: we might want instead connect to the input stream
        // so we can interpret individual lines
        value = "";

        String line = null;

        for (BufferedReader read = new BufferedReader((Reader) content);
            (line = read.readLine()) != null; ) {
          if (value.length() > 0) {
            value += "\n";
          }

          value += line;
        }
      } else {
        value = content.toString();
      }

      if (value == null) {
        return true;
      }

      putString(value);

      return true;
    } catch (UnsupportedFlavorException ufe) {
      if (debugger != null) debug(ufe + "");

      return false;
    }
  }
Example #30
0
  public void drop(DropTargetDropEvent dtde) {
    Transferable t = dtde.getTransferable();
    StringBuffer dropData = null;
    DataFlavor dtf;

    JConfig.log().logVerboseDebug("Dropping!");

    if (t.getTransferDataFlavors().length == 0) {
      Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
      Transferable t2 = sysClip.getContents(null);
      DataFlavor[] dfa2;
      int j;

      JConfig.log().logDebug("Dropped 0 data flavors, trying clipboard.");
      dfa2 = null;

      if (t2 != null) {
        JConfig.log().logVerboseDebug("t2 is not null: " + t2);
        dfa2 = t2.getTransferDataFlavors();
        JConfig.log().logVerboseDebug("Back from getTransferDataFlavors()!");
      } else {
        JConfig.log().logVerboseDebug("t2 is null!");
      }

      if (JConfig.queryConfiguration("debug.uber", "false").equals("true")) {
        if (dfa2 != null) {
          if (dfa2.length == 0) {
            JConfig.log().logVerboseDebug("Length is still zero!");
          }
          for (j = 0; j < dfa2.length; j++) {
            JConfig.log()
                .logVerboseDebug("Flavah " + j + " == " + dfa2[j].getHumanPresentableName());
            JConfig.log().logVerboseDebug("Flavah/mime " + j + " == " + dfa2[j].getMimeType());
          }
        } else {
          JConfig.log().logVerboseDebug("Flavahs supported: none!\n");
        }
      }
    }

    if (JConfig.queryConfiguration("debug.uber", "false").equals("true") && JConfig.debugging)
      dumpFlavorsOld(t);

    dtf = testAllFlavors(t);
    if (dtf != null) {
      JConfig.log().logVerboseDebug("Accepting!");
      acceptDrop(dtde);

      dropData = getTransferData(t);
      dtde.dropComplete(true);
      dtde.getDropTargetContext().dropComplete(true);
      if (dropData != null) {
        if (handler != null) {
          handler.receiveDropString(dropData);
        }
      }
    } else {
      JConfig.log().logVerboseDebug("Rejecting!");
      dtde.rejectDrop();
      handler.receiveDropString(dropData);
    }
  }