Package com.linxpda.dbaware.awt

This package contains a collection of data aware components for use in building applications around the PJODe and PJODe C/S ODBMS systems.

See:
          Description

Class Summary
DBCheckbox A data aware implementation of java.awt.Checkbox.
DBChoice A data-aware implementation of java.awt.Choice.
DBContainer A data-aware implementation of java.awt.Panel.
DBList A data-aware implementation of java.awt.List.
DBNumericField A data-aware implementation of java.awt.TextField that only allows input of numeric values (and a single decimal point if DECIMAL mode is selected.
DBRadiobox A data-aware implementation of java.awt.Checkbox which belongs to a group of other Checkboxes, parented by a DBRadioGroup.
DBRadioGroup This class is responsible for parenting a collection of DBRadiobox components.
DBRootPanel Top-most parent for all DBAware components.
DBScrollPanel A DBContainer that provides automatic scrolling capabilities very similar to java.awt.ScrollPane.
DBTabbedPanel Data-aware Tabbed Panel implementation.
DBTextArea A data-aware implementation of a java.awt.TextField.
DBTextField A data-aware implementation of java.awt.TextArea.
 

Package com.linxpda.dbaware.awt Description

This package contains a collection of data aware components for use in building applications around the PJODe and PJODe C/S ODBMS systems. All components store their state and values automatically with no user intervention required. They can also be provided additional functionality by the programmer without affecting their data awareness.

The heart of the package is the DBRootPanel which should act as the parent to all other DBAware components. Any number of DBContainer objects can be placed within the DBRootPanel to create complex nested GUIs.

When adding a DBAware component (except DBContainer and DBRadiobox objects) to a DBRootPanel or DBContainer, be sure to call it's setColumnLabel method to establish what value the component will hold. This value need not be meaningful, but should be unique to any other DBAware component within the DBRootPanel. Otherwise, the particular column in question will only contain the value from the last added component with that particular column label. DBContainer objects do not require a column label.

DBRadiobox components are handled a little differently. As multiple components will be used to hold state for only one column, you do not need to set a column label for them. Simply call the setColumnLabel method for the DBRadioGroup that is responsible for them.

Below is an example of a test file that stores email information for clients. This particular example uses the PJODe ODBMS, but could be changed to a client/server PJODe C/S version by changing only a single line of code.

import com.linxpda.dbaware.awt.*;
import java.awt.*;
import java.awt.event.*;

public class DBTest extends Frame {
	
	public static void main(String args[]) {
		if (args.length != 1) {
			System.out.println("USEAGE java DBTest ");
			System.exit(1);
		}
		else {
			new DBTest(args[0]);
		}
	}
	
	private DBRootPanel root;
	
	public DBTest(String filename) {
		try {
			// Setup the DBAware main panel first...
			root = new DBRootPanel();
			root.setFileName(filename);
			GridBagLayout g = new GridBagLayout();
			GridBagConstraints c = new GridBagConstraints();
			c.gridx = 0;
			c.gridy = 0;
			c.insets = new Insets(2, 2, 2, 2);
			c.anchor = c.WEST;
			root.setLayout(g);
			Label label = (Label) root.add(new Label("Name:"));
			g.setConstraints(label, c);
			DBTextField name = (DBTextField) root.add(new DBTextField(15));
			name.setColumnLabel("name");
			c.gridx++;
			c.gridwidth = 2;
			g.setConstraints(name, c);
			label = (Label) root.add(new Label("Email:"));
			c.gridx--;
			c.gridy++;
			c.gridwidth = 1;
			g.setConstraints(label, c);
			DBTextField email = (DBTextField) root.add(new DBTextField(15));
			email.setColumnLabel("email");
			c.gridx++;
			c.gridwidth = 2;
			g.setConstraints(email, c);
			DBRadioGroup group = new DBRadioGroup();
			group.setColumnLabel("friend");
			label = (Label) root.add(new Label("Friend:"));
			c.gridx--;
			c.gridy++;
			c.gridwidth = 1;
			g.setConstraints(label, c);
			DBRadiobox yes = (DBRadiobox) root.add(new DBRadiobox("Yes"));
			group.addRadiobox(yes);
			c.gridx++;
			g.setConstraints(yes, c);
			DBRadiobox no = (DBRadiobox) root.add(new DBRadiobox("No"));
			group.addRadiobox(no);
			c.gridx++;
			g.setConstraints(no, c);
			group.setDefault(yes);
			label = (Label) root.add(new Label("Access:"));
			c.gridx = 0;
			c.gridy++;
			g.setConstraints(label, c);
			DBCheckbox pop3 = (DBCheckbox) root.add(new DBCheckbox("POP3"));
			pop3.setColumnLabel("http");
			c.gridx++;
			g.setConstraints(pop3, c);
			DBCheckbox imap = (DBCheckbox) root.add(new DBCheckbox("IMAP"));
			imap.setColumnLabel("imap");
			c.gridx++;
			g.setConstraints(imap, c);
			label = (Label) root.add(new Label("Notes:"));
			c.gridx = 0;
			c.gridy++;
			g.setConstraints(label, c);
			DBTextArea notes = (DBTextArea) root.add(new DBTextArea(3, 15));
			notes.setColumnLabel("notes");
			c.gridx++;
			c.gridwidth = 2;
			g.setConstraints(notes, c);
			c.gridx = 0;
			c.gridy++;
			c.gridwidth = 1;
			label = (Label) root.add(new Label("State:"));
			g.setConstraints(label, c);
			DBChoice choice = (DBChoice) root.add(new DBChoice());
			choice.setColumnLabel("state");
			choice.add("MD");
			choice.add("NJ");
			choice.add("DE");
			c.gridx++;
			c.gridwidth = 2;
			g.setConstraints(choice, c);
			setLayout(new BorderLayout());
			add(root, BorderLayout.CENTER);
			
			// Now make a navigation panel...
			Panel panel = new Panel(new FlowLayout());
			Button first = (Button) panel.add(new Button("<<"));
			first.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.showFirstEntry();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			Button previous = (Button) panel.add(new Button("<"));
			previous.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.showPreviousEntry();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			Button next = (Button) panel.add(new Button(">"));
			next.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.showNextEntry();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			Button last = (Button) panel.add(new Button(">>"));
			last.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.showLastEntry();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			Button add = (Button) panel.add(new Button("+"));
			add.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.addEntry();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			Button delete = (Button) panel.add(new Button("X"));
			delete.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.deleteEntry();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			Button update = (Button) panel.add(new Button("^"));
			update.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.updateEntry();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			Button clear = (Button) panel.add(new Button("Clear"));
			clear.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.reset();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			Button search = (Button) panel.add(new Button("?"));
			search.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.search();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			add(panel, BorderLayout.SOUTH);
			
			// Connect the database...
			root.connect();
			
			// Pack and display...
			pack();
			addWindowListener(new WindowAdapter() {
				public void windowClosing(WindowEvent e) {
					try {
						setVisible(false);
						root.close();
						dispose();
						System.exit(1);
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			setVisible(true);
		}
		catch(Exception ex) {
			ex.printStackTrace();
			System.exit(1);
		}
	}
	
	public void reportException(Exception ex) {
		ex.printStackTrace();
	}
}

As you can see, with the exception of the setColumnLabel method call requirement, programming a database application using our DBAware package is virtually no different then programming any other GUI interface.