📄 clipboard.java
字号:
package HAB.object;
import java.awt.*;
import java.awt.datatransfer.*;
import java.io.*;
import java.util.*;
import java.awt.image.*;
import HAB.HcBean.HpException;
import HAB.HcBean.HalcyonAppletBeanInterface;
public class ClipBoard implements HAB.HcBean.HalcyonAppletBeanInterface ,java.io.Serializable
{
public static int formatstr = 1; // text
public static int formatpic = 2; // bmp
static Clipboard clipboardstr = Toolkit.getDefaultToolkit().getSystemClipboard();
static Clipboard clipboardpic = new Clipboard("image clipboard");
static ClipboardOwner defaultClipboardOwner = new ClipboardObserver();
//--------------------- Get...------------------------------
public static void Clear()throws HpException
{
SetText("");
formatstr=formatpic=0;
}
public static boolean GetFormat(int Format)//return 0 =false -1=true
{
if(formatstr == Format)return true;
else if(formatpic == Format )
return true;
else return false;
}
//==================== TEXT ==================
public static void SetText(String textname)throws HpException
{
SetText(textname,1);
}
public static void SetText(String textname,int Format)throws HpException
{
if(!(Format==1 || Format== 0xBF00 || Format==0xBF01))
throw new HpException(460,"Invalid clipboard format");
formatstr=Format;
StringSelection contents = new StringSelection(textname);
clipboardstr.setContents(contents, defaultClipboardOwner);
}
public static String GetText()throws HpException
{
return GetText(1);
}
public static String GetText(int Format)throws HpException
{
if(!(Format==1 || Format== 0xBF00 || Format==0xBF01))
throw new HpException(460,"Invalid clipboard format");
String dstData="";
if(formatstr==Format)
{
Transferable content = clipboardstr.getContents(dstData);
if (content != null)
{
boolean bol=false;
try{
bol=content.isDataFlavorSupported(DataFlavor.stringFlavor);
}catch(Exception e)
{
return "";
}
if(bol)
{
try
{
dstData = (String)content.getTransferData(DataFlavor.stringFlavor);
}
catch (UnsupportedFlavorException e) { }
catch (IOException e){}
}
}
return dstData ;
}
else return dstData;
}
//================== BMP ===================
public static void SetData(Picture picture) throws HpException
{
SetData(picture,2);
}
public static void SetData(Picture pict,int Format)throws HpException
{
if(!(Format==2 || Format==3 || Format==8 || Format==9))
throw new HpException(461,"Speccified format doesn't match the format of data ");
formatpic=Format;
Picture picture=pict;
PictureSelection contents = new PictureSelection(picture);
clipboardpic.setContents(contents, defaultClipboardOwner);
}
public static Picture GetData()throws HpException
{
return GetData(2);
}
public static Picture GetData(int Format)throws HpException
{
if(!(Format==2 || Format== 3 || Format==8 || Format==9))
throw new HpException(460,"Invalid clipboard format");
Picture picture=null;
if(Format==formatpic)
{
Transferable contents = clipboardpic.getContents(picture);
if(contents != null && contents.isDataFlavorSupported(PictureSelection.PictureFlavor))
{
try
{
picture=(Picture) contents.getTransferData(PictureSelection.PictureFlavor);
}
catch(Exception e)
{e.printStackTrace();}
}
if(picture==null)
return new Picture();
else
return picture;
}
if(picture==null)
return new Picture();
else
return picture;
}
static class ClipboardObserver implements ClipboardOwner
{
public void lostOwnership(Clipboard clipboard, Transferable contents) {}
}
private static java.beans.BeanInfo bi = null;
public java.beans.BeanInfo getBeanInfo()
{
if (bi == null)
{
bi =(java.beans.BeanInfo) new HAB.object.ClipBoardBeanInfo();
}
return bi;
}
private void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException
{
s.defaultWriteObject();
}
private void readObject(java.io.ObjectInputStream s)
throws java.lang.ClassNotFoundException,
java.io.IOException
{
s.defaultReadObject();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -