Procedure

Basic Events Test / VE Style 3 Events Test

Adding Events

Create a new empty class and drop a JButton on the canvas
Set the text of the JButton to something.
Switch the beans view to Show Events.

Select the JButton on the canvas, bring up the context menu and select Events
Verify that "Add Event...",  actionPerformed callback, and enabled, model and text properites are on the submenu


Select the JButton on the beans view and bring up the context menu and select Events
Verify that "Add Event...", actionPerformed callback, and enabled, model and text properties are on the submenu

Bring up the context menu again and select actionPerformed.
Verify that the actionPerformed event shows up on the beans list.
Verify the following code is added to the JButton

                jButton.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {    
                                System.out.println("actionPerformed()"); // TODO Auto-generated stub actionPerformed()
                        }
                });

Repeat the step above
Verify that another actionPerformed event shows up on the beans list and in the code

Bring up the context menu and select "Add Event ..." this time
Verify the Add Event dialog is displayed
Verify the title of the Wizard is the selected bean's label
Verify that the event types supported by JButton are displayed in the tree:


Verify the events which extend interfaces use the I icon.
Verify the events which have adapters by default use the C icon.
Verify that the action event icon is denotes that an inner class exist - the others use the default icons.

Expand the action tree item and the ancestor tree item
Verify the icon for actionPerformed is colorized
Verify the icons under ancestor are defaulted
Verify the icons under the propertyChange (denoting properties) are in different color.

Select actionPerformed item
Verify use existing listener radio is disabled
Verify extends: radio is disabled

Click Finish
Verify that another actionPerformed event shows up on the beans list and in the code

Select two out of the three actionPerformed events and use the context menu to delete them.

Bring up the Add Events dialog again, this time using the context menu on the beans view
Verify that the dialog is displayed

Select key then keyPressed
Verify the Use existing listener radio is disabled
Verify that extends and implements are enabled

Select the extends radio and press Finish
Verify that the keyPressed event shows up on the beans view
Verify that the following source is added:
                jButton.addKeyListener(new java.awt.event.KeyAdapter() {
                        public void keyPressed(java.awt.event.KeyEvent e) {    
                                System.out.println("keyPressed()"); // TODO Auto-generated stub keyPressed()
                        }
                });

Bring up the add events dialog again
Verify that the class icon next to key is colorized
Expand the key item
Verify that the keyPressed icon is colorized and the others are not
Select the keyPressed item
Verify that the Use existing listener radio is disabled
Select the keyReleased item
Verify that the Use existing listener and Create new listener items are enabled
Verify that the Use existing listener is selected by default
Verify that the extends and implements radios are disabled
Select the Create new listener radio
Verify that the extends and implements radios are enabled

Select the Use existing listener radio
Press Finish
Verify that the keyReleased event shows up on the beans view
Verify that the keyReleased source is added to the existing KeyAdapter

Bring up the add events dialog again
Select key->keyTyped
Select the Create new listener radio
Select Implements: KeyListener
Press Finish
Verify the following source is added:
                jButton.addKeyListener(new java.awt.event.KeyListener() {
                        public void keyTyped(java.awt.event.KeyEvent e) {    
                                System.out.println("keyTyped()"); // TODO Auto-generated stub keyTyped()
                        }
                        public void keyPressed(java.awt.event.KeyEvent e) {}
                        public void keyReleased(java.awt.event.KeyEvent e) {}
                });

Switch the beans view to expert mode



Verify that the event classes are shown properly


Verify that the events extending listeners have the I (interface) icon
Verify that the events extending adapters have the C (class) icon
Verify that the children events are nested under the classes properly

Select the KeyAdapter class and bring up the Events context menu
Verify that the keyPressed and keyReleased items are disabled
Verify that the keyTyped item is enabled.

Select the keyTyped event.
Verify that keyTyped event is added to the existing adapter.

Bring up the Event context menu on the adapter again.
Verify that all of the events are disabled.

Drop a JFrame on the canvas
MB2->Events on the JFrame
Verify that windowClosing and windowOpened callbacks, and enabled property are available on the context menu

Select windowClosing
Verify that the windowAdapter and windowClosing event are created correctly

Bring up the context menu again and select windowOpened
Verify that the windowOpened event is added to the existing WindowAdapter

Bring up the context menu again and select windowOpened again
Verify that the new windowOpened event is added to a new WindowAdapter

Select the JFrame and delete it from the canvas.

Save the class.

Source Manipulation

Select the keyTyped event on the Adapter on tree
Verify that the source is driven to the method declaration line of the keyTyped event.

Select the ActionListener on the tree
Verify that the source is driven to the addActionListener line where the inner class is declared

Select the KeyAdapter on the tree
Verify that the source is driven to the addKeyListener line where the inner class is declared

Select the actionPerformed event on the tree
Verify that the source is driven to the method declaration line of the actionPerformed event.

