Package com.linxpda.dbaware.swing

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
DBButtonGroup Holds state for multiple DBRadioButton isntances.
DBCheckBox A data-aware version of the javax.swing.JCheckBox.
DBComboBox A data-aware version of the javax.swing.JComboBox.
DBContainer A data-aware implementation of javax.swing.JPanel.
DBList A data-aware implementation of java.awt.List.
DBNumericField A data-aware component that only allows input of number values.
DBPasswordField A data-aware version of javax.swing.JPasswordField.
DBRadioButton A data-aware version of JRadioButton.
DBRootPane Top-most parent for all DBAware components.
DBScrollPane A data-aware version of javax.swing.JScrollPane.
DBSplitPane Data-aware version of javax.swing.JSplitPane.
DBTabbedPane A data-aware version of javax.swing.JTabbedPane.
DBTextArea A data-aware implementation of a java.awt.TextField.
DBTextField A data-aware implementation of javax.swing.JTextArea.
DBToggleButton Data-aware implementation of javax.swing.JToggleButton.
 

Package com.linxpda.dbaware.swing 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 DBRootPane which should act as the parent to all other DBAware components. Any number of DBContainer objects can be placed within the DBRootPane to create complex nested GUIs.

When adding a DBAware component (except DBContainer and DBRadioButton objects) to a DBRootPane 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 DBRootPane. 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.

DBRadioButton 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 each DBRadioButton, but you must specify one for the DBButtonGroup that controls them. Be sure to call the addRadioButton method of DBButtonGroup for each DBRadioButton that should paired together.

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.swing.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class DBTest extends JFrame {
	
	public static void main(String args[]) {
		if (args.length < 1) {
			System.out.println("USEAGE java DBTest  []");
			System.exit(1);
		}
		else if (args.length == 1) {
			new DBTest(args[0], null);
		}
		else {
			new DBTest(args[0], args[1]);
		}		
	}
	
	private DBRootPane root;
	
	public DBTest(String filename, String remote) {
		super("Email test");
		try {
			// Setup the DBAware main panel first...
			root = new DBRootPane();
			root.setFileName(filename);
			if (remote != null)
				root.setRemoteURL(remote);
			
			DBContainer main = new DBContainer();
			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;
			main.setLayout(g);
			JLabel label = (JLabel) main.add(new JLabel("Name:"));
			g.setConstraints(label, c);
			DBTextField name = (DBTextField) main.add(new DBTextField(15));
			name.setColumnLabel("name");
			c.gridx++;
			c.gridwidth = 2;
			g.setConstraints(name, c);
			label = (JLabel) main.add(new JLabel("Email:"));
			c.gridx--;
			c.gridy++;
			c.gridwidth = 1;
			g.setConstraints(label, c);
			DBTextField email = (DBTextField) main.add(new DBTextField(15));
			email.setColumnLabel("email");
			c.gridx++;
			c.gridwidth = 2;
			g.setConstraints(email, c);
			label = (JLabel) main.add(new JLabel("Friend:"));
			c.gridx--;
			c.gridy++;
			c.gridwidth = 1;
			g.setConstraints(label, c);
			DBButtonGroup group = new DBButtonGroup();
			group.setColumnLabel("friend");
			DBRadioButton yes = (DBRadioButton) main.add(new DBRadioButton("Yes"));
			group.addRadioButton(yes);
			c.gridx++;
			g.setConstraints(yes, c);
			DBRadioButton no = (DBRadioButton) main.add(new DBRadioButton("No"));
			group.addRadioButton(no);
			c.gridx++;
			g.setConstraints(no, c);
			group.setDefaultRadioButton(yes);
			label = (JLabel) main.add(new JLabel("Access:"));
			c.gridx = 0;
			c.gridy++;
			c.gridwidth = 1;
			g.setConstraints(label, c);
			DBCheckBox pop3 = (DBCheckBox) main.add(new DBCheckBox("POP3"));
			pop3.setColumnLabel("http");
			c.gridx++;
			g.setConstraints(pop3, c);
			DBCheckBox imap = (DBCheckBox) main.add(new DBCheckBox("IMAP"));
			imap.setColumnLabel("imap");
			c.gridx++;
			g.setConstraints(imap, c);
			label = (JLabel) main.add(new JLabel("Notes:"));
			c.gridx = 0;
			c.gridy++;
			g.setConstraints(label, c);
			DBTextArea notes = new DBTextArea(3, 15);
			DBScrollPane scroll = new DBScrollPane(notes);
			main.add(scroll);
			notes.setColumnLabel("notes");
			c.gridx++;
			c.gridwidth = 2;
			g.setConstraints(scroll, c);
			c.gridx = 0;
			c.gridy++;
			c.gridwidth = 1;
			label = (JLabel) main.add(new JLabel("State:"));
			g.setConstraints(label, c);
			DBComboBox choice = (DBComboBox) main.add(new DBComboBox());
			choice.setColumnLabel("state");
			choice.addItem("MD");
			choice.addItem("NJ");
			choice.addItem("DE");
			c.gridx++;
			c.gridwidth = 2;
			g.setConstraints(choice, c);
			DBTabbedPane tabs = new DBTabbedPane();
			tabs.addTab("Email Info", main);
			DBContainer con1 = new DBContainer();
			DBPasswordField field = (DBPasswordField) con1.add(new DBPasswordField(20));
			field.setColumnLabel("blank");
			tabs.addTab("Password", con1);
			root.setLayout(new BorderLayout());
			root.add(tabs, BorderLayout.CENTER);
			getContentPane().setLayout(new BorderLayout());
			getContentPane().add(root, BorderLayout.CENTER);
			
			// Now make a navigation panel...
			JPanel panel = new JPanel(new FlowLayout());
			JButton first = (JButton) panel.add(new JButton("<<"));
			first.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.showFirstEntry();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			JButton previous = (JButton) panel.add(new JButton("<"));
			previous.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.showPreviousEntry();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			JButton next = (JButton) panel.add(new JButton(">"));
			next.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.showNextEntry();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			JButton last = (JButton) panel.add(new JButton(">>"));
			last.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.showLastEntry();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			JButton add = (JButton) panel.add(new JButton("+"));
			add.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.addEntry();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			JButton delete = (JButton) panel.add(new JButton("X"));
			delete.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.deleteEntry();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			JButton update = (JButton) panel.add(new JButton("^"));
			update.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.updateEntry();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			JButton clear = (JButton) panel.add(new JButton("Clear"));
			clear.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.reset();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			JButton search = (JButton) panel.add(new JButton("?"));
			search.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					try {
						root.search();
					}
					catch(Exception ex) {
						reportException(ex);
					}
				}
			});
			getContentPane().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.