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:Joelle Lam (Joel@Sun.COM)
Date:Jun 6, 2007 8:19:48 am
List:org.netbeans.graph.users

Are you sure the Scene has the focus?

Did you try CTRL-SHIFT-BREAK ( and confirm on the console that the SceneComponent has the focus)?

Regards Joelle

Chris Palmer wrote:

Hi David!

I am still striking out. I can't get my widgets to respond to a delete in the key action. Below is the code. Its really strange.

Chris

public class CanvasModel extends AbstractCanvasModel<DesignerHandle, Object> { private WidgetAction designSelect = createSelectAction(); private WidgetAction designDeselect = ActionFactory.createSelectAction(new DeselectionImpl()); private WidgetAction designAccept = ActionFactory.createAcceptAction(new AcceptProviderImpl()); private WidgetAction designMove; private WidgetAction designResize; private WidgetAction designDeleteAction = new KeyEventLoggerAction(); private WidgetAction hoverAction = createObjectHoverAction(); private LayerWidget backgroundLayer; private LayerWidget componentLayer; private LayerWidget interactionLayer;

/** Creates a new instance of CanvasModel */ public CanvasModel() { init(); }

private void init() { setBackground(Color.black); // Furthest back backgroundLayer = new LayerWidget(this); // components sit there. componentLayer = new LayerWidget(this); // moves occur here interactionLayer = new LayerWidget(this); setKeyEventProcessingType (EventProcessingType.FOCUSED_WIDGET_AND_ITS_CHILDREN);

addChild(backgroundLayer); addChild(componentLayer); addChild(interactionLayer); getActions().addAction(designAccept); getActions().addAction(designDeselect);

getActions().addAction(ActionFactory.createPopupMenuAction(createPopupMenuProvider()));

getActions().addAction(hoverAction); designResize = ActionFactory.createAlignWithResizeAction (componentLayer, interactionLayer, null); designMove = createMoveAction();

}

protected WidgetAction createMoveAction() { return ActionFactory.createAlignWithMoveAction (componentLayer, interactionLayer, null); }

protected Widget attachNodeWidget(DesignerHandle handle) { final DesignComponentWidget des = new DesignComponentWidget(this,handle.getRuntimeComponent().getViewDelegate().getComponent());

componentLayer.addChild(des); des.setBorder(createDesignBorder()); des.getActions().addAction(designDeleteAction); des.getActions().addAction(designSelect); des.getActions().addAction(designResize); des.getActions().addAction(designMove); des.getActions().addAction(hoverAction); attachDesignActions(des, handle); return des; }

protected Widget attachEdgeWidget(Object edge) { return null; }

protected void attachEdgeSourceAnchor(Object edge, DesignerHandle source, DesignerHandle target) { }

protected void attachEdgeTargetAnchor(Object edge, DesignerHandle source, DesignerHandle target) { }

public static final int BORDER_SIZE = 5;

public Border createDesignResizeBorder(DesignerHandle dh) { return CanvasBorderFactory.BORDER_SHADOW_SELECTED; }

public Border createDesignBorder() { return CanvasBorderFactory.BORDER_SHADOW_NORMAL; }

private class AcceptProviderImpl implements AcceptProvider { public ConnectorState isAcceptable(Widget widget, Point point, Transferable transferable) { if ( transferable.isDataFlavorSupported(PaletteTransferable.FLAVOUR)) { return ConnectorState.ACCEPT; } else return ConnectorState.REJECT; }

public void accept(Widget widget, Point point, Transferable transferable) { try { final DesignerHandle handle = (DesignerHandle)transferable.getTransferData(PaletteTransferable.FLAVOUR);

final Widget wid = addNode(handle); wid.setPreferredLocation(point); updatePreferredSize(handle, wid); onAccept(handle); // update to scene to show the widget just dropped as selected setFocusedObject(handle); userSelectionSuggested(Collections.singleton(handle),false); } catch (UnsupportedFlavorException ex) { // log.error("Unsupported flavor on drop"); // NOI18N } catch (IOException ex) { // log.error("IO Problem on drop"); // NOI18N } }

private void updatePreferredSize(final DesignerHandle handle, final Widget wid) {

Dimension dim = handle.getComponentDataBean().getPreferredSize(); if ( dim == null ) { dim = handle.getRuntimeComponent().getViewDelegate().getComponent().getPreferredSize();

} wid.setPreferredSize(new Dimension(dim.width + 10, dim.height + 10)); } }

private class KeyEventLoggerAction extends WidgetAction.Adapter {

public State keyPressed(Widget widget, WidgetKeyEvent event) { return State.REJECTED; }

public State keyTyped(Widget widget, WidgetKeyEvent event) { return State.REJECTED; }

public State keyReleased(Widget widget, WidgetKeyEvent event) { if (event.getKeyCode() == KeyEvent.VK_DELETE) { DesignerHandle handle = (DesignerHandle)CanvasModel.this.findObject(widget); if (handle == null) { return State.REJECTED; } if ( JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(null,"Are you sure you want to remove the widget?")) { CanvasModel.this.removeNode(handle); } return State.CONSUMED; }; return State.REJECTED; }

}

private class DeselectionImpl implements SelectProvider {

public boolean isAimingAllowed(Widget widget, Point localLocation, boolean invertSelection) { return false; }

public boolean isSelectionAllowed(Widget widget, Point localLocation, boolean invertSelection) { if (widget == CanvasModel.this) { return true; } return false; }

public void select(Widget widget, Point localLocation, boolean invertSelection) { if (widget == CanvasModel.this) { if (getFocusedObject() != null) {

findWidget(getFocusedObject()).setBorder(createDesignBorder()); } setFocusedObject(null); userSelectionSuggested(Collections.emptySet(), false); } }