From the source, copy in the following code beneath the existing events:
                        jButton.addFocusListener(new java.awt.event.FocusAdapter() {
                                public void focusGained(java.awt.event.FocusEvent e ) {
                                        System.out.println();
                                }
                        });

Verify that the beans view updates to reflect the new event class and method

Underneath the focusGained method, copy in the following code:
                                public void focusLost(java.awt.event.FocusEvent e) {
                                        System.out.println();
                                }
Verify that the beans view updates to reflect the new event method.

Underneath the FocusListener block, copy in the following code:
                        jButton.addMouseListener(new java.awt.event.MouseAdapter() {
                        });
Verify that the beans view updates to reflect the new event class.

Go to the existing KeyListener class
Change the line
public void keyPressed(java.awt.event.KeyEvent e) {}
to
public void keyPressed(java.awt.event.KeyEvent e) { System.out.println(); }
Verify that the beans view updates to reflect the new event method in the KeyListener.

Within the MouseAdapter add the following code:
                        public void mouseEntered(java.awt.event.MouseEvent e) {
                                System.out.println();
                        }
Verify that the beans view updates to reflect the new event method in the MouseAdapter.

Change the mouseEntered method to be mouseExited
Verify that the beans view updates to reflect the changed event method in the MouseAdapter.

Copy the following code into the body of the KeyListener class.        
                        public void foo(java.awt.event.KeyEvent e ) {
                                System.out.println();
                        }

Verify that the beans view does NOT reflect the foo callback.

Copy the foo method into the body of the MouseAdapter
Verify that the beans view does not change reflect this method.

Comment out the System.out.println(); line in the mouseExited method.
Verify that the beans view updates to reflect the removed event method
Uncomment the println line
Verify that the event method returns to the beans view.
Comment out the entire mouseExited method
Verify that the beans view updates to reflect the removed event method
Uncomment the entire mouseExited method
Verify that the event method returns to the beans view.
Comment out the entire mouseExited method again
Uncomment the method declaration and closing bracket, but not the System.out.println(); line
Verify that the event method  does not return to the beans view
Uncomment the System.out.println(); line
Verify that the event method returns to the beans view.

Comment out the System.out.println() line in the KeyListener's keyTyped method.
Verify that the beans view updates to reflect the removed event method
Uncomment the System.out.println() line
Verify that the event method returns to the beans view.

Change the parameter type in the mouseExited method from MouseEvent to KeyEvent.
Verify that the mouseExited event is removed from the beans view
Change the parameter type back to MouseEvent
Verify that the mouseExited event returns to the beans view.

Cut the entire keyTyped method in the KeyListener and paste it below the keyPressed method
Verify that the event methods swap order in the beans view

Note: The following test is a current limitation of V5.1. Do not fail test because of this.
Cut the entire addKeyListener(new KeyListener) block
Verify that the event class and methods is removed from the beans view
Paste the method back in above the ActionListener at the top
Verify that the event class and methods are returned to the beans view, above the ActionListener

Switch to Show Events in the beans view (from Expert Events)
Verify that the event methods are represented properly in the basic mode.
Revert your class to the previous saved state and repeat the steps of this section, making sure the source modifications provoke the correct responses for the basic mode.

Once repeated, save your class.

 

Property Changed events

Switch to Expert Events.

Open the Events wizard, open the propertyChange interface icon, and select the enabled property, and use the default two argument propety change method.
Verify that a propertyChange Listener with the enabled property icon was added to the JavaBean view.
Verify that selecting on the "enabled" property drives you to the following generated code:
                        jFrame.addPropertyChangeListener("enabled", new java.beans.PropertyChangeListener() {
                                public void propertyChange(java.beans.PropertyChangeEvent e) {
                                                System.out.println("propertyChange(enabled)"); // TODO Auto-generated stub "enabled"
                                }
                        });

Open the Events wizard again, and select the propertyChange->enabled property again.
 Verify that the "Use Existing" option is not available.

Select the single argument listener registration method


 Verify that a new listener was generated on the JavaBean viewer and in the source as following:
jFrame.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
                public void propertyChange(java.beans.PropertyChangeEvent e) {
                        if ((e.getPropertyName().equals("enabled"))) {
                                System.out.println("propertyChange(enabled)"); // TODO Auto-generated stub "enabled"
                        }
                }
        });

Open the Events wizard again, and select the propertyChange->font property.
Select use Existing, and Finish.
 Verify that the font property was added in the JavaBean viewer.
 Verify that when clicking on the font property, the source is driven to the following added if statement:
                        if ((e.getPropertyName().equals("font"))) {
                                System.out.println("propertyChange(font)"); // TODO Auto-generated stub "font"
                        }  

