fileshape.java
来自「mywork是rcp开发的很好的例子」· Java 代码 · 共 77 行
JAVA
77 行
package net.sf.freenote.model;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import net.sf.util.TousleUtil;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
import sun.misc.BASE64Encoder;
/**
* 文件类形体的父类
* @author levin
*/
public abstract class FileShape extends Shape {
public static final String FILEPATH_PROP = "FilePath";
private String[] fileEmbed; //0-name,1-base64 content
public FileShape() {
super();
fileEmbed=new String[2];
}
public String getFilePath() {
return fileEmbed[0]==null?"":fileEmbed[0];
}
public void setFilePath(String filePath) {
//处理文件嵌入
File f=new File(filePath);
if(f.exists()){
try {
fileEmbed[0]=f.getName();
ByteArrayOutputStream baos=new ByteArrayOutputStream();
TousleUtil.copyIntput2Output(new FileInputStream(f), baos);
fileEmbed[1]=new BASE64Encoder().encode(baos.toByteArray());
} catch (Exception e) {
e.printStackTrace();
}
}
firePropertyChange(FILEPATH_PROP, null, filePath);
}
@Override
public IPropertyDescriptor[] getPropertyDescriptors() {
IPropertyDescriptor[] propertyDescriptors = super.getPropertyDescriptors();
IPropertyDescriptor[] ret=new IPropertyDescriptor[propertyDescriptors.length+1];
System.arraycopy(propertyDescriptors, 0, ret, 1, propertyDescriptors.length);
ret[0]=new TextPropertyDescriptor(FILEPATH_PROP, FILEPATH_PROP);
return ret;
}
@Override
public Object getPropertyValue(Object propertyId) {
if(FILEPATH_PROP.equals(propertyId))
return getFilePath();
return super.getPropertyValue(propertyId);
}
@Override
public void setPropertyValue(Object propertyId, Object value) {
if(FILEPATH_PROP.equals(propertyId))
setFilePath(String.valueOf(value));
else
super.setPropertyValue(propertyId, value);
}
public String[] getFileEmbed() {
return fileEmbed;
}
public void setFileEmbed(String[] fileEmbed) {
this.fileEmbed = fileEmbed;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?