source: trunk/src/org/expeditee/gui/Vector.java@ 454

Last change on this file since 454 was 454, checked in by davidb, 12 years ago

Refactored to use the new PermissionPair and UserAppliedPermission classes

File size: 1.5 KB
Line 
1package org.expeditee.gui;
2
3import java.awt.Color;
4import java.awt.Dimension;
5import java.awt.Point;
6import java.text.NumberFormat;
7
8import org.expeditee.items.Item;
9import org.expeditee.items.UserAppliedPermission;
10
11public class Vector extends Overlay {
12
13 public Point Origin;
14
15 public float Scale;
16
17 public Color Foreground;
18
19 public Color Background;
20
21 public Item Source;
22
23 public Dimension Size;
24
25 public Vector(Frame overlay, UserAppliedPermission permission,
26 Float scale, Item source) {
27 super(overlay, permission);
28 Origin = source.getPosition();
29 Scale = scale;
30 Foreground = source.getColor();
31 Background = source.getBackgroundColor();
32 Source = source;
33 }
34
35 @Override
36 public boolean equals(Object o) {
37 if (o == null || o.getClass() != Vector.class)
38 return false;
39 Vector v = (Vector) o;
40
41 return v.Frame == Frame && Origin.equals(v.Origin)
42 && Scale == v.Scale && Foreground == v.Foreground
43 && Background == v.Background;
44 }
45
46 @Override
47 public int hashCode() {
48 return 0;
49 }
50
51 /**
52 * Converts the given x position to be relative to the overlay frame.
53 *
54 * @param x
55 * @return
56 */
57 public float getX(int x) {
58 return (x - Origin.x) / Scale;
59 }
60
61 public float getY(int y) {
62 return (y - Origin.y) / Scale;
63 }
64
65 public void setSize(int maxX, int maxY) {
66 Size = new Dimension(maxX, maxY);
67 }
68
69 public static NumberFormat getNumberFormatter() {
70 NumberFormat nf = NumberFormat.getInstance();
71 nf.setMaximumFractionDigits(4);
72 return nf;
73 }
74}
Note: See TracBrowser for help on using the repository browser.