1 7 package com.sun.java.swing.plaf.gtk; 8 9 import sun.swing.plaf.synth.SynthUI; 10 11 import javax.swing.plaf.synth.*; 12 import java.awt.*; 13 import javax.swing.*; 14 import javax.swing.border.*; 15 import javax.swing.plaf.*; 16 17 22 class GTKPainter extends SynthPainter { 32 static final GTKPainter INSTANCE = new GTKPainter(); 33 static final Insets EMPTY_INSETS = new Insets(0, 0, 0, 0); 34 private static final Insets TEMP_INSETS = new Insets(0, 0, 0, 0); 35 36 39 private static final Insets BUTTON_DEFAULT_BORDER_INSETS = 40 new Insets(1, 1, 1, 1); 41 42 43 private GTKEngine getEngine(SynthContext context) { 44 return ((GTKStyle)context.getStyle()).getEngine(context); 45 } 46 47 private String getName(SynthContext context) { 48 return (context.getRegion().isSubregion()) ? null : 49 context.getComponent().getName(); 50 } 51 52 Insets getInsets(SynthContext state, Insets insets) { 53 Region id = state.getRegion(); 54 String name = (id.isSubregion()) ? null : 55 state.getComponent().getName(); 56 57 if (insets == null) { 58 insets = new Insets(0, 0, 0, 0); 59 } 60 else { 61 insets.top = insets.bottom = insets.left = insets.right = 0; 62 } 63 if (id == Region.BUTTON || id == Region.TOGGLE_BUTTON 64 || id == Region.CHECK_BOX || id == Region.RADIO_BUTTON 65 || id == Region.ARROW_BUTTON || id == Region.TOGGLE_BUTTON 66 || id == Region.RADIO_BUTTON_MENU_ITEM 67 || id == Region.CHECK_BOX_MENU_ITEM) { 68 if ("Spinner.previousButton" == name || 69 "Spinner.nextButton" == name) { 70 return getSpinnerButtonInsets(state, insets); 71 } else { 72 return getButtonInsets(state, insets); 73 } 74 } 75 else if (id == Region.MENU 76 || id == Region.MENU_ITEM) { 77 return getMenuItemInsets(state, insets); 78 } 79 else if (id == Region.FORMATTED_TEXT_FIELD) { 80 return getTextFieldInsets(state, insets); 81 } 82 else if (id == Region.INTERNAL_FRAME) { 83 insets = Metacity.INSTANCE.getBorderInsets(state, insets); 84 } 85 else if (id == Region.DESKTOP_ICON) { 86 } 88 else if (id == Region.LABEL) { 89 if ("TableHeader.renderer" == name) { 90 return getButtonInsets(state, insets); 91 } 92 else if ("ComboBox.renderer" == name || 93 "ComboBox.listRenderer" == name) { 94 return getTextFieldInsets(state, insets); 95 } 96 else if ("Tree.cellRenderer" == name) { 97 return getTreeCellRendererInsets(state, insets); 98 } 99 } 100 else if (id == Region.MENU_BAR) { 101 return getMenuBarInsets(state, insets); 102 } 103 else if (id == Region.OPTION_PANE) { 104 return getOptionPaneInsets(state, insets); 105 } 106 else if (id == Region.POPUP_MENU) { 107 return getPopupMenuInsets(state, insets); 108 } 109 else if (id == Region.PROGRESS_BAR) { 110 return getProgressBarInsets(state, insets); 111 } 112 else if (id == Region.SCROLL_BAR) { 113 return getScrollBarInsets(state, insets); 114 } 115 else if (id == Region.SEPARATOR) { 116 return getSeparatorInsets(state, insets); 117 } 118 else if (id == Region.SLIDER) { 119 return getSliderInsets(state, insets); 120 } 121 else if (id == Region.SLIDER_TRACK) { 122 return getSliderTrackInsets(state, insets); 123 } 124 else if (id == Region.SPINNER) { 125 return getSpinnerInsets(state, insets); 126 } 127 else if (id == Region.TABBED_PANE) { 128 return getTabbedPaneInsets(state, insets); 129 } 130 else if (id == Region.TABBED_PANE_CONTENT) { 131 return getTabbedPaneContentInsets(state, insets); 132 } 133 else if (id == Region.TABBED_PANE_TAB) { 134 return getTabbedPaneTabInsets(state, insets); 135 } 136 else if (id == Region.TEXT_FIELD || 137 id == Region.PASSWORD_FIELD) { 138 if (name == "Tree.cellEditor") { 139 return getTreeCellEditorInsets(state, insets); 140 } 141 return getTextFieldInsets(state, insets); 142 } 143 else if (id == Region.TOOL_BAR) { 144 return getToolBarInsets(state, insets); 145 } 146 else if (id == Region.TOOL_TIP) { 147 return getToolTipInsets(state, insets); 148 } 149 return insets; 150 } 151 152 public void paintCheckBoxBackground(SynthContext context, 153 Graphics g, int x, int y, 154 int w, int h) { 155 paintRadioButtonCheckBoxBackground(context, getEngine(context), 156 g, x, y, w, h); 157 } 158 159 public void paintFormattedTextFieldBackground(SynthContext context, 161 Graphics g, int x, int y, 162 int w, int h) { 163 paintTextFieldBackground(context, getEngine(context), g, x, y, w, h); 164 } 165 166 public void paintToolBarDragWindowBackground(SynthContext context, 170 Graphics g, int x, int y, 171 int w, int h) { 172 paintToolBarBackground(context, getEngine(context), g, x, y, w, h); 173 } 174 175 176 public void paintToolBarBackground(SynthContext context, 180 Graphics g, int x, int y, 181 int w, int h) { 182 paintToolBarBackground(context, getEngine(context), g, x, y, w, h); 183 } 184 185 public void paintPasswordFieldBackground(SynthContext context, 189 Graphics g, int x, int y, 190 int w, int h) { 191 paintTextFieldBackground(context, g, x, y, w, h); 192 } 193 194 public void paintTextFieldBackground(SynthContext context, 198 Graphics g, int x, int y, 199 int w, int h) { 200 GTKEngine engine = getEngine(context); 201 if (getName(context) == "Tree.cellEditor") { 202 paintTreeCellEditorBackground(context, engine, g, x, y, w, h); 203 } 204 else { 205 paintTextFieldBackground(context, engine, g, x, y, w, h); 206 } 207 } 208 209 public void paintRadioButtonBackground(SynthContext context, 213 Graphics g, int x, int y, 214 int w, int h) { 215 paintRadioButtonCheckBoxBackground(context, getEngine(context), 216 g, x, y, w, h); 217 } 218 219 public void paintRadioButtonMenuItemBackground(SynthContext context, 223 Graphics g, int x, int y, 224 int w, int h) { 225 paintRadioButtonCheckBoxMenuItemBackground(context, getEngine(context), 226 g, x, y, w, h); 227 } 228 229 public void paintLabelBackground(SynthContext context, 233 Graphics g, int x, int y, 234 int w, int h) { 235 GTKEngine engine = getEngine(context); 236 String name = getName(context); 237 if ("TableHeader.renderer" == name || 238 name == "GTKFileChooser.directoryListLabel" || 239 name == "GTKFileChooser.fileListLabel") { 240 paintButtonBackground(context, engine, g, x, y, w, h, "button"); 241 } 242 else if (name == "ComboBox.renderer") { 243 paintTextFieldBackground(context, engine, g, x, y, w, h); 244 } 245 } 246 247 public void paintInternalFrameBorder(SynthContext context, 251 Graphics g, int x, int y, 252 int w, int h) { 253 Metacity.INSTANCE.paintFrameBorder(context, g, x, y, w, h); 254 } 255 256 public void paintDesktopPaneBackground(SynthContext context, 260 Graphics g, int x, int y, 261 int w, int h) { 262 GTKEngine engine = getEngine(context); 263 int gtkState = GTKLookAndFeel.synthStateToGTKState( 264 context.getRegion(), context.getComponentState()); 265 engine.paintFlatBoxNormal(context, g, gtkState, "base", x, y, w, h); 266 } 267 268 public void paintDesktopIconBorder(SynthContext context, 272 Graphics g, int x, int y, 273 int w, int h) { 274 Metacity.INSTANCE.paintFrameBorder(context, g, x, y, w, h); 275 } 276 277 public void paintCheckBoxMenuItemBackground(SynthContext context, 281 Graphics g, int x, int y, 282 int w, int h) { 283 paintRadioButtonCheckBoxMenuItemBackground(context, getEngine(context), 284 g, x, y, w, h); 285 } 286 287 private Insets getButtonInsets(SynthContext context, Insets insets) { 291 GTKStyle style = (GTKStyle)context.getStyle(); 292 int focusSize = style.getClassSpecificIntValue(context, 293 "focus-line-width",1); 294 int focusPad = style.getClassSpecificIntValue(context, 295 "focus-padding", 1); 296 int xThickness = style.getXThickness(); 297 int yThickness = style.getYThickness(); 298 int w = focusSize + focusPad + xThickness; 299 int h = focusSize + focusPad + yThickness; 300 Component component = context.getComponent(); 301 302 insets.left = insets.right = w; 303 insets.top = insets.bottom = h; 304 if ((component instanceof JButton) && 305 ((JButton)component).isDefaultCapable()) { 306 Insets defaultInsets = style.getClassSpecificInsetsValue(context, 307 "default-border", BUTTON_DEFAULT_BORDER_INSETS); 308 insets.left += defaultInsets.left; 309 insets.right += defaultInsets.right; 310 insets.top += defaultInsets.top; 311 insets.bottom += defaultInsets.bottom; 312 } 313 return insets; 314 } 315 316 public void paintButtonBackground(SynthContext context, 317 Graphics g, int x, int y, 318 int w, int h) { 319 String name = getName(context); 320 if (name != null && name.startsWith("InternalFrameTitlePane.")) { 321 Metacity.INSTANCE.paintButtonBackground(context, g, x, y, w, h); 322 } else { 323 paintButtonBackground(context, getEngine(context), g, x, y, w, h, 324 "button"); 325 } 326 } 327 328 private void paintButtonBackground(SynthContext context, GTKEngine engine, 329 Graphics g, int x, int y, int w, int h, 330 String detail) { 331 int state = context.getComponentState(); 333 int gtkState = GTKLookAndFeel.synthStateToGTKState( 334 context.getRegion(), state); 335 GTKStyle style = (GTKStyle)context.getStyle(); 336 boolean interiorFocus = style.getClassSpecificBoolValue(context, 337 "interior-focus", true); 338 int focusSize = style.getClassSpecificIntValue(context, 339 "focus-line-width",1); 340 int focusPad = style.getClassSpecificIntValue(context, "focus-padding", 341 1); 342 int totalFocusSize = focusSize + focusPad; 343 int xThickness = style.getXThickness(); 344 int yThickness = style.getYThickness(); 345 Component component = context.getComponent(); 346 AbstractButton button = (component instanceof AbstractButton) ? 347 (AbstractButton)component : null; 348 boolean paintBG = (button == null || (button.isContentAreaFilled() && 349 button.isBorderPainted())); 350 351 if ((component instanceof JButton) && 353 ((JButton)component).isDefaultCapable()) { 354 Insets defaultInsets = (Insets)style.getClassSpecificInsetsValue( 355 context, "default-border", BUTTON_DEFAULT_BORDER_INSETS); 356 357 if (paintBG && (state & SynthConstants.DEFAULT) == 358 SynthConstants.DEFAULT) { 359 engine.paintBox(context, g, SynthConstants.ENABLED, 360 GTKConstants.SHADOW_IN, "buttondefault", 361 x, y, w, h); 362 } 363 x += defaultInsets.left; 364 y += defaultInsets.top; 365 w -= (defaultInsets.left + defaultInsets.right); 366 h -= (defaultInsets.top + defaultInsets.bottom); 367 } 368 369 if (!interiorFocus && (state & SynthConstants.FOCUSED) == 371 SynthConstants.FOCUSED) { 372 x += totalFocusSize; 373 y += totalFocusSize; 374 w -= 2 * totalFocusSize; 375 h -= 2 * totalFocusSize; 376 } 377 if (paintBG && (!(component.getParent() instanceof JToolBar) || 378 gtkState != SynthConstants.ENABLED)) { 379 int shadowType; 380 if ((state & SynthConstants.PRESSED) == SynthConstants.PRESSED) { 381 shadowType = GTKConstants.SHADOW_IN; 382 } 383 else { 384 shadowType = GTKConstants.SHADOW_OUT; 385 } 386 engine.paintBox(context, g, gtkState, shadowType, detail, 387 x, y, w, h); 388 } 389 390 if ((state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED && 392 (button == null || button.isFocusPainted())) { 393 if (interiorFocus) { 394 x += xThickness + focusPad; 395 y += yThickness + focusPad; 396 w -= 2 * (xThickness + focusPad); 397 h -= 2 * (yThickness + focusPad); 398 } 399 else { 400 x -= totalFocusSize; 401 y -= totalFocusSize; 402 w += 2 * totalFocusSize; 403 h += 2 * totalFocusSize; 404 } 405 engine.paintFocus(context, g, gtkState, detail, x, y, w, h); 406 } 407 } 408 409 410 public void paintArrowButtonForeground(SynthContext context, Graphics g, 414 int x, int y, int w, int h, 415 int direction) { 416 GTKEngine engine = getEngine(context); 417 int state = GTKLookAndFeel.synthStateToGTKState( 418 Region.ARROW_BUTTON, context.getComponentState()); 419 int shadowType; 420 421 if (state == SynthConstants.PRESSED) { 422 shadowType = GTKConstants.SHADOW_IN; 423 } 424 else { 425 shadowType = GTKConstants.SHADOW_OUT; 426 } 427 switch (direction) { 428 case SwingConstants.NORTH: 429 direction = GTKConstants.ARROW_UP; 430 break; 431 case SwingConstants.SOUTH: 432 direction = GTKConstants.ARROW_DOWN; 433 break; 434 case SwingConstants.EAST: 435 direction = GTKConstants.ARROW_RIGHT; 436 break; 437 case SwingConstants.WEST: 438 direction = GTKConstants.ARROW_LEFT; 439 break; 440 } 441 Component c = context.getComponent(); 442 String name = c.getName(); 443 String detail = "arrow"; 444 445 if (name == "ScrollBar.button") { 446 if (c.getParent() instanceof JScrollBar) { 447 if (((JScrollBar)c.getParent()).getOrientation() == 448 SwingConstants.HORIZONTAL) { 449 detail = "hscrollbar"; 450 } 451 else { 452 detail = "vscrollbar"; 453 } 454 } 455 } 456 else if (name == "Spinner.nextButton") { 457 detail = "spinbutton"; 458 } 459 else if (name == "Spinner.previousButton") { 460 detail = "spinbutton"; 461 } 462 463 engine.paintArrow(context, g, state, shadowType, direction, 464 detail, x, y, w, h); 465 } 466 467 public void paintArrowButtonBackground(SynthContext context, 468 Graphics g, 469 int x, int y, int w, int h) { 470 GTKEngine engine = getEngine(context); 471 Component c = context.getComponent(); 472 String name = c.getName(); 473 String detail = "button"; 474 475 if (name == "ScrollBar.button") { 476 if (c.getParent() instanceof JScrollBar) { 477 if (((JScrollBar)c.getParent()).getOrientation() == 478 SwingConstants.HORIZONTAL) { 479 detail = "hscrollbar"; 480 } 481 else { 482 detail = "vscrollbar"; 483 } 484 } 485 } else if ("Spinner.previousButton" == name) { 486 detail = "spinbutton_down"; 487 } else if ("Spinner.nextButton" == name) { 488 detail = "spinbutton_up"; 489 } 490 paintButtonBackground(context, engine, g, x, y, w, h, detail); 491 } 492 493 private void paintRadioButtonCheckBoxBackground(SynthContext context, 497 GTKEngine engine, Graphics g, 498 int x, int y, int w, int h) { 499 int gtkState = GTKLookAndFeel.synthStateToGTKState( 500 context.getRegion(), context.getComponentState()); 501 502 if ((gtkState & SynthConstants.MOUSE_OVER) != 0) { 503 engine.paintFlatBoxNormal(context, g, SynthConstants.MOUSE_OVER, 504 "checkbutton", x, y, w, h); 505 } 506 } 507 508 509 private void paintRadioButtonCheckBoxMenuItemBackground( 513 SynthContext context, 514 GTKEngine engine, Graphics g, 515 int x, int y, int w, int h) { 516 int gtkState = GTKLookAndFeel.synthStateToGTKState( 517 context.getRegion(), context.getComponentState()); 518 if ((context.getComponentState() & SynthConstants.MOUSE_OVER) != 0) { 519 if (GTKLookAndFeel.is2_2()) { 520 engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_NONE, 521 "menuitem", x, y, w, h); 522 } 523 else { 524 engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_OUT, 525 "menuitem", x, y, w, h); 526 } 527 } 528 } 529 530 531 public void paintListBackground(SynthContext context, Graphics g, 535 int x, int y, int w, int h) { 536 GTKEngine engine = getEngine(context); 537 int state = GTKLookAndFeel.synthStateToGTKState( 538 Region.LIST, context.getComponentState()); 539 540 if (context.getComponent().getName() == "ComboBox.list") { 541 } 543 engine.paintFlatBoxText(context, g, state, "base", x, y, w, h); 544 545 } 546 547 private Insets getMenuBarInsets(SynthContext context, Insets insets) { 551 GTKStyle style = (GTKStyle)context.getStyle(); 552 int internalPadding = style.getClassSpecificIntValue(context, 553 "internal-padding", 0); 554 int xThickness = style.getXThickness(); 555 int yThickness = style.getYThickness(); 556 insets.top = insets.bottom = internalPadding + yThickness; 557 insets.left = insets.right = internalPadding + xThickness; 558 return insets; 559 } 560 561 public void paintMenuBarBackground(SynthContext context, 562 Graphics g, 563 int x, int y, int w, int h) { 564 GTKEngine engine = getEngine(context); 565 GTKStyle style = (GTKStyle)context.getStyle(); 566 int shadowType = style.getClassSpecificIntValue(context, 567 "shadow-type", GTKConstants.SHADOW_OUT); 568 int gtkState = GTKLookAndFeel.synthStateToGTKState( 569 context.getRegion(), context.getComponentState()); 570 571 engine.paintBox(context, g, gtkState, shadowType, "menubar", 572 x, y, w, h); 573 } 574 575 public void paintMenuBackground(SynthContext context, 579 Graphics g, 580 int x, int y, int w, int h) { 581 GTKEngine engine = getEngine(context); 582 int gtkState = GTKLookAndFeel.synthStateToGTKState( 583 context.getRegion(), context.getComponentState()); 584 if (gtkState == SynthConstants.MOUSE_OVER) { 585 if (GTKLookAndFeel.is2_2()) { 586 engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_NONE, 587 "menuitem", x, y, w, h); 588 } 589 else { 590 engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_OUT, 591 "menuitem", x, y, w, h); 592 } 593 } 594 } 595 596 private Insets getMenuItemInsets(SynthContext context, Insets insets) { 600 GTKStyle style = (GTKStyle)context.getStyle(); 601 int internalPadding = style.getClassSpecificIntValue(context, 602 "internal-padding", 0); 603 int xThickness = style.getXThickness(); 604 int yThickness = style.getYThickness(); 605 insets.top = insets.bottom = internalPadding + yThickness; 606 insets.left = insets.right = internalPadding + xThickness; 607 return insets; 608 } 609 610 public void paintMenuItemBackground(SynthContext context, 611 Graphics g, 612 int x, int y, int w, int h) { 613 GTKEngine engine = getEngine(context); 614 int gtkState = GTKLookAndFeel.synthStateToGTKState( 615 context.getRegion(), context.getComponentState()); 616 if ((context.getComponentState() & SynthConstants.MOUSE_OVER) != 0) { 617 if (GTKLookAndFeel.is2_2()) { 618 engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_NONE, 619 "menuitem", x, y, w, h); 620 } 621 else { 622 engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_OUT, 623 "menuitem", x, y, w, h); 624 } 625 } 626 } 627 628 private Insets getPopupMenuInsets(SynthContext context, Insets insets) { 629 insets.left = insets.right = insets.top = insets.bottom = 2; 630 return insets; 631 } 632 633 public void paintPopupMenuBackground(SynthContext context, Graphics g, 634 int x, int y, int w, int h) { 635 GTKEngine engine = getEngine(context); 636 int gtkState = GTKLookAndFeel.synthStateToGTKState( 637 context.getRegion(), context.getComponentState()); 638 engine.paintBox(context, g, gtkState, GTKConstants.SHADOW_OUT, 639 "menu", x, y, w, h); 640 641 GTKStyle style = (GTKStyle)context.getStyle(); 642 int xThickness = style.getXThickness(); 643 int yThickness = style.getYThickness(); 644 645 engine.paintBackground(context, g, gtkState, style.getGTKColor( 646 context.getComponent(), context.getRegion(), gtkState, 647 GTKColorType.BACKGROUND), x + xThickness, y + yThickness, 648 w - xThickness - xThickness, h - yThickness - yThickness); 649 } 650 651 private Insets getProgressBarInsets(SynthContext context, Insets insets) { 655 GTKStyle style = (GTKStyle)context.getStyle(); 656 insets.left = insets.right = style.getXThickness(); 657 insets.top = insets.bottom = style.getYThickness(); 658 return insets; 659 } 660 661 public void paintProgressBarBackground(SynthContext context, 662 Graphics g, 663 int x, int y, int w, int h) { 664 GTKEngine engine = getEngine(context); 665 GTKStyle style = (GTKStyle)context.getStyle(); 666 engine.paintBox(context, g, SynthConstants.ENABLED, 668 GTKConstants.SHADOW_IN, "trough", x, y, w, h); 669 670 } 671 672 public void paintProgressBarForeground(SynthContext context, Graphics g, 673 int x, int y, int w, int h, 674 int orientation) { 675 if (w != 0 || h != 0) { 677 getEngine(context).paintBox(context, g, SynthConstants.MOUSE_OVER, 678 GTKConstants.SHADOW_OUT, "bar", x, y, w, h); 679 } 680 } 681 682 public void paintViewportBorder(SynthContext context, Graphics g, 683 int x, int y, int w, int h) { 684 getEngine(context).paintShadow(context, g, SynthConstants.ENABLED, 685 GTKConstants.SHADOW_IN, "scrolled_window", 686 x, y, w, h); 687 } 688 689 public void paintScrollPaneBorder(SynthContext context, Graphics g, 690 int x, int y, int w, int h) { 691 getEngine(context).paintShadow(context, g, SynthConstants.ENABLED, 692 GTKConstants.SHADOW_IN, "scrolled_window", 693 x, y, w, h); 694 } 695 696 Insets getScrollPaneInsets(SynthContext context, Insets insets) { 697 GTKStyle style = (GTKStyle)context.getStyle(); 698 insets.right = insets.left = style.getXThickness(); 699 insets.top = insets.bottom = style.getYThickness(); 700 return insets; 701 } 702 703 private Insets getSeparatorInsets(SynthContext context, Insets insets) { 707 return insets; 708 } 709 710 public void paintSeparatorBackground(SynthContext context, 711 Graphics g, 712 int x, int y, int w, int h) { 713 GTKEngine engine = getEngine(context); 714 if (((JSeparator)context.getComponent()).getOrientation() == 715 JSeparator.HORIZONTAL) { 716 engine.paintHline(context, g, SynthConstants.ENABLED, 717 "hseparator", x, y, w, h); 718 } else { 719 engine.paintVline(context, g, SynthConstants.ENABLED, 720 "vseparator", x, y, w, h); 721 } 722 } 723 724 private Insets getSliderInsets(SynthContext context, Insets insets) { 728 GTKStyle style = (GTKStyle)context.getStyle(); 729 int xThickness = style.getXThickness(); 730 int yThickness = style.getYThickness(); 731 insets.top = insets.bottom = yThickness; 732 insets.right = insets.left = xThickness; 733 return insets; 734 } 735 736 private Insets getSliderTrackInsets(SynthContext context, Insets insets) { 737 GTKStyle style = (GTKStyle)context.getStyle(); 738 int focusSize = style.getClassSpecificIntValue(context, 739 "focus-line-width", 1); 740 int focusPad = style.getClassSpecificIntValue(context, 741 "focus-padding", 1); 742 insets.top = insets.bottom = insets.left = insets.right = 743 focusSize + focusPad; 744 return insets; 745 } 746 747 public void paintSliderTrackBackground(SynthContext context, 748 Graphics g, 749 int x, int y, int w,int h) { 750 GTKEngine engine = getEngine(context); 751 GTKStyle style = (GTKStyle)context.getStyle(); 752 753 int state = context.getComponentState(); 754 int gtkState = GTKLookAndFeel.synthStateToGTKState(context.getRegion(), 755 state); 756 engine.paintBox(context, g, gtkState, 757 GTKConstants.SHADOW_IN, "trough", x, y, w, h); 758 759 if ((state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED) { 760 int focusSize = style.getClassSpecificIntValue(context, 761 "focus-line-width", 1); 762 focusSize += style.getClassSpecificIntValue(context, 763 "focus-padding", 1); 764 x -= focusSize; 765 y -= focusSize; 766 w += 2 * focusSize; 767 h += 2 * focusSize; 768 engine.paintFocus(context, g, SynthConstants.ENABLED, 769 "trough", x, y, w, h); 770 } 771 } 772 773 public void paintSliderThumbBackground(SynthContext context, 774 Graphics g, int x, int y, int w, int h, int orientation) { 775 GTKEngine engine = getEngine(context); 776 if (orientation == JSlider.HORIZONTAL) { 777 orientation = GTKConstants.HORIZONTAL; 778 } 779 else { 780 orientation = GTKConstants.VERTICAL; 781 } 782 engine.paintSlider(context, g, GTKLookAndFeel.synthStateToGTKState( 783 context.getRegion(), context.getComponentState()), 784 GTKConstants.SHADOW_OUT, "slider", x, y, w, h, orientation); 785 } 786 787 public void paintSpinnerBackground(SynthContext context, 791 Graphics g, 792 int x, int y, int w, int h) { 793 } 795 796 private Insets getSpinnerInsets(SynthContext context, Insets insets) { 797 return insets; 799 } 800 801 private Insets getSpinnerButtonInsets(SynthContext context, Insets insets) { 802 insets.top = insets.bottom = 1; 803 insets.right = insets.left = 1; 804 return insets; 805 } 806 807 public void paintSplitPaneDividerBackground(SynthContext context, 811 Graphics g, 812 int x, int y, int w, int h) { 813 GTKEngine engine = getEngine(context); 814 int orientation; 815 if (((JSplitPane)context.getComponent()).getOrientation() == 816 JSplitPane.VERTICAL_SPLIT) { 817 orientation = GTKConstants.HORIZONTAL; 818 } 819 else { 820 orientation = GTKConstants.VERTICAL; 821 } 822 823 engine.paintHandle(context, g, GTKLookAndFeel.synthStateToGTKState( 824 context.getRegion(), context.getComponentState()), 825 GTKConstants.UNDEFINED, "paned", x, y, w, h, orientation); 826 } 827 828 public void paintSplitPaneDragDivider(SynthContext context, 829 Graphics g,int x, int y, int w, int h, 830 int orientation) { 831 paintSplitPaneDividerForeground(context, g, x, y, w, h, orientation); 832 } 833 834 public void paintSplitPaneDividerForeground(SynthContext context, 835 Graphics g,int x, int y, int w, int h, 836 int orientation) { 837 g.setColor(context.getStyle().getColor(context, 838 GTKColorType.BACKGROUND)); 839 g.fillRect(x, y, w, h); 840 paintSplitPaneDividerBackground(context, g, x, y, w, h); 841 } 842 843 private Insets getTabbedPaneInsets(SynthContext context, Insets insets) { 847 GTKStyle style = (GTKStyle)context.getStyle(); 848 int xThickness = style.getXThickness(); 849 int yThickness = style.getYThickness(); 850 insets.top = insets.bottom = yThickness; 851 insets.right = insets.left = xThickness; 852 return insets; 853 } 854 855 private Insets getTabbedPaneContentInsets(SynthContext context, 859 Insets insets) { 860 GTKStyle style = (GTKStyle)context.getStyle(); 861 int xThickness = style.getXThickness(); 862 int yThickness = style.getYThickness(); 863 insets.top = insets.bottom = yThickness; 864 insets.right = insets.left = xThickness; 865 return insets; 866 } 867 868 public void paintTabbedPaneContentBackground(SynthContext context, 869 Graphics g, 870 int x, int y, int w, int h) { 871 GTKEngine engine = getEngine(context); 872 JTabbedPane tabPane = (JTabbedPane)context.getComponent(); 873 GTKStyle style = (GTKStyle)context.getStyle(); 874 Region region = context.getRegion(); 875 int placement = GTKLookAndFeel.SwingOrientationConstantToGTK( 876 tabPane.getTabPlacement()); 877 int start = 0; 878 int size = 0; 879 880 int selectedIndex = tabPane.getSelectedIndex(); 881 if (selectedIndex != -1) { 882 Rectangle tabBounds = tabPane.getBoundsAt(selectedIndex); 883 884 if (placement == GTKConstants.TOP || 885 placement == GTKConstants.BOTTOM) { 886 start = tabBounds.x - 1; 887 size = tabBounds.width; 888 } 889 else { 890 start = tabBounds.y - 1; 891 size = tabBounds.height; 892 } 893 } 894 engine.paintBoxGap(context, g, GTKLookAndFeel.synthStateToGTKState( 895 context.getRegion(), context.getComponentState()), 896 GTKConstants.SHADOW_OUT, "notebook", x, y, w, h, 897 placement, start, size); 898 } 899 900 private Insets getTabbedPaneTabInsets(SynthContext context, 904 Insets insets) { 905 GTKStyle style = (GTKStyle)context.getStyle(); 906 int xThickness = style.getXThickness(); 907 int yThickness = style.getYThickness(); 908 int focusSize = 0; 909 int pad = 2; 910 911 focusSize = style.getClassSpecificIntValue(context, 912 "focus-line-width",1); 913 insets.left = insets.right = focusSize + pad + xThickness; 914 insets.top = insets.bottom = focusSize + pad + yThickness; 915 return insets; 916 } 917 918 public void paintTabbedPaneTabBackground(SynthContext context, 919 Graphics g, 920 int x, int y, int w, int h, 921 int tabIndex) { 922 GTKEngine engine = getEngine(context); 923 GTKStyle style = (GTKStyle)context.getStyle(); 924 int state = context.getComponentState(); 925 int selectedIndex = ((JTabbedPane)context.getComponent()). 926 getSelectedIndex(); 927 int offset = (selectedIndex == tabIndex) ? 0 : 2; 928 int side; 929 state = GTKLookAndFeel.synthStateToGTKState(context.getRegion(), state); 930 switch (((JTabbedPane)context.getComponent()).getTabPlacement()) { 931 case SwingConstants.TOP: 932 side = GTKConstants.BOTTOM; 933 y += offset; 934 h -= offset; 935 break; 936 case SwingConstants.BOTTOM: 937 h -= offset; 938 side = GTKConstants.TOP; 939 break; 940 case SwingConstants.LEFT: 941 x += offset; 942 w -= offset; 943 side = GTKConstants.RIGHT; 944 break; 945 default: 946 w -= offset; 947 side = GTKConstants.LEFT; 948 break; 949 } 950 engine.paintExtension(context, g, state, GTKConstants.SHADOW_OUT, 951 "tab", x, y, w, h, side, tabIndex); 952 } 953 954 public void paintTextAreaBackground(SynthContext context, 958 Graphics g, 959 int x, int y, int w, int h) { 960 GTKEngine engine = getEngine(context); 961 GTKStyle style = (GTKStyle)context.getStyle(); 962 int state = context.getComponentState(); 963 engine.paintFlatBoxText(context, g, state, "base", x, y, w, h); 964 } 965 966 private void paintTextFieldBackground(SynthContext context, 971 GTKEngine engine, Graphics g, 972 int x, int y, int w, int h) { 973 GTKStyle style = (GTKStyle)context.getStyle(); 974 boolean interiorFocus = style.getClassSpecificBoolValue(context, 975 "interior-focus", true); 976 int state = context.getComponentState(); 977 int gtkState = GTKLookAndFeel.synthStateToGTKState( 978 context.getRegion(), state); 979 int focusSize; 980 int xThickness = style.getXThickness(); 981 int yThickness = style.getYThickness(); 982 983 paintTextBackground(context, engine, g, x, y, w, h); 984 state = GTKLookAndFeel.synthStateToGTKState(context.getRegion(),state); 985 986 if (!interiorFocus && (state & SynthConstants.FOCUSED) == 987 SynthConstants.FOCUSED) { 988 focusSize = style.getClassSpecificIntValue(context, 989 "focus-line-width",1); 990 x += focusSize; 991 y += focusSize; 992 w -= 2 * focusSize; 993 h -= 2 * focusSize; 994 } 995 else { 996 focusSize = 0; 997 } 998 999 engine.paintShadow(context, g, SynthConstants.ENABLED, 1000 GTKConstants.SHADOW_IN, "entry", x, y, w, h); 1001 1002 g.setColor(style.getGTKColor(context.getComponent(), 1003 context.getRegion(), SynthConstants.ENABLED, 1004 GTKColorType.TEXT_BACKGROUND)); 1005 g.fillRect(x + xThickness, y + yThickness, w - (2 * xThickness), 1006 h - (2 * yThickness)); 1007 1008 1009 engine.paintFlatBoxText(context, g, SynthConstants.ENABLED, "entry_bg", 1010 x + xThickness, y + yThickness, w - (2 * xThickness), 1011 h - (2 * yThickness)); 1012 1013 if (focusSize > 0) { 1014 x -= focusSize; 1015 y -= focusSize; 1016 w += 2 * focusSize; 1017 h += 2 * focusSize; 1018 engine.paintFocus(context, g, gtkState, "entry", x, y, w, h); 1019 } 1020 } 1021 1022 private Insets getTextFieldInsets(SynthContext context, Insets insets) { 1024 GTKStyle style = (GTKStyle)context.getStyle(); 1025 int xThickness = style.getXThickness(); 1026 int yThickness = style.getYThickness(); 1027 boolean interiorFocus = style.getClassSpecificBoolValue(context, 1028 "interior-focus", true); 1029 int focusSize = 0; 1030 1031 if (!interiorFocus) { 1032 focusSize = style.getClassSpecificIntValue(context, 1033 "focus-line-width",1); 1034 } 1035 1036 insets.left = insets.right = focusSize + xThickness + 2; 1037 insets.top = insets.bottom = focusSize + yThickness + 2; 1038 return insets; 1039 } 1040 1041 1042 private void paintTextBackground(SynthContext context, 1043 GTKEngine engine, Graphics g, 1044 int x, int y, int w,int h) { 1045 JComponent c = context.getComponent(); 1048 if (c.isOpaque() && c.getBackground() instanceof ColorUIResource) { 1050 g.setColor(((GTKStyle)context.getStyle()).getGTKColor( 1051 context.getComponent(), context.getRegion(), 1052 SynthConstants.ENABLED, GTKColorType.TEXT_BACKGROUND)); 1053 g.fillRect(x, y, w, h); 1054 } 1055 } 1056 1057 1058 1062 private Insets getOptionPaneInsets(SynthContext context, Insets insets) { 1063 insets.left = insets.right = insets.top = insets.bottom = 6; 1064 return insets; 1065 } 1066 1067 1068 public void paintToggleButtonBackground(SynthContext context, 1072 Graphics g, 1073 int x, int y, int w, int h) { 1074 GTKEngine engine = getEngine(context); 1075 int state = context.getComponentState(); 1076 int gtkState = GTKLookAndFeel.synthStateToGTKState(context.getRegion(), 1077 state); 1078 GTKStyle style = (GTKStyle)context.getStyle(); 1079 boolean interiorFocus = style.getClassSpecificBoolValue(context, 1080 "interior-focus", true); 1081 int focusSize = style.getClassSpecificIntValue(context, 1082 "focus-line-width",1); 1083 int focusPad = style.getClassSpecificIntValue(context, "focus-padding", 1084 1); 1085 int totalFocusSize = focusSize + focusPad; 1086 int xThickness = style.getXThickness(); 1087 int yThickness = style.getYThickness(); 1088 JToggleButton toggleButton = (JToggleButton)context.getComponent(); 1089 1090 if (!interiorFocus && (state & SynthConstants.FOCUSED) == 1091 SynthConstants.FOCUSED) { 1092 x += totalFocusSize; 1093 y += totalFocusSize; 1094 w -= 2 * totalFocusSize; 1095 h -= 2 * totalFocusSize; 1096 } 1097 1098 int shadow = GTKConstants.SHADOW_OUT; 1099 if (toggleButton.isSelected() || 1100 ((state & SynthConstants.PRESSED) != 0)) { 1101 shadow = GTKConstants.SHADOW_IN; 1102 } 1103 if (toggleButton.isContentAreaFilled() && 1104 toggleButton.isBorderPainted()) { 1105 engine.paintBox(context, g, gtkState, shadow, "button", x, y, w,h); 1106 } 1107 1108 if ((state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED && 1110 toggleButton.isFocusPainted()) { 1111 if (interiorFocus) { 1112 x += xThickness + focusPad; 1113 y += yThickness + focusPad; 1114 w -= 2 * (xThickness + focusPad); 1115 h -= 2 * (yThickness + focusPad); 1116 } 1117 else { 1118 x -= totalFocusSize; 1119 y -= totalFocusSize; 1120 w += 2 * totalFocusSize; 1121 h += 2 * totalFocusSize; 1122 } 1123 engine.paintFocus(context, g, gtkState, "button", x, y, w, h); 1124 } 1125 } 1126 1127 public void paintRootPaneBackground(SynthContext context, 1131 Graphics g, 1132 int x, int y, int w, int h) { 1133 GTKEngine engine = getEngine(context); 1134 int gtkState = GTKLookAndFeel.synthStateToGTKState( 1135 context.getRegion(), context.getComponentState()); 1136 1137 engine.paintFlatBoxNormal(context, g, gtkState, "base", x, y, w, h); 1138 } 1139 1140 public void paintScrollBarBackground(SynthContext context, 1144 Graphics g, 1145 int x, int y, int w,int h) { 1146 GTKEngine engine = getEngine(context); 1147 GTKStyle style = (GTKStyle)context.getStyle(); 1148 int state = context.getComponentState(); 1149 int gtkState = GTKLookAndFeel.synthStateToGTKState(context.getRegion(), 1150 state); 1151 int focusSize = style.getClassSpecificIntValue(context, 1152 "focus-line-width",1); 1153 int focusPad = style.getClassSpecificIntValue(context, 1154 "focus-padding", 1); 1155 int totalFocus = focusSize + focusPad; 1156 1157 engine.paintBox(context, g, SynthConstants.PRESSED, 1158 GTKConstants.SHADOW_IN, "trough", x + totalFocus, 1159 y + totalFocus, w - 2 * totalFocus, 1160 h - 2 * totalFocus); 1161 if ((state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED) { 1162 engine.paintFocus(context, g, SynthConstants.ENABLED, 1163 "trough", x, y, w, h); 1164 } 1165 } 1166 1167 private Insets getScrollBarInsets(SynthContext context, Insets insets) { 1168 GTKStyle style = (GTKStyle)context.getStyle(); 1169 if (context.getComponent().isFocusable()) { 1170 int focusSize = style.getClassSpecificIntValue(context, 1171 "focus-line-width",1); 1172 int focusPad = style.getClassSpecificIntValue(context, 1173 "focus-padding", 1); 1174 int w = focusSize + focusPad; 1175 int h = focusSize + focusPad; 1176 1177 insets.left = insets.right = w; 1178 insets.top = insets.bottom = h; 1179 } 1180 int troughBorder = style.getClassSpecificIntValue(context, 1181 "trough-border", 1); 1182 insets.left += troughBorder; 1183 insets.right += troughBorder; 1184 insets.top += troughBorder; 1185 insets.bottom += troughBorder; 1186 return insets; 1187 } 1188 1189 1190 public void paintScrollBarThumbBackground(SynthContext context, 1194 Graphics g, int x, int y, int w, int h, int orientation) { 1195 GTKEngine engine = getEngine(context); 1196 if (orientation == JScrollBar.VERTICAL) { 1197 orientation = GTKConstants.VERTICAL; 1198 } 1199 else { 1200 orientation = GTKConstants.HORIZONTAL; 1201 } 1202 engine.paintSlider(context, g, GTKLookAndFeel.synthStateToGTKState( 1203 context.getRegion(), context.getComponentState()), 1204 GTKConstants.SHADOW_OUT, "slider", x, y, w, h, orientation); 1205 } 1206 1207 private void paintToolBarBackground(SynthContext context, GTKEngine engine, 1211 Graphics g, int x, int y, 1212 int w, int h) { 1213 int state = context.getComponentState(); 1214 int gtkState = GTKLookAndFeel.synthStateToGTKState(context.getRegion(), 1215 state); 1216 GTKStyle style = (GTKStyle)context.getStyle(); 1217 1218 g.setColor(style.getGTKColor(context.getComponent(), 1219 context.getRegion(), state, GTKColorType.BACKGROUND)); 1220 engine.paintFlatBox(context, g, gtkState, "handlebox_bin", x, y, w, h); 1221 } 1222 1223 private Insets getToolBarInsets(SynthContext context, Insets insets) { 1224 GTKStyle style = (GTKStyle)context.getStyle(); 1225 int xThickness = style.getXThickness(); 1226 int yThickness = style.getYThickness(); 1227 insets.top = insets.bottom = yThickness; 1228 insets.right = insets.left = xThickness; 1229 return insets; 1230 } 1231 1232 public void paintToolBarContentBackground(SynthContext context, 1233 Graphics g, int x, int y, int w, int h) { 1234 int state = context.getComponentState(); 1235 int gtkState = GTKLookAndFeel.synthStateToGTKState(context.getRegion(), 1236 state); 1237 getEngine(context).paintShadow(context, g, SynthConstants.ENABLED, 1238 GTKConstants.SHADOW_OUT, "handlebox_bin", x, y, w, h); 1239 } 1240 1241 public void paintToolTipBackground(SynthContext context, Graphics g, 1245 int x, int y, int w,int h) { 1246 getEngine(context).paintFlatBoxNormal(context, g, 1247 SynthConstants.ENABLED,"tooltip", 1248 x, y, w, h); 1249 } 1250 1251 private Insets getToolTipInsets(SynthContext context, Insets insets) { 1252 GTKStyle style = (GTKStyle)context.getStyle(); 1253 1254 insets.left = insets.right = style.getXThickness(); 1255 insets.top = insets.bottom = style.getYThickness(); 1256 return insets; 1257 } 1258 1259 1260 public void paintTreeCellBackground(SynthContext context, Graphics g, 1264 int x, int y, int w,int h) { 1265 int gtkState = GTKLookAndFeel.synthStateToGTKState( 1266 context.getRegion(), context.getComponentState()); 1267 getEngine(context).paintFlatBoxText(context, g, gtkState, "cell_odd", 1270 x, y, w, h); 1271 } 1272 1273 public void paintTreeCellFocus(SynthContext context, Graphics g, 1274 int x, int y, int w,int h) { 1275 GTKEngine engine = getEngine(context); 1276 int gtkState = GTKLookAndFeel.synthStateToGTKState( 1277 context.getRegion(), context.getComponentState()); 1278 engine.paintFocus(context, g, gtkState, "treeview", x, y, w, h); 1279 } 1280 1281 1282 private Insets getTreeCellRendererInsets(SynthContext context, 1286 Insets insets) { 1287 insets.left = insets.right = insets.top = insets.bottom = 1; 1288 return insets; 1289 } 1290 1291 1292 private Insets getTreeCellEditorInsets(SynthContext context, 1296 Insets insets) { 1297 insets.left = insets.right = insets.top = insets.bottom = 1; 1298 return insets; 1299 } 1300 1301 private void paintTreeCellEditorBackground(SynthContext context, 1302 GTKEngine engine, Graphics g, 1303 int x, int y, int w,int h) { 1304 int gtkState = GTKLookAndFeel.synthStateToGTKState( 1305 context.getRegion(), context.getComponentState()); 1306 engine.paintFlatBoxText(context, g, gtkState, "entry_bg", x, y, w, h); 1307 } 1308 1309 1310 public void paintTreeBackground(SynthContext context, Graphics g, 1314 int x, int y, int w,int h) { 1315 int gtkState = GTKLookAndFeel.synthStateToGTKState( 1317 context.getRegion(), context.getComponentState()); 1318 g.setColor(((GTKStyle)context.getStyle()).getGTKColor( 1319 context.getComponent(), context.getRegion(), gtkState, 1320 GTKColorType.TEXT_BACKGROUND)); 1321 g.fillRect(x, y, w, h); 1322 } 1323 1324 1325 public void paintViewportBackground(SynthContext context, Graphics g, 1329 int x, int y, int w,int h) { 1330 int gtkState = GTKLookAndFeel.synthStateToGTKState( 1335 context.getRegion(), context.getComponentState()); 1336 g.setColor(((GTKStyle)context.getStyle()).getGTKColor( 1337 context.getComponent(), context.getRegion(), gtkState, 1338 GTKColorType.TEXT_BACKGROUND)); 1339 g.fillRect(x, y, w, h); 1340 } 1341 1342 1343 1344 static class ListTableFocusBorder extends AbstractBorder implements 1346 UIResource { 1347 1348 private boolean selectedCell; 1349 1350 public static ListTableFocusBorder getSelectedCellBorder() { 1351 return new ListTableFocusBorder(true); 1352 } 1353 1354 public static ListTableFocusBorder getUnselectedCellBorder() { 1355 return new ListTableFocusBorder(false); 1356 } 1357 1358 public ListTableFocusBorder(boolean selectedCell) { 1359 this.selectedCell = selectedCell; 1360 } 1361 1362 private SynthContext getContext(Component c) { 1363 SynthContext context = null; 1364 1365 Component parent = c; 1366 while(parent != null && 1367 !(parent instanceof JTable) && 1368 !(parent instanceof JList)) { 1369 parent = parent.getParent(); 1370 } 1371 1372 ComponentUI ui = null; 1373 if (parent instanceof JTable) { 1374 ui = ((JTable)parent).getUI(); 1375 } else if (parent instanceof JList) { 1376 ui = ((JList)parent).getUI(); 1377 } 1378 1379 if (ui instanceof SynthUI) { 1380 context = ((SynthUI)ui).getContext((JComponent)parent); 1381 } 1382 1383 return context; 1384 } 1385 1386 public void paintBorder(Component c, Graphics g, int x, int y, 1387 int w, int h) { 1388 SynthContext context = getContext(c); 1389 int state = (selectedCell? SynthConstants.SELECTED: 1390 SynthConstants.FOCUSED | SynthConstants.ENABLED); 1391 1392 if (context != null) { 1393 ((GTKStyle)context.getStyle()).getEngine(context). 1394 paintFocus(context, g, state, "", x, y, w, h); 1395 } else { 1396 g.setColor(Color.BLACK); 1397 GTKEngine.INSTANCE._paintFocus( 1398 g, x, y, w, h, GTKEngine.DEFAULT_FOCUS_PATTERN, 1); 1399 } 1400 } 1401 public Insets getBorderInsets(Component c) { 1402 int size = 1; 1403 SynthContext context = getContext(c); 1404 if (context != null) { 1405 size = ((GTKStyle)context.getStyle()).getClassSpecificIntValue( 1406 context, "focus-line-width", 1); 1407 } 1408 return new Insets(size, size, size, size); 1409 } 1410 public Insets getBorderInsets(Component c, Insets i) { 1411 Insets ins = getBorderInsets(c); 1412 if (i == null) { 1413 return ins; 1414 } 1415 i.left = ins.left; 1416 i.right = ins.right; 1417 i.top = ins.top; 1418 i.bottom = ins.bottom; 1419 return i; 1420 } 1421 public boolean isBorderOpaque() { 1422 return true; 1423 } 1424 } 1425} 1426 | Popular Tags |