In the source, generated if statement
if ((e.getPropertyName().equals("font"))) {  
to
if ((e.getPropertyName().equals("foo"))) {

Verify that the JavaBean viewer reflect "foo" with a Warning (TBD).

Delete the "foo" if statement
Verify that foo is removed from the JavaBean Viewer.

Deleting events

Make sure the beans view is set to basic (Show Events) mode

Select the first keyPressed  event on the tree
MB2->Delete the keyPressed
Verify that the contents of the event method are removed from the source.
Verify that the event method itself is not removed from the source
Verify that the event method is removed from the beans view

Press UNDO
Verify that the contents of the event method return and the event method returns to the beans view

Select the keyTyped event (next one down)
MB2->Delete the keyTyped
Verify that the contents of the event method are removed from the source.
Verify that the event method itself is not removed from the source
Verify that the event method is removed from the beans view

Select the keyPressed event on the tree
MB2->Delete the keyPressed
Verify that the contents of the event method are removed from the source.
Verify that the event method is removed from the beans view
Verify that the entire event body (whole listener including add statement) is removed from the source.

Select the focusGained event
Press the delete key on the keyboard
Verify that the focusGained event is removed from the beans view
Verify that the focusGained event method is completely removed from the source

Select the focusLost event
Press the delete button on the toolbar
Verify that the focusLost event is removed from the beans view
Verify that the entire event body (whole adapter including add statement) is removed from the source.

Switch to Expert Events mode
Select the actionPerformed event on the beans view
Press the delete key
Verify that the contents of the event method are removed from the source.
Verify that the event method itself is not removed from the source
Verify that the event method is removed from the beans view

Press UNDO
Verify that the contents of the event method return and the event method returns to the beans view

Select the ActionListener class on the beans view
MB2->Delete
Verify that the event method and event class is removed from the beans view
Verify that the entire event body (whole listener including add statement) is removed from the source.

Select all three events under the KeyAdapter class by using the Ctrl key
Press the Delete button on the toolbar
Verify that the event methods are removed from the source
Verify that the event methods are removed from the beans view
Verify that the empty Adapter class remains in the source and the beans view

Select the KeyAdapter
Press the delete key
Verify that the Adapter class is removed from the source and the beans view

MB2->Undo
Verify that the empty Adapter class returns in the source and is shown on the beans view

Press Ctrl-Z (Undo again)
Verify that the event methods return to the source and beans view

Select the KeyAdapter class
MB2->Delete
Verify that the Adapter class and all its event methods are removed from the source and the beans view

Events on this bean

Create a new Visual Class extending JFrame

Test out adding/deleting/modifying events as described above on the JFrame with both events extending Listeners and Adapters.
Verify that the event code is generated properly in the initialize method.
Verify that the add events wizard works properly.
Verify that the context menus on the thispart work properly.
Verify that the other event functionality works as expected.

User defined events
 

Import the answer sample zip from here -> answer.zip into a project.
Open Test.java in the VE
Select the answerPanel and bring up the add events wizard on it.
Verify that the event answer is available from the events list
Verify that the event's methods (answeredCorrectly, answeredIncorrectly) show up under answer
Verify that the description of the class and methods show up ok
Verify that the implements: class is the correct class - answer.AnswerListener

Select the answeredIncorrectly event and press finish.
Verify that the following code gets added to the answer panel's initializer method.
                        answerPanel.addAnswerListener(new answer.AnswerListener() {
                                public void answeredIncorrectly(answer.AnswerEvent e) {    
                                        System.out.println("answeredIncorrectly()"); // TODO Auto-generated stub answeredIncorrectly()
                                }
                                public void answeredCorrectly(answer.AnswerEvent e) {}
                        });
Verify that the answerListener class and answeredIncorrectly event show up properly on the beans view.

Launch the Add Event wizard again.
Expand the answer event class.
Verify the answeredIncorrectly event is filled in, answeredCorrectly isn't.

Select answeredCorrectly
Verify the use existing listener option is enabled.

Click finish.
Verify the existing answeredCorrectly method has a body added.

Copy the following code in to replace the body of the listener.
                                public void answeredIncorrectly(answer.AnswerEvent e) {    
                                        getJLabel().setForeground(java.awt.Color.red);
                                        getJLabel().setText("Wrong!");
                                }
                                public void answeredCorrectly(answer.AnswerEvent e) {
                                        getJLabel().setForeground(java.awt.Color.green);
                                        getJLabel().setText("Right!");
                                }

Select the answer panel and bring up the Add Events Wizard
Expand the PropertyChanged item
Verify the answer property shows up on the list
Verify the answer description shows up ok
Select the two param method and click finish
Verify the code is added correctly:
                        answerPanel.addPropertyChangeListener("answer", new java.beans.PropertyChangeListener() {
                                public void propertyChange(java.beans.PropertyChangeEvent e) {
                                                System.out.println("propertyChange(answer)"); // TODO Auto-generated stub "answer"
                                }
                        });

Use the context menu to add a enabled property event to the answer panel.
Bring up the Add Events Wizard again on the answer panel and select the answer property again
Verify the Use Existing radio is enabled and selected by default.
Click Finish.
Verify the new answer property is added to the existing property change correctly


Save, close and reopen the file.
Verify the events are parsed correctly.

If you feel like running the code, the default answer is 42.