1 package main;
2
3 import intellego.Intellego;
4 import util.*;
5 import interfaces.*;
6 import real.*;
7 import NetBeansResources.*;
8
9 import java.awt.*;
10 import java.lang.*;
11 import java.awt.event.*;
12 import javax.swing.*;
13 import java.io.*;
14 import javax.imageio.*;
15 import java.awt.image.*;
16
17
21 public class MainInterface extends JFrame
22 {
23
24 private static JDesktopPane mainPane;
25
26 private static SimUI frame = null;
27
28 private HelpDialog helpDialog=null;
29
30 private About about = null;
31
34 public MainInterface()
35 {
36 super("Intellego 2.0");
37
38 int inset = 50;
40
41 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
42 setBounds(inset, inset, screenSize.width - inset*2, screenSize.height-inset*2);
43
44 try{
46 BufferedImage simIcon= ImageIO.read(new File("images\\lego.png"));
47 this.setIconImage(simIcon);
48 }
49 catch(Exception e){}
50
51 addWindowListener(new WindowAdapter()
53 {
54 public void windowClosing(WindowEvent e)
55 {
56 Intellego.addToLog("MainInterface.init(): System quitting");
57 System.exit(0);
58 }
59 });
60
61 mainPane=new JDesktopPane();
63
64 setContentPane(mainPane);
65 mainPane.setBackground(Color.darkGray);
66 setJMenuBar(createMenuBar());
67
68 this.setDefaultLookAndFeelDecorated(false);
69 this.setUndecorated(true);
70 this.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
71
72 }
73
74
77 public static void createCodeEditorFrame()
78 {
79
80 CodeEditor frame = new CodeEditor();
81 frame.setVisible(true);
82 mainPane.add(frame);
83
84 try
85 {
86 frame.setSelected(true);
87 }
88 catch (Exception e)
89 {
90 Intellego.addToLog("MainInterface.createFrame(): Failed to create internal code editor frame properly: "+e);
91 }
92 }
93
94
97 public void createSimulatorFrame()
98 {
99 if(frame == null || !frame.isVisible()){
100 frame = new SimUI();
101 frame.setVisible(true);
102 mainPane.add(frame);
103 try
104 {
105 frame.setSelected(true);
106 }
107 catch (Exception e)
108 {
109 Intellego.addToLog("MainInterface.createFrame(): Failed to create internal simulator frame properly: "+e);
110 }
111 }
112 else displayMessage("ERROR: more than one active SIMULATOR WINDOW | ONLY ONE is allowed");
113 }
114
115
118 public static void createSimulatorFrame(File file) {
120 if(frame == null || !frame.isShowing()){
123 frame = new SimUI(file);
124 frame.setVisible(true);
125 mainPane.add(frame);
126 try
127 {
128 frame.setSelected(true);
129 }
130 catch (Exception e)
131 {
132 Intellego.addToLog("MainInterface.createFrame(): Failed to create internal simulator frame properly: "+e);
133 }
134 }
135
136 else
139 {
140
141 frame.openCurrentController(file);
142
143
144
145 }
146 }
148
149
153 public static ExternalMessager createExternalMessagerFrame(int num)
154 {
155 ExternalMessager frame = new ExternalMessager(num);
156 frame.setVisible(true);
157 mainPane.add(frame);
158 try
159 {
160 frame.setSelected(true);
161 }
162 catch (Exception e)
163 {
164 Intellego.addToLog("MainInterface.createFrame(): Failed to create internal frame properly: "+e);
165 }
166 return frame;
167 }
168
169
174 private JMenuBar createMenuBar()
175 {
176 JMenuBar menuBar = new JMenuBar();
177 JMenu toolsMenu = new JMenu("Tools");
178 toolsMenu.setMnemonic(KeyEvent.VK_T);
179
180 JMenu help = new JMenu("Help");
181 help.setMnemonic(KeyEvent.VK_H);
182
183 JMenuItem codeEditor = new JMenuItem(" Code Editor",new ImageIcon("images/code.gif"));
184 codeEditor.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,ActionEvent.ALT_MASK));
185 JMenuItem simulator = new JMenuItem(" Simulator",new ImageIcon("images/execute.gif"));
186 simulator.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.ALT_MASK));
187
188 JMenuItem helpI = new JMenuItem(" Help",new ImageIcon("images/help.gif"));
189 helpI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1,0));
190 JMenuItem aboutI = new JMenuItem("About Intellego 2.0");
191
192 toolsMenu.setBackground(Color.darkGray);
194 toolsMenu.setForeground(Color.lightGray);
195 help.setBackground(Color.darkGray);
196 help.setForeground(Color.lightGray);
197 helpI.setBackground(Color.darkGray);
198 helpI.setForeground(Color.lightGray);
199 aboutI.setBackground(Color.darkGray);
200 aboutI.setForeground(Color.lightGray);
201 codeEditor.setBackground(Color.darkGray);
202 codeEditor.setForeground(Color.red.darker());
203 simulator.setBackground(Color.darkGray);
204 simulator.setForeground(Color.yellow);
205
206 helpI.addActionListener(new ActionListener()
207 {
208 public void actionPerformed(ActionEvent e)
209 {
210 if(helpDialog == null){
211 helpDialog = new HelpDialog();
213 }
214
215 else{
216 helpDialog.setVisible(true);
217 }
218 }
219 });
220 aboutI.addActionListener(new ActionListener()
221 {
222 public void actionPerformed(ActionEvent e)
223 {
224 if(about == null){
225 about = new About();
227 }
228
229 else{
230 about.setVisible(true);
231 }
232 }
233 });
234 codeEditor.addActionListener(new ActionListener()
235 {
236 public void actionPerformed(ActionEvent e)
237 {
238 createCodeEditorFrame();
239 }
240 });
241
242 simulator.addActionListener(new ActionListener()
243 {
244 public void actionPerformed(ActionEvent e)
245 {
246 createSimulatorFrame();
247 }
248 });
249
250 toolsMenu.add(codeEditor);
251 toolsMenu.addSeparator();
252 toolsMenu.add(simulator);
253
254 help.add(helpI);
255 help.addSeparator();
256 help.add(aboutI);
257
258 menuBar.setLayout(new AbsoluteLayout());
259 menuBar.setBackground(Color.DARK_GRAY);
260 menuBar.add(toolsMenu,new AbsoluteConstraints(3,0));
261 menuBar.add(help,new AbsoluteConstraints(50,0));
262
263 JButton sizeButton = new JButton("hi");
265 sizeButton.setSize(new Dimension(20,10));
266 sizeButton.setMargin(new Insets(0,0,0,0));
267 sizeButton.setVisible(false);
268 menuBar.add(sizeButton,new AbsoluteConstraints(263,0));
269
270 return menuBar;
271 }
272
273
278 public static void displayMessage(String message)
279 {
280 IntellegoDialog dialog=new IntellegoDialog(message);
282
283 }
284 }
285