

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
11 messages in org.netbeans.graph.usersRe: Delete Not working still| From | Sent On | Attachments |
|---|---|---|
| Chris Palmer | May 28, 2007 8:56 pm | |
| Chris Palmer | May 28, 2007 10:28 pm | |
| David Kaspar | May 29, 2007 7:12 am | |
| David Kaspar | May 29, 2007 7:12 am | |
| Chris Palmer | May 29, 2007 7:32 pm | |
| David Kaspar | May 30, 2007 1:55 am | |
| Chris Palmer | May 30, 2007 2:10 am | |
| David Kaspar | May 30, 2007 5:47 am | |
| Chris Palmer | Jun 6, 2007 5:57 am | |
| Joelle Lam | Jun 6, 2007 8:19 am | |
| David Kaspar | Jun 6, 2007 8:35 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: Delete Not working still | Actions... |
|---|---|---|
| From: | David Kaspar (Davi...@Sun.COM) | |
| Date: | May 29, 2007 7:12:20 am | |
| List: | org.netbeans.graph.users | |
Hi Chris,
The issue is in the your label widgets are in mainLayer and not directly under the Scene. Therefore you have an issue in KeyEventLoggerAction.keyPressed method, where you should change: widget.getScene().removeChild(widget); with: widget.remoreFromParent();
There is an "assert" in the Widget.removeChild method but you probably had assertion disabled in runtime. In the future I am going to convert assertions to exceptions, so you will notify the problem immediately.
After the change, it works correctly. The key-events are processed for all widgets. It is because: 1) you have assigned the KeyEventLoggerAction to all widgets, 2) you are using FOCUSED_WIDGET_AND_ITS_CHILDREN event processing type, 3) by default the Scene itself is set as the focused widget.
BTW: for this test you would not need to use ObjectScene at all. Scene would be enough, also you would not need interractionLayer widget as well as LabelEditor class.
Regards, David
Chris Palmer wrote:
Hello!
I reworked the EnterKeyProcessingTest to try and match a similiar implementation that I have. I got a null pointer.
Thats besides the fact. With a basic scene and no layer widgets I was able to get the a delete to work. I used EnterKeyProcessingTest a base. But then I realized that the EnterKeyProcessingTest wasn't using layer widgets. So this is my attempt at reproducing my impl.
Chris
package test.keyboard;
import java.awt.Point; import java.awt.event.KeyEvent; import org.netbeans.api.visual.action.ActionFactory; import org.netbeans.api.visual.action.SelectProvider; import org.netbeans.api.visual.action.TextFieldInplaceEditor; import org.netbeans.api.visual.action.WidgetAction; import org.netbeans.api.visual.action.WidgetAction.State; import org.netbeans.api.visual.layout.LayoutFactory; import org.netbeans.api.visual.model.ObjectScene; import org.netbeans.api.visual.widget.EventProcessingType; import org.netbeans.api.visual.widget.LabelWidget; import org.netbeans.api.visual.widget.LayerWidget; import org.netbeans.api.visual.widget.Scene; import org.netbeans.api.visual.widget.Widget; import test.SceneSupport;
/** * @author David Kaspar */ 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 ()); LabelWidget label1 = new LabelWidget(scene, "First non-editable label. Should not receive any key event."); 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_CHILDREN);
// 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(Widget widget, WidgetKeyEvent event) { if (event.getKeyCode() == KeyEvent.VK_DELETE) { System.out.println("KeyReleased at " + ((LabelWidget) widget).getLabel()); final Scene scene = widget.getScene(); scene.removeChild(widget); 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); } } }







