/**************************************************************************
* Copyright (c) 1996 Jim Crossley
*
* Although it's unlikely that anyone would actually want it,
* permission is hereby granted, without written agreement and
* without license or royalty fees, to use, copy, modify, and
* distribute this software and its documentation for any purpose,
* provided that the above copyright notice and the following three
* paragraphs appear in all copies of this software, its documentation
* and any derivative work.
*
* In no event shall Jim Crossley or Automated Design Systems, Inc. be
* liable to any party for direct, indirect, special, incidental, or
* consequential damages arising out of the use of this software and
* its documentation.
*
* The software provided hereunder is on an "as is" basis, and neither
* Jim Crossley nor Automated Design Systems, Inc. has any obligation
* to provide maintenance, support, updates, enhancements, or modifications.
*
* Derived or altered versions must be plainly marked as such, and
* must not be misrepresented as being the original software.
***************************************************************************/
package dba;

import java.awt.*;
import utilities.TabKeyPanel;
import java.applet.Applet;
import java.util.Properties;

/**
 * This applet provides a framework for querying databases and displaying results.
 *
 * @author Jim Crossley
 * @version 1.0, 9/17/1996
 */
public class dba extends Applet implements Connectable{

    //DBClient dbc = new DBClient();
    LoginBox lb = new LoginBox(this);

    /**
     * Initialize GUI components and set the focus.
     */
    public void init() {

        super.init();
        setBackground(Color.lightGray);

        TabKeyPanel p = new TabKeyPanel();
        //{{INIT_CONTROLS
        p.setLayout(null);
        p.resize(489,287);
        txtStmt=new TextArea(4,54);
        txtStmt.setFont(new Font("Dialog",Font.PLAIN,10));
        p.add(txtStmt);
        txtStmt.reshape(21,29,449,69);
        btnExecute=new Button("&Execute");
        btnExecute.disable();
        p.add(btnExecute);
        btnExecute.reshape(250,110,84,20);
        lblStmt=new Label("SQL Statement:");
        p.add(lblStmt);
        lblStmt.reshape(21,7,98,16);
        lblResults=new Label("Results:");
        p.add(lblResults);
        lblResults.reshape(23,137,93,14);
        txtResults=new TextArea(7,54);
        p.add(txtResults);
        txtResults.reshape(24,156,446,115);
        btnConnect=new Button("Connect");
        p.add(btnConnect);
        btnConnect.reshape(154,110,84,20);
        //}}
        add(p);

        txtStmt.requestFocus();
    }

    // Handle the click events for the two buttons on the applet.
    public boolean handleEvent(Event event) {
        if (event.id == Event.ACTION_EVENT && event.target == btnConnect) {
            // Connect button
            clickedBtnConnect();
            return true;
        }
        else
        if (event.id == Event.ACTION_EVENT && event.target == btnExecute) {
            // Execute button
            clickedBtnExecute();
            return true;
        }
        return super.handleEvent(event);
    }

    //{{DECLARE_CONTROLS
    TextArea txtStmt;
    Button btnExecute;
    Label lblStmt;
    Label lblResults;
    TextArea txtResults;
    Button btnConnect;
    //}}

    /**
     * Execute a query through the DBClient object.
     */
    public void clickedBtnExecute() {

        txtResults.setText("");
        btnExecute.disable();
        /*
        if (dbc.execute(txtStmt.getText())) {
            do {
                txtResults.appendText(dbc.getString(1) + "\n");
            } while (dbc.next());
        }
        */
        btnExecute.enable();
    }

    /**
     * Bring up a dialog box (frame actually) that prompts the user for
     * username and password.
     */
    public void clickedBtnConnect() {
        //if (!dbc.canConnect()) {
            lb.show();
        //}
    }

    /**
     * To support the Connectable interface.
     */
    public boolean connect(String l, String p) {
        //if (dbc.connect(l,p)) {
            btnExecute.enable();
            return true;
        //}
        //else return false;
    }
}

