diff --git a/src/plugins/adufour/protocols/gui/block/BlockPanel.java b/src/plugins/adufour/protocols/gui/block/BlockPanel.java index 686b36c89dcd276088b6ca2d30a0f1a679d863fc..52e5180d10e1114cf9618f7ea60492d017720a48 100644 --- a/src/plugins/adufour/protocols/gui/block/BlockPanel.java +++ b/src/plugins/adufour/protocols/gui/block/BlockPanel.java @@ -621,7 +621,15 @@ public class BlockPanel extends JPanel implements ActionListener, BlockListener @Override public void blockVariableAdded(BlockDescriptor block, Var<?> variable) { - refresh(); + ThreadUtil.invokeNow(new Runnable() + { + @Override + public void run() + { + refreshNow(); + } + }); + // refresh(); } @Override diff --git a/src/plugins/adufour/protocols/gui/block/WorkFlowContainer.java b/src/plugins/adufour/protocols/gui/block/WorkFlowContainer.java index 2d895b098e2611181f9431a5326c44ef1ebe8a3c..c954e10cb37851b3d6c93d5a6bf04e7ab03ad276 100644 --- a/src/plugins/adufour/protocols/gui/block/WorkFlowContainer.java +++ b/src/plugins/adufour/protocols/gui/block/WorkFlowContainer.java @@ -324,10 +324,10 @@ public class WorkFlowContainer extends JLayeredPane implements WorkFlowListener, BlockDescriptor targetInnerlBlock = innerFlow.workFlow.getInputOwner(link.dstVar); - innerFlow.getBlockPanel(targetInnerlBlock).refresh(); + innerFlow.getBlockPanel(targetInnerlBlock).refreshNow(); } else - dstBlockPanel.refresh(); + dstBlockPanel.refreshNow(); repaint(); } @@ -582,7 +582,7 @@ public class WorkFlowContainer extends JLayeredPane implements WorkFlowListener, } @Override - public void linkAdded(WorkFlow targetWorkFlow, Link<?> link) + public void linkAdded(WorkFlow targetWorkFlow, final Link<?> link) { if (targetWorkFlow != this.workFlow) return; @@ -656,10 +656,10 @@ public class WorkFlowContainer extends JLayeredPane implements WorkFlowListener, BlockDescriptor targetInnerlBlock = innerFlow.workFlow.getInputOwner(link.dstVar); - innerFlow.getBlockPanel(targetInnerlBlock).refresh(); + innerFlow.getBlockPanel(targetInnerlBlock).refreshNow(); } else - dstBlockPanel.refresh(); + dstBlockPanel.refreshNow(); } repaint(); diff --git a/src/plugins/adufour/protocols/gui/link/Line.java b/src/plugins/adufour/protocols/gui/link/Line.java index 222636e5e4baf45188f3c52a7a37b9a04672fc75..5ac5ab36b479f3c3095b1e0e161c2c86221d3050 100644 --- a/src/plugins/adufour/protocols/gui/link/Line.java +++ b/src/plugins/adufour/protocols/gui/link/Line.java @@ -1,7 +1,5 @@ package plugins.adufour.protocols.gui.link; -import icy.system.thread.ThreadUtil; - import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; @@ -20,6 +18,7 @@ import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.awt.geom.Path2D; +import icy.system.thread.ThreadUtil; import plugins.adufour.blocks.lang.Link; import plugins.adufour.blocks.lang.WorkFlow; import plugins.adufour.protocols.gui.block.BlockPanel; @@ -29,66 +28,67 @@ import plugins.adufour.vars.lang.Var; @SuppressWarnings("serial") public abstract class Line extends Line2D.Float implements ComponentListener, MouseListener { - private final Link<?> link; - - private final Color typeColor; - - protected final BlockPanel srcPanel; - - protected final BlockPanel dstPanel; - + private final Link<?> link; + + private final Color typeColor; + + protected final BlockPanel srcPanel; + + protected final BlockPanel dstPanel; + // dashed line: // new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{9}, 0)); - private final Stroke stroke = new BasicStroke(2); - - private boolean isHighlighted = false; - - private final Path2D.Float path = new Path2D.Float(); - - private final Ellipse2D.Float closeButton = new Ellipse2D.Float(); - - private boolean isSelected = false; - - private Stroke selectedStroke = new BasicStroke(8); - + private final Stroke stroke = new BasicStroke(2); + + private boolean isHighlighted = false; + + private final Path2D.Float path = new Path2D.Float(); + + private final Ellipse2D.Float closeButton = new Ellipse2D.Float(); + + private boolean isSelected = false; + + private Stroke selectedStroke = new BasicStroke(8); + /** * Creates a line representing a link between two variables * * @param srcPanel - * the source panel of the link + * the source panel of the link * @param dstPanel - * the destination panel of the link + * the destination panel of the link * @param link - * the link between the two variables + * the link between the two variables * @throws IllegalArgumentException - * if the <code>link</code> argument is <code>null</code> + * if the <code>link</code> argument is <code>null</code> */ public Line(BlockPanel srcPanel, BlockPanel dstPanel, Link<?> link) throws IllegalArgumentException { - if (link == null) throw new IllegalArgumentException("link cannot be null"); - + if (link == null) + throw new IllegalArgumentException("link cannot be null"); + this.link = link; this.srcPanel = srcPanel; this.dstPanel = dstPanel; this.typeColor = DragDropZone.getColor(link.getType()); - + srcPanel.addComponentListener(this); dstPanel.addComponentListener(this); - + attachListeners(); - + update(); } - + /** * Creates a line exposing a variable outside a work flow. * * @param srcPanel - * the source panel of the link + * the source panel of the link * @param dstPanel - * the destination panel of the link + * the destination panel of the link * @param exposedVariable - * the exposed variable + * the exposed variable */ public Line(BlockPanel srcPanel, BlockPanel dstPanel, Var<?> exposedVariable) { @@ -96,7 +96,7 @@ public abstract class Line extends Line2D.Float implements ComponentListener, Mo this.srcPanel = srcPanel; this.dstPanel = dstPanel; this.typeColor = DragDropZone.getColor(exposedVariable.getType()); - + if (srcPanel.blockDesc.isWorkFlow() && ((WorkFlow) srcPanel.blockDesc.getBlock()).contains(dstPanel.blockDesc)) { // srcPanel contains dstPanel => listen only to dstPanel @@ -107,18 +107,27 @@ public abstract class Line extends Line2D.Float implements ComponentListener, Mo // dstPanel contains srcPanel => listen only to srcPanel srcPanel.addComponentListener(this); } - + attachListeners(); - + update(); } - + private void attachListeners() { - getP1Zone().addMouseListener(this); - getP2Zone().addMouseListener(this); + final DragDropZone p1z = getP1Zone(); + final DragDropZone p2z = getP2Zone(); + + if (p1z != null) + p1z.addMouseListener(this); + else + System.err.print("source drag zone null !"); + if (p2z != null) + p2z.addMouseListener(this); + else + System.err.print("destination drop zone null !"); } - + /** * @return the drag'drop zone corresponding to the first extremity of this line. This method is * called once when creating the line, in order to attach a mouse listener to the @@ -129,7 +138,7 @@ public abstract class Line extends Line2D.Float implements ComponentListener, Mo { return srcPanel.getDragZone(link.srcVar); } - + /** * @return the drag'drop zone corresponding to the second extremity of this line. This method is * called once when creating the line, in order to attach a mouse listener to the @@ -140,21 +149,21 @@ public abstract class Line extends Line2D.Float implements ComponentListener, Mo { return dstPanel.getDropZone(link.dstVar); } - + protected void updateP1() { Point loc = srcPanel.getDragZoneLocation(link.srcVar); x1 = loc.x; y1 = loc.y; } - + protected void updateP2() { Point loc = dstPanel.getDropZoneLocation(link.dstVar); x2 = loc.x; y2 = loc.y; } - + /** * updates the path describing the line and the shape and location of the close button * @@ -162,27 +171,29 @@ public abstract class Line extends Line2D.Float implements ComponentListener, Mo * @param theCloseButton */ public abstract void updateShape(Path2D thePath, Ellipse2D theCloseButton); - + public void paint(Graphics2D g) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - - if(isSelected) { - g.setColor(WorkFlowContainer.TRANSPARENT_BLUE); - g.setStroke(selectedStroke); - g.draw(path); + + if (isSelected) + { + g.setColor(WorkFlowContainer.TRANSPARENT_BLUE); + g.setStroke(selectedStroke); + g.draw(path); } - + g.setColor(typeColor); g.setStroke(stroke); - + path.reset(); updateShape(path, closeButton); g.draw(path); - - if (isHighlighted) paintCloseButton(g); + + if (isHighlighted) + paintCloseButton(g); } - + private void paintCloseButton(Graphics g) { Graphics2D g2 = (Graphics2D) g.create(); @@ -192,99 +203,101 @@ public abstract class Line extends Line2D.Float implements ComponentListener, Mo g2.drawLine((int) closeButton.x + 4, (int) closeButton.y + 8, (int) closeButton.x + 8, (int) closeButton.y + 4); g2.dispose(); } - + protected void updateCloseButtonShape(Shape s) { Rectangle r = s.getBounds(); closeButton.setFrame(r.x + r.width / 2 - 6, r.y + r.height / 2 - 6, 13, 13); } - + /** * Indicates if the location p is inside the virtual close button. This method can be used to * check whether the user has clicked on the close button * * @param p - * the point to check + * the point to check * @return true if p is within the virtual close button, false otherwise */ public boolean isOverCloseButton(Point p) { return isOverCloseButton(p.x, p.y); } - + /** * Indicates if the location p is inside the virtual close button. This method can be used to * check whether the user has clicked on the close button * * @param p - * the point to check + * the point to check * @return true if p is within the virtual close button, false otherwise */ public boolean isOverCloseButton(double x, double y) { return closeButton.contains(x, y); } - + public void dispose() { DragDropZone p1 = getP1Zone(); DragDropZone p2 = getP2Zone(); - if (p1 != null) p1.removeMouseListener(this); // TODO leak ? - if (p2 != null) p2.removeMouseListener(this); // TODO leak ? - + if (p1 != null) + p1.removeMouseListener(this); // TODO leak ? + if (p2 != null) + p2.removeMouseListener(this); // TODO leak ? + srcPanel.removeComponentListener(this); dstPanel.removeComponentListener(this); } - + @Override public void componentHidden(ComponentEvent arg0) { } - + @Override public void componentMoved(ComponentEvent arg0) { updateLine((BlockPanel) arg0.getSource()); } - + @Override public void componentResized(ComponentEvent arg0) { updateLine((BlockPanel) arg0.getSource()); } - + @Override public void componentShown(ComponentEvent arg0) { } - + @Override public void mouseClicked(MouseEvent e) { } - + @Override public void mousePressed(MouseEvent e) { } - + @Override public void mouseReleased(MouseEvent e) { } - + @Override public void mouseEntered(MouseEvent e) { setCustomColor(true); } - + @Override public void mouseExited(MouseEvent e) { setCustomColor(false); } - + /** * Sets whether the line should appear with a custom color (reflecting the type of transferred * data) or false if the default look'n'feel based color should be used. This method causes the @@ -297,7 +310,7 @@ public abstract class Line extends Line2D.Float implements ComponentListener, Mo isHighlighted = custom; srcPanel.getWorkFlowContainer().repaint(); } - + public void update() { // This has to be done on the EDT, in case P1 or P2 have just appeared @@ -313,16 +326,16 @@ public abstract class Line extends Line2D.Float implements ComponentListener, Mo } catch (IllegalComponentStateException e) { - + } catch (NullPointerException e) { - + } } }); } - + private void updateLine(BlockPanel panel) { if (panel == srcPanel) @@ -334,8 +347,9 @@ public abstract class Line extends Line2D.Float implements ComponentListener, Mo updateP2(); } } - - public void setSelected(boolean selected) { - isSelected = selected; + + public void setSelected(boolean selected) + { + isSelected = selected; } }