?? runaction.java
字號:
/*
* *****************************************************
* Copyright (c) 2005 IIM Lab. All Rights Reserved.
* Created by xuehao at 2005-10-12
* Contact: zxuehao@mail.ustc.edu.cn
* *****************************************************
*/
package org.indigo.gui.actions;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.HashMap;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import org.indigo.commands.*;
import org.indigo.gui.IView;
import org.indigo.gui.TableView;
import org.indigo.gui.ViewManager;
import org.indigo.spider.Spider;
import org.indigo.spider.ThreadPool;
import org.indigo.util.*;
/**
* 當(dāng)選擇任務(wù)并啟動時,此類完成主要的功能。
* 即此類是run按鈕的監(jiān)聽器,當(dāng)點(diǎn)擊run時,執(zhí)行此類的actionPerformed方法。
* @author wbz
*
*/
public class RunAction implements ActionListener
{
private IView itsView=null;
public void setTableView( IView v )
{
itsView = v;
}
/**
* run按鈕的監(jiān)聽函數(shù)。當(dāng)任務(wù)運(yùn)行時,首先執(zhí)行此函數(shù)。
*/
public void actionPerformed(ActionEvent e)
{
JTree tree = ViewManager.getInstance().getTree();//獲取主界面左側(cè)的結(jié)構(gòu)樹。
String nodeName="";
TreePath treePath= tree.getSelectionPath();//獲取所選擇的左側(cè)結(jié)構(gòu)樹中的結(jié)點(diǎn)路徑。
if( treePath==null || treePath.getPathCount()==1 )
return;
int i=1;
for( i=1; i<treePath.getPathCount(); i++ )//對結(jié)點(diǎn)路徑進(jìn)行處理,獲得結(jié)點(diǎn)所對應(yīng)的文件路徑。
{
nodeName += treePath.getPathComponent(i).toString()+"/";
}
nodeName = nodeName.substring( 0, nodeName.length()-1 );//獲得和結(jié)點(diǎn)對應(yīng)的任務(wù)名。
// System.out.println( str );
File file = new File( "./taskconfig/" + nodeName + ".task" );
if( nodeName==null || file.isDirectory() || !file.exists() )
return ;
if( ViewManager.getInstance().checkInTab(nodeName) )//檢查此相同的任務(wù)名是否已經(jīng)啟動。
{
return ;
}
else
{
ViewManager.getInstance().putInTab( nodeName, true );//如果沒有啟動則把此任務(wù)顯示。
}
String taskName = "taskconfig/" + nodeName+".task";//任務(wù)對應(yīng)的文件路徑。
System.out.println( taskName );
Command cmd;
TaskProperties props = new TaskProperties();
props.open( taskName );//打開任務(wù)對應(yīng)文件。
String str = props.getProperty( "Nested" );//判斷任務(wù)中是否包含子任務(wù)。if bComp=true則包含子任務(wù),否則不包含子任務(wù)。
boolean bComp=false;
if( str==null )
bComp = false;
else
if( str.equalsIgnoreCase("true") || str.equals("") )
bComp = true;
else
bComp = false;
boolean bWithXml;
str = MainConfig.getInstance().getProperty( "GuiWithXml" );
//判斷是否把數(shù)據(jù)保存在xml中。
if( str==null || str.equals("") )
bWithXml = false;
if( str.equalsIgnoreCase("true") )
bWithXml = true;
else
bWithXml = false;
if( !bComp )
{
System.out.println( "will create raw command "+taskName );
cmd = new RawCommand( taskName, true, bWithXml );//把任務(wù)封裝成RawCommand對象
}else
{
System.out.println( "will create composite command "+taskName );
cmd = new CompositeCommand( taskName, true, bWithXml );//如果此任務(wù)包含子任務(wù),則把任務(wù)封裝為CompositeCommand對象。
}
ThreadPool.getInstance().execute( new Spider(cmd) );//啟動采集已經(jīng)封裝的任務(wù)。
// ( new Spider( cmd ) ).start();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -