View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  
23  
24  /********************************************************************
25   *          ZEUS Visualiser Hub Swing Implementation               *
26   *******************************************************************/
27  
28  package zeus.visualiser;
29  
30  import javax.swing.*;
31  import java.awt.*;
32  import java.awt.event.*;
33  import java.util.*;
34  import java.io.*;
35  
36  import zeus.util.*;
37  import zeus.concepts.*;
38  import zeus.gui.*;
39  import zeus.gui.help.*;
40  import zeus.actors.*;
41  
42  import zeus.visualiser.basic.BasicTool;
43  import zeus.visualiser.report.ReportTool;
44  import zeus.visualiser.control.ControlTool;
45  import zeus.visualiser.statistics.StatisticsTool;
46  import zeus.visualiser.society.SocietyTool;
47  
48  
49  public class VisualiserHub extends JFrame {
50      protected AgentContext    context = null;
51      protected VisualiserModel model   = null;
52      public    boolean         quick   = false;
53      protected HelpWindow      helpWin = null;
54  
55      private static final String disclaimer =
56          "This software was produced as a part of research\n" +
57          "activities. It is not intended to be used as commercial\n" +
58          "or industrial software by any organisation. Except as\n" +
59          "explicitly stated, no guarantees are given as to its\n" +
60          "reliability or trustworthiness if used for purposes other\n" +
61          "than those for which it was originally intended.\n \n" +
62          "(c) British Telecommunications plc 1996-9.";
63  
64      protected String path = SystemProps.getProperty("gif.dir") +
65         File.separator + "visualiser" + File.separator;
66  
67      protected Icon headerIcon = new ImageIcon(path + "header.gif");
68      protected Icon societyIcon = new ImageIcon(path + "society.gif");
69      protected Icon reportIcon = new ImageIcon(path + "report.gif");
70      protected Icon infoIcon = new ImageIcon(path + "info.gif");
71      protected Icon controlIcon = new ImageIcon(path + "control.gif");
72      protected Icon statsIcon = new ImageIcon(path + "stats.gif");
73      protected Icon helpIcon = new ImageIcon(path + "help.gif");
74  
75  
76      public VisualiserHub(AgentContext context, boolean quick) {
77        super(context.whoami());
78  
79        this.context = context;
80        this.model = new VisualiserModel(context);
81        this.quick = quick;
82  
83        Address a;
84        for(int i = 0; i < context.nameservers().size(); i++ ) {
85           a = (Address)context.nameservers().elementAt(i);
86           model.addNameserver(a.getName());
87        }
88  
89        ImageIcon icon = new ImageIcon(path + "visicon.gif");
90        setIconImage(icon.getImage());
91  
92        getContentPane().add(makeToolbar());
93        pack();
94        setResizable(false);
95        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
96  
97        addWindowListener(new WindowAdapter() {
98           public void windowClosing(WindowEvent e) {
99              int result = JOptionPane.showConfirmDialog(VisualiserHub.this,
100                "Exit Visualiser?", "Exit", JOptionPane.YES_NO_OPTION);
101             if ( result == JOptionPane.YES_OPTION )
102 	       System.exit(0);
103          }
104       });
105       setVisible(true);
106     }
107 
108     private void quickConnection(BasicTool tool) {
109        if ( quick ) {
110           quick = false;
111           tool.quickConnect();
112        }
113     }
114 
115     private JPanel makeToolbar()  {
116         JPanel toolbar = new JPanel();
117         toolbar.setBorder(BorderFactory.createEtchedBorder());
118         toolbar.setLayout(new GridLayout(7,1));
119 
120         JButton aboutBtn = new JButton(headerIcon);
121         aboutBtn.setToolTipText("Information");
122         aboutBtn.setMargin(new Insets(0,0,0,0));
123         aboutBtn.addActionListener(new ActionListener() {
124             public void actionPerformed(ActionEvent e) {
125                 JOptionPane.showMessageDialog(VisualiserHub.this, disclaimer);
126             }
127         });
128 
129         JButton societyBtn = new JButton(societyIcon);
130         societyBtn.setToolTipText("View Agent Society");
131         societyBtn.setMargin(new Insets(0,0,0,0));
132         societyBtn.addActionListener(new ActionListener() {
133             public void actionPerformed(ActionEvent e) {
134               SocietyTool tool = new SocietyTool(context,model);
135               quickConnection(tool);
136               Point pt = getLocation();
137               tool.setLocation(pt.x+getWidth(), pt.y);
138             }
139         });
140 
141         JButton reportBtn = new JButton(reportIcon);
142         reportBtn.setToolTipText("View Agent Reports");
143         reportBtn.setMargin(new Insets(0,0,0,0));
144         reportBtn.addActionListener(new ActionListener() {
145             public void actionPerformed(ActionEvent e) {
146               ReportTool tool = new ReportTool(context,model);
147               quickConnection(tool);
148               Point pt = getLocation();
149               tool.setLocation(pt.x+getWidth(), pt.y);
150             }
151         });
152 
153         JButton statsBtn = new JButton(statsIcon);
154         statsBtn.setToolTipText("View Agent Statistics");
155         statsBtn.setMargin(new Insets(0,0,0,0));
156         statsBtn.addActionListener(new ActionListener() {
157             public void actionPerformed(ActionEvent e) {
158               StatisticsTool tool = new StatisticsTool(context,model);
159               quickConnection(tool);
160               Point pt = getLocation();
161               tool.setLocation(pt.x+getWidth(), pt.y);
162             }
163         });
164 
165         JButton remoteBtn = new JButton(infoIcon);
166         remoteBtn.setToolTipText("Remote Agent Viewer");
167         remoteBtn.setMargin(new Insets(0,0,0,0));
168         remoteBtn.setEnabled(false);
169         remoteBtn.addActionListener(new ActionListener() {
170             public void actionPerformed(ActionEvent e) {
171             }
172         });
173 
174         JButton controlBtn = new JButton(controlIcon);
175         controlBtn.setToolTipText("Launch Control Tool");
176         controlBtn.setMargin(new Insets(0,0,0,0));
177         //controlBtn.setEnabled(false);
178         controlBtn.addActionListener(new ActionListener() {
179           public void actionPerformed(ActionEvent e) {
180               ControlTool tool = new ControlTool(context,model);
181               quickConnection(tool);
182               Point pt = getLocation();
183               tool.setLocation(pt.x+getWidth(), pt.y);
184             }
185         });
186 
187         final JToggleButton helpBtn = new JToggleButton(helpIcon);
188         helpBtn.setToolTipText("Help");
189         helpBtn.setMargin(new Insets(0,0,0,0));
190         helpBtn.addActionListener(new ActionListener() {
191             public void actionPerformed(ActionEvent e) {
192               Point pt = getLocation();
193               JToggleButton button = (JToggleButton)e.getSource();
194               if ( button.isSelected() ) {
195                  helpWin = new HelpWindow(VisualiserHub.this, pt,
196                     "visualiser", "Visualiser Hub");
197                  helpWin.setSource(button);
198               }
199               else
200                 helpWin.dispose();
201             }
202         });
203 
204         toolbar.add(aboutBtn);
205         toolbar.add(societyBtn);
206         toolbar.add(reportBtn);
207         toolbar.add(statsBtn);
208         toolbar.add(remoteBtn);
209         toolbar.add(controlBtn);
210         toolbar.add(helpBtn);
211 
212         return toolbar;
213     }
214 }