/* 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: EqualizerFrame.java Description: This class implements a frame which allows the user to run the category tool "Equalizer" on the current category. The algorithms used to perform the equalizer check on the category were removed and put in the file Equalizer.java. The obselete Borland libraries were also removed. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.beans.*; public class EqualizerFrame extends JInternalFrame { JLabel equalizerPathLabel; JLabel equalizerObjectLabel; JLabel alphaLabel; JLabel betaLabel; JButton equalizerButton; JButton closeButton; JComboBox equalizerChoice; // JTextArea viewbox; JTextField alphaPath; JTextField betaPath; JTextField equalizerPath; // JScrollPane areaScrollPane; JRadioButton pathsButton; JRadioButton objectsButton; ButtonGroup pathObjectGroup; CategoryInternalFrame categoryInternalFrame_; Category cat; Equalizer coeq; public EqualizerFrame(CategoryInternalFrame categoryInternalFrame) { super(categoryInternalFrame.getTitle() + ": Equalizer Tool", true, true, false, false); categoryInternalFrame_ = categoryInternalFrame; cat = new Category(); cat.copyCategory(categoryInternalFrame_.getCategory()); coeq = new Equalizer(cat, "equalizer"); 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); equalizerButton = new JButton("Equalizer?"); equalizerButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { equalizerButton_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()); equalizerObjectLabel = new JLabel("Equalizer object:"); equalizerObjectLabel.setEnabled(false); equalizerPathLabel = new JLabel("Equalizer path:"); equalizerPath = new JTextField(15); equalizerChoice = new JComboBox(); equalizerChoice.setBackground(Color.white); equalizerChoice.addItem("Check all objects"); for (int i = 0; i < cat.num_objects; i++) equalizerChoice.addItem(cat.obj[i]); equalizerChoice.setSelectedIndex(0); equalizerChoice.setEnabled(false); // viewbox = new JTextArea("", 3, 3); // viewbox.setEditable(false); // viewbox.setBackground(Color.white); // areaScrollPane = new JScrollPane(viewbox); // areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); // areaScrollPane.setBorder(BorderFactory.createEtchedBorder()); Container contentPane = getContentPane(); contentPane.setLayout(new GridBagLayout()); contentPane.add(equalizerButton, 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(equalizerPathLabel, new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(equalizerPath, 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(equalizerObjectLabel, new GridBagConstraints(2, 2, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); contentPane.add(equalizerChoice, new GridBagConstraints(2, 3, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); } private void equalizerButton_actionPerformed(ActionEvent e) { String viewbox = ""; int alpha[] = new int[cat.ini.getMAXWORD()]; int beta[] = new int[cat.ini.getMAXWORD()]; int equalizer[] = new int[cat.ini.getMAXWORD()]; coeq.setEndoPassed(false); coeq.setOutput(""); if (pathsButton.isSelected() && (equalizerPath.getText().length() == 0 || !cat.check_string(equalizerPath.getText()))) { JOptionPane.showInternalMessageDialog(this, "Invalid equalizer 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()); equalizer = cat.string_to_path(equalizerPath.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]][1] != cat.arr[beta[0]][1]) { 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]][0] != cat.arr[beta[cat.path_len(beta)-1]][0]) { JOptionPane.showInternalMessageDialog(this, "The two paths must have the same domain.", "Error", JOptionPane.ERROR_MESSAGE); return; } else if (pathsButton.isSelected() && cat.arr[alpha[cat.path_len(alpha)-1]][0] != cat.arr[equalizer[0]][1]) { JOptionPane.showInternalMessageDialog(this, "The domain of the equalizer 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 alpha = cat.reverse_path(alpha); beta = cat.reverse_path(beta); equalizer = cat.reverse_path(equalizer); if (objectsButton.isSelected()) { for (int i=0; i