package bakatxt.gui;

import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;

class BakaScrollPane extends JScrollPane {

    private static final int WIDTH = UIHelper.WINDOW_X - 4 * UIHelper.BORDER;

    public BakaScrollPane(JComponent contained, int initialHeight) {
        super(contained);
        contained.setAutoscrolls(true);
        this.setComponentSizeBasedOnHeight(initialHeight);
        this.setViewportView(contained);
        this.setOpaque(false);
        this.getViewport().setOpaque(false);
        this.getViewport().setBackground(UIHelper.TRANSPARENT);
        this.setBorder(BorderFactory.createEmptyBorder());

        this.setVerticalScrollBar(invisibleScrollBar());
        this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
        this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    }

    protected void setComponentSizeBasedOnHeight(int height) {

        assert (height > 0) : "height of pane must not be less than zero";

        if (height > UIHelper.WINDOW_Y) {
            height = UIHelper.WINDOW_Y;
        }
        this.setPreferredSize(new Dimension(WIDTH, height));
    }

    /**
     * Use a 'hack' to have an invisible scrollbar
     * @return an invisible vertical scrollbar
     */
    private static JScrollBar invisibleScrollBar() {
        JScrollBar invisibleScrollBar = new JScrollBar(JScrollBar.VERTICAL) {

            @Override
            public boolean isVisible() {
              return true;
            }
          };
          return invisibleScrollBar;
    }
}

@@ -1,8 +1,29 @@
+//@author A0116538A%0A%0A
 package 
@@ -193,16 +193,133 @@
 lPane;%0A%0A
+/**%0A * This class gives an invisible vertical scrollbar to a component when it's%0A * maximum height is reached%0A *%0A */%0A
 class Ba
@@ -472,23 +472,23 @@
 onent co
-ntained
+mponent
 , int in
@@ -518,23 +518,23 @@
 super(co
-ntained
+mponent
 );%0A     
@@ -538,23 +538,23 @@
       co
-ntained
+mponent
 .setAuto
@@ -576,21 +576,16 @@
         
-this.
 setCompo
@@ -626,29 +626,24 @@
 t);%0A        
-this.
 setViewportV
@@ -652,31 +652,618 @@
 w(co
-ntained);%0A        this.
+mponent);%0A        setInvisiblePane();%0A        setScrollBars();%0A    %7D%0A%0A    /**%0A     * @param height is to be the height of the BakaScrollPane%0A     */%0A    protected void setComponentSizeBasedOnHeight(int height) %7B%0A%0A        assert (height %3E= 0) : %22height of pane must not be less than zero%22;%0A%0A        if (height %3E UIHelper.WINDOW_Y) %7B%0A            height = UIHelper.WINDOW_Y;%0A        %7D%0A        this.setPreferredSize(new Dimension(WIDTH, height));%0A    %7D%0A%0A    /**%0A     * Make the background of the pane invisible as well as the borders to be%0A     * non-existent%0A     */%0A    private void setInvisiblePane() %7B%0A        
 setO
@@ -1276,37 +1276,32 @@
 false);%0A        
-this.
 getViewport().se
@@ -1324,21 +1324,16 @@
         
-this.
 getViewp
@@ -1383,21 +1383,16 @@
         
-this.
 setBorde
@@ -1429,16 +1429,152 @@
 der());%0A
+    %7D%0A%0A    /**%0A     * Remove horizontal scrolling and set the vertical scrollbar to invisible%0A     */%0A    private void setScrollBars() %7B
 %0A       
@@ -1566,37 +1566,32 @@
 ars() %7B%0A        
-this.
 setVerticalScrol
@@ -1626,21 +1626,16 @@
         
-this.
 setVerti
@@ -1700,21 +1700,16 @@
         
-this.
 setHoriz
@@ -1781,308 +1781,8 @@
  %7D%0A%0A
-    protected void setComponentSizeBasedOnHeight(int height) %7B%0A%0A        assert (height %3E 0) : %22height of pane must not be less than zero%22;%0A%0A        if (height %3E UIHelper.WINDOW_Y) %7B%0A            height = UIHelper.WINDOW_Y;%0A        %7D%0A        this.setPreferredSize(new Dimension(WIDTH, height));%0A    %7D%0A%0A
     

Refactor BakaScrollPane and add comments