Skip to content

Commit 31110ae

Browse files
committed
re design history UI and undoRedoDialog
1 parent e706c5d commit 31110ae

22 files changed

Lines changed: 527 additions & 186 deletions

images/addCursor.png

-485 Bytes
Loading

images/redo.png

2.09 KB
Loading

images/undo.png

2.06 KB
Loading

src/actions/edit/undoredo/SharedUndoRedoActionManager.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,19 @@ public Stack<UndoRedoableInterface> getUndoStack() {
9191
public Stack<UndoRedoableInterface> getRedoStack() {
9292
return redoStack;
9393
}
94+
95+
/**
96+
* return the last item in undoStack
97+
*/
98+
public UndoRedoableInterface undoPeek(){
99+
return undoStack.peek();
100+
}
101+
102+
/**
103+
* return last item in redoStack
104+
*/
105+
public UndoRedoableInterface redoPeek(){
106+
return redoStack.peek();
107+
}
94108

95109
}

src/buttons/CustomJButton.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package buttons;
2+
3+
import java.awt.event.ActionEvent;
4+
import java.awt.event.ActionListener;
5+
6+
import javax.swing.ImageIcon;
7+
import javax.swing.JButton;
8+
9+
public class CustomJButton extends JButton{
10+
11+
private String buttonTitle;
12+
13+
public CustomJButton(String title){
14+
buttonTitle = title;
15+
setOpaque(false);
16+
setFocusPainted(false);
17+
setBorderPainted(false);
18+
}
19+
public void setCustomImageIcon(ImageIcon i){
20+
setIcon(i);
21+
setText("");
22+
23+
}
24+
25+
public void setButtonTitle(String title){
26+
buttonTitle = title;
27+
}
28+
29+
public String getButtonTitle(){
30+
return buttonTitle;
31+
}
32+
33+
}

src/buttons/ToolButton.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import javax.swing.JToggleButton;
99

1010
public class ToolButton extends JToggleButton {
11-
Dimension d = new Dimension(60,60);
11+
Dimension d = new Dimension(40,40);
1212

1313
public ToolButton(String str){
1414
super(str);
@@ -20,7 +20,7 @@ public ToolButton(){
2020
setOpaque(false);
2121
setFocusPainted(false);
2222
setBorderPainted(false);
23-
setButtonSize(new Dimension(60,60));
23+
setButtonSize(d);
2424
}
2525

2626

src/painttools/tools/ActionToolsInterface.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,19 @@
99
public interface ActionToolsInterface extends PaintToolsInterface, ActionListener {
1010

1111
/**
12-
* If you implements add paint actions,
13-
* 1. make sure override the actionPeformed method, to define the actions when
12+
* If you implement add paint action tools:
13+
*
14+
* 1. make sure override the actionPeformed method to define actions when
1415
* button is clicked.
1516
*
17+
* 2. modify mouseClicked method to defined actions to perform when click
18+
* on paintPanel
19+
*
20+
* 3. you can call setX and setY to set the starting point for paintComponent
21+
*
22+
* 4. you may need to call createButton in constructor to create a button for
23+
* this tool, and you can set icons for button in createButton.
24+
*
25+
*
1626
*/
1727
}

src/painttools/tools/AddClassTool.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import java.awt.event.ActionEvent;
44
import java.awt.event.MouseEvent;
55

6-
import javax.swing.ImageIcon;
7-
86
import actions.AddLazyJavaClassAction;
97
import buttons.ToolButton;
108
import ui.PaintPanel;
@@ -27,6 +25,9 @@ public AddClassTool(PaintPanel panel) {
2725
public void start(PaintPanel panel) {
2826
}
2927

28+
/**
29+
* create a toolButton for this tool, and set icons
30+
*/
3031
@Override
3132
public void createButton() {
3233
// TODO Auto-generated method stub
@@ -48,11 +49,15 @@ public void reset() {
4849

4950
}
5051

52+
/**
53+
* when mouse click paintPanel, add class dialog will pop up, and a class
54+
* component will be added to where mouse was clicked
55+
*/
5156
@Override
5257
public void mouseClicked(MouseEvent e) {
53-
// TODO Auto-generated method stub
5458
AddLazyJavaClassAction action = new AddLazyJavaClassAction(panel);
5559
if (action.canPerformAction()) {
60+
// set the starting point for class component
5661
action.setXY(e.getX(), e.getY());
5762
action.performAction();
5863
}
@@ -96,6 +101,9 @@ public void mouseMoved(MouseEvent e) {
96101

97102
}
98103

104+
/**
105+
* change the cursor when add button is clicked
106+
*/
99107
@Override
100108
public void actionPerformed(ActionEvent e) {
101109
panel.setNewCursor (CustomCursors.addComponentcursor());

src/painttools/tools/AddInputBoxTool.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public class AddInputBoxTool implements ActionToolsInterface {
1717
public AddInputBoxTool(PaintPanel panel) {
1818
this.panel = panel;
1919
createButton();
20-
21-
2220
}
2321

2422
@Override
2523
public void start(PaintPanel panel) {
2624
}
2725

28-
26+
/**
27+
* create a toolButton for this tool, and set icons
28+
*/
2929
@Override
3030
public void createButton() {
3131
// TODO Auto-generated method stub
@@ -46,11 +46,17 @@ public void reset() {
4646

4747
}
4848

49+
50+
/**
51+
* when mouse click paintPanel, a input box will be added to
52+
* where mouse was clicked
53+
*/
4954
@Override
5055
public void mouseClicked(MouseEvent e) {
5156

5257
AddDataInputBoxAction action = new AddDataInputBoxAction(panel);
5358
if(action.canPerformAction()){
59+
//set starting point for paint component
5460
action.setXY(e.getX(), e.getY());
5561
action.performAction();
5662
action.setDefaultXY();
@@ -95,6 +101,9 @@ public void mouseMoved(MouseEvent e) {
95101

96102
}
97103

104+
/**
105+
* change the cursor when add button is clicked
106+
*/
98107
@Override
99108
public void actionPerformed(ActionEvent e) {
100109
// TODO Auto-generated method stub

src/painttools/tools/AddOutputBoxTool.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import java.awt.event.ActionEvent;
44
import java.awt.event.MouseEvent;
55

6-
import javax.swing.ImageIcon;
7-
86
import actions.AddDataDisplayBoxAction;
97
import buttons.ToolButton;
108
import ui.PaintPanel;
@@ -26,6 +24,10 @@ public AddOutputBoxTool(PaintPanel panel) {
2624
@Override
2725
public void start(PaintPanel panel) {
2826
}
27+
28+
/**
29+
* create a toolButton for this tool, and set icons
30+
*/
2931
@Override
3032
public void createButton() {
3133
// TODO Auto-generated method stub
@@ -45,11 +47,17 @@ public void reset() {
4547

4648
}
4749

50+
51+
/**
52+
* when mouse click paintPanel, a display box will be added to
53+
* where mouse was clicked
54+
*/
4855
@Override
4956
public void mouseClicked(MouseEvent e) {
5057
// TODO Auto-generated method stub
5158
AddDataDisplayBoxAction action = new AddDataDisplayBoxAction(panel);
5259
if (action.canPerformAction()) {
60+
// set the starting point for paint component
5361
action.setXY(e.getX(), e.getY());
5462
action.performAction();
5563
action.setDefaultXY();
@@ -94,6 +102,9 @@ public void mouseMoved(MouseEvent e) {
94102

95103
}
96104

105+
/**
106+
* change the cursor when add button is clicked
107+
*/
97108
@Override
98109
public void actionPerformed(ActionEvent e) {
99110
panel.setNewCursor (CustomCursors.addComponentcursor());

0 commit comments

Comments
 (0)