1 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 width = ""; 39 public String up = ""; 40 public String 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 width, String up, String down) { 56 this.width = width; 57 this.up = up; 58 this.down = down; 59 } 60 61 public void addWidth(String width) { 62 this.width = GLiteral.add(this.width, width); 63 } 64 65 public void addUp(String up) { 66 this.up = GLiteral.add(this.up, up); 67 } 68 69 public void addDown(String down) { 70 this.down = GLiteral.add(this.down, down); 71 } 72 73 public void maxWidth(String width) { 74 this.width = GLiteral.max(this.width, width); 75 } 76 77 public void maxUp(String height) { 78 this.up = GLiteral.max(this.up, height); 79 } 80 81 public void maxDown(String 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 toString() { 117 return "{ "+width+", "+up+"|"+down+" }"; 118 } 119 } 120 | Popular Tags |