-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPickColorCommand.java
More file actions
38 lines (31 loc) · 1.07 KB
/
PickColorCommand.java
File metadata and controls
38 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.all.sandboxjava.designpatterns.command;
import com.all.sandboxjava.designpatterns.command.Canvas.Point;
public class PickColorCommand extends Command {
private String[] arguments;
@Override
void execute() throws IllegalArgumentException {
try {
//Decipher arguments
Canvas.pickColor(getPickColorLocationFromArgs());
}
catch (Exception e) {
e.printStackTrace();
throw new IllegalArgumentException("Illegal arguments passed to " + getCommandName() + " command!");
}
}
private Point getPickColorLocationFromArgs() {
return new Point(Integer.parseInt(arguments[0]), Integer.parseInt(arguments[1]));
}
@Override
void setArgs(String args) {
this.arguments = args.replaceAll(" ", "").split(Constants.COMMAND_ARGUMENT_DELIMETER);
}
@Override
String getCommandName() {
return "Pick Color";
}
@Override
public void undo() {
System.out.println("Undoing " + getCommandName());
}
}