|
Re: Delete Not working still: msg#00059java.netbeans.modules.graph.user
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); > } > } > } > > --------------------------------------------------------------------- > To unsubscribe, e-mail: > users-unsubscribe-Hi7mZnf3vbIkiw2pgZvNdR2eb7JE58TQ@xxxxxxxxxxxxxxxx > For additional commands, e-mail: > users-help-Hi7mZnf3vbIkiw2pgZvNdR2eb7JE58TQ@xxxxxxxxxxxxxxxx >
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Deleting widgets, David Kaspar |
|---|---|
| Next by Date: | Re: Delete Not working still, David Kaspar |
| Previous by Thread: | Re: Delete Not working still, David Kaspar |
| Next by Thread: | Question ?, Satyaranjan |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |