JLCA 3.0 - Java Event Model (AWT and Swing)

Java Event Model mechanism is primarily featured by listeners and adapters used to deal with the different types of events fired by AWT, Swing of the user himself. Most of Swing components use new event types and listeners. Java Event Model is mainly converted through towards .NET Framework event delegation model inherent in System.Windows.Forms and System.ComponentModel APIs and, .NET Framework Classes such as System.EventHandler and System.EventArgs.

 

JLCA 3.0 main conversion about AWT and Swing events takes into account: Most of the Java API Listeners and Adapters in AWT (some in Swing), DragAndDrop Operations and Custom User Events.

 

Table 27,Table 28,Table 29 and Table 30 show the most relevant details about Java’s Event Model conversion. In a summarized manner, they enunciate the Java Event Model features preserved in converted applications. On the other hand, they suggest the issues that the user should take care while converting applications using events.

 

Coverage Details

Class / Interface in Package java.awt.event

Functionality

JLCA 3.0 Coverage

Description

ActionEvent

ActionListener

ActionEvent indicates when a component-defined action occurred.

ActionListener is the listener interface for receiving action events.

Converted

Converted to System.Windows.Forms.Button.Click, System.Windows.Forms.TextBox.KeyPress, System.Windows.Forms.ListBox.DoubleClick and System.Windows.Forms.MenuItem.Click.

ActiveEvent

This is the interface for events that know how dispatch themselves.

Not Converted

These events have no equivalent in .NET Framework.

AdjustmentEvent

AdjustmentListener

AdjustmentEvent is the event emitted by Adjustable objects.

AdjustmentListener is the listener interface for receiving adjustment events.

Converted

Converted to System.Windows.Forms.Scrollbar.Scroll.

ComponentEvent

ComponentAdapter

ComponentListener

ComponentEvent indicates that a component moved, changed size, or changed visibility.

ComponentAdapter & ComponentListener are adapter and listener for receiving componentevents.

Converted

Converted to System.Windows.Forms.Control.Resize, System.Windows.Forms.Control.Move and System.Windows.Forms.Control.VisibleChanged.

ContainerEvent

ContainerAdapter

ContainerListener

ContainerEvent indicates when a component was added or removed.

ContainerAdapter & ContainerListener are adapter and listener for receiving containerevents.

Converted

Converted to System.Windows.Forms.ContainerControl.ControlAdded and System.Windows.Forms.ContainerControl.ControlRemoved

FocusEvent

FocusAdapter

FocusListener

FocusEvent indicates that a Component has gained or lost the input focus.

FocusAdapter & FocusListener are Adapter and listener for receiving keyboard focus events on a component.

Converted

Converted to System.Windows.Forms.Control.Enter and System.Windows.Forms.Control.Leave.

HierarchyBoundsAdapter

HierarchyBoundsListener

These are adapter class and listener interface for receiving ancestor moved and resized events.

Not Converted

These events have no equivalent in .NET Framework.

HierarchyEvent

HierarchyListener

These are event and listener for change to hierarchy of component occurs.

Not Converted

These events have no equivalent in .NET Framework.

InputEvent

This is the root event class for all component-level input events.

Not Converted

These events have no equivalent in .NET Framework.

InputMethodEvent

InputMethodListener

InputMethodEvent contain information about text that is being composed using an input method.

InputMethodListener is the listener interface for receiving input method events.

Not Converted

These events have no equivalent in .NET Framework.

InvocationEvent

This executes the run() method on a Runnable when dispatched by the AWT event dispatcher thread.

Not Converted

These events have no equivalent in .NET Framework.

ItemEvent

ItemListener

ItemEvent indicates that an item is selected or deselected.

ItemListener is the listener interface for receiving item events.

Converted

Converted to System.Windows.Forms.CheckBox.Click System.Windows.Forms.MenuItem.Click and

System.Windows.Forms.ListBox.SelectedIndexChanged.

KeyEvent

KeyListener

KeyEvent indicates that a keystroke occurred in a component.

KeyListener is the listener interface for receiving keyboard events.

Converted

Converted to System.Windows.Forms.Control.KeyPress, System.Windows.Forms.Control.KeyDown and System.Windows.Forms.Control.KeyUp.

MouseEvent

MouseListener

MouseMotionAdapter

MouseMotionListener

MouseEvent indicates that a mouse action occurred in a component.

MouseListener is the listener interface for receiving mouse events.

MouseMotionAdapter & MouseMotionListener are the adapter and listener for receiving mouse motion events.

Converted

Converted to System.Windows.Forms.Control.Click, System.Windows.Forms.Control.MouseEnter, System.Windows.Forms.Control.MouseLeave, System.Windows.Forms.Control.MouseMove, System.Windows.Forms.Control.MouseDown and System.Windows.Forms.Control.MouseUp.

TextEvent

TextListener

TextEvent indicates that an object's text changed.

TextListener is the listener interface for receiving text events.

Converted

Ported to System.Windows.Forms.TextBox.TextChanged.

WindowEvent

