java.awt.datatransfer.Clipboard Java Examples

The following examples show how to use java.awt.datatransfer.Clipboard. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DebuggingActionsProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static void stackToCLBD(List<JPDAThread> threads) {
    StringBuffer frameStr = new StringBuffer(512);
    for (JPDAThread t : threads) {
        if (frameStr.length() > 0) {
            frameStr.append('\n');
        }
        frameStr.append("\"");
        frameStr.append(t.getName());
        frameStr.append("\"\n");
        appendStackInfo(frameStr, t);
    }
    Clipboard systemClipboard = getClipboard();
    Transferable transferableText =
            new StringSelection(frameStr.toString());
    systemClipboard.setContents(
            transferableText,
            null);
}
 
Example #2
Source File: DebuggingJSActionsProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void stackToCLBD(List<JPDAThread> threads) {
    StringBuffer frameStr = new StringBuffer(512);
    for (JPDAThread t : threads) {
        if (frameStr.length() > 0) {
            frameStr.append('\n');
        }
        frameStr.append("\"");
        frameStr.append(t.getName());
        frameStr.append("\"\n");
        appendStackInfo(frameStr, t);
    }
    Clipboard systemClipboard = getClipboard();
    Transferable transferableText =
            new StringSelection(frameStr.toString());
    systemClipboard.setContents(
            transferableText,
            null);
}
 
Example #3
Source File: PasteAction.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {
  if (calledFromAppleScreenMenu(evt)) {
    return;
  }
  ChartSelection selection = myViewmanager.getSelectedArtefacts();
  if (!selection.isEmpty()) {
    pasteInternalFlavor(selection);
    return;
  }
  Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  if (clipboard.isDataFlavorAvailable(GPTransferable.EXTERNAL_DOCUMENT_FLAVOR)) {
    try {
      Object data = clipboard.getData(GPTransferable.EXTERNAL_DOCUMENT_FLAVOR);
      if (data instanceof InputStream == false) {
        return;
      }
      pasteExternalDocument((InputStream) data);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
 
Example #4
Source File: DErrorDetail.java    From keystore-explorer with GNU General Public License v3.0 6 votes vote down vote up
private void copyPressed() {
	StringBuffer strBuff = new StringBuffer();

	Throwable copyError = error;

	while (copyError != null) {
		strBuff.append(copyError);
		strBuff.append('\n');

		for (StackTraceElement stackTrace : copyError.getStackTrace()) {
			strBuff.append("\tat ");
			strBuff.append(stackTrace);
			strBuff.append('\n');
		}

		copyError = copyError.getCause();

		if (copyError != null) {
			strBuff.append('\n');
		}
	}

	Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
	StringSelection copy = new StringSelection(strBuff.toString());
	clipboard.setContents(copy, copy);
}
 
Example #5
Source File: NetAdmin.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Copy the selected row to clipboard
 * @param table JTable
 */
private static void copyTableRowToClipboard(final JTable table) {
	int row = table.getSelectedRow();

	if(row != -1) {
		String strCopy = "";

		for(int column = 0; column < table.getColumnCount(); column++) {
			Object selectedObject = table.getValueAt(row, column);
			if(selectedObject instanceof String) {
				if(column == 0) {
					strCopy += (String)selectedObject;
				} else {
					strCopy += "," + (String)selectedObject;
				}
			}
		}

		StringSelection ss = new StringSelection(strCopy);
		Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
		clipboard.setContents(ss, ss);
	}
}
 
Example #6
Source File: bug8059739.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void runTest() throws Exception {
    String testString = "my string";
    JTextField tf = new JTextField(testString);
    tf.selectAll();
    Clipboard clipboard = new Clipboard("clip");
    tf.getTransferHandler().exportToClipboard(tf, clipboard, TransferHandler.COPY);
    DataFlavor[] dfs = clipboard.getAvailableDataFlavors();
    for (DataFlavor df: dfs) {
        String charset = df.getParameter("charset");
        if (InputStream.class.isAssignableFrom(df.getRepresentationClass()) &&
                charset != null) {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    (InputStream) clipboard.getData(df), charset));
            String s = br.readLine();
            System.out.println("Content: '" + s + "'");
            passed &= s.contains(testString);
        }
    }
}
 
Example #7
Source File: AbstractPlUmlEditor.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean doPaste() {
  boolean result = false;

  final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  String text = null;
  try {
    if (Utils.isDataFlavorAvailable(clipboard, DataFlavor.stringFlavor)) {
      text = clipboard.getData(DataFlavor.stringFlavor).toString();
    }
  } catch (Exception ex) {
    logger.warn("Can't get data from clipboard : " + ex.getMessage()); //NOI18N
  }
  if (text != null) {
    this.editor.replaceSelection(text);
    result = true;
  }
  return result;
}
 
Example #8
Source File: CircuitComponent.java    From Digital with GNU General Public License v3.0 6 votes vote down vote up
private ToolTipAction createPasteAction(ShapeFactory shapeFactory) {
    return new ToolTipAction(Lang.get("menu_paste")) {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (!isLocked()) {
                Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                try {
                    Object data = clipboard.getData(DataFlavor.stringFlavor);
                    if (data instanceof String) {
                        Vector posVector = getPosVector(lastMousePos.x, lastMousePos.y);
                        ArrayList<Movable> elements = CircuitTransferable.createList(data, shapeFactory);
                        if (elements != null)
                            setPartsToInsert(elements, posVector);
                    }
                } catch (Exception e1) {
                    e1.printStackTrace();
                    SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_clipboardContainsNoImportableData")).setComponent(CircuitComponent.this));
                }
            }
        }
    }.setAcceleratorCTRLplus('V').enableAcceleratorIn(this);
}
 
