1 19 package org.netbeans.test.editor.app.gui; 20 21 import java.awt.Component ; 22 import java.awt.event.ComponentAdapter ; 23 import java.awt.event.ComponentEvent ; 24 import java.awt.event.WindowAdapter ; 25 import javax.swing.*; 26 import java.util.Vector ; 27 import java.io.File ; 28 import java.util.ArrayList ; 29 import javax.swing.filechooser.FileFilter ; 30 import javax.swing.tree.DefaultTreeModel ; 31 import org.netbeans.test.editor.app.Main; 32 33 import org.netbeans.test.editor.app.core.*; 34 import org.netbeans.test.editor.app.core.Test; 35 import org.netbeans.test.editor.app.gui.QuestionDialog; 36 import org.netbeans.test.editor.app.gui.tree.TestNodeDelegate; 37 import org.netbeans.test.editor.app.tests.GenerateTests; 38 import org.netbeans.test.editor.app.util.Scheduler; 39 40 49 50 public class TestEditorFrame extends javax.swing.JFrame { 51 52 private static String TITLE="Editor Test Application"; 53 54 private TestNodeDelegate root; 55 56 private Test test; 57 58 private TreeDialog tree=null; 59 60 File currentDirectory; 61 62 String oldpath,oldpackage; 63 64 65 66 public TestEditorFrame() { 67 initComponents(); 68 pack(); 69 this.setSize(800,500); 70 this.setLocation(300,100); 71 oldpath=""; 72 oldpackage=""; 73 currentDirectory=new File ("/nbcvs/nball/editor/test/qa-functional/src/org/netbeans/test/editor/app"); 75 } 76 77 public EventLoggingEditorPane getEditor() { 78 return (EventLoggingEditorPane)editor; 79 } 80 81 public void setTest(Test test) { 82 this.test=test; 83 root = (TestNodeDelegate)test.getNodeDelegate(); 84 if (tree != null) { 85 tree.setRootContext(root); 86 } 87 } 88 89 public void newRootWindow() { 90 if (tree == null) { 91 tree=new TreeDialog(this); 92 tree.setRootContext(root); 93 addComponentListener(new ComponentAdapter () { 94 public void componentMoved(ComponentEvent e) { 95 if (tree != null) { 96 tree.setLocation(getX()-tree.getWidth(), getY()); 97 } 98 } 99 100 public void componentResized(ComponentEvent e) { 101 if (tree != null) { 102 tree.setSize(tree.getWidth(),getHeight()); 103 tree.setLocation(getX()-tree.getWidth(), getY()); 104 } 105 } 106 }); 107 viewExplorerM.setEnabled(false); 108 tree.addWindowListener(new WindowAdapter () { 109 public void windowClosing(java.awt.event.WindowEvent evt) { 110 viewExplorerM.setEnabled(true); 111 tree=null; 112 } 113 }); 114 tree.show(); 115 } 116 } 117 118 public Test getTest() { 119 return test; 120 } 121 122 public TestNodeDelegate getRootNode() { 123 return root; 124 } 125 126 135 136 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 138 139 jPanel2 = new javax.swing.JPanel (); 140 jScrollPane3 = new javax.swing.JScrollPane (); 141 editor = new EventLoggingEditorPane(); 142 jPanel4 = new javax.swing.JPanel (); 143 historyScrollPane = new javax.swing.JScrollPane (); 144 history = new javax.swing.JTextArea (); 145 jMenuBar1 = new javax.swing.JMenuBar (); 146 jMenu1 = new javax.swing.JMenu (); 147 jMenuItem1 = new javax.swing.JMenuItem (); 148 jMenuItem2 = new javax.swing.JMenuItem (); 149 jMenuItem3 = new javax.swing.JMenuItem (); 150 jMenuItem4 = new javax.swing.JMenuItem (); 151 jSeparator1 = new javax.swing.JSeparator (); 152 jMenuItem5 = new javax.swing.JMenuItem (); 153 jMenu3 = new javax.swing.JMenu (); 154 jMenuItem6 = new javax.swing.JMenuItem (); 155 jSeparator2 = new javax.swing.JSeparator (); 156 jMenuItem7 = new javax.swing.JMenuItem (); 157 jMenu2 = new javax.swing.JMenu (); 158 viewExplorerM = new javax.swing.JMenuItem (); 159 160 getContentPane().setLayout(new java.awt.GridBagLayout ()); 161 162 setTitle("Editor Test Application"); 163 addWindowListener(new java.awt.event.WindowAdapter () { 164 public void windowClosing(java.awt.event.WindowEvent evt) { 165 TestEditorFrame.this.exitForm(evt); 166 } 167 }); 168 169 jPanel2.setLayout(new java.awt.BorderLayout ()); 170 171 jPanel2.setBorder(new javax.swing.border.TitledBorder ("Editor")); 172 jPanel2.setMinimumSize(new java.awt.Dimension (300, 200)); 173 jPanel2.setPreferredSize(new java.awt.Dimension (300, 200)); 174 jScrollPane3.setAutoscrolls(true); 175 editor.setMinimumSize(new java.awt.Dimension (200, 100)); 176 editor.setPreferredSize(new java.awt.Dimension (6, 23)); 177 jScrollPane3.setViewportView(editor); 178 179 jPanel2.add(jScrollPane3, java.awt.BorderLayout.CENTER); 180 181 gridBagConstraints = new java.awt.GridBagConstraints (); 182 gridBagConstraints.gridx = 1; 183 gridBagConstraints.gridy = 0; 184 gridBagConstraints.gridwidth = 3; 185 gridBagConstraints.gridheight = 3; 186 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 187 gridBagConstraints.weightx = 1.0; 188 gridBagConstraints.weighty = 1.0; 189 getContentPane().add(jPanel2, gridBagConstraints); 190 191 jPanel4.setLayout(new java.awt.BorderLayout ()); 192 193 jPanel4.setBorder(new javax.swing.border.TitledBorder ("History")); 194 jPanel4.setMinimumSize(new java.awt.Dimension (500, 75)); 195 jPanel4.setPreferredSize(new java.awt.Dimension (500, 75)); 196 historyScrollPane.setViewportView(history); 197 198 jPanel4.add(historyScrollPane, java.awt.BorderLayout.CENTER); 199 200 gridBagConstraints = new java.awt.GridBagConstraints (); 201 gridBagConstraints.gridx = 1; 202 gridBagConstraints.gridy = 3; 203 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 204 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 205 gridBagConstraints.weightx = 1.0; 206 gridBagConstraints.weighty = 1.0; 207 getContentPane().add(jPanel4, gridBagConstraints); 208 209 jMenu1.setText("Test"); 210 jMenuItem1.setText("New"); 211 jMenuItem1.addActionListener(new java.awt.event.ActionListener () { 212 public void actionPerformed(java.awt.event.ActionEvent evt) { 213 TestEditorFrame.this.newTest(evt); 214 } 215 }); 216 217 jMenu1.add(jMenuItem1); 218 219 jMenuItem2.setText("Open"); 220 jMenuItem2.addActionListener(new java.awt.event.ActionListener () { 221 public void actionPerformed(java.awt.event.ActionEvent evt) { 222 TestEditorFrame.this.openTest(evt); 223 } 224 }); 225 226 jMenu1.add(jMenuItem2); 227 228 jMenuItem3.setText("Save"); 229 jMenuItem3.addActionListener(new java.awt.event.ActionListener () { 230 public void actionPerformed(java.awt.event.ActionEvent evt) { 231 TestEditorFrame.this.saveTest(evt); 232 } 233 }); 234 235 jMenu1.add(jMenuItem3); 236 237 jMenuItem4.setText("Save as ..."); 238 jMenuItem4.addActionListener(new java.awt.event.ActionListener () { 239 public void actionPerformed(java.awt.event.ActionEvent evt) { 240 TestEditorFrame.this.saveAsTest(evt); 241 } 242 }); 243 244 jMenu1.add(jMenuItem4); 245 246 jMenu1.add(jSeparator1); 247 248 jMenuItem5.setText("Exit"); 249 jMenuItem5.addActionListener(new java.awt.event.ActionListener () { 250 public void actionPerformed(java.awt.event.ActionEvent evt) { 251 TestEditorFrame.this.exitTest(evt); 252 } 253 }); 254 255 jMenu1.add(jMenuItem5); 256 257 jMenuBar1.add(jMenu1); 258 259 jMenu3.setText("Tools"); 260 jMenuItem6.setText("Generate Test"); 261 jMenuItem6.addActionListener(new java.awt.event.ActionListener () { 262 public void actionPerformed(java.awt.event.ActionEvent evt) { 263 TestEditorFrame.this.generateTest(evt); 264 } 265 }); 266 267 jMenu3.add(jMenuItem6); 268 269 jMenu3.add(jSeparator2); 270 271 jMenuItem7.setText("Actions"); 272 jMenuItem7.addActionListener(new java.awt.event.ActionListener () { 273 public void actionPerformed(java.awt.event.ActionEvent evt) { 274 TestEditorFrame.this.testThreads(evt); 275 } 276 }); 277 278 jMenu3.add(jMenuItem7); 279 280 jMenuBar1.add(jMenu3); 281 282 jMenu2.setText("View"); 283 viewExplorerM.setText("Explorer"); 284 viewExplorerM.addActionListener(new java.awt.event.ActionListener () { 285 public void actionPerformed(java.awt.event.ActionEvent evt) { 286 TestEditorFrame.this.viewExplorer(evt); 287 } 288 }); 289 290 jMenu2.add(viewExplorerM); 291 292 jMenuBar1.add(jMenu2); 293 294 setJMenuBar(jMenuBar1); 295 296 } 298 private void testThreads(java.awt.event.ActionEvent evt) { try { 301 java.io.PrintWriter pw=new java.io.PrintWriter (new java.io.FileWriter ("/tmp/actions.lst")); 302 TestLogAction tl=new TestLogAction(1); 303 String [] keymap=tl.getKeyMaps(); 304 for (int i=0;i < keymap.length;i++) { 305 pw.println(" <TestLogAction Name=\""+keymap[i]+"\" Command=\"\" />"); 306 } 307 pw.close(); 308 309 } catch (Exception ex) { 310 ex.printStackTrace(); 311 } 312 } 314 private void generateTest(java.awt.event.ActionEvent evt) { if (Main.getFileName() == null) { 317 System.err.println("You have not specify xml file of the Test."); 318 return; 319 } 320 TestGenerateDialog dlg = new TestGenerateDialog(this,currentDirectory.getAbsolutePath()); 321 if (oldpath.length() > 0) { 322 dlg.setPath(oldpath); 323 } 324 if (oldpackage.length() > 0) { 325 dlg.setPackageName(oldpackage); 326 } 327 dlg.show(); 328 if (dlg.getState()) { 329 new Thread () { 330 String path,pack; 331 332 public void start(String pth,String pck) { 333 path=pth; 334 pack=pck; 335 oldpath=path; 336 oldpackage=pack; 337 start(); 338 } 339 340 public void run() { 341 try { 342 GenerateTests.generateTest(test, Main.getFileName(), path, pack); 343 } catch (Exception ex) { 344 ex.printStackTrace(); 345 } 346 } 347 }.start(dlg.getPath(),dlg.getPackageName()); 348 } 349 } 351 private void viewExplorer(java.awt.event.ActionEvent evt) { newRootWindow(); 354 } 356 private void exitTest(java.awt.event.ActionEvent evt) { exitForm(null); 359 } 361 private void saveAsTest(java.awt.event.ActionEvent evt) { String dlgFile; 364 365 if ((dlgFile = fileDlg(false)) != null) { 366 new Thread () { 367 private String file; 368 369 public void start(String afile) { 370 file = afile; 371 start(); 372 } 373 374 public void run() { 375 Main.saveAsTest(file); 376 } 377 }.start(dlgFile); 378 } 379 } 381 private void saveTest(java.awt.event.ActionEvent evt) { if (Main.isNoname()) { 384 saveAsTest(null); 385 } 386 387 new Thread () { 388 public void run() { 389 Main.saveTest(); 390 } 391 }.start(); 392 } 394 private void openTest(java.awt.event.ActionEvent evt) { String dlgFile; 397 398 if ((dlgFile = fileDlg(true)) != null) { 399 new Thread () { 400 401 private String file; 402 403 public void start(String afile) { 404 file = afile; 405 start(); 406 } 407 public void run() { 408 Main.openTest(file); 409 } 410 }.start(dlgFile); 411 } 412 } 414 private void newTest(java.awt.event.ActionEvent evt) { if (!Main.newTest()) { 417 if (quest("Test was modified. Save it?")) { 418 saveTest(null); 419 } 420 } 421 Main.newTest(); 422 } 424 private void exitForm(java.awt.event.WindowEvent evt) { if (Main.isChanged()) { 426 if (quest("Test is modified. Save it?")) { 427 saveTest(null); 428 } 429 } 430 431 if (tree != null) { 432 tree.close(); 433 } 434 Main.finish(); System.exit(0); 436 } 438 public void killFrame() { 439 setVisible(false); 440 } 441 442 public boolean quest(String question) { 443 QuestionDialog dlg=new QuestionDialog(this,question); 444 dlg.show(); 445 return dlg.getAnswer(); 446 } 447 448 public String fileDlg(boolean open) { 449 450 JFileChooser fch; 451 File file = null; 452 System.err.println(currentDirectory); 453 fch=new JFileChooser(currentDirectory); 454 fch.setFileFilter(new FileFilter () { 455 public boolean accept(File f) { 456 String s=f.getName().substring(f.getName().lastIndexOf('.')+1).toLowerCase(); 457 if (f.isDirectory() || s.compareTo("xml") == 0) { 458 return true; 459 } 460 return false; 461 } 462 463 public String getDescription() { 464 return "XML Test files"; 465 } 466 }); 467 if (open) { 468 fch.setDialogTitle("Open Test ..."); 469 if (fch.showOpenDialog(fch) == JFileChooser.APPROVE_OPTION) 470 if (!(file = fch.getSelectedFile()).isFile()) 471 return null; 472 } else { 473 fch.setDialogTitle("Save Test As ..."); 474 if (fch.showSaveDialog(fch) == JFileChooser.APPROVE_OPTION) { 475 file = fch.getSelectedFile(); 476 } 477 } 478 if (file == null) 479 return null; 480 else 481 currentDirectory=file.getParentFile(); 482 return file.getAbsolutePath(); 483 } 484 485 public void appendHistory(String text) { 486 history.append(text); 487 history.repaint(); 488 JScrollBar bar=historyScrollPane.getVerticalScrollBar(); 489 if (bar != null) { 490 bar.setValue(bar.getMaximum()); 491 } 492 } 493 502 506 public TreeDialog getTree() { 507 return tree; 508 } 509 510 public void setTitleFileName(String name) { 511 setTitle(TITLE+" ["+name+"]"); 512 } 513 514 private javax.swing.JSeparator jSeparator2; 516 private javax.swing.JPanel jPanel4; 517 private javax.swing.JMenuItem jMenuItem2; 518 private javax.swing.JMenu jMenu2; 519 private javax.swing.JMenuItem jMenuItem5; 520 private javax.swing.JMenuItem jMenuItem3; 521 private javax.swing.JMenuItem viewExplorerM; 522 private javax.swing.JPanel jPanel2; 523 private javax.swing.JMenuItem jMenuItem4; 524 private javax.swing.JMenuItem jMenuItem1; 525 private javax.swing.JMenu jMenu3; 526 private javax.swing.JMenuItem jMenuItem6; 527 private javax.swing.JSeparator jSeparator1; 528 private javax.swing.JEditorPane editor; 529 private javax.swing.JMenu jMenu1; 530 private javax.swing.JTextArea history; 531 private javax.swing.JScrollPane historyScrollPane; 532 private javax.swing.JScrollPane jScrollPane3; 533 private javax.swing.JMenuItem jMenuItem7; 534 private javax.swing.JMenuBar jMenuBar1; 535 537 } 538 539 | Popular Tags |