?? sharemanager.java
字號:
package connex.plugins.filesharing;
import java.io.*;
import javax.swing.*;
import net.jxta.document.*;
import net.jxta.share.*;
import net.jxta.share.metadata.*;
public class ShareManager
implements Runnable {
/**
* @directed
* @link aggregationByValue
*/
CMService myCMS;
MimeMediaType type = new MimeMediaType("text", "xml");
/**
* @directed
*/
private ShareFile file;
private DefaultListModel fileList;
//private File files[] = null;
JFileChooser fc = new JFileChooser();
private boolean run = false;
private Thread shareThread=null;
public ShareManager(CMService myCMS, DefaultListModel fileList) {
this.myCMS = myCMS;
this.fileList = fileList;
}
public void share(ShareFile file) {
this.file = file;
shareThread = new Thread(this);
shareThread.start();
}
protected boolean isRunning() {
if(shareThread==null){
return false;
}
return shareThread.isAlive();
}
public void run() {
shareContent(file);
//th = null;
}
private void shareContent(ShareFile file) {
try {
if (file.isDirectory()) {
File[] files = file.listFiles();
//Share a default Directory
int length = files.length;
for (int i = 0; i < length; i++) {
ShareFile tmpfile = new ShareFile(files[i].getPath());
shareContent(tmpfile);
}
}
else {
String fileType = myCMS.getContentManager().getMimeType(
file);
StructuredDocument doc = StructuredDocumentFactory.
newStructuredDocument(type,
"metadata",
FilesharingService.getInstance().
getWorkspace().getPeerAdv().getName());
ContentMetadata[] md = {
ContentMetadataFactory.newInstance(doc)};
FileContent f = myCMS.getContentManager().share(
file, file.getName().toString(),
fileType, md);
try {
Icon ico = fc.getIcon(file);
file.setContent( (Content) f);
file.setIcon(ico);
fileList.addElement(file);
}
catch (Exception ex) {
}
}
}
catch (IOException e) {
System.out.println("ERROR: could not share ");
e.printStackTrace();
return;
}
}
/**
*
* @param file ShareFile
*/
public void unShare(ShareFile file) {
try {
myCMS.getContentManager().unshare(file.getContent());
}
catch (Exception e) {}
}
/**
*
*/
public void unshareAll() {
File f = new File("client/shares.ser");
f.delete();
int size = fileList.size();
for (int i = 0; i < size; i++) {
try {
myCMS.getContentManager().unshare( ( (ShareFile) fileList.
elementAt(i)).getContent());
}
catch (IOException ex) {
}
}
fileList.removeAllElements();
}
/**
*
*/
public void loadContents() {
ShareFile file;
Content[] con;
con = myCMS.getContentManager().getContent();
if (con.length < 1) {
return;
}
for (int i = 0; i < con.length; i++) {
try {
file = new ShareFile(con[i].toString().substring(6,
con[i].toString().indexOf(";")));
Icon ico = fc.getIcon(file);
file.setContent(con[i]);
myCMS.publishContent(con[i]);
file.setIcon(ico);
fileList.addElement(file);
}
catch (Exception ex) {
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -