?? datatransfer.java
字號:
/*
* $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/gefmodule/util/DataTransfer.java,v 1.1.1.1 2004/07/01 09:07:49 wang_j Exp $
* $Revision: 1.1.1.1 $
* $Date: 2004/07/01 09:07:49 $
*
* ====================================================================
*
* The NanJing HopeRun(IT-FOREST) Software License, Version 2.0.0
*
* Copyright 2003-2004 by NanJing HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and
* IT Forest Corporation
* All rights reserved.
*
* This software is the confidential and proprietary information of
* HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
* You shall not disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into with
* HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
*/
package com.webpump.ui.gefmodule.util;
import java.io.*;
import org.eclipse.swt.dnd.*;
/**
* Class for DataTransfer
*
* @author shi_l
* @version 2.0.0 2004-5-30
*/
public class DataTransfer extends ByteArrayTransfer {
/**
* Singleton instance.
*/
private static final DataTransfer instance = new DataTransfer();
// Create a unique ID to make sure that different Eclipse
// applications use different "types" of <code>ModelDataTransfer</code>
public static final String TYPE_PREFIX = "webpump-model-transfer-format";
private static final String TYPE_NAME =
TYPE_PREFIX + ":" + System.currentTimeMillis() + ":" + instance.hashCode();
private static final int TYPEID = registerType(TYPE_NAME);
public static DataTransfer getInstance() {
return instance;
}
/**
* Constructor for ModelDataTransfer.
*/
public DataTransfer() {
super();
}
/* (non-Javadoc)
* Method declared on Transfer.
*/
protected int[] getTypeIds() {
return new int[] { TYPEID };
}
/* (non-Javadoc)
* Returns the type names.
*
* @return the list of type names
*/
protected String[] getTypeNames() {
return new String[] { TYPE_NAME };
}
/* (non-Javadoc)
* Method declared on Transfer.
*/
protected void javaToNative(Object data, TransferData transferData) {
if (!(data instanceof Object[])) {
return;
}
Object[] objects = (Object[]) data;
int count = objects.length;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream objectOut = new ObjectOutputStream(out);
//write the number of resources
objectOut.writeInt(count);
//write each object
for (int i = 0; i < objects.length; i++) {
objectOut.writeObject(objects[i]);
}
//cleanup
objectOut.close();
out.close();
byte[] bytes = out.toByteArray();
super.javaToNative(bytes, transferData);
} catch (IOException e) {
//it's best to send nothing if there were problems
System.out.println(e);
}
}
/* (non-Javadoc)
* Method declared on Transfer.
*/
protected Object nativeToJava(TransferData transferData) {
byte[] bytes = (byte[]) super.nativeToJava(transferData);
if (bytes == null)
return null;
try {
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
int count = in.readInt();
Object[] objects = new Object[count];
for (int i = 0; i < count; i++) {
objects[i] = in.readObject();
}
in.close();
return objects;
} catch (ClassNotFoundException e) {
return null;
} catch (IOException e) {
return null;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -