Skip to content

Commit e706c5d

Browse files
committed
tool set to selectTool when add component actions finished
1 parent 70ca9fd commit e706c5d

10 files changed

Lines changed: 70 additions & 76 deletions

File tree

src/painttools/toolbar/ToolBar.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,6 @@ public void actionPerformed(ActionEvent e) {
7979
addSeprator();
8080
add(button);
8181
}
82-
83-
/**
84-
* Adds a component tool to the toolbar. This method will add specific tool to the
85-
* tool bar, and an action listener associated with it
86-
*
87-
* @param tool
88-
*/
89-
private void addComponentTool(PaintToolsInterface tool) {
90-
ToolButton button = tool.getButton();
91-
buttons.add(button);
92-
button.addActionListener(new ActionListener() {
93-
94-
@Override
95-
public void actionPerformed(ActionEvent e) {
96-
setButtonSelection(e);
97-
select(tool);
98-
99-
//buttons.get(1).doClick();
100-
}
101-
});
102-
addSeprator();
103-
add(button);
104-
}
10582

10683
/**
10784
* Adds a ToolBarListener to this toolbar
@@ -148,10 +125,4 @@ public void addSeprator(){
148125
add(j);
149126
}
150127

151-
/**
152-
* change click selectTool button
153-
*/
154-
public void setSelectTool(){
155-
buttons.get(1).doClick();
156-
}
157128
}

src/painttools/tools/AddClassTool.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import buttons.ToolButton;
1010
import ui.PaintPanel;
1111
import ui.cursor.CustomCursors;
12+
import ui.icons.CustomIcons;
1213