WindowAdapter

WindowListener

WindowEvent indicates that a window has changed its status.

WindowAdapter & WindowListener are the adapter and listener for receiving window events.

Converted

Converted to System.Windows.Forms.Form.Load, System.Windows.Forms.Form.Activated, System.Windows.Forms.Form.Deactivated, System.Windows.Forms.Form.Closed and System.Windows.Forms.Form.Closing.

Table 27: Java Event Model Conversion Coverage (1) – Package java.awt.event

Class / Interface in Package java.awt.dnd

Functionality

JLCA 3.0 Coverage

Description

AutoScroll

Interface that provides auto scrolling facility.

Not Converted

It is not converted to .NET Framework as the auto-scrolling is managed implicitly in .NET Framework.

DnDConstants

Contains constant values representing the type of action(s) to be performed by a Drag and Drop operation.

Converted

Converted to System.Windows.Forms.DragDropEffects.

DragGestureEvent

DragGestureListener

DragGestureEvent occurs when a particular DragGestureRecognizer detects that a platform dependent drag initiating gesture has occurred on the Component.

DragGestureListener is invoked when an object of that class detects a drag initiating gesture.

Partially

Converted

Core Functionality achieved through DragSource is converted. Advanced functionality is not converted as .NET Framework does not have its equivalent.

DragGestureRecognizer

MouseDragGestureRecognizer

This is an abstract base class for the specification of a platform-dependent listener that can be associated with a particular Component in order to identify platform-dependent drag initiating gestures.

Not Converted

It is not converted to .NET Framework as similar functionality is not available in .NET Framework.

DragSource

DragSourceContext

DragSourceDragEvent

DragSourceDropEvent

DragSourceEvent

DragSourceListener

DragSource is responsible for the initiation of the Drag and Drop operation.

DragSourceContext is responsible for managing the initiator side of the Drag and Drop protocol.

DragSourceEvent is the base class for DragSourceDrag Event and DragSourceDrop Event.

DragSourceListener is the event interface for originators of Drag and Drop operations to track the state of the user's gesture, and to provide appropriate "drag over" feedback to the user throughout the Drag and Drop operation.

Partially

Converted

Core functionality exposed by these components is converted to .NET Framework. Since Drag n Drop is managed in a different way in .NET Framework, there is no equivalent for these classes but, the functionality is converted to .NET Framework’s Drag n Drop.

DropTarget

DropTargetContext

DropTargetDragEvent

DropTargetDropEvent

DropTargetEvent

DropTargetListener

These are associatedwith a Component when that Component wishes to accept drops during Drag and Drop operations.

Partially Converted

Core functionality exposed by these components is converted to .NET Framework. Operations like dragEnter, dragOver, dragExit and drop are being converted.

InvalidDnDOperationException

This is thrown by various methods in the java.awt.dnd package.

Converted

It is converted to a more general exception (System.Exception) since there is no direct equivalent in .NET Framework.

Table 28: Java Event Model Conversion Coverage (2) – Package java.awt.dnd

Class / Interface in Package javax.swing.event

Functionality

JLCA 3.0 Coverage

Description

AncestorEvent

AncestorListener

AncestorEvent occurs when there is a change to ancestor happens.

AncestorListener listens for AncestorEvent.

Not Converted

These have no equivalent in .NET Framework.

CaretEvent

CaretListener

CaretEvent occurs when text caret has changed.

CaretListener listens for changes in the caret position of a text component.

Not Converted

These have no equivalent in .NET Framework.

ChangeEvent

ChangeListener

ChangeEvent occurs when state has changed in the event source.

ChangeListener listens for ChangeEvents.

Partially Converted

Only JSlider and JTabbedPane are converted to System.Windows.Forms.TrackBar.ValueChanged and System.Windows.Forms.TabControl.SelectedIndexChanged.

HyperlinkEvent

HyperlinkListener

HyperlinkEvent occurs when something has happened with respect to a hypertext link.

HyperlinkListener listens for HyperlinkEvent

Partially Converted

Only JEditorPane is converted to System.Windows.Forms.RichTextBox.LinkClicked.

InternalFrameEvent

InternalFrameListener

InternalFrameEvent adds support for JInternalFrame objects as the event source.

InternalFrameListener is the listener interface for receiving internal frame events.

Partially

Converted

JInternalFrame is converted. Messages Deiconified and Iconified are not supported.

javax.swing.Action

Action interface provides a useful extension to the ActionListener interface in cases where the same functionality may be accessed by several controls.

Partially

Converted

Only actionPerformed is converted.

ListDataEvent

ListDataListener

ListDataEvent occurs when list changes.

ListDataListener listens for changes in list.

Not Converted

These have no equivalent in .NET Framework.

ListSelectionEvent

ListSelectionListener

ListSelectionEvent occurs when a change in the current selection occurs.

ListSelectionListener listens for lists selection value changes.

Partially

Converted

Only JList is converted to System.Windows.Forms.ListBox.SelectedValueChanged.

MenuDragMouseEvent

MenuDragMouseListener

MenuDragMouseEvent occurs when menu element has received a MouseEvent under drag conditions.

MenuDragMouseListener listens for MenuDragMouseEvent.

Not Converted

These have no equivalent in .NET Framework.

MenuEvent

MenuListener

MenuEvent occurs when a menu has been posted or selected or canceled.

MenuListener listener for menu events.

Partially Converted

JMenu (message Selected) is converted to System.Windows.Forms.MenuItem.Select.

MenuKeyEvent

MenuKeyListener

MenuKeyEvent occurs when menu element has received a KeyEvent forwarded to it in a menu tree.

MenuKeyListener listens for MenuKeyListener.

Not Converted

These have no equivalent in .NET Framework.

PopupMenuEvent

PopupMenuListener

PopupMenuEvent occurs with regarding to JPopupMenu.

PopupMenuListener listens for PopupMenuEvent.

Partially

Converted

JPopupMenu is converted to System.Windows.Forms.ContextMenu.Popup (message WillBecomeVisible)

PropertyChangeEvent

PropertyChangeListener

PropertyChangeEvent occurs whenever a bean changes a "bound" or "constrained" property.

PropertyChangeListener listens for PropertyChangeEvent.

Not Converted

These have no equivalent in .NET Framework.

TableColumnModelEvent

TableColumnModelListener

TableColumnModelEvent occurs when a table column has been added or moved or removed.

TableColumnModelListener listens to changes in a TableColumnModel.

Partially

Converted

Only converted for messages Added/Removed to System.Data.DataColumnCollection.CollectionChanged.

TableModelEvent

TableModelListener

TableModelEvent occurs when a table model has changed.

TableModelListener listens to changes in a Table Model.

Converted

AbstractTableModel is converted to System.Data.DataTable.RowChanged.

TreeExpansionEvent

TreeExpansionListener

TreeExpansionEventoccurs when a tree expands or collapses a node.

TreeExpansionListener listens for TreeExpansionEvent.

Converted

Converted to System.Windows.Forms.TreeView.BeforeExpand,

System.Windows.Forms.TreeView.BeforeCollapse,

System.Windows.Forms.TreeView.AfterExpand and

System.Windows.Forms.TreeView.AfterCollapse.

TreeModelEvent

TreeModelListener

TreeModelEvent occurs when tree model has changed.

TreeModelListener listens to changes in a TreeModel.

Not Converted

These have no equivalent in .NET Framework.

TreeSelectionEvent

TreeSelectionListener

TreeSelectionEvent occurs when the selection in a TreeSelectionModel changes.

TreeSelectionListener listens for TreeSelectionEvent.

Converted

JTree is converted through System.Windows.Forms.TreeView.AfterSelect.

UndoableEditEvent

UndoableEditListener

UndoableEditEvent occurs when operation that can be undone has occurred.

UndoableEditListener listens for undoable operations.

Not Converted

These have no equivalent in .NET Framework.

Table 29: Java Event Model Conversion Coverage (3) – Package javax.swing.event

Issues

Issue

Description

Events Equivalence And

Event Handling Behavior

In some cases, Java’s events behave differently to .NET Framework’s equivalent ones in the sense: the events are fired and handled on corresponding controls. So, the behavior of converted applications could be different since the status of the .NET Framework controls slightly differs.

Thus, the stabilization of converted applications –in event handling issues- could require reviewing the .NET framework documentation to learn about the specific events used on the application, their collateral effects and the way they are fired and handled on respective controls.

EventObject.getSource()

In Java, the use of method java.util.EventObject.getSource() is to identify the event firing a component.

In .NET Framework, the sender of the event is passed as parameter to the event handling method.

Invocations to getSource() are converted only within event-handling methods (in Java, listener’s methods).

So, conversion for method getSource() could require user-intervention if it is up to 2 level of depth. A workaround could require modifying the arguments of the respective routines to the expected correct parameters sent from the event handling routine.

Event Queue Managing And

Low-Level Event Handling

Accessing of system event queue is converted because there is no centralized mechanism to read events from a queue and post them.

Also, low-level event handling –also known as containment model- is not converted in .NET Framework because the heavy centralization and the lack of modularity inherent in this Java’s model, makes it a very particular way to handle events.

General Issues

Java Event Model conversion is mostly based on source code patterns. Java’s event notification –through listeners and adapters- is converted to .NET Framework through events and delegates.

In .NET Framework, listener and adapter classes are not essential. However, their methods are converted to delegates through delegate System.EventHandler. In this way, the same source methods are notified when events occur. In .NET Framework, Event “listener registration” is performed attaching event handlers (delegates) to the corresponding events.

User Raised Events

Events programmatically-raised by the user (not by the GUI normal interaction) through method dispatchEvent() are not completely converted. Only ActionEvent and ItemEvent (for Button, MenuItem and CheckboxMenuItem) are converted through method PerformClick.

Remaining user raised events have no equivalent in .NET Framework. A workaround could require designing another way of event notification.

Table 30: Java Event Model Conversion Issues

Comments