KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > visualization > graphics > primitive > GDimension


1 /*
2
3 [The "BSD licence"]
4 Copyright (c) 2005 Jean Bovet
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10
11 1. Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16 3. The name of the author may not be used to endorse or promote products
17 derived from this software without specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 */

31
32 package org.antlr.works.visualization.graphics.primitive;
33
34 import org.antlr.works.visualization.graphics.GContext;
35
36 public class GDimension {
37
38     public String JavaDoc width = "";
39     public String JavaDoc up = "";
40     public String JavaDoc down = "";
41
42     private float cacheWidth = Float.MIN_VALUE;
43     private float cacheUp = Float.MIN_VALUE;
44     private float cacheDown = Float.MIN_VALUE;
45
46     public GDimension() {
47     }
48
49     public GDimension(GDimension dimension) {
50         this.width = dimension.width;
51         this.up = dimension.up;
52         this.down = dimension.down;
53     }
54
55     public GDimension(String JavaDoc width, String JavaDoc up, String JavaDoc down) {
56         this.width = width;
57         this.up = up;
58         this.down = down;
59     }
60
61     public void addWidth(String JavaDoc width) {
62         this.width = GLiteral.add(this.width, width);
63     }
64
65     public void addUp(String JavaDoc up) {
66         this.up = GLiteral.add(this.up, up);
67     }
68
69     public void addDown(String JavaDoc down) {
70         this.down = GLiteral.add(this.down, down);
71     }
72
73     public void maxWidth(String JavaDoc width) {
74         this.width = GLiteral.max(this.width, width);
75     }
76
77     public void maxUp(String JavaDoc height) {
78         this.up = GLiteral.max(this.up, height);
79     }
80
81     public void maxDown(String JavaDoc height) {
82         this.down = GLiteral.max(this.down, height);
83     }
84
85     public float getPixelWidth(GContext context) {
86         if(cacheWidth == Float.MIN_VALUE)
87             return context.getPixelValue(width);
88         else
89             return cacheWidth;
90     }
91
92     public float getPixelUp(GContext context) {
93         if(cacheUp == Float.MIN_VALUE)
94             return context.getPixelValue(up);
95         else
96             return cacheUp;
97     }
98
99     public float getPixelDown(GContext context) {
100         if(cacheDown == Float.MIN_VALUE)
101             return context.getPixelValue(down);
102         else
103             return cacheDown;
104     }
105
106     public float getPixelHeight(GContext context) {
107         return getPixelUp(context)+getPixelDown(context);
108     }
109
110     public void cache(GContext context) {
111         cacheWidth = context.getPixelValue(width);
112         cacheUp = context.getPixelValue(up);
113         cacheDown = context.getPixelValue(down);
114     }
115
116     public String JavaDoc toString() {
117         return "{ "+width+", "+up+"|"+down+" }";
118     }
119 }
120
Popular Tags