/* 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: EqualityCompositesFrame.java Description: This class implements a frame that tests paths in a given category for equality. The algorithms that were used to test for equality were removed and put into the EqualityComposites.java file. */ //import statements import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.beans.*; public class EqualityCompositesFrame extends JInternalFrame { Category cat; CategoryInternalFrame categoryInternalFrame_; //Objects in the Graphical User Interface(GUI) JButton equalityButton = new JButton(); JButton closeButton = new JButton(); JLabel path1Label = new JLabel(); JLabel path2Label = new JLabel(); JTextField path1Field = new JTextField(10); JTextField path2Field = new JTextField(10); public EqualityCompositesFrame(CategoryInternalFrame categoryInternalFrame) //Default Constructor with the list of categories as a parameter { super("Equality Composites", true, true, false, false); categoryInternalFrame_ = categoryInternalFrame; cat = categoryInternalFrame_.getCategory(); try {jbInit();} catch (Exception e) {e.printStackTrace();} } private void jbInit() throws Exception //This function intializes the GUI { equalityButton.setText("Equality?"); equalityButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { equalityButton_actionPerformed(e); } }); closeButton.setText("Close"); closeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { closeButton_actionPerformed(e); } }); path1Label.setText("First Path:"); path2Label.setText("Second Path:"); path1Field.setBackground(Color.white); path2Field.setBackground(Color.white); Container contentPane = getContentPane(); contentPane.setLayout(new GridBagLayout()); contentPane.add(equalityButton, new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(closeButton, new GridBagConstraints(1, 2, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(path1Label, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(path2Label, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(path1Field, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(path2Field, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); } private void closeButton_actionPerformed(ActionEvent e) { try {this.setClosed(true);} catch (PropertyVetoException PVE) {PVE.printStackTrace();} } private void equalityButton_actionPerformed(ActionEvent e) //Function called when OK button is pressed. { String result = ""; if (cat.check_string(path1Field.getText()) && cat.check_string(path2Field.getText())) { int[] path1 = cat.string_to_path(path1Field.getText()); int[] path2 = cat.string_to_path(path2Field.getText()); if (cat.check_path(path1) && cat.check_path(path2)) { result+=path1Field.getText() + " and " + path2Field.getText() + " are "; if (!cat.equals(cat.reduce(path1), cat.reduce(path2))) result+="NOT"; result+=" equal."; JOptionPane.showInternalMessageDialog(this, result, "Equality of Composites", JOptionPane.PLAIN_MESSAGE); return; } else { if (!cat.check_path(path1)) result+="Invalid path: " + path1Field.getText(); if (!cat.check_path(path2)) result+="Invalid path: " + path2Field.getText(); } } else { if (!cat.check_string(path1Field.getText())) result+="Invalid string: " + path1Field.getText(); if (!cat.check_string(path2Field.getText())) result+="Invalid string: " + path2Field.getText(); } JOptionPane.showInternalMessageDialog(this, result, "Error", JOptionPane.ERROR_MESSAGE); } }