1   package main;
2   
3   import intellego.Intellego;
4   import util.*;
5   import interfaces.*;
6   import real.*;
7   
8   import java.awt.*;
9   import java.lang.*;
10  import java.awt.event.*;
11  import javax.swing.*;
12  import java.io.*;
13  
14  /**
15  * The main GUI.
16  *
17  * @author Graham Ritchie
18  */
19  public class MainInterface extends JFrame
20  {
21      private static JDesktopPane mainPane; // the main desktop pane
22      
23      /**
24      * Sets up the JDesktopPane
25      */
26      public MainInterface()
27      {
28          super("Intellego");
29  
30          // Make the main window indented 50 pixels from each edge of the screen.
31          int inset = 50;
32          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
33          setBounds(inset, inset, screenSize.width - inset*2, screenSize.height-inset*2);
34          
35          // Quit the whole program when the main window closes.
36          addWindowListener(new WindowAdapter() 
37          {
38              public void windowClosing(WindowEvent e) 
39              {
40                  Intellego.addToLog("MainInterface.init(): System quitting");
41                  System.exit(0);
42              }
43          });
44          
45          // set up the main pane
46          mainPane=new JDesktopPane();
47          
48          setContentPane(mainPane);
49          setJMenuBar(createMenuBar());
50      }
51      
52      /**
53      * Creates a new code editor window
54      */
55      public static void createCodeEditorFrame() 
56      {
57          CodeEditor frame = new CodeEditor();
58          frame.setVisible(true);
59          mainPane.add(frame);
60          try 
61          {
62              frame.setSelected(true);
63          }
64          catch (Exception e) 
65          {
66              Intellego.addToLog("MainInterface.createFrame(): Failed to create internal code editor frame properly: "+e);
67          }
68      }
69      
70      /**
71      * Creates a new simulator window
72      */
73      public static void createSimulatorFrame() 
74      {
75          SimUI frame = new SimUI();
76          frame.setVisible(true);
77          mainPane.add(frame);
78          try 
79          {
80              frame.setSelected(true);
81          }
82          catch (Exception e) 
83          {
84              Intellego.addToLog("MainInterface.createFrame(): Failed to create internal simulator frame properly: "+e);
85          }
86      }
87      
88      /**
89      * Creates a new simulator window with the specified controller preloaded
90      *
91      * @param className the name of the controller class to be preloaded
92      */
93      public static void createSimulatorFrame(String className) 
94      {
95          SimUI frame = new SimUI(className);
96          frame.setVisible(true);
97          mainPane.add(frame);
98          try 
99          {
100             frame.setSelected(true);
101         }
102         catch (Exception e) 
103         {
104             Intellego.addToLog("MainInterface.createFrame(): Failed to create internal simulator frame properly: "+e);
105         }
106     }
107     
108     /**
109     * Creates a new window to display messages from external processes
110     *
111     * @return the ExternalMessager frame
112     */
113     public static ExternalMessager createExternalMessagerFrame() 
114     {
115         ExternalMessager frame = new ExternalMessager();
116         frame.setVisible(true);
117         mainPane.add(frame);
118         try 
119         {
120             frame.setSelected(true);
121         }
122         catch (Exception e) 
123         {
124             Intellego.addToLog("MainInterface.createFrame(): Failed to create internal frame properly: "+e);
125         }
126         return frame;
127     }
128     
129     /**
130     * Creates the menu bar for the main desktop pane
131     *
132     * @return the menu bar
133     */
134     private JMenuBar createMenuBar() 
135     {
136         JMenuBar menuBar = new JMenuBar();
137 
138         JMenu toolsMenu = new JMenu("Tools");
139         JMenuItem codeEditor = new JMenuItem("Code Editor");
140         JMenuItem simulator = new JMenuItem("Simulator");
141         
142         codeEditor.addActionListener(new ActionListener() 
143         {
144             public void actionPerformed(ActionEvent e) 
145             {
146                 createCodeEditorFrame();
147             }
148         });
149         
150         simulator.addActionListener(new ActionListener() 
151         {
152             public void actionPerformed(ActionEvent e) 
153             {
154                 createSimulatorFrame();
155             }
156         });
157         
158         toolsMenu.add(codeEditor);
159         toolsMenu.add(simulator);
160         
161         menuBar.add(toolsMenu);
162 
163         return menuBar;
164     }
165     
166     /**
167     * Displays messages to the user in a dialog box
168     *
169     * @param message the message to be displayed to the user
170     */
171     public static void displayMessage(String message)
172     {
173         // pop up a dialog box with the message
174         IntellegoDialog dialog=new IntellegoDialog(message);
175     }
176 }
177