1 30 31 package com.jgoodies.looks.windows; 32 33 import java.awt.Component ; 34 import java.awt.LayoutManager ; 35 36 import javax.swing.JButton ; 37 import javax.swing.JComponent ; 38 import javax.swing.JSpinner ; 39 import javax.swing.SwingConstants ; 40 import javax.swing.border.Border ; 41 import javax.swing.border.EmptyBorder ; 42 import javax.swing.plaf.BorderUIResource ; 43 import javax.swing.plaf.ComponentUI ; 44 45 import com.jgoodies.looks.LookUtils; 46 import com.jgoodies.looks.common.ExtBasicArrowButtonHandler; 47 import com.jgoodies.looks.common.ExtBasicSpinnerLayout; 48 49 55 public final class WindowsSpinnerUI extends com.sun.java.swing.plaf.windows.WindowsSpinnerUI { 56 57 private static final Border EMPTY_BORDER = new BorderUIResource ( 58 new EmptyBorder (2, 2, 2, 2)); 59 60 61 public static ComponentUI createUI(JComponent b) { 62 return new WindowsSpinnerUI(); 63 } 64 65 72 private static final ExtBasicArrowButtonHandler nextButtonHandler = new ExtBasicArrowButtonHandler( 73 "increment", 74 true); 75 private static final ExtBasicArrowButtonHandler previousButtonHandler = new ExtBasicArrowButtonHandler( 76 "decrement", 77 false); 78 79 80 93 protected Component createPreviousButton() { 94 if (LookUtils.IS_LAF_WINDOWS_XP_ENABLED) 95 return super.createPreviousButton(); 96 97 JButton b = new WindowsArrowButton(SwingConstants.SOUTH); 98 b.addActionListener(previousButtonHandler); 99 b.addMouseListener(previousButtonHandler); 100 return b; 101 } 102 103 104 116 protected Component createNextButton() { 117 if (LookUtils.IS_LAF_WINDOWS_XP_ENABLED) 118 return super.createNextButton(); 119 120 JButton b = new WindowsArrowButton(SwingConstants.NORTH); 121 b.addActionListener(nextButtonHandler); 122 b.addMouseListener(nextButtonHandler); 123 return b; 124 } 125 126 127 149 protected JComponent createEditor() { 150 JComponent editor = spinner.getEditor(); 151 configureEditor(editor); 152 return editor; 153 } 154 155 156 169 protected LayoutManager createLayout() { 170 return new ExtBasicSpinnerLayout(); 171 } 172 173 174 191 protected void replaceEditor(JComponent oldEditor, JComponent newEditor) { 192 spinner.remove(oldEditor); 193 configureEditor(newEditor); 194 spinner.add(newEditor, "Editor"); 195 } 196 197 198 201 private void configureEditor(JComponent editor) { 202 if ((editor instanceof JSpinner.DefaultEditor )) { 203 JSpinner.DefaultEditor defaultEditor = (JSpinner.DefaultEditor ) editor; 204 defaultEditor.getTextField().setBorder(EMPTY_BORDER); 205 } 206 } 207 208 } | Popular Tags |