home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 13.8 KB | 449 lines |
- package symantec.itools.awt;
-
- import java.awt.Dimension;
- import java.awt.Point;
- import java.awt.Component;
- import java.awt.Adjustable;
-
- // 02/15/97 RKM Changed add to call setComponent
- // Changed setComponent to add the component before the VBar, HBar, & cornerRect
- // Removed bOsFlag and added isSolaris to OS
- // Added handling of correct scrollbar width for the Mac
- // 05/08/97 CAR Changed handleEvent to check that event target is either the HBar OR the VBar
- // before executing a scroll. This fixed the bug where a scroll event that was
- // not targeted at the VBar would cause the VBar logic to execute.
- // 05/11/97 CAR Changed setComponent to not call super.removeAll and addInternalComponents.
- // Replaced all calls to repaint with calls to placeComponents (except in reshape).
- // Changed visibility of placeComponents from default to private.
- // 05/16/97 CAR Changed scrollVerticalAbsolute and scrollHorizontalAbsolute to account for
- // the visible page size
- // 05/19/97 CAR Changed reshape to call placeComponents
- // 05/20/97 CAR Added vendor/version check to placeComponents, scrollDown/Right/PageDown/PageRight
- // 07/15/97 RKM Changed call to super.setLayout so it would bypass our override
- // 07/19/97 RKM Hide components immediately after creation, instead of waiting to post add (eliminate flicker)
- // Removed hard coded scrollbar size (called getPreferredSize())
- // Removed add overrides and added addImpl (this is the 1.1 way of doing this)
- // Changed removeAll to not call super, but remove the one component that could be there
- // 07/25/97 RKM Added getScrollPosition a la ScrollPane
- // 07/29/97 RKM Made bSun1_1 static
- // 07/30/97 CAR marked fields transient as needed
- // 08/21/97 CAR Ripped out guts of ScrollingPanel, now extend directly from java.awt.ScrollPane
- // 08/30/97 LAB Deprecated class (Addresses Mac Bug #7651). Updated version to 1.1.
- // 09/04/97 LAB Backed out deprecation. Interactions are more useful than baseclass.
-
- /**
- * Similar to java.awt.ScrollPane, but with better Interaction Wizard support.
- * <p>
- * The ScrollingPanel is a panel with automatic scroll bars.
- * It may contain only one component/container/panel/etc.
- * It automatically tracks the size of this (usually large) component and
- * provides scroll bars so the entire component may be viewed within a
- * panel of limited size.
- * Typically, the added component would be a panel (or some other container)
- * which would then contain a variety of other components.
- *
- * @see java.awt.ScrollPane
- * @version 1.1, August 30, 1997
- * @author Symantec
- */
- public class ScrollingPanel extends java.awt.ScrollPane
- {
- /**
- * Constructs a default ScrollingPanel.
- * The panel is initialized with a null component, zero
- * minimum height and zero minimum width.
- */
- public ScrollingPanel()
- {
- super();
- }
-
- /**
- * Constructs a new ScrollingPanel initialized with the
- * specified scrollbarDisplayPolicy.
- * @param scrollbarDisplayPolicy policy for when scrollbars should be shown
- */
- public ScrollingPanel(int scrollbarDisplayPolicy)
- {
- super(scrollbarDisplayPolicy);
- }
-
- /**
- * Constructs a new ScrollingPanel initialized with the
- * specified component, minimum height and minimum width.
- * @param component the component (usually a Panel) to be
- * scrolled
- * @param minWidth the value to be used for the minimumSize()
- * width of the ScrollingPanel
- * @param minHeight the value to be used for the minimumSize()
- * height of the ScrollingPanel
- */
- public ScrollingPanel(Component component, int minWidth, int minHeight)
- {
- super();
- addImpl(component, null, -1);
- setSize(minWidth, minHeight);
- }
-
- /**
- * Sets the value to be used for the minimumSize() width
- * of the ScrollingPanel.
- * @param minWidth the value to be used for the minimumSize()
- * width of the ScrollingPanel
- * @see #getMinimumWidth
- */
- public void setMinimumWidth(int minWidth)
- {
- this.width = minWidth;
- }
-
- /**
- * Gets the current value used for the minimumSize()
- * width of the ScrollingPanel.
- * @return the current minimum width value
- */
- public int getMinimumWidth()
- {
- return this.width;
- }
-
- /**
- * Sets the value to be used for the minimumSize()
- * height of the ScrollingPanel.
- * @param minHeight the value to be used for the minimumSize()
- * height of the ScrollingPanel
- * @see #getMinimumHeight
- */
- public void setMinimumHeight(int minHeight)
- {
- this.height = minHeight;
- }
-
- /**
- * Gets the value used for the minimumSize() height
- * of the ScrollingPanel.
- * @return current minimum height value
- * @see #setMinimumHeight
- */
- public int getMinimumHeight()
- {
- return this.height;
- }
-
- /**
- * @deprecated
- * removed functionality
- */
- public void setVerticalGap(int gapPixels)
- {
- }
-
- /**
- * @deprecated
- * removed functionality
- */
- public int getVerticalGap()
- {
- return 0;
- }
-
- /**
- * @deprecated
- * removed functionality
- */
- public void setHorizontalGap(int gapPixels)
- {
- }
-
- /**
- * @deprecated
- * removed functionality
- */
- public int getHorizontalGap()
- {
- return 0;
- }
-
- /**
- * @deprecated
- * replaced by constructor which takes a scrollbarDisplayPolicy
- */
- public void setShowVerticalScroll(boolean cond)
- {
- }
-
- /**
- * @deprecated
- * replaced by getScrollbarDisplayPolicy
- */
- public boolean getShowVerticalScroll()
- {
- int i = getScrollbarDisplayPolicy();
- if (i == SCROLLBARS_ALWAYS || i == SCROLLBARS_AS_NEEDED)
- return true;
- else
- return false;
- }
-
- /**
- * @deprecated
- * replaced by constructor which takes a scrollbarDisplayPolicy
- */
- public void setShowHorizontalScroll(boolean cond)
- {
- }
-
- /**
- * @deprecated
- * replaced by getScrollbarDisplayPolicy
- */
- public boolean getShowHorizontalScroll()
- {
- int i = getScrollbarDisplayPolicy();
- if (i == SCROLLBARS_ALWAYS || i == SCROLLBARS_AS_NEEDED)
- return true;
- else
- return false;
- }
-
- /**
- * @deprecated
- * replaced by Adjustable.setUnitIncrement
- */
- public void setScrollLineIncrement(int scrollLineIncrement)
- {
- getHAdjustable().setUnitIncrement(scrollLineIncrement);
- getVAdjustable().setUnitIncrement(scrollLineIncrement);
- }
-
- /**
- * @deprecated
- * replaced by Adjustable.getUnitIncrement
- */
- public int getScrollLineIncrement()
- {
- return Math.max(getHAdjustable().getUnitIncrement(),
- getVAdjustable().getUnitIncrement());
- }
-
- /**
- * Sets the component in this ScrollingPanel. This is the component
- * that gets scrolled. The ScrollingPanel can only contain one component.
- * Any previous component will be removed before the new one is added.
- * @param comp the component to add
- * @see #getComponent
- */
- public void setComponent(Component comp)
- {
- addImpl(comp, null, -1);
- }
-
- /**
- * Gets the current component in the ScrollingPanel.
- * This is the component that gets scrolled.
- * @return the current component in the ScrollingPanel
- * @see #setComponent
- */
- public Component getComponent()
- {
- if (getComponentCount() > 0) {
- return getComponent(0);
- }
- else
- return null;
- }
-
- /**
- * Scrolls up by the number of pixels specified in the method setScrollLineIncrement().
- * The default is one pixel.
- * @see #scrollDown
- * @see #scrollLeft
- * @see #scrollRight
- * @see #setScrollLineIncrement
- * @see #getScrollLineIncrement
- */
- public void scrollUp()
- {
- Point p = getScrollPosition();
- setScrollPosition(new Point(p.x, p.y - getVAdjustable().getUnitIncrement()));
- }
-
- /**
- * Scrolls left by the number of pixels specified in the method setScrollLineIncrement().
- * The default is one pixel.
- * @see #scrollRight
- * @see #scrollUp
- * @see #scrollDown
- * @see #setScrollLineIncrement
- * @see #getScrollLineIncrement
- */
- public void scrollLeft()
- {
- Point p = getScrollPosition();
- setScrollPosition(new Point(p.x - getHAdjustable().getUnitIncrement(), p.y));
- }
-
- /**
- * Scrolls down by the number of pixels specified in the method setScrollLineIncrement().
- * The default is one pixel.
- * @see #scrollUp
- * @see #scrollLeft
- * @see #scrollRight
- * @see #setScrollLineIncrement
- * @see #getScrollLineIncrement
- */
- public void scrollDown()
- {
- Point p = getScrollPosition();
- setScrollPosition(new Point(p.x, p.y + getVAdjustable().getUnitIncrement()));
- }
-
- /**
- * Scrolls right by the number of pixels specified in the method setScrollLineIncrement().
- * The default is one pixel.
- * @see #scrollLeft
- * @see #scrollUp
- * @see #scrollDown
- * @see #setScrollLineIncrement
- * @see #getScrollLineIncrement
- */
- public void scrollRight()
- {
- Point p = getScrollPosition();
- setScrollPosition(new Point(p.x + getHAdjustable().getUnitIncrement(), p.y));
- }
-
- /**
- * Scrolls one "page" up.
- * The page size is the size of this ScrollingPanel not including the
- * scroll bar, if present.
- * @see #scrollPageDown
- * @see #scrollPageLeft
- * @see #scrollPageRight
- */
- public void scrollPageUp()
- {
- Point p = getScrollPosition();
- setScrollPosition(new Point(p.x, p.y - getVAdjustable().getBlockIncrement()));
- }
-
- /**
- * Scrolls one "page" left.
- * The page size is the size of this ScrollingPanel not including the
- * scroll bar, if present.
- * @see #scrollPageRight
- * @see #scrollPageUp
- * @see #scrollPageDown
- */
- public void scrollPageLeft()
- {
- Point p = getScrollPosition();
- setScrollPosition(new Point(p.x - getHAdjustable().getBlockIncrement(), p.y));
- }
-
- /**
- * Scrolls one "page" down.
- * The page size is the size of this ScrollingPanel not including the
- * scroll bar, if present.
- * @see #scrollPageUp
- * @see #scrollPageLeft
- * @see #scrollPageRight
- */
- public void scrollPageDown()
- {
- Point p = getScrollPosition();
- setScrollPosition(new Point(p.x, p.y + getVAdjustable().getBlockIncrement()));
- }
-
- /**
- * Scrolls one "page" right.
- * The page size is the size of this ScrollingPanel not including the
- * scroll bar, if present.
- * @see #scrollPageLeft
- * @see #scrollPageUp
- * @see #scrollPageDown
- */
- public void scrollPageRight()
- {
- Point p = getScrollPosition();
- setScrollPosition(new Point(p.x + getHAdjustable().getBlockIncrement(), p.y));
- }
-
- /**
- * Scrolls to an absolute vertical position.
- * The contained component's given pixel position will be scrolled to the
- * top line of the scrolling panel. The provided position is constrained to the range
- * [0, component's height - view port height].
- * @param position the pixel position to scroll to
- * @see #scrollHorizontalAbsolute
- */
- public void scrollVerticalAbsolute(int position)
- {
- Point p = getScrollPosition();
- setScrollPosition(new Point(p.x, position));
- }
-
- /**
- * Scrolls to an absolute horizontal position.
- * The contained component's given pixel position will be scrolled to the
- * leftmost part of the scrolling panel. The provided position is constrained to the range
- * [0, component's width - view port width].
- * @param position the pixel position to scroll to
- * @see #scrollVerticalAbsolute
- */
- public void scrollHorizontalAbsolute(int position)
- {
- Point p = getScrollPosition();
- setScrollPosition(new Point(position, p.y));
- }
-
- /**
- * Returns the recommended dimensions to properly display this component.
- * This is a standard Java AWT method which gets called to determine
- * the recommended size of this component.
- *
- * For each axis, it returns the larger of the current size or the
- * minimum size.
- *
- * @see #minimumSize
- */
- public Dimension preferredSize()
- {
- Dimension s = size();
- Dimension m = minimumSize();
- return new Dimension(Math.max(s.width, m.width), Math.max(s.height, m.height));
- }
-
- public Dimension getPreferredSize()
- {
- return preferredSize();
- }
-
- /**
- * Returns the minimum dimensions to properly display this component.
- * This is a standard Java AWT method which gets called to determine
- * the minimum size of this component.
- *
- * The value returned is set using the setMinimumHeight() and
- * setMinimumWidth() methods or when this ScrollingPanel is constructed.
- *
- * @see #preferredSize
- * @see #setMinimumHeight
- * @see #setMinimumWidth
- */
- public Dimension minimumSize()
- {
- return new Dimension(width, height);
- }
-
- public Dimension getMinimumSize()
- {
- return minimumSize();
- }
-
- private int width = 100;
- private int height = 100;
-
- }
-
-