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


Java DataFlavor.getReaderForText方法代码示例

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


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

示例1: extractText

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
private String extractText( Transferable t, DataFlavor flavor ) 
        throws IOException, UnsupportedFlavorException {
    
    Reader reader = flavor.getReaderForText(t);
    if( null == reader )
        return null;
    StringBuffer res = new StringBuffer();
    char[] buffer = new char[4*1024];
    int len;
    while( (len=reader.read( buffer )) > 0 ) {
        res.append(buffer, 0, len);
    }
    
    return res.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:DragAndDropHandler.java

示例2: getPasteTypes

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
public PasteType[] getPasteTypes(final Object node, final Transferable t) throws UnknownTypeException {
    if (node != TreeModel.ROOT && getWatch(node) == null) {
        return null;
    }
    DataFlavor[] flavors = t.getTransferDataFlavors();
    final DataFlavor textFlavor = DataFlavor.selectBestTextFlavor(flavors);
    if (textFlavor != null) {
        return new PasteType[] { new PasteType() {

            public Transferable paste() {
                try {
                    java.io.Reader r = textFlavor.getReaderForText(t);
                    java.nio.CharBuffer cb = java.nio.CharBuffer.allocate(1000);
                    r.read(cb);
                    cb.flip();
                    Watch w = getWatch(node);
                    if (w != null) {
                        w.setExpression(cb.toString());
                        //fireModelChange(new ModelEvent.NodeChanged(WatchesNodeModel.this, node));
                    } else {
                        // Root => add a new watch
                        DebuggerManager.getDebuggerManager().createWatch(cb.toString());
                    }
                } catch (Exception ex) {}
                return null;
            }
        } };
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:WatchesNodeModel.java

示例3: importData

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
/**
 * This method causes a transfer to a component from a clipboard or a
 * DND drop operation.  The Transferable represents the data to be
 * imported into the component.
 *
 * @param comp  The component to receive the transfer.  This
 *  argument is provided to enable sharing of TransferHandlers by
 *  multiple components.
 * @param t The data to import
 * @return <code>true</code> iff the data was inserted into the component.
 */
@Override
public boolean importData(JComponent comp, Transferable t) {

	JTextComponent c = (JTextComponent)comp;
	withinSameComponent = c==exportComp;

	// if we are importing to the same component that we exported from
	// then don't actually do anything if the drop location is inside
	// the drag location and set shouldRemove to false so that exportDone
	// knows not to remove any data
	if (withinSameComponent && c.getCaretPosition()>=p0 && c.getCaretPosition()<=p1) {
		shouldRemove = false;
		return true;
	}

	boolean imported = false;
	DataFlavor importFlavor = getImportFlavor(t.getTransferDataFlavors(), c);
	if (importFlavor != null) {
		try {
			InputContext ic = c.getInputContext();
			if (ic != null) {
				ic.endComposition();
			}
			Reader r = importFlavor.getReaderForText(t);
			handleReaderImport(r, c);
			imported = true;
		} catch (UnsupportedFlavorException ufe) {
			ufe.printStackTrace();
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}

	return imported;

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:48,代码来源:RTATextTransferHandler.java

示例4: main

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  DataFlavor df = DataFlavor.plainTextFlavor;
  TextTransferable t = new TextTransferable();
  Reader reader;
  try {
      reader = df.getReaderForText(t);
  } catch (UnsupportedEncodingException e) {
       throw new RuntimeException("FAILED: Exception thrown in getReaderForText()");
  }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ReaderForUnicodeText.java

示例5: main

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  DataFlavor pt ;

  try {
      pt = DataFlavor.plainTextFlavor;
      StringSelection ss = new StringSelection("ReaderExample");
      Reader re = pt.getReaderForText(ss);
      if(re == null) {
          throw new RuntimeException("Test FAILED! reader==null");
      }
  } catch (Exception e) {
      throw new RuntimeException("Test FAILED because of the exception: " + e);
  }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:GetReaderForTextIAEForStringSelectionTest.java

示例6: getDropType

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
public PasteType getDropType(final Object node, final Transferable t, int action,
                             final int index) throws UnknownTypeException {
    //System.err.println("\n\ngetDropType("+node+", "+t+", "+action+", "+index+")");
    DataFlavor[] flavors = t.getTransferDataFlavors();
    final DataFlavor textFlavor = DataFlavor.selectBestTextFlavor(flavors);
    //System.err.println("Text Flavor = "+textFlavor);
    if (textFlavor != null) {
        return new PasteType() {

            public Transferable paste() {
                String watchExpression;
                try {
                    java.io.Reader r = textFlavor.getReaderForText(t);
                    java.nio.CharBuffer cb = java.nio.CharBuffer.allocate(1000);
                    r.read(cb);
                    cb.flip();
                    watchExpression = cb.toString();
                } catch (Exception ex) {
                    return t;
                }
                Watch w = getWatch(node);
                if (w != null) {
                    w.setExpression(watchExpression);
                    //fireModelChange(new ModelEvent.NodeChanged(WatchesNodeModel.this, node));
                } else {
                    // Root => add a new watch
                    if (index < 0) {
                        DebuggerManager.getDebuggerManager().createWatch(watchExpression);
                    } else {
                        DebuggerManager.getDebuggerManager().createWatch(
                                Math.min(index, DebuggerManager.getDebuggerManager().getWatches().length),
                                watchExpression);
                    }
                }
                return t;
            }
        };
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:WatchesNodeModel.java

示例7: getDroppedNativeFiles

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static List<File> getDroppedNativeFiles(Transferable t) throws UnsupportedFlavorException, IOException
{
	// This works for Windows
	if( t.isDataFlavorSupported(DataFlavor.javaFileListFlavor) )
	{
		return (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
	}

	// This works for Gnome and KDE
	for( DataFlavor flavor : t.getTransferDataFlavors() )
	{
		if( flavor.isRepresentationClassReader() )
		{
			try( BufferedReader reader = new BufferedReader(flavor.getReaderForText(t)) )
			{
				List<File> list = new ArrayList<File>();

				String line = null;
				while( (line = reader.readLine()) != null )
				{
					try
					{
						if( ZERO_CHAR_STRING.equals(line) )
						{
							continue;
						}

						list.add(new File(new java.net.URI(line)));
					}
					catch( Exception ex )
					{
						ex.printStackTrace();
					}
				}

				return list;
			}
		}
	}

	throw new UnsupportedFlavorException(null);
}
 
开发者ID:equella,项目名称:Equella,代码行数:44,代码来源:DnDUtils.java


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