/**
 * Copyright 2013, Alex Stangl. See LICENSE for licensing details.
 */
package us.stangl.crostex.gui;

import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import us.stangl.crostex.Grid;
import us.stangl.crostex.util.Message;

/**
 * Panel containing all content for a top-level tab.
 * @author Alex Stangl
 */
public class TopLevelTabPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	
	// minimum zoom (grid cell width/height)
	private static final int ZOOM_MINIMUM = 10;
	
	// maximum zoom (grid cell width/height)
	private static final int ZOOM_MAXIMUM = 100;
	
	// default zoom factor (grid cell width/height)
	private static final int DEFAULT_ZOOM_VALUE = 24;
	
	// panel holding crossword grid
	private final CrosswordPanel crosswordPanel;

	// tabbed pane holding other panes related to the grid
	private final JTabbedPane tabbedPane = new JTabbedPane();

	private final JSlider zoomSlider = new JSlider();
	
	private final JScrollPane scrollPane;
	
	public TopLevelTabPanel(MainFrame mainFrame, Grid grid) {

		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		crosswordPanel = new CrosswordPanel(mainFrame, grid);
		scrollPane = new JScrollPane(crosswordPanel);
		//scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		//scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		JPanel leftPanel = GuiUtils.yBoxLayoutPanel(scrollPane, zoomSlider);
		
		// set range on zoomSlider
		zoomSlider.setMinimum(ZOOM_MINIMUM);
		zoomSlider.setMaximum(ZOOM_MAXIMUM);
		zoomSlider.setValue(DEFAULT_ZOOM_VALUE);
		zoomSlider.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				Grid grid = crosswordPanel.getGrid();
				int value = zoomSlider.getValue();
				grid.setCellHeight(value);
				grid.setCellWidth(value);
				crosswordPanel.setSize(grid.getPixelWidth(), grid.getPixelHeight());
				scrollPane.revalidate();
				crosswordPanel.repaint(0);
			}
		});
		
		add(leftPanel);
		add(tabbedPane);
		tabbedPane.addTab(Message.STATS_TAB_TITLE.toString(), new StatsPanel(grid));
		tabbedPane.addTab(Message.CLUES_TAB_TITLE.toString(), new SideTabPanel(mainFrame, grid));
		tabbedPane.setSelectedIndex(0);
	}

	/**
	 * @return the crosswordPanel
	 */
	public CrosswordPanel getCrosswordPanel() {
		return crosswordPanel;
	}

	/**
	 * @return the tabbedPane
	 */
	public JTabbedPane getTabbedPane() {
		return tabbedPane;
	}
}

@@ -217,16 +217,47 @@
 Slider;%0A
+import javax.swing.JSplitPane;%0A
 import j
@@ -1246,16 +1246,19 @@
 rid) %7B%0A%0A
+%09%09%0A
 %09%09setLay
@@ -1301,16 +1301,16 @@
 AXIS));%0A
-
 %09%09crossw
@@ -1357,16 +1357,16 @@
  grid);%0A
+
 %09%09scroll
@@ -1409,176 +1409,8 @@
 l);%0A
-%09%09//scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);%0A%09%09//scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);%0A
 %09%09JP
@@ -2023,40 +2023,100 @@
 %09%0A%09%09
-add(leftPanel);%0A%09%09add(tabbedPane
+JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, tabbedPane);%0A%09%09add(sp
 );%0A%09

Add split pane.