00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import javax.swing.*;
00036 import java.awt.*;
00037 import java.awt.event.*;
00038
00039
00040 public class SenseGui extends JPanel implements ActionListener
00041 {
00042 static public java.util.Random global_rand = new java.util.Random();
00043 static public int FIELD_WIDTH = 800;
00044 static public int GetHeight(int width) {
00045 return width + (width / 4);
00046 }
00047
00048 public int width;
00049 public boolean in_browser;
00050 public Network topology;
00051 public SenseApplet app;
00052
00053 public TopologyPanel view_panel;
00054 public OptionMenu menu_options;
00055 public ControlPanel ctl_panel;
00056 public JTextField status_panel;
00057
00058
00059 public SenseGui(int w, SenseApplet a, JFrame frame, boolean b) {
00060 width = w;
00061 in_browser = b;
00062 app = a;
00063
00064 setBackground(Color.white);
00065 setLayout(new BorderLayout(0,0));
00066
00067 int pnl_width = width - 4;
00068 int ctl_ht = pnl_width / 3 - 4;
00069 view_panel = new TopologyPanel(this, pnl_width, pnl_width);
00070 ctl_panel = new ControlPanel(this, pnl_width, ctl_ht);
00071 status_panel = new JTextField("Connecting...");
00072 status_panel.setEditable(false);
00073 int ht = status_panel.getPreferredSize().height;
00074 status_panel.setPreferredSize(new Dimension(pnl_width, ht));
00075 status_panel.setOpaque(false);
00076
00077 add("North", view_panel);
00078 add("Center", ctl_panel);
00079
00080
00081 if (in_browser == false) {
00082 int height = width + GetHeight(width);
00083 setSize(width, height);
00084 center(frame);
00085 }
00086
00087 installMenus(app);
00088
00089 if (app.socket != null)
00090 status_panel.setText("Connected to CORBA server at " +
00091 app.socket.getInetAddress().getHostName());
00092 }
00093
00094
00095 public void center(JFrame f) {
00096 Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
00097 Dimension frame_size = this.getSize();
00098 if (frame_size.height > screen_size.height)
00099 frame_size.height = screen_size.height;
00100 if (frame_size.width > screen_size.width)
00101 frame_size.width = screen_size.width;
00102 f.setLocation((screen_size.width - frame_size.width) / 2,
00103 (screen_size.height - frame_size.height) / 2);
00104 }
00105
00106
00107 private void installMenus(JApplet app) {
00108 JMenuBar menubar = new JMenuBar();
00109 app.setJMenuBar(menubar);
00110
00111 menu_options = new OptionMenu("Options", this);
00112 menubar.add(menu_options);
00113 menu_options.addActionListener(this);
00114
00115 ConfigMenu menu_config = new ConfigMenu("Connection", this);
00116 menubar.add(menu_config);
00117 menu_config.addActionListener(this);
00118
00119 if (in_browser == false) {
00120 JMenuItem about_item = new JMenuItem("About...");
00121 about_item.addActionListener(this);
00122 JMenu menu_help = new JMenu("Help");
00123 menu_help.add(about_item);
00124 menubar.add(menu_help);
00125 }
00126 }
00127
00128
00129 public void actionPerformed(ActionEvent ae){
00130 String s = ae.getActionCommand();
00131
00132 if (s.equalsIgnoreCase("About...")) {
00133 System.out.println("About dialog");
00134
00135 } else {
00136 java.lang.Object arg = ae.getSource();
00137 if (arg instanceof ExtendedMenuItem)
00138 ((ExtendedMenuItem)arg).parent.handleAction(s);
00139 else if (arg instanceof ExtendedCheckBox)
00140 ((ExtendedCheckBox)arg).parent.handleAction(s);
00141 }
00142 }
00143
00144
00145 public void refreshTopology() {
00146 view_panel.clear();
00147
00148
00149 }
00150
00151
00152 public void zoom(int z) {
00153 view_panel.zoom(z);
00154 view_panel.repaint();
00155 }
00156
00157
00158 public void quit() {
00159
00160
00161
00162 System.exit(0);
00163 }
00164 }