/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: EndomorphismFrame.java Description: This file is displayed when the user selects the "Endomorphism Limit". It allows the user to select a new maximum order of endomorphism to replace the default of 2 */ //import statements import java.awt.*; import java.awt.event.*; public class EndomorphismFrame extends Frame { Category c = new Category(); CategoryList l = new CategoryList(); int check_enter = 0; //Objects in the Graphical User Interface(GUI) Button exit = new Button(); Panel button_panel = new Panel(); BorderLayout borderLayout1 = new BorderLayout(); Button okButton = new Button(); Button cancelButton = new Button(); CheckboxGroup orderGroup = new CheckboxGroup(); Checkbox orderOne = new Checkbox("Order 10", orderGroup, false); Checkbox orderOther = new Checkbox("Order = ", orderGroup, false); Checkbox orderTwo = new Checkbox("Order 20", orderGroup, false); Checkbox orderThree = new Checkbox("Order 30", orderGroup, false); TextField orderField = new TextField(); MainWindow ed; Checkbox orderFour = new Checkbox("Order 40", orderGroup, false); Checkbox orderFive = new Checkbox("Order 50", orderGroup, false); Label label1 = new Label(); Label label2 = new Label(); Label titleLabel = new Label(); GridBagLayout gridBagLayout1 = new GridBagLayout(); GBConstraintsEditor g = new GBConstraintsEditor(); public EndomorphismFrame(MainWindow edit) //Default Constructor with the list of categories as a parameter { ed = edit; ed.enableMenus(false); try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } public boolean handleEvent(Event e) { if (e.id == Event.WINDOW_DESTROY) { ed.enableMenus(true); hide(); //hide frame dispose(); //free resources return true; } else if (e.key == Event.ENTER) { if (check_enter == 0) check_enter++; else { ed.enableMenus(true); hide(); //hide frame dispose(); //free resources } return true; } else if (e.target instanceof Choice) { return (true); } else return super.handleEvent(e); } public boolean action(Event e, Object o) { if ((e.target == exit) || (e.key == Event.ENTER)) { ed.enableMenus(true); hide(); //hide frame dispose(); //free resources return true; } return false; } private void jbInit() throws Exception //This function intializes the GUI { this.setTitle("GDCT: Endomorphism Order"); this.setBackground(new Color(192,192,192)); this.setSize(new Dimension(260, 300)); okButton.setLabel("OK"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { okButton_actionPerformed(e); } }); cancelButton.setLabel("Cancel"); orderField.setBackground(Color.white); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { cancelButton_actionPerformed(e); } }); label1.setText("Current Order: " + ed.ini.getMaxLoop()); label2.setText("New Order:"); titleLabel.setText("Max Order of Endomorphism:"); this.setLayout(gridBagLayout1); this.add(okButton, g.getConstraints(0, 8, 2, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(22, 10, 12, 0), 69, 8)); this.add(cancelButton, g.getConstraints(2, 8, 5, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(22, 15, 12, 13), 53, 8)); this.add(titleLabel, g.getConstraints(0, 0, 5, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 10, 0, 0), 0, 0)); this.add(label1, g.getConstraints(0, 1, 5, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 84, 0)); this.add(label2, g.getConstraints(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 10, 0, 0), 0, 0)); this.add(orderOne, g.getConstraints(1, 2, 3, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); this.add(orderTwo, g.getConstraints(1, 3, 3, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); this.add(orderThree, g.getConstraints(1, 4, 3, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); this.add(orderFour, g.getConstraints(1, 5, 3, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); this.add(orderFive, g.getConstraints(1, 6, 3, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); this.add(orderOther, g.getConstraints(1, 7, 2, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), -9, 0)); this.add(orderField, g.getConstraints(3, 7, 3, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 14, 0)); selectTrueBox(); } void selectTrueBox() //Determines which check box is true when window is opened { if (ed.ini.getMaxLoop() == 10) orderGroup.setSelectedCheckbox(orderOne); else if (ed.ini.getMaxLoop() == 20) orderGroup.setSelectedCheckbox(orderTwo); else if (ed.ini.getMaxLoop() == 30) orderGroup.setSelectedCheckbox(orderThree); else if (ed.ini.getMaxLoop() == 40) orderGroup.setSelectedCheckbox(orderFour); else if (ed.ini.getMaxLoop() == 50) orderGroup.setSelectedCheckbox(orderFive); else { orderGroup.setSelectedCheckbox(orderOther); orderField.setText("" + ed.ini.getMaxLoop()); } } void okButton_actionPerformed(ActionEvent e) //Function called when OK button is pressed { Checkbox selected = orderGroup.getCurrent(); String label = selected.getLabel(); if(label.equals("Order 10")) ed.ini.setMaxLoop(10); else if(label.equals("Order 20")) ed.ini.setMaxLoop(20); else if(label.equals("Order 30")) ed.ini.setMaxLoop(30); else if(label.equals("Order 40")) ed.ini.setMaxLoop(40); else if(label.equals("Order 50")) ed.ini.setMaxLoop(50); else { try { ed.ini.setMaxLoop(Integer.parseInt(orderField.getText())); } catch (NumberFormatException e1) { new MessageDialog(this, "Error", "Endomorphism value must be an integer", true); } } ed.enableMenus(true); hide(); dispose(); } void cancelButton_actionPerformed(ActionEvent e) { ed.enableMenus(true); hide(); dispose(); } }