| 1 |
|
package ca.spaz.gui; |
| 2 |
|
|
| 3 |
|
import java.awt.Rectangle; |
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
public class SpazPosition { |
| 9 |
|
public int leftA, rightA, topA, bottomA; |
| 10 |
|
public double leftR, rightR, topR, bottomR; |
| 11 |
|
|
| 12 |
0 |
public SpazPosition(){} |
| 13 |
|
|
| 14 |
0 |
public SpazPosition(SpazPosition copy) { |
| 15 |
0 |
this.leftA = copy.leftA; |
| 16 |
0 |
this.leftR = copy.leftR; |
| 17 |
0 |
this.rightA = copy.rightA; |
| 18 |
0 |
this.rightR = copy.rightR; |
| 19 |
0 |
this.topA = copy.topA; |
| 20 |
0 |
this.topR = copy.topR; |
| 21 |
0 |
this.bottomA = copy.bottomA; |
| 22 |
0 |
this.bottomR = copy.bottomR; |
| 23 |
0 |
} |
| 24 |
|
|
| 25 |
|
public void setHPos(double lR, int lA, class="keyword">double rR, class="keyword">int rA) { |
| 26 |
0 |
this.leftR = lR; |
| 27 |
0 |
this.leftA = lA; |
| 28 |
0 |
this.rightR = rR; |
| 29 |
0 |
this.rightA = rA; |
| 30 |
0 |
} |
| 31 |
|
|
| 32 |
|
public void setVPos(double tR, int tA, class="keyword">double bR, class="keyword">int bA) { |
| 33 |
0 |
this.topR = tR; |
| 34 |
0 |
this.topA = tA; |
| 35 |
0 |
this.bottomR = bR; |
| 36 |
0 |
this.bottomA = bA; |
| 37 |
0 |
} |
| 38 |
|
|
| 39 |
|
public Rectangle getRectangle(int width, class="keyword">int height) { |
| 40 |
0 |
int top = (class="keyword">int)(topR*height) + topA; |
| 41 |
0 |
int bottom = (class="keyword">int)(bottomR*height) + bottomA; |
| 42 |
0 |
int left = (class="keyword">int)(leftR*width) + leftA; |
| 43 |
0 |
int right = (class="keyword">int)(rightR*width) + rightA; |
| 44 |
0 |
return ( new Rectangle(left, top, (right - left), (bottom - top)) ); |
| 45 |
|
} |
| 46 |
|
|
| 47 |
|
public Rectangle getMinRectangle() { |
| 48 |
0 |
return ( new Rectangle(leftA, topA, (rightA - leftA), (bottomA - topA)) ); |
| 49 |
|
} |
| 50 |
|
|
| 51 |
|
public String toString() { |
| 52 |
0 |
return (leftA + ", " + rightA + ", " + topA + ", " + bottomA); |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
public void adjustLeft(int val, class="keyword">int width) { |
| 56 |
0 |
int cur = (class="keyword">int)(width * leftR); |
| 57 |
0 |
this.leftA = (val - cur); |
| 58 |
0 |
} |
| 59 |
|
|
| 60 |
|
public void adjustRight(int val, class="keyword">int width) { |
| 61 |
0 |
int cur = (class="keyword">int)(width * rightR); |
| 62 |
0 |
this.rightA = (val - cur); |
| 63 |
0 |
} |
| 64 |
|
|
| 65 |
|
public void adjustTop(int val, class="keyword">int height) { |
| 66 |
0 |
int cur = (class="keyword">int)(height * topR); |
| 67 |
0 |
this.topA = (val - cur); |
| 68 |
0 |
} |
| 69 |
|
|
| 70 |
|
public void adjustBottom(int val, class="keyword">int height) { |
| 71 |
0 |
int cur = (class="keyword">int)(height * bottomR); |
| 72 |
0 |
this.bottomA = (val - cur); |
| 73 |
0 |
} |
| 74 |
|
|
| 75 |
|
public boolean valid() { |
| 76 |
0 |
if ((topA + (topR*500)) > (bottomA + (bottomR*500))) return false; |
| 77 |
0 |
if ((leftA + (leftR*500)) > (rightA + (rightR*500))) return false; |
| 78 |
0 |
if (leftR < 0 || leftR > 1) return false; |
| 79 |
0 |
if (rightR < 0 || rightR > 1) return false; |
| 80 |
0 |
if (topR < 0 || topR > 1) return false; |
| 81 |
0 |
if (bottomR < 0 || bottomR > 1) return false; |
| 82 |
0 |
return true; |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
public String toXMLString() { |
| 87 |
0 |
StringBuffer sb = new StringBuffer(); |
| 88 |
0 |
sb.append("<position "); |
| 89 |
0 |
sb.append(" left_rel=\""+ leftR + '"'); |
| 90 |
0 |
sb.append(" left_abs=\""+ leftA + '"'); |
| 91 |
0 |
sb.append(" right_rel=\""+ rightR + '"'); |
| 92 |
0 |
sb.append(" right_abs=\""+ rightA + '"'); |
| 93 |
0 |
sb.append(" top_rel=\""+ topR + '"'); |
| 94 |
0 |
sb.append(" top_abs=\""+ topA + '"'); |
| 95 |
0 |
sb.append(" bottom_rel=\""+ bottomR + '"'); |
| 96 |
0 |
sb.append(" bottom_abs=\""+ bottomA + '"'); |
| 97 |
0 |
sb.append("/>\n"); |
| 98 |
0 |
return sb.toString(); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
} |