/**  FlipModePanel Class
   * @version 1.0  18 apr 2000
   * @author Lawrence Rodrigues
   **/
package com.vistech.jai.render;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.geom.*;
import javax.media.jai.*;
import com.vistech.util.*;
import com.vistech.imageviewer.*;

/** Creates a panel for selecting interpolation modes.
  * @version 1.0 18 Apr 2000
  * @author Lawrence Rodrigues
  **/

public class InterpModePanel extends JPanel implements TabPanel {
   protected ImageManipulator viewer;
   public InterpModePanel(ImageManipulator viewer){
      this.viewer = viewer;
      createUI();
   }
   public void openPanel() { }
   public void closePanel(){ }

   protected void createUI() {
      ButtonGroup bg = new ButtonGroup();
      JRadioButton nearest = new JRadioButton("Nearest");
      JRadioButton bilinear= new JRadioButton("Bilinear");
      JRadioButton bicubic = new JRadioButton("Bi-cubic");
      JRadioButton bicubic2= new JRadioButton("Bi-cubic 2");

      InterpModeAdapter na = new InterpModeAdapter(Interpolation.INTERP_NEAREST);
      InterpModeAdapter bla= new InterpModeAdapter(Interpolation.INTERP_BILINEAR);
      InterpModeAdapter bca = new InterpModeAdapter(Interpolation.INTERP_BICUBIC);
      InterpModeAdapter bc2a = new InterpModeAdapter(Interpolation.INTERP_BICUBIC_2);
      nearest.setSelected(true);

      nearest.addActionListener(na);
      bilinear.addActionListener(bla);
      bicubic.addActionListener(bca);
      bicubic2.addActionListener(bc2a);

      bg.add(nearest);
      bg.add(bilinear);
      bg.add(bicubic);
      bg.add(bicubic2);
      setLayout(new GridLayout(2,2));
      add(nearest);
      add(bilinear);
      add(bicubic);
      add(bicubic2);
   }
    class InterpModeAdapter implements ActionListener {
      int mode;
      public InterpModeAdapter( int type) {mode = type;}
      public void actionPerformed(ActionEvent e) {
        viewer.setInterpolationType(mode);
      }
   }
}