|
51 | 51 | import java.util.AbstractMap; |
52 | 52 | import java.util.ArrayList; |
53 | 53 | import java.util.Collection; |
| 54 | +import java.util.Enumeration; |
54 | 55 | import java.util.Set; |
55 | 56 | import java.util.HashMap; |
56 | 57 | import java.util.HashSet; |
|
108 | 109 | import edu.rice.cs.util.swing.Utilities; |
109 | 110 | import edu.rice.cs.util.swing.*; |
110 | 111 |
|
| 112 | +import static edu.rice.cs.drjava.config.OptionConstants.KEY_NEW_CLASS_FILE; |
111 | 113 | import static edu.rice.cs.drjava.ui.RecentFileManager.*; |
112 | 114 | import static edu.rice.cs.drjava.ui.predictive.PredictiveInputModel.*; |
113 | 115 | import static edu.rice.cs.util.XMLConfig.XMLConfigException; |
@@ -426,6 +428,141 @@ public void actionPerformed(ActionEvent ae) { |
426 | 428 | } |
427 | 429 | }; |
428 | 430 |
|
| 431 | + |
| 432 | + //newclass addition |
| 433 | + /** Creates a new Java class file. */ |
| 434 | + private final Action _newClassAction = new AbstractAction("New Java Class") { |
| 435 | + public void actionPerformed(ActionEvent ae) { |
| 436 | + _newClassFileGUI(); |
| 437 | + } |
| 438 | + }; |
| 439 | + |
| 440 | + //newclass addition |
| 441 | + public void _newClassFileGUI(){ |
| 442 | + |
| 443 | + final JFrame frame = new JFrame("New Java Class"); |
| 444 | + final JButton createClass = new JButton("Create"); |
| 445 | + final JTextField className = new JTextField(20); |
| 446 | + final JTextField interfaces = new JTextField(20); |
| 447 | + final JTextField superClass = new JTextField(20); |
| 448 | + final JLabel classNameLable = new JLabel("Class Name: "); |
| 449 | + final JLabel superClassLabel = new JLabel("SuperClass: "); |
| 450 | + final JLabel interfacesLabel = new JLabel("InterFaces: "); |
| 451 | + final JLabel modifierLabel = new JLabel("Modifier: "); |
| 452 | + final JLabel blankLabel = new JLabel(" "); |
| 453 | + |
| 454 | + |
| 455 | + final JLabel errorMessage = new JLabel(); |
| 456 | + final JRadioButton defaultRadio= new JRadioButton("default", false); |
| 457 | + final JRadioButton publicRadio= new JRadioButton("public", true); |
| 458 | + final JRadioButton abstractRadio= new JRadioButton("abstract", false); |
| 459 | + final JRadioButton finalRadio= new JRadioButton("final", false); |
| 460 | + final ButtonGroup group1 = new ButtonGroup(); |
| 461 | + final ButtonGroup group2 = new ButtonGroup(); |
| 462 | + final JCheckBox mainMethod = new JCheckBox("Include main method"); |
| 463 | + final JCheckBox classConstructor = new JCheckBox("Include class constructor"); |
| 464 | + |
| 465 | + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE ); |
| 466 | + frame.setSize(250, 350); |
| 467 | + frame.setLocationRelativeTo(null); |
| 468 | + frame.setVisible(true); |
| 469 | + |
| 470 | + frame.setLayout(new FlowLayout()); |
| 471 | + //the modifiers |
| 472 | + frame.add(modifierLabel); |
| 473 | + frame.add(publicRadio); |
| 474 | + frame.add(defaultRadio); |
| 475 | + |
| 476 | + //blankLabel.setSize(150,2); |
| 477 | + frame.add(blankLabel); |
| 478 | + frame.add(abstractRadio); |
| 479 | + frame.add(finalRadio); |
| 480 | + |
| 481 | + //grouping the modifiers |
| 482 | + group1.add(publicRadio); |
| 483 | + group1.add(defaultRadio); |
| 484 | + |
| 485 | + group2.add(abstractRadio); |
| 486 | + group2.add(finalRadio); |
| 487 | + |
| 488 | + frame.add(classNameLable); |
| 489 | + frame.add(className); |
| 490 | + frame.add(superClassLabel); |
| 491 | + frame.add(superClass); |
| 492 | + frame.add(interfacesLabel); |
| 493 | + frame.add(interfaces); |
| 494 | + |
| 495 | + frame.add(errorMessage); |
| 496 | + frame.add(mainMethod); |
| 497 | + frame.add(classConstructor); |
| 498 | + frame.add(createClass); |
| 499 | + //listen to the button when it is pressed |
| 500 | + //createClass.addActionListener(this); |
| 501 | + |
| 502 | + createClass.addActionListener( |
| 503 | + new ActionListener() { |
| 504 | + public void actionPerformed(ActionEvent e) { |
| 505 | + JRadioButton selectedRadioButton1 = new JRadioButton(); |
| 506 | + JRadioButton selectedRadioButton2 = new JRadioButton(); |
| 507 | + //to check which radio buttom has been choosen |
| 508 | + for (Enumeration enu = group1.getElements(); enu.hasMoreElements(); ) { |
| 509 | + JRadioButton b = (JRadioButton)enu.nextElement(); |
| 510 | + if (b.getModel() == group1.getSelection()) |
| 511 | + selectedRadioButton1 = b; |
| 512 | + }//for |
| 513 | + |
| 514 | + for (Enumeration enu = group2.getElements(); enu.hasMoreElements(); ) { |
| 515 | + JRadioButton b = (JRadioButton)enu.nextElement(); |
| 516 | + if (b.getModel() == group2.getSelection()) |
| 517 | + selectedRadioButton2 = b; |
| 518 | + }//for |
| 519 | + |
| 520 | + NewJavaClass javaClass = new NewJavaClass(); |
| 521 | + boolean sc = false; |
| 522 | + boolean in = false; |
| 523 | + |
| 524 | + // probability of entering the 3 variables |
| 525 | + String msg = ""; |
| 526 | + |
| 527 | + if(javaClass.classNameMeetsNamingConvention(className.getText())){ |
| 528 | + |
| 529 | + if(superClass.getText().length() != 0) |
| 530 | + if(javaClass.classNameMeetsNamingConvention(superClass.getText())) |
| 531 | + sc = true; |
| 532 | + else |
| 533 | + msg += "<html>Enter correct superclass name.<br></html>"; |
| 534 | + |
| 535 | + if(interfaces.getText().length() != 0) |
| 536 | + if(javaClass.interfacesNameMeetsNamingConvention(interfaces.getText())) |
| 537 | + in = true; |
| 538 | + else |
| 539 | + msg += "Enter correct interfaces name."; |
| 540 | + |
| 541 | + if( ((superClass.getText().length() == 0 && interfaces.getText().length() == 0)) || |
| 542 | + ((superClass.getText().length() != 0 && sc == true) && (interfaces.getText().length() != 0 && in == true)) || |
| 543 | + ((superClass.getText().length() != 0 && sc == true) && (interfaces.getText().length() == 0)) || |
| 544 | + ((superClass.getText().length() == 0) && (interfaces.getText().length() != 0 && in == true)) |
| 545 | + ) { |
| 546 | + _model.newClass(selectedRadioButton1.getText(), selectedRadioButton2.getText() ,className.getText(), mainMethod.isSelected(), classConstructor.isSelected(), superClass.getText(), interfaces.getText()); |
| 547 | + frame.setVisible(false); |
| 548 | + _save(); |
| 549 | + } else { |
| 550 | + errorMessage.setForeground(Color.RED); |
| 551 | + errorMessage.setText(msg); |
| 552 | + } |
| 553 | + |
| 554 | + } else { |
| 555 | + msg += "Enter correct class name. "; |
| 556 | + errorMessage.setForeground(Color.RED); |
| 557 | + errorMessage.setText(msg); |
| 558 | + } |
| 559 | + } |
| 560 | + } |
| 561 | + ); |
| 562 | + } |
| 563 | + |
| 564 | + |
| 565 | + |
429 | 566 | private final Action _newProjectAction = new AbstractAction("New") { |
430 | 567 | public void actionPerformed(ActionEvent ae) { _newProject(); } |
431 | 568 | }; |
@@ -663,6 +800,15 @@ public void pack() { |
663 | 800 | /** Supports MainFrameTest.*/ |
664 | 801 | public boolean isSaveEnabled() { return _saveAction.isEnabled(); } |
665 | 802 |
|
| 803 | + //newclass addition |
| 804 | + /** Creates a new Java Class File in the current folder. */ |
| 805 | + public final Action _newClassFileFolderAction = new AbstractAction("Create New Java Class in Folder") { |
| 806 | + public void actionPerformed(ActionEvent ae) { |
| 807 | + _newClassFileGUI(); |
| 808 | + _findReplace.updateFirstDocInSearch(); |
| 809 | + } |
| 810 | + }; |
| 811 | + |
666 | 812 | /** Asks the user for a file name and saves the active document (in the definitions pane) to that file. */ |
667 | 813 | private final Action _saveAsAction = new AbstractAction("Save As...") { |
668 | 814 | public void actionPerformed(ActionEvent ae) { _saveAs(); } |
@@ -6145,6 +6291,7 @@ private void _removeErrorListener(OpenDefinitionsDocument doc) { |
6145 | 6291 | */ |
6146 | 6292 | private void _setUpActions() { |
6147 | 6293 | _setUpAction(_newAction, "New", "Create a new document"); |
| 6294 | + _setUpAction(_newClassAction, "New", "Create a new Java Class"); |
6148 | 6295 | _setUpAction(_newJUnitTestAction, "New", "Create a new JUnit test case class"); |
6149 | 6296 | _setUpAction(_newProjectAction, "New", "Make a new project"); |
6150 | 6297 | _setUpAction(_openAction, "Open", "Open an existing file"); |
@@ -6403,6 +6550,8 @@ private JMenu _setUpFileMenu(int mask) { |
6403 | 6550 | PlatformFactory.ONLY.setMnemonic(fileMenu,KeyEvent.VK_F); |
6404 | 6551 | // New, open |
6405 | 6552 | _addMenuItem(fileMenu, _newAction, KEY_NEW_FILE); |
| 6553 | + _addMenuItem(fileMenu, _newClassAction, KEY_NEW_CLASS_FILE); |
| 6554 | + |
6406 | 6555 | _addMenuItem(fileMenu, _newJUnitTestAction, KEY_NEW_TEST); |
6407 | 6556 | _addMenuItem(fileMenu, _openAction, KEY_OPEN_FILE); |
6408 | 6557 | _addMenuItem(fileMenu, _openFolderAction, KEY_OPEN_FOLDER); |
@@ -7510,6 +7659,7 @@ protected void _popupAction(MouseEvent e) { |
7510 | 7659 | // "New File in Folder" and "Open File in Folder" only work if exactly |
7511 | 7660 | // one folder is selected |
7512 | 7661 | m.add(_newFileFolderAction); |
| 7662 | + m.add(_newClassFileFolderAction); |
7513 | 7663 | m.add(_openOneFolderAction); |
7514 | 7664 |
|
7515 | 7665 | // get singular/plural right |
|
0 commit comments