1314
public class AddClassTool implements ActionToolsInterface {
1415

@@ -30,12 +31,8 @@ public void start(PaintPanel panel) {
3031
public void createButton() {
3132
// TODO Auto-generated method stub
3233
button = new ToolButton();
33-
34-
ImageIcon icon = new ImageIcon("./images/dot.png");
35-
button.setOriginalImage(icon);
36-
37-
ImageIcon icon2 = new ImageIcon("./images/dotselected.png");
38-
button.setSelectedImage(icon2);
34+
button.setOriginalImage(CustomIcons.arrow());
35+
button.setSelectedImage(CustomIcons.selectedArrow());
3936

4037
button.addActionListener(this);
4138

@@ -59,6 +56,7 @@ public void mouseClicked(MouseEvent e) {
5956
action.setXY(e.getX(), e.getY());
6057
action.performAction();
6158
}
59+
panel.setDefaultSelectTool();
6260

6361
}
6462

src/painttools/tools/AddInputBoxTool.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
package painttools.tools;
22

3-
import java.awt.Cursor;
4-
import java.awt.Image;
5-
import java.awt.Point;
6-
import java.awt.Toolkit;
73
import java.awt.event.ActionEvent;
84
import java.awt.event.MouseEvent;
95

10-
import javax.swing.ImageIcon;
11-
126
import actions.AddDataInputBoxAction;
137
import buttons.ToolButton;
148
import ui.PaintPanel;
159
import ui.cursor.CustomCursors;
10+
import ui.icons.CustomIcons;
1611

1712
public class AddInputBoxTool implements ActionToolsInterface {
1813

@@ -30,17 +25,13 @@ public AddInputBoxTool(PaintPanel panel) {
3025
public void start(PaintPanel panel) {
3126
}
3227

28+
3329
@Override
3430
public void createButton() {
3531
// TODO Auto-generated method stub
3632
button = new ToolButton();
37-
38-
ImageIcon icon = new ImageIcon("./images/dot.png");
39-
button.setOriginalImage(icon);
40-
41-
ImageIcon icon2 = new ImageIcon("./images/dotselected.png");
42-
button.setSelectedImage(icon2);
43-
33+
button.setOriginalImage(CustomIcons.arrow());
34+
button.setSelectedImage(CustomIcons.selectedArrow());
4435
button.addActionListener(this);
4536
}
4637

@@ -57,13 +48,14 @@ public void reset() {
5748

5849
@Override
5950
public void mouseClicked(MouseEvent e) {
60-
// TODO Auto-generated method stub
51+
6152
AddDataInputBoxAction action = new AddDataInputBoxAction(panel);
6253
if(action.canPerformAction()){
6354
action.setXY(e.getX(), e.getY());
6455
action.performAction();
6556
action.setDefaultXY();
6657
}
58+
panel.setDefaultSelectTool();
6759

6860
}
6961

src/painttools/tools/AddMethodTool.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import ui.PaintPanel;
1212
import ui.cursor.CustomCursors;
1313

14-
public class AddMethodTool implements PaintToolsInterface {
14+
public class AddMethodTool implements ActionToolsInterface {
1515

1616
private ToolButton button;
1717
private PaintPanel panel;
@@ -102,7 +102,14 @@ public void mouseDragged(MouseEvent e) {
102102

103103
@Override
104104
public void mouseMoved(MouseEvent e) {
105+
}
106+
107+
108+
@Override
109+
public void actionPerformed(ActionEvent e) {
110+
105111
panel.setNewCursor (CustomCursors.addComponentcursor());
112+
106113
}
107114

108115

src/painttools/tools/AddOutputBoxTool.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import buttons.ToolButton;
1010
import ui.PaintPanel;
1111
import ui.cursor.CustomCursors;
12+
import ui.icons.CustomIcons;
1213

1314
public class AddOutputBoxTool implements ActionToolsInterface {
1415

@@ -29,14 +30,8 @@ public void start(PaintPanel panel) {
2930
public void createButton() {
3031
// TODO Auto-generated method stub
3132
button = new ToolButton();
32-
33-
ImageIcon icon = new ImageIcon("./images/dot.png");
34-
button.setOriginalImage(icon);
35-
36-
ImageIcon icon2 = new ImageIcon("./images/dotselected.png");
37-
button.setSelectedImage(icon2);
38-
39-
33+
button.setOriginalImage(CustomIcons.arrow());
34+
button.setSelectedImage(CustomIcons.selectedArrow());
4035
button.addActionListener(this);
4136

4237
}
@@ -58,8 +53,8 @@ public void mouseClicked(MouseEvent e) {
5853
action.setXY(e.getX(), e.getY());
5954
action.performAction();
6055
action.setDefaultXY();
61-
//panel.toolSelected(panel.getSelectTool());
6256
}
57+
panel.setDefaultSelectTool();
6358

6459
}
6560

src/painttools/tools/DotTool.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import paintcomponents.SimplePoint;
88
import ui.PaintPanel;
9+
import ui.icons.CustomIcons;
910
import buttons.ToolButton;
1011

1112
public class DotTool implements PaintToolsInterface {
@@ -31,12 +32,8 @@ public void createButton() {
3132
// TODO Auto-generated method stub
3233

3334
button = new ToolButton();
34-
35-
ImageIcon icon = new ImageIcon("./images/dot.png");
36-
button.setOriginalImage(icon);
37-
38-
ImageIcon icon2 = new ImageIcon("./images/dotselected.png");
39-
button.setSelectedImage(icon2);
35+
button.setOriginalImage(CustomIcons.dot());
36+
button.setSelectedImage(CustomIcons.selectedDot());
4037

4138
}
4239
@Override

src/painttools/tools/LineTool.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import paintcomponents.data.DataTextPaintComponent;
1515
import paintcomponents.data.DataToPoint;
1616
import ui.PaintPanel;
17+
import ui.icons.CustomIcons;
1718
import actions.global.ActionName;
1819
import actions.global.GlobalPaintActionExecuter;
1920
import actions.global.globalactions.ConstructDataLineSegmentGlobalAction;
@@ -35,12 +36,8 @@ public void createButton() {
3536
// TODO Auto-generated method stub
3637

3738
button = new ToolButton();
38-
39-
ImageIcon icon = new ImageIcon("./images/line.png");
40-
button.setOriginalImage(icon);
41-
42-
ImageIcon icon2 = new ImageIcon("./images/lineselected.png");
43-
button.setSelectedImage(icon2);
39+
button.setOriginalImage(CustomIcons.line());
40+
button.setSelectedImage(CustomIcons.selectedLine());
4441

4542
}
4643

@@ -259,7 +256,6 @@ public void mouseMoved(MouseEvent e) {
259256
@Override
260257
public void start(PaintPanel panel) {
261258
this.panel = panel;
262-
263259
panel.getSelectTool().clearSelection();
264260
}
265261

src/painttools/tools/SelectTool.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import paintcomponents.PaintComponent;
1010
import settings.Defaults;
1111
import ui.PaintPanel;
12+
import ui.icons.CustomIcons;
1213
import ui.icons.LeftArrow;
1314

1415
public class SelectTool implements PaintToolsInterface {
@@ -252,10 +253,8 @@ public void start(PaintPanel panel) {
252253
@Override
253254
public void createButton() {
254255
button = new ToolButton();
255-
ImageIcon icon = new ImageIcon("./images/arrow.png");
256-
button.setOriginalImage(icon);
257-
ImageIcon icon2 = new ImageIcon("./images/arrowselected.png");
258-
button.setSelectedImage(icon2);
256+
button.setOriginalImage(CustomIcons.arrow());
257+
button.setSelectedImage(CustomIcons.selectedArrow());
259258

260259
}
261260
@Override

src/ui/PaintPanel.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,12 @@ public SelectTool getSelectTool() {
235235
public void setSelectTool(SelectTool selectTool) {
236236
this.selectTool = selectTool;
237237
}
238+
239+
/**
240+
* change selectedTool to be selectTool
241+
*/
242+
public void setDefaultSelectTool(){
243+
selectTool.getButton().doClick();
244+
}
238245

239246
}

src/ui/icons/CustomIcons.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ui.icons;
2+
3+
import javax.swing.ImageIcon;
4+
5+
public class CustomIcons {
6+
7+
8+
public static ImageIcon arrow(){
9+
return new ImageIcon("./images/arrow.png");
10+
}
11+
12+
public static ImageIcon selectedArrow(){
13+
return new ImageIcon("./images/arrowselected.png");
14+
}
15+
16+
public static ImageIcon line(){
17+
return new ImageIcon("./images/line.png");
18+
19+
}
20+
21+
public static ImageIcon selectedLine(){
22+
return new ImageIcon("./images/lineselected.png");
23+
}
24+
25+
public static ImageIcon dot(){
26+
return new ImageIcon("./images/dot.png");
27+
}
28+
29+
public static ImageIcon selectedDot(){
30+
return new ImageIcon("./images/dotselected.png");
31+
}
32+
}

0 commit comments

Comments
 (0)