home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / ScrollingPanel.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  26.3 KB  |  968 lines

  1. package symantec.itools.awt;
  2.  
  3.  
  4. import java.awt.Panel;
  5. import java.awt.Component;
  6. import java.awt.Scrollbar;
  7. import java.awt.Dimension;
  8. import java.awt.Color;
  9. import java.awt.Rectangle;
  10. import java.awt.Graphics;
  11. import java.awt.Event;
  12. import java.awt.LayoutManager;
  13. import symantec.itools.awt.shape.Rect;
  14. import symantec.itools.awt.KeyPressManagerPanel;
  15.  
  16. /**
  17.  * Creates a container with scroll bars.
  18.  * <p>
  19.  * The ScrollingPanel can contain one panel that can contain visual components 
  20.  * and other panels. The ScrollingPanel will be displayed with attached scroll bars.
  21.  * <p>
  22.  * Use this component to display a region that allows the user to scroll 
  23.  * through all items in the panel, and specifically to:
  24.  * <UL>
  25.  * <DT>╖ create a subcontainer that organizes container space within an Applet, Frame or Dialog container. This simplifies your component layout task.</DT>
  26.  * <DT>╖ hold other specialized Panel containers.</DT>
  27.  * </UL>
  28.  * @version 1.0, Nov 26, 1996
  29.  * @author Symantec
  30.  */
  31.  
  32.  
  33. //  05/08/97    CAR Changed handleEvent to check that event target is either the HBar OR the VBar
  34. //                  before executing a scroll.  This fixed the bug where a scroll event that was 
  35. //                  not targeted at the VBar would cause the VBar logic to execute.
  36.  
  37. //     02/15/97    RKM    Changed add to call setComponent
  38. //                    Changed setComponent to add the component before the VBar, HBar, & cornerRect
  39. //                    Removed bOsFlag and added isSolaris to OS
  40. //                    Added handling of correct scrollbar width for the Mac
  41.  
  42. public class ScrollingPanel
  43.     extends KeyPressManagerPanel
  44. {
  45.     private Component spComponent;
  46.     private int width;
  47.     private int height;
  48.     private int xCoord, yCoord;
  49.     private Scrollbar VBar = null;
  50.     private Scrollbar HBar= null;
  51.     private boolean bVBarVisible;
  52.     private boolean bHBarVisible;
  53.     private boolean bCornerRectVisible;
  54.     private int vPageSize;
  55.     private int hPageSize;
  56.     private Dimension dimComponent;
  57.     private int vGapWid;
  58.     private int hGapHt;
  59.     private boolean bAllowShowVBar = true;
  60.     private boolean bAllowShowHBar = true;
  61.     private int scrollLineIncrement = 1;
  62.     private Rect cornerRect;
  63.  
  64.     //--------------------------------------------------
  65.     // constructors
  66.     //--------------------------------------------------
  67.  
  68.     /**
  69.      * Constructs a default ScrollingPanel.
  70.      * The panel is initialized with a null component, zero
  71.      * minimum height and zero minimum width.
  72.      */
  73.     public ScrollingPanel()
  74.     {
  75.         this(null, 0, 0);
  76.     }
  77.  
  78.     /**
  79.      * Constructs a new ScrollingPanel initialized with the
  80.      * specified component, minimum height and minimum width.
  81.      * @param component the component (usually a Panel) to be
  82.      * scrolled
  83.      * @param minWidth the value to be used for the minimumSize()
  84.      * width of the ScrollingPanel
  85.      * @param minHeight the value to be used for the minimumSize()
  86.      * height of the ScrollingPanel
  87.      */
  88.     public ScrollingPanel(Component component, int minWidth, int minHeight)
  89.     {
  90.         this.spComponent = component;
  91.         this.width = minWidth;
  92.         this.height = minHeight;
  93.         xCoord = 0;
  94.         yCoord = 0;
  95.         bVBarVisible = false;
  96.         bHBarVisible = false;
  97.         bCornerRectVisible = false;
  98.         vPageSize = 0;
  99.         hPageSize = 0;
  100.         vGapWid = 6;
  101.         hGapHt = 6;
  102.         dimComponent = new Dimension(0,0);
  103.  
  104.         VBar = new Scrollbar();
  105.         VBar.setBackground(Color.lightGray);
  106.  
  107.         HBar = new Scrollbar(Scrollbar.HORIZONTAL);
  108.         HBar.setBackground(Color.lightGray);
  109.  
  110.         cornerRect = new Rect();
  111.         cornerRect.setForeground(Color.lightGray);
  112.         cornerRect.setFillColor(Color.lightGray);
  113.         cornerRect.setFillMode(true);
  114.  
  115.         setLayout(null);
  116.         addInternalComponents();
  117.         
  118.         VBar.hide();
  119.         HBar.hide();
  120.         cornerRect.hide();
  121.  
  122.         if (spComponent != null)
  123.         {
  124.             super.add(spComponent, -1);
  125.             placeComponents();
  126.         }
  127.     }
  128.  
  129.     /**
  130.      * Sets the value to be used for the minimumSize() width
  131.      * of the ScrollingPanel.
  132.      * @param minWidth the value to be used for the minimumSize()
  133.      * width of the ScrollingPanel
  134.      * @see #getMinimumWidth
  135.      */
  136.     public void setMinimumWidth(int minWidth)
  137.     {
  138.         this.width = minWidth;
  139.     }
  140.  
  141.     /**
  142.      * Gets the current value used for the minimumSize()
  143.      * width of the ScrollingPanel.
  144.      * @return the current width value
  145.      */
  146.     public int getMinimumWidth()
  147.     {
  148.         return this.width;
  149.     }
  150.  
  151.     /**
  152.      * Sets the value to be used for the minimumSize()
  153.      * height of the ScrollingPanel.
  154.      * @param minHeight the value to be used for the minimumSize()
  155.      * height of the ScrollingPanel
  156.      * @see #getMinimumHeight
  157.      */
  158.     public void setMinimumHeight(int minHeight)
  159.     {
  160.         this.height = minHeight;
  161.     }
  162.  
  163.     /**
  164.      * Gets the value used for the minimumSize() height
  165.      * of the ScrollingPanel.
  166.      * @return current height value
  167.      * @see #setMinimumHeight
  168.      */
  169.     public int getMinimumHeight()
  170.     {
  171.         return this.height;
  172.     }
  173.  
  174.     /**
  175.      * Sets the vertical gap amount between the container
  176.      * in ScrollingPanel and the vertical scroll bar.
  177.      * @param gapPixels the size of vertical gap in pixels
  178.      * @see #getVerticalGap
  179.      */
  180.     public void setVerticalGap(int gapPixels)
  181.     {
  182.         vGapWid = gapPixels;
  183.         invalidate();
  184.     }
  185.  
  186.     /**
  187.      * Gets the current vertical gap amount between the
  188.      * container in ScrollingPanel and the vertical scroll
  189.      * bar.
  190.      * @return the size of vertical gap in pixels
  191.      * @see #setVerticalGap
  192.      */
  193.     public int getVerticalGap()
  194.     {
  195.         return vGapWid;
  196.     }
  197.  
  198.     /**
  199.      * Sets the horizontal gap amount between the container
  200.      * in ScrollingPanel and the horizontal scroll bar.
  201.      * @param gapPixels the size of horizontal gap in pixels
  202.      * @see #getHorizontalGap
  203.      */
  204.     public void setHorizontalGap(int gapPixels)
  205.     {
  206.         hGapHt = gapPixels;
  207.         invalidate();
  208.     }
  209.  
  210.     /**
  211.      * Gets the current horizontal gap amount between the
  212.      * container in ScrollingPanel and horizontal scroll
  213.      * bar.
  214.      * @return the size of horizontal gap in pixels
  215.      * @see #setHorizontalGap
  216.      */
  217.     public int getHorizontalGap()
  218.     {
  219.         return hGapHt;
  220.     }
  221.  
  222.     /**
  223.      * Sets whether or not the vertical scrollbar should be
  224.      * made visible when necessary or should never be made
  225.      * visible.
  226.      * @param cond if true, show the scrollbar when necessary;
  227.      * if false, never show the scrollbar
  228.      * @see #getShowVerticalScroll
  229.      */
  230.     public void setShowVerticalScroll(boolean cond)
  231.     {
  232.         if (bAllowShowVBar != cond)
  233.         {
  234.             bAllowShowVBar = cond;
  235.             invalidate();
  236.         }
  237.     }
  238.  
  239.     /**
  240.      * Gets the current vertical scrollbar visibility flag.
  241.      * @return the visibility flag. If true, show the scrollbar when
  242.      * necessary; if false, never show the scrollbar
  243.      * @see #setShowVerticalScroll
  244.      */
  245.     public boolean getShowVerticalScroll()
  246.     {
  247.         return bAllowShowVBar;
  248.     }
  249.  
  250.     /**
  251.      * Sets whether or not the horizontal scrollbar should be
  252.      * made visible when necessary or should never be made
  253.      * visible.
  254.      * @param cond if true, show the scrollbar when necessary;
  255.      * if false, never show the scrollbar
  256.      * @see #getShowHorizontalScroll
  257.      */
  258.     public void setShowHorizontalScroll(boolean cond)
  259.     {
  260.         if (bAllowShowHBar != cond)
  261.         {
  262.             bAllowShowHBar = cond;
  263.             invalidate();
  264.         }
  265.     }
  266.  
  267.     /**
  268.      * Gets the current horizontal scrollbar visibility flag.
  269.      * @return the visibility flag. If true, show the scrollbar when
  270.      * necessary; if false, never show the scrollbar
  271.      * @see #setShowHorizontalScroll
  272.      */
  273.     public boolean getShowHorizontalScroll()
  274.     {
  275.         return bAllowShowHBar;
  276.     }
  277.  
  278.     /**
  279.      * Sets the pixel increment to scroll for every scrollbar
  280.      * arrow press.
  281.      * @param scrollLineIncrement the pixel value to scroll,
  282.      * default is one pixel
  283.      * @see #getScrollLineIncrement
  284.      */
  285.     public void setScrollLineIncrement(int scrollLineIncrement)
  286.     {
  287.         this.scrollLineIncrement = scrollLineIncrement;
  288.     }
  289.  
  290.     /**
  291.      * Gets the current pixel scroll increment.
  292.      * @return the current scroll increment in pixels
  293.      * @see #setScrollLineIncrement
  294.      */
  295.     public int getScrollLineIncrement()
  296.     {
  297.         return scrollLineIncrement;
  298.     }
  299.  
  300.     /**
  301.      * Sets the component in the ScrollingPanel.
  302.      * @param comp the new component to be in the ScrollingPanel
  303.      * @see #getComponent
  304.      */
  305.     public void setComponent(Component comp)
  306.     {
  307.         super.removeAll();
  308.         
  309.         //If we had a component, remove it
  310.         if (this.spComponent != null)
  311.             super.remove(this.spComponent);
  312.         
  313.         //Keep track of the new component 
  314.         this.spComponent = comp;
  315.         
  316.         //Add the new component at the end
  317.         super.add(spComponent, -1);
  318.         
  319.         addInternalComponents();
  320.         
  321.         invalidate();
  322.     }
  323.  
  324.     /**
  325.      * Gets the current component in the ScrollingPanel.
  326.      * @return the current component in the ScrollingPanel
  327.      * @see #setComponent
  328.      */
  329.     public Component getComponent()
  330.     {
  331.         return this.spComponent;
  332.     }
  333.  
  334.     /**
  335.      * Processes events for this component.
  336.      * This is a standard Java AWT method which gets called by the AWT
  337.      * to handle this component's events. The default handler for
  338.      * components dispatches to one of the following methods as needed:
  339.      * action(), gotFocus(), lostFocus(), keyDown(), keyUp(), mouseEnter(),
  340.      * mouseExit(), mouseMove(), mouseDrag(), mouseDown(), or mouseUp().
  341.      *
  342.      * @param evt the event to handle
  343.      * @return true if the event was handled and no further action is needed,
  344.      * false to pass the event to this component's parent
  345.      * @see java.awt.Component#action
  346.      * @see java.awt.Component#gotFocus
  347.      * @see java.awt.Component#lostFocus
  348.      * @see java.awt.Component#keyDown
  349.      * @see java.awt.Component#keyUp
  350.      * @see java.awt.Component#mouseEnter
  351.      * @see java.awt.Component#mouseExit
  352.      * @see java.awt.Component#mouseMove
  353.      * @see java.awt.Component#mouseDrag
  354.      * @see java.awt.Component#mouseDown
  355.      * @see java.awt.Component#mouseUp
  356.      */
  357.     public boolean handleEvent(Event evt)
  358.     {
  359.         if (evt.target == HBar || evt.target == VBar) {
  360.             switch (evt.id)
  361.             {
  362.                 case Event.SCROLL_LINE_UP:
  363.                 {
  364.                     if (evt.target == HBar)
  365.                     {
  366.                         scrollLeft();
  367.                     }
  368.                     else
  369.                     {
  370.                         scrollUp();
  371.                     }
  372.  
  373.                     return true;
  374.                 }
  375.  
  376.                 case Event.SCROLL_LINE_DOWN:
  377.                 {
  378.                     if (evt.target == HBar)
  379.                     {
  380.                         scrollRight();
  381.                     }
  382.                     else
  383.                     {
  384.                         scrollDown();
  385.                     }
  386.  
  387.                     return true;
  388.                 }
  389.  
  390.                 case Event.SCROLL_PAGE_UP:
  391.                 {
  392.                     if (evt.target == HBar)
  393.                     {
  394.                         scrollPageLeft();
  395.                     }
  396.                     else
  397.                     {
  398.                         scrollPageUp();
  399.                     }
  400.  
  401.                     return true;
  402.                 }
  403.  
  404.                 case Event.SCROLL_PAGE_DOWN:
  405.                 {
  406.                     if (evt.target == HBar)
  407.                     {
  408.                         scrollPageRight();
  409.                     }
  410.                     else
  411.                     {
  412.                         scrollPageDown();
  413.                     }
  414.  
  415.                     return true;
  416.                 }
  417.  
  418.                 case Event.SCROLL_ABSOLUTE:
  419.                 {
  420.                     if (evt.target == HBar)
  421.                     {
  422.                         scrollHorizontalAbsolute(((Integer)evt.arg).intValue());
  423.                     }
  424.                     else
  425.                     {
  426.                         scrollVerticalAbsolute(((Integer)evt.arg).intValue());
  427.                     }
  428.  
  429.                     return true;
  430.                 }
  431.             }
  432.         }
  433.  
  434.         return super.handleEvent(evt);
  435.     }
  436.  
  437.     /**
  438.      * Handles redrawing of this component on the screen.
  439.      * This is a standard Java AWT method which gets called by the Java
  440.      * AWT (repaint()) to handle repainting this component on the screen.
  441.      * The graphics context clipping region is set to the bounding rectangle
  442.      * of this component and its <0,0> coordinate is this component's 
  443.      * top-left corner.
  444.      * Typically this method paints the background color to clear the
  445.      * component's drawing space, sets graphics context to be the foreground
  446.      * color, and then calls paint() to draw the component.
  447.      *
  448.      * It is overridden here to avoid unneeded clearing of the background.
  449.      *
  450.      * @param g the graphics context
  451.      * @see java.awt.Component#repaint
  452.      * @see #paint
  453.      */
  454.     public void update(Graphics g)
  455.     {
  456.         paint(g);
  457.     }
  458.  
  459.     /**
  460.      * Paints this component using the given graphics context.
  461.      * This is a standard Java AWT method which typically gets called
  462.      * by the AWT to handle painting this component. It paints this component
  463.      * using the given graphics context. The graphics context clipping region
  464.      * is set to the bounding rectangle of this component and its <0,0>
  465.      * coordinate is this component's top-left corner.
  466.      * 
  467.      * @param g the graphics context used for painting
  468.      * @see java.awt.Component#repaint
  469.      * @see #update
  470.      */
  471.     public void paint(Graphics g)
  472.     {
  473.         if (spComponent == null)
  474.         {
  475.             return;
  476.         }
  477.  
  478.         placeComponents();
  479.     }
  480.  
  481.     /**
  482.      * Scrolls one pixel up.
  483.      * @see #scrollDown
  484.      * @see #scrollLeft
  485.      * @see #scrollRight
  486.      */
  487.     public void scrollUp()
  488.     {
  489.         yCoord += scrollLineIncrement;
  490.  
  491.         if (yCoord > 0)
  492.         {
  493.             yCoord = 0;
  494.         }
  495.  
  496.         VBar.setValue(-yCoord);
  497.         repaint();
  498.     }
  499.  
  500.     /**
  501.      * Scrolls one pixel left.
  502.      * @see #scrollRight
  503.      * @see #scrollUp
  504.      * @see #scrollDown
  505.      */
  506.     public void scrollLeft()
  507.     {
  508.         xCoord += scrollLineIncrement;
  509.  
  510.         if (xCoord > 0)
  511.         {
  512.             xCoord = 0;
  513.         }
  514.  
  515.         HBar.setValue(-xCoord);
  516.         repaint();
  517.     }
  518.  
  519.     /**
  520.      * Scrolls one pixel down.
  521.      * @see #scrollUp
  522.      * @see #scrollLeft
  523.      * @see #scrollRight
  524.      */
  525.     public void scrollDown()
  526.     {
  527.         yCoord -= scrollLineIncrement;
  528.  
  529.         if ( (-yCoord) > VBar.getMaximum())
  530.         {
  531.             yCoord = -VBar.getMaximum();
  532.         }
  533.  
  534.         VBar.setValue(-yCoord);
  535.         repaint();
  536.     }
  537.  
  538.     /**
  539.      * Scrolls one pixel right.
  540.      * @see #scrollLeft
  541.      * @see #scrollUp
  542.      * @see #scrollDown
  543.      */
  544.     public void scrollRight()
  545.     {
  546.         xCoord -= scrollLineIncrement;
  547.  
  548.         if ( (-xCoord) > HBar.getMaximum())
  549.         {
  550.             xCoord = -HBar.getMaximum();
  551.         }
  552.  
  553.         HBar.setValue(-xCoord);
  554.         repaint();
  555.     }
  556.  
  557.     /**
  558.      * Scrolls one "page" up.
  559.      * @see #scrollPageDown
  560.      * @see #scrollPageLeft
  561.      * @see #scrollPageRight
  562.      */
  563.     public void scrollPageUp()
  564.     {
  565.         yCoord += vPageSize;
  566.  
  567.         if (yCoord > 0)
  568.         {
  569.             yCoord = 0;
  570.         }
  571.  
  572.         VBar.setValue(-yCoord);
  573.         repaint();
  574.     }
  575.  
  576.     /**
  577.      * Scrolls one "page" left.
  578.      * @see #scrollPageRight
  579.      * @see #scrollPageUp
  580.      * @see #scrollPageDown
  581.      */
  582.     public void scrollPageLeft()
  583.     {
  584.         xCoord += hPageSize;
  585.  
  586.         if (xCoord > 0)
  587.         {
  588.             xCoord = 0;
  589.         }
  590.  
  591.         HBar.setValue(-xCoord);
  592.         repaint();
  593.     }
  594.  
  595.     /**
  596.      * Scrolls one "page" down.
  597.      * @see #scrollPageUp
  598.      * @see #scrollPageLeft
  599.      * @see #scrollPageRight
  600.      */
  601.     public void scrollPageDown()
  602.     {
  603.         yCoord -= vPageSize;
  604.  
  605.         if ( (-yCoord) > VBar.getMaximum())
  606.         {
  607.             yCoord = -VBar.getMaximum();
  608.         }
  609.  
  610.         VBar.setValue(-yCoord);
  611.         repaint();
  612.     }
  613.  
  614.     /**
  615.      * Scrolls one "page" right.
  616.      * @see #scrollPageLeft
  617.      * @see #scrollPageUp
  618.      * @see #scrollPageDown
  619.      */
  620.     public void scrollPageRight()
  621.     {
  622.         xCoord -= hPageSize;
  623.  
  624.         if ( (-xCoord) > HBar.getMaximum())
  625.         {
  626.             xCoord = -HBar.getMaximum();
  627.         }
  628.  
  629.         HBar.setValue(-xCoord);
  630.         repaint();
  631.     }
  632.  
  633.     /**
  634.      * Scrolls to an absolute vertical position.
  635.      * @param position the pixel position to scroll to
  636.      * @see #scrollHorizontalAbsolute
  637.      */
  638.     public void scrollVerticalAbsolute(int position)
  639.     {
  640.         yCoord = -position;
  641.  
  642.         if (yCoord > 0)
  643.         {
  644.             yCoord = 0;
  645.         }
  646.         else if ( (-yCoord) > VBar.getMaximum())
  647.         {
  648.             yCoord = -VBar.getMaximum();
  649.         }
  650.  
  651.         VBar.setValue(-yCoord);
  652.         repaint();
  653.     }
  654.  
  655.     /**
  656.      * Scrolls to an absolute horizontal position.
  657.      * @param position the pixel position to scroll to
  658.      * @see #scrollVerticalAbsolute
  659.      */
  660.     public void scrollHorizontalAbsolute(int position)
  661.     {
  662.         xCoord = -position;
  663.  
  664.         if (xCoord > 0)
  665.         {
  666.             xCoord = 0;
  667.         }
  668.         else if ( (-xCoord) > HBar.getMaximum())
  669.         {
  670.             xCoord = -HBar.getMaximum();
  671.         }
  672.  
  673.         HBar.setValue(-xCoord);
  674.         repaint();
  675.     }
  676.  
  677.     /**
  678.      * Returns the recommended dimensions to properly display this component.
  679.      * This is a standard Java AWT method which gets called to determine
  680.      * the recommended size of this component. 
  681.      *
  682.      * @see #minimumSize
  683.      */
  684.     public Dimension preferredSize()
  685.     {
  686.         Dimension s = size();
  687.         Dimension m = minimumSize();
  688.         return new Dimension(Math.max(s.width, m.width), Math.max(s.height, m.height));
  689.     }
  690.     
  691.     /**
  692.      * Returns the minimum dimensions to properly display this component.
  693.      * This is a standard Java AWT method which gets called to determine
  694.      * the minimum size of this component. 
  695.      * 
  696.      * @see #preferredSize
  697.      */
  698.     public Dimension minimumSize()
  699.     {
  700.         return new Dimension(width, height);
  701.     }
  702.     
  703.     /**
  704.      * Adds a component to the end of this container.
  705.      * This is a standard Java AWT method which gets called to add a
  706.      * component to a container. The specified component is added to
  707.      * the end of this container.
  708.      *
  709.      * @param comp the component to add
  710.      * @return the added component
  711.      * @see #remove
  712.      */
  713.     public Component add(Component comp)
  714.     {
  715.         setComponent(comp);
  716.         
  717.         repaint();
  718.  
  719.         return comp;
  720.     }
  721.  
  722.     /**
  723.      * Adds a component to the end of this container.
  724.      * This is a standard Java AWT method which gets called to add a
  725.      * component to a container. Typically, the specified component is added to
  726.      * this container at the given zero-relative position index. A
  727.      * position index of -1 would append the component to the end.
  728.      * It has been overridden so that the component always gets added to
  729.      * the end of this container.
  730.      *
  731.      * @param comp the component to add
  732.      * @param pos the zero-relative index at which to add the component or -1 
  733.      * for end (IGNORED)
  734.      * @return the added component
  735.      * @see #remove
  736.      */
  737.     public synchronized Component add(Component comp, int pos)
  738.     {
  739.         return add(comp);
  740.     }
  741.  
  742.     /**
  743.      * Adds a component to the end of this container.
  744.      * This is a standard Java AWT method which gets called to add a
  745.      * component to a container. Typically, the specified component is added to
  746.      * the end of this container, and also added to this container's
  747.      * layout manager with the given name.
  748.      * It has been overridden so that the component always gets added to
  749.      * the end of this container.
  750.      *
  751.      * @param name the positioning directive for the layout manager (IGNORED)
  752.      * @param comp the component to add
  753.      * @return the added component
  754.      * @see #remove
  755.      */
  756.     public synchronized Component add(String name, Component comp)
  757.     {
  758.         return add(comp);
  759.     }
  760.  
  761.     /**
  762.      * Removes the specified component from this container.
  763.      * This is a standard Java AWT method which gets called to remove a
  764.      * component from a container. When this happens the component's 
  765.      * removeNotify() will also get called to indicate component removal.
  766.      * 
  767.      * @param comp the component to remove
  768.      * @see #removeAll
  769.      * @see #add
  770.      */
  771.     public synchronized void remove(Component comp)
  772.     {
  773.         if (comp == VBar || comp == HBar)
  774.         {
  775.             return;
  776.         }
  777.  
  778.         super.remove(comp);
  779.  
  780.         if (comp == spComponent)
  781.         {
  782.             spComponent = null;
  783.         }
  784.     }
  785.     
  786.     private void addInternalComponents()
  787.     {
  788.         super.add(VBar, -1);
  789.         super.add(HBar, -1);
  790.         super.add(cornerRect, -1);
  791.     }
  792.     
  793.     /**
  794.      * Removes all the components from this container.
  795.      * This is a standard Java AWT method which gets called to remove all
  796.      * the components from a container. When this happens each component's 
  797.      * removeNotify() will also get called to indicate component removal.
  798.      * 
  799.      * @see #remove
  800.      * @see #add
  801.      */
  802.     public synchronized void removeAll()
  803.     {
  804.         super.removeAll();
  805.         addInternalComponents();
  806.         spComponent = null;
  807.     }
  808.  
  809.     /**
  810.      * Takes no action. 
  811.      * This is a standard Java AWT method which gets called to specify
  812.      * which layout manager should be used to layout the components in
  813.      * standard containers.
  814.      *
  815.      * Since layout managers CANNOT BE USED with this container the standard
  816.      * setLayout has been OVERRIDDEN for this container and does nothing.
  817.      *
  818.      * @param l the layout manager to use to layout this container's components
  819.      * (IGNORED)
  820.      * @see java.awt.Container#getLayout
  821.      **/
  822.     public void setLayout(LayoutManager mgr)
  823.     {
  824.     }
  825.  
  826.     /**
  827.      * Moves and/or resizes this component.
  828.      * This is a standard Java AWT method which gets called to move and/or 
  829.      * resize this component. Components that are in containers with layout
  830.      * managers should not call this method, but rely on the layout manager
  831.      * instead.
  832.      * 
  833.      * @param x horizontal position in the parent's coordinate space
  834.      * @param y vertical position in the parent's coordinate space
  835.      * @param width the new width
  836.      * @param height the new height
  837.      */
  838.     public synchronized void reshape(int x, int y, int width, int height)
  839.     {
  840.         repaint();
  841.  
  842.         super.reshape(x, y, width, height);
  843.     }
  844.  
  845.     void placeComponents()
  846.     {
  847.         boolean bShowV, bShowH;
  848.         int barSize = 0;
  849.         int vWid = 0;
  850.         int hHt = 0;
  851.         dimComponent = spComponent.size();
  852.         Rectangle rect = bounds();
  853.         
  854.         //???RKM??? Should add an OSPreference for things like this (layout manager would work as well?)
  855.         if (symantec.itools.lang.OS.isSolaris())
  856.             barSize = 17;
  857.         else if (symantec.itools.lang.OS.isMacintosh())
  858.             barSize = 16;
  859.         else
  860.             barSize = 15;
  861.         
  862.         if (bAllowShowHBar && dimComponent.width > rect.width)
  863.         {
  864.             bShowH = true;
  865.             hHt = barSize;
  866.         }
  867.         else
  868.         {
  869.             bShowH = false;
  870.             hHt = 0;
  871.         }
  872.         
  873.         if (bAllowShowVBar && dimComponent.height > (rect.height-hHt))
  874.         {
  875.             bShowV = true;
  876.             vWid = barSize;
  877.             
  878.             if (!bShowH)
  879.             {
  880.                 if (dimComponent.width > (rect.width-vWid))
  881.                 {
  882.                     bShowH = true;
  883.                     hHt = barSize;
  884.                 }
  885.             }
  886.         }
  887.         else
  888.         {
  889.             bShowV = false;
  890.             vWid = 0;
  891.         }
  892.         
  893.         hPageSize = rect.width - vWid - vGapWid;
  894.         vPageSize = rect.height - hHt - hGapHt;
  895.  
  896.         if (bShowV)
  897.         {
  898.             VBar.reshape(rect.width-barSize, 0, barSize, rect.height-hHt);
  899.             VBar.setValues(-yCoord, vPageSize, 0, dimComponent.height - vPageSize);
  900.             VBar.setPageIncrement(vPageSize);
  901.  
  902.             if (!bVBarVisible)
  903.             {
  904.                 bVBarVisible = true;
  905.                 VBar.show();
  906.             }
  907.         }
  908.         else
  909.         {
  910.             if (bVBarVisible)
  911.             {
  912.                 bVBarVisible = false;
  913.                 VBar.hide();
  914.             }
  915.             yCoord = 0;
  916.         }
  917.  
  918.         if (bShowH)
  919.         {
  920.             HBar.reshape(0, rect.height-barSize, rect.width-vWid, barSize);
  921.             HBar.setValues(-xCoord, hPageSize, 0, dimComponent.width - hPageSize);
  922.             HBar.setPageIncrement(hPageSize);
  923.  
  924.             if (!bHBarVisible)
  925.             {
  926.                 bHBarVisible = true;
  927.                 HBar.show();
  928.             }
  929.         }
  930.         else
  931.         {
  932.             if (bHBarVisible)
  933.             {
  934.                 bHBarVisible = false;
  935.                 HBar.hide();
  936.             }
  937.             xCoord = 0;
  938.         }
  939.  
  940.         if (bHBarVisible && bVBarVisible)
  941.         {
  942.             int x = rect.width - vWid;
  943.             int y = rect.height - hHt;
  944.             int w = rect.width - x + 1;
  945.             int h = rect.height - y + 1;
  946.             cornerRect.reshape(x, y, w, h);
  947.  
  948.             if (!bCornerRectVisible)
  949.             {
  950.                 bCornerRectVisible = true;
  951.                 cornerRect.show();
  952.             }
  953.         }
  954.         else
  955.         {
  956.             if (bCornerRectVisible)
  957.             {
  958.                 bCornerRectVisible = false;
  959.                 cornerRect.hide();
  960.             }
  961.         }
  962.  
  963.         spComponent.move(xCoord, yCoord);
  964.         spComponent.validate();
  965.     }
  966. }
  967.  
  968.