/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford M. Graves, J. Tweedle Mount Allison University 2001 Updated: May 8th, 2003 File: CoequalizerFrame.java Description: This class implements a frame which allows the user to run the category tool "Coequalizer" on the current category; the methods to check Coequalizers were removed and put into a separate class; now they can be accessed by constructing a Coequalizer object and calling the check methods, then calling the getOutput() method to display messages. Also, the obselete Borland libraries were removed. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.beans.*; public class CoequalizerFrame extends JInternalFrame { private JLabel coequalizerPathLabel; private JLabel coequalizerObjectLabel; private JLabel alphaLabel; private JLabel betaLabel; private JButton coequalizerButton; private JButton closeButton; private JComboBox coequalizerChoice; private JTextField alphaPath; private JTextField betaPath; private JTextField coequalizerPath; private JScrollPane areaScrollPane; private JRadioButton pathsButton; private JRadioButton objectsButton; private ButtonGroup pathObjectGroup; private CategoryInternalFrame categoryInternalFrame_; private Category cat; private Equalizer coeq;; public CoequalizerFrame(CategoryInternalFrame categoryInternalFrame) { super(categoryInternalFrame.getTitle() + ": Coequalizer Tool", true, true, false, false); categoryInternalFrame_ = categoryInternalFrame; cat = categoryInternalFrame_.getCategory().makeDual(); coeq = new Equalizer(cat, "coequalizer"); try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { pathsButton = new JRadioButton(); pathsButton.setSelected(true); pathsButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { pathsButton_action(); } }); objectsButton = new JRadioButton(); objectsButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { objectsButton_action(); } }); pathObjectGroup = new ButtonGroup(); pathObjectGroup.add(pathsButton); pathObjectGroup.add(objectsButton); coequalizerButton = new JButton("Coequalizer?"); coequalizerButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { coequalizerButton_actionPerformed(e); } }); closeButton = new JButton("Close"); closeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { closeButton_actionPerformed(e); } }); alphaLabel = new JLabel("First path:"); alphaPath = new JTextField(15); alphaPath.setBorder(BorderFactory.createEtchedBorder()); betaLabel = new JLabel("Second path:"); betaPath = new JTextField(15); betaPath.setBorder(BorderFactory.createEtchedBorder()); coequalizerObjectLabel = new JLabel("Coequalizer object:"); coequalizerObjectLabel.setEnabled(false); coequalizerPathLabel = new JLabel("Coequalizer path:"); coequalizerPath = new JTextField(15); coequalizerChoice = new JComboBox(); coequalizerChoice.setBackground(Color.white); coequalizerChoice.addItem("Check all objects"); for (int i = 0; i < cat.num_objects; i++) coequalizerChoice.addItem(cat.obj[i]); coequalizerChoice.setSelectedIndex(0); coequalizerChoice.setEnabled(false); Container contentPane = getContentPane(); contentPane.setLayout(new GridBagLayout()); contentPane.add(coequalizerButton, new GridBagConstraints(0, 4, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(closeButton, new GridBagConstraints(1, 4, 2, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(alphaPath, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(betaPath, new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(alphaLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(betaLabel, new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(pathsButton, new GridBagConstraints(1, 0, 1, 2, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(coequalizerPathLabel, new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(coequalizerPath, new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(objectsButton, new GridBagConstraints(1, 2, 1, 2, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(coequalizerObjectLabel, new GridBagConstraints(2, 2, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(coequalizerChoice, new GridBagConstraints(2, 3, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); } private void coequalizerButton_actionPerformed(ActionEvent e) { int alpha[] = new int[cat.ini.getMAXWORD()]; int beta[] = new int[cat.ini.getMAXWORD()]; int coequalizer[] = new int[cat.ini.getMAXWORD()]; coeq.setEndoPassed(false); coeq.setOutput(""); if (pathsButton.isSelected() && (coequalizerPath.getText().length() == 0 || !cat.check_string(coequalizerPath.getText()))) { JOptionPane.showInternalMessageDialog(this, "Invalid coequalizer path.", "Error", JOptionPane.ERROR_MESSAGE); return; } if (alphaPath.getText().length() == 0 || !cat.check_string(alphaPath.getText())) { JOptionPane.showInternalMessageDialog(this, "Invalid second path.", "Error", JOptionPane.ERROR_MESSAGE); return; } if (betaPath.getText().length() == 0 || !cat.check_string(betaPath.getText())) { JOptionPane.showInternalMessageDialog(this, "Invalid first path.", "Error", JOptionPane.ERROR_MESSAGE); return; } alpha = cat.string_to_path(alphaPath.getText()); beta = cat.string_to_path(betaPath.getText()); coequalizer = cat.string_to_path(coequalizerPath.getText()); if (alpha[0] < 0 && beta[0] < 0) { JOptionPane.showInternalMessageDialog(this, "Cannot check two identity paths on an unknown object.", "Error", JOptionPane.ERROR_MESSAGE); return; } else if (alpha[0] < 0 && cat.arr[beta[cat.path_len(beta)-1]][0] != cat.arr[beta[0]][1]) { JOptionPane.showInternalMessageDialog(this, "Since alpha is an identity map, beta must have the same domain and codomain.", "Error", JOptionPane.ERROR_MESSAGE); return; } else if (beta[0] < 0 && cat.arr[alpha[cat.path_len(alpha)-1]][0] != cat.arr[alpha[0]][1]) { JOptionPane.showInternalMessageDialog(this, "Since beta is an identity map, alpha must have the same domain and codomain.", "Error", JOptionPane.ERROR_MESSAGE); return; } if (alpha[0] > 0 && beta[0] > 0) { if (cat.arr[alpha[0]][0] != cat.arr[beta[0]][0]) { JOptionPane.showInternalMessageDialog(this, "The two paths must have the same codomain.", "Error", JOptionPane.ERROR_MESSAGE); return; } else if (cat.arr[alpha[cat.path_len(alpha)-1]][1] != cat.arr[beta[cat.path_len(beta)-1]][1]) { JOptionPane.showInternalMessageDialog(this, "The two paths must have the same domain.", "Error", JOptionPane.ERROR_MESSAGE); return; } else if (pathsButton.isSelected() && coequalizer[0] != -2 && cat.arr[alpha[0]][0] != cat.arr[coequalizer[0]][1]) { //System.out.println("alpha: " + cat.obj[cat.arr[alpha[0]][0]]); //System.out.println("eq: " + cat.obj[cat.arr[coequalizer[0]][1]]); JOptionPane.showInternalMessageDialog(this, "The domain of the coequalizer path must be equal to the codomain of the two paths.", "Error", JOptionPane.ERROR_MESSAGE); return; } } if (alpha[0] < 0) { int[] bob = beta; beta = alpha; alpha = bob; } // reverse the paths and perform the equalizer algorithm String viewbox = ""; alpha = cat.reverse_path(alpha); beta = cat.reverse_path(beta); coequalizer = cat.reverse_path(coequalizer); //System.out.println(coequalizer[0]); if (cat.equals(cat.reduce(alpha), cat.reduce(beta)) && (objectsButton.isSelected() || coequalizer[0] == -2)) { viewbox+="1 is a coequalizer.\n1 coequalizer found."; } else if (objectsButton.isSelected()) { for (int i=0; i