1 7 package javax.swing.plaf.synth; 8 9 import java.awt.*; 10 import javax.swing.*; 11 import javax.swing.plaf.UIResource ; 12 13 19 class SynthArrowButton extends JButton implements SwingConstants, UIResource { 20 private int direction; 21 22 public SynthArrowButton(int direction) { 23 super(); 24 setFocusable(false); 25 setDirection(direction); 26 setDefaultCapable(false); 27 } 28 29 public String getUIClassID() { 30 return "ArrowButtonUI"; 31 } 32 33 public void updateUI() { 34 setUI(new SynthArrowButtonUI()); 35 } 36 37 public void setDirection(int dir) { 38 direction = dir; 39 putClientProperty("__arrow_direction__", new Integer (dir)); 40 repaint(); 41 } 42 43 public int getDirection() { 44 return direction; 45 } 46 47 48 private static class SynthArrowButtonUI extends SynthButtonUI { 49 protected void installDefaults(AbstractButton b) { 50 super.installDefaults(b); 51 updateStyle(b); 52 } 53 54 protected void paint(SynthContext context, Graphics g) { 55 SynthArrowButton button = (SynthArrowButton )context. 56 getComponent(); 57 context.getPainter().paintArrowButtonForeground( 58 context, g, 0, 0, button.getWidth(), button.getHeight(), 59 button.getDirection()); 60 } 61 62 void paintBackground(SynthContext context, Graphics g, JComponent c) { 63 context.getPainter().paintArrowButtonBackground(context, g, 0, 0, 64 c.getWidth(), c.getHeight()); 65 } 66 67 public void paintBorder(SynthContext context, Graphics g, int x, 68 int y, int w, int h) { 69 context.getPainter().paintArrowButtonBorder(context, g, x, y, w,h); 70 } 71 72 public Dimension getMinimumSize() { 73 return new Dimension(5, 5); 74 } 75 76 public Dimension getMaximumSize() { 77 return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); 78 } 79 80 public Dimension getPreferredSize(JComponent c) { 81 SynthContext context = getContext(c); 82 int size = context.getStyle().getInt(context, "ArrowButton.size", 83 16); 84 85 context.dispose(); 86 return new Dimension(size, size); 87 } 88 } 89 } 90 | Popular Tags |