1 22 23 24 package net.sourceforge.chart2d; 25 26 27 import java.awt.*; 28 29 30 46 final class YAxisArea extends AxisArea { 47 48 49 private VerticalTextListArea textList; 50 private Color ticksColor; 51 private int numTicks; 52 private boolean needsUpdate; 53 54 55 77 YAxisArea() { 78 79 textList = new VerticalTextListArea(); 80 81 setAutoSizes (false, false); 82 setAutoJustifys (false, false); 83 setTitleJustifications (LEFT, CENTER); 84 setTitleRotateLeft (true); 85 setBackgroundExistence (false); 86 setBorderExistence (false); 87 setGapExistence (false); 88 setTicksSizeModel (new Dimension (3, 3)); 89 setType (LABELSBOTTOM); 90 setTicksColor (Color.black); 91 setNumTicks (0); 92 textList.setBulletsRelation (TOP); 93 textList.setAutoJustifys (false, false); 94 textList.setBorderExistence (false); 95 textList.setGapExistence (false); 96 textList.setBackgroundExistence (false); 97 textList.setBulletsOutline (false); 98 resetYAxisModel (true); 99 needsUpdate = true; 100 } 101 102 103 114 final void setType (int type) { 115 116 needsUpdate = true; 117 if (type == LABELSBOTTOM) textList.setBulletsAlignment (CENTERED); 118 else textList.setBulletsAlignment (BETWEEN); 119 } 120 121 122 126 final void setTicksColor (Color color) { 127 128 needsUpdate = true; 129 ticksColor = color; 130 } 131 132 133 140 final void setTicksAlignment (int alignment) { 141 142 textList.setBulletsAlignment (alignment); 143 } 144 145 146 152 final void setNumTicks (int num) { 153 154 needsUpdate = true; 155 numTicks = num; 156 } 157 158 159 167 final void setTicksSizeModel (Dimension size) { 168 169 needsUpdate = true; 170 textList.setBulletsSizeModel (size); 171 } 172 173 174 182 final Dimension getTicksSizeModel() { 183 return textList.getBulletsSizeModel(); 184 } 185 186 187 193 final void setBetweenLabelsGapExistence (boolean existence) { 194 195 needsUpdate = true; 196 textList.setBetweenLabelsGapExistence (existence); 197 } 198 199 200 206 final void setBetweenTicksGapExistence (boolean existence) { 207 208 needsUpdate = true; 209 textList.setBetweenBulletsGapExistence (existence); 210 } 211 212 213 223 final void setBetweenTicksGapThicknessModel (int gap) { 224 225 needsUpdate = true; 226 textList.setBetweenBulletsGapThicknessModel (gap); 227 } 228 229 230 237 final void setBetweenTicksAndLabelsGapExistence (boolean existence) { 238 239 needsUpdate = true; 240 textList.setBetweenBulletsAndLabelsGapExistence (existence); 241 } 242 243 244 256 final void setBetweenTicksAndLabelsGapThicknessModel (int gap) { 257 258 needsUpdate = true; 259 textList.setBetweenBulletsAndLabelsGapThicknessModel (gap); 260 } 261 262 263 268 final VerticalTextListArea getTextList() { 269 270 return textList; 271 } 272 273 274 280 final TextArea[] getLabels (Graphics2D g2D) { 281 282 updateYAxisArea (g2D); 283 return textList.getLabels (g2D); 284 } 285 286 287 294 final Rectangle[] getTicks (Graphics2D g2D) { 295 296 updateYAxisArea (g2D); 297 return textList.getBullets (g2D); 298 } 299 300 301 305 final int getBetweenTicksGapThicknessModel() { 306 307 return textList.getBetweenBulletsGapThicknessModel(); 308 } 309 310 311 315 final Color getTicksColor() { 316 317 return ticksColor; 318 } 319 320 321 325 final int getTicksAlignment() { 326 327 return textList.getBulletsAlignment(); 328 } 329 330 331 335 final boolean getYAxisAreaNeedsUpdate() { 336 337 return (needsUpdate || getTitledAreaNeedsUpdate() || 338 textList.getVerticalTextListAreaNeedsUpdate()); 339 } 340 341 342 346 final void updateYAxisArea (Graphics2D g2D) { 347 348 if (getYAxisAreaNeedsUpdate()) { 349 updateTitledArea (g2D); 350 update (g2D); 351 textList.updateVerticalTextListArea(g2D); 352 } 353 needsUpdate = false; 354 } 355 356 357 369 final void resetYAxisModel (boolean reset) { 370 371 needsUpdate = true; 372 resetTitledAreaModel (reset); 373 textList.resetVerticalTextListAreaModel (reset); 374 } 375 376 377 381 final void paintComponent (Graphics2D g2D) { 382 383 updateYAxisArea (g2D); 384 super.paintComponent (g2D); 385 textList.paintComponent (g2D); 386 } 387 388 389 private void update (Graphics2D g2D) { 390 textList.setCustomRatio (WIDTH, true, getRatio (WIDTH)); 391 textList.setCustomRatio (HEIGHT, true, getRatio (HEIGHT)); 392 updateTickColors(); 393 updateMaxTextList (g2D); 394 textList.updateVerticalTextListArea (g2D); 395 updateMinSizes (g2D); 396 updateMinTextList (g2D); 397 } 398 399 400 private void updateTickColors() { 401 402 Color[] tickColors = new Color[numTicks]; 403 for (int i = 0; i < numTicks; ++i) { 404 405 tickColors[i] = ticksColor; 406 } 407 408 textList.setBulletColors (tickColors); 409 } 410 411 412 private void updateMaxTextList (Graphics2D g2D) { 413 414 textList.setAllowSelfSize (true); 415 textList.setAutoSizes (getAutoSize (MAXMODEL), false); 416 Rectangle maxBounds = getMaxEntitledSpaceBounds (g2D); 417 textList.setSize (MAX, maxBounds.getSize()); 418 textList.setSizeLocation (MAX, maxBounds.getLocation()); 419 } 420 421 422 private void updateMinSizes (Graphics2D g2D) { 423 424 if (!getAutoSize(MIN)) { 425 Dimension titleSize = getTitleSize (MIN, g2D); 426 Dimension textListSize = textList.getSize (MIN); 427 int minWidth; 428 if (titleSize.width > 0) { 429 minWidth = titleSize.width + getBetweenTitleAndSpaceGapThickness (g2D) + 430 textListSize.width; 431 } 432 else minWidth = titleSize.width + textListSize.width; 433 int minHeight = titleSize.height > textListSize.height ? 434 titleSize.height : textListSize.height; 435 setSpaceSize (MIN, new Dimension (minWidth, minHeight)); 436 } 437 } 438 439 440 private void updateMinTextList (Graphics2D g2D) { 441 442 int spaceHeight = textList.getSize (MIN).height; 443 textList.setAllowSelfSize (false); 444 spaceHeight = spaceHeight < getSpaceSize(MIN).height ? 445 getSpaceSize(MIN).height : spaceHeight; 446 int betweenHeight = 447 textList.getSize (MIN).height - textList.getSpaceSize (MIN).height; 448 spaceHeight = spaceHeight - betweenHeight; 449 textList.setSpaceSize (MIN, 450 new Dimension (textList.getSpaceSize(MIN).width, spaceHeight)); 451 452 int spaceY = getSpaceSizeLocation(MIN).y; 453 int spaceX; 454 int betweenWidth = 455 textList.getSize (MIN).width - textList.getSpaceSize (MIN).width; 456 if (textList.getJustifications (HORIZONTAL) == LEFT) 457 spaceX = getSpaceSizeLocation (MIN).x + getTitleSize (MIN, g2D).width + 458 getBetweenTitleAndSpaceGapThickness (g2D) + 459 textList.getSpaceSize (MIN).width + betweenWidth / 2; 460 else 461 spaceX = getSpaceSizeLocation (MIN).x + getSpaceSize (MIN).width - 462 textList.getSize (MIN).width + betweenWidth / 2; 463 464 textList.setSpaceSizeLocation (MIN, new Point (spaceX, spaceY)); 465 } 466 } | Popular Tags |