diff --git a/N2A/src/gov/sandia/n2a/ui/eq/GraphEdge.java b/N2A/src/gov/sandia/n2a/ui/eq/GraphEdge.java index 162cb14f..9d12c381 100644 --- a/N2A/src/gov/sandia/n2a/ui/eq/GraphEdge.java +++ b/N2A/src/gov/sandia/n2a/ui/eq/GraphEdge.java @@ -9,7 +9,6 @@ import java.awt.BasicStroke; import java.awt.Color; import java.awt.FontMetrics; -import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; @@ -74,11 +73,24 @@ public class GraphEdge protected static float strokeThicknessScaled; protected static int padNameBetweenScaled; // px + // Color + protected static Color colorForeground; // Normal color of lines and text + protected static Color colorActive; // Color of edges touching the lead selection + protected static Color colorDrag; // Color of edge that is either currently being dragged or would be if drag started now. + static { rescale (1); } + public static void updateUI () + { + // TODO: base these on canvas background color + colorForeground = Color.black; + colorActive = Color.blue; + colorDrag = new Color (0, 0xC0, 0); + } + public GraphEdge (GraphNode nodeFrom, NodePart partTo, String alias) { this.nodeFrom = nodeFrom; @@ -701,22 +713,25 @@ Not a true paintComponent(), but rather a subroutine of PanelEquationGraph.paint g gets disposed by the caller immediately after all GraphEdges are done drawing, so any changes we make to g are safe. **/ - public void paintComponent (Graphics g) + public void paintComponent (Graphics2D g2) { - Graphics2D g2 = (Graphics2D) g; + Color color = colorForeground; + if (nodeFrom.parent.focus == nodeFrom || nodeFrom.parent.focus == nodeTo) color = colorActive; + if (nodeFrom.parent.likelyTip == this) color = colorDrag; - g2.setColor (Color.black); + g2.setColor (color); if (line != null) g2.draw (line); if (head != null) { if (! headFill) g2.setColor (PanelEquationGraph.background); g2.fill (head); - g2.setColor (Color.black); + g2.setColor (color); g2.draw (head); } if (! text.isEmpty () && label != null) { + // TODO: base matte and text foreground color on canvas background g2.setColor (new Color (0xD0FFFFFF, true)); g2.fill (textBox); g2.setColor (Color.black); diff --git a/N2A/src/gov/sandia/n2a/ui/eq/GraphNode.java b/N2A/src/gov/sandia/n2a/ui/eq/GraphNode.java index 4b730526..78f10955 100644 --- a/N2A/src/gov/sandia/n2a/ui/eq/GraphNode.java +++ b/N2A/src/gov/sandia/n2a/ui/eq/GraphNode.java @@ -666,6 +666,14 @@ public void updateEdge (String alias, NodePart partTo, boolean kill) parent.repaint (paintRegion); } + public void repaintEdges () + { + Rectangle paintRegion = new Rectangle (0, 0, -1, -1); + for (GraphEdge ge : edgesIn ) paintRegion = paintRegion.union (ge.bounds); + for (GraphEdge ge : edgesOut) paintRegion = paintRegion.union (ge.bounds); + parent.repaint (paintRegion); + } + /** Sets bounds to current preferred location & size. Updates everything affected by the change. **/ @@ -1265,6 +1273,13 @@ public void focusGained (FocusEvent e) getTreeCellRendererComponent (getEquationTree ().tree, node, true, open, false, -2, true); restoreFocus (); // does repaint container.updateHighlights (node); + + if (parent.focus != GraphNode.this) + { + repaintEdges (); + if (parent.focus != null) parent.focus.repaintEdges (); + parent.focus = GraphNode.this; + } } public void focusLost (FocusEvent e) @@ -1278,6 +1293,12 @@ public void focusLost (FocusEvent e) getTreeCellRendererComponent (getEquationTree ().tree, node, GraphNode.this.selected, open, false, -2, false); GraphNode.this.repaint (); + + if (parent.focus == GraphNode.this) + { + parent.focus = null; + repaintEdges (); + } } }); } diff --git a/N2A/src/gov/sandia/n2a/ui/eq/PanelEquationGraph.java b/N2A/src/gov/sandia/n2a/ui/eq/PanelEquationGraph.java index d9444f56..c5c03d6d 100644 --- a/N2A/src/gov/sandia/n2a/ui/eq/PanelEquationGraph.java +++ b/N2A/src/gov/sandia/n2a/ui/eq/PanelEquationGraph.java @@ -89,7 +89,7 @@ public class PanelEquationGraph extends JScrollPane protected ColoredBorder border; protected NodeBase lastHighlightTarget; - protected static Color background = new Color (0xF0F0F0); // light gray + protected static Color background; public PanelEquationGraph (PanelEquations container) { @@ -367,6 +367,8 @@ public class GraphPanel extends JPanel protected GraphMouseListener mouseListener; protected List edges = new ArrayList (); // Note that GraphNodes are stored directly as Swing components. public Point offset = new Point (); // Offset from persistent coordinates to viewport coordinates. Add this to a stored (x,y) value to get non-negative coordinates that can be painted. + protected GraphNode focus; // Set by paint() for use by GraphNode.paintComponent() + protected GraphEdge likelyTip; // ditto protected JPopupMenu arrowMenu; protected GraphEdge arrowEdge; // Most recent edge when arrowMenu was activated. protected Point popupLocation; @@ -451,6 +453,7 @@ public void updateUI () if (zoom == 0) zoom = 1; // Workaround. Superclass calls updateUI() before our constructor runs. scaleFonts (); if (layout != null) layout.UIupdated = true; + GraphEdge.updateUI (); } public void scaleFonts () @@ -1754,9 +1757,17 @@ public void mouseWheelMoved (MouseWheelEvent me) public void mouseMoved (MouseEvent me) { if (container.locked) return; + GraphEdge e = graphPanel.findTipAt (me.getPoint ()); if (e == null) setCursor (Cursor.getDefaultCursor ()); else setCursor (Cursor.getPredefinedCursor (Cursor.MOVE_CURSOR)); + + GraphEdge f = graphPanel.likelyTip; + if (f == e) return; + graphPanel.likelyTip = e; + + if (e != null) graphPanel.repaint (e.bounds); + if (f != null) graphPanel.repaint (f.bounds); } public void mousePressed (MouseEvent me)