33import java .awt .event .MouseEvent ;
44import java .util .ArrayList ;
55
6+
7+ import javax .swing .ImageIcon ;
8+
9+ import actions .InputDataForDataInputBoxAction ;
610import buttons .ToolButton ;
711import paintcomponents .PaintComponent ;
12+ import paintcomponents .data .DataInputTextfieldPaintComponent ;
813import settings .Defaults ;
914import ui .PaintPanel ;
1015import ui .icons .CustomIcons ;
@@ -64,10 +69,17 @@ public void mouseClicked(MouseEvent e) {
6469 * @param comp
6570 */
6671 public void selectComponent (PaintComponent comp ) {
72+
6773 comp .select (this );
74+
75+ // update the components listening to select tool
6876 for (SelectionToolListener selectionToolListener : listeners ) {
6977 selectionToolListener .selectionChanged ();
7078 }
79+
80+ // prompt data input if user double clicked on a selected data box
81+ doubleClickAction (comp );
82+
7183 panel .repaint ();
7284 }
7385
@@ -78,6 +90,11 @@ public void selectComponent(PaintComponent comp) {
7890 * @param comp
7991 */
8092 public void deselectComponent (PaintComponent comp ) {
93+
94+ // check if double clicked, if so perform the action on the data box
95+ doubleClickAction (comp );
96+
97+ // then deselect the component
8198 comp .deselect (this );
8299 for (SelectionToolListener selectionToolListener : listeners ) {
83100 selectionToolListener .selectionChanged ();
@@ -285,4 +302,22 @@ public void removeSelectedComponent(PaintComponent pc){
285302 selectedComponents .remove (pc );
286303 }
287304
305+
306+ /**
307+ * Check if user double clicked a data box and it will prompt user to type
308+ * data if double clicked on a selected or de-selected data box
309+ *
310+ * @param comp
311+ */
312+ private void doubleClickAction (PaintComponent comp ) {
313+
314+ // data input box prompt right after a double click on the box
315+ if (comp instanceof DataInputTextfieldPaintComponent && getLastMouseEvent ().getClickCount () == 2
316+ && !getLastMouseEvent ().isConsumed ()) {
317+
318+ InputDataForDataInputBoxAction newAction = new InputDataForDataInputBoxAction (panel );
319+ newAction .performAction ();
320+ getLastMouseEvent ().consume ();
321+ }
322+ }
288323}
0 commit comments