-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLabel.java
More file actions
41 lines (35 loc) · 891 Bytes
/
Label.java
File metadata and controls
41 lines (35 loc) · 891 Bytes
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
import java.util.*;
import java.awt.*;
public class Label extends Polygon
{
public String label="";
public Point3D point;
public Label(Point3D p, String l)
{
super();
id="Label";
label=l;
point=p;
lines.add(new Line3D(point,point));
pan(new Point3D(0,0,0));
}
public void printPolygon(Graphics page, Point pt, double d)
{
if(!label.equals(""))
{
Point scrPt=getScreenPoint(lines.get(0).point1,pt,d);
page.setColor(color);
String [] lines=label.split("\n");
for(int i=0;i<lines.length;i++)
page.drawString(lines[i],(int)scrPt.x,(int)scrPt.y-(lines.length-1)*15+i*15);
}
}
public Point getScreenPoint(Point3D point, Point p, double d)
{
Vect direc= new Vect(p,new Point(point.x,point.y));
direc.multiply(d/(d+point.z));
if(point.z>=0)
return direc.getPointFrom(p);
return new Point(0,0);
}
}