Skip to content

Commit 341a025

Browse files
committed
Disabled keyboard events on component widgets (moving with arrows, deletion)
Should resolve the issues with deselection (selection of the background scene) and reselection (e.g. widget not responding to keyboard events after reselection), before reenabling keyboard interaction
1 parent d8958d6 commit 341a025

File tree

2 files changed

+68
-68
lines changed

2 files changed

+68
-68
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
1-
package org.uml.visual.widgets.actions;
2-
3-
import java.awt.Point;
4-
import java.awt.event.KeyEvent;
5-
import org.netbeans.api.visual.action.ActionFactory;
6-
import org.netbeans.api.visual.action.MoveProvider;
7-
import org.netbeans.api.visual.action.WidgetAction;
8-
import org.netbeans.api.visual.widget.Widget;
9-
import org.uml.model.ClassDiagram;
10-
import org.uml.visual.widgets.components.ComponentWidgetBase;
11-
12-
/**
13-
*
14-
* @author Boris Perović
15-
*/
16-
// TODO not detecting key events
17-
public class ComponentWidgetKeyboardAction extends WidgetAction.Adapter {
18-
19-
private final MoveProvider provider;
20-
21-
public ComponentWidgetKeyboardAction() {
22-
this.provider = ActionFactory.createDefaultMoveProvider();
23-
}
24-
25-
@Override
26-
public State keyTyped(Widget widget, WidgetKeyEvent event) {
27-
return super.keyTyped(widget, event); //To change body of generated methods, choose Tools | Templates.
28-
}
29-
30-
@Override
31-
public State mouseWheelMoved(Widget widget, WidgetMouseWheelEvent event) {
32-
return super.mouseWheelMoved(widget, event); //To change body of generated methods, choose Tools | Templates.
33-
}
34-
35-
@Override
36-
public WidgetAction.State keyPressed(Widget widget, WidgetAction.WidgetKeyEvent event) {
37-
Widget focused = widget.getScene().getFocusedWidget();
38-
if (focused.equals(widget)) {
39-
Point originalSceneLocation = provider.getOriginalLocation(widget);
40-
int newY = originalSceneLocation.y;
41-
int newX = originalSceneLocation.x;
42-
if (event.getKeyCode() == KeyEvent.VK_UP) {
43-
newY = newY - 20;
44-
} else if (event.getKeyCode() == KeyEvent.VK_DOWN) {
45-
newY = newY + 20;
46-
} else if (event.getKeyCode() == KeyEvent.VK_RIGHT) {
47-
newX = newX + 20;
48-
} else if (event.getKeyCode() == KeyEvent.VK_LEFT) {
49-
newX = newX - 20;
50-
} else if (event.getKeyCode() == KeyEvent.VK_DELETE) {
51-
ClassDiagram classDiagram = ((ComponentWidgetBase) widget).getComponent().getParentDiagram();
52-
classDiagram.removeComponentFromContainer(((ComponentWidgetBase) widget).getComponent());
53-
}
54-
provider.movementStarted(widget);
55-
provider.setNewLocation(widget, new Point(newX, newY));
56-
}
57-
return WidgetAction.State.CONSUMED;
58-
}
59-
60-
@Override
61-
public WidgetAction.State keyReleased(Widget widget, WidgetAction.WidgetKeyEvent event) {
62-
provider.movementFinished(widget);
63-
return WidgetAction.State.REJECTED;
64-
}
65-
}
1+
//package org.uml.visual.widgets.actions;
2+
//
3+
//import java.awt.Point;
4+
//import java.awt.event.KeyEvent;
5+
//import org.netbeans.api.visual.action.ActionFactory;
6+
//import org.netbeans.api.visual.action.MoveProvider;
7+
//import org.netbeans.api.visual.action.WidgetAction;
8+
//import org.netbeans.api.visual.widget.Widget;
9+
//import org.uml.model.ClassDiagram;
10+
//import org.uml.visual.widgets.components.ComponentWidgetBase;
11+
//
12+
///**
13+
// *
14+
// * @author Boris Perović
15+
// */
16+
//// TODO not detecting key events
17+
//public class ComponentWidgetKeyboardAction extends WidgetAction.Adapter {
18+
//
19+
// private final MoveProvider provider;
20+
//
21+
// public ComponentWidgetKeyboardAction() {
22+
// this.provider = ActionFactory.createDefaultMoveProvider();
23+
// }
24+
//
25+
// @Override
26+
// public State keyTyped(Widget widget, WidgetKeyEvent event) {
27+
// return super.keyTyped(widget, event); //To change body of generated methods, choose Tools | Templates.
28+
// }
29+
//
30+
// @Override
31+
// public State mouseWheelMoved(Widget widget, WidgetMouseWheelEvent event) {
32+
// return super.mouseWheelMoved(widget, event); //To change body of generated methods, choose Tools | Templates.
33+
// }
34+
//
35+
// @Override
36+
// public WidgetAction.State keyPressed(Widget widget, WidgetAction.WidgetKeyEvent event) {
37+
// Widget focused = widget.getScene().getFocusedWidget();
38+
// if (focused.equals(widget)) {
39+
// Point originalSceneLocation = provider.getOriginalLocation(widget);
40+
// int newY = originalSceneLocation.y;
41+
// int newX = originalSceneLocation.x;
42+
// if (event.getKeyCode() == KeyEvent.VK_UP) {
43+
// newY = newY - 20;
44+
// } else if (event.getKeyCode() == KeyEvent.VK_DOWN) {
45+
// newY = newY + 20;
46+
// } else if (event.getKeyCode() == KeyEvent.VK_RIGHT) {
47+
// newX = newX + 20;
48+
// } else if (event.getKeyCode() == KeyEvent.VK_LEFT) {
49+
// newX = newX - 20;
50+
// } else if (event.getKeyCode() == KeyEvent.VK_DELETE) {
51+
// ClassDiagram classDiagram = ((ComponentWidgetBase) widget).getComponent().getParentDiagram();
52+
// classDiagram.removeComponentFromContainer(((ComponentWidgetBase) widget).getComponent());
53+
// }
54+
// provider.movementStarted(widget);
55+
// provider.setNewLocation(widget, new Point(newX, newY));
56+
// }
57+
// return WidgetAction.State.CONSUMED;
58+
// }
59+
//
60+
// @Override
61+
// public WidgetAction.State keyReleased(Widget widget, WidgetAction.WidgetKeyEvent event) {
62+
// provider.movementFinished(widget);
63+
// return WidgetAction.State.REJECTED;
64+
// }
65+
//}

UMLVisual/src/org/uml/visual/widgets/components/ComponentWidgetBase.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.uml.visual.themes.Theme;
3232
import org.uml.visual.widgets.ClassDiagramScene;
3333
import org.uml.visual.widgets.actions.ComponentNameEditor;
34-
import org.uml.visual.widgets.actions.ComponentWidgetKeyboardAction;
34+
//import org.uml.visual.widgets.actions.ComponentWidgetKeyboardAction;
3535
import org.uml.visual.widgets.providers.ComponentConnectProvider;
3636

3737
/**
@@ -106,8 +106,8 @@ public ComponentWidgetBase(final ClassDiagramScene scene, ComponentBase componen
106106
// **** Actions ****
107107
// Connect action - CTRL + click
108108
getActions().addAction(ActionFactory.createExtendedConnectAction(scene.getInterractionLayer(), new ComponentConnectProvider()));
109-
// Keybord actions over components
110-
getActions().addAction(new ComponentWidgetKeyboardAction());
109+
// // Keybord actions over components
110+
// getActions().addAction(new ComponentWidgetKeyboardAction());
111111
// Select, resize, moveo and hover
112112
getActions().addAction(scene.createSelectAction());
113113

0 commit comments

Comments
 (0)