Skip to content

Commit 7bd18a1

Browse files
committed
GET BOTH TOOLS WORKING SIMULTANEOUSLY
1 parent 71f545f commit 7bd18a1

File tree

10 files changed

+173
-239
lines changed

10 files changed

+173
-239
lines changed

SoftwareConstruction_DataAbstraction/finalProject/SimpleDrawingPlayer-starter/.idea/workspace.xml

+110-216
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SoftwareConstruction_DataAbstraction/finalProject/SimpleDrawingPlayer-starter/src/model/Oval.java

+37
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,41 @@ public Oval(Point topLeft, MidiSynth midiSynth) {
1010
super(topLeft, midiSynth);
1111
PLAYING_COLOR = new Color(231, 22, 229);
1212
}
13+
14+
// EFFECTS: return true if this Oval contains the given Point point, else return false
15+
@Override
16+
public boolean contains(Point point) {
17+
final double TOL = 1.0e-6;
18+
double halfWidth = width / 2.0;
19+
double halfHeight = height / 2.0;
20+
double diff = 0.0;
21+
22+
if (halfWidth > 0.0) {
23+
diff = diff + sqrDiff(x + halfWidth, point.x) / (halfWidth * halfWidth);
24+
} else {
25+
diff = diff + sqrDiff(x + halfWidth, point.x);
26+
}
27+
if (halfHeight > 0.0) {
28+
diff = diff + sqrDiff(y + halfHeight, point.y) / (halfHeight * halfHeight);
29+
} else {
30+
diff = diff + sqrDiff(y + halfHeight, point.y);
31+
}
32+
return diff <= 1.0 + TOL;
33+
}
34+
35+
@Override
36+
protected void drawGraphics(Graphics g) {
37+
g.drawOval(x, y, width, height);
38+
}
39+
40+
@Override
41+
protected void fillGraphics(Graphics g) {
42+
g.fillOval(x, y, width, height);
43+
}
44+
45+
// Compute square of difference
46+
// EFFECTS: returns the square of the difference of num1 and num2
47+
private double sqrDiff(double num1, int num2) {
48+
return (num1 - num2) * (num1 - num2);
49+
}
1350
}

SoftwareConstruction_DataAbstraction/finalProject/SimpleDrawingPlayer-starter/src/model/Rectangle.java

+18
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,22 @@ public class Rectangle extends Shape {
99
public Rectangle(Point topLeft, MidiSynth midiSynth) {
1010
super(topLeft, midiSynth);
1111
}
12+
13+
@Override
14+
public boolean contains(Point point) {
15+
int point_x = point.x;
16+
int point_y = point.y;
17+
18+
return containsX(point_x) && containsY(point_y);
19+
}
20+
21+
@Override
22+
protected void drawGraphics(Graphics g) {
23+
g.drawRect(x, y, width, height);
24+
}
25+
26+
@Override
27+
protected void fillGraphics(Graphics g) {
28+
g.fillRect(x, y, width, height);
29+
}
1230
}

SoftwareConstruction_DataAbstraction/finalProject/SimpleDrawingPlayer-starter/src/model/Shape.java

+8-20
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
package model;
22

3-
43
import sound.MidiSynth;
54

65
import java.awt.*;
76

8-
97
public abstract class Shape {
10-
protected static Color PLAYING_COLOR;
8+
protected Color PLAYING_COLOR;
119

12-
private int x;
13-
private int y;
14-
private int width;
15-
private int height;
10+
protected int x;
11+
protected int y;
12+
protected int width;
13+
protected int height;
1614

1715
private boolean selected;
1816

@@ -57,12 +55,7 @@ public boolean containsY(int y) {
5755
}
5856

5957
// EFFECTS: return true if the given Point (x,y) is contained within the bounds of this Shape
60-
public boolean contains(Point point) {
61-
int point_x = point.x;
62-
int point_y = point.y;
63-
64-
return containsX(point_x) && containsY(point_y);
65-
}
58+
protected abstract boolean contains(Point point);
6659

6760
// REQUIRES: the x,y coordinates of the Point are larger than the x,y coordinates of the shape
6861
// MODIFIES: this
@@ -129,15 +122,10 @@ public void unselectAndStopPlaying() {
129122
}
130123

131124
//EFFECTS: draws the shape
132-
private void drawGraphics(Graphics g) {
133-
g.drawRect(x, y, width, height);
134-
}
125+
protected abstract void drawGraphics(Graphics g);
135126

136127
//EFFECTS: fills the shape
137-
private void fillGraphics(Graphics g) {
138-
g.fillRect(x, y, width, height);
139-
}
140-
128+
protected abstract void fillGraphics(Graphics g);
141129

142130
// EFFECTS: starts playing this Shape, where sound is dependent on the area/coordinates of the Shape
143131
private void play(){

SoftwareConstruction_DataAbstraction/finalProject/SimpleDrawingPlayer-starter/src/ui/tools/ShapeTool.java

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package ui.tools;
22

3-
4-
import model.Oval;
5-
import model.Rectangle;
63
import model.Shape;
74
import ui.DrawingEditor;
85

0 commit comments

Comments
 (0)