public void mouseClicked(MouseEvent e) {
// TODO stop using direct access to controller as a field, and start
// using get/set methods
if (SwingUtilities.isLeftMouseButton(e)) {
Node newNode = null;
switch (getAction()) {
case CREATE_CONTINUOUS_NODE: {
newNode = controller.insertContinuousNode(e.getX(), e.getY());
UShapeProbabilisticNode shape = new UShapeProbabilisticNode(
this, newNode, (int) newNode.getPosition().x
- newNode.getWidth() / 2, (int) newNode
.getPosition().y
- newNode.getHeight() / 2, newNode.getWidth(),
newNode.getHeight());
addShape(shape);
shape.setState(UShape.STATE_SELECTED, null);
showCPT(newNode);
}
break;
case CREATE_PROBABILISTIC_NODE: {
newNode = controller
.insertProbabilisticNode(e.getX(), e.getY());
UShapeProbabilisticNode shape = new UShapeProbabilisticNode(
this, newNode, (int) newNode.getPosition().x
- newNode.getWidth() / 2, (int) newNode
.getPosition().y
- newNode.getHeight() / 2, newNode.getWidth(),
newNode.getHeight());
addShape(shape);
shape.setState(UShape.STATE_SELECTED, null);
showCPT(newNode);
}
break;
case CREATE_DECISION_NODE: {
newNode = controller.insertDecisionNode(e.getX(), e.getY());
UShapeDecisionNode shape = new UShapeDecisionNode(this,
newNode, (int) newNode.getPosition().x
- newNode.getWidth() / 2, (int) newNode
.getPosition().y
- newNode.getHeight() / 2, newNode.getWidth(),
newNode.getHeight());
addShape(shape);
shape.setState(UShape.STATE_SELECTED, null);
showCPT(newNode);
}
break;
case CREATE_UTILITY_NODE: {
newNode = controller.insertUtilityNode(e.getX(), e.getY());
UShapeUtilityNode shape = new UShapeUtilityNode(
this,
newNode,
(int) newNode.getPosition().x - newNode.getWidth() / 2,
(int) newNode.getPosition().y - newNode.getHeight() / 2,
newNode.getWidth(), newNode.getHeight());
addShape(shape);
shape.setState(UShape.STATE_SELECTED, null);
showCPT(newNode);
}
break;
case ADD_PLUGIN_NODE: {
// build new node
newNode = this.getNodeDataTransferObject().getNodeBuilder()
.buildNode();
newNode.setPosition(e.getX(), e.getY());
// add new node into network
this.controller.getNetwork().addNode(newNode);
// build a new shape for new node