package org.khelekore.jsizer;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/** An action that pops up a dialog that sets the ClassSizeFilter */
class SetClassNameFilter extends AbstractAction {
    private static final long serialVersionUID = 1;
    private JFrame f;
    private SizePanel sp;
    
    public SetClassNameFilter (JFrame f, SizePanel sp) {
	super ("Set class name filter...");
	this.f = f;
	this.sp = sp;
    }

    public void actionPerformed (ActionEvent e) {
	ClassNameFilter cnf = sp.getClassNameFilter ();
	String current = "";
	if (cnf != null)
	    current = cnf.getDescription ();
	String prefix = 
	    JOptionPane.showInputDialog (f, "Give class name prefix", current);
	if (prefix == null)
	    return;
	prefix = prefix.trim ();
	if (prefix.equals (""))
	    sp.setClassNameFilter (null);
	else
	    sp.setClassNameFilter (new PrefixFilter (prefix));
    }
}
