80 } 81 } 82 83 /** 84 * {@inheritDoc} 85 */ 86 @Override 87 protected void uninstallListeners() { 88 super.uninstallListeners(); 89 spinner.removePropertyChangeListener(this); 90 JComponent editor = spinner.getEditor(); 91 if (editor instanceof JSpinner.DefaultEditor) { 92 JTextField tf = ((JSpinner.DefaultEditor)editor).getTextField(); 93 if (tf != null) { 94 tf.removeFocusListener(editorFocusHandler); 95 } 96 } 97 } 98 99 /** 100 * Initializes the <code>JSpinner</code> <code>border</code>, 101 * <code>foreground</code>, and <code>background</code>, properties 102 * based on the corresponding "Spinner.*" properties from defaults table. 103 * The <code>JSpinners</code> layout is set to the value returned by 104 * <code>createLayout</code>. This method is called by <code>installUI</code>. 105 * 106 * @see #uninstallDefaults 107 * @see #installUI 108 * @see #createLayout 109 * @see LookAndFeel#installBorder 110 * @see LookAndFeel#installColors 111 */ 112 @Override 113 protected void installDefaults() { 114 LayoutManager layout = spinner.getLayout(); 115 116 if (layout == null || layout instanceof UIResource) { 117 spinner.setLayout(createLayout()); 118 } 119 updateStyle(spinner); 120 } 121 122 123 private void updateStyle(JSpinner c) { 124 SynthContext context = getContext(c, ENABLED); 125 SynthStyle oldStyle = style; 126 style = SynthLookAndFeel.updateStyle(context, this); 127 if (style != oldStyle) { 128 if (oldStyle != null) { 129 // Only call installKeyboardActions as uninstall is not 130 // public. 131 installKeyboardActions(); 132 } 133 } 134 context.dispose(); 135 } 136 137 138 /** 139 * Sets the <code>JSpinner's</code> layout manager to null. This 140 * method is called by <code>uninstallUI</code>. 141 * 142 * @see #installDefaults 143 * @see #uninstallUI 144 */ 145 @Override 146 protected void uninstallDefaults() { 147 if (spinner.getLayout() instanceof UIResource) { 148 spinner.setLayout(null); 149 } 150 151 SynthContext context = getContext(spinner, ENABLED); 152 153 style.uninstallDefaults(context); 154 context.dispose(); 155 style = null; 156 } 157 158 /** 159 * {@inheritDoc} 160 */ 173 b.setName("Spinner.previousButton"); 174 installPreviousButtonListeners(b); 175 return b; 176 } 177 178 179 /** 180 * {@inheritDoc} 181 */ 182 @Override 183 protected Component createNextButton() { 184 JButton b = new SynthArrowButton(SwingConstants.NORTH); 185 b.setName("Spinner.nextButton"); 186 installNextButtonListeners(b); 187 return b; 188 } 189 190 191 /** 192 * This method is called by installUI to get the editor component 193 * of the <code>JSpinner</code>. By default it just returns 194 * <code>JSpinner.getEditor()</code>. Subclasses can override 195 * <code>createEditor</code> to return a component that contains 196 * the spinner's editor or null, if they're going to handle adding 197 * the editor to the <code>JSpinner</code> in an 198 * <code>installUI</code> override. 199 * <p> 200 * Typically this method would be overridden to wrap the editor 201 * with a container with a custom border, since one can't assume 202 * that the editors border can be set directly. 203 * <p> 204 * The <code>replaceEditor</code> method is called when the spinners 205 * editor is changed with <code>JSpinner.setEditor</code>. If you've 206 * overriden this method, then you'll probably want to override 207 * <code>replaceEditor</code> as well. 208 * 209 * @return the JSpinners editor JComponent, spinner.getEditor() by default 210 * @see #installUI 211 * @see #replaceEditor 212 * @see JSpinner#getEditor 213 */ 214 @Override 215 protected JComponent createEditor() { 216 JComponent editor = spinner.getEditor(); 217 editor.setName("Spinner.editor"); 218 updateEditorAlignment(editor); 219 return editor; 220 } 221 222 223 /** 224 * Called by the <code>PropertyChangeListener</code> when the 225 * <code>JSpinner</code> editor property changes. It's the responsibility 226 * of this method to remove the old editor and add the new one. By 227 * default this operation is just: 228 * <pre> 229 * spinner.remove(oldEditor); 230 * spinner.add(newEditor, "Editor"); 231 * </pre> 232 * The implementation of <code>replaceEditor</code> should be coordinated 233 * with the <code>createEditor</code> method. 234 * 235 * @see #createEditor 236 * @see #createPropertyChangeListener 237 */ 238 @Override 239 protected void replaceEditor(JComponent oldEditor, JComponent newEditor) { 240 spinner.remove(oldEditor); 241 spinner.add(newEditor, "Editor"); 242 if (oldEditor instanceof JSpinner.DefaultEditor) { 243 JTextField tf = ((JSpinner.DefaultEditor)oldEditor).getTextField(); 244 if (tf != null) { 245 tf.removeFocusListener(editorFocusHandler); 246 } 247 } 248 if (newEditor instanceof JSpinner.DefaultEditor) { 249 JTextField tf = ((JSpinner.DefaultEditor)newEditor).getTextField(); 250 if (tf != null) { 251 tf.addFocusListener(editorFocusHandler); 252 } 253 } | 80 } 81 } 82 83 /** 84 * {@inheritDoc} 85 */ 86 @Override 87 protected void uninstallListeners() { 88 super.uninstallListeners(); 89 spinner.removePropertyChangeListener(this); 90 JComponent editor = spinner.getEditor(); 91 if (editor instanceof JSpinner.DefaultEditor) { 92 JTextField tf = ((JSpinner.DefaultEditor)editor).getTextField(); 93 if (tf != null) { 94 tf.removeFocusListener(editorFocusHandler); 95 } 96 } 97 } 98 99 /** 100 * Initializes the {@code JSpinner border}, 101 * {@code foreground}, and {@code background}, properties 102 * based on the corresponding "Spinner.*" properties from defaults table. 103 * The {@code JSpinners} layout is set to the value returned by 104 * {@code createLayout}. This method is called by {@code installUI}. 105 * 106 * @see #uninstallDefaults 107 * @see #installUI 108 * @see #createLayout 109 * @see LookAndFeel#installBorder 110 * @see LookAndFeel#installColors 111 */ 112 @Override 113 protected void installDefaults() { 114 LayoutManager layout = spinner.getLayout(); 115 116 if (layout == null || layout instanceof UIResource) { 117 spinner.setLayout(createLayout()); 118 } 119 updateStyle(spinner); 120 } 121 122 123 private void updateStyle(JSpinner c) { 124 SynthContext context = getContext(c, ENABLED); 125 SynthStyle oldStyle = style; 126 style = SynthLookAndFeel.updateStyle(context, this); 127 if (style != oldStyle) { 128 if (oldStyle != null) { 129 // Only call installKeyboardActions as uninstall is not 130 // public. 131 installKeyboardActions(); 132 } 133 } 134 context.dispose(); 135 } 136 137 138 /** 139 * Sets the {@code JSpinner's} layout manager to null. This 140 * method is called by {@code uninstallUI}. 141 * 142 * @see #installDefaults 143 * @see #uninstallUI 144 */ 145 @Override 146 protected void uninstallDefaults() { 147 if (spinner.getLayout() instanceof UIResource) { 148 spinner.setLayout(null); 149 } 150 151 SynthContext context = getContext(spinner, ENABLED); 152 153 style.uninstallDefaults(context); 154 context.dispose(); 155 style = null; 156 } 157 158 /** 159 * {@inheritDoc} 160 */ 173 b.setName("Spinner.previousButton"); 174 installPreviousButtonListeners(b); 175 return b; 176 } 177 178 179 /** 180 * {@inheritDoc} 181 */ 182 @Override 183 protected Component createNextButton() { 184 JButton b = new SynthArrowButton(SwingConstants.NORTH); 185 b.setName("Spinner.nextButton"); 186 installNextButtonListeners(b); 187 return b; 188 } 189 190 191 /** 192 * This method is called by installUI to get the editor component 193 * of the {@code JSpinner}. By default it just returns 194 * {@code JSpinner.getEditor()}. Subclasses can override 195 * {@code createEditor} to return a component that contains 196 * the spinner's editor or null, if they're going to handle adding 197 * the editor to the {@code JSpinner} in an 198 * {@code installUI} override. 199 * <p> 200 * Typically this method would be overridden to wrap the editor 201 * with a container with a custom border, since one can't assume 202 * that the editors border can be set directly. 203 * <p> 204 * The {@code replaceEditor} method is called when the spinners 205 * editor is changed with {@code JSpinner.setEditor}. If you've 206 * overriden this method, then you'll probably want to override 207 * {@code replaceEditor} as well. 208 * 209 * @return the JSpinners editor JComponent, spinner.getEditor() by default 210 * @see #installUI 211 * @see #replaceEditor 212 * @see JSpinner#getEditor 213 */ 214 @Override 215 protected JComponent createEditor() { 216 JComponent editor = spinner.getEditor(); 217 editor.setName("Spinner.editor"); 218 updateEditorAlignment(editor); 219 return editor; 220 } 221 222 223 /** 224 * Called by the {@code PropertyChangeListener} when the 225 * {@code JSpinner} editor property changes. It's the responsibility 226 * of this method to remove the old editor and add the new one. By 227 * default this operation is just: 228 * <pre> 229 * spinner.remove(oldEditor); 230 * spinner.add(newEditor, "Editor"); 231 * </pre> 232 * The implementation of {@code replaceEditor} should be coordinated 233 * with the {@code createEditor} method. 234 * 235 * @see #createEditor 236 * @see #createPropertyChangeListener 237 */ 238 @Override 239 protected void replaceEditor(JComponent oldEditor, JComponent newEditor) { 240 spinner.remove(oldEditor); 241 spinner.add(newEditor, "Editor"); 242 if (oldEditor instanceof JSpinner.DefaultEditor) { 243 JTextField tf = ((JSpinner.DefaultEditor)oldEditor).getTextField(); 244 if (tf != null) { 245 tf.removeFocusListener(editorFocusHandler); 246 } 247 } 248 if (newEditor instanceof JSpinner.DefaultEditor) { 249 JTextField tf = ((JSpinner.DefaultEditor)newEditor).getTextField(); 250 if (tf != null) { 251 tf.addFocusListener(editorFocusHandler); 252 } 253 } |