< prev index next >

src/java.desktop/unix/classes/sun/awt/X11/XScrollPanePeer.java

Print this page


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


 124 
 125     public Insets getInsets() {
 126         return new Insets(MARGIN, MARGIN, MARGIN+hsbSpace, MARGIN+vsbSpace);
 127     }
 128 
 129     public int getHScrollbarHeight() {
 130         return SCROLLBAR;
 131     }
 132 
 133     public int getVScrollbarWidth() {
 134         return SCROLLBAR;
 135     }
 136 
 137     public void childResized(int w, int h) {
 138         if (setScrollbarSpace()) {
 139             setViewportSize();
 140         }
 141         repaint();
 142     }
 143 

 144     Dimension getChildSize() {
 145         ScrollPane sp = (ScrollPane)target;
 146         if (sp.countComponents() > 0) {
 147             Component c = sp.getComponent(0);
 148             return c.size();
 149         } else {
 150             return new Dimension(0, 0);
 151         }
 152     }
 153 

 154     boolean setScrollbarSpace() {
 155         ScrollPane sp = (ScrollPane)target;
 156         boolean changed = false;
 157         int sbDisplayPolicy = sp.getScrollbarDisplayPolicy();
 158 
 159         if (sbDisplayPolicy == ScrollPane.SCROLLBARS_NEVER) {
 160             return changed;
 161         }
 162         Dimension cSize = getChildSize();
 163 
 164         if (sbDisplayPolicy == ScrollPane.SCROLLBARS_AS_NEEDED) {
 165             int oldHsbSpace = hsbSpace;
 166             int oldVsbSpace = vsbSpace;
 167             hsbSpace = (cSize.width <= (width - 2*MARGIN) ? 0 : SCROLLBAR);
 168             vsbSpace = (cSize.height <= (height - 2*MARGIN) ? 0 : SCROLLBAR);
 169 
 170             if (hsbSpace == 0 && vsbSpace != 0) {
 171                 hsbSpace = (cSize.width <= (width - SCROLLBAR - 2*MARGIN) ? 0 : SCROLLBAR);
 172             }
 173             if (vsbSpace == 0 && hsbSpace != 0) {


 251     public void setValue(Adjustable adj, int v) {
 252         if (adj.getOrientation() == Adjustable.VERTICAL) {
 253             scroll(-1, v, VERTICAL);
 254         } else {
 255             // HORIZONTAL
 256             scroll(v, -1, HORIZONTAL);
 257         }
 258     }
 259 
 260     public void setScrollPosition(int x, int y) {
 261         scroll(x, y, VERTICAL | HORIZONTAL);
 262     }
 263 
 264     void scroll(int x, int y, int flag) {
 265         scroll(x, y, flag, AdjustmentEvent.TRACK);
 266     }
 267 
 268     /**
 269      * Scroll the contents to position x, y
 270      */

 271     void scroll(int x, int y, int flag, int type) {
 272         checkSecurity();
 273         ScrollPane sp = (ScrollPane)target;
 274         Component c = getScrollChild();
 275         if (c == null) {
 276             return;
 277         }
 278         int sx, sy;
 279         Color colors[] = getGUIcolors();
 280 
 281         if (sp.getScrollbarDisplayPolicy() == ScrollPane.SCROLLBARS_NEVER) {
 282             sx = -x;
 283             sy = -y;
 284         } else {
 285             Point p = c.location();
 286             sx = p.x;
 287             sy = p.y;
 288 
 289             if ((flag & HORIZONTAL) != 0) {
 290                 hsb.setValue(Math.min(x, hsb.getMaximum()-hsb.getVisibleAmount()));


 552     private Component getScrollChild() {
 553         ScrollPane sp = (ScrollPane)target;
 554         Component child = null;
 555         try {
 556             child = sp.getComponent(0);
 557         } catch (ArrayIndexOutOfBoundsException e) {
 558             // do nothing.  in this case we return null
 559         }
 560         return child;
 561     }
 562 
 563     int vval;
 564     int hval;
 565     int vmax;
 566     int hmax;
 567     /*
 568      * Print the native component by rendering the Motif look ourselves.
 569      * ToDo(aim): needs to query native motif for more accurate size and
 570      * color information.
 571      */

 572     public void print(Graphics g) {
 573         ScrollPane sp = (ScrollPane)target;
 574         Dimension d = sp.size();
 575         Color bg = sp.getBackground();
 576         Color fg = sp.getForeground();
 577         Point p = sp.getScrollPosition();
 578         Component c = getScrollChild();
 579         Dimension cd;
 580         if (c != null) {
 581             cd = c.size();
 582         } else {
 583             cd = new Dimension(0, 0);
 584         }
 585         int sbDisplay = sp.getScrollbarDisplayPolicy();
 586         int vvis, hvis, vmin, hmin, vmax, hmax, vval, hval;
 587 
 588         switch (sbDisplay) {
 589             case ScrollPane.SCROLLBARS_NEVER:
 590                 hsbSpace = vsbSpace = 0;
 591                 break;


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


 124 
 125     public Insets getInsets() {
 126         return new Insets(MARGIN, MARGIN, MARGIN+hsbSpace, MARGIN+vsbSpace);
 127     }
 128 
 129     public int getHScrollbarHeight() {
 130         return SCROLLBAR;
 131     }
 132 
 133     public int getVScrollbarWidth() {
 134         return SCROLLBAR;
 135     }
 136 
 137     public void childResized(int w, int h) {
 138         if (setScrollbarSpace()) {
 139             setViewportSize();
 140         }
 141         repaint();
 142     }
 143 
 144     @SuppressWarnings("deprecation")
 145     Dimension getChildSize() {
 146         ScrollPane sp = (ScrollPane)target;
 147         if (sp.countComponents() > 0) {
 148             Component c = sp.getComponent(0);
 149             return c.size();
 150         } else {
 151             return new Dimension(0, 0);
 152         }
 153     }
 154 
 155     @SuppressWarnings("deprecation")
 156     boolean setScrollbarSpace() {
 157         ScrollPane sp = (ScrollPane)target;
 158         boolean changed = false;
 159         int sbDisplayPolicy = sp.getScrollbarDisplayPolicy();
 160 
 161         if (sbDisplayPolicy == ScrollPane.SCROLLBARS_NEVER) {
 162             return changed;
 163         }
 164         Dimension cSize = getChildSize();
 165 
 166         if (sbDisplayPolicy == ScrollPane.SCROLLBARS_AS_NEEDED) {
 167             int oldHsbSpace = hsbSpace;
 168             int oldVsbSpace = vsbSpace;
 169             hsbSpace = (cSize.width <= (width - 2*MARGIN) ? 0 : SCROLLBAR);
 170             vsbSpace = (cSize.height <= (height - 2*MARGIN) ? 0 : SCROLLBAR);
 171 
 172             if (hsbSpace == 0 && vsbSpace != 0) {
 173                 hsbSpace = (cSize.width <= (width - SCROLLBAR - 2*MARGIN) ? 0 : SCROLLBAR);
 174             }
 175             if (vsbSpace == 0 && hsbSpace != 0) {


 253     public void setValue(Adjustable adj, int v) {
 254         if (adj.getOrientation() == Adjustable.VERTICAL) {
 255             scroll(-1, v, VERTICAL);
 256         } else {
 257             // HORIZONTAL
 258             scroll(v, -1, HORIZONTAL);
 259         }
 260     }
 261 
 262     public void setScrollPosition(int x, int y) {
 263         scroll(x, y, VERTICAL | HORIZONTAL);
 264     }
 265 
 266     void scroll(int x, int y, int flag) {
 267         scroll(x, y, flag, AdjustmentEvent.TRACK);
 268     }
 269 
 270     /**
 271      * Scroll the contents to position x, y
 272      */
 273     @SuppressWarnings("deprecation")
 274     void scroll(int x, int y, int flag, int type) {
 275         checkSecurity();
 276         ScrollPane sp = (ScrollPane)target;
 277         Component c = getScrollChild();
 278         if (c == null) {
 279             return;
 280         }
 281         int sx, sy;
 282         Color colors[] = getGUIcolors();
 283 
 284         if (sp.getScrollbarDisplayPolicy() == ScrollPane.SCROLLBARS_NEVER) {
 285             sx = -x;
 286             sy = -y;
 287         } else {
 288             Point p = c.location();
 289             sx = p.x;
 290             sy = p.y;
 291 
 292             if ((flag & HORIZONTAL) != 0) {
 293                 hsb.setValue(Math.min(x, hsb.getMaximum()-hsb.getVisibleAmount()));


 555     private Component getScrollChild() {
 556         ScrollPane sp = (ScrollPane)target;
 557         Component child = null;
 558         try {
 559             child = sp.getComponent(0);
 560         } catch (ArrayIndexOutOfBoundsException e) {
 561             // do nothing.  in this case we return null
 562         }
 563         return child;
 564     }
 565 
 566     int vval;
 567     int hval;
 568     int vmax;
 569     int hmax;
 570     /*
 571      * Print the native component by rendering the Motif look ourselves.
 572      * ToDo(aim): needs to query native motif for more accurate size and
 573      * color information.
 574      */
 575     @SuppressWarnings("deprecation")
 576     public void print(Graphics g) {
 577         ScrollPane sp = (ScrollPane)target;
 578         Dimension d = sp.size();
 579         Color bg = sp.getBackground();
 580         Color fg = sp.getForeground();
 581         Point p = sp.getScrollPosition();
 582         Component c = getScrollChild();
 583         Dimension cd;
 584         if (c != null) {
 585             cd = c.size();
 586         } else {
 587             cd = new Dimension(0, 0);
 588         }
 589         int sbDisplay = sp.getScrollbarDisplayPolicy();
 590         int vvis, hvis, vmin, hmin, vmax, hmax, vval, hval;
 591 
 592         switch (sbDisplay) {
 593             case ScrollPane.SCROLLBARS_NEVER:
 594                 hsbSpace = vsbSpace = 0;
 595                 break;


< prev index next >