jdk/src/solaris/classes/sun/awt/motif/MScrollbarPeer.java
changeset 1192 715cf9378c53
parent 1051 90cf935adb35
parent 1191 f142c1da78c2
child 1193 41afb8ee8f45
equal deleted inserted replaced
1051:90cf935adb35 1192:715cf9378c53
     1 /*
       
     2  * Copyright 1995-2002 Sun Microsystems, Inc.  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.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 package sun.awt.motif;
       
    26 
       
    27 import java.awt.*;
       
    28 import java.awt.peer.*;
       
    29 import java.awt.event.AdjustmentEvent;
       
    30 
       
    31 class MScrollbarPeer extends MComponentPeer implements ScrollbarPeer {
       
    32     static {
       
    33         initIDs();
       
    34     }
       
    35 
       
    36     private boolean inUpCall = false;
       
    37 
       
    38     native void create(MComponentPeer parent);
       
    39 
       
    40     MScrollbarPeer(Scrollbar target) {
       
    41         super(target);
       
    42     }
       
    43 
       
    44     // Initialize JNI field and method IDs
       
    45     private static native void initIDs();
       
    46 
       
    47     public native void pSetValues(int value, int visible, int minimum, int maximum);
       
    48     public native void setLineIncrement(int l);
       
    49     public native void setPageIncrement(int l);
       
    50 
       
    51     /**
       
    52      * Returns default size of Motif scrollbar on the platform
       
    53      * Currently uses hardcoded values
       
    54      */
       
    55     int getDefaultDimension() {
       
    56         if (System.getProperty("os.name").equals("Linux")) {
       
    57             return 15;
       
    58         } else {
       
    59             return 19;
       
    60         }
       
    61     }
       
    62 
       
    63     public Dimension getMinimumSize() {
       
    64         if (((Scrollbar)target).getOrientation() == Scrollbar.VERTICAL) {
       
    65             return new Dimension(getDefaultDimension(), 50);
       
    66         } else {
       
    67             return new Dimension(50, getDefaultDimension());
       
    68         }
       
    69     }
       
    70 
       
    71     // NOTE: Callback methods are called by privileged threads.
       
    72     //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
       
    73 
       
    74     private void postAdjustmentEvent(final int type, final int value,
       
    75                                      final boolean isAdjusting)
       
    76     {
       
    77         final Scrollbar sb = (Scrollbar)target;
       
    78         MToolkit.executeOnEventHandlerThread(sb, new Runnable() {
       
    79             public void run() {
       
    80                 inUpCall = true;
       
    81                 sb.setValueIsAdjusting(isAdjusting);
       
    82                 sb.setValue(value);
       
    83                 postEvent(new AdjustmentEvent(sb,
       
    84                                 AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED,
       
    85                                 type, value, isAdjusting));
       
    86                 inUpCall = false;
       
    87             }
       
    88         });
       
    89     }
       
    90 
       
    91     void lineUp(int value) {
       
    92         postAdjustmentEvent(AdjustmentEvent.UNIT_DECREMENT, value, false);
       
    93     }
       
    94 
       
    95     void lineDown(int value) {
       
    96         postAdjustmentEvent(AdjustmentEvent.UNIT_INCREMENT, value, false);
       
    97     }
       
    98 
       
    99     void pageUp(int value) {
       
   100         postAdjustmentEvent(AdjustmentEvent.BLOCK_DECREMENT, value, false);
       
   101     }
       
   102 
       
   103     void pageDown(int value) {
       
   104         postAdjustmentEvent(AdjustmentEvent.BLOCK_INCREMENT, value, false);
       
   105     }
       
   106 
       
   107     // SB_TOP/BOTTOM are mapped to tracking
       
   108     void warp(int value) {
       
   109         postAdjustmentEvent(AdjustmentEvent.TRACK, value, false);
       
   110     }
       
   111 
       
   112     private boolean dragInProgress = false;
       
   113 
       
   114     void drag(final int value) {
       
   115         if (!dragInProgress) {
       
   116             dragInProgress = true;
       
   117         }
       
   118         postAdjustmentEvent(AdjustmentEvent.TRACK, value, true);
       
   119     }
       
   120 
       
   121     void dragEnd(final int value) {
       
   122         final Scrollbar sb = (Scrollbar)target;
       
   123 
       
   124         if (!dragInProgress) {
       
   125             return;
       
   126         }
       
   127 
       
   128         dragInProgress = false;
       
   129         MToolkit.executeOnEventHandlerThread(sb, new Runnable() {
       
   130             public void run() {
       
   131                 // NB: notification only, no sb.setValue()
       
   132                 // last TRACK event will have done it already
       
   133                 inUpCall = true;
       
   134                 sb.setValueIsAdjusting(false);
       
   135                 postEvent(new AdjustmentEvent(sb,
       
   136                                 AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED,
       
   137                                 AdjustmentEvent.TRACK, value, false));
       
   138                 inUpCall = false;
       
   139             }
       
   140         });
       
   141     }
       
   142 
       
   143     /**
       
   144      * Set the value of the slider in the ScrollBar.
       
   145      */
       
   146     public void setValues(int value, int visible, int minimum, int maximum) {
       
   147         // Fix for BugTraq ID 4048060.  Prevent unnecessary redrawing
       
   148         // of the slider, when the slider is already in the correct
       
   149         // position.  Since the ScrollBar widget now receives the
       
   150         // ButtonRelease X event before the Java Adjustor event is
       
   151         // handled, the slider is already in the correct position and
       
   152         // does not need to be set again and redrawn, when processing
       
   153         // the Adjustor event.
       
   154         if (!inUpCall) {
       
   155             pSetValues(value, visible, minimum, maximum);
       
   156         }
       
   157     }
       
   158 
       
   159     public void print(Graphics g) {
       
   160         Scrollbar sb = (Scrollbar)target;
       
   161         Dimension d = sb.size();
       
   162         Color bg = sb.getBackground();
       
   163 
       
   164         boolean horiz = (sb.getOrientation() == Scrollbar.HORIZONTAL);
       
   165 
       
   166         drawScrollbar(g, bg, horiz? d.height : d.width,
       
   167                           horiz? d.width : d.height,
       
   168                           sb.getMinimum(), sb.getMaximum(),
       
   169                           sb.getValue(), sb.getVisible(),
       
   170                           horiz);
       
   171 
       
   172         target.print(g);
       
   173     }
       
   174 
       
   175 
       
   176     /**
       
   177      * DEPRECATED
       
   178      */
       
   179     public Dimension minimumSize() {
       
   180             return getMinimumSize();
       
   181     }
       
   182 
       
   183     protected boolean shouldFocusOnClick() {
       
   184         // Changed in 1.4 - scroll bars are made focusable by mouse clicks.
       
   185         return true;
       
   186     }
       
   187 }