Example #9
Source File: TToolBar.java    From tracker with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Refreshes and returns the "new tracks" popup menu.
 *
 * @return the popup
 */
protected JPopupMenu getNewTracksPopup() {
  newPopup.removeAll();
  TMenuBar menubar = TMenuBar.getMenuBar(trackerPanel);
  menubar.refresh();
	for (Component c: menubar.newTrackItems) {
    newPopup.add(c);
    if (c==menubar.newDataTrackMenu) {
      // disable newDataTrackPasteItem unless pastable data is on the clipboard
      menubar.newDataTrackPasteItem.setEnabled(false);
      Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
      Transferable data = clipboard.getContents(null);
      if (data != null && data.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
        	String s = (String)data.getTransferData(DataFlavor.stringFlavor);
        	menubar.newDataTrackPasteItem.setEnabled(ParticleDataTrack.getImportableDataName(s)!=null);
        } catch (Exception ex) {}
      }      	
    }
	}
  if (menubar.cloneMenu.getItemCount()>0 && trackerPanel.isEnabled("new.clone")) { //$NON-NLS-1$
  	newPopup.addSeparator();
    newPopup.add(menubar.cloneMenu);    
  }
  return newPopup;
}
 
Example #10
Source File: Clip.java    From Logisim with GNU General Public License v3.0 6 votes vote down vote up
public void copy() {
	Caret caret = editor.getCaret();
	long p0 = caret.getMark();
	long p1 = caret.getDot();
	if (p0 < 0 || p1 < 0)
		return;
	if (p0 > p1) {
		long t = p0;
		p0 = p1;
		p1 = t;
	}
	p1++;

	int[] data = new int[(int) (p1 - p0)];
	HexModel model = editor.getModel();
	for (long i = p0; i < p1; i++) {
		data[(int) (i - p0)] = model.get(i);
	}

	Clipboard clip = editor.getToolkit().getSystemClipboard();
	clip.setContents(new Data(data), this);
}
 
Example #11
Source File: OutlineView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void doCopy(ExplorerManager em) {
    Node[] sel = em.getSelectedNodes();
    Transferable trans = ExplorerActionsImpl.getTransferableOwner(sel, true);
    
    Transferable ot = new OutlineTransferHandler().createOutlineTransferable();
    if (trans != null) {
        if (ot != null) {
            trans = new TextAddedTransferable(trans, ot);
        }
    } else {
        trans = ot;
    }
    
    if (trans != null) {
        Clipboard clipboard = ExplorerActionsImpl.getClipboard();
        if (clipboard != null) {
            clipboard.setContents(trans, new StringSelection("")); // NOI18N
        }
    }                        
}
 
Example #12
Source File: bug8059739.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static void runTest() throws Exception {
    String testString = "my string";
    JTextField tf = new JTextField(testString);
    tf.selectAll();
    Clipboard clipboard = new Clipboard("clip");
    tf.getTransferHandler().exportToClipboard(tf, clipboard, TransferHandler.COPY);
    DataFlavor[] dfs = clipboard.getAvailableDataFlavors();
    for (DataFlavor df: dfs) {
        String charset = df.getParameter("charset");
        if (InputStream.class.isAssignableFrom(df.getRepresentationClass()) &&
                charset != null) {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    (InputStream) clipboard.getData(df), charset));
            String s = br.readLine();
            System.out.println("Content: '" + s + "'");
            passed &= s.contains(testString);
        }
    }
}
 
