1. /*
  2. * @(#)SynthArrowButton.java 1.15 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.plaf.synth;
  8. import java.awt.*;
  9. import javax.swing.*;
  10. import javax.swing.plaf.UIResource;
  11. /**
  12. * JButton object that draws a scaled Arrow in one of the cardinal directions.
  13. *
  14. * @version 1.15, 12/19/03
  15. * @author Scott Violet
  16. */
  17. class SynthArrowButton extends JButton implements SwingConstants, UIResource {
  18. private int direction;
  19. public SynthArrowButton(int direction) {
  20. super();
  21. setFocusable(false);
  22. setDirection(direction);
  23. setDefaultCapable(false);
  24. }
  25. public String getUIClassID() {
  26. return "ArrowButtonUI";
  27. }
  28. public void updateUI() {
  29. setUI(new SynthArrowButtonUI());
  30. }
  31. public void setDirection(int dir) {
  32. direction = dir;
  33. putClientProperty("__arrow_direction__", new Integer(dir));
  34. repaint();
  35. }
  36. public int getDirection() {
  37. return direction;
  38. }
  39. private static class SynthArrowButtonUI extends SynthButtonUI {
  40. protected void installDefaults(AbstractButton b) {
  41. super.installDefaults(b);
  42. updateStyle(b);
  43. }
  44. protected void paint(SynthContext context, Graphics g) {
  45. SynthArrowButton button = (SynthArrowButton)context.
  46. getComponent();
  47. context.getPainter().paintArrowButtonForeground(
  48. context, g, 0, 0, button.getWidth(), button.getHeight(),
  49. button.getDirection());
  50. }
  51. void paintBackground(SynthContext context, Graphics g, JComponent c) {
  52. context.getPainter().paintArrowButtonBackground(context, g, 0, 0,
  53. c.getWidth(), c.getHeight());
  54. }
  55. public void paintBorder(SynthContext context, Graphics g, int x,
  56. int y, int w, int h) {
  57. context.getPainter().paintArrowButtonBorder(context, g, x, y, w,h);
  58. }
  59. public Dimension getMinimumSize() {
  60. return new Dimension(5, 5);
  61. }
  62. public Dimension getMaximumSize() {
  63. return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
  64. }
  65. public Dimension getPreferredSize(JComponent c) {
  66. SynthContext context = getContext(c);
  67. int size = context.getStyle().getInt(context, "ArrowButton.size",
  68. 16);
  69. context.dispose();
  70. return new Dimension(size, size);
  71. }
  72. }
  73. }