PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/bsh/commands/thinBorder.bsh

#
Unknown | 80 lines | 67 code | 13 blank | 0 comment | 0 complexity | e5f8248b0f5ee283fd8081f3a560cfde MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /**
  2. * A one pixel wide bevel border. This border works for buttons (with optional
  3. * rollover) and other components
  4. *
  5. * @author Daniel Leuck
  6. */
  7. import javax.swing.border.*;
  8. Insets INSETS = new Insets(1,1,1,1);
  9. public thinBorder() { return thinBorder(null, null, false); }
  10. public thinBorder(Color lightColor, Color darkColor) {
  11. return thinBorder(lightColor, darkColor, false);
  12. }
  13. public thinBorder(Color lightColor, Color darkColor, boolean rollOver)
  14. {
  15. /**
  16. * Draw a 1 pixel border given a color for topLeft and bottomRight.
  17. */
  18. drawBorder(g, x, y, width, height, topLeft, bottomRight) {
  19. //Color oldColor = g.color;
  20. Color oldColor = g.getColor();
  21. //g.color=topLeft;
  22. g.setColor(topLeft);
  23. g.drawLine(x, y, x+width-1, y);
  24. g.drawLine(x, y, x, y+height-1);
  25. //g.color=bottomRight;
  26. g.setColor(bottomRight);
  27. g.drawLine(x+width-1, y, x+width-1, y+height-1);
  28. g.drawLine(x, y+height-1, x+width-1, y+height-1);
  29. //g.color=oldColor;
  30. g.setColor(oldColor);
  31. }
  32. public void paintBorder(c, g, x, y, width, height)
  33. {
  34. // Access to the background color is protected on the Mac for
  35. // some reason... workaround
  36. try {
  37. Color bgColor = c.background;
  38. Color dark = (darkColor==null) ? bgColor.darker().darker() :
  39. darkColor;
  40. Color light = (lightColor==null) ? bgColor.brighter() :
  41. lightColor;
  42. if(c instanceof AbstractButton) {
  43. if(c.rolloverEnabled && !c.model.rollover && c.opaque) {
  44. drawBorder(g, x, y, width, height, bgColor, bgColor);
  45. } else {
  46. if(c.model.isPressed())
  47. drawBorder(g, x, y, width, height, dark, light);
  48. else
  49. drawBorder(g, x, y, width, height, light, dark);
  50. }
  51. } else {
  52. drawBorder(g, x, y, width, height, light, dark);
  53. }
  54. } catch ( SecurityException e ) { }
  55. }
  56. /**
  57. * Returns the insets of the border.
  58. *
  59. * @param c the component for which this border insets value applies
  60. */
  61. public Insets getBorderInsets(Component c) { return INSETS; }
  62. /**
  63. * Always returns false
  64. */
  65. public boolean isBorderOpaque() { return false; }
  66. return this;
  67. }