11 messages in org.netbeans.graph.usersRe: Delete Not working still
FromSent OnAttachments
Chris PalmerMay 28, 2007 8:56 pm 
Chris PalmerMay 28, 2007 10:28 pm 
David KasparMay 29, 2007 7:12 am 
David KasparMay 29, 2007 7:12 am 
Chris PalmerMay 29, 2007 7:32 pm 
David KasparMay 30, 2007 1:55 am 
Chris PalmerMay 30, 2007 2:10 am 
David KasparMay 30, 2007 5:47 am 
Chris PalmerJun 6, 2007 5:57 am 
Joelle LamJun 6, 2007 8:19 am 
David KasparJun 6, 2007 8:35 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: Delete Not working stillActions...
From:David Kaspar (Davi@Sun.COM)
Date:May 30, 2007 5:47:57 am
List:org.netbeans.graph.users

Hi Chris,

I have tried the example and: 1) When you click on the JTextArea, then it takes the focus. 2) Therefore all key events from that moment are going to the JTextArea (not to the scene). 3) When you press Ctrl+Tab, then the focus is moved to the next JComponent which is the scene view. 4) Then you can use Delete key again.

Solution: Into the KeySelectProvider.select method, add following line: scene.getView ().requestFocus (); Also I would recommend you to add an action to the scene itself. The new action would be calling the "requestFocus" method too.

Regards, David

Chris Palmer wrote:

Hi David!

Well this exhibits the same behavior....when I select another widget it won't delete....

Chris public class EnterKeyProcessingTest { private static WidgetAction deleteAction = new KeyEventLoggerAction(); public static void main(String[] args) { ObjectScene scene = new ObjectScene(); LayerWidget main = new LayerWidget(scene); LayerWidget interaction = new LayerWidget(scene); scene.addChild(main); scene.addChild(interaction); main.setLayout(LayoutFactory.createVerticalFlowLayout()); // scene.setLayout(LayoutFactory.createVerticalFlowLayout ()); ComponentWidget label1 = new ComponentWidget(scene,new JTextArea("HI MOM")); label1.getActions().addAction(deleteAction);

label1.getActions().addAction(ActionFactory.createSelectAction(new KeySelectProvider())); main.addChild(label1); LabelWidget label2 = new LabelWidget(scene, "Second editable label."); label2.getActions().addAction(deleteAction);

label2.getActions().addAction(ActionFactory.createSelectAction(new KeySelectProvider())); main.addChild(label2); LabelWidget label3 = new LabelWidget(scene, "Third non-editable label. Should not receive any key event."); label3.getActions().addAction(deleteAction);

label3.getActions().addAction(ActionFactory.createSelectAction(new KeySelectProvider())); main.addChild(label3);

scene.setKeyEventProcessingType(EventProcessingType.FOCUSED_WIDGET_AND_ITS_PARENTS);

// scene.setFocusedWidget (label2); SceneSupport.show(scene); } private static class KeySelectProvider implements SelectProvider { public boolean isAimingAllowed(Widget widget, Point localLocation, boolean invertSelection) { return false; }

public boolean isSelectionAllowed(Widget widget, Point localLocation, boolean invertSelection) { return true; }

public void select(Widget widget, Point localLocation, boolean invertSelection) { Scene scene = widget.getScene(); scene.setFocusedWidget(widget); } } private static class KeyEventLoggerAction extends WidgetAction.Adapter { public State keyPressed(Widget widget, WidgetKeyEvent event) { System.out.println("KeyPressed at " + ((LabelWidget) widget).getLabel()); return State.REJECTED; } public State keyReleased(final Widget widget, WidgetKeyEvent event) { if (event.getKeyCode() == KeyEvent.VK_DELETE) { System.out.println("KeyReleased at " + ((LabelWidget) widget).getLabel()); final ObjectScene scene = (ObjectScene)widget.getScene(); scene.findObject(widget); widget.removeFromParent(); return State.CONSUMED; } return State.REJECTED; } public State keyTyped(Widget widget, WidgetKeyEvent event) { System.out.println("KeyTyped at " + ((LabelWidget) widget).getLabel()); return State.REJECTED; } } private static class LabelEditor implements TextFieldInplaceEditor { public boolean isEnabled(Widget widget) { return true; }

public String getText(Widget widget) { return ((LabelWidget) widget).getLabel(); } public void setText(Widget widget, String text) { ((LabelWidget) widget).setLabel(text); } } }