/*
 * Copyright (c) 2017, Adam <Adam@sigterm.info>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package net.runelite.client.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.EmptyBorder;
import lombok.AccessLevel;
import lombok.Getter;

public abstract class PluginPanel extends JPanel
{
	static final int PANEL_WIDTH = 225;
	static final int SCROLLBAR_WIDTH = 17;
	private static final int OFFSET = 6;
	private static final EmptyBorder BORDER_PADDING = new EmptyBorder(OFFSET, OFFSET, OFFSET, OFFSET);

	@Getter(AccessLevel.PROTECTED)
	private final JScrollPane scrollPane;

	@Getter(AccessLevel.PACKAGE)
	private final JPanel wrappedPanel;

	public PluginPanel()
	{
		super();
		setBorder(BORDER_PADDING);
		setLayout(new GridLayout(0, 1, 0, 3));

		final JPanel northPanel = new JPanel();
		northPanel.setLayout(new BorderLayout());
		northPanel.add(this, BorderLayout.NORTH);

		scrollPane = new JScrollPane(northPanel);
		scrollPane.getVerticalScrollBar().setUnitIncrement(16); //Otherwise scrollspeed is really slow
		scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

		wrappedPanel = new JPanel();

		// Adjust the preferred size to expand to width of scrollbar to
		// to preven scrollbar overlapping over contents
		wrappedPanel.setPreferredSize(new Dimension(PluginPanel.PANEL_WIDTH + SCROLLBAR_WIDTH, 0));
		wrappedPanel.setLayout(new BorderLayout());
		wrappedPanel.add(scrollPane, BorderLayout.CENTER);
	}

	@Override
	public Dimension getPreferredSize()
	{
		return new Dimension(PANEL_WIDTH, super.getPreferredSize().height);
	}

	public void onActivate()
	{
	}

	public void onDeactivate()
	{
	}
}

@@ -1731,16 +1731,23 @@
 anel%0A%7B%0A%09
+public 
 static f
@@ -1951,16 +1951,132 @@
 OFFSET);
+%0A%09private static final Dimension OUTER_PREFERRED_SIZE = new Dimension(PluginPanel.PANEL_WIDTH + SCROLLBAR_WIDTH, 0);
 %0A%0A%09@Gett
@@ -2210,21 +2210,70 @@
 nel;%0A%0A%09p
-ublic
+rotected PluginPanel()%0A%09%7B%0A%09%09this(true);%0A%09%7D%0A%0A%09protected
  PluginP
@@ -2273,24 +2273,36 @@
 PluginPanel(
+boolean wrap
 )%0A%09%7B%0A%09%09super
@@ -2305,16 +2305,33 @@
 uper();%0A
+%09%09if (wrap)%0A%09%09%7B%0A%09
 %09%09setBor
@@ -2351,16 +2351,17 @@
 DDING);%0A
+%09
 %09%09setLay
@@ -2396,16 +2396,17 @@
 3));%0A%0A%09%09
+%09
 final JP
@@ -2437,16 +2437,17 @@
 anel();%0A
+%09
 %09%09northP
@@ -2482,16 +2482,17 @@
 out());%0A
+%09
 %09%09northP
@@ -2530,16 +2530,17 @@
 TH);%0A%0A%09%09
+%09
 scrollPa
@@ -2573,16 +2573,17 @@
 Panel);%0A
+%09
 %09%09scroll
@@ -2671,16 +2671,17 @@
 ly slow%0A
+%09
 %09%09scroll
@@ -2766,16 +2766,17 @@
 ER);%0A%0A%09%09
+%09
 wrappedP
@@ -2797,16 +2797,17 @@
 nel();%0A%0A
+%09
 %09%09// Adj
@@ -2864,16 +2864,17 @@
 lbar to%0A
+%09
 %09%09// to 
@@ -2918,16 +2918,17 @@
 tents%0A%09%09
+%09
 wrappedP
@@ -2953,70 +2953,32 @@
 ize(
-new Dimension(PluginPanel.PANEL_WIDTH + SCROLLBAR_WIDTH, 0)
+OUTER_PREFERRED_SIZE
 );%0A
+%09
 %09%09wr
@@ -3019,16 +3019,17 @@
 out());%0A
+%09
 %09%09wrappe
@@ -3078,61 +3078,208 @@
 );%0A%09
-%7D%0A%0A%09@Override%0A%09public Dimension getPreferredSize()%0A%09%7B
+%09%7D%0A%09%09else%0A%09%09%7B%0A%09%09%09scrollPane = null;%0A%09%09%09wrappedPanel = this;%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public Dimension getPreferredSize()%0A%09%7B%0A%09%09int width = this == wrappedPanel ? PANEL_WIDTH + SCROLLBAR_WIDTH : PANEL_WIDTH;
 %0A%09%09r
@@ -3298,27 +3298,21 @@
 mension(
-PANEL_WIDTH
+width
 , super.

Allow PluginPanels to opt-out of the scrollbar