📄 statisticstool.java
字号:
/*
* The contents of this file are subject to the BT "ZEUS" Open Source
* Licence (L77741), Version 1.0 (the "Licence"); you may not use this file
* except in compliance with the Licence. You may obtain a copy of the Licence
* from $ZEUS_INSTALL/licence.html or alternatively from
* http://www.labs.bt.com/projects/agents/zeus/licence.htm
*
* Except as stated in Clause 7 of the Licence, software distributed under the
* Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the Licence for the specific language governing rights and
* limitations under the Licence.
*
* The Original Code is within the package zeus.*.
* The Initial Developer of the Original Code is British Telecommunications
* public limited company, whose registered office is at 81 Newgate Street,
* London, EC1A 7AJ, England. Portions created by British Telecommunications
* public limited company are Copyright 1996-9. All Rights Reserved.
*
* THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
*/
package zeus.visualiser.statistics;
import java.io.File;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import zeus.util.*;
import zeus.concepts.*;
import zeus.gui.*;
import zeus.gui.help.*;
import zeus.actors.*;
import zeus.visualiser.VisualiserModel;
import zeus.visualiser.statistics.charts.*;
import zeus.visualiser.basic.*;
public class StatisticsTool extends VideoTool {
private static int count = 0;
static final int NIL = 0;
static final int BAT = 1;
static final int TVT = 2;
static final int TVA = 4;
static final int IAT = 8;
static final int MPG = 16;
static final int NEG = 32;
static final int GCS = 64;
static final int AEM = 128;
static final int AMS = 256;
static final int CRR = 512;
static final int GLT = 1024;
static final int TAL = 2048;
static final int PIE = 1;
static final int BAR = 2;
static final int LIN = 4;
static final int XYG = 8;
static final int TAB = 16;
static String[] STATS_MENU_ITEMS = {
"Breakdown of agent types",
"Traffic volume by type",
"Traffic volume by agent",
"Inter agent traffic volume",
"Messages per goal",
"Inter agent negotiation graphs",
"Goal completion status",
"Agent efficiency measure",
"Agent monetary statement",
"Plan/Resources ratio",
"Average goal lapse times",
"Task activity level"
};
protected StatisticsMenuBar menubar;
protected StatisticsToolBar statisticsToolBar;
protected EditableMultipleSelectionDialog message_dialog = null;
protected DoubleSelectionDialog neg_dialog = null;
protected NumberDialog as_dialog = null;
protected JScrollPane scrollpane;
protected DrawCanvas canvas;
private int chart_type = PIE;
private int statistics_type = NIL;
protected TrafficVolume offlineQueue;
protected TrafficVolume onlineQueue;
protected TrafficVolume msgQueue = null;
protected Grapher grapher = null;
protected MultipleSelectionDialog ms_dialog = null;
public StatisticsTool(AgentContext context, VisualiserModel model) {
super(context, model);
this.setTitle(context.whoami() + " - Statistics Tool:" + (count++));
this.setBackground(Color.lightGray);
ImageIcon icon = new ImageIcon(SystemProps.getProperty("gif.dir") +
File.separator + "visualiser" + File.separator + "stats-icon.gif");
setIconImage(icon.getImage());
offlineQueue = new TrafficVolume(context.OntologyDb());
onlineQueue = new TrafficVolume(context.OntologyDb());
getContentPane().setLayout(new BorderLayout());
canvas = new DrawCanvas();
canvas.setBackground(new Color(245,230,145));
scrollpane = new JScrollPane(canvas);
scrollpane.setPreferredSize(new Dimension(460,460));
scrollpane.setMaximumSize(new Dimension(1600, 1600));
canvas.setPreferredSize(new Dimension(1600,1600));
// Create the statistics tool bar
statisticsToolBar = new StatisticsToolBar();
// Create a panel for the tool bars
JPanel toolpane = new JPanel();
toolpane.setLayout(new GridLayout(1,2));
toolpane.add(statisticsToolBar);
toolpane.add(videoToolbar);
getContentPane().add("North",toolpane);
getContentPane().add("Center",scrollpane);
msgQueue = onlineQueue;
grapher = new Grapher();
// Create the frame's menu bar
menubar = new StatisticsMenuBar();
setJMenuBar(menubar);
this.pack();
this.setVisible(true);
/* initialisation sequence */
setMode(ONLINE);
}
public void Exit() {
if ( grapher != null )
grapher.terminate();
grapher = null;
super.Exit();
}
public Dimension getViewportSize() {
return scrollpane.getViewport().getExtentSize();
}
public void SaveGoalTraffic(boolean set) {
msgQueue.setUpdatingGoalTraffic(set);
}
public void ClearGoalTraffic() {
msgQueue.clearGoalTraffic();
}
public void StreamMessages(boolean mode) {
if ( !hubOK() ) return;
if ( !stopPlayback() ) return;
String[] agents = model.getAgents();
if ( message_dialog == null ) {
message_dialog = new EditableMultipleSelectionDialog(this,
"Select Agents", agents);
message_dialog.setLocationRelativeTo(this);
}
else {
Object[] chosen = message_dialog.getPriorSelection();
message_dialog.setListData(agents);
message_dialog.setSelection(chosen);
}
Object[] data = message_dialog.getSelection();
model.addAgents(Misc.stringArray(message_dialog.getListData()));
subscribe(mode,model.keys[VisualiserModel.MESSAGE_KEY],
Misc.stringArray(data),"log_message");
}
protected void setMode(int mode) {
if ( mode == ONLINE ) {
menubar.update(ONLINE);
videoToolbar.setStatus(false);
offlineQueue.clear();
msgQueue = onlineQueue;
}
else {
menubar.update(PLAYBACK);
videoToolbar.setStatus(true);
offlineQueue.clear();
msgQueue = offlineQueue;
}
}
protected void registerAgent(String name, String type) {
//onlineQueue.addAgent(name,type);
}
protected void registerListOfPlaybackAgents(Vector List) {
//offlineQueue.addAgents(List);
}
protected void visualiseVideoData(int dir, Performative msg) {
if ( state.mode == PLAYBACK && filterMsg(msg) )
offlineQueue.update(msg);
}
public void log_message(Performative msg) {
try {
Performative imsg = ZeusParser.performative(msg.getContent());
if ( filterMsg(imsg) )
onlineQueue.update(imsg);
// save to persistent db
record_item(imsg);
} catch(Exception e) {
}
}
public void AnimationSpeed() {
if ( !hubOK() ) return;
long speed = grapher.getSpeed();
if ( as_dialog == null ) {
as_dialog = new NumberDialog(this, "Set Animation Speed", "Enter speed:");
as_dialog.setLocationRelativeTo(this);
}
as_dialog.setValue(speed);
Long value = as_dialog.getValue();
if ( value != null )
grapher.setSpeed(value.longValue());
}
protected boolean statisticIsOneOf(int st) {
if ( statistics_type != NIL && ((statistics_type & st) == 0) ) {
JOptionPane.showMessageDialog(this, "Invalid chart type for current statistic");
return false;
}
return true;
}
public void RedrawGraph() {
if ( grapher != null )
grapher.drawChart();
}
public void DrawPieGraph() {
if ( !statisticIsOneOf(BAT|TVT) ) return;
chart_type = PIE;
if ( grapher != null )
grapher.drawChart();
}
public void DrawBarGraph() {
if ( !statisticIsOneOf(BAT|TVT|TVA|MPG) ) return;
chart_type = BAR;
if ( grapher != null )
grapher.drawChart();
}
public void DrawLineGraph() {
if ( !statisticIsOneOf(BAT|TVT|TVA|MPG) ) return;
chart_type = LIN;
if ( grapher != null )
grapher.drawChart();
}
public void DrawXYGraph() {
if ( !statisticIsOneOf(NEG) ) return;
chart_type = XYG;
if ( grapher != null )
grapher.drawChart();
}
public void DrawTabularGraph() {
if ( !statisticIsOneOf(IAT) ) return;
chart_type = TAB;
if ( grapher != null )
grapher.drawChart();
}
public void setStatisticsType(int type) {
if ( grapher == null ) return;
Object[] user_choice;
Object[] prior_goals;
String[] current_goals;
switch(type) {
case NIL: // None
break;
case BAT: // Breakdown of Agent Types
if ( (chart_type & (PIE|BAR|LIN)) == 0 )
chart_type = PIE;
statistics_type = type;
grapher.drawChart();
break;
case TVT: // Traffic Volume by Type
if ( (chart_type & (PIE|BAR|LIN)) == 0 )
chart_type = BAR;
statistics_type = type;
grapher.drawChart();
break;
case TVA: // Traffic Volume by Agent
if ( (chart_type & (BAR|LIN)) == 0 )
chart_type = BAR;
statistics_type = type;
grapher.drawChart();
break;
case IAT: // Inter Agent Traffic Volume
if ( (chart_type & (TAB)) == 0 )
chart_type = TAB;
statistics_type = type;
grapher.drawChart();
break;
case MPG: // Messages per Goal
current_goals = msgQueue.getCurrentGoals();
if ( current_goals.length == 0 ) {
JOptionPane.showMessageDialog(this,"No goals currently available");
menubar.setStatisticsType(statistics_type);
return;
}
if ( ms_dialog == null ) {
ms_dialog = new MultipleSelectionDialog(this,"Select Required Goals");
ms_dialog.setLocationRelativeTo(this);
}
prior_goals = ms_dialog.getPriorSelection();
ms_dialog.setListData(current_goals);
ms_dialog.setSelection(prior_goals);
user_choice = ms_dialog.getSelection();
if ( user_choice == null ) return;
if ( (chart_type & (BAR|LIN)) == 0 )
chart_type = BAR;
statistics_type = type;
grapher.setUserGoals(Misc.stringArray(user_choice));
grapher.drawChart();
break;
case NEG: // Inter-agent negotiation graph
current_goals = msgQueue.getCurrentGoals();
if ( current_goals.length == 0 ) {
JOptionPane.showMessageDialog(this,"No goals currently available");
menubar.setStatisticsType(statistics_type);
return;
}
Hashtable input = msgQueue.getNegotiationGoals();
if ( neg_dialog == null ) {
neg_dialog = new DoubleSelectionDialog(this,
"Goal & Negotiation Partners","Goal","Negotiation Partners");
neg_dialog.setLocationRelativeTo(this);
}
prior_goals = neg_dialog.getPriorSelection();
neg_dialog.setListData(input);
neg_dialog.setSelection(prior_goals[0],prior_goals[1]);
user_choice = neg_dialog.getSelection();
if ( user_choice == null ) return;
if ( (chart_type & XYG) == 0 )
chart_type = XYG;
statistics_type = type;
grapher.setUserGoals(Misc.stringArray(user_choice));
grapher.drawChart();
break;
case TAL: // Task Activity Level
case GCS: // Goal Completion Status
case AEM: // Agent Efficiency Measure
case AMS: // Agent Monetary Statement
case CRR: // Plan/Resources Ratio
case GLT: // Average Goal Lapse Times
statistics_type = type;
grapher.drawChart();
break;
default:
break;
}
}
public void Help() {
Point pt = getLocation();
HelpWindow helpWin = new HelpWindow(this, pt, "visualiser", "Statistics Tool");
helpWin.setSize(new Dimension(getWidth(),440));
helpWin.setLocation(pt.x+24, pt.y+24);
helpWin.validate();
}
class StatisticsMenuBar extends JMenuBar
implements ActionListener,
ItemListener {
protected static final int CHECKITEM = 0;
protected static final int PLAINITEM = 1;
protected static final int RADIOITEM = 2;
protected JMenu fileMenu, onLineMenu, replayMenu;
protected JMenu optionsMenu, viewMenu, helpMenu;
protected JMenu animationMenu;
protected JMenu doMenu;
protected JMenuItem sessions, load, save, close, forward, rewind,
fforward, frewind, stop, forward_step, rewind_step,
forward_last, rewind_first, delete, purge;
protected JMenuItem connect, disconnect, exit;
protected JMenuItem cc, un_cc;
protected JMenuItem filter, animation_speed, player_speed, clear_goal;
protected JMenuItem redraw, line, bar, pie, xy, table;
protected JMenuItem help, about;
protected JCheckBoxMenuItem save_goal;
protected JRadioButtonMenuItem[] statsRadioBox;
public StatisticsMenuBar() {
super();
add(fileMenu());
add(onlineMenu());
add(playbackMenu());
add(optionsMenu());
add(doMenu());
add(viewMenu());
add(helpMenu());
}
private JMenu fileMenu() {
JMenu menu = new JMenu("File");
menu.setMnemonic('F');
connect = createMenuItem(menu,PLAINITEM,"Connect to namservers", 'C');
disconnect=createMenuItem(menu,PLAINITEM,"Disconnect from nameservers",'D');
exit = createMenuItem(menu, PLAINITEM, "Quit", 'Q');
return menu;
}
private JMenu onlineMenu() {
JMenu menu = new JMenu("Online");
menu.setMnemonic('O');
cc = createMenuItem(menu, PLAINITEM, "Request messages...", 'R');
un_cc = createMenuItem(menu, PLAINITEM, "Unrequest messages...", 'U');
return menu;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -