Skip to content

Commit 59cf778

Browse files
Merge pull request #128 from UCSDOalads/doubleClickPromptForDataInputBoxByAlex
Double click prompt for data input box by alex
2 parents d860c1b + fba3166 commit 59cf778

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/actions/InputDataForDataInputBoxAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public InputDataForDataInputBoxAction(PaintPanel panel) {
2121
public boolean canPerformAction() {
2222
ArrayList<PaintComponent> comps = panel.getSelectTool().getSelectedComponents();
2323
if(comps.size()!= 1) return false;
24-
if(comps.get(0) instanceof DataInputTextfieldPaintComponent){
24+
if (comps.get(0) instanceof DataInputTextfieldPaintComponent) {
2525
return true;
2626
}
2727
return false;

src/painttools/tools/SelectTool.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
import javax.swing.ImageIcon;
77

8+
import actions.InputDataForDataInputBoxAction;
89
import buttons.ToolButton;
910
import icons.LeftArrow;
1011
import paintcomponents.PaintComponent;
12+
import paintcomponents.data.DataInputTextfieldPaintComponent;
1113
import settings.Defaults;
1214
import 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

Comments
 (0)