0N/A/*
2362N/A * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.awt.X11;
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport java.awt.peer.*;
0N/Aimport java.lang.reflect.*;
5255N/Aimport sun.awt.AWTAccessor;
0N/A
0N/Aclass XScrollPanePeer extends XComponentPeer implements ScrollPanePeer, XScrollbarClient {
0N/A
0N/A public final static int MARGIN = 1;
0N/A public final static int SCROLLBAR;
0N/A public final static int SPACE = 2;
0N/A public final static int SCROLLBAR_INSET = 2;
0N/A
0N/A public final static int VERTICAL = 1 << 0;
0N/A public final static int HORIZONTAL = 1 << 1;
0N/A
0N/A static {
0N/A SCROLLBAR = XToolkit.getUIDefaults().getInt("ScrollBar.defaultWidth");
0N/A }
0N/A
0N/A XVerticalScrollbar vsb;
0N/A XHorizontalScrollbar hsb;
0N/A XWindow clip;
0N/A
0N/A int active=VERTICAL;
0N/A int hsbSpace;
0N/A int vsbSpace;
0N/A
0N/A static class XScrollPaneContentWindow extends XWindow {
0N/A XScrollPaneContentWindow(ScrollPane target, long parentWindow) {
0N/A super(target, parentWindow);
0N/A }
0N/A public String getWMName() {
0N/A return "ScrollPane content";
0N/A }
0N/A }
0N/A
0N/A XScrollPanePeer(ScrollPane target) {
0N/A super(target);
0N/A
0N/A // Create the clip window. The field "clip" must be null when
0N/A // we call winCreate, or the parent of clip will be set to itself!
0N/A clip = null;
0N/A
0N/A
0N/A XWindow c = new XScrollPaneContentWindow(target,window);
0N/A clip = c;
0N/A
0N/A vsb = new XVerticalScrollbar(this);
0N/A
0N/A hsb = new XHorizontalScrollbar(this);
0N/A
0N/A if (target.getScrollbarDisplayPolicy() == ScrollPane.SCROLLBARS_ALWAYS) {
0N/A vsbSpace = hsbSpace = SCROLLBAR;
0N/A } else {
0N/A vsbSpace = hsbSpace = 0;
0N/A }
0N/A
0N/A int unitIncrement = 1;
0N/A Adjustable vAdjustable = target.getVAdjustable();
0N/A if (vAdjustable != null){
0N/A unitIncrement = vAdjustable.getUnitIncrement();
0N/A }
0N/A int h = height-hsbSpace;
0N/A vsb.setValues(0, h, 0, h, unitIncrement, Math.max(1, (int)(h * 0.90)));
0N/A vsb.setSize(vsbSpace-SCROLLBAR_INSET, h);
0N/A
0N/A unitIncrement = 1;
0N/A Adjustable hAdjustable = target.getHAdjustable();
0N/A if (hAdjustable != null){
0N/A unitIncrement = hAdjustable.getUnitIncrement();
0N/A }
0N/A int w = width - vsbSpace;
0N/A hsb.setValues(0, w, 0, w, unitIncrement, Math.max(1, (int)(w * 0.90)));
0N/A hsb.setSize(w, hsbSpace-SCROLLBAR_INSET);
0N/A
0N/A setViewportSize();
0N/A clip.xSetVisible(true);
0N/A
0N/A
0N/A }
0N/A
0N/A public long getContentWindow()
0N/A {
0N/A return (clip == null) ? window : clip.getWindow();
0N/A }
0N/A
0N/A public void setBounds(int x, int y, int w, int h, int op) {
0N/A super.setBounds(x, y, w, h, op);
0N/A
0N/A if (clip == null) return;
0N/A setScrollbarSpace();
0N/A setViewportSize();
0N/A repaint();
0N/A }
0N/A
0N/A public Insets getInsets() {
0N/A return new Insets(MARGIN, MARGIN, MARGIN+hsbSpace, MARGIN+vsbSpace);
0N/A }
0N/A
0N/A public int getHScrollbarHeight() {
0N/A return SCROLLBAR;
0N/A }
0N/A
0N/A public int getVScrollbarWidth() {
0N/A return SCROLLBAR;
0N/A }
0N/A
0N/A public void childResized(int w, int h) {
0N/A if (setScrollbarSpace()) {
0N/A setViewportSize();
0N/A }
0N/A repaint();
0N/A }
0N/A
0N/A Dimension getChildSize() {
0N/A ScrollPane sp = (ScrollPane)target;
0N/A if (sp.countComponents() > 0) {
0N/A Component c = sp.getComponent(0);
0N/A return c.size();
0N/A } else {
0N/A return new Dimension(0, 0);
0N/A }
0N/A }
0N/A
0N/A boolean setScrollbarSpace() {
0N/A ScrollPane sp = (ScrollPane)target;
0N/A boolean changed = false;
0N/A int sbDisplayPolicy = sp.getScrollbarDisplayPolicy();
0N/A
0N/A if (sbDisplayPolicy == ScrollPane.SCROLLBARS_NEVER) {
0N/A return changed;
0N/A }
0N/A Dimension cSize = getChildSize();
0N/A
0N/A if (sbDisplayPolicy == ScrollPane.SCROLLBARS_AS_NEEDED) {
0N/A int oldHsbSpace = hsbSpace;
0N/A int oldVsbSpace = vsbSpace;
0N/A hsbSpace = (cSize.width <= (width - 2*MARGIN) ? 0 : SCROLLBAR);
0N/A vsbSpace = (cSize.height <= (height - 2*MARGIN) ? 0 : SCROLLBAR);
0N/A
0N/A if (hsbSpace == 0 && vsbSpace != 0) {
0N/A hsbSpace = (cSize.width <= (width - SCROLLBAR - 2*MARGIN) ? 0 : SCROLLBAR);
0N/A }
0N/A if (vsbSpace == 0 && hsbSpace != 0) {
0N/A vsbSpace = (cSize.height <= (height - SCROLLBAR - 2*MARGIN) ? 0 : SCROLLBAR);
0N/A }
0N/A if (oldHsbSpace != hsbSpace || oldVsbSpace != vsbSpace) {
0N/A changed = true;
0N/A }
0N/A }
0N/A if (vsbSpace > 0) {
0N/A int vis = height - (2*MARGIN) - hsbSpace;
0N/A int max = Math.max(cSize.height, vis);
0N/A vsb.setValues(vsb.getValue(), vis, 0, max);
0N/A vsb.setBlockIncrement((int)(vsb.getVisibleAmount() * .90));
0N/A vsb.setSize(vsbSpace-SCROLLBAR_INSET, height-hsbSpace);
0N/A // Adjustable vadj = sp.getVAdjustable();
0N/A // vadj.setVisibleAmount(vsb.vis);
0N/A // vadj.setMaximum(vsb.max);
0N/A // vadj.setBlockIncrement(vsb.page);
0N/A }
0N/A if (hsbSpace > 0) {
0N/A int vis = width - (2*MARGIN) - vsbSpace;
0N/A int max = Math.max(cSize.width, vis);
0N/A hsb.setValues(hsb.getValue(), vis, 0, max);
0N/A hsb.setBlockIncrement((int)(hsb.getVisibleAmount() * .90));
0N/A hsb.setSize(width-vsbSpace, hsbSpace-SCROLLBAR_INSET);
0N/A // Adjustable hadj = sp.getHAdjustable();
0N/A // hadj.setVisibleAmount(hsb.vis);
0N/A // hadj.setMaximum(hsb.max);
0N/A // hadj.setBlockIncrement(hsb.page);
0N/A }
0N/A
0N/A // Check to see if we hid either of the scrollbars but left
0N/A // ourselves scrolled off of the top and/or right of the pane.
0N/A // If we did, we need to scroll to the top and/or right of of
0N/A // the pane to make it visible.
0N/A //
0N/A // Reminder: see if there is a better place to put this code.
0N/A boolean must_scroll = false;
0N/A
0N/A // Get the point at which the ScrollPane is currently located
0N/A // if number of components > 0
0N/A Point p = new Point(0, 0);
0N/A
0N/A if (((ScrollPane)target).getComponentCount() > 0){
0N/A
0N/A p = ((ScrollPane)target).getComponent(0).location();
0N/A
0N/A if ((vsbSpace == 0) && (p.y < 0)) {
0N/A p.y = 0;
0N/A must_scroll = true;
0N/A }
0N/A
0N/A if ((hsbSpace == 0) && (p.x < 0)) {
0N/A p.x = 0;
0N/A must_scroll = true;
0N/A }
0N/A }
0N/A
0N/A if (must_scroll)
0N/A scroll(x, y, VERTICAL | HORIZONTAL);
0N/A
0N/A return changed;
0N/A }
0N/A
0N/A void setViewportSize() {
0N/A clip.xSetBounds(MARGIN, MARGIN,
0N/A width - (2*MARGIN) - vsbSpace,
0N/A height - (2*MARGIN) - hsbSpace);
0N/A }
0N/A
0N/A public void setUnitIncrement(Adjustable adj, int u) {
0N/A if (adj.getOrientation() == Adjustable.VERTICAL) {
0N/A vsb.setUnitIncrement(u);
0N/A } else {
0N/A // HORIZONTAL
0N/A hsb.setUnitIncrement(u);
0N/A }
0N/A }
0N/A
0N/A public void setValue(Adjustable adj, int v) {
0N/A if (adj.getOrientation() == Adjustable.VERTICAL) {
0N/A scroll(-1, v, VERTICAL);
0N/A } else {
0N/A // HORIZONTAL
0N/A scroll(v, -1, HORIZONTAL);
0N/A }
0N/A }
0N/A
0N/A public void setScrollPosition(int x, int y) {
0N/A scroll(x, y, VERTICAL | HORIZONTAL);
0N/A }
0N/A
0N/A void scroll(int x, int y, int flag) {
0N/A scroll(x, y, flag, AdjustmentEvent.TRACK);
0N/A }
0N/A
0N/A /**
0N/A * Scroll the contents to position x, y
0N/A */
0N/A void scroll(int x, int y, int flag, int type) {
0N/A checkSecurity();
0N/A ScrollPane sp = (ScrollPane)target;
0N/A Component c = getScrollChild();
0N/A if (c == null) {
0N/A return;
0N/A }
0N/A int sx, sy;
0N/A Color colors[] = getGUIcolors();
0N/A
0N/A if (sp.getScrollbarDisplayPolicy() == ScrollPane.SCROLLBARS_NEVER) {
0N/A sx = -x;
0N/A sy = -y;
0N/A } else {
0N/A Point p = c.location();
0N/A sx = p.x;
0N/A sy = p.y;
0N/A
0N/A if ((flag & HORIZONTAL) != 0) {
0N/A hsb.setValue(Math.min(x, hsb.getMaximum()-hsb.getVisibleAmount()));
0N/A ScrollPaneAdjustable hadj = (ScrollPaneAdjustable)sp.getHAdjustable();
0N/A setAdjustableValue(hadj, hsb.getValue(), type);
0N/A sx = -(hsb.getValue());
0N/A Graphics g = getGraphics();
0N/A try {
0N/A paintHorScrollbar(g, colors, true);
0N/A } finally {
0N/A g.dispose();
0N/A }
0N/A }
0N/A if ((flag & VERTICAL) != 0) {
0N/A vsb.setValue(Math.min(y, vsb.getMaximum() - vsb.getVisibleAmount()));
0N/A ScrollPaneAdjustable vadj = (ScrollPaneAdjustable)sp.getVAdjustable();
0N/A setAdjustableValue(vadj, vsb.getValue(), type);
0N/A sy = -(vsb.getValue());
0N/A Graphics g = getGraphics();
0N/A try {
0N/A paintVerScrollbar(g, colors, true);
0N/A } finally {
0N/A g.dispose();
0N/A }
0N/A }
0N/A }
0N/A c.move(sx, sy);
0N/A }
0N/A
0N/A void setAdjustableValue(ScrollPaneAdjustable adj, int value, int type) {
5255N/A AWTAccessor.getScrollPaneAdjustableAccessor().setTypedValue(adj, value, type);
0N/A }
0N/A
0N/A public void paint(Graphics g) {
0N/A paintComponent(g);
0N/A }
0N/A
0N/A
0N/A void paintScrollBars(Graphics g, Color[] colors) {
0N/A if (vsbSpace > 0) {
0N/A paintVerScrollbar(g, colors, true);
0N/A // paint the whole scrollbar
0N/A }
0N/A
0N/A if (hsbSpace > 0) {
0N/A paintHorScrollbar(g, colors, true);
0N/A // paint the whole scrollbar
0N/A }
0N/A }
0N/A
0N/A void repaintScrollBars() {
0N/A Graphics g = getGraphics();
0N/A Color colors[] = getGUIcolors();
0N/A if (g != null) {
0N/A paintScrollBars(g,colors);
0N/A }
0N/A g.dispose();
0N/A }
0N/A
0N/A public void repaintScrollbarRequest(XScrollbar sb) {
0N/A Graphics g = getGraphics();
0N/A Color colors[] = getGUIcolors();
0N/A if (g != null) {
0N/A if (sb == vsb) {
0N/A paintVerScrollbar(g,colors,true);
0N/A }
0N/A else if (sb == hsb) {
0N/A paintHorScrollbar(g,colors,true);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Paint the scrollpane.
0N/A */
0N/A public void paintComponent(Graphics g) {
0N/A
0N/A Color colors[] = getGUIcolors();
0N/A g.setColor(colors[BACKGROUND_COLOR]);
0N/A int h = height - hsbSpace;
0N/A int w = width - vsbSpace;
0N/A
0N/A g.fillRect(0, 0, w, h);
0N/A
0N/A // paint rectangular region between scrollbars
0N/A g.fillRect(w, h, vsbSpace, hsbSpace);
0N/A
0N/A if (MARGIN > 0) {
0N/A draw3DRect(g, colors, 0, 0, w - 1, h - 1, false);
0N/A }
0N/A
0N/A paintScrollBars(g,colors);
0N/A }
0N/A
0N/A public void handleEvent(java.awt.AWTEvent e) {
0N/A super.handleEvent(e);
0N/A
0N/A int id = e.getID();
0N/A switch(id) {
0N/A case PaintEvent.PAINT:
0N/A case PaintEvent.UPDATE:
0N/A repaintScrollBars();
0N/A break;
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Paint the horizontal scrollbar to the screen
0N/A *
0N/A * @param g the graphics context to draw into
0N/A * @param colors the colors used to draw the scrollbar
0N/A * @param paintAll paint the whole scrollbar if true, just the thumb if false
0N/A */
0N/A void paintHorScrollbar(Graphics g, Color colors[], boolean paintAll) {
0N/A if (hsbSpace <= 0) {
0N/A return;
0N/A }
0N/A Graphics ng = g.create();
0N/A g.setColor(colors[BACKGROUND_COLOR]);
0N/A
0N/A // SCROLLBAR is the height of scrollbar area
0N/A // but the actual scrollbar is SCROLLBAR-SPACE high;
0N/A // the rest must be filled with background color
0N/A int w = width - vsbSpace - (2*MARGIN);
0N/A g.fillRect(MARGIN, height-SCROLLBAR, w, SPACE);
0N/A g.fillRect(0, height-SCROLLBAR, MARGIN, SCROLLBAR);
0N/A g.fillRect(MARGIN + w, height-SCROLLBAR, MARGIN, SCROLLBAR);
0N/A
0N/A try {
0N/A ng.translate(MARGIN, height - (SCROLLBAR - SPACE));
0N/A hsb.paint(ng, colors, paintAll);
0N/A }
0N/A finally {
0N/A ng.dispose();
0N/A }
0N/A
0N/A
0N/A }
0N/A
0N/A
0N/A
0N/A
0N/A /**
0N/A * Paint the vertical scrollbar to the screen
0N/A *
0N/A * @param g the graphics context to draw into
0N/A * @param colors the colors used to draw the scrollbar
0N/A * @param paintAll paint the whole scrollbar if true, just the thumb if false
0N/A */
0N/A void paintVerScrollbar(Graphics g, Color colors[], boolean paintAll) {
0N/A if (vsbSpace <= 0) {
0N/A return;
0N/A }
0N/A Graphics ng = g.create();
0N/A g.setColor(colors[BACKGROUND_COLOR]);
0N/A
0N/A // SCROLLBAR is the width of scrollbar area
0N/A // but the actual scrollbar is SCROLLBAR-SPACE wide;
0N/A // the rest must be filled with background color
0N/A int h = height - hsbSpace - (2*MARGIN);
0N/A g.fillRect(width-SCROLLBAR, MARGIN, SPACE, h);
0N/A g.fillRect(width-SCROLLBAR, 0, SCROLLBAR, MARGIN);
0N/A g.fillRect(width-SCROLLBAR, MARGIN+h, SCROLLBAR, MARGIN);
0N/A
0N/A try {
0N/A ng.translate(width - (SCROLLBAR - SPACE), MARGIN);
0N/A vsb.paint(ng, colors, paintAll);
0N/A }
0N/A finally {
0N/A ng.dispose();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A *
0N/A * @see java.awt.event.MouseEvent
0N/A * MouseEvent.MOUSE_CLICKED
0N/A * MouseEvent.MOUSE_PRESSED
0N/A * MouseEvent.MOUSE_RELEASED
0N/A * MouseEvent.MOUSE_MOVED
0N/A * MouseEvent.MOUSE_ENTERED
0N/A * MouseEvent.MOUSE_EXITED
0N/A * MouseEvent.MOUSE_DRAGGED
0N/A */
0N/A public void handleJavaMouseEvent( MouseEvent mouseEvent ) {
0N/A super.handleJavaMouseEvent(mouseEvent);
0N/A int modifiers = mouseEvent.getModifiers();
0N/A int id = mouseEvent.getID();
0N/A int x = mouseEvent.getX();
0N/A int y = mouseEvent.getY();
0N/A
0N/A
0N/A // super.handleMouseEvent(mouseEvent);
0N/A
0N/A if ((modifiers & InputEvent.BUTTON1_MASK) == 0) {
0N/A return;
0N/A }
0N/A
0N/A switch (id) {
0N/A case MouseEvent.MOUSE_PRESSED:
0N/A if (inVerticalScrollbar(x,y )) {
0N/A active = VERTICAL;
0N/A int h = height - hsbSpace - (2*MARGIN);
0N/A vsb.handleMouseEvent(id,modifiers,x - (width - SCROLLBAR + SPACE),y-MARGIN);
0N/A } else if (inHorizontalScrollbar(x, y) ) {
0N/A active = HORIZONTAL;
0N/A int w = width - 2*MARGIN - vsbSpace;
0N/A hsb.handleMouseEvent(id,modifiers,x-MARGIN,y-(height - SCROLLBAR + SPACE));
0N/A }
0N/A break;
0N/A
0N/A // On mouse up, pass the event through to the scrollbar to stop
0N/A // scrolling. The x & y passed do not matter.
0N/A case MouseEvent.MOUSE_RELEASED:
0N/A // winReleaseCursorFocus();
0N/A if (active == VERTICAL) {
0N/A vsb.handleMouseEvent(id,modifiers,x,y);
0N/A } else if (active == HORIZONTAL) {
0N/A hsb.handleMouseEvent(id,modifiers,x,y);
0N/A }
0N/A break;
0N/A
0N/A
0N/A case MouseEvent.MOUSE_DRAGGED:
0N/A if ((active == VERTICAL)) {
0N/A int h = height - 2*MARGIN - hsbSpace;
0N/A vsb.handleMouseEvent(id,modifiers,x-(width - SCROLLBAR + SPACE),y-MARGIN);
0N/A } else if ((active == HORIZONTAL)) {
0N/A int w = width - 2*MARGIN - vsbSpace;
0N/A hsb.handleMouseEvent(id,modifiers,x-MARGIN,y-(height - SCROLLBAR + SPACE));
0N/A }
0N/A break;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * return value from the scrollbar
0N/A */
0N/A public void notifyValue(XScrollbar obj, int type, int v, boolean isAdjusting) {
0N/A if (obj == vsb) {
0N/A scroll(-1, v, VERTICAL, type);
0N/A } else if ((XHorizontalScrollbar)obj == hsb) {
0N/A scroll(v, -1, HORIZONTAL, type);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * return true if the x and y position is in the verticalscrollbar
0N/A */
0N/A boolean inVerticalScrollbar(int x, int y) {
0N/A if (vsbSpace <= 0) {
0N/A return false;
0N/A }
0N/A int h = height - MARGIN - hsbSpace;
0N/A return (x >= width - (SCROLLBAR - SPACE)) && (x < width) && (y >= MARGIN) && (y < h);
0N/A }
0N/A
0N/A /**
0N/A * return true if the x and y position is in the horizontal scrollbar
0N/A */
0N/A boolean inHorizontalScrollbar(int x, int y) {
0N/A if (hsbSpace <= 0) {
0N/A return false;
0N/A }
0N/A int w = width - MARGIN - vsbSpace;
0N/A return (x >= MARGIN) && (x < w) && (y >= height - (SCROLLBAR - SPACE)) && (y < height);
0N/A }
0N/A
0N/A private Component getScrollChild() {
0N/A ScrollPane sp = (ScrollPane)target;
0N/A Component child = null;
0N/A try {
0N/A child = sp.getComponent(0);
0N/A } catch (ArrayIndexOutOfBoundsException e) {
0N/A // do nothing. in this case we return null
0N/A }
0N/A return child;
0N/A }
0N/A
0N/A int vval;
0N/A int hval;
0N/A int vmax;
0N/A int hmax;
0N/A /*
0N/A * Print the native component by rendering the Motif look ourselves.
0N/A * ToDo(aim): needs to query native motif for more accurate size and
0N/A * color information.
0N/A */
0N/A public void print(Graphics g) {
0N/A ScrollPane sp = (ScrollPane)target;
0N/A Dimension d = sp.size();
0N/A Color bg = sp.getBackground();
0N/A Color fg = sp.getForeground();
0N/A Point p = sp.getScrollPosition();
0N/A Component c = getScrollChild();
0N/A Dimension cd;
0N/A if (c != null) {
0N/A cd = c.size();
0N/A } else {
0N/A cd = new Dimension(0, 0);
0N/A }
0N/A int sbDisplay = sp.getScrollbarDisplayPolicy();
0N/A int vvis, hvis, vmin, hmin, vmax, hmax, vval, hval;
0N/A
0N/A switch (sbDisplay) {
0N/A case ScrollPane.SCROLLBARS_NEVER:
0N/A hsbSpace = vsbSpace = 0;
0N/A break;
0N/A case ScrollPane.SCROLLBARS_ALWAYS:
0N/A hsbSpace = vsbSpace = SCROLLBAR;
0N/A break;
0N/A case ScrollPane.SCROLLBARS_AS_NEEDED:
0N/A hsbSpace = (cd.width <= (d.width - 2*MARGIN)? 0 : SCROLLBAR);
0N/A vsbSpace = (cd.height <= (d.height - 2*MARGIN)? 0 : SCROLLBAR);
0N/A
0N/A if (hsbSpace == 0 && vsbSpace != 0) {
0N/A hsbSpace = (cd.width <= (d.width - SCROLLBAR - 2*MARGIN)? 0 : SCROLLBAR);
0N/A }
0N/A if (vsbSpace == 0 && hsbSpace != 0) {
0N/A vsbSpace = (cd.height <= (d.height - SCROLLBAR - 2*MARGIN)? 0 : SCROLLBAR);
0N/A }
0N/A }
0N/A
0N/A vvis = hvis = vmin = hmin = vmax = hmax = vval = hval = 0;
0N/A
0N/A if (vsbSpace > 0) {
0N/A vmin = 0;
0N/A vvis = d.height - (2*MARGIN) - hsbSpace;
0N/A vmax = Math.max(cd.height - vvis, 0);
0N/A vval = p.y;
0N/A }
0N/A if (hsbSpace > 0) {
0N/A hmin = 0;
0N/A hvis = d.width - (2*MARGIN) - vsbSpace;
0N/A hmax = Math.max(cd.width - hvis, 0);
0N/A hval = p.x;
0N/A }
0N/A
0N/A // need to be careful to add the margins back in here because
0N/A // we're drawing the margin border, after all!
0N/A int w = d.width - vsbSpace;
0N/A int h = d.height - hsbSpace;
0N/A
0N/A g.setColor(bg);
0N/A g.fillRect(0, 0, d.width, d.height);
0N/A
0N/A if (hsbSpace > 0) {
0N/A int sbw = d.width - vsbSpace;
0N/A g.fillRect(1, d.height - SCROLLBAR - 3, sbw - 1, SCROLLBAR - 3);
0N/A Graphics ng = g.create();
0N/A try {
0N/A ng.translate(0, d.height - (SCROLLBAR - 2));
0N/A drawScrollbar(ng, bg, SCROLLBAR - 2, sbw,
0N/A hmin, hmax, hval, hvis, true);
0N/A } finally {
0N/A ng.dispose();
0N/A }
0N/A }
0N/A if (vsbSpace > 0) {
0N/A int sbh = d.height - hsbSpace;
0N/A g.fillRect(d.width - SCROLLBAR - 3, 1, SCROLLBAR - 3, sbh - 1);
0N/A Graphics ng = g.create();
0N/A try {
0N/A ng.translate(d.width - (SCROLLBAR - 2), 0);
0N/A drawScrollbar(ng, bg, SCROLLBAR - 2, sbh,
0N/A vmin, vmax, vval, vvis, false);
0N/A } finally {
0N/A ng.dispose();
0N/A }
0N/A }
0N/A
0N/A draw3DRect(g, bg, 0, 0, w - 1, h - 1, false);
0N/A
0N/A target.print(g);
0N/A sp.printComponents(g);
0N/A }
0N/A
0N/A}