/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: AddDataFrame.java Description: This file is displayed when the user selects the "Add Object", "Add Arrow", or "Add Relation" menu option in the main window. It displays a list of objects in categories that are presently in memory. The user can select a category file(*.CAT) and chose add an object, arrow, or relation. */ //import statements import java.awt.*; import java.awt.event.*; public class AddDataFrame extends Frame { Category cat; 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(); Label label2 = new Label(); TextField categoryField = new TextField(); MainWindow edit; TextArea statusArea = new TextArea("", 10, 10, TextArea.SCROLLBARS_VERTICAL_ONLY); Label label1 = new Label(); TextField dataInputField = new TextField(); Label dataInputLabel = new Label(); Button doneButton = new Button(); int submenu = 1; String temp = new String(); //String that contains the new //relations added to the category String newRelations = new String(); GridBagLayout gridBagLayout1 = new GridBagLayout(); GBConstraintsEditor g = new GBConstraintsEditor(); public AddDataFrame(MainWindow ed) //Default Constructor with the list of categories as a parameter { edit = ed; cat = ed.cat; edit.enableMenus(false); try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } public boolean handleEvent(Event e) { if ((e.id == Event.WINDOW_DESTROY)) { edit.enableMenus(true); hide(); //hide frame dispose(); //free resources return true; } return super.handleEvent(e); } public boolean action(Event e, Object o) { if (e.target == exit) { edit.enableMenus(true); hide(); //hide frame dispose(); //free resources return true; } else if (e.key == Event.ENTER) { //okButton.requestFocus(); return(true); } return false; } private void jbInit() throws Exception //This function intializes the GUI { this.setTitle("GDCT: Add Data to Category"); this.setBackground(new Color(192,192,192)); label2.setText("Current Category:"); this.setLayout(gridBagLayout1); categoryField.setBackground(Color.white); this.add(statusArea, g.getConstraints(0, 4, 4, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(7, 8, 14, 16), 229, -54)); this.add(label1, g.getConstraints(0, 3, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(15, 8, 0, 0), 14, -2)); this.add(doneButton, g.getConstraints(3, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 6, 0, 15), 55, 7)); this.add(dataInputField, g.getConstraints(3, 1, 1, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(11, 0, 0, 18), 143, 0)); this.add(dataInputLabel, g.getConstraints(0, 1, 3, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(11, 8, 0, 0), 58, -1)); this.add(categoryField, g.getConstraints(3, 0, 1, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(8, 0, 0, 16), 145, 0)); this.add(label2, g.getConstraints(0, 0, 2, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 8, 0, 0), 0, -6)); cat = edit.cat; categoryField.setEditable(false); categoryField.setText(cat.name); doneButton.setLabel("Done"); doneButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { doneButton_actionPerformed(e); } }); label1.setText("Add Status:"); //Initialize Input GUI submenu = 1; dataInputLabel.setText("Object Name:"); dataInputLabel.validate(); doneButton.setLabel("Objects Complete"); doneButton.validate(); doneButton.setVisible(true); dataInputField.setVisible(true); dataInputLabel.setVisible(true); dataInputField.requestFocus(); } void end() //This function is called when program is //terminated { edit.enableMenus(true); edit.catList.replaceNode(cat); edit.cat = cat; //Clear graphical display HERE edit.displayCategoryText(edit.cat); //edit.GraphCategory(edit.graph_, edit.graphCanvas_, edit.cat); hide(); dispose(); } public boolean check_string(String str, Category c) //This function is designed to verify that all arrows in the str are //valid arrows of the category c. For each arrow of the string checks //that it exists in the category c. Returns true if this is the case //and false otherwise. The parameter str is the string to check and the //parameter c is the current category { int i; //for (i=0;i"); dataInputField.setText(""); submenu = 4; dataInputLabel.setText("CoDomain of " + cat.arrow[cat.numarr] + ": "); dataInputLabel.validate(); dataInputField.requestFocus(); } else { new MessageDialog(this, "Error", "Invalid Domain Declaration. Domain " + temp + " Not Found", true); dataInputLabel.setText("Domain of " + cat.arrow[cat.numarr] + ": "); dataInputLabel.validate(); } } else if (submenu == 4) { String temp = dataInputField.getText(); for (int i = 0; i < cat.numobj; i++) { if (cat.obj[i].equals(temp)) { check = 1; cat.arr[cat.numarr][1] = i; } } if (check == 1) { statusArea.append(dataInputField.getText() + "\n"); dataInputField.setText(""); cat.numarr++; //Edit graphical display of category GMLEditor gEdit = new GMLEditor(); gEdit.addArrow(cat); //Display category graphically edit.displayCategoryGraph(cat.gml, edit.graph_); //Display text version of category edit.cat = cat; edit.displayCategoryText(edit.cat); dataInputField.requestFocus(); dataInputLabel.setText("Arrow Name: "); dataInputLabel.validate(); submenu = 2; } else { new MessageDialog(this, "Error", "Invalid CoDomain Declaration. CoDomain " + temp + " Not Found", true); dataInputLabel.setText("CoDomain of " + cat.arrow[cat.numarr] + ": "); dataInputLabel.validate(); } } else if (submenu == 5) { temp = dataInputField.getText(); statusArea.append("Relation: " + temp + " = "); dataInputField.setText(""); submenu = 6; dataInputLabel.setText("RHS of equation :"); dataInputLabel.validate(); dataInputField.requestFocus(); } else if (submenu == 6) { statusArea.append(dataInputField.getText() + "\n"); //Save number of relations in t int t = cat.num_rel; edit.get_rel(temp, dataInputField.getText(), cat); //If a relation was added... if (t < cat.num_rel) { if (newRelations.equals("")) newRelations = temp + " = " + dataInputField.getText(); else newRelations = newRelations + ", " + temp + " = " + dataInputField.getText(); } dataInputField.setText(""); submenu = 5; dataInputLabel.setText("LHS of equation :"); dataInputLabel.validate(); } } public boolean keyDown(Event e, int key) { if (e.key == Event.ENTER) { CatMenuEnter(e); } return (false); } }