package editor.gui.generic;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.plaf.basic.BasicArrowButton;

/**
 * TODO: Comment this
 * TODO: Eventually allow this to have vertical versions as well
 * @author Alec Roelke
 */
@SuppressWarnings("serial")
public class ButtonScrollPane extends JPanel
{
	public ButtonScrollPane(Component view)
	{
		super(new BorderLayout());
		
		BasicArrowButton left = new BasicArrowButton(BasicArrowButton.WEST);
		add(left, BorderLayout.WEST);
		
		JScrollPane pane = new JScrollPane(view);
		pane.setBorder(null);
		pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		add(pane, BorderLayout.CENTER);
		
		BasicArrowButton right = new BasicArrowButton(BasicArrowButton.EAST);
		add(right, BorderLayout.EAST);
		
		JScrollBar bar = pane.getHorizontalScrollBar();
		left.addActionListener(e -> {
			bar.getActionMap().get("negativeUnitIncrement").actionPerformed(new ActionEvent(
			bar,
			ActionEvent.ACTION_PERFORMED,
			"",
			e.getWhen(),
			e.getModifiers()));
		});
		right.addActionListener(e -> {
			bar.getActionMap().get("positiveUnitIncrement").actionPerformed(new ActionEvent(
			bar,
			ActionEvent.ACTION_PERFORMED,
			"",
			e.getWhen(),
			e.getModifiers()));
		});
		
		view.addComponentListener(new ComponentListener()
		{
			@Override
			public void componentResized(ComponentEvent e)
			{
				boolean scrollable = view != null && view.getPreferredSize().width > pane.getSize().width;
				left.setEnabled(scrollable);
				right.setEnabled(scrollable);
			}
			
			@Override
			public void componentHidden(ComponentEvent e)
			{}

			@Override
			public void componentMoved(ComponentEvent e)
			{}

			@Override
			public void componentShown(ComponentEvent e)
			{}
		});
	}
}

@@ -194,16 +194,44 @@
 tener;%0A%0A
+import javax.swing.JButton;%0A
 import j
@@ -361,16 +361,52 @@
 utton;%0A%0A
+import editor.util.UnicodeSymbols;%0A%0A
 /**%0A * T
@@ -590,16 +590,417 @@
 Panel%0A%7B%0A
+%09private static class ArrowButton extends JButton%0A%09%7B%0A%09%09public static final int EAST = 1;%0A%09%09public static final int WEST = 3;%0A%0A%09%09public ArrowButton(int direction)%0A%09%09%7B%0A%09%09%09super(String.valueOf(switch (direction) %7B%0A%09%09%09%09case EAST -%3E UnicodeSymbols.RIGHT_ARROW;%0A%09%09%09%09case WEST -%3E UnicodeSymbols.LEFT_ARROW;%0A%09%09%09%09default -%3E throw new IllegalArgumentException(%22Illegal direction %22 + direction);%0A%09%09%09%7D));%0A%09%09%7D%0A%09%7D%0A%0A
 %09public 
@@ -1064,26 +1064,19 @@
 out());%0A
-%09%09
 %0A%09%09
-Basic
 ArrowBut
@@ -1082,37 +1082,32 @@
 tton left = new 
-Basic
 ArrowButton(Basi
@@ -1094,37 +1094,32 @@
 new ArrowButton(
-Basic
 ArrowButton.WEST
@@ -1149,26 +1149,24 @@
 yout.WEST);%0A
-%09%09
 %0A%09%09JScrollPa
@@ -1337,18 +1337,11 @@
 R);%0A
-%09%09
 %0A%09%09
-Basic
 Arro
@@ -1360,21 +1360,16 @@
 t = new 
-Basic
 ArrowBut
@@ -1372,21 +1372,16 @@
 wButton(
-Basic
 ArrowBut
@@ -1424,18 +1424,16 @@
 .EAST);%0A
-%09%09
 %0A%09%09JScro
@@ -1492,33 +1492,35 @@
 dActionListener(
-e
+(e)
  -%3E %7B%0A%09%09%09bar.get
@@ -1712,17 +1712,19 @@
 istener(
-e
+(e)
  -%3E %7B%0A%09%09
@@ -1898,18 +1898,16 @@
 ;%0A%09%09%7D);%0A
-%09%09
 %0A%09%09view.
@@ -2190,19 +2190,16 @@
 );%0A%09%09%09%7D%0A
-%09%09%09
 %0A%09%09%09@Ove

Add placeholder for arrow button class