From a99f427c7a231fbbbe8ea6fb801eaac065bc028e Mon Sep 17 00:00:00 2001 From: Stephane Dallongeville <stephane@outlook.com> Date: Tue, 7 Apr 2020 12:33:39 +0200 Subject: [PATCH] fixed possible NPE --- .../protocols/gui/block/BlockPanel.java | 9 +++-- .../gui/block/WorkFlowContainer.java | 35 +++++++++++-------- .../protocols/gui/block/WorkFlowPanel.java | 2 ++ 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/plugins/adufour/protocols/gui/block/BlockPanel.java b/src/plugins/adufour/protocols/gui/block/BlockPanel.java index 52e5180..07e6f83 100644 --- a/src/plugins/adufour/protocols/gui/block/BlockPanel.java +++ b/src/plugins/adufour/protocols/gui/block/BlockPanel.java @@ -90,13 +90,18 @@ public class BlockPanel extends JPanel implements ActionListener, BlockListener if (dragging) { WorkFlow wf = workFlowPane.getWorkFlow(); + if (wf.isBlockSelected(blockDesc)) + { for (BlockDescriptor bd : wf.getBlockSelection()) { BlockPanel bp = workFlowPane.getBlockPanel(bd); - bp.setBounds(Math.max(0, dx - pressedX + bp.getX()), Math.max(0, dy - pressedY + bp.getY()), - bp.getWidth(), bp.getHeight()); + + if (bp != null) + bp.setBounds(Math.max(0, dx - pressedX + bp.getX()), Math.max(0, dy - pressedY + bp.getY()), + bp.getWidth(), bp.getHeight()); } + } else setBounds(Math.max(0, dx - pressedX + x), Math.max(0, dy - pressedY + y), w, h); } diff --git a/src/plugins/adufour/protocols/gui/block/WorkFlowContainer.java b/src/plugins/adufour/protocols/gui/block/WorkFlowContainer.java index c954e10..f07994a 100644 --- a/src/plugins/adufour/protocols/gui/block/WorkFlowContainer.java +++ b/src/plugins/adufour/protocols/gui/block/WorkFlowContainer.java @@ -315,21 +315,29 @@ public class WorkFlowContainer extends JLayeredPane implements WorkFlowListener, BlockPanel srcBlockPanel = getBlockPanel(link.srcBlock); BlockPanel dstBlockPanel = getBlockPanel(link.dstBlock); - linkLines.put(link, new RoundedSquareLine(srcBlockPanel, dstBlockPanel, link)); - - // refresh the target block - if (dstBlockPanel instanceof WorkFlowPanel) + if ((srcBlockPanel == null) || (dstBlockPanel == null)) { - WorkFlowContainer innerFlow = ((WorkFlowPanel) dstBlockPanel).innerFlowPane; - - BlockDescriptor targetInnerlBlock = innerFlow.workFlow.getInputOwner(link.dstVar); - - innerFlow.getBlockPanel(targetInnerlBlock).refreshNow(); + System.err.println("Warning: cannot recover link between " + link.srcBlock.getDefinedName() + + " and " + link.dstBlock.getDefinedName() + " !"); } else - dstBlockPanel.refreshNow(); + { + linkLines.put(link, new RoundedSquareLine(srcBlockPanel, dstBlockPanel, link)); - repaint(); + // refresh the target block + if (dstBlockPanel instanceof WorkFlowPanel) + { + WorkFlowContainer innerFlow = ((WorkFlowPanel) dstBlockPanel).innerFlowPane; + + BlockDescriptor targetInnerlBlock = innerFlow.workFlow.getInputOwner(link.dstVar); + + innerFlow.getBlockPanel(targetInnerlBlock).refreshNow(); + } + else + dstBlockPanel.refreshNow(); + + repaint(); + } } }, true); } @@ -638,15 +646,12 @@ public class WorkFlowContainer extends JLayeredPane implements WorkFlowListener, Line line = linkLines.remove(link); if (line == null) - { System.err.println("Warning: missing link, cannot be removed properly"); - } else - { line.dispose(); - } BlockPanel dstBlockPanel = getBlockPanel(link.dstBlock); + if (dstBlockPanel != null) { // refresh the target block diff --git a/src/plugins/adufour/protocols/gui/block/WorkFlowPanel.java b/src/plugins/adufour/protocols/gui/block/WorkFlowPanel.java index 27bc16d..b1114dc 100644 --- a/src/plugins/adufour/protocols/gui/block/WorkFlowPanel.java +++ b/src/plugins/adufour/protocols/gui/block/WorkFlowPanel.java @@ -297,6 +297,7 @@ public class WorkFlowPanel extends BlockPanel implements VarVisibilityListener public void run() { final BlockPanel ownerPanel = innerFlowPane.getBlockPanel(innerBlock); + exposingLinks.put(variable, new RoundedSquareLine(WorkFlowPanel.this, ownerPanel, variable) { @Override @@ -360,6 +361,7 @@ public class WorkFlowPanel extends BlockPanel implements VarVisibilityListener { final BlockPanel ownerPanel = innerFlowPane.getBlockPanel(innerBlock); + exposingLinks.put(variable, new RoundedSquareLine(ownerPanel, WorkFlowPanel.this, variable) { @Override -- GitLab