[g-a-devel] [PATCH] java-access-bridge: handle selecting text and typing over it



Hi,

I apologise if this is not the correct place for the patch.

This is a patch for the java-access-bridge in gnome (http://live.gnome.org/Java%20Access%20Bridge). Using a swing JTextField, if a user selects text and starts typing to replace it, a StringIndexOutOfBoundsException is thrown in .

The following events are observed through acccerciser in gedit when selecting text and typing over it:
object:text-changed:delete
object:text-changed:insert
object:text-caret-moved

While the Swing program only emits
object:text-changed:delete
object:text-changed:insert

The 'object:text-caret-moved' event is not sent. The attached patch catches the exception and silently ignores it, ensuring the selection-changed event is not sent and the text-caret-moved event is.

Cheers,

Omair
Thread [AWT-EventQueue-2] (Suspended (exception StringIndexOutOfBoundsException))	
	String.substring(int, int) line: 1946	
	JavaBridge.dispatchCaretProperty(PropertyChangeEvent) line: 608	
	JavaBridge$1.propertyChange(PropertyChangeEvent) line: 69	
	PropertyChangeSupport.fire(PropertyChangeListener[], PropertyChangeEvent) line: 298	
	PropertyChangeSupport.firePropertyChange(PropertyChangeEvent) line: 291	
	PropertyChangeSupport.firePropertyChange(String, Object, Object) line: 229	
	JTextField$AccessibleJTextField(AccessibleContext).firePropertyChange(String, Object, Object) line: 743	
	JTextField$AccessibleJTextField(JTextComponent$AccessibleJTextComponent).caretUpdate(CaretEvent) line: 2591	
	JTextField(JTextComponent).fireCaretUpdate(CaretEvent) line: 408	
	JTextComponent$MutableCaretEvent.fire() line: 4406	
	JTextComponent$MutableCaretEvent.stateChanged(ChangeEvent) line: 4428	
	BasicTextUI$BasicCaret(DefaultCaret).fireStateChanged() line: 799	
	BasicTextUI$BasicCaret(DefaultCaret).changeCaretPosition(int, Position$Bias) line: 1274	
	BasicTextUI$BasicCaret(DefaultCaret).handleSetDot(int, Position$Bias) line: 1170	
	BasicTextUI$BasicCaret(DefaultCaret).setDot(int, Position$Bias) line: 1151	
	DefaultCaret$Handler.insertUpdate(DocumentEvent) line: 1719	
	PlainDocument(AbstractDocument).fireInsertUpdate(DocumentEvent) line: 202	
	PlainDocument(AbstractDocument).handleInsertString(int, String, AttributeSet) line: 751	
	PlainDocument(AbstractDocument).insertString(int, String, AttributeSet) line: 710	
	PlainDocument.insertString(int, String, AttributeSet) line: 131	
	PlainDocument(AbstractDocument).replace(int, int, String, AttributeSet) line: 672	
	JTextField(JTextComponent).replaceSelection(String) line: 1368	
	DefaultEditorKit$DefaultKeyTypedAction.actionPerformed(ActionEvent) line: 876	
	SwingUtilities.notifyAction(Action, KeyStroke, KeyEvent, Object, int) line: 1661	
	JTextField(JComponent).processKeyBinding(KeyStroke, KeyEvent, int, boolean) line: 2860	
	JTextField(JComponent).processKeyBindings(KeyEvent, boolean) line: 2895	
	JTextField(JComponent).processKeyEvent(KeyEvent) line: 2823	
	JTextField(Component).processEvent(AWTEvent) line: 5885	
	JTextField(Container).processEvent(AWTEvent) line: 2105	
	JTextField(Component).dispatchEventImpl(AWTEvent) line: 4469	
	JTextField(Container).dispatchEventImpl(AWTEvent) line: 2163	
	JTextField(Component).dispatchEvent(AWTEvent) line: 4295	
	DefaultKeyboardFocusManager(KeyboardFocusManager).redispatchEvent(Component, AWTEvent) line: 1881	
	DefaultKeyboardFocusManager.dispatchKeyEvent(KeyEvent) line: 742	
	DefaultKeyboardFocusManager.preDispatchKeyEvent(KeyEvent) line: 1007	
	DefaultKeyboardFocusManager.typeAheadAssertions(Component, AWTEvent) line: 879	
	DefaultKeyboardFocusManager.dispatchEvent(AWTEvent) line: 706	
	AppletViewer(Component).dispatchEventImpl(AWTEvent) line: 4339	
	AppletViewer(Container).dispatchEventImpl(AWTEvent) line: 2163	
	AppletViewer(Window).dispatchEventImpl(AWTEvent) line: 2478	
	AppletViewer(Component).dispatchEvent(AWTEvent) line: 4295	
	EventQueue.dispatchEvent(AWTEvent) line: 604	
	EventDispatchThread.pumpOneEventForFilters(int) line: 275	
	EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter) line: 200	
	EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: 190	
	EventDispatchThread.pumpEvents(int, Conditional) line: 185	
	EventDispatchThread.pumpEvents(Conditional) line: 177	
	EventDispatchThread.run() line: 138	

Index: bridge/org/GNOME/Accessibility/JavaBridge.java
===================================================================
--- bridge/org/GNOME/Accessibility/JavaBridge.java	(revision 232)
+++ bridge/org/GNOME/Accessibility/JavaBridge.java	(working copy)
@@ -623,16 +623,21 @@
 			}
 			oldFocusSelectStart = selection_start;
 			oldFocusSelectEnd = selection_end;
-			if (selection_change_start != selection_change_end) {
-			    selection_any.insert_string (oldFocusText.substring (
-							     Math.min (selection_change_start, selection_change_end),
-							     Math.max (selection_change_start, selection_change_end)));
-			    dispatchEvent (e.getSource(),
-					   "object:text-selection-changed",
-					   selection_start, selection_end,
-					   selection_any);
-			}
+			try {
+				if (selection_change_start != selection_change_end) {
+				    selection_any.insert_string (oldFocusText.substring (
+								     Math.min (selection_change_start, selection_change_end),
+								     Math.max (selection_change_start, selection_change_end)));
+				    dispatchEvent (e.getSource(),
+						   "object:text-selection-changed",
+						   selection_start, selection_end,
+						   selection_any);
+				}
+		    } catch(StringIndexOutOfBoundsException indexException) { 
+		    	// the selection_change_end index may be more than the 
+		    	// length of the string. ignore this case silently
 		    }
+		    }
 		}
 		dispatchEvent(e.getSource(), 
 			      "object:text-caret-moved",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]