Example #13
Source File: ClientGlobals.java    From gepard with MIT License 6 votes vote down vote up
public static void unexpectedError(Exception e, Controller ctrl) {
	
	// handles any unexpected errors
	// asks the user to send an error report to the developer
	
	String guidump = ctrl.getGUIDump();
	String msg;
	msg = "An unexpected error occured!\nStack trace & GUI details copied to clipboard.";
	JOptionPane.showMessageDialog(null, msg, "Error", JOptionPane.ERROR_MESSAGE);
	
	String report = stack2string(e) + "\n\n\n\n" + guidump;
	StringSelection stringSelection = new StringSelection (report);
	Clipboard clpbrd = Toolkit.getDefaultToolkit ().getSystemClipboard ();
	clpbrd.setContents (stringSelection, null);

}
 
Example #14
Source File: WToolkit.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Clipboard getSystemClipboard() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
    }
    synchronized (this) {
        if (clipboard == null) {
            clipboard = new WClipboard();
        }
    }
    return clipboard;
}
 
Example #15
Source File: MDExporter.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void doExportToClipboard(@Nonnull final PluginContext context, @Nonnull final JComponent options) throws IOException {
  final String text = makeContent(context.getPanel());
  SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
      final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
      if (clipboard != null) {
        clipboard.setContents(new StringSelection(text), null);
      }
    }
  });
}
 
Example #16
Source File: XToolkit.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public Clipboard getSystemSelection() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
    }
    synchronized (this) {
        if (selection == null) {
            selection = new XClipboard("Selection", "PRIMARY");
        }
    }
    return selection;
}
 
Example #17
Source File: DViewAsn1Dump.java    From keystore-explorer with GNU General Public License v3.0 5 votes vote down vote up
private void copyPressed() {
	String policy = jtaAsn1Dump.getText();

	Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
	StringSelection copy = new StringSelection(policy);
	clipboard.setContents(copy, copy);
}
 
Example #18
Source File: WToolkit.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Clipboard getSystemClipboard() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
    }
    synchronized (this) {
        if (clipboard == null) {
            clipboard = new WClipboard();
        }
    }
    return clipboard;
}
 
Example #19
Source File: JValue.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void doCopyPath() {
  String path = node.absolutePath();

  StringSelection sel  = new StringSelection(path);
  Clipboard       clip = Toolkit.getDefaultToolkit().getSystemClipboard();
  
  clip.setContents(sel, sel);
}
 
Example #20
Source File: DataFlavorRemoteTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Producer contents = new Producer();
    clipboard.setContents(contents, null);
    ProcessResults processResults =
            ProcessCommunicator
                    .executeChildProcess(Consumer.class, new String[0]);
    if (!"Hello".equals(processResults.getStdErr())) {
        throw new RuntimeException("transfer of remote object failed");
    }
    System.out.println("ok");
}
 
Example #21
Source File: TextInputBox.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 5 votes vote down vote up
private static String getClipboardContent(){
		Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
		try {
			return (String) cb.getData(DataFlavor.stringFlavor);
		} catch (UnsupportedFlavorException | IOException e) {
			e.printStackTrace();
			return "";
		}
}
 
Example #22
Source File: WToolkit.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Clipboard getSystemClipboard() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
    }
    synchronized (this) {
        if (clipboard == null) {
            clipboard = new WClipboard();
        }
    }
    return clipboard;
}
 
Example #23
Source File: LegendPanelImage.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Copy to clipboard. */
protected void copyToClipboard() {
    if (imageIcon != null) {
        try {
            Image image = imageIcon.getImage();
            BufferedImage buffered = (BufferedImage) image;

            ImageSelection trans = new ImageSelection(buffered);
            Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
            c.setContents(trans, null);
        } catch (Exception e) {
            ConsoleManager.getInstance().exception(LegendPanelImage.class, e);
        }
    }
}
 
Example #24
Source File: AboutDomainObjectUtils.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private static void writeDataToClipboard(Component component) {
	Clipboard systemClipboard = GClipboard.getSystemClipboard();
	try {
		systemClipboard.setContents(createContents(component), null);
	}
	catch (IllegalStateException e) {
		Msg.showInfo(AboutDomainObjectUtils.class, null, "Cannot Copy Data",
			"Unable to copy information to clipboard.  Please try again.");
	}
}
 
Example #25
Source File: DragDropUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Gets right transferable of given nodes (according to given
* drag action) and also converts the transferable.<br>
* Can be called only with correct action constant.
* @return The transferable.
*/
static Transferable getNodeTransferable(Node[] nodes, int dragAction)
throws IOException {
    Transferable[] tArray = new Transferable[nodes.length];

    for (int i = 0; i < nodes.length; i++) {
        if ((dragAction & DnDConstants.ACTION_MOVE) != 0) {
            tArray[i] = nodes[i].clipboardCut();
        } else {
            tArray[i] = nodes[i].drag ();
        }
    }
    Transferable result;
    if (tArray.length == 1) {
        // only one node, so return regular single transferable
        result = tArray[0];
    } else {
        // enclose the transferables into multi transferable
        result = ExternalDragAndDrop.maybeAddExternalFileDnd( new Multi(tArray) );
    }

    Clipboard c = getClipboard();
    if (c instanceof ExClipboard) {
        return ((ExClipboard) c).convert(result);
    } else {
        return result;
    }
}
 
Example #26
Source File: ProcessPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Looks through the file list for the first file with .rmp file extension and returns its content as a String. If
 * there is no such file, {@code null} is returned instead.
 *
 * @param clipBoard
 * 		Clipboard holding a file list.
 * @return XML process definition or {@code null}.
 */
private static String loadProcessFromFileList(Clipboard clipBoard, MainFrame mainFrame) throws IOException, UnsupportedFlavorException {
	@SuppressWarnings("unchecked") // we did the check in firePasteProcess - the cast is safe
			List<File> fileList = ((List<File>) clipBoard.getContents(mainFrame.getProcessPanel()).getTransferData(DataFlavor.javaFileListFlavor));
	for (File file : fileList) {
		if (RapidMiner.PROCESS_FILE_EXTENSION.equals(FilenameUtils.getExtension(file.getName()))) {
			return new String(Files.readAllBytes(file.toPath()));
		}
	}
	return null;
}
 
Example #27
Source File: DebuggingActionsModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void stackToCLBD() {
    if (!dbg.isSuspended()) {
        return ;
    }
    StringBuilder frameStr = new StringBuilder(500);
    CallStack stack = dbg.getCurrentCallStack();
    if (stack != null) {
        for (CallFrame frame : stack.getCallFrames()) {
            String thisName = frame.getThisName();
            if ("Object".equals(thisName) || "global".equals(thisName)) {
                thisName = null;
            }
            if (thisName != null && !thisName.isEmpty()) {
                frameStr.append(thisName);
                frameStr.append('.');
            }
            String functionName = frame.getFunctionName();
            frameStr.append(functionName);
            
            String scriptName = DebuggingModel.getScriptName(frame);
            if (scriptName == null) {
                scriptName = "?";
            }
            frameStr.append(" (");
            frameStr.append(scriptName);
            long line = frame.getFrame().getLine()+1;
            long column = frame.getFrame().getColumn()+1;
            frameStr.append(":");
            frameStr.append(line + 1);
            frameStr.append(":");
            frameStr.append(column + 1);
            frameStr.append(")\n");
        }
    }
    Clipboard systemClipboard = getClipboard();
    Transferable transferableText = new StringSelection(frameStr.toString());
    systemClipboard.setContents(transferableText, null);
}
 
Example #28
Source File: ShellTextComponent.java    From basicv2 with The Unlicense 5 votes vote down vote up
private static String getClipBoardString() throws Exception {
	Clipboard clipboard = getDefaultToolkit().getSystemClipboard();
	Transferable clipData = clipboard.getContents(clipboard);
	if (clipData != null) {
		if (clipData.isDataFlavorSupported(stringFlavor)) {
			return (String) (clipData.getTransferData(stringFlavor));
		}
	}
	throw new Exception("no clpboard data");
}
 
Example #29
Source File: XToolkit.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public  Clipboard getSystemClipboard() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
    }
    synchronized (this) {
        if (clipboard == null) {
            clipboard = new XClipboard("System", "CLIPBOARD");
        }
    }
    return clipboard;
}
 
Example #30
Source File: FreeMindExporter.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void doExportToClipboard(@Nonnull final PluginContext context, @Nonnull final JComponent options) throws IOException {
  final String text = makeContent(context.getPanel());

  SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
      final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
      if (clipboard != null) {
        clipboard.setContents(new StringSelection(text), null);
      }
    }
  });
}