55
66import javax .swing .ImageIcon ;
77
8+ import actions .InputDataForDataInputBoxAction ;
89import buttons .ToolButton ;
910import icons .LeftArrow ;
1011import paintcomponents .PaintComponent ;
12+ import paintcomponents .data .DataInputTextfieldPaintComponent ;
1113import settings .Defaults ;
1214import ui .PaintPanel ;
1315
@@ -63,10 +65,17 @@ public void mouseClicked(MouseEvent e) {
6365 * @param comp
6466 */
6567 public void selectComponent (PaintComponent comp ) {
68+
6669 comp .select (this );
70+
71+ // update the components listening to select tool
6772 for (SelectionToolListener selectionToolListener : listeners ) {
6873 selectionToolListener .selectionChanged ();
6974 }
75+
76+ // prompt data input if user double clicked on a selected data box
77+ doubleClickAction (comp );
78+
7079 panel .repaint ();
7180 }
7281
@@ -77,6 +86,11 @@ public void selectComponent(PaintComponent comp) {
7786 * @param comp
7887 */
7988 public void deselectComponent (PaintComponent comp ) {
89+
90+ // check if double clicked, if so perform the action on the data box
91+ doubleClickAction (comp );
92+
93+ // then deselect the component
8094 comp .deselect (this );
8195 for (SelectionToolListener selectionToolListener : listeners ) {
8296 selectionToolListener .selectionChanged ();
@@ -280,4 +294,22 @@ public void addSelectedComponent(PaintComponent pc){
280294 public void removeSelectedComponent (PaintComponent pc ){
281295 selectedComponents .remove (pc );
282296 }
297+
298+ /**
299+ * Check if user double clicked a data box and it will prompt user to type
300+ * data if double clicked on a selected or de-selected data box
301+ *
302+ * @param comp
303+ */
304+ private void doubleClickAction (PaintComponent comp ) {
305+
306+ // data input box prompt right after a double click on the box
307+ if (comp instanceof DataInputTextfieldPaintComponent && getLastMouseEvent ().getClickCount () == 2
308+ && !getLastMouseEvent ().isConsumed ()) {
309+
310+ InputDataForDataInputBoxAction newAction = new InputDataForDataInputBoxAction (panel );
311+ newAction .performAction ();
312+ getLastMouseEvent ().consume ();
313+ }
314+ }
283315}
0 commit comments