/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 Updated: May 8th, 2003 File: ProductFrame.java Description: This class implements a frame which allows the user to run the category tool "Product" on the current category. The algorithms used to test the category for products were removed and put into the file Product.java. */ //import statements import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.beans.*; public class ProductFrame extends JInternalFrame { private Category cat = new Category(); private Sum prod; private CategoryInternalFrame categoryInternalFrame_; private String objchr; //Objects in the Graphical User Interface(GUI) private JLabel objectLabel = new JLabel(); private JLabel alphaLabel = new JLabel(); private JLabel betaLabel = new JLabel(); private JButton okButton = new JButton(); private JButton productButton = new JButton(); private JTextField alphaField = new JTextField(13); private JTextField betaField = new JTextField(13); private JComboBox objectChoice = new JComboBox(); public ProductFrame(CategoryInternalFrame categoryInternalFrame) //Default Constructor with the parent frame as a parameter { super(categoryInternalFrame.getTitle() + ": Product Tool", true, true, false, false); categoryInternalFrame_ = categoryInternalFrame; cat = categoryInternalFrame_.getCategory().makeDual(); prod = new Sum(cat, "product"); okButton.setText("Close"); objectLabel.setText("Object of Product:"); alphaLabel.setText("First product:"); betaLabel.setText("Second projection:"); objectChoice.setBackground(Color.white); productButton.setText("Product?"); alphaField.setBackground(Color.white); betaField.setBackground(Color.white); productButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { productButton_actionPerformed(e); } }); objectChoice.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { objectChoice_itemStateChanged(e); } }); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { okButton_actionPerformed(e); } }); Container contentPane = getContentPane(); contentPane.setLayout(new GridBagLayout()); contentPane.add(productButton, new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 3, 3, 3), 0, 0)); contentPane.add(okButton, new GridBagConstraints(1, 3, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 3, 3, 3), 0, 0)); contentPane.add(alphaLabel, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 3, 3, 3), 0, 0)); contentPane.add(betaLabel, new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 3, 3, 3), 0, 0)); contentPane.add(objectLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 3, 3, 3), 0, 0)); contentPane.add(objectChoice, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(3, 3, 3, 3), 0, 0)); contentPane.add(alphaField, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(3, 3, 3, 3), 0, 0)); contentPane.add(betaField, new GridBagConstraints(1, 2, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(3, 3, 3, 3), 0, 0)); objectChoice.addItem("Check all objects"); for (int i = 0; i < cat.num_objects; i++) objectChoice.addItem(cat.obj[i]); objectChoice.setSelectedIndex(1); } private void productButton_actionPerformed(ActionEvent e) //Determine the product of the current object given //an alpha and beta value { String viewbox = ""; prod.setNumSums(0); prod.setOutput(""); prod.setEndoPassed(false); objchr = (String)objectChoice.getSelectedItem(); if (objchr.equals("Check all objects")) { if (!cat.check_obj(alphaField.getText())) { JOptionPane.showInternalMessageDialog(this, alphaField.getText() + " is not an object of " + cat.name + ".\n", "Error", JOptionPane.ERROR_MESSAGE); return; } else if (!cat.check_obj(betaField.getText())) { JOptionPane.showInternalMessageDialog(this, betaField.getText() + " is not an object of " + cat.name + ".\n", "Error", JOptionPane.ERROR_MESSAGE); return; } else { for (int i=0; i