/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 Updated: May 8th, 2003 (J. Tweedle) File: SumFrame.java Description: This class implements a frame which allows the user to run the category tool "Sum" on the current category. The algorithms used to test the category for sums were removed and put into the file Sum.java */ //import statements import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.beans.*; public class SumFrame extends JInternalFrame { private CategoryInternalFrame categoryInternalFrame_; private Category cat = new Category(); private Sum sum; private int obj; 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 sumButton = new JButton(); //private JTextArea viewbox = new JTextArea("", 10, 15); private JComboBox objectChoice = new JComboBox(); private JTextField alphaField = new JTextField(13); private JTextField betaField = new JTextField(13); //private JScrollPane areaScrollPane; public SumFrame(CategoryInternalFrame categoryInternalFrame) //Default Constructor with the parent frame as a parameter { super(categoryInternalFrame.getTitle() + ": Sum", true, true, false, false); categoryInternalFrame_ = categoryInternalFrame; cat.copyCategory(categoryInternalFrame_.getCategory()); sum = new Sum(cat, "sum"); okButton.setText("Close"); objectLabel.setText("Object of Sum:"); alphaLabel.setText("First injection:"); betaLabel.setText("Second injection:"); objectChoice.setBackground(Color.white); /* viewbox.setEditable(false); viewbox.setBackground(Color.white); viewbox.setLineWrap(true); viewbox.setWrapStyleWord(true);*/ sumButton.setText("Sum?"); alphaField.setBackground(Color.white); betaField.setBackground(Color.white); sumButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { sumButton_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); } }); /* areaScrollPane = new JScrollPane(viewbox); areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); areaScrollPane.setBorder(BorderFactory.createEtchedBorder());*/ Container contentPane = getContentPane(); contentPane.setLayout(new GridBagLayout()); contentPane.add(sumButton, 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 sumButton_actionPerformed(ActionEvent e) //Determine the sum of the current object given //an alpha and beta value { sum.setNumSums(0); sum.setOutput(""); String viewbox = ""; //viewbox.setText(""); sum.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