// AdderOfOneEnteredShape.java
// Listener class used with window class ShapesWindow2,
// defined in ShapesWindow2.java.
//
// Adds one shape, using data obtained from the
// user via a dialog box.
//
// This version obtains, from the user, a line of
// text representing a ShapeOutline object, then
// parses the line to generate the ShapeOutline
// object.
import java.awt.event.*;
import javax.swing.*;
class AdderOfOneEnteredShape implements ActionListener
{
private ShapesWindow2 window;
private ShapeBoundedBuffer shapes;
AdderOfOneEnteredShape(ShapesWindow2 window,
ShapeBoundedBuffer shapes)
{
this.window = window;
this.shapes = shapes;
} // constructor
public void actionPerformed(ActionEvent e)
{
String line;
// Between two rows of asterisks below are two statements
// obtaining line from a dialog box of some kind.
// Exactly one of the two statements should be uncommented.
// ****************************************************************
//
line = JOptionPane.showInputDialog(
window,
"Enter a string representation of a shape");
//
// line = ShapeInputTextDialog.showDialog(window);
//
// ****************************************************************
if ( line == null )
{
window.repaint();
return;
} // if
try {
shapes.add(ShapeOutline.parseShape(line));
} // try
catch (ShapeTextFormatException stfe) {
JOptionPane.showMessageDialog(window,
stfe.getMessage(),
"Invalid shape data",
JOptionPane.ERROR_MESSAGE);
} // catch
catch (RuntimeException re) {
re.printStackTrace();
} // catch
window.updateDisplay();
} // method actionPerformed
} // class AdderOfOneEnteredShape