📄 statisticstool.java
字号:
private JMenu playbackMenu() {
JMenu menu = new JMenu("Playback");
menu.setMnemonic('P');
sessions = createMenuItem(menu, PLAINITEM, "Request saved sessions", 0);
delete = createMenuItem(menu, PLAINITEM, "Delete session", 0);
purge = createMenuItem(menu, PLAINITEM, "Purge database", 0);
menu.addSeparator();
load = createMenuItem(menu, PLAINITEM, "Load session", 0);
save = createMenuItem(menu, PLAINITEM, "Save session", 0);
close = createMenuItem(menu, PLAINITEM, "Close session", 0);
menu.addSeparator();
forward = createMenuItem(menu, PLAINITEM, "Forward", 0);
rewind = createMenuItem(menu, PLAINITEM, "Rewind", 0);
fforward = createMenuItem(menu, PLAINITEM, "Fast forward", 0);
frewind = createMenuItem(menu, PLAINITEM, "Fast rewind", 0);
forward_step = createMenuItem(menu, PLAINITEM, "Step forward", 0);
rewind_step = createMenuItem(menu, PLAINITEM, "Step backward", 0);
forward_last = createMenuItem(menu, PLAINITEM, "Forward to end", 0);
rewind_first = createMenuItem(menu, PLAINITEM, "Rewind to beginning", 0);
stop = createMenuItem(menu, PLAINITEM, "Stop", 0);
return menu;
}
private JMenu optionsMenu() {
JMenu menu = new JMenu("Options");
menu.setMnemonic('O');
filter = createMenuItem(menu, PLAINITEM, "Filter messages...", 0);
player_speed = createMenuItem(menu, PLAINITEM, "Player speed...", 0);
animation_speed = createMenuItem(menu, PLAINITEM, "Animation speed...", 0);
save_goal = (JCheckBoxMenuItem) createMenuItem(menu, CHECKITEM, "Save goal traffic data", 0);
clear_goal = createMenuItem(menu, PLAINITEM, "Clear goal traffic data", 0);
save_goal.setState(StatisticsTool.this.msgQueue.isUpdatingGoalTraffic());
return menu;
}
private JMenu doMenu() {
JMenu menu = new JMenu("Statistics");
ButtonGroup group = new ButtonGroup();
menu.setMnemonic('S');
statsRadioBox = new JRadioButtonMenuItem[STATS_MENU_ITEMS.length];
for(int i= 0; i < STATS_MENU_ITEMS.length; i++) {
statsRadioBox[i] = new JRadioButtonMenuItem(STATS_MENU_ITEMS[i]);
statsRadioBox[i].addActionListener(this);
if ( i >= 6 ) statsRadioBox[i].setEnabled(false);
menu.add(statsRadioBox[i]);
group.add(statsRadioBox[i]);
}
return menu;
}
private JMenu viewMenu() {
JMenu menu = new JMenu("View");
menu.setMnemonic('V');
redraw = createMenuItem(menu, PLAINITEM, "Redraw current", 'R');
pie = createMenuItem(menu, PLAINITEM, "Pie chart", 'P');
line = createMenuItem(menu, PLAINITEM, "Line graph", 0);
xy = createMenuItem(menu, PLAINITEM, "XY graph", 'X');
table = createMenuItem(menu, PLAINITEM, "Table", 'T');
bar = createMenuItem(menu, PLAINITEM, "Bar chart", 'B');
return menu;
}
private JMenu helpMenu() {
JMenu menu = new JMenu("Help");
menu.setMnemonic('H');
help = createMenuItem(menu, PLAINITEM, "Using the statistics tool", 'U');
about = createMenuItem(menu, PLAINITEM, "About ZEUS...", 'A');
return menu;
}
private JMenuItem createMenuItem(JMenu menu, int type, String text, int accelKey) {
JMenuItem item;
switch(type) {
case CHECKITEM:
item = new JCheckBoxMenuItem(text);
((JCheckBoxMenuItem) item).setState(false);
item.addItemListener(this);
break;
case RADIOITEM:
item = new JRadioButtonMenuItem(text,false);
item.addActionListener(this);
default:
item = new JMenuItem(text);
item.addActionListener(this);
break;
}
if (accelKey > 0)
item.setMnemonic(accelKey);
menu.add(item);
return item;
}
public void actionPerformed(ActionEvent event) {
Object src = event.getSource();
if ( src == connect ) Connect(true);
if ( src == disconnect ) Connect(false);
else if ( src == exit ) Exit();
else if ( src == cc) StreamMessages(true);
else if ( src == un_cc ) StreamMessages(false);
else if ( src == sessions) Sessions();
else if ( src == delete) Delete();
else if ( src == purge) Purge();
else if ( src == load) Load();
else if ( src == save ) Record();
else if ( src == close ) Close();
else if ( src == forward ) Forward();
else if ( src == rewind ) Rewind();
else if ( src == fforward ) FForward();
else if ( src == frewind ) FRewind();
else if ( src == stop ) Stop();
else if ( src == forward_step ) StepForward();
else if ( src == forward_last ) ForwardEnd();
else if ( src == rewind_step ) StepRewind();
else if ( src == rewind_first ) RewindBegin();
else if ( src == clear_goal ) ClearGoalTraffic();
else if ( src == filter ) Filter();
else if ( src == player_speed ) PlayerSpeed();
else if ( src == animation_speed) AnimationSpeed();
else if ( src == redraw ) RedrawGraph();
else if ( src == xy ) DrawXYGraph();
else if ( src == table ) DrawTabularGraph();
else if ( src == line ) DrawLineGraph();
else if ( src == pie ) DrawPieGraph();
else if ( src == bar ) DrawBarGraph();
else if (src == help) Help();
else if (src == about) About();
else
for(int i = 0; i < STATS_MENU_ITEMS.length; i++ )
if ( statsRadioBox[i] == src )
StatisticsTool.this.setStatisticsType((int)(Math.pow(2,(double)i) +0.51));
}
public void itemStateChanged(ItemEvent event) {
Object src = event.getSource();
if ( src == save_goal ) {
boolean v = save_goal.getState();
SaveGoalTraffic(v);
return;
}
}
public void setStatisticsType(int type) {
if ( type == 0 ) {
for(int j = 0; j < STATS_MENU_ITEMS.length; j++ )
statsRadioBox[j].setSelected(false);
return;
}
int n = (int)(Math.log((double)type)/Math.log(2) + 0.51);
statsRadioBox[n].setSelected(true);
}
public void update(int mode) {
boolean b = mode == StatisticsTool.this.PLAYBACK;
cc.setEnabled(!b);
forward.setEnabled(b);
rewind.setEnabled(b);
fforward.setEnabled(b);
frewind.setEnabled(b);
stop.setEnabled(b);
forward_step.setEnabled(b);
rewind_step.setEnabled(b);
forward_last.setEnabled(b);
rewind_first.setEnabled(b);
}
}
protected class StatisticsToolBar extends JToolBar implements ActionListener {
protected JButton barBtn, pieBtn, lineBtn, xyBtn, tabularBtn;
public StatisticsToolBar() {
setFloatable(false);
String path = SystemProps.getProperty("gif.dir") + File.separator +
"visualiser" + File.separator;
addSeparator();
// Bar Button
barBtn = new JButton(new ImageIcon(path + "bar.gif"));
add(barBtn);
barBtn.setPreferredSize(new Dimension(24,24));
barBtn.setToolTipText("Show as Bar Chart");
barBtn.setMargin(new Insets(0,0,0,0));
addSeparator();
// Pie Button
pieBtn = new JButton(new ImageIcon(path + "pie.gif"));
add(pieBtn);
pieBtn.setPreferredSize(new Dimension(24,24));
pieBtn.setToolTipText("Show as Pie Chart");
pieBtn.setMargin(new Insets(0,0,0,0));
addSeparator();
// Line Button
lineBtn = new JButton(new ImageIcon(path + "line.gif"));
add(lineBtn);
lineBtn.setPreferredSize(new Dimension(24,24));
lineBtn.setToolTipText("Show as Line Chart");
lineBtn.setMargin(new Insets(0,0,0,0));
addSeparator();
// XY Button
xyBtn = new JButton(new ImageIcon(path + "xy.gif"));
add(xyBtn);
xyBtn.setPreferredSize(new Dimension(24,24));
xyBtn.setToolTipText("Show as XY Chart");
xyBtn.setMargin(new Insets(0,0,0,0));
addSeparator();
// Tabluar Button
tabularBtn = new JButton(new ImageIcon(path + "table.gif"));
add(tabularBtn);
tabularBtn.setPreferredSize(new Dimension(24,24));
tabularBtn.setToolTipText("Show as Tabular Chart");
tabularBtn.setMargin(new Insets(0,0,0,0));
addSeparator();
setPreferredSize(new Dimension(300,32));
barBtn.addActionListener(this);
pieBtn.addActionListener(this);
lineBtn.addActionListener(this);
xyBtn.addActionListener(this);
tabularBtn.addActionListener(this);
}
public void actionPerformed(ActionEvent evt) {
Object src = evt.getSource();
if ( src == xyBtn ) DrawXYGraph();
else if ( src == tabularBtn ) DrawTabularGraph();
else if ( src == barBtn ) DrawBarGraph();
else if ( src == pieBtn ) DrawPieGraph();
else if ( src == lineBtn ) DrawLineGraph();
}
}
class Grapher extends Thread {
protected long speed = 3000;
protected boolean running = true;
protected PieChart pie = new PieChart();
protected Histogram bar = new Histogram();
protected LineGraph line = new LineGraph();
protected XYGraph xy = new XYGraph();
protected TabularGraph tabular = new TabularGraph();
protected String[] user_goals;
public String[] AGENT_TYPES = {
SystemProps.getProperty("agent.names.nameserver"),
SystemProps.getProperty("agent.names.facilitator"),
SystemProps.getProperty("agent.names.visualiser"),
SystemProps.getProperty("agent.names.dbProxy"),
SystemProps.getProperty("agent.names.agent")
};
public Grapher() {
this.setPriority(Thread.NORM_PRIORITY-3);
this.start();
}
public void setSpeed(long speed) {
this.speed = speed;
}
public long getSpeed() {
return speed;
}
public void run() {
long count = 0;
while( running ) {
synchronized(this) {
try {
while( !StatisticsTool.this.state.animating ||
chart_type == StatisticsTool.NIL ||
statistics_type == StatisticsTool.NIL )
wait(speed);
drawChart();
wait(speed);
}
catch(InterruptedException e) {
}
}
}
}
public void terminate() {
running = false;
}
public void wakeup() {
notifyAll();
}
public void setUserGoals(String[] goals) {
user_goals = goals;
}
public String[] getUserGoals() {
return user_goals;
}
public void drawChart() {
double[][] values = null;
double[][] x_values = null;
double[] data = null;
double[] x_data = null;
String[] labels = null;
String[] keys = null;
String title = null;
switch( statistics_type ) {
case StatisticsTool.NIL: // None
return;
case StatisticsTool.BAT:
title = "Breakdown of Agent Types";
labels = AGENT_TYPES;
data = new double[AGENT_TYPES.length];
String[] s;
for(int i = 0; i < data.length; i++ ) {
s = StatisticsTool.this.model.getAgents(AGENT_TYPES[i]);
data[i] = (s == null) ? 0.0 : s.length;
}
break;
case StatisticsTool.TVT:
title = "Traffic Volume: Distribution by Type";
labels = msgQueue.getDistributionByTypeLabels();
data = msgQueue.getDistributionByTypeData();
break;
case StatisticsTool.TVA:
title = "Traffic Volume: Distribution by Agent";
labels = msgQueue.getDistributionByAgentLabels();
values = msgQueue.getDistributionByAgentData();
keys = msgQueue.getDistributionByAgentKeys();
if ( values == null ) return;
break;
case StatisticsTool.IAT: // Inter-Agent Traffic Volume
title = "Inter-Agent Traffic Volume";
labels = msgQueue.getInterAgentTrafficLabels();
values = msgQueue.getInterAgentTrafficData();
if ( values == null ) return;
break;
case StatisticsTool.MPG: // Messages per Goal
title = "Traffic Volume for Selected Goals: Distribution by Agent";
labels = msgQueue.getDistributionByGoalLabels(user_goals);
values = msgQueue.getDistributionByGoalData(user_goals);
keys = msgQueue.getDistributionByGoalKeys();
if ( values == null ) return;
break;
case StatisticsTool.NEG: // Negotiation graphs
title = "Negotiation Graph for " + user_goals[1];
values = msgQueue.getDistributionByNegotiationDialogueData(user_goals);
x_values = msgQueue.getDistributionByNegotiationDialogueXData(user_goals);
keys = msgQueue.getDistributionByNegotiationDialogueKeys(user_goals);
if ( x_values == null ) return;
break;
case StatisticsTool.TAL: // Task Activity Level
case StatisticsTool.GCS: // Goal Completion Status
case StatisticsTool.AEM: // Agent Efficiency Measure
case StatisticsTool.AMS: // Agent Monetary Statement
case StatisticsTool.CRR: // Plan/Resources Ratio
case StatisticsTool.GLT: // Average Goal Lapse Times
return;
default:
return;
}
Dimension d;
switch( chart_type ) {
case StatisticsTool.NIL:
return;
case StatisticsTool.PIE:
pie.setData(data,labels,title);
d = getViewportSize();
pie.setXY(d.width,d.height);
canvas.setDrawType(pie);
canvas.repaint();
return;
case StatisticsTool.BAR:
if ( keys != null )
bar.setData(values,labels,keys,title);
else
bar.setData(data,labels,title);
d = getViewportSize();
bar.setXY(d.width,d.height);
canvas.setDrawType(bar);
canvas.repaint();
return;
case StatisticsTool.LIN:
if ( keys != null )
line.setData(values,labels,keys,title);
else
line.setData(data,labels,title);
d = getViewportSize();
line.setXY(d.width,d.height);
canvas.setDrawType(line);
canvas.repaint();
return;
case StatisticsTool.TAB:
tabular.setData(values,labels,title);
d = getViewportSize();
tabular.setXY(d.width,d.height);
canvas.setDrawType(tabular);
canvas.repaint();
return;
case StatisticsTool.XYG:
if ( keys != null )
xy.setData(values,x_values,keys,title);
else
xy.setData(data,x_data,title);
d = getViewportSize();
xy.setXY(d.width,d.height);
canvas.setDrawType(xy);
canvas.repaint();
return;
default:
return;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -