1 22 23 24 package net.sourceforge.chart2d; 25 26 27 import java.awt.*; 28 29 30 46 final class XAxisArea extends AxisArea { 47 48 49 private HorizontalTextListArea textList; 50 private Color ticksColor; 51 private int numTicks; 52 private boolean needsUpdate; 53 54 57 XAxisArea() { 58 59 textList = new HorizontalTextListArea(); 60 61 setAutoSizes (false, false); 62 setAutoJustifys (false, false); 63 setTitleJustifications (CENTER, BOTTOM); 64 setBackgroundExistence (false); 65 setBorderExistence (false); 66 setGapExistence (false); 67 68 setTicksSizeModel (new Dimension (3, 3)); 69 setType (LABELSBOTTOM); 70 setTicksColor (Color.black); 71 setNumTicks (0); 72 73 textList.setBulletsRelation (TOP); 74 textList.setAutoJustifys (false, false); 75 textList.setBorderExistence (false); 76 textList.setGapExistence (false); 77 textList.setBackgroundExistence (false); 78 textList.setBulletsOutline (false); 79 80 resetXAxisModel (true); 81 needsUpdate = true; 82 } 83 84 85 96 final void setType (int type) { 97 98 needsUpdate = true; 99 if (type == LABELSBOTTOM) textList.setBulletsAlignment (BETWEEN); 100 else textList.setBulletsAlignment (CENTERED); 101 } 102 103 104 108 final void setTicksColor (Color color) { 109 110 needsUpdate = true; 111 ticksColor = color; 112 } 113 114 115 122 final void setTicksAlignment (int alignment) { 123 124 textList.setBulletsAlignment (alignment); 125 } 126 127 128 134 final void setNumTicks (int num) { 135 136 needsUpdate = true; 137 numTicks = num; 138 } 139 140 141 149 final void setTicksSizeModel (Dimension size) { 150 151 needsUpdate = true; 152 textList.setBulletsSizeModel (size); 153 } 154 155 156 164 final Dimension getTicksSizeModel() { 165 return textList.getBulletsSizeModel(); 166 } 167 168 169 175 final void setBetweenTicksGapExistence (boolean existence) { 176 177 needsUpdate = true; 178 textList.setBetweenBulletsGapExistence (existence); 179 } 180 181 182 192 final void setBetweenTicksGapThicknessModel (int gap) { 193 194 needsUpdate = true; 195 textList.setBetweenBulletsGapThicknessModel (gap); 196 } 197 198 199 206 final void setBetweenTicksAndLabelsGapExistence (boolean existence) { 207 208 needsUpdate = true; 209 textList.setBetweenBulletsAndLabelsGapExistence (existence); 210 } 211 212 213 225 final void setBetweenTicksAndLabelsGapThicknessModel (int gap) { 226 227 needsUpdate = true; 228 textList.setBetweenBulletsAndLabelsGapThicknessModel (gap); 229 } 230 231 232 237 final HorizontalTextListArea getTextList() { 238 239 return textList; 240 } 241 242 243 249 final TextArea[] getLabels (Graphics2D g2D) { 250 251 updateXAxisArea (g2D); 252 return textList.getLabels (g2D); 253 } 254 255 256 263 final Rectangle[] getTicks (Graphics2D g2D) { 264 265 updateXAxisArea (g2D); 266 return textList.getBullets (g2D); 267 } 268 269 270 274 final int getBetweenTicksGapThicknessModel() { 275 276 return textList.getBetweenBulletsGapThicknessModel(); 277 } 278 279 280 284 final Color getTicksColor() { 285 286 return ticksColor; 287 } 288 289 290 294 final int getTicksAlignment() { 295 296 return textList.getBulletsAlignment(); 297 } 298 299 300 304 final boolean getXAxisAreaNeedsUpdate() { 305 306 return (needsUpdate || getTitledAreaNeedsUpdate() || 307 textList.getHorizontalTextListAreaNeedsUpdate()); 308 } 309 310 311 315 final void updateXAxisArea (Graphics2D g2D) { 316 317 if (getXAxisAreaNeedsUpdate()) { 318 updateTitledArea (g2D); 319 update (g2D); 320 textList.updateHorizontalTextListArea(g2D); 321 } 322 needsUpdate = false; 323 } 324 325 326 338 final void resetXAxisModel (boolean reset) { 339 340 needsUpdate = true; 341 resetTitledAreaModel (reset); 342 textList.resetHorizontalTextListAreaModel (reset); 343 } 344 345 346 350 final void paintComponent (Graphics2D g2D) { 351 352 updateXAxisArea (g2D); 353 super.paintComponent (g2D); 354 textList.paintComponent (g2D); 355 } 356 357 358 private void update (Graphics2D g2D) { 359 textList.setCustomRatio (WIDTH, true, getRatio (WIDTH)); 360 textList.setCustomRatio (HEIGHT, true, getRatio (HEIGHT)); 361 updateTickColors(); 362 updateMaxTextList (g2D); 363 textList.updateHorizontalTextListArea (g2D); 364 updateMinSizes (g2D); 365 updateMinTextList (g2D); 366 } 367 368 369 private void updateTickColors() { 370 371 Color[] tickColors = new Color[numTicks]; 372 for (int i = 0; i < numTicks; ++i) { 373 374 tickColors[i] = ticksColor; 375 } 376 377 textList.setBulletColors (tickColors); 378 } 379 380 381 private void updateMaxTextList (Graphics2D g2D) { 382 383 textList.setAllowSelfSize(true); 384 textList.setAutoSizes (getAutoSize(MAXMODEL), false); 385 Rectangle maxBounds = getMaxEntitledSpaceBounds (g2D); 386 textList.setSize (MAX, maxBounds.getSize()); 387 textList.setSizeLocation (MAX, maxBounds.getLocation()); 388 } 389 390 391 private void updateMinSizes (Graphics2D g2D) { 392 393 if (!getAutoSize(MIN)) { 394 Dimension titleSize = getTitleSize (MIN, g2D); 395 Dimension textListSize = textList.getSize (MIN); 396 int minWidth = titleSize.width > textListSize.width ? 397 titleSize.width : textListSize.width; 398 int minHeight; 399 if (titleSize.height > 0) { 400 minHeight = titleSize.height + 401 getBetweenTitleAndSpaceGapThickness (g2D) + textListSize.height; 402 } 403 else minHeight = titleSize.height + textListSize.height; 404 setSpaceSize (MIN, new Dimension (minWidth, minHeight)); 405 } 406 } 407 408 409 private void updateMinTextList (Graphics2D g2D) { 410 411 int spaceWidth = textList.getSize (MIN).width; 412 textList.setAllowSelfSize (false); 413 spaceWidth = spaceWidth < getSpaceSize(MIN).width ? 414 getSpaceSize(MIN).width : spaceWidth; 415 int betweenWidth = 416 textList.getSize (MIN).width - textList.getSpaceSize (MIN).width; 417 spaceWidth = spaceWidth - betweenWidth; 418 textList.setSpaceSize (MIN, 419 new Dimension (spaceWidth, textList.getSpaceSize(MIN).height)); 420 421 int spaceX = getSpaceSizeLocation(MIN).x; 422 int spaceY; 423 int betweenHeight = 424 textList.getSize (MIN).height - textList.getSpaceSize (MIN).height; 425 if (textList.getJustifications (VERTICAL) == TOP) 426 spaceY = getSpaceSizeLocation (MIN).y + betweenHeight / 2; 427 else 428 spaceY = getSpaceSizeLocation (MIN).y + getSpaceSize (MIN).height - 429 getTitleSize (MIN, g2D).height - 430 getBetweenTitleAndSpaceGapThickness (g2D) - 431 textList.getSize (MIN).height + betweenHeight / 2; 432 433 textList.setSpaceSizeLocation (MIN, new Point (spaceX, spaceY)); 434 } 435 } | Popular Tags |