TextDialog.java 2.58 KB
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Graphics;
import java.awt.Frame;

/**
 * A TextDialog is created where you can input a string and there is an advanced
 * setting method. Once you submit you draw the string onto the screen.
 **/
public class TextDialog extends JDialog implements ActionListener
{
	private JButton submit, advanced;
	private JTextField text, xCoord, yCoord;
	private JLabel x, y;
	private FontChooser adText;
	
	/** Creates a TextDialog with parameters of the x and y coordinates clicked. **/
	public TextDialog(int xValue, int yValue)
	{
		// sets the title and other default settings
		setTitle("Text Setup");
		getContentPane().setLayout(null);
		setSize(160,200);
		setVisible(true);	
		initialize(xValue,yValue);
	}
	/** 
	 * Instantiates the fields for the text dialog, such as the text field,
	 * the x and y coordinate field and the advanced settings.
	 **/
	public void initialize(int xValue, int yValue)
	{
		x = new JLabel("X: ");
		x.setBounds(20,50,20,20);
		getContentPane().add(x);
		
		y = new JLabel("Y: ");
		y.setBounds(20,80,20,20);
		getContentPane().add(y);
		
		text = new JTextField();
		text.setBounds(20,20,120,20);
		getContentPane().add(text);
		
		xCoord = new JTextField(xValue+"");
		xCoord.setBounds(40,50,100,20);
		getContentPane().add(xCoord);
		
		yCoord = new JTextField(yValue+"");
		yCoord.setBounds(40,80,100,20);
		getContentPane().add(yCoord);
		
		submit = new JButton("SUBMIT");
		submit.setBounds(20,110,120,20);	
		getContentPane().add(submit);
		submit.addActionListener(this);
		
		advanced = new JButton("Advanced");
		advanced.setBounds(20,140,120,20);	
		getContentPane().add(advanced);
		advanced.addActionListener(this);
		
		Frame[] frames = ControlClass.getFrames();
		adText = new FontChooser(frames[0]);
	}
	
	/** 
	 * Invoked if action performed. If the button clicked is submit then it
	 * will draw it to the screen other wise if its the advanced button then 
	 * the advanced settings will pop up. 
	 **/
	public void actionPerformed(ActionEvent e)
	{
		JButton hit = (JButton)e.getSource();
		if(hit == submit)
		{
			((DrawingCanvas)ControlClass.canvas.get(ControlClass.currentFile)).textOperation2(text.getText(),
			Integer.parseInt(xCoord.getText()),Integer.parseInt(yCoord.getText()), adText.getSelectedFont());
			setVisible(false);
		}
		if(hit == advanced)
		{
			adText.setVisible(true);
		}
	}
}