当前位置: 首页>>代码示例>>Java>>正文


Java Clipboard.getContents方法代码示例

本文整理汇总了Java中java.awt.datatransfer.Clipboard.getContents方法的典型用法代码示例。如果您正苦于以下问题:Java Clipboard.getContents方法的具体用法?Java Clipboard.getContents怎么用?Java Clipboard.getContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.datatransfer.Clipboard的用法示例。


在下文中一共展示了Clipboard.getContents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testClipboard

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
public void testClipboard() throws Exception {
    MockServices.setServices(Cnv.class);
    Clipboard c = Lookup.getDefault().lookup(Clipboard.class);
    ExClipboard ec = Lookup.getDefault().lookup(ExClipboard.class);
    assertEquals("Clipboard == ExClipboard", c, ec);
    assertNotNull(Lookup.getDefault().lookup(ExClipboard.Convertor.class));
    assertEquals(Cnv.class, Lookup.getDefault().lookup(ExClipboard.Convertor.class).getClass());
    c.setContents(new ExTransferable.Single(DataFlavor.stringFlavor) {
        protected Object getData() throws IOException, UnsupportedFlavorException {
            return "17";
        }
    }, null);
    Transferable t = c.getContents(null);
    assertTrue("still supports stringFlavor", t.isDataFlavorSupported(DataFlavor.stringFlavor));
    assertEquals("correct string in clipboard", "17", t.getTransferData(DataFlavor.stringFlavor));
    assertTrue("support Integer too", t.isDataFlavorSupported(MYFLAV));
    assertEquals("correct Integer", new Integer(17), t.getTransferData(MYFLAV));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:NbClipboardNativeTest.java

示例2: paste

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
void paste() throws IOException {
	Clipboard clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
	Transferable contents = clip.getContents(this);
	DataFlavor[] flavors = contents.getTransferDataFlavors();
	for( int k=0 ; k<flavors.length ; k++) {
		try {
			if( flavors[k].getHumanPresentableName().indexOf("html")>=0 )continue;
			BufferedReader in = new BufferedReader(
				flavors[k].getReaderForText(contents));
	System.out.println( flavors[k].getHumanPresentableName());
			read( in );
			break;
		} catch( UnsupportedFlavorException e) {
		}
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:17,代码来源:TableDB.java

示例3: doPaste

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
private void doPaste() {
	Clipboard clip =
		java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
	try {
		Transferable content = clip.getContents(this);
		if (content == null)
			return;
		String txt =
			content
				.getTransferData(new DataFlavor(String.class, "String"))
				.toString();
		document.replace(
			editor.getSelectionStart(),
			editor.getSelectionEnd() - editor.getSelectionStart(),
			txt,
			editorKit.getInputAttributes());
		//editor.replaceSelection(content.getTransferData(new
		// DataFlavor(String.class, "String")).toString());
		//editor.paste();
		//insertHTML(content.getTransferData(new DataFlavor(String.class,
		// "String")).toString(), editor.getCaretPosition());
		/*
		 * Element el =
		 * document.getParagraphElement(editor.getCaretPosition());
		 * insertTextInElement(el, content.getTransferData(new
		 * DataFlavor(String.class, "String")).toString(),
		 */

	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
开发者ID:ser316asu,项目名称:Neukoelln_SER316,代码行数:33,代码来源:HTMLEditor.java

示例4: updateTrans

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
private void updateTrans() {
    Clipboard clipboard = getClipboard();
    if (clipboard == null) {
        return;
    }
    Transferable t = clipboard.getContents(ExplorerActionsImpl.this);
    synchronized (this) {
        trans = t;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:ExplorerActionsImpl.java

示例5: pasteHelp

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
private void pasteHelp(Clipboard cb) {
    if (read_only) {
        return;
    }

    Transferable contents = cb.getContents(screen);
    if (contents == null) {
        return;
    }

    if (!contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        return;
    }

    try {
        String string;
        string = (String) contents.getTransferData(DataFlavor.stringFlavor);
        
        // bug #237034
        if (string == null) {
            return;
        }
        /* DEBUG
        System.out.println("System selection contains '" + string + "'"); // NOI18N
         */
        char ca[] = string.toCharArray();
        sendChars(ca, 0, ca.length);
    } catch (UnsupportedFlavorException | IOException e) {
        //
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:Term.java

示例6: doPaste

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
private void doPaste() {
    Clipboard clip =
        java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
    try {
        Transferable content = clip.getContents(this);
        if (content == null)
            return;
        String txt =
            content
                .getTransferData(new DataFlavor(String.class, "String"))
                .toString();
        document.replace(
            editor.getSelectionStart(),
            editor.getSelectionEnd() - editor.getSelectionStart(),
            txt,
            editorKit.getInputAttributes());
        //editor.replaceSelection(content.getTransferData(new
        // DataFlavor(String.class, "String")).toString());
        //editor.paste();
        //insertHTML(content.getTransferData(new DataFlavor(String.class,
        // "String")).toString(), editor.getCaretPosition());
        /*
         * Element el =
         * document.getParagraphElement(editor.getCaretPosition());
         * insertTextInElement(el, content.getTransferData(new
         * DataFlavor(String.class, "String")).toString(),
         */

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
开发者ID:ser316asu,项目名称:SER316-Dresden,代码行数:33,代码来源:HTMLEditor.java

示例7: mouseReleased

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
/**
 * Gets called when the mouse was released on a Swing component
 * that has this object as a MouseListener.
 *
 * @param e The event that holds the information about the mouse click.
 */
@Override
public void mouseReleased(MouseEvent e) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable clipData = clipboard.getContents(clipboard);
    if (clipData != null) {
        if (clipData.isDataFlavorSupported(DefaultTransferHandler.flavor)) {
            JComponent comp = (JComponent)e.getSource();
            TransferHandler handler = comp.getTransferHandler();
            handler.importData(comp, clipData);
        }
    }
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:19,代码来源:DropListener.java

示例8: getSysClipboardText

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
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();
			}
		}
	}
	return ret;
}
 
开发者ID:PluginsCDTribe,项目名称:MultiThreadDownloader,代码行数:16,代码来源:MTDownload.java

示例9: doPaste

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
private void doPaste() {
	Clipboard clip =
		java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
	try {
		Transferable content = clip.getContents(this);
		if (content == null)
		{
			return;
		}
		String txt =
			content
				.getTransferData(new DataFlavor(String.class, "String"))
				.toString();
		document.replace(
			editor.getSelectionStart(),
			editor.getSelectionEnd() - editor.getSelectionStart(),
			txt,
			editorKit.getInputAttributes());
		//editor.replaceSelection(content.getTransferData(new
		// DataFlavor(String.class, "String")).toString());
		//editor.paste();
		//insertHTML(content.getTransferData(new DataFlavor(String.class,
		// "String")).toString(), editor.getCaretPosition());
		/*
		 * Element el =
		 * document.getParagraphElement(editor.getCaretPosition());
		 * insertTextInElement(el, content.getTransferData(new
		 * DataFlavor(String.class, "String")).toString(),
		 */

	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
开发者ID:ser316asu,项目名称:SER316-Aachen,代码行数:35,代码来源:HTMLEditor.java

示例10: getContents

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
/**
 * Gets the contents of the system clipboard
 *
 * @return The text contents of the system clipboard
 */
public String getContents() {
    String contents = null;
    Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable data = c.getContents(null);
    if (data != null && data.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
            contents = ((String) (data.getTransferData(DataFlavor.stringFlavor)));
        } catch (Exception e) {
            logger.log(Level.WARNING, "Failed getting tranfer data: " + e.getMessage(), e);
        }
    }
    return contents;
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:19,代码来源:ClipboardHandlerAWT.java

示例11: mouseClicked

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent evt) {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("mouseClicked: " + logMouseEvent(evt) + ", state=" + mouseState + '\n'); // NOI18N
    }
    
    JTextComponent c = component;
    if (c != null) {
        if (isMiddleMouseButtonExt(evt)) {
            if (evt.getClickCount() == 1) {
                if (c == null) {
                    return;
                }
                Clipboard buffer = getSystemSelection();

                if (buffer == null) {
                    return;
                }

                Transferable trans = buffer.getContents(null);
                if (trans == null) {
                    return;
                }

                final BaseDocument doc = (BaseDocument) c.getDocument();
                if (doc == null) {
                    return;
                }

                final int offset = ((BaseTextUI) c.getUI()).viewToModel(c,
                        evt.getX(), evt.getY());

                try {
                    final String pastingString = (String) trans.getTransferData(DataFlavor.stringFlavor);
                    if (pastingString == null) {
                        return;
                    }
                    doc.runAtomicAsUser(new Runnable() {
                        public @Override
                        void run() {
                            try {
                                doc.insertString(offset, pastingString, null);
                                setDot(offset + pastingString.length());
                            } catch (BadLocationException exc) {
                            }
                        }
                    });
                } catch (UnsupportedFlavorException ufe) {
                } catch (IOException ioe) {
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:55,代码来源:BaseCaret.java

示例12: mouseClicked

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent evt) {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("EditorCaret.mouseClicked: " + logMouseEvent(evt) + ", state=" + mouseState + '\n'); // NOI18N
    }

    JTextComponent c = component;
    if (c != null) {
        if (evt.getClickCount() == 1 && evt.isControlDown() && evt.isShiftDown()) {
            evt.consume(); // consume event already handled by mousePressed
        }
        if (isMiddleMouseButtonExt(evt)) {
            if (evt.getClickCount() == 1) {
                if (c == null) {
                    return;
                }
                Clipboard buffer = component.getToolkit().getSystemSelection();

                if (buffer == null) {
                    return;
                }

                Transferable trans = buffer.getContents(null);
                if (trans == null) {
                    return;
                }

                final Document doc = c.getDocument();
                if (doc == null) {
                    return;
                }

                final int offset = c.getUI().viewToModel(c, new Point(evt.getX(), evt.getY()));

                try {
                    final String pastingString = (String) trans.getTransferData(DataFlavor.stringFlavor);
                    if (pastingString == null) {
                        return;
                    }
                    Runnable pasteRunnable = new Runnable() {
                        public @Override
                        void run() {
                            try {
                                doc.insertString(offset, pastingString, null);
                                setDot(offset + pastingString.length());
                                setMagicCaretPosition(null);
                            } catch (BadLocationException exc) {
                            }
                        }
                    };
                    AtomicLockDocument ald = LineDocumentUtils.as(doc, AtomicLockDocument.class);
                    if (ald != null) {
                        ald.runAtomic(pasteRunnable);
                    } else {
                        pasteRunnable.run();
                    }
                } catch (UnsupportedFlavorException ufe) {
                } catch (IOException ioe) {
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:64,代码来源:EditorCaret.java

示例13: clipboard

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
public Object clipboard() throws UnsupportedFlavorException, IOException {
    Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
    DataFlavor d = DataFlavor.getTextPlainUnicodeFlavor();
    Transferable o = c.getContents(this);
    return o;
}
 
开发者ID:Obsidiam,项目名称:joanne,代码行数:7,代码来源:ScreenCenter.java

示例14: pasteFromClipboard

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
public static void pasteFromClipboard(final Row parent) {
    final String error = Main.dataPlugin.getRowPerrmision(parent);
    if (error != null) {
        JOptionPane.showMessageDialog(null, error, ResourceLoader
                .getString("no_permision"), JOptionPane.WARNING_MESSAGE);
        return;
    }

    if (parent != null && parent.getRowType() != Row.TYPE_ROW)
        return;
    int i = 0;
    final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
    final Transferable tr = clip.getContents(null);
    byte[] bs;
    try {
        bs = (byte[]) tr.getTransferData(dataFlavor);
        if (bs == null) {
            if (parent == null)
                return;
            final String t = (String) tr.getTransferData(DataFlavor.stringFlavor);
            if (t == null)
                return;
            boolean tag = false;
            Row old = parent;
            int oldLevel = 0;
            Row r = null;
            if (parent != null)
                tag = true;
            while (i < t.length()) {
                int level = 0;
                String name = "";
                while (i < t.length()) {
                    if (t.charAt(i) != '\r')
                        break;
                    i++;
                }

                while (i < t.length()) {
                    if (t.charAt(i) == '\t')
                        level++;
                    else
                        break;
                    i++;
                }

                while (i < t.length()) {
                    if (t.charAt(i) == ' ')
                        break;
                    i++;
                }

                while (i < t.length()) {
                    if (t.charAt(i) != '\n')
                        name += t.charAt(i);
                    else
                        break;
                    i++;
                }
                if (!name.equals("")) {
                    if (level > oldLevel && r != null) {
                        old = r;
                        oldLevel = level;
                    } else
                        while (level < oldLevel) {
                            old = old.getParentRow();
                            oldLevel--;
                        }
                    r = Main.dataPlugin.createRow(old, tag);
                    r.setName(name);
                }
                i++;
            }
        } else {


        }
    } catch (final Exception e) {
    }

}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:81,代码来源:RowClipboard.java

示例15: canPaste

import java.awt.datatransfer.Clipboard; //导入方法依赖的package包/类
public boolean canPaste() {
	Clipboard clip = editor.getToolkit().getSystemClipboard();
	Transferable xfer = clip.getContents(this);
	return xfer.isDataFlavorSupported(binaryFlavor);
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:6,代码来源:Clip.java


注:本文中的java.awt.datatransfer.Clipboard.getContents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。