src/macosx/classes/sun/lwawt/LWScrollBarPeer.java

Print this page




  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
  23  * questions.
  24  */
  25 
  26 
  27 package sun.lwawt;
  28 
  29 import java.awt.Adjustable;
  30 import java.awt.Dimension;
  31 import java.awt.Scrollbar;
  32 import java.awt.event.AdjustmentEvent;
  33 import java.awt.event.AdjustmentListener;
  34 import java.awt.peer.ScrollbarPeer;
  35 
  36 import javax.swing.JScrollBar;
  37 
  38 final class LWScrollBarPeer extends LWComponentPeer<Scrollbar, JScrollBar>
  39         implements ScrollbarPeer, AdjustmentListener {
  40 
  41     //JScrollBar fires two changes with firePropertyChange (one for old value
  42     // and one for new one.
  43     // We save the last value and don't fire event if not changed.
  44     private int currentValue;
  45 
  46     LWScrollBarPeer(final Scrollbar target,
  47                     final PlatformComponent platformComponent) {
  48         super(target, platformComponent);
  49     }
  50 


  73     @Override
  74     public void setValues(final int value, final int visible, final int minimum,
  75                           final int maximum) {
  76         synchronized (getDelegateLock()) {
  77             currentValue = value;
  78             getDelegate().setValues(value, visible, minimum, maximum);
  79         }
  80     }
  81 
  82     @Override
  83     public void setLineIncrement(final int l) {
  84         synchronized (getDelegateLock()) {
  85             getDelegate().setUnitIncrement(l);
  86         }
  87     }
  88 
  89     @Override
  90     public void setPageIncrement(final int l) {
  91         synchronized (getDelegateLock()) {
  92             getDelegate().setBlockIncrement(l);
  93         }
  94     }
  95 
  96     @Override
  97     public Dimension getPreferredSize() {
  98         synchronized (getDelegateLock()) {
  99             return getDelegate().getPreferredSize();
 100         }
 101     }
 102 
 103     // Peer also registered as a listener for ComponentDelegate component
 104     @Override
 105     public void adjustmentValueChanged(final AdjustmentEvent e) {
 106         final int value = e.getValue();
 107         synchronized (getDelegateLock()) {
 108             if (currentValue == value) {
 109                 return;
 110             }
 111             currentValue = value;
 112         }
 113         getTarget().setValueIsAdjusting(e.getValueIsAdjusting());
 114         getTarget().setValue(value);
 115         postEvent(new AdjustmentEvent(getTarget(), e.getID(),
 116                 e.getAdjustmentType(), value,
 117                 e.getValueIsAdjusting()));
 118     }
 119 }


  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
  23  * questions.
  24  */
  25 
  26 
  27 package sun.lwawt;
  28 
  29 import java.awt.Adjustable;

  30 import java.awt.Scrollbar;
  31 import java.awt.event.AdjustmentEvent;
  32 import java.awt.event.AdjustmentListener;
  33 import java.awt.peer.ScrollbarPeer;
  34 
  35 import javax.swing.JScrollBar;
  36 
  37 final class LWScrollBarPeer extends LWComponentPeer<Scrollbar, JScrollBar>
  38         implements ScrollbarPeer, AdjustmentListener {
  39 
  40     //JScrollBar fires two changes with firePropertyChange (one for old value
  41     // and one for new one.
  42     // We save the last value and don't fire event if not changed.
  43     private int currentValue;
  44 
  45     LWScrollBarPeer(final Scrollbar target,
  46                     final PlatformComponent platformComponent) {
  47         super(target, platformComponent);
  48     }
  49 


  72     @Override
  73     public void setValues(final int value, final int visible, final int minimum,
  74                           final int maximum) {
  75         synchronized (getDelegateLock()) {
  76             currentValue = value;
  77             getDelegate().setValues(value, visible, minimum, maximum);
  78         }
  79     }
  80 
  81     @Override
  82     public void setLineIncrement(final int l) {
  83         synchronized (getDelegateLock()) {
  84             getDelegate().setUnitIncrement(l);
  85         }
  86     }
  87 
  88     @Override
  89     public void setPageIncrement(final int l) {
  90         synchronized (getDelegateLock()) {
  91             getDelegate().setBlockIncrement(l);







  92         }
  93     }
  94 
  95     // Peer also registered as a listener for ComponentDelegate component
  96     @Override
  97     public void adjustmentValueChanged(final AdjustmentEvent e) {
  98         final int value = e.getValue();
  99         synchronized (getDelegateLock()) {
 100             if (currentValue == value) {
 101                 return;
 102             }
 103             currentValue = value;
 104         }
 105         getTarget().setValueIsAdjusting(e.getValueIsAdjusting());
 106         getTarget().setValue(value);
 107         postEvent(new AdjustmentEvent(getTarget(), e.getID(),
 108                 e.getAdjustmentType(), value,
 109                 e.getValueIsAdjusting()));
 110     }
 111 }