package GCB; import Application.*; import java.awt.*; import java.awt.event.*; import java.util.*; /** Build the main GUI * * Put up a window with three areas * Top area is a menu bar * Middle area is a scroll window to display text (use append() method) * Bottom area is an input area that controls the program operation * and supplies input that the program can use. * @author George C. Blankenship, Jr. */ public class SolicitGUI extends Frame { static final String CODE_FILE = "SolicitGUI"; static final int CODE_REVISION = 0; // global data private MainGUI mainGUI; // so that this object can get to main window private SolicitGUI box; // this window private ParameterPanel configurationPanel; private String lastInput, // last input entered on input line title, author; private Dimension screenSize, windowSize; // internal data private Button doneButton, cancelButton; private Trace trace; // internal classes class MainWindowEvents extends WindowAdapter implements ActionListener { // events from the solicit GUI // potential methods: // windowActivated() // windowClosed() // windowClosing() - X pressed // windowDactivated() // windowDeiconified() - restored // windowIconified() - minimized // windowOpened() public void windowClosing(WindowEvent e) { // someone wants to closed the solicit window trace.write("solicitation finished"); box.dispose(); } public void actionPerformed(ActionEvent e) { // a menu has generated an event trace.write(CODE_FILE+"->actionPerformed"); String name = e.getActionCommand(); // get menu keyword trace.write(CODE_FILE+"->actionPerformed"+":"+name); if(name=="done") { // Done button configurationPanel.solicitationDone(); trace.write("solicitation finished"); box.dispose(); } if(name=="cancel") { // Cancel button trace.write("solicitation aborted"); box.dispose(); } } } // the following class is used to debug the sizing and placement of a window class WindowComponentListener implements ComponentListener { public void componentResized(ComponentEvent e) { System.out.println("Resize component "+e.paramString()); e.getComponent().list(); } public void componentMoved(ComponentEvent e) { System.out.println("Move component "+e.paramString()); e.getComponent().list(); } public void componentHidden(ComponentEvent e) { System.out.println("Hide component "+e.paramString()); e.getComponent().list(); } public void componentShown(ComponentEvent e) { System.out.println("Show component "+e.paramString()); e.getComponent().list(); } } // private methods void setupPanels() { // define smaller windows (or panels) Panel p = new Panel(); // parameter area p.setLayout(new FlowLayout()); // centered p.add(configurationPanel.setSolicitPanel()); Font d = new Font("Courier",Font.PLAIN,12); p.setFont(d); p.setBackground(Color.white); p.setForeground(Color.black); add("Center",p); // center of main window p = new Panel(); // buttons p.setLayout(new FlowLayout()); doneButton = new Button("done"); doneButton.setActionCommand("done"); doneButton.addActionListener(new SolicitGUI.MainWindowEvents()); p.add("East",doneButton); cancelButton = new Button("cancel"); cancelButton.setActionCommand("cancel"); cancelButton.addActionListener(new SolicitGUI.MainWindowEvents()); p.add("West",cancelButton); Font i = new Font("Courier",Font.PLAIN,12); p.setFont(i); p.setBackground(Color.white); p.setForeground(Color.black); add("South",p); // bottom of main window pack(); } // public methods /* Constructor for the main window */ public SolicitGUI(String t, MainGUI g, ParameterPanel p) { // initialize the main window super(t); // define the main window screenSize = Toolkit.getDefaultToolkit().getScreenSize(); title = t; configurationPanel = p; mainGUI = g; box = this; trace = new Trace(mainGUI,CODE_FILE); // trace for debug trace.setActive(false); // turn it off initially setupPanels(); // set up the display panels doneButton.requestFocus(); addWindowListener(new SolicitGUI.MainWindowEvents()); // wait for something to happen // addComponentListener(new GUI.WindowComponentListener()); // needed to find real information setVisible(true); // make window visible windowSize = getSize(); // center the window setLocation((screenSize.width-windowSize.width)/2, (screenSize.height-windowSize.height)/2); trace.write("solicit GUI ready"); } }