-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointCanvas.java
112 lines (99 loc) · 3.16 KB
/
PointCanvas.java
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import java.util.*;
import java.awt.*;
import javax.swing.*;
/**
* Implements a graphical canvas that displays a graph made from Linum and Profile objects.
*
* @author Nicholas R. Howe (modded by Sarah Abowitz/Lepidopterane)
* @version CSC 112, 18 April 2006 (modded 4.20.17)
*/
class PointCanvas extends JComponent {
private LinkedList<Linum> threads;
private LinkedList<Profile> profiles;
/** No-args constructor */
public PointCanvas() {
threads = new LinkedList<Linum>();
profiles = new LinkedList<Profile>();
}
/**
* Paints the graph.
*
* @param g The graphics object to draw with
*/
public void paintComponent(Graphics g) {
for (Linum t: threads){
g.setColor(t.getColor());
int x1 = (int) t.getHead().getX(), y1 = (int) t.getHead().getY();
int x2 = (int) t.getTail().getX(), y2 = (int) t.getTail().getY();
g.drawLine(x1, y1, x2, y2);
}
int cnt = 0;
for (Profile profile: profiles){
Point p = profile.getPoint();
g.setColor(profile.getHue());
int x = (int) p.getX();
int y = (int) p.getY();
int xtra = profile.getWidth()*2;
g.fillOval(x-5,y-5,10+xtra,10+xtra);
//String postring = "X:"+x+" Y:"+y;
cnt++;
//g.setColor(Color.BLACK);
//g.drawString(postring,x,y);
}
}
/**
* Securely adds a profile to profiles. @param p The Profile added.
*/
public void addProfile(Profile p) {profiles.add(p);}
/**
* Securely adds a linum to threads. @param t The Linum added.
*/
public void addLinum(Linum t) {threads.add(t);}
/**
* Securely clears all data in this element.
*/
public void clear() {
threads.clear();
profiles.clear();
}
/**
* Securely adds a profile to profiles.
* @param i The index of the target profile.
* @return The target profile.
*/
public Profile getProfile(int i){return profiles.get(i);}
/**
* Accesses profiles.
* @return profiles The LinkedList of profiles.
*/
public LinkedList<Profile> getProfileList() {return profiles;}
/**
* Checks if a given point is the point of any Profile in profiles.
* @param p The given point.
* @return The index of the given point in profiles.
* An index of -1 indicates that the given point is not in profiles.
*/
public int findPointIndex(Point p){
LinkedList<Point> pts = new LinkedList<Point>();
for (Profile pr: profiles){
pts.add(pr.getPoint());
}
return pts.indexOf(p);
}
/**
* The component will look bad if it is sized smaller than this
*
* @returns The minimum dimension
*/
public Dimension getMinimumSize() {
return new Dimension(500,3000);
}
/**
* The component will look best at this size
*
* @returns The preferred dimension
*/
public Dimension getPreferredSize() {
return new Dimension(400,300);
}
}