-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphicsPainter.java
More file actions
81 lines (78 loc) · 2.22 KB
/
Copy pathGraphicsPainter.java
File metadata and controls
81 lines (78 loc) · 2.22 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* ============================================================================================
* Text version of a painter
* NAME: JANHAV KHANNA
* YOUR UPI: JKHA639
* DATE: 20/05/21
* DESCRIPTION: This is the graphicspainter class which handles the values required to allow the painter class to function properly.
* ============================================================================================
*/
import java.awt.*;
import java.awt.Graphics2D;
public class GraphicsPainter implements Painter {
private Graphics2D g;
public GraphicsPainter() {
}
public void setGraphics(Graphics g) {
this.g = (Graphics2D)g;
}
@Override
public void drawLine(int x1, int y1, int x2, int y2) {
g.drawLine(x1, y1, x2, y2);
}
@Override
public void drawRect(int x, int y, int width, int height) {
g.drawRect(x, y, width, height);
}
@Override
public void fillRect(int x, int y, int width, int height) {
g.fillRect(x, y, width, height);
}
@Override
public void drawOval(int x, int y, int width, int height) {
g.drawOval(x, y, width, height);
}
@Override
public void fillOval(int x, int y, int width, int height) {
g.fillOval(x, y, width, height);
}
@Override
public void setPaint(Color c) {
g.setPaint(c);
}
@Override
public void drawHandles(boolean isSelected, int x, int y, int width, int height) {
if (isSelected) {
g.setPaint(Color.black);
g.fillRect(x -2, y-2, 4, 4);
g.fillRect(x + width -2, y + height -2, 4, 4);
g.fillRect(x -2, y + height -2, 4, 4);
g.fillRect(x + width -2, y-2, 4, 4);
}
}
@Override
public void translate(int x, int y) {
g.translate(x, y);
}
@Override
public void drawString(String t, int x, int y){
g.drawString(t, x, y);
}
@Override
public void setColor(Color c){
g.setColor(c);
}
@Override
public void drawCenteredText(String t, int x, int y, int w, int h) {
FontMetrics fm = g.getFontMetrics();
int as = fm.getAscent();
int de = fm.getDescent();
int he = fm.getHeight();
int sw = fm.stringWidth(t);
int xd;
int yd;
xd = x + ((w - sw) / 2);
yd = y + ((h + (as - de))/2);
g.drawString(t,xd,yd);
}
}