1. /*
  2. * @(#)MetalUtils.java 1.24 00/07/26
  3. *
  4. * Copyright 1998-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing.plaf.metal;
  11. import javax.swing.plaf.*;
  12. import javax.swing.*;
  13. import java.awt.*;
  14. /**
  15. * This is a dumping ground for random stuff we want to use in several places.
  16. *
  17. * @version 1.24 07/26/00
  18. * @author Steve Wilson
  19. */
  20. class MetalUtils {
  21. static void drawFlush3DBorder(Graphics g, Rectangle r) {
  22. drawFlush3DBorder(g, r.x, r.y, r.width, r.height);
  23. }
  24. /**
  25. * This draws the "Flush 3D Border" which is used throughout the Metal L&F
  26. */
  27. static void drawFlush3DBorder(Graphics g, int x, int y, int w, int h) {
  28. g.translate( x, y);
  29. g.setColor( MetalLookAndFeel.getControlDarkShadow() );
  30. g.drawRect( 0, 0, w-2, h-2 );
  31. g.setColor( MetalLookAndFeel.getControlHighlight() );
  32. g.drawRect( 1, 1, w-2, h-2 );
  33. g.setColor( MetalLookAndFeel.getControl() );
  34. g.drawLine( 0, h-1, 1, h-2 );
  35. g.drawLine( w-1, 0, w-2, 1 );
  36. g.translate( -x, -y);
  37. }
  38. /**
  39. * This draws a variant "Flush 3D Border"
  40. * It is used for things like pressed buttons.
  41. */
  42. static void drawPressed3DBorder(Graphics g, Rectangle r) {
  43. drawPressed3DBorder( g, r.x, r.y, r.width, r.height );
  44. }
  45. static void drawDisabledBorder(Graphics g, int x, int y, int w, int h) {
  46. g.translate( x, y);
  47. g.setColor( MetalLookAndFeel.getControlShadow() );
  48. g.drawRect( 0, 0, w-1, h-1 );
  49. }
  50. /**
  51. * This draws a variant "Flush 3D Border"
  52. * It is used for things like pressed buttons.
  53. */
  54. static void drawPressed3DBorder(Graphics g, int x, int y, int w, int h) {
  55. g.translate( x, y);
  56. drawFlush3DBorder(g, 0, 0, w, h);
  57. g.setColor( MetalLookAndFeel.getControlShadow() );
  58. g.drawLine( 1, 1, 1, h-2 );
  59. g.drawLine( 1, 1, w-2, 1 );
  60. g.translate( -x, -y);
  61. }
  62. /**
  63. * This draws a variant "Flush 3D Border"
  64. * It is used for things like active toggle buttons.
  65. * This is used rarely.
  66. */
  67. static void drawDark3DBorder(Graphics g, Rectangle r) {
  68. drawDark3DBorder(g, r.x, r.y, r.width, r.height);
  69. }
  70. /**
  71. * This draws a variant "Flush 3D Border"
  72. * It is used for things like active toggle buttons.
  73. * This is used rarely.
  74. */
  75. static void drawDark3DBorder(Graphics g, int x, int y, int w, int h) {
  76. g.translate( x, y);
  77. drawFlush3DBorder(g, 0, 0, w, h);
  78. g.setColor( MetalLookAndFeel.getControl() );
  79. g.drawLine( 1, 1, 1, h-2 );
  80. g.drawLine( 1, 1, w-2, 1 );
  81. g.setColor( MetalLookAndFeel.getControlShadow() );
  82. g.drawLine( 1, h-2, 1, h-2 );
  83. g.drawLine( w-2, 1, w-2, 1 );
  84. g.translate( -x, -y);
  85. }
  86. static void drawButtonBorder(Graphics g, int x, int y, int w, int h, boolean active) {
  87. if (active) {
  88. drawActiveButtonBorder(g, x, y, w, h);
  89. } else {
  90. drawFlush3DBorder(g, x, y, w, h);
  91. }
  92. }
  93. static void drawActiveButtonBorder(Graphics g, int x, int y, int w, int h) {
  94. drawFlush3DBorder(g, x, y, w, h);
  95. g.setColor( MetalLookAndFeel.getPrimaryControl() );
  96. g.drawLine( x+1, y+1, x+1, h-3 );
  97. g.drawLine( x+1, y+1, w-3, x+1 );
  98. g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
  99. g.drawLine( x+2, h-2, w-2, h-2 );
  100. g.drawLine( w-2, y+2, w-2, h-2 );
  101. }
  102. static void drawDefaultButtonBorder(Graphics g, int x, int y, int w, int h, boolean active) {
  103. drawButtonBorder(g, x+1, y+1, w-1, h-1, active);
  104. g.setColor( MetalLookAndFeel.getControlDarkShadow() );
  105. g.drawRect( x, y, w-3, h-3 );
  106. g.drawLine( w-2, 0, w-2, 0);
  107. g.drawLine( 0, h-2, 0, h-2);
  108. }
  109. /*
  110. * Convenience function for determining ComponentOrientation. Helps us
  111. * avoid having Munge directives throughout the code.
  112. */
  113. static boolean isLeftToRight( Component c ) {
  114. return c.getComponentOrientation().isLeftToRight();
  115. }
  116. }