src/macosx/classes/com/apple/laf/AquaSpinnerUI.java

Print this page


   1 /*
   2  * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 171         width = width - insets.left - insets.right;
 172         height = height - insets.top - insets.bottom;
 173         if (width >= 0 && height >= 0) {
 174             int baseline = editor.getBaseline(width, height);
 175             if (baseline >= 0) {
 176                 return insets.top + baseline;
 177             }
 178         }
 179         return -1;
 180     }
 181 
 182     /**
 183      * {@inheritDoc}
 184      */
 185     public Component.BaselineResizeBehavior getBaselineResizeBehavior(
 186             JComponent c) {
 187         super.getBaselineResizeBehavior(c);
 188         return spinner.getEditor().getBaselineResizeBehavior();
 189     }
 190 

 191     class TransparentButton extends JButton implements SwingConstants {
 192         boolean interceptRepaints = false;
 193 
 194         public TransparentButton() {
 195             super();
 196             setFocusable(false);
 197             // only intercept repaints if we are after this has been initialized
 198             // otherwise we can't talk to our containing class
 199             interceptRepaints = true;
 200         }
 201 
 202         public void paint(final Graphics g) {}
 203 
 204         public void repaint() {
 205             // only intercept repaints if we are after this has been initialized
 206             // otherwise we can't talk to our containing class
 207             if (interceptRepaints) {
 208                 if (spinPainter == null) return;
 209                 spinPainter.repaint();
 210             }


 276 
 277     private ActionMap getActionMap() {
 278         ActionMap map = (ActionMap)UIManager.get("Spinner.actionMap");
 279 
 280         if (map == null) {
 281             map = createActionMap();
 282             if (map != null) {
 283                 UIManager.getLookAndFeelDefaults().put("Spinner.actionMap", map);
 284             }
 285         }
 286         return map;
 287     }
 288 
 289     private ActionMap createActionMap() {
 290         final ActionMap map = new ActionMapUIResource();
 291         map.put("increment", getNextButtonHandler());
 292         map.put("decrement", getPreviousButtonHandler());
 293         return map;
 294     }
 295 

 296     private static class ArrowButtonHandler extends AbstractAction implements MouseListener {
 297         final javax.swing.Timer autoRepeatTimer;
 298         final boolean isNext;
 299         JSpinner spinner = null;
 300 
 301         ArrowButtonHandler(final String name, final boolean isNext) {
 302             super(name);
 303             this.isNext = isNext;
 304             autoRepeatTimer = new javax.swing.Timer(60, this);
 305             autoRepeatTimer.setInitialDelay(300);
 306         }
 307 
 308         private JSpinner eventToSpinner(final AWTEvent e) {
 309             Object src = e.getSource();
 310             while ((src instanceof Component) && !(src instanceof JSpinner)) {
 311                 src = ((Component)src).getParent();
 312             }
 313             return (src instanceof JSpinner) ? (JSpinner)src : null;
 314         }
 315 


 444          */
 445         private void focusSpinnerIfNecessary() {
 446             final Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
 447             if (!spinner.isRequestFocusEnabled() || (fo != null && (SwingUtilities.isDescendingFrom(fo, spinner)))) return;
 448             Container root = spinner;
 449 
 450             if (!root.isFocusCycleRoot()) {
 451                 root = root.getFocusCycleRootAncestor();
 452             }
 453 
 454             if (root == null) return;
 455             final FocusTraversalPolicy ftp = root.getFocusTraversalPolicy();
 456             final Component child = ftp.getComponentAfter(root, spinner);
 457 
 458             if (child != null && SwingUtilities.isDescendingFrom(child, spinner)) {
 459                 child.requestFocus();
 460             }
 461         }
 462     }
 463 

 464     class SpinPainter extends JComponent {
 465         final AquaPainter<JRSUIState> painter = AquaPainter.create(JRSUIStateFactory.getSpinnerArrows());
 466 
 467         ButtonModel fTopModel;
 468         ButtonModel fBottomModel;
 469 
 470         boolean fPressed = false;
 471         boolean fTopPressed = false;
 472 
 473         Dimension kPreferredSize = new Dimension(15, 24); // 19,27 before trimming
 474 
 475         public SpinPainter(final AbstractButton top, final AbstractButton bottom) {
 476             if (top != null) {
 477                 fTopModel = top.getModel();
 478             }
 479 
 480             if (bottom != null) {
 481                 fBottomModel = bottom.getModel();
 482             }
 483         }


   1 /*
   2  * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 171         width = width - insets.left - insets.right;
 172         height = height - insets.top - insets.bottom;
 173         if (width >= 0 && height >= 0) {
 174             int baseline = editor.getBaseline(width, height);
 175             if (baseline >= 0) {
 176                 return insets.top + baseline;
 177             }
 178         }
 179         return -1;
 180     }
 181 
 182     /**
 183      * {@inheritDoc}
 184      */
 185     public Component.BaselineResizeBehavior getBaselineResizeBehavior(
 186             JComponent c) {
 187         super.getBaselineResizeBehavior(c);
 188         return spinner.getEditor().getBaselineResizeBehavior();
 189     }
 190 
 191     @SuppressWarnings("serial") // Superclass is not serializable across versions
 192     class TransparentButton extends JButton implements SwingConstants {
 193         boolean interceptRepaints = false;
 194 
 195         public TransparentButton() {
 196             super();
 197             setFocusable(false);
 198             // only intercept repaints if we are after this has been initialized
 199             // otherwise we can't talk to our containing class
 200             interceptRepaints = true;
 201         }
 202 
 203         public void paint(final Graphics g) {}
 204 
 205         public void repaint() {
 206             // only intercept repaints if we are after this has been initialized
 207             // otherwise we can't talk to our containing class
 208             if (interceptRepaints) {
 209                 if (spinPainter == null) return;
 210                 spinPainter.repaint();
 211             }


 277 
 278     private ActionMap getActionMap() {
 279         ActionMap map = (ActionMap)UIManager.get("Spinner.actionMap");
 280 
 281         if (map == null) {
 282             map = createActionMap();
 283             if (map != null) {
 284                 UIManager.getLookAndFeelDefaults().put("Spinner.actionMap", map);
 285             }
 286         }
 287         return map;
 288     }
 289 
 290     private ActionMap createActionMap() {
 291         final ActionMap map = new ActionMapUIResource();
 292         map.put("increment", getNextButtonHandler());
 293         map.put("decrement", getPreviousButtonHandler());
 294         return map;
 295     }
 296 
 297     @SuppressWarnings("serial") // Superclass is not serializable across versions
 298     private static class ArrowButtonHandler extends AbstractAction implements MouseListener {
 299         final javax.swing.Timer autoRepeatTimer;
 300         final boolean isNext;
 301         JSpinner spinner = null;
 302 
 303         ArrowButtonHandler(final String name, final boolean isNext) {
 304             super(name);
 305             this.isNext = isNext;
 306             autoRepeatTimer = new javax.swing.Timer(60, this);
 307             autoRepeatTimer.setInitialDelay(300);
 308         }
 309 
 310         private JSpinner eventToSpinner(final AWTEvent e) {
 311             Object src = e.getSource();
 312             while ((src instanceof Component) && !(src instanceof JSpinner)) {
 313                 src = ((Component)src).getParent();
 314             }
 315             return (src instanceof JSpinner) ? (JSpinner)src : null;
 316         }
 317 


 446          */
 447         private void focusSpinnerIfNecessary() {
 448             final Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
 449             if (!spinner.isRequestFocusEnabled() || (fo != null && (SwingUtilities.isDescendingFrom(fo, spinner)))) return;
 450             Container root = spinner;
 451 
 452             if (!root.isFocusCycleRoot()) {
 453                 root = root.getFocusCycleRootAncestor();
 454             }
 455 
 456             if (root == null) return;
 457             final FocusTraversalPolicy ftp = root.getFocusTraversalPolicy();
 458             final Component child = ftp.getComponentAfter(root, spinner);
 459 
 460             if (child != null && SwingUtilities.isDescendingFrom(child, spinner)) {
 461                 child.requestFocus();
 462             }
 463         }
 464     }
 465 
 466     @SuppressWarnings("serial") // Superclass is not serializable across versions
 467     class SpinPainter extends JComponent {
 468         final AquaPainter<JRSUIState> painter = AquaPainter.create(JRSUIStateFactory.getSpinnerArrows());
 469 
 470         ButtonModel fTopModel;
 471         ButtonModel fBottomModel;
 472 
 473         boolean fPressed = false;
 474         boolean fTopPressed = false;
 475 
 476         Dimension kPreferredSize = new Dimension(15, 24); // 19,27 before trimming
 477 
 478         public SpinPainter(final AbstractButton top, final AbstractButton bottom) {
 479             if (top != null) {
 480                 fTopModel = top.getModel();
 481             }
 482 
 483             if (bottom != null) {
 484                 fBottomModel = bottom.getModel();
 485             }
 486         }