?? filesharingservice.java
字號:
package connex.plugins.filesharing;
import java.io.*;
import java.lang.reflect.*;
import javax.swing.*;
import net.jxta.share.*;
import connex.plugins.filesharing.CMService;
import connex.plugins.filesharing.ui.ResultsTable;
import connex.plugins.filesharing.ui.FilesharingPanel;
import connex.session.plugin.Plugin;
import connex.core.WS.Workspace;
import java.util.Hashtable;
import java.util.Enumeration;
import connex.core.WS.Boot;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
public class FilesharingService
implements Plugin {
/**
* @directed
* @link aggregationByValue
*/
private CMService myCMS;
// private SearchManager searchM;
/**
* @directed
* @supplierCardinality 1
* @clientCardinality 1
*/
private ShareManager shareM = null;
protected static FilesharingService fsc = null;
private FilesharingPanel fspanel = null;
private File dir;
private boolean started = false;
private Workspace ws;
/**
* @directed
* @supplierCardinality 0..*
* @clientCardinality 1
* @clientRole create
* @link aggregation
*/
private ContentSearch search;
private Hashtable<String, ContentDownload> downloads = new Hashtable<String,
ContentDownload> ();
/**
* @directed
* @supplierCardinality 0..*
* @clientCardinality 1
* @clientRole create
* @link aggregation
*/
private ContentDownload dmg;
private File folder;
//private ResultsTable rt;
static final Logger LOG = Logger.getLogger(FilesharingService.class);
public FilesharingService() {
fsc = this;
}
public void initPlugin(Object param) {
LOG.setLevel(Level.INFO);
this.ws = (Workspace) param;
myCMS = CMService.getInstance();
try {
myCMS.init(ws.getPeerGroup(), null, null);
this.fspanel = new FilesharingPanel();
if (LOG.isEnabledFor(Level.INFO)) {
LOG.info("CMS init success...\n");
}
}
catch (Exception e) {
if (LOG.isEnabledFor(Level.INFO)) {
LOG.info("CMS init failure...");
}
e.printStackTrace();
// System.exit( -1);
}
}
public void startPlugin() {
if (started) {
return;
}
myCMS.startApp(ws.getWorkspaceFolder());
if (LOG.isEnabledFor(Level.INFO)) {
LOG.info("CMS started...\n");
}
started = true;
}
public JPanel getMainUI() {
return this.fspanel;
}
public void stopPlugin() {
myCMS.stopApp();
started = false;
Enumeration<ContentDownload> num = downloads.elements();
ContentDownload dMangr;
while (num.hasMoreElements()) {
dMangr = downloads.remove(num.nextElement().getContentAdvertisement().
getContentId().toString());
dMangr.cancel();
}
fspanel.cleanUP();
fspanel = null;
if (LOG.isEnabledFor(Level.INFO)) {
LOG.info("CMS stoped...\n");
}
}
public Workspace getWorkspace() {
return this.ws;
}
public void downloadContent(ContentAdvertisement[] res) {
if (downloads.containsKey(res[0].getContentId().toString())) {
JOptionPane.showMessageDialog(null, "File already downloaded",
"Download Info",
JOptionPane.INFORMATION_MESSAGE);
return;
}
try {
dmg = new ContentDownload(ws.getPeerGroup(), res);
downloads.put(res[0].getContentId().toString(), dmg);
}
catch (InvocationTargetException ex) {
}
}
public void cancelDownload(String id) {
if (downloads.containsKey(id)) {
dmg = downloads.remove(id);
dmg.cancel();
}
}
public void searchContent(String subStr) {
ResultsTable rt = new ResultsTable();
fspanel.addResultsTable(rt);
rt.startSearch(subStr);
}
public synchronized void shareContent(ShareFile file) {
if (shareM == null) {
shareM = new ShareManager(myCMS, getShareList());
}
if (!shareM.isRunning()) {
shareM.share(file);
}
else {
JOptionPane.showMessageDialog(null, "Please waite ...",
"Download Info",
JOptionPane.INFORMATION_MESSAGE);
}
}
public void unshareContent(ShareFile file) {
if (shareM == null) {
shareM = new ShareManager(myCMS, getShareList());
}
shareM.unShare(file);
}
public void unshareAll() {
if (shareM == null) {
shareM = new ShareManager(myCMS, getShareList());
}
shareM.unshareAll();
}
public void loadContents() {
if (shareM == null) {
shareM = new ShareManager(myCMS, getShareList());
}
shareM.loadContents();
}
public DefaultListModel getShareList() {
return fspanel.getShareList();
}
public void setDownloadDir(String downloadDir) {
dir = new File(downloadDir);
if (false == dir.exists()) {
// create the directory
dir.mkdir();
}
}
public static FilesharingService getInstance() {
if (fsc == null) {
return new FilesharingService();
}
else {
return fsc;
}
}
public void createSession(String id) {
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -