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

Last change on this file since 919 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 2.2 KB
Line 
1/**
2 * Vector.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.gui;
20
21import java.awt.Color;
22import java.awt.Dimension;
23import java.awt.Point;
24import java.text.NumberFormat;
25
26import org.expeditee.items.Item;
27import org.expeditee.items.UserAppliedPermission;
28
29public class Vector extends Overlay {
30
31 public Point Origin;
32
33 public float Scale;
34
35 public Color Foreground;
36
37 public Color Background;
38
39 public Item Source;
40
41 public Dimension Size;
42
43 public Vector(Frame overlay, UserAppliedPermission permission,
44 Float scale, Item source) {
45 super(overlay, permission);
46 Origin = source.getPosition();
47 Scale = scale;
48 Foreground = source.getColor();
49 Background = source.getBackgroundColor();
50 Source = source;
51 }
52
53 @Override
54 public boolean equals(Object o) {
55 if (o == null || o.getClass() != Vector.class)
56 return false;
57 Vector v = (Vector) o;
58
59 return v.Frame == Frame && Origin.equals(v.Origin)
60 && Scale == v.Scale && Foreground == v.Foreground
61 && Background == v.Background;
62 }
63
64 @Override
65 public int hashCode() {
66 return 0;
67 }
68
69 /**
70 * Converts the given x position to be relative to the overlay frame.
71 *
72 * @param x
73 * @return
74 */
75 public float getX(int x) {
76 return (x - Origin.x) / Scale;
77 }
78
79 public float getY(int y) {
80 return (y - Origin.y) / Scale;
81 }
82
83 public void setSize(int maxX, int maxY) {
84 Size = new Dimension(maxX, maxY);
85 }
86
87 public static NumberFormat getNumberFormatter() {
88 NumberFormat nf = NumberFormat.getInstance();
89 nf.setMaximumFractionDigits(4);
90 return nf;
91 }
92}
Note: See TracBrowser for help on using the repository browser.