/*
   Source code by David Eck
                  Department of Mathematics and Computer Science
                  Hobart and William Smith Colleges
                  Geneva, NY 14456
                  eck@hws.edu
                  
   This Java source code file can be used IN UNMODIFIED FORM for
   any purpose.  You can also make and distribute modified versions,
   as long as you include an acknowledgement of the original
   author in the modified version.
*/

package xca;

import java.awt.*;
import javax.swing.*;

public class MainPanel extends JPanel {

   private WorldPane worldPane;

   public MainPanel() {
      this(null,0,null);
   }
   
   public MainPanel(World world) {
      this(world,0,null);
   }
   
   public MainPanel(World world, int imageHeight) {
      this(world,imageHeight,null);
   }

   public MainPanel(World world, int imageHeight, int[] palette) {
      create(new WorldPane(world,imageHeight,palette));
   }
   
   public MainPanel(boolean create) {
      if (create)
         create(new WorldPane(true));
      else
         create(new WorldPane(false));
   }

   private void create(WorldPane worldPane) {
      this.worldPane = worldPane;
      JPanel w = worldPane.getScrollingWorldPane();

      setLayout(new BorderLayout());
      add(w, BorderLayout.CENTER);

      JPanel top = new JPanel();
      top.setLayout(new GridLayout(2,1,2,2));
      top.setBackground(Color.gray);

      JLabel info = worldPane.getInfoLabel();
      info.setForeground(new Color(0xAA0000));
      info.setBackground(Color.white);
      JPanel ip = new JPanel();
      ip.setLayout(new BorderLayout());
      ip.setBackground(Color.white);
      ip.add(info, BorderLayout.CENTER);
      top.add(ip);

      JPanel sp = new JPanel();
      sp.setBackground(Color.white);
      sp.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
      sp.setLayout(new BorderLayout(10,10));
      JSlider slider = worldPane.getLambdaSlider();
      slider.setBackground(Color.white);
      sp.add(slider, BorderLayout.CENTER);
      JLabel label = worldPane.getLambdaLabel();
      label.setForeground(new Color(0xAA0000));
      label.setBackground(Color.white);
      sp.add(label, BorderLayout.WEST);
      top.add(sp);

      top.setBorder(BorderFactory.createLineBorder(Color.gray,2));
      add(top, BorderLayout.NORTH);
   }
   
   public WorldPane getWorldPane() {
      return worldPane;
   }

}

