/******************************************************************************************
 * Surface Plotter version 1.10                                               Oct 14 1996 *
 * Surface Plotter version 1.20                                               Nov  8 1996 *
 *                                                                                        *
 * InputField.java: Input field with plus-minus buttons for modifying value               *
 *                                                                                        *
 * Copyright (c) 1996 Yanto Suryono. All Rights Reserved.                                 *
 *                                                                                        *
 * Permission to use, copy, and distribute this software for NON-COMMERCIAL purposes      *
 * and without fee is hereby granted, provided that this copyright notice appears in all  *
 * copies and this software is not modified in any way                                    *
 *                                                                                        *
 * Please send bug reports and/or corrections/suggestions to                              *
 * Yanto Suryono <d0771@cranesv.egg.kushiro-ct.ac.jp>                                     *
 ******************************************************************************************/

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


public class InputField extends JPanel {
    private float min_val, max_val, delta;
    private boolean int_val;
    private JTextField textfield;
    
    InputField(int size, float min, float max, float d, boolean integer) {
	super();  
	min_val = min; 
	max_val = max; 
	delta = d; 
	int_val = integer;
	
	setLayout(new BorderLayout());
	add("East", new PlusMinus(this));
	add("Center", textfield = new JTextField(size));
    }
    
    public String getText() {
	return textfield.getText();
    }
    
    public void setText(String text) {
	textfield.setText(text);
    }
    
    public void Increase() {
	float value;
	
	try {
	    value = Float.valueOf(getText()).floatValue();
	}
	catch(NumberFormatException e) {
	    value = 0;
	}    
	if (int_val) value = (int)value;
	value += delta;
	if (value > max_val) value = max_val;
	setText(value + "");
    }
    
    public void Decrease() {
	float value;
	
	try {
	    value = Float.valueOf(getText()).floatValue();
	}
	catch(NumberFormatException e) {
	    value = 0;
	}    
	if (int_val) value = (int)value;
	value -= delta;
	if (value < min_val) value = min_val;
	setText(value + "");
    }
}
