src/share/classes/javax/swing/plaf/basic/BasicSpinnerUI.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2010, 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


 584         super.getBaselineResizeBehavior(c);
 585         return spinner.getEditor().getBaselineResizeBehavior();
 586     }
 587 
 588     /**
 589      * A handler for spinner arrow button mouse and action events.  When
 590      * a left mouse pressed event occurs we look up the (enabled) spinner
 591      * that's the source of the event and start the autorepeat timer.  The
 592      * timer fires action events until any button is released at which
 593      * point the timer is stopped and the reference to the spinner cleared.
 594      * The timer doesn't start until after a 300ms delay, so often the
 595      * source of the initial (and final) action event is just the button
 596      * logic for mouse released - which means that we're relying on the fact
 597      * that our mouse listener runs after the buttons mouse listener.
 598      * <p>
 599      * Note that one instance of this handler is shared by all slider previous
 600      * arrow buttons and likewise for all of the next buttons,
 601      * so it doesn't have any state that persists beyond the limits
 602      * of a single button pressed/released gesture.
 603      */

 604     private static class ArrowButtonHandler extends AbstractAction
 605                                             implements FocusListener, MouseListener, UIResource {
 606         final javax.swing.Timer autoRepeatTimer;
 607         final boolean isNext;
 608         JSpinner spinner = null;
 609         JButton arrowButton = null;
 610 
 611         ArrowButtonHandler(String name, boolean isNext) {
 612             super(name);
 613             this.isNext = isNext;
 614             autoRepeatTimer = new javax.swing.Timer(60, this);
 615             autoRepeatTimer.setInitialDelay(300);
 616         }
 617 
 618         private JSpinner eventToSpinner(AWTEvent e) {
 619             Object src = e.getSource();
 620             while ((src instanceof Component) && !(src instanceof JSpinner)) {
 621                 src = ((Component)src).getParent();
 622             }
 623             return (src instanceof JSpinner) ? (JSpinner)src : null;


   1 /*
   2  * Copyright (c) 2000, 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


 584         super.getBaselineResizeBehavior(c);
 585         return spinner.getEditor().getBaselineResizeBehavior();
 586     }
 587 
 588     /**
 589      * A handler for spinner arrow button mouse and action events.  When
 590      * a left mouse pressed event occurs we look up the (enabled) spinner
 591      * that's the source of the event and start the autorepeat timer.  The
 592      * timer fires action events until any button is released at which
 593      * point the timer is stopped and the reference to the spinner cleared.
 594      * The timer doesn't start until after a 300ms delay, so often the
 595      * source of the initial (and final) action event is just the button
 596      * logic for mouse released - which means that we're relying on the fact
 597      * that our mouse listener runs after the buttons mouse listener.
 598      * <p>
 599      * Note that one instance of this handler is shared by all slider previous
 600      * arrow buttons and likewise for all of the next buttons,
 601      * so it doesn't have any state that persists beyond the limits
 602      * of a single button pressed/released gesture.
 603      */
 604     @SuppressWarnings("serial") // Superclass is not serializable across versions
 605     private static class ArrowButtonHandler extends AbstractAction
 606                                             implements FocusListener, MouseListener, UIResource {
 607         final javax.swing.Timer autoRepeatTimer;
 608         final boolean isNext;
 609         JSpinner spinner = null;
 610         JButton arrowButton = null;
 611 
 612         ArrowButtonHandler(String name, boolean isNext) {
 613             super(name);
 614             this.isNext = isNext;
 615             autoRepeatTimer = new javax.swing.Timer(60, this);
 616             autoRepeatTimer.setInitialDelay(300);
 617         }
 618 
 619         private JSpinner eventToSpinner(AWTEvent e) {
 620             Object src = e.getSource();
 621             while ((src instanceof Component) && !(src instanceof JSpinner)) {
 622                 src = ((Component)src).getParent();
 623             }
 624             return (src instanceof JSpinner) ? (JSpinner)src : null;