Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Bug in VerifyEvent handling?
Bug in VerifyEvent handling? [message #212373] Wed, 17 March 2004 13:13 Go to next message
Eclipse UserFriend
Originally posted by: burner.zclipse.org

I have the following Editor pasted below, where it _should_ input 'A'
instead of 'a' and 'B' instead of 'b', however, only the untyped Listener
appears to be working. According to the API on VerifyEvent, I should be
able to change the text field to change the text that will be inserted.
However, this only works when I do it to the Event object in my untyped
Listener. Also, Event.character isn't set for the untyped Listener, but I
don't know if it supposed to be or not.

mike

(this is doing PDE on 3.0.200403100800)


/*
* Created on Mar 16, 2004
* $Id$
*/
package org.zclipse.extremities.editors;

import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor ;
import org.eclipse.jface.text.source.IOverviewRuler;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.VerifyKeyListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.editors.text.TextEditor;

/**
* TODO: Document ExtremityJavaEditor
*
* @author <a href="mailto:burner@zclipse.org">Michael R. Head</a>
* @version $Name$ $Date$ $Revision$
*/
public class ExtremityJavaEditor extends TextEditor {//CompilationUnitEditor {
/* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse. swt.widgets.Composite)
*/
public void createPartControl(Composite parent) {
// TODO Auto-generated method stub
super.createPartControl(parent);

getSourceViewer().getTextWidget().addVerifyKeyListener(new VerifyKeyListener() {

public void verifyKey(VerifyEvent event) {
// TODO Auto-generated method stub
System.out.println("Verifying Key:"+event);
if(event.character == 'a' && event.stateMask == 0) {
event.text="A";
event.keyCode = 97;
event.character = 'A';
}
System.out.println("Verified Key"+event);
}
});

getSourceViewer().getTextWidget().addListener(SWT.Verify, new Listener() {

public void handleEvent(Event event) {
if(event.type == SWT.Verify) {
System.out.println("Handling Verify:"+event+", event.character="+event.character+", event.text=\""+event.text+"\"");
if(event.text.equals("b") && event.stateMask == 0) {
event.text="B";
event.keyCode=98;
event.character = 'B';
}
System.out.println("Handled Verify:"+event+", event.character="+event.character+", event.txt=\""+event.text+"\"");
}

}
});

}
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#createJava SourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, org.eclipse.jface.text.source.IOverviewRuler, boolean, int)
*/
//protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean isOverviewRulerVisible, int styles) {
// TODO Auto-generated method stub
//return super.createJavaSourceViewer(parent, verticalRuler,
// overviewRuler, isOverviewRulerVisible, styles);
//}
}


--
http://zclipse.org
Re: Bug in VerifyEvent handling? [message #212771 is a reply to message #212373] Thu, 18 March 2004 03:04 Go to previous messageGo to next message
Eclipse UserFriend
You are listening to two different kinds of events: VerifyKey and Verify
are different. VerifyKey allows you to check every typed character /
keyboard input, Verify allows you to veto changes about to be entered
into the text component.

-tom

Michael R Head wrote:
> I have the following Editor pasted below, where it _should_ input 'A'
> instead of 'a' and 'B' instead of 'b', however, only the untyped Listener
> appears to be working. According to the API on VerifyEvent, I should be
> able to change the text field to change the text that will be inserted.
> However, this only works when I do it to the Event object in my untyped
> Listener. Also, Event.character isn't set for the untyped Listener, but I
> don't know if it supposed to be or not.
>
> mike
Re: Bug in VerifyEvent handling? [message #212805 is a reply to message #212771] Thu, 18 March 2004 06:47 Go to previous message
Eclipse UserFriend
Originally posted by: burner.zclipse.org

On Thu, 18 Mar 2004 09:04:53 +0100, Tom Eicher wrote:

> You are listening to two different kinds of events: VerifyKey and Verify
> are different. VerifyKey allows you to check every typed character /
> keyboard input, Verify allows you to veto changes about to be entered
> into the text component.


OK, fair enough, but then why does the documentation (in 3.0M7) for
VerifyEvent say that you can change the "text" field to change the text
that will be inserted? That's really what's confusing.

After looking closer, it's just this piece of documentation that is
misleading. VerifyEvent is used by two different listeners (VerifyListener
and VerifyKeyListener). As you say, VerifyListener lets you modify the
input from the user in the VerifyEvent (or abort processing of the event),
whereas the VerifyKeyListener is specific to StyledText and only allows
you to abort the processing of a key stroke.

VerifyKeyListener.verifyKey() explicitly says which fields of VerifyEvent
are used. Perhaps the documentation on VerifyEvent.text should not specify
how it will be used, and leave that up to the individual Listener
interfaces that will use the event.

Anyway, thanks for setting me straight, mike

> -tom
>

--
http://zclipse.org
Previous Topic:http://eclipse.org/downloads/index.php is down?
Next Topic:eclipse.org website broken with Mozilla
Goto Forum:
  


Current Time: Wed Jun 18 17:21:40 EDT 2025

Powered by FUDForum. Page generated in 0.03428 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top