1 2 25 26 package org.aspectj.tools.ajbrowser; 27 28 import javax.swing.*; 29 import javax.swing.plaf.multi.MultiViewportUI ; 30 import javax.swing.tree.*; 31 import javax.swing.event.*; 32 import javax.swing.filechooser.FileFilter ; 33 import java.awt.*; 34 import java.io.*; 35 import javax.swing.border.*; 36 import java.awt.event.*; 37 import java.util.*; 38 import java.text.*; 39 import org.aspectj.ajde.*; 40 import org.aspectj.ajde.ui.*; 41 import org.aspectj.ajde.ui.swing.*; 42 import org.aspectj.asm.*; 43 44 49 public class TopFrame extends JFrame { 50 51 JLabel statusText_label = new JLabel(); 52 53 private JPanel editor_panel = null; 55 private JPanel sourceEditor_panel = null; 56 57 private JMenuBar menuBar = new JMenuBar(); 58 private JMenu jMenu1 = new JMenu(); 59 private JMenu jMenu2 = new JMenu(); 60 private JMenuItem projectBuild_menuItem = new JMenuItem(); 61 private FlowLayout left_flowLayout = new FlowLayout(); 62 private Border border1; 63 private Border border2; 64 private JMenuItem jMenuItem1 = new JMenuItem(); 65 private JMenuItem exit_menuItem = new JMenuItem(); 66 private JSplitPane top_splitPane = new JSplitPane(); 67 private BorderLayout borderLayout2 = new BorderLayout(); 68 private BorderLayout borderLayout1 = new BorderLayout(); 69 private BorderLayout borderLayout3 = new BorderLayout(); 70 private JMenuItem projectRun_menuItem = new JMenuItem(); 71 private Border border3; 72 private JPanel status_panel = new JPanel(); 73 private BorderLayout borderLayout4 = new BorderLayout(); 74 private Border emptyBorder = BorderFactory.createEmptyBorder(); 75 private JPanel toolbar_panel = new JPanel(); 76 private JSplitPane right_splitPane = new JSplitPane(); 77 private JPanel messages_panel = null; 78 private JMenu tools_menu = new JMenu(); 79 private JMenuItem joinpointProbe_menuItem = new JMenuItem(); 80 private JMenuItem projectDebug_menuItem = new JMenuItem(); 81 private Border border4; 82 private Border border5; 83 private Border border6; 84 private Border border7; 85 private JMenuItem svProperties_menuItem = new JMenuItem(); 86 JPanel toolBar_panel = new JPanel(); 87 JToolBar build_toolBar = new JToolBar(); 88 JButton closeConfig_button = new JButton(); 89 JButton openConfig_button = new JButton(); 90 JButton run_button = new JButton(); 91 JToolBar project_toolBar = new JToolBar(); 92 JButton save_button = new JButton(); 93 JButton options_button = new JButton(); 94 JButton editConfig_button = new JButton(); 95 JToolBar file_toolBar = new JToolBar(); 96 JPanel filler_panel = new JPanel(); 97 BorderLayout borderLayout5 = new BorderLayout(); 98 BorderLayout borderLayout6 = new BorderLayout(); 99 Border border8; 100 JLabel jLabel1 = new JLabel(); 101 JLabel jLabel2 = new JLabel(); 102 JPanel multiView_panel; 103 104 private AJButtonMenuCombo buildCombo; 105 109 119 public void init(MultiStructureViewPanel multiViewPanel, JPanel compilerMessagesPanel, JPanel editorPanel) { 120 try { 121 this.multiView_panel = multiViewPanel; 122 this.messages_panel = compilerMessagesPanel; 125 this.editor_panel = editorPanel; 126 this.sourceEditor_panel = editorPanel; 127 128 jbInit(); 129 svProperties_menuItem.setIcon(AjdeUIManager.getDefault().getIconRegistry().getBrowserOptionsIcon()); 130 projectBuild_menuItem.setIcon(AjdeUIManager.getDefault().getIconRegistry().getBuildIcon()); 131 projectRun_menuItem.setIcon(AjdeUIManager.getDefault().getIconRegistry().getExecuteIcon()); 132 projectDebug_menuItem.setIcon(AjdeUIManager.getDefault().getIconRegistry().getDebugIcon()); 133 134 this.setJMenuBar(menuBar); 135 this.setIconImage(((ImageIcon)AjdeUIManager.getDefault().getIconRegistry().getStructureSwingIcon(ProgramElementNode.Kind.ADVICE)).getImage()); 136 this.setLocation(75, 10); 137 this.setSize(900, 650); 138 this.setTitle(BrowserManager.TITLE); 139 bindKeys(); 140 fixButtonBorders(); 141 messages_panel.setVisible(false); 142 143 JPopupMenu orderMenu = new BuildConfigPopupMenu(new AbstractAction() { 144 public void actionPerformed(ActionEvent arg0) { 145 BrowserManager.getDefault().saveAll(); 146 } 147 }); 148 149 buildCombo = new AJButtonMenuCombo( 150 "Build", 151 "Build", 152 AjdeUIManager.getDefault().getIconRegistry().getBuildIcon(), 153 orderMenu, 154 false); 155 156 build_toolBar.add(buildCombo, 1); 157 refreshBuildMenu(); 158 } 159 catch(Exception e) { 160 e.printStackTrace(); 161 } 162 } 163 164 private void refreshBuildMenu() { 165 JPopupMenu orderMenu = new BuildConfigPopupMenu(new AbstractAction() { 166 public void actionPerformed(ActionEvent arg0) { 167 BrowserManager.getDefault().saveAll(); 168 } 169 }); 170 171 buildCombo.setMenu(orderMenu); 172 } 173 174 public void setEditorPanel(JPanel panel) { 175 editor_panel = panel; 176 right_splitPane.remove(editor_panel); 177 right_splitPane.add(panel, JSplitPane.TOP); 178 panel.setVisible(true); 179 } 180 181 184 private void fixButtonBorders() { 185 run_button.setBorder(null); 186 options_button.setBorder(null); 187 openConfig_button.setBorder(null); 188 closeConfig_button.setBorder(null); 189 save_button.setBorder(null); 190 editConfig_button.setBorder(null); 191 } 192 193 private void bindKeys() { 194 this.addKeyListener(new KeyAdapter() { 195 public void keyPressed(KeyEvent e) { 196 if (e.getModifiers() == java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) { 197 if (e.getKeyCode() == e.VK_F11) { 198 Ajde.getDefault().getBuildManager().build(); 199 } else if (e.getKeyCode() == e.VK_S) { 200 Ajde.getDefault().getEditorManager().saveContents(); 201 } else if (e.getKeyCode() == e.VK_P) { 202 AjdeUIManager.getDefault().showOptionsFrame(); 203 } 204 } 205 } 206 }); 207 } 208 209 private void jbInit() throws Exception { 210 border1 = BorderFactory.createBevelBorder(BevelBorder.LOWERED,Color.white,Color.white,new Color(148, 145, 140),new Color(103, 101, 98)); 211 border2 = BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)); 212 border3 = BorderFactory.createBevelBorder(BevelBorder.LOWERED,Color.white,Color.white,new Color(148, 145, 140),new Color(103, 101, 98)); 213 border4 = BorderFactory.createBevelBorder(BevelBorder.RAISED,Color.white,Color.white,new Color(148, 145, 140),new Color(103, 101, 98)); 214 border5 = BorderFactory.createEmptyBorder(); 215 border6 = BorderFactory.createEmptyBorder(); 216 border7 = BorderFactory.createBevelBorder(BevelBorder.RAISED,Color.white,Color.white,new Color(148, 145, 140),new Color(103, 101, 98)); 217 border8 = BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(Color.white,new Color(156, 156, 158)),BorderFactory.createEmptyBorder(2,2,2,2)); 218 emptyBorder = BorderFactory.createEmptyBorder(2,2,2,2); 219 jMenu1.setFont(new java.awt.Font ("Dialog", 0, 11)); 220 jMenu1.setText("File"); 221 jMenu2.setFont(new java.awt.Font ("Dialog", 0, 11)); 222 jMenu2.setText("Project"); 223 projectBuild_menuItem.setFont(new java.awt.Font ("Dialog", 0, 11)); 224 projectBuild_menuItem.setText("Build"); 225 projectBuild_menuItem.addActionListener(new java.awt.event.ActionListener () { 226 public void actionPerformed(ActionEvent e) { 227 projectBuild_menuItem_actionPerformed(e); 228 } 229 }); 230 left_flowLayout.setAlignment(FlowLayout.LEFT); 231 jMenuItem1.setFont(new java.awt.Font ("Dialog", 0, 11)); 232 jMenuItem1.setText("Save"); 233 jMenuItem1.addActionListener(new java.awt.event.ActionListener () { 234 public void actionPerformed(ActionEvent e) { 235 jMenuItem1_actionPerformed(e); 236 } 237 }); 238 exit_menuItem.setFont(new java.awt.Font ("Dialog", 0, 11)); 239 exit_menuItem.setText("Exit"); 240 exit_menuItem.addActionListener(new java.awt.event.ActionListener () { 241 public void actionPerformed(ActionEvent e) { 242 exit_menuItem_actionPerformed(e); 243 } 244 }); 245 top_splitPane.setPreferredSize(new Dimension(706, 800)); 246 top_splitPane.setDividerSize(4); 247 this.getContentPane().setLayout(borderLayout3); 248 projectRun_menuItem.setEnabled(true); 249 projectRun_menuItem.setFont(new java.awt.Font ("Dialog", 0, 11)); 250 projectRun_menuItem.setText("Run"); 251 projectRun_menuItem.addActionListener(new java.awt.event.ActionListener () { 252 public void actionPerformed(ActionEvent e) { 253 projectRun_menuItem_actionPerformed(e); 254 } 255 }); 256 statusText_label.setFont(new java.awt.Font ("Dialog", 0, 11)); 257 statusText_label.setBorder(BorderFactory.createLoweredBevelBorder()); 258 statusText_label.setMaximumSize(new Dimension(2000, 20)); 259 statusText_label.setPreferredSize(new Dimension(300, 20)); 260 status_panel.setLayout(borderLayout4); 261 this.addWindowListener(new java.awt.event.WindowAdapter () { 262 public void windowClosed(WindowEvent e) { 263 this_windowClosed(e); 264 } 265 public void windowClosing(WindowEvent e) { 266 this_windowClosing(e); 267 } 268 }); 269 toolbar_panel.setLayout(borderLayout5); 270 right_splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); 271 right_splitPane.setBorder(null); 272 right_splitPane.setDividerSize(4); 273 tools_menu.setFont(new java.awt.Font ("Dialog", 0, 11)); 274 tools_menu.setText("Tools"); 275 projectDebug_menuItem.setEnabled(false); 276 projectDebug_menuItem.setFont(new java.awt.Font ("Dialog", 0, 11)); 277 projectDebug_menuItem.setText("Debug"); 278 svProperties_menuItem.addActionListener(new java.awt.event.ActionListener () { 279 public void actionPerformed(ActionEvent e) { 280 svProperties_menuItem_actionPerformed(e); 281 } 282 }); 283 svProperties_menuItem.setText("Options..."); 284 svProperties_menuItem.setActionCommand("AJDE Console..."); 285 svProperties_menuItem.setFont(new java.awt.Font ("Dialog", 0, 11)); 286 build_toolBar.setBorder(emptyBorder); 287 build_toolBar.setFloatable(false); 288 closeConfig_button.setMaximumSize(new Dimension(100, 20)); 289 closeConfig_button.setEnabled(true); 290 closeConfig_button.setFont(new java.awt.Font ("Dialog", 0, 11)); 291 closeConfig_button.setBorder(null); 292 closeConfig_button.setMinimumSize(new Dimension(24, 20)); 293 closeConfig_button.setPreferredSize(new Dimension(20, 20)); 294 closeConfig_button.setToolTipText("Close build configuration"); 295 closeConfig_button.setIcon(AjdeUIManager.getDefault().getIconRegistry().getCloseConfigIcon()); 296 closeConfig_button.addActionListener(new java.awt.event.ActionListener () { 297 public void actionPerformed(ActionEvent e) { 298 closeConfig_button_actionPerformed(e); 299 } 300 }); 301 openConfig_button.setMaximumSize(new Dimension(100, 20)); 302 openConfig_button.setEnabled(true); 303 openConfig_button.setFont(new java.awt.Font ("Dialog", 0, 11)); 304 openConfig_button.setBorder(null); 305 openConfig_button.setMinimumSize(new Dimension(24, 20)); 306 openConfig_button.setPreferredSize(new Dimension(20, 20)); 307 openConfig_button.setToolTipText("Open build configuration..."); 308 openConfig_button.setIcon(AjdeUIManager.getDefault().getIconRegistry().getOpenConfigIcon()); 309 openConfig_button.addActionListener(new java.awt.event.ActionListener () { 310 public void actionPerformed(ActionEvent e) { 311 openConfig_button_actionPerformed(e); 312 } 313 }); 314 run_button.setMaximumSize(new Dimension(60, 20)); 315 run_button.setEnabled(true); 316 run_button.setFont(new java.awt.Font ("Dialog", 0, 11)); 317 run_button.setBorder(null); 318 run_button.setMinimumSize(new Dimension(24, 20)); 319 run_button.setPreferredSize(new Dimension(20, 20)); 320 run_button.setToolTipText("Run"); 321 run_button.setIcon(AjdeUIManager.getDefault().getIconRegistry().getExecuteIcon()); 322 run_button.addActionListener(new java.awt.event.ActionListener () { 323 public void actionPerformed(ActionEvent e) { 324 run_button_actionPerformed(e); 325 } 326 }); 327 project_toolBar.setBorder(emptyBorder); 328 save_button.addActionListener(new java.awt.event.ActionListener () { 329 public void actionPerformed(ActionEvent e) { 330 save_button_actionPerformed(e); 331 } 332 }); 333 save_button.setIcon(AjdeUIManager.getDefault().getIconRegistry().getSaveIcon()); 334 save_button.setText("Save"); 335 save_button.setToolTipText("Save"); 336 save_button.setPreferredSize(new Dimension(55, 20)); 337 save_button.setMinimumSize(new Dimension(24, 20)); 338 save_button.setFont(new java.awt.Font ("Dialog", 0, 11)); 339 save_button.setBorder(null); 340 save_button.setMaximumSize(new Dimension(60, 20)); 341 options_button.addActionListener(new java.awt.event.ActionListener () { 342 public void actionPerformed(ActionEvent e) { 343 options_button_actionPerformed(e); 344 } 345 }); 346 options_button.setIcon(AjdeUIManager.getDefault().getIconRegistry().getBrowserOptionsIcon()); 347 options_button.setText("Options"); 348 options_button.setToolTipText("Options..."); 349 options_button.setPreferredSize(new Dimension(60, 20)); 350 options_button.setMinimumSize(new Dimension(24, 20)); 351 options_button.setFont(new java.awt.Font ("Dialog", 0, 11)); 352 options_button.setBorder(null); 353 options_button.setMaximumSize(new Dimension(80, 20)); 354 editConfig_button.addActionListener(new java.awt.event.ActionListener () { 355 public void actionPerformed(ActionEvent e) { 356 editConfig_button_actionPerformed(e); 357 } 358 }); 359 editConfig_button.setIcon(AjdeUIManager.getDefault().getIconRegistry().getStructureSwingIcon(ProgramElementNode.Kind.FILE_LST)); 360 editConfig_button.setText("Edit Config"); 361 editConfig_button.setToolTipText("Edit Config..."); 362 editConfig_button.setPreferredSize(new Dimension(80, 20)); 363 editConfig_button.setMinimumSize(new Dimension(24, 20)); 364 editConfig_button.setFont(new java.awt.Font ("Dialog", 0, 11)); 365 editConfig_button.setBorder(null); 366 editConfig_button.setMaximumSize(new Dimension(80, 20)); 367 file_toolBar.setBorder(emptyBorder); 368 toolBar_panel.setLayout(borderLayout6); 369 jLabel1.setFont(new java.awt.Font ("Dialog", 0, 11)); 370 jLabel1.setText(" Build: "); 371 jLabel2.setText(" Run: "); 372 jLabel2.setFont(new java.awt.Font ("Dialog", 0, 11)); 373 this.getContentPane().add(top_splitPane, BorderLayout.CENTER); 376 top_splitPane.add(right_splitPane, JSplitPane.RIGHT); 377 top_splitPane.add(multiView_panel, JSplitPane.LEFT); 378 right_splitPane.add(messages_panel, JSplitPane.BOTTOM); 379 right_splitPane.add(editor_panel, JSplitPane.TOP); 380 this.getContentPane().add(status_panel, BorderLayout.SOUTH); 383 status_panel.add(statusText_label, BorderLayout.CENTER); 384 this.getContentPane().add(toolbar_panel, BorderLayout.NORTH); 385 toolbar_panel.add(filler_panel, BorderLayout.CENTER); 386 toolbar_panel.add(toolBar_panel, BorderLayout.WEST); 387 file_toolBar.add(save_button, null); 389 file_toolBar.add(options_button, null); 390 toolBar_panel.add(build_toolBar, BorderLayout.WEST); 391 toolBar_panel.add(project_toolBar, BorderLayout.CENTER); 392 project_toolBar.add(jLabel2, null); 393 project_toolBar.add(run_button, null); 394 build_toolBar.add(jLabel1, null); 395 build_toolBar.add(openConfig_button, null); 396 build_toolBar.add(closeConfig_button, null); 397 toolBar_panel.add(file_toolBar, BorderLayout.EAST); 398 menuBar.add(jMenu1); 399 menuBar.add(jMenu2); 400 menuBar.add(tools_menu); 401 jMenu1.add(jMenuItem1); 402 jMenu1.addSeparator(); 403 jMenu1.add(exit_menuItem); 404 jMenu2.add(projectBuild_menuItem); 405 jMenu2.add(projectRun_menuItem); 406 tools_menu.add(joinpointProbe_menuItem); 408 tools_menu.add(svProperties_menuItem); 409 top_splitPane.setDividerLocation(380); 410 right_splitPane.setDividerLocation(500); 411 project_toolBar.addSeparator(); 412 project_toolBar.addSeparator(); 413 } 414 415 private void exit_menuItem_actionPerformed(ActionEvent e) { 416 quit(); 417 } 418 419 private void this_windowClosing(WindowEvent e) { 420 quit(); 421 } 422 423 private void quit() { 424 this.dispose(); 425 System.exit(0); 426 } 427 428 429 void treeMode_comboBox_actionPerformed(ActionEvent e) { } 430 431 void save_button_actionPerformed(ActionEvent e) { 432 Ajde.getDefault().getEditorManager().saveContents(); 433 } 434 435 436 void this_windowClosed(WindowEvent e) { 437 quit(); 438 } 439 440 public void showMessagesPanel() { 441 right_splitPane.setDividerLocation(right_splitPane.getHeight()-100); 442 messages_panel.setVisible(true); 443 } 444 445 public void hideMessagesPanel() { 446 right_splitPane.setDividerLocation(right_splitPane.getHeight()); 447 messages_panel.setVisible(false); 448 } 449 450 451 void emacsTest_button_actionPerformed(ActionEvent e) { 452 } 454 455 void jMenuItem1_actionPerformed(ActionEvent e) { 456 Ajde.getDefault().getEditorManager().saveContents(); 457 } 458 459 void projectBuild_menuItem_actionPerformed(ActionEvent e) { 460 BrowserManager.getDefault().saveAll(); 461 Ajde.getDefault().getBuildManager().build(); 462 } 463 464 void run_button_actionPerformed(ActionEvent e) { 465 BrowserManager.getDefault().run(); 466 } 467 468 void projectRun_menuItem_actionPerformed(ActionEvent e) { 469 BrowserManager.getDefault().run(); 470 } 471 472 void build_button_actionPerformed(ActionEvent e) { 473 BrowserManager.getDefault().saveAll(); 474 Ajde.getDefault().getBuildManager().build(); 475 } 476 477 void options_button_actionPerformed(ActionEvent e) { 478 AjdeUIManager.getDefault().showOptionsFrame(); 479 } 480 481 void editConfig_button_actionPerformed(ActionEvent e) { 482 BrowserManager.getDefault().openFile(Ajde.getDefault().getConfigurationManager().getActiveConfigFile()); 484 refreshBuildMenu(); 485 } 486 487 public void resetSourceEditorPanel() { 488 right_splitPane.removeAll(); 489 right_splitPane.add(sourceEditor_panel, JSplitPane.TOP); 490 } 491 492 private void svProperties_menuItem_actionPerformed(ActionEvent e) { 493 AjdeUIManager.getDefault().showOptionsFrame(); 494 } 495 496 private void openConfig_button_actionPerformed(ActionEvent e) { 497 JFileChooser fileChooser = new JFileChooser(); 498 fileChooser.setFileFilter(new FileFilter () { 499 public boolean accept(File f) { 500 if (f.getPath().endsWith(".lst") || f.isDirectory()) { 501 return true; 502 } else { 503 return false; 504 } 505 } 506 public String getDescription() { 507 return "AspectJ Build Configuration (*.lst)"; 508 } 509 }); 510 int returnVal = fileChooser.showOpenDialog(this); 511 if(returnVal == JFileChooser.APPROVE_OPTION) { 512 String path = fileChooser.getSelectedFile().getAbsolutePath(); BrowserManager.getDefault().getConfigFiles().add(0, path); 514 Ajde.getDefault().getConfigurationManager().setActiveConfigFile(path); 515 refreshBuildMenu(); 516 } 517 } 518 519 private void closeConfig_button_actionPerformed(ActionEvent e) { 520 BrowserManager.getDefault().getConfigFiles().remove(Ajde.getDefault().getConfigurationManager().getActiveConfigFile()); 521 if (!BrowserManager.getDefault().getConfigFiles().isEmpty()) { 522 Ajde.getDefault().getConfigurationManager().setActiveConfigFile((String )BrowserManager.getDefault().getConfigFiles().get(0)); 523 } 524 refreshBuildMenu(); 525 } 526 } 527 | Popular Tags |