Allow PluginPanels to opt-out of the scrollbar

For panels with tabs it is best to have the scrollbar inside of the tab pane, not around it.
This commit is contained in:
Max Weber
2018-04-21 08:56:10 -06:00
committed by Adam
parent 16aca14f7f
commit 7645d6a04f

View File

@@ -36,10 +36,11 @@ import lombok.Getter;
public abstract class PluginPanel extends JPanel
{
static final int PANEL_WIDTH = 225;
public 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);
private static final Dimension OUTER_PREFERRED_SIZE = new Dimension(PluginPanel.PANEL_WIDTH + SCROLLBAR_WIDTH, 0);
@Getter(AccessLevel.PROTECTED)
private final JScrollPane scrollPane;
@@ -47,33 +48,47 @@ public abstract class PluginPanel extends JPanel
@Getter(AccessLevel.PACKAGE)
private final JPanel wrappedPanel;
public PluginPanel()
protected PluginPanel()
{
this(true);
}
protected PluginPanel(boolean wrap)
{
super();
setBorder(BORDER_PADDING);
setLayout(new GridLayout(0, 1, 0, 3));
if (wrap)
{
setBorder(BORDER_PADDING);
setLayout(new GridLayout(0, 1, 0, 3));
final JPanel northPanel = new JPanel();
northPanel.setLayout(new BorderLayout());
northPanel.add(this, BorderLayout.NORTH);
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);
scrollPane = new JScrollPane(northPanel);
scrollPane.getVerticalScrollBar().setUnitIncrement(16); //Otherwise scrollspeed is really slow
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
wrappedPanel = new JPanel();
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);
// Adjust the preferred size to expand to width of scrollbar to
// to preven scrollbar overlapping over contents
wrappedPanel.setPreferredSize(OUTER_PREFERRED_SIZE);
wrappedPanel.setLayout(new BorderLayout());
wrappedPanel.add(scrollPane, BorderLayout.CENTER);
}
else
{
scrollPane = null;
wrappedPanel = this;
}
}
@Override
public Dimension getPreferredSize()
{
return new Dimension(PANEL_WIDTH, super.getPreferredSize().height);
int width = this == wrappedPanel ? PANEL_WIDTH + SCROLLBAR_WIDTH : PANEL_WIDTH;
return new Dimension(width, super.getPreferredSize().height);
}
public void onActivate()