/*
 * Copyright 2004-2005 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy
 * of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 *  
 */

/*
 * Created on Sep 15, 2004
 */
package org.apache.jmeter.gui;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.GridLayout;
// import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JPanel;

import org.apache.jmeter.samplers.SampleSaveConfiguration;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.jorphan.reflect.Functor;
import org.apache.log.Logger;

/**
 * @author mstover
 */
public class SavePropertyDialog extends JDialog implements ActionListener {
	private static final Logger log = LoggingManager.getLoggerForClass();

	private static Map functors = new HashMap();

	private static final long serialVersionUID = 1;

	private SampleSaveConfiguration saveConfig;

    public SavePropertyDialog(){
        log.warn("Constructor only intended for use in testing"); // $NON-NLS-1$
    }
	/**
	 * @param owner
	 * @param title
	 * @param modal
	 * @throws java.awt.HeadlessException
	 */
	public SavePropertyDialog(Frame owner, String title, boolean modal, SampleSaveConfiguration s)
	// throws HeadlessException
	{
		super(owner, title, modal);
		saveConfig = s;
		log.info("SampleSaveConfiguration = " + saveConfig);
		dialogInit();
	}

	private int countMethods(Method[] m) {
		int count = 0;
		for (int i = 0; i < m.length; i++) {
			if (m[i].getName().startsWith("save"))
				count++;
		}
		return count;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.JDialog#dialogInit()
	 */
	protected void dialogInit() {
		if (saveConfig != null) {
			super.dialogInit();
			this.getContentPane().setLayout(new BorderLayout());
			Method[] methods = SampleSaveConfiguration.class.getMethods();
			int x = (countMethods(methods) / 3) + 1;
			log.info("grid panel is " + 3 + " by " + x);
			JPanel checkPanel = new JPanel(new GridLayout(x, 3));
			for (int i = 0; i < methods.length; i++) {
				String name = methods[i].getName();
				if (name.startsWith("save") && methods[i].getParameterTypes().length == 0) {
					try {
						name = name.substring(4);
						JCheckBox check = new JCheckBox(JMeterUtils.getResString("save " + name), ((Boolean) methods[i]
								.invoke(saveConfig, new Object[0])).booleanValue());
						checkPanel.add(check, BorderLayout.NORTH);
						check.addActionListener(this);
						check.setActionCommand("set" + name);
						if (!functors.containsKey(check.getActionCommand())) {
							functors.put(check.getActionCommand(), new Functor(check.getActionCommand()));
						}
					} catch (Exception e) {
						log.warn("Problem creating save config dialog", e);
					}
				}
			}
			getContentPane().add(checkPanel, BorderLayout.NORTH);
			JButton exit = new JButton(JMeterUtils.getResString("done"));
			this.getContentPane().add(exit, BorderLayout.SOUTH);
			exit.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					dispose();
				}
			});
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	public void actionPerformed(ActionEvent e) {
		String action = e.getActionCommand();
		Functor f = (Functor) functors.get(action);
		f.invoke(saveConfig, new Object[] { new Boolean(((JCheckBox) e.getSource()).isSelected()) });
	}

	/**
	 * @return Returns the saveConfig.
	 */
	public SampleSaveConfiguration getSaveConfig() {
		return saveConfig;
	}

	/**
	 * @param saveConfig
	 *            The saveConfig to set.
	 */
	public void setSaveConfig(SampleSaveConfiguration saveConfig) {
		this.saveConfig = saveConfig;
	}
}

@@ -1401,17 +1401,21 @@
 tener %7B%0A
-%09
+%0A    
 private 
@@ -1574,17 +1574,92 @@
 D = 1;%0A%0A
-%09
+    private static final String NAME_SAVE_PFX = %22save%22; // $NON-NLS-1$%0A%0A    
 private 
@@ -2145,16 +2145,30 @@
 Config);
+// $NON-NLS-1$
 %0A%09%09dialo
@@ -2313,29 +2313,52 @@
 ith(
-%22save%22))%0A%09%09%09%09count++;
+NAME_SAVE_PFX)) %7B%0A%09%09%09%09count++;%0A            %7D
 %0A%09%09%7D
@@ -2707,20 +2707,21 @@
 %0A%09%09%09log.
-info
+debug
 (%22grid p
@@ -2916,22 +2916,29 @@
 rtsWith(
-%22save%22
+NAME_SAVE_PFX
 ) && met
@@ -3061,16 +3061,49 @@
 heckBox(
+%0A                                
 JMeterUt
@@ -3124,17 +3124,17 @@
 ng(%22save
- 
+_
 %22 + name
@@ -3134,18 +3134,64 @@
  + name)
+// $NON-NLS-1$%0A                                
 ,
- 
 ((Boolea
@@ -3207,17 +3207,8 @@
 s%5Bi%5D
-%0A%09%09%09%09%09%09%09%09
 .inv
@@ -3385,16 +3385,30 @@
 + name);
+// $NON-NLS-1$
 %0A%09%09%09%09%09%09i
@@ -3781,16 +3781,31 @@
 done%22));
+ // $NON-NLS-1$
 %0A%09%09%09this
@@ -4276,20 +4276,23 @@
 %5B%5D %7B
- new 
 Boolean
+.valueOf
 (((J

Replace new Boolean with Boolean.valueOf Extract common string constant and add NON-NLS comments