/* $Id: ChangeBreadthAction.java 327 2011-08-30 12:59:17Z minao $ */
package smart_gs.drawing_tool.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import smart_gs.drawing_tool.ImageLabel;
import smart_gs.drawing_tool.SpreadCanvas;
import smart_gs.drawing_tool.view.MarkerView;
import smart_gs.drawing_tool.view.MemoPadView;
import smart_gs.drawing_tool.view.View;
import smart_gs.logical.Region;
import smart_gs.swingui.WorkspaceWindow;

public class ChangeBreadthAction implements ActionListener {
	private View view;
	private SpreadCanvas canvas;
	
	public ChangeBreadthAction(SpreadCanvas canvas, Region region) {
		this.view = region.getView();
		this.canvas = canvas;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		int old_breadth = ((MarkerView)view).getBreadth();
		try {
			String new_breadth = JOptionPane.showInputDialog("Please input a positive integer (not less than 5).", old_breadth);
			while (new_breadth == null || Integer.parseInt(new_breadth) < 5) {
				new_breadth = JOptionPane.showInputDialog("Please input a positive integer greater than 15.", old_breadth);
			}
			((MarkerView)view).setBreadth(Integer.parseInt(new_breadth));
			WorkspaceWindow.setUpdated(true);
			ImageLabel.setRectangleVisible(true);
		} catch (NumberFormatException error) {
			JOptionPane.showMessageDialog(canvas.getRootPane(), "An inappropriate value!");
		}
	}

}
