/plugins/LookAndFeel/tags/1.6.1/lipstik-1.1/src/com/lipstikLF/delegate/LipstikSplitPaneContentBorder.java

# · Java · 124 lines · 83 code · 26 blank · 15 comment · 17 complexity · c3c7f59414a75fda2af916f933472e87 MD5 · raw file

  1. package com.lipstikLF.delegate;
  2. import javax.swing.*;
  3. import javax.swing.border.Border;
  4. import java.awt.*;
  5. public class LipstikSplitPaneContentBorder implements Border
  6. {
  7. /** The first color for the shadow gradient */
  8. private Color fromColor;
  9. /** The second color for the shadow gradient */
  10. private Color toColor;
  11. /** The background color */
  12. private Color bg;
  13. /** If true, draws a line around the bordered component */
  14. private boolean drawBoundaryLine;
  15. public LipstikSplitPaneContentBorder()
  16. {
  17. this(null, null, null, false);
  18. }
  19. public LipstikSplitPaneContentBorder(boolean drawBoundaryLine)
  20. {
  21. this(null, null, null, drawBoundaryLine);
  22. }
  23. public LipstikSplitPaneContentBorder(Color bg, Color fromColor, Color toColor)
  24. {
  25. this(bg, fromColor, toColor, false);
  26. }
  27. public LipstikSplitPaneContentBorder(Color bg, Color fromColor, Color toColor, boolean drawBoundaryLine)
  28. {
  29. this.drawBoundaryLine=drawBoundaryLine;
  30. if (bg != null)
  31. this.bg = bg;
  32. else
  33. this.bg = UIManager.getColor("Button.borderColor");
  34. if(fromColor != null)
  35. this.fromColor = fromColor;
  36. else
  37. this.fromColor = UIManager.getColor("Button.borderColor");
  38. if (toColor != null)
  39. this.toColor = toColor;
  40. else
  41. this.toColor = UIManager.getColor("ScrollPane.background");
  42. }
  43. /** Returns the insets of this border */
  44. public Insets getBorderInsets(Component c)
  45. {
  46. int leftTop=(drawBoundaryLine ? 1 : 0);
  47. int rightBottom=(drawBoundaryLine ? 4 : 3);
  48. return new Insets(leftTop, leftTop, rightBottom, rightBottom);
  49. }
  50. /** Returns true if this border is opaque */
  51. public boolean isBorderOpaque()
  52. {
  53. return false;
  54. }
  55. public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
  56. {
  57. g.setColor(toColor);
  58. g.fillRect(x, y+height-3, 3, 3);
  59. g.fillRect(x+width-3, y, 3, 3);
  60. for(int i=0; i<3; i++)
  61. {
  62. g.setColor(blendColors(fromColor, toColor, (double)(i+2)/(double)4));
  63. g.drawLine(x+width-3+i, y+i+1, x+width-3+i, y+height-3+i);
  64. g.drawLine(x+i+1, y+height-3+i, x+width-3+i, y+height-3+i);
  65. }
  66. if(drawBoundaryLine)
  67. {
  68. g.setColor(bg);
  69. g.drawRect(x, y, x+width-4, y+height-4);
  70. }
  71. }
  72. /** Blends two colors.
  73. *
  74. * @param c1 The first color
  75. * @param c2 The second color
  76. * @param factor The ratio between the first and second color. If this is 0.0,
  77. * the result will be c1, if it is 1.0, the result will be c2.
  78. *
  79. * @return A color resulting from blending c1 and c2
  80. */
  81. private static Color blendColors(Color c1, Color c2, double factor)
  82. {
  83. if(c1 == null || c2 == null)
  84. {
  85. if(c1 != null)
  86. return c1;
  87. else
  88. if(c2 != null)
  89. return c2;
  90. else
  91. return Color.BLACK;
  92. }
  93. int r=(int)(c2.getRed()*factor+c1.getRed()*(1.0-factor));
  94. int g=(int)(c2.getGreen()*factor+c1.getGreen()*(1.0-factor));
  95. int b=(int)(c2.getBlue()*factor+c1.getBlue()*(1.0-factor));
  96. return new Color(r,g,b);
  97. }
  98. }