1+ /**
2+ * A custom SelectionFeedbackPolicy for connections.
3+ * Extends LineSelectionFeedbackPolicy to add visual feedback (color, stroke, outline)
4+ * while keeping the standard resize handles functionality.
5+ *
6+ * @extends draw2d.policy.line.LineSelectionFeedbackPolicy
7+ */
8+ var ConnectionSelectionFeedbackPolicy = draw2d . policy . line . LineSelectionFeedbackPolicy . extend ( {
9+
10+ NAME : "ConnectionSelectionFeedbackPolicy" ,
11+
12+ /**
13+ * Constructor
14+ */
15+ init : function ( attr , setter , getter ) {
16+ this . _super ( attr , setter , getter ) ;
17+ } ,
18+
19+ /**
20+ * Called when the figure is selected.
21+ * Store original attributes and apply selection feedback.
22+ *
23+ * @param {draw2d.Canvas } canvas - The canvas
24+ * @param {draw2d.Figure } figure - The figure being selected (should be a Connection)
25+ * @param {Boolean } isPrimarySelection - Whether this is the primary selection
26+ */
27+ onSelect : function ( canvas , figure , isPrimarySelection ) {
28+ this . _super ( canvas , figure , isPrimarySelection ) ;
29+
30+ // Store original state if not already stored
31+ if ( ! figure . _selectionFeedbackState ) {
32+ figure . _selectionFeedbackState = {
33+ stroke : figure . getStroke ( ) ,
34+ color : figure . getColor ( ) ,
35+ outlineStroke : figure . getOutlineStroke ( ) ,
36+ outlineColor : figure . getOutlineColor ( )
37+ } ;
38+ }
39+
40+ // Apply selection feedback
41+ var originalColor = figure . _selectionFeedbackState . color ;
42+ var originalStroke = figure . _selectionFeedbackState . stroke ;
43+
44+ // Make color lighter (60% lighter) - originalColor is already a Color object
45+ var lighterColor = originalColor . lighter ( 0.6 ) ;
46+
47+ // Apply the visual feedback using attr() for batch update
48+ figure . attr ( {
49+ stroke : originalStroke * 2 , // Double the stroke width
50+ color : lighterColor , // Lighter color
51+ outlineStroke : 3 , // Add outline
52+ outlineColor : "#000000" // Black outline
53+ } ) ;
54+ } ,
55+
56+ /**
57+ * Called when the figure is unselected.
58+ * Restore original attributes.
59+ *
60+ * @param {draw2d.Canvas } canvas - The canvas
61+ * @param {draw2d.Figure } figure - The figure being unselected
62+ */
63+ onUnselect : function ( canvas , figure ) {
64+ this . _super ( canvas , figure ) ;
65+
66+ // Restore original attributes if we have stored state
67+ if ( figure . _selectionFeedbackState ) {
68+ // Restore original attributes using attr() for batch update
69+ figure . attr ( {
70+ stroke : figure . _selectionFeedbackState . stroke ,
71+ color : figure . _selectionFeedbackState . color ,
72+ outlineStroke : figure . _selectionFeedbackState . outlineStroke ,
73+ outlineColor : figure . _selectionFeedbackState . outlineColor
74+ } ) ;
75+
76+ // Clean up stored state
77+ delete figure . _selectionFeedbackState ;
78+ }
79+ } ,
80+
81+ } ) ;
0 commit comments