OSPE_SelectSpectraRangePanel.java 2.31 KB
package osp.ui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

import osp.Mask;

public class OSPE_SelectSpectraRangePanel extends JDialog
{
  private static final long serialVersionUID = 1L;

  BorderLayout borderLayout = new BorderLayout();
  JComboBox<String> startSlit = new JComboBox<String>();
  JComboBox<String> stopSlit = new JComboBox<String>();
  
  JButton jButtonOK = new JButton("OK");
  JButton jButtonCancel = new JButton("Cancel");
  
  Mask mask;
  boolean plot;
  
  public OSPE_SelectSpectraRangePanel(Mask m, boolean b)
  {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setAlwaysOnTop(true);
    
    mask = m;
    plot = b;
    
    for (int i=0 ; i<Mask._NBRSLITS_; i++)
    {
      String texte = new String();
      texte = ""+(i+1);
      startSlit.addItem(texte);
      stopSlit.addItem(texte);
    }

    startSlit.setSelectedIndex( mask.getSelectedSlit() );
    stopSlit.setSelectedIndex( mask.getSelectedSlit() + 1 );
    
    JPanel firstPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    firstPanel.add(new JLabel("Range of slits from"));
    firstPanel.add(startSlit);
    firstPanel.add(new JLabel("to"));
    firstPanel.add(stopSlit);
    this.getContentPane().add(firstPanel, BorderLayout.NORTH);
    
    jButtonOK.addActionListener( new ActionOK() );
    jButtonCancel.addActionListener( new ActionCancel() );
    
    JPanel thirdPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    thirdPanel.add(jButtonOK);
    thirdPanel.add(jButtonCancel);
    this.getContentPane().add(thirdPanel, BorderLayout.SOUTH);
    
    pack();
    setVisible(true);
  }
  
  class ActionOK  extends AbstractAction
  {
    private static final long serialVersionUID = 1L;

    @Override
	public void actionPerformed(ActionEvent e)
    {
      for (int i = startSlit.getSelectedIndex(); i <= stopSlit.getSelectedIndex(); i++)
      {
        mask.setPlotSpectrum(i, plot);
      }
      dispose();
    }
  }

  class ActionCancel  extends AbstractAction
  {
    private static final long serialVersionUID = 1L;

    @Override
	public void actionPerformed(ActionEvent e)
    {
      dispose();
    }
  }
}