1 7 package com.sun.java.swing.plaf.gtk; 8 9 import javax.swing.plaf.synth.*; 10 import java.awt.*; 11 import javax.swing.*; 12 import com.sun.java.swing.plaf.gtk.GTKConstants.ArrowType; 13 import com.sun.java.swing.plaf.gtk.GTKConstants.ExpanderStyle; 14 import com.sun.java.swing.plaf.gtk.GTKConstants.Orientation; 15 import com.sun.java.swing.plaf.gtk.GTKConstants.PositionType; 16 import com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType; 17 18 25 public class GTKDefaultEngine extends GTKEngine { 26 static final int[] DEFAULT_FOCUS_PATTERN = new int[] {1, 1}; 27 28 static int adjustAxisForComponentOrientation(JComponent c, 29 int axis) { 30 if (c.getComponentOrientation().isLeftToRight()) { 31 return axis; 32 } 33 switch (axis) { 34 case SwingConstants.EAST: 35 return SwingConstants.WEST; 36 case SwingConstants.WEST: 37 return SwingConstants.EAST; 38 } 39 return axis; 40 } 41 42 public void paintArrow(Graphics g, SynthContext context, Region id, 43 int state, ShadowType shadowType, ArrowType direction, 44 String info, int x, int y, int w, int h) { 45 int sizeW = w / 4 + 1; 46 int sizeH = h / 4 + 1; 47 int size = Math.max(2, Math.min(sizeW, sizeH)); 48 49 switch (direction) { 50 case UP: 51 case DOWN: 52 x += (w - size * 2 + 1) / 2; 53 y += (h - size) / 2; 54 break; 55 case LEFT: 56 case RIGHT: 57 x += (w - size) / 2; 58 y += (h - size * 2 + 1) / 2; 59 break; 60 } 61 62 GTKStyle style = (GTKStyle)context.getStyle(); 63 int i; 64 int arW = size * 2 - 2; 65 66 g.translate(x, y); 67 68 if (state == SynthConstants.DISABLED) { 69 g.setColor(style.getGTKColor(context, state, GTKColorType.WHITE)); 70 } 71 else { 72 g.setColor(style.getGTKColor(context, state, GTKColorType.FOREGROUND)); 73 } 74 75 switch(direction) { 76 case UP: 77 for(i = 0; i < size; i++) { 78 g.drawLine(i, size - i - 1, arW - i, size - i - 1); 79 } 80 break; 81 case DOWN: 82 for (i = 0; i < size; i++) { 83 g.drawLine(i, i, arW - i, i); 84 } 85 break; 86 case LEFT: 87 int j; 88 for (j = 0, i = size - 1; i >= 0; i--, j++) { 89 g.drawLine(i, j, i, arW - j); 90 } 91 break; 92 case RIGHT: 93 for (i = 0; i < size; i++) { 94 g.drawLine(i, i, i, arW - i); 95 } 96 break; 97 } 98 g.translate(-x, -y); 99 } 100 101 public void paintBox(Graphics g, SynthContext context, Region id, 102 int state, ShadowType shadowType, String info, 103 int x, int y, int w, int h) { 104 GTKStyle style = (GTKStyle)context.getStyle(); 105 if (info == "menuitem" && state == SynthConstants.MOUSE_OVER && 107 GTKLookAndFeel.is2_2()) { 108 paintBackground(g, context, id, state, 109 style.getGTKColor(context, SynthConstants.MOUSE_OVER, 110 GTKColorType.BACKGROUND), 111 x, y, w, h); 112 } 113 else { 114 paintBackground(g, context, id, state, 115 style.getGTKColor(context, state, 116 GTKColorType.BACKGROUND), x, y, w, h); 117 } 118 paintShadow(g, context, id, state, shadowType, info, x, y, w, h); 119 } 120 121 public void paintBoxGap(Graphics g, SynthContext context, Region id, 122 int state, ShadowType shadowType, String info, 123 int x, int y, int w, int h, PositionType boxGapType, int tabBegin, 124 int size) { 125 _paintBoxGap(context, g, state, shadowType, x, y, w, h, boxGapType, 126 tabBegin, size, GTKColorType.BACKGROUND, GTKColorType.LIGHT, 127 GTKColorType.BLACK, GTKColorType.DARK, false); 128 } 129 130 void _paintBoxGap(SynthContext context, Graphics g, int state, 131 ShadowType shadowType, int x, int y, int w, int h, 132 PositionType boxGapType, int tabBegin, int size, 133 ColorType backgroundType, ColorType upperLeftType, 134 ColorType bottomRightType, ColorType innerRightType, 135 boolean paintWhite) { 136 GTKStyle style = (GTKStyle)context.getStyle(); 137 138 paintBackground(g, context, context.getRegion(), state, 139 style.getGTKColor(context, state, backgroundType), 140 x, y, w, h); 141 int tabEnd = tabBegin + size; 142 143 Color upperLeft = style.getGTKColor(context, state, upperLeftType); 144 Color bottomRight = style.getGTKColor(context, state, bottomRightType); 145 Color innerRight = style.getGTKColor(context, state, innerRightType); 146 Color white = style.getGTKColor(context, state, GTKColorType.WHITE); 147 148 g.translate(x, y); 149 if (boxGapType == PositionType.TOP) { 150 g.setColor(bottomRight); 152 g.drawLine(0, h - 1, w - 1, h - 1); 153 g.setColor(innerRight); 154 g.drawLine(1, h - 2, w - 2, h - 2); 155 156 g.setColor(upperLeft); 158 g.drawLine(0, 0, 0, h - 2); 159 if (paintWhite) { 160 g.setColor(white); 161 g.drawLine(1, 0, 1, h - 3); 162 } 163 164 g.setColor(bottomRight); 166 g.drawLine(w - 1, 0, w - 1, h - 1); 167 g.setColor(innerRight); 168 g.drawLine(w - 2, 0, w - 2, h - 2); 169 170 if (tabBegin > 1) { 172 g.setColor(upperLeft); 173 g.drawLine(0, 0, tabBegin - 2, 0); 174 } 175 g.setColor(upperLeft); 176 g.drawLine(tabEnd - 1, 0, w - 2, 0); 177 if (paintWhite) { 178 g.setColor(white); 179 if (tabBegin > 0) { 180 g.drawLine(0, 1, tabBegin, 1); 181 } 182 g.drawLine(tabEnd, 1, w - 2, 1); 183 } 184 } 185 else if (boxGapType == PositionType.BOTTOM) { 186 g.setColor(upperLeft); 188 g.drawLine(0, 0, w - 1, 0); 189 if (paintWhite) { 190 g.setColor(white); 191 g.drawLine(0, 1, w - 1, 1); 192 } 193 194 g.setColor(upperLeft); 196 g.drawLine(0, 0, 0, h - 1); 197 if (paintWhite) { 198 g.setColor(white); 199 g.drawLine(1, 1, 1, h - 2); 200 } 201 202 g.setColor(bottomRight); 204 g.drawLine(w - 1, 0, w - 1, h - 1); 205 g.setColor(innerRight); 206 g.drawLine(w - 2, 1, w - 2, h - 2); 207 208 if (tabBegin > 1) { 210 g.setColor(bottomRight); 211 g.drawLine(0, h - 1, tabBegin - 2, h - 1); 212 g.setColor(innerRight); 213 g.drawLine(tabBegin - 1, h - 1, tabBegin - 1, h - 1); 214 g.drawLine(1, h - 2, tabBegin - 2, h - 2); 215 } 216 g.setColor(bottomRight); 217 g.drawLine(tabEnd - 1, h - 1, w - 1, h - 1); 218 g.setColor(innerRight); 219 g.drawLine(tabEnd - 2, h - 1, tabEnd - 2, h - 1); 220 g.drawLine(tabEnd - 1, h - 2, w - 2, h - 2); 221 } 222 else if (boxGapType == PositionType.RIGHT) { 223 g.setColor(upperLeft); 225 g.drawLine(0, 0, w - 1, 0); 226 if (paintWhite) { 227 g.setColor(white); 228 g.drawLine(0, 1, w - 1, 1); 229 } 230 231 g.setColor(bottomRight); 233 g.drawLine(0, h - 1, w - 1, h - 1); 234 g.setColor(innerRight); 235 g.drawLine(1, h - 2, w - 2, h - 2); 236 237 g.setColor(upperLeft); 239 g.drawLine(0, 0, 0, h - 2); 240 if (paintWhite) { 241 g.setColor(white); 242 g.drawLine(1, 1, 1, h - 3); 243 } 244 245 if (tabBegin > 1) { 246 g.setColor(bottomRight); 247 g.drawLine(w - 1, 0, w - 1, tabBegin - 2); 248 g.setColor(innerRight); 249 g.drawLine(w - 1, tabBegin - 1, w - 1, tabBegin - 1); 250 g.drawLine(w - 2, 1, w - 2, tabBegin - 2); 251 } 252 g.setColor(bottomRight); 253 g.drawLine(w - 1, tabEnd - 1, w - 1, h - 1); 254 g.setColor(innerRight); 255 g.drawLine(w - 1, tabEnd - 2, w - 1, tabEnd - 2); 256 g.drawLine(w - 2, tabEnd - 1, w - 2, h - 2); 257 } 258 else if (boxGapType == PositionType.LEFT) { 259 g.setColor(upperLeft); 261 g.drawLine(0, 0, w - 2, 0); 262 if (paintWhite) { 263 g.setColor(white); 264 g.drawLine(0, 1, w - 2, 1); 265 } 266 267 g.setColor(bottomRight); 269 g.drawLine(0, h - 1, w - 1, h - 1); 270 g.setColor(innerRight); 271 g.drawLine(1, h - 2, w - 2, h - 2); 272 273 g.setColor(bottomRight); 275 g.drawLine(w - 1, 1, w - 1, h - 1); 276 g.setColor(innerRight); 277 g.drawLine(w - 2, 0, w - 2, h - 2); 278 279 if (tabBegin > 1) { 281 g.setColor(upperLeft); 282 g.drawLine(0, 0, 0, tabBegin - 2); 283 } 284 g.setColor(upperLeft); 285 g.drawLine(0, tabEnd - 1, 0, h - 2); 286 if (paintWhite) { 287 g.setColor(white); 288 if (tabBegin > 1) { 289 g.drawLine(1, 0, 1, tabBegin - 1); 290 } 291 g.drawLine(1, tabEnd - 1, 1, h - 3); 292 } 293 } 294 g.translate(-x, -y); 295 } 296 297 public void paintCheck(Graphics g, SynthContext context, Region id, 298 int state, ShadowType shadowType, String info, 299 int x, int y, int w, int h) { 300 int componentState = context.getComponentState(); 301 GTKStyle style = (GTKStyle)context.getStyle(); 302 303 if ("checkbutton" == info) { 304 int checkState = ((componentState & SynthConstants.PRESSED) == 0) ? 305 SynthConstants.ENABLED : SynthConstants.PRESSED; 306 307 paintFlatBox(g, context, id, checkState, ShadowType.ETCHED_OUT, 308 info, x, y, w, h, ColorType.TEXT_BACKGROUND); 309 paintShadow(g, context, id, checkState, 310 ShadowType.IN, info, x, y, w, h); 311 } 312 313 g.translate(x, y); 314 315 int centerY = h / 2 - 1; 316 317 if ((componentState & SynthConstants.SELECTED) != 0) { 319 g.setColor(style.getGTKColor(context, state, 320 GTKColorType.FOREGROUND)); 321 g.drawLine(3, centerY + 2, 4, centerY + 2); 322 g.drawLine(5, centerY + 3, 6, centerY + 3); 323 g.drawLine(6, centerY + 2, 6, centerY + 4); 324 g.drawLine(7, centerY + 1, 7, centerY); 325 g.drawLine(7, centerY, 8, centerY); 326 g.drawLine(8, centerY, 8, centerY - 1); 327 g.drawLine(8, centerY - 1, 9, centerY - 1); 328 g.drawLine(9, centerY - 1, 9, centerY - 2); 329 330 if (!GTKLookAndFeel.is2_2()) { 331 if ((componentState & SynthConstants.PRESSED) != 0) { 332 g.setColor(style.getGTKColor(context, 333 SynthConstants.PRESSED, GTKColorType.DARK)); 334 } else { 335 g.setColor(style.getGTKColor(context, 336 SynthConstants.ENABLED, GTKColorType.DARK)); 337 } 338 } 339 g.drawLine(3, centerY + 1, 4, centerY + 1); 340 g.drawLine(4, centerY + 3, 4, centerY + 3); 341 g.drawLine(5, centerY + 2, 5, centerY + 2); 342 g.drawLine(6, centerY + 1, 6, centerY + 1); 343 g.drawLine(7, centerY + 2, 7, centerY + 2); 344 g.drawLine(10, centerY - 2, 10, centerY - 2); 345 } 346 g.translate(-x, -y); 347 } 348 349 public void paintExtension(Graphics g, SynthContext context, Region id, 350 int state, ShadowType shadowType, String info, 351 int x, int y, int w, int h, PositionType placement, int tabIndex) { 352 _paintExtension(context, g, state, shadowType, x, y, w, h, placement, 353 GTKColorType.LIGHT, GTKColorType.BACKGROUND, 354 GTKColorType.BLACK, GTKColorType.DARK, false,tabIndex); 355 } 356 357 void _paintExtension(SynthContext context, Graphics g, int state, 358 ShadowType shadowType, int x, int y, int w, int h, 359 PositionType placement, ColorType upperLeftType, 360 ColorType backgroundType, ColorType bottomRightType, 361 ColorType innerRightType, boolean paintWhite, int tabIndex) { 362 GTKStyle style = (GTKStyle)context.getStyle(); 363 Region region = context.getRegion(); 364 int xThickness = style.getXThickness(); 365 int yThickness = style.getYThickness(); 366 367 if (xThickness < 0 && yThickness < 0) { 368 return; 370 } 371 372 Color upperLeft = style.getGTKColor(context, state, upperLeftType); 373 Color background = style.getGTKColor(context, state, backgroundType); 374 Color bottomRight = style.getGTKColor(context, state, bottomRightType); 375 Color innerRight = style.getGTKColor(context, state, innerRightType); 376 Color white = style.getGTKColor(context, state, GTKColorType.WHITE); 377 378 int selectedIndex = ((JTabbedPane)context.getComponent()).getSelectedIndex(); 379 380 g.translate(x, y); 381 382 if (placement == PositionType.BOTTOM) { 385 paintBackground(g, context, region, state, background, 0, 1, w, h); 387 388 if (tabIndex == selectedIndex || tabIndex == 0) { 389 g.setColor(upperLeft); 390 g.drawLine(0, 1, 0, h - 1); 391 g.drawLine(1, 0, w - 2, 0); 392 if (paintWhite) { 393 g.setColor(white); 394 g.drawLine(1, 1, 1, h - 1); 395 g.drawLine(1, 1, w - 3, 1); 396 } 397 } else { 398 g.setColor(upperLeft); 399 g.drawLine(0, 0, w - 2, 0); 400 if (paintWhite) { 401 g.setColor(white); 402 g.drawLine(0, 1, w - 3, 1); 403 } 404 } 405 if ((tabIndex + 1) != selectedIndex) { 406 g.setColor(innerRight); 407 g.drawLine(w - 2, 2, w - 2, h - 1); 408 g.setColor(bottomRight); 409 g.drawLine(w - 1, 1, w - 1, h - 1); 410 } 411 412 } else if (placement == PositionType.TOP) { 413 paintBackground(g, context, region, state, background, 0, 0, w, h - 1); 415 416 if (tabIndex == selectedIndex || tabIndex == 0) { 417 g.setColor(upperLeft); 418 g.drawLine(0, 0, 0, h - 2); 419 g.setColor(bottomRight); 420 g.drawLine(1, h - 1, w - 2, h - 1); 421 g.setColor(innerRight); 422 g.drawLine(2, h - 2, w - 2, h - 2); 423 if (paintWhite) { 424 g.setColor(white); 425 g.drawLine(1, 0, 1, h - 2); 426 } 427 } else { 428 g.setColor(bottomRight); 429 g.drawLine(0, h - 1, w - 2, h - 1); 430 g.setColor(innerRight); 431 g.drawLine(0, h - 2, w - 2, h - 2); 432 if (paintWhite) { 433 g.setColor(white); 434 g.drawLine(0, 0, 0, h - 2); 435 } 436 } 437 if ((tabIndex + 1) != selectedIndex) { 438 g.setColor(bottomRight); 439 g.drawLine(w - 1, 0, w - 1, h - 2); 440 g.setColor(innerRight); 441 g.drawLine(w - 2, 0, w - 2, h - 2); 442 } 443 } else if (placement == PositionType.RIGHT) { 444 paintBackground(g, context, region, state, background, 1, 0, w, h); 446 447 if (tabIndex == selectedIndex || tabIndex == 0) { 448 g.setColor(upperLeft); 449 g.drawLine(1, 0, w - 1, 0); 450 g.drawLine(0, 1, 0, h - 2); 451 if (paintWhite) { 452 g.setColor(white); 453 g.drawLine(1, 1, w, 1); 454 g.drawLine(1, 1, 1, h - 3); 455 } 456 } else { 457 g.setColor(upperLeft); 458 g.drawLine(0, 0, 0, h - 2); 459 if (paintWhite) { 460 g.setColor(white); 461 g.drawLine(1, 1, 1, h - 3); 462 } 463 } 464 if ((tabIndex + 1) != selectedIndex) { 465 g.setColor(bottomRight); 466 g.drawLine(1, h - 1, w - 1, h - 1); 467 g.setColor(innerRight); 468 g.drawLine(2, h - 2, w - 1, h - 2); 469 } 470 } else if (placement == PositionType.LEFT) { 471 paintBackground(g, context, region, state, background, 0, 0, w - 1, h); 473 474 if (tabIndex == selectedIndex || tabIndex == 0) { 475 g.setColor(upperLeft); 476 g.drawLine(0, 0, w - 2, 0); 477 g.setColor(bottomRight); 478 g.drawLine(w - 1, 1, w - 1, h - 2); 479 g.setColor(innerRight); 480 g.drawLine(w - 2, 2, w - 2, h - 2); 481 if (paintWhite) { 482 g.setColor(white); 483 g.drawLine(0, 1, w - 2, 1); 484 g.drawLine(w - 2, 1, w - 2, h - 3); 485 } 486 } else { 487 g.setColor(bottomRight); 488 g.drawLine(w - 1, 0, w - 1, h - 2); 489 g.setColor(innerRight); 490 g.drawLine(w - 2, 0, w - 2, h - 2); 491 if (paintWhite) { 492 g.setColor(white); 493 g.drawLine(w - 2, 1, w - 2, h - 3); 494 } 495 } 496 if ((tabIndex + 1) != selectedIndex) { 497 g.setColor(bottomRight); 498 g.drawLine(0, h - 1, w - 2, h - 1); 499 g.setColor(innerRight); 500 g.drawLine(0, h - 2, w - 2, h - 2); 501 502 } 503 } 504 g.translate(-x, -y); 505 } 506 507 public void paintFlatBox(Graphics g, SynthContext context, Region id, 508 int state, ShadowType shadowType, String key, 509 int x, int y, int w, int h, ColorType colorType) { 510 GTKStyle style = (GTKStyle)context.getStyle(); 511 g.setColor(style.getGTKColor(context, state, colorType)); 512 513 if (key == "cell_odd") { 514 g.fillRect(x, y, w, h); 515 } 516 else { 517 paintBackground(g, context, id, state, g.getColor(), x, y, w, h); 518 } 519 520 if (key == "tooltip") { 521 g.setColor(Color.BLACK); 522 g.drawRect(x, y, w - 1, h - 1); 523 } 524 } 525 526 public void paintFocus(Graphics g, SynthContext context, Region id, 527 int state, String key, int x, int y, int w, int h) { 528 GTKStyle style = (GTKStyle)context.getStyle(); 529 int[] pattern = (int[])style.getClassSpecificValue( 530 context, "focus-line-pattern"); 531 int size = style.getClassSpecificIntValue(context, 532 "focus-line-width", 1); 533 534 if (pattern == null) { 535 pattern = DEFAULT_FOCUS_PATTERN; 536 } 537 if (size <= 0) { 538 return; 539 } 540 g.setColor(getFocusColor(context, state)); 541 542 _paintFocus(g, x, y, w, h, pattern, size); 543 } 544 545 void _paintFocus(Graphics g, int x, int y, int w, int h, int[] pattern, 546 int size) { 547 g.translate(x, y); 548 549 int initial = size / 2; 551 int offset = initial; 552 int index = 0; 553 554 int max1 = w - size; 555 int max2 = max1 + h - size; 556 int max3 = max2 + w - size; 557 int max4 = max3 + h; 558 559 while (offset < max4) { 560 int next = offset + pattern[index]; 561 562 if (index % 2 == 0) { 563 if (offset < max1) { 564 g.fillRect(offset, 0, Math.min(next, w) - offset, size); 566 offset = Math.min(next, max1); 567 } 568 if (offset != next && offset < max2) { 569 g.fillRect(w - size, offset - max1, size, 571 Math.min(max2, next) - offset); 572 offset = Math.min(max2, next); 573 } 574 if (offset != next && offset < max3) { 575 int x2 = w - (offset - max2); 577 int temp = Math.min(next - offset, max3 - offset); 578 g.fillRect(x2 - temp, h - size, temp, size); 579 offset += temp; 580 } 581 if (offset != next) { 582 int y2 = h - (offset - max3); 583 int temp = Math.min(next - offset, max4 - offset); 584 g.fillRect(0, y2 - temp, size, temp); 585 offset += temp; 586 } 587 } 588 else { 589 offset = next; 590 } 591 index = (index + 1) % pattern.length; 592 } 593 594 g.translate(-x, -y); 595 } 596 597 Color getFocusColor(SynthContext context, int state) { 598 return ((GTKStyle)context.getStyle()).getGTKColor( 599 context, state, ColorType.FOREGROUND); 600 } 601 602 public void paintHandle(Graphics g, SynthContext context, Region id, 603 int paintState, ShadowType shadowType, String info, 604 int x, int y, int w, int h, Orientation orientation) { 605 paintBox(g, context, id, paintState, shadowType, info, 606 x, y, w, h); 607 608 g.translate(x, y); 609 610 GTKStyle style = (GTKStyle)context.getStyle(); 611 Color lightColor = style.getGTKColor(context, paintState, 612 GTKColorType.LIGHT); 613 Color darkColor = style.getGTKColor(context, paintState, 614 GTKColorType.DARK); 615 Color blackColor = style.getGTKColor(context, paintState, 616 GTKColorType.BLACK); 617 int startX; 618 int startY; 619 if (info == "paned") { 620 JSplitPane splitPane = (JSplitPane)context.getComponent(); 621 622 int markerLength = 7 * 3 + 6 * 2; if (orientation == Orientation.HORIZONTAL) { 625 startX = w / 2 - markerLength / 2; 627 startY = splitPane.getDividerSize() / 2 - 1; 628 } else { 629 startX = splitPane.getDividerSize() / 2 - 1; 631 startY = h / 2 - markerLength / 2; 632 } 633 634 for (int i = 0; i < 7; i++) { 635 if (orientation == Orientation.HORIZONTAL) { 637 startX += 5; 638 } else { 639 startY += 5; 640 } 641 g.setColor(lightColor); 642 g.fillRect(startX, startY, 2, 2); 643 g.setColor(blackColor); 644 g.fillRect(startX + 1, startY + 1, 2, 2); 645 g.setColor(darkColor); 646 g.fillRect(startX + 1, startY + 1, 1, 1); 647 } 648 } else if (info == "handlebox") { 649 JToolBar tb = (JToolBar)context.getComponent(); 650 startX = 2; 651 startY = 2; 652 if (tb.getOrientation() == JToolBar.HORIZONTAL) { 653 while (startY < h) { 654 g.setColor(darkColor); 655 g.fillRect(startX + 1, startY + 1, 2, 2); 656 g.fillRect(startX + 4, startY + 2, 2, 2); 657 g.setColor(lightColor); 658 g.fillRect(startX, startY, 2, 2); 659 g.fillRect(startX + 3, startY + 1, 2, 2); 660 startY += 3; 661 } 662 } else { 663 boolean toggle = true; 664 while (startX < w) { 665 g.setColor(darkColor); 666 g.fillRect(startX + 1, startY + 1, 2, 2); 667 g.fillRect(startX + 1, startY + 4, 2, 2); 668 g.setColor(lightColor); 669 g.fillRect(startX, startY, 2, 2); 670 g.fillRect(startX, startY + 3, 2, 2); 671 startX += 3; 672 if (toggle) { 673 startY++; 674 toggle = false; 675 } else { 676 startY--; 677 toggle = true; 678 } 679 } 680 } 681 paintShadow(g, context, id, paintState, shadowType, info, 683 0, 0, w, h); 684 } 685 g.translate(-x, -y); 686 } 687 688 public void paintOption(Graphics g, SynthContext context, Region id, 689 int paintState, ShadowType shadowType, String info, 690 int x, int y, int w, int h) { 691 g.translate(x, y); 692 693 int componentState = context.getComponentState(); 694 int centerY = h / 2 - 1; 695 GTKStyle style = (GTKStyle)context.getStyle(); 696 697 int optionState = ((componentState & SynthConstants.PRESSED) == 0) ? 700 SynthConstants.ENABLED : SynthConstants.PRESSED; 701 g.setColor(style.getGTKColor(context, optionState, 702 GTKColorType.TEXT_BACKGROUND)); 703 704 if (context.getRegion() != Region.RADIO_BUTTON_MENU_ITEM) { 705 g.fillRect(3, centerY - 3, 9, 9); 707 g.fillRect(13, centerY - 1, 1, 4); 708 g.fillRect(12, centerY + 3, 1, 2); 709 g.fillRect(9, centerY + 6, 2, 1); 710 g.fillRect(5, centerY + 7, 4, 1); 711 712 g.setColor(style.getGTKColor(context, SynthConstants.ENABLED, 714 GTKColorType.DARK)); 715 g.fillRect(5, centerY - 5, 4, 1); 716 g.fillRect(3, centerY - 4, 3, 1); 717 g.fillRect(2, centerY - 3, 1, 2); 718 g.fillRect(1, centerY - 1, 1, 4); 719 g.fillRect(2, centerY + 4, 1, 1); 720 g.fillRect(3, centerY + 5, 2, 1); 721 g.fillRect(5, centerY + 6, 4, 1); 722 g.fillRect(9, centerY + 5, 2, 1); 723 g.fillRect(11, centerY + 3, 1, 2); 724 g.fillRect(12, centerY - 1, 1, 4); 725 g.fillRect(11, centerY - 3, 1, 2); 726 g.fillRect(10, centerY - 4, 1, 1); 727 728 g.setColor(style.getGTKColor(context, paintState, 730 GTKColorType.BLACK)); 731 g.fillRect(5, centerY - 4, 5, 1); 732 g.fillRect(10, centerY - 3, 1, 1); 733 g.fillRect(3, centerY - 3, 2, 1); 734 g.fillRect(3, centerY - 2, 1, 1); 735 g.fillRect(2, centerY - 1, 1, 5); 736 g.fillRect(3, centerY + 4, 1, 1); 737 } 738 739 if ((componentState & SynthConstants.SELECTED) != 0) { 741 g.setColor(style.getGTKColor(context, SynthConstants.ENABLED, 742 GTKColorType.FOREGROUND)); 743 g.fillRect(5, centerY, 5, 3); 744 g.fillRect(6, centerY - 1, 3, 1); 745 g.fillRect(6, centerY + 3, 3, 1); 746 } 747 g.translate(-x, -y); 748 } 749 750 public void paintShadow(Graphics g, SynthContext context, Region id, 751 int state, ShadowType shadowType, String info, 752 int x, int y, int w, int h) { 753 if (info == "buttondefault") { 754 g.setColor(((GTKStyle)context.getStyle()).getGTKColor(context, 756 state, GTKColorType.BLACK)); 757 g.drawRect(x, y, w - 1, h - 1); 758 return; 759 } 760 GTKStyle style = (GTKStyle)context.getStyle(); 761 JComponent c = context.getComponent(); 762 int xThickness = style.getXThickness(); 763 int yThickness = style.getYThickness(); 764 765 if (info == "trough" || 766 (info == "spinbutton" && c instanceof JButton)) { 767 xThickness = yThickness = 1; 769 } 770 771 if (xThickness < 0 && yThickness < 0) { 772 return; 774 } 775 Color upperLeft = null, innerLeft = null, bottomRight = null, 776 innerRight = null; 777 switch (shadowType) { 778 case IN: 779 if (info == "spinbutton" && c instanceof JButton) { 780 upperLeft = style.getGTKColor(context, state, 781 GTKColorType.DARK); 782 innerRight = upperLeft; 783 bottomRight = style.getGTKColor(context, state, 784 GTKColorType.BLACK); 785 } else { 786 upperLeft = style.getGTKColor(context, state, 787 GTKColorType.DARK); 788 innerLeft = style.getGTKColor(context, state, 789 GTKColorType.BLACK); 790 bottomRight = style.getGTKColor(context, state, 791 GTKColorType.LIGHT); 792 innerRight = style.getGTKColor(context, state, 793 GTKColorType.BACKGROUND); 794 } 795 break; 796 case OUT: 797 upperLeft = style.getGTKColor(context, state,GTKColorType.LIGHT); 798 innerLeft = style.getGTKColor(context, state, GTKColorType.BACKGROUND); 799 bottomRight = style.getGTKColor(context, state, GTKColorType.BLACK); 800 innerRight = style.getGTKColor(context, state,GTKColorType.DARK); 801 break; 802 default: 803 assert true : "Unknown shadow type!"; 804 } 805 if (info == "spinbutton" && c instanceof JButton) { 806 _paintSpinButtonShadow(g, x, y, w, h, xThickness, yThickness, 807 upperLeft, innerLeft, bottomRight, innerRight); 808 } else { 809 _paintShadow(g, x, y, w, h, xThickness, yThickness, 810 upperLeft, innerLeft, bottomRight, innerRight); 811 } 812 } 813 814 void _paintShadow(Graphics g, int x, int y, int w, int h, 815 int xThickness, int yThickness, Color upperLeft, 816 Color innerLeft, Color bottomRight, Color innerRight) { 817 g.translate(x, y); 818 g.setColor(upperLeft); 820 if (xThickness > 0) { 821 g.drawLine(0, 0, 0, h - 1); 822 } 823 if (yThickness > 0) { 824 g.drawLine(1, 0, w - 1, 0); 825 } 826 827 if (xThickness > 1 || yThickness > 1) { 829 g.setColor(innerLeft); 830 if (xThickness > 1) { 831 g.drawLine(1, 1, 1, h - 2); 832 } 833 if (yThickness > 1) { 834 g.drawLine(2, 1, w - 2, 1); 835 } 836 } 837 838 g.setColor(bottomRight); 840 if (xThickness > 0) { 841 g.drawLine(w - 1, 1, w - 1, h - 1); 842 } 843 if (yThickness > 0) { 844 g.drawLine(1, h - 1, w - 2, h - 1); 845 } 846 if (xThickness > 1 || yThickness > 1) { 848 g.setColor(innerRight); 849 if (xThickness > 1) { 850 g.drawLine(w - 2, 2, w - 2, h - 2); 851 } 852 if (yThickness > 1) { 853 g.drawLine(2, h - 2, w - 3, h - 2); 854 } 855 } 856 g.translate(-x, -y); 857 } 858 859 void _paintSpinButtonShadow(Graphics g, int x, int y, 860 int w, int h, int xThickness, int yThickness, Color upperLeft, 861 Color innerLeft, Color bottomRight, Color innerRight) { 862 g.translate(x, y); 863 864 g.setColor(upperLeft); 866 g.drawLine(0, 0, w - 1, 0); 867 g.setColor(innerRight); 869 g.drawLine(0, h - 1, w - 1, h - 1); 870 g.setColor(bottomRight); 872 g.drawLine(0, 0, 0, h - 1); 873 g.drawLine(w - 1, 0, w - 1, h - 1); 874 875 g.translate(-x, -y); 876 } 877 878 public void paintExpander(Graphics g, SynthContext context, Region id, 879 int state, ExpanderStyle expanderStyle, String info, 880 int x, int y, int w, int h) { 881 if (expanderStyle == ExpanderStyle.COLLAPSED) { 882 if (state != SynthConstants.MOUSE_OVER) { 883 paintHollowTriangle(context, g, state, 884 x, y, Math.min(w,h), 885 adjustAxisForComponentOrientation( 886 context.getComponent(), SwingConstants.EAST)); 887 } else { 888 } 889 } 890 else { 891 if (state != SynthConstants.MOUSE_OVER) { 892 paintHollowTriangle(context, g, state, 893 x, y, Math.min(w,h), SwingConstants.SOUTH); 894 } else { 895 } 896 } 897 } 898 899 private void paintHollowTriangle(SynthContext ss, Graphics g, int state, 900 int x, int y, int size, int direction) { 901 GTKStyle style = (GTKStyle)ss.getStyle(); 902 int mid, height, thick, i, j, up, down; 903 904 mid = (size / 2); 905 height = size / 2 + 1; 906 thick = Math.max(1, size / 7); 907 908 g.translate(x, y); 909 910 Color foreground = style.getGTKColor(ss, state, GTKColorType.FOREGROUND); 911 Color background = style.getGTKColor(ss, state, GTKColorType.BACKGROUND); 912 913 switch(direction) { 914 case SwingConstants.NORTH: 915 j = size / 2 + height / 2 - 1; 916 g.setColor(background); 918 for(i = height - 1; i > 0; i--) { 919 g.drawLine(mid - i + 1, j, mid + i - 1, j); 920 j--; 921 } 922 923 g.setColor(foreground); 924 j = size / 2 + height / 2 - 1; 925 down = thick - 1; 926 for (up = 0; up < thick; up++) { 928 g.drawLine(0 - down, j - up, size + down, j - up); 929 down--; 930 } 931 j--; 932 933 for(i = height - 1; i > 0; i--) { 935 for (up = 0; up < thick; up++ ) { 936 g.drawLine(mid - i + 1 - up, j, mid - i + 1 - up, j); 937 g.drawLine(mid + i - 1 + up, j, mid + i - 1 + up, j); 938 } 939 j--; 940 } 941 942 if (thick > 1) { 944 for (up = thick - 2; up >= 0; up--) { 945 g.drawLine(mid - up, j, mid + up, j); 946 j--; 947 } 948 } 949 break; 950 case SwingConstants.SOUTH: 951 j = size / 2 - height / 2 - 1; 952 g.setColor(background); 954 for (i = height - 1; i > 0; i--) { 955 g.drawLine(mid - i + 1, j, mid + i - 1, j); 956 j++; 957 } 958 959 g.setColor(foreground); 960 j = size / 2 - height / 2 - 1; 961 down = thick - 1; 962 for (up = 0; up < thick; up++) { 964 g.drawLine(0 - down, j + up, size + down, j + up); 965 down--; 966 } 967 j++; 968 969 for (i = height - 1; i > 0; i--) { 971 for (up = 0; up < thick; up++ ) { 972 g.drawLine(mid - i + 1 - up, j, mid - i + 1 - up, j); 973 g.drawLine(mid + i - 1 + up, j, mid + i - 1 + up, j); 974 } 975 j++; 976 } 977 978 if (thick > 1) { 980 for (up = thick - 2; up >= 0; up--) { 981 g.drawLine(mid - up, j, mid + up, j); 982 j++; 983 } 984 } 985 break; 986 case SwingConstants.WEST: 987 i = size / 2 + height / 2 - 1; 988 g.setColor(background); 990 for (j = height - 1; j > 0; j--) { 991 g.drawLine(i, mid - j + 1, i, mid + j - 1); 992 i--; 993 } 994 995 g.setColor(foreground); 996 i = size / 2 + height / 2 - 1; 997 down = thick - 1; 998 for (up = 0; up < thick; up++) { 1000 g.drawLine(i - up, 0 - down, i - up, size + down); 1001 down--; 1002 } 1003 i--; 1004 1005 for (j = height - 1; j > 0; j--) { 1007 for (up = 0; up < thick; up++) { 1008 g.drawLine(i, mid - j + 1 - up, i, mid - j + 1 - up); 1009 g.drawLine(i, mid + j - 1 + up, i, mid + j - 1 + up); 1010 } 1011 i--; 1012 } 1013 1014 if (thick > 1) { 1016 for (up = thick - 2; up >= 0; up--) { 1017 g.drawLine(i, mid - up, i, mid + up); 1018 i--; 1019 } 1020 } 1021 break; 1022 case SwingConstants.EAST: 1023 i = size / 2 - height / 2 - 1; 1024 1025 g.setColor(background); 1027 for (j = height - 1; j > 0; j--) { 1028 g.drawLine(i, mid - j + 1, i, mid + j - 1); 1029 i++; 1030 } 1031 1032 g.setColor(foreground); 1033 i = size / 2 - height / 2 - 1; 1034 down = thick - 1; 1035 for (up = 0; up < thick; up++) { 1037 g.drawLine(i + up, 0 - down, i + up, size + down); 1038 down--; 1039 } 1040 i++; 1041 1042 for (j = height - 1; j > 0; j--) { 1044 for (up = 0; up < thick; up++) { 1045 g.drawLine(i, mid - j + 1 - up, i, mid - j + 1 - up); 1046 g.drawLine(i, mid + j - 1 + up, i, mid + j - 1 + up); 1047 } 1048 i++; 1049 } 1050 1051 if (thick > 1) { 1053 for (up = thick - 2; up >= 0; up--) { 1054 g.drawLine(i, mid - up, i, mid + up); 1055 i++; 1056 } 1057 } 1058 break; 1059 } 1060 g.translate(-x, -y); 1061 } 1062 1063 public void paintSlider(Graphics g, SynthContext context, Region id, 1064 int state, ShadowType shadowType, String info, 1065 int x, int y, int w, int h, Orientation orientation) { 1066 paintBox(g, context, id, state, shadowType, info, x, y, w, h); 1067 if (context.getRegion() == Region.SLIDER_THUMB) { 1068 if (orientation == Orientation.HORIZONTAL) { 1069 paintVline(g, context, id, state, info, 1070 x + w / 2 - 1, y + 2, 2, h - 4); 1071 } else { 1072 paintHline(g, context, id, state, info, 1073 x + 2, y + h / 2 - 1, w - 4, 2); 1074 } 1075 } 1076 } 1077 1078 public void paintHline(Graphics g, SynthContext context, Region id, 1079 int state, String info, int x, int y, int w, int h) { 1080 g.translate(x, y); 1081 1082 GTKStyle style = (GTKStyle)context.getStyle(); 1083 int centerY = h / 2; 1084 if (h == 2) { 1085 centerY = 0; 1086 } 1087 g.setColor(style.getGTKColor(context, state, GTKColorType.DARK)); 1088 g.drawLine(0, centerY, w - 2, centerY); 1089 g.setColor(style.getGTKColor(context, state, GTKColorType.LIGHT)); 1090 g.drawLine(0, centerY + 1, w - 1, centerY + 1); 1091 g.drawLine(w - 1, centerY, w - 1, centerY + 1); 1092 1093 g.translate(-x, -y); 1094 } 1095 1096 public void paintVline(Graphics g, SynthContext context, Region id, 1097 int state, String info, int x, int y, int w, int h) { 1098 g.translate(x, y); 1099 1100 GTKStyle style = (GTKStyle)context.getStyle(); 1101 int centerX = w / 2; 1102 g.setColor(style.getGTKColor(context, state, GTKColorType.DARK)); 1103 g.drawLine(centerX, 0, centerX, h - 2); 1104 g.drawLine(centerX, 0, centerX + 1, 0); 1105 g.setColor(style.getGTKColor(context, state, GTKColorType.LIGHT)); 1106 g.drawLine(centerX + 1, 1, centerX + 1, h - 1); 1107 g.drawLine(centerX, h - 1, centerX + 1, h - 1); 1108 1109 g.translate(-x, -y); 1110 } 1111 1112 1115 public void paintBackground(Graphics g, SynthContext context, 1116 Region id, int state, Color color, int x, int y, int w, int h) { 1117 GTKStyle style = (GTKStyle)context.getStyle(); 1118 1119 if (style.fillBackground(context, state)) { 1120 g.setColor(color); 1121 g.fillRect(x, y, w, h); 1122 } 1123 else { 1124 Image image = style.getBackgroundImage(context, state); 1125 int iW; 1126 int iH; 1127 1128 if (image != null && (iW = image.getWidth(null)) > 0 && 1129 (iH = image.getHeight(null)) > 0) { 1130 int x2 = x; 1133 int y2 = y; 1134 Component parent = context.getComponent().getParent(); 1135 1136 while (parent != null && !(parent instanceof Window) && 1137 !(parent instanceof java.applet.Applet )) { 1138 Component nextParent = parent.getParent(); 1139 1140 if (parent instanceof JRootPane && 1141 !(nextParent instanceof Window) && 1142 !(nextParent instanceof java.applet.Applet )) { 1143 x2 += parent.getX(); 1144 y2 += parent.getY(); 1145 } 1146 parent = nextParent; 1147 } 1148 x2 = x2 % iW; 1149 y2 = y2 % iH; 1150 1151 Rectangle clip = g.getClipBounds(); 1152 int cx1 = clip.x; 1153 int cy1 = clip.y; 1154 int cx2 = cx1 + clip.width; 1155 int cy2 = cy1 + clip.height; 1156 1157 int lastIY = y2; 1158 for (int yCounter = y, maxY = y + h; yCounter < maxY; 1159 yCounter += (iH - lastIY), lastIY = 0) { 1160 int lastIX = x2; 1161 for (int xCounter = x, maxX = x + w; xCounter < maxX; 1162 xCounter += (iW - lastIX), lastIX = 0) { 1163 int dx2 = Math.min(maxX, xCounter + iW - lastIX); 1164 int dy2 = Math.min(maxY, yCounter + iH - lastIY); 1165 if (dx2 > cx1 && dy2 > cy1 && cx2 > xCounter && 1166 cy2 > yCounter) { 1167 g.drawImage(image, xCounter, yCounter, dx2, dy2, 1168 lastIX, lastIY, lastIX + dx2 - xCounter, 1169 lastIY + dy2 - yCounter, null); 1170 } 1171 } 1172 } 1173 } 1174 } 1175 } 1176} 1177 | Popular Tags |