1 22 23 24 package net.sourceforge.chart2d; 25 26 27 import java.awt.*; 28 29 30 38 class FontArea extends Area { 39 40 41 private int fontPointModel; 42 private String fontName; 43 private int fontStyle; 44 private Color fontColor; 45 private Font font; 46 private boolean needsUpdate; 47 48 49 52 FontArea () { 53 54 setFontPointModel (12); 55 setFontName ("SansSerif"); 56 setFontStyle (Font.PLAIN); 57 setFontColor (Color.black); 58 resetFontAreaModel (true); 59 needsUpdate = true; 60 } 61 62 63 70 final void setFontPointModel (int p) { 71 72 needsUpdate = true; 73 fontPointModel = p; 74 } 75 76 77 83 final void setFontName (String n) { 84 85 needsUpdate = true; 86 fontName = n; 87 } 88 89 90 96 final void setFontStyle (int s) { 97 98 needsUpdate = true; 99 fontStyle = s; 100 } 101 102 103 108 final void setFontColor (Color c) { 109 110 needsUpdate = true; 111 fontColor = c; 112 } 113 114 115 119 final int getFontPointModel() { 120 121 return fontPointModel; 122 } 123 124 125 129 final String getFontName() { 130 131 return fontName; 132 } 133 134 135 139 final int getFontStyle() { 140 141 return fontStyle; 142 } 143 144 145 149 final Color getFontColor() { 150 151 return fontColor; 152 } 153 154 155 161 final Font getFont() { 162 163 updateFontArea(); 164 return font; 165 } 166 167 168 172 final boolean getFontAreaNeedsUpdate() { 173 174 return (needsUpdate || getAreaNeedsUpdate()); 175 } 176 177 178 190 final void resetFontAreaModel (boolean reset) { 191 192 needsUpdate = true; 193 resetAreaModel (reset); 194 } 195 196 197 201 final void updateFontArea () { 202 203 if (getFontAreaNeedsUpdate()) { 204 updateArea (); 205 update(); 206 } 207 needsUpdate = false; 208 } 209 210 211 216 void paintComponent (Graphics2D g2D) { 217 218 updateFontArea(); 219 super.paintComponent (g2D); 220 } 221 222 223 private void update() { 224 225 int fontPoint = 0; 226 if (fontPointModel > 0) { 227 fontPoint = applyRatio (fontPointModel, getRatio (LESSER)); 228 } 229 else fontPoint = 0; 230 font = new Font (fontName, fontStyle, fontPoint); 231 } 232 } | Popular Tags |