PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/bsh/commands/thinBorder.bsh

#
Unknown | 70 lines | 57 code | 13 blank | 0 comment | 0 complexity | 7c3f8caf414c9ef4813b1661c8dc7920 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. * Draw a 1 pixel border given a color for topLeft and bottomRight.
  16. */
  17. drawBorder(g, x, y, width, height, topLeft, bottomRight) {
  18. Color oldColor = g.color;
  19. g.color=topLeft;
  20. g.drawLine(x, y, x+width-1, y);
  21. g.drawLine(x, y, x, y+height-1);
  22. g.color=bottomRight;
  23. g.drawLine(x+width-1, y, x+width-1, y+height-1);
  24. g.drawLine(x, y+height-1, x+width-1, y+height-1);
  25. g.color=oldColor;
  26. }
  27. public void paintBorder(c, g, x, y, width, height) {
  28. Color bgColor = c.background;
  29. Color dark = (darkColor==null) ? bgColor.darker().darker() :
  30. darkColor;
  31. Color light = (lightColor==null) ? bgColor.brighter() :
  32. lightColor;
  33. if(c instanceof AbstractButton) {
  34. if(c.rolloverEnabled && !c.model.rollover && c.opaque) {
  35. drawBorder(g, x, y, width, height, bgColor, bgColor);
  36. } else {
  37. if(c.model.pressed)
  38. drawBorder(g, x, y, width, height, dark, light);
  39. else
  40. drawBorder(g, x, y, width, height, light, dark);
  41. }
  42. } else {
  43. drawBorder(g, x, y, width, height, light, dark);
  44. }
  45. }
  46. /**
  47. * Returns the insets of the border.
  48. *
  49. * @param c the component for which this border insets value applies
  50. */
  51. public Insets getBorderInsets(Component c) { return INSETS; }
  52. /**
  53. * Always returns false
  54. */
  55. public boolean isBorderOpaque() { return false; }
  56. return this;
  57. }