/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford M. Graves, J.Tweedle Mount Allison University: July 2003 File: AddDataFrame.java Description: An internal frame that gives the user the ability to add data to the category. */ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.beans.*; public class AddDataFrame extends JInternalFrame { private CategoryInternalFrame categoryInternalFrame_; // stores the parent internal frame private Category category_; // stores the category to be modified private GMLEditor gmlEdit_; // used to edit the gml private JButton doneButton; // done button: applies the changes made private JButton cancelButton; // cancel button: cancels all changes made private JTabbedPane tabs; // tabs used to display elements (objects, arrows, etc.) private JLabel categoryLabel; // displays category name label private JTextField categoryField;// displays (and allows changes to) category name private Container contentPane; private InputCheck ic; // checks the user's input for special characters private int num_objects; // the new number of objects (original + number added) private String[] objects; // the names of the objects to be checked and added to the category private JPanel objectPanel; // the "objects" tab private JButton addObjectButton;// add button: checks the name and adds the object to the category private JTextArea objectArea; // displays the objects in the category (including new and old ones) private JLabel objectLabel; // displays the "Object Name:" label private JTextField objectField; // used to input the name of the object private JScrollPane objectPane; // wraps "objectArea"; need this to use scrollbars private int num_arrows; // the new number of arrows (original + number added) private int[][] arrDC; // the co/domains of the arrows private String[] arrows; // the names of the arrows to be checked and added to the category private JPanel arrowPanel; // the "arrows" tab private JButton addArrowButton; // add button: checks the name and adds the object to the category private JTable arrowTable; // displays the (names, co/do) arrows in the category (including new and old) private JComboBox domainBox; // drop-down list to pick the domain of the arrow to be added private JComboBox codomainBox; // drop-down list to pick the codomain of the arrow to be added private JLabel arrowLabel; // displays the "Arrow Name:" label private JLabel domainLabel; // displays the "Domain:" label private JLabel codomainLabel; // displays the "Codomain:" label private JTextField arrowField; // used to input the name of the arrow private JScrollPane arrowPane; // wraps "arrowTable"; need this to use scrollbars private int num_relations; // the new number of relations (original + number added) private String[] relations; // the relations to be checked and added to the category private JPanel relationPanel; // the "relations" tab private JButton addRelationButton;// add button: checks the relation and adds it to the category private JLabel relationLabel; // displays the "Relation:" label private JTextField relationField;// used to input the relation private JTextArea relationArea; // displays the relations in the category (including new and old) private JScrollPane relationPane;// wraps "relationArea"; need this to use scrollbars private JPanel commentPanel; // the "comments" tab private JLabel commentLabel; // displays the "Comments:" label private JTextArea commentArea; // displays the comments (including new and old) private JScrollPane commentPane;// wraps "commentArea"; need this to use scrollbars public AddDataFrame(CategoryInternalFrame categoryInternalFrame) /* AddDataFrame constructor: - takes a CategoryInternalFrame - constructs an JInternalFrame, adds it to the CIF's desktop - displays all current category information in appropriate tab - displays all labels, buttons, text fields for user - allows user to add objects, arrows, relations and comments to the category - allows user to change the name of the category - allows user to discard changes by clicking "Cancel" - allows user to apply changes by clicking "Done" - uses InputCheck.java (for name checking purposes) and GMLEditor.java (for adding the specified elements to the GML) */ { super("Add Data to Category", // call to the constructor of JInternalFrame true, //resizable true, //closable false, //maximizable false);//iconifiable categoryInternalFrame_ = categoryInternalFrame; // store the parent internal frame category_ = categoryInternalFrame_.getCategory(); // store the category to be modified num_objects = category_.num_objects; // set num_objects to be the original number of objects objects = category_.obj; // set objects to be the original objects num_arrows = category_.num_arrows; // set num_arrows to be the original number of arrows arrows = category_.arrow; // set arrows to be the original arrows arrDC = category_.arr; // set arrDC to be the original co/domains num_relations = category_.num_relations; // set num_relations to be the original number of relations relations = new String[category_.ini.getRELLEN()]; // relations that will be added gmlEdit_ = new GMLEditor(); // used to add the new elements to the category's GML ic = new InputCheck(); // used to check the names of the new elements /* construct tabs and category name/label/textfield/buttons */ contentPane = getContentPane(); tabs = new JTabbedPane(JTabbedPane.TOP); categoryLabel = new JLabel("Category Name:"); categoryField = new JTextField(category_.name); doneButton = new JButton("Done"); doneButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doneButton_actionPerformed(e); } }); cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancelButton_actionPerformed(e); } }); /* end constructing tabs and category information */ /* construct all GUI objects in "arrow" tab */ arrowLabel = new JLabel("Arrow(s):"); domainLabel = new JLabel("Domain:"); codomainLabel = new JLabel("Codomain:"); arrowField = new JTextField(15); addArrowButton = new JButton("Add Arrow"); addArrowButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { addArrowButton_actionPerformed(e); } }); domainBox = new JComboBox(); codomainBox = new JComboBox(); domainBox.setEditable(false); codomainBox.setEditable(false); domainBox.setBackground(Color.white); codomainBox.setBackground(Color.white); String[][] data = new String[50][3]; for (int i=0; i<50; i++) { for (int j=0; j<3; j++) { if (i < num_arrows) { data[i][0] = arrows[i]; data[i][1] = objects[arrDC[i][0]]; data[i][2] = objects[arrDC[i][1]]; } else data[i][0] = data[i][1] = data[i][2] = ""; } } String[] columnNames = {"Arrow Name", "Domain of Arrow", "Codomain of Arrow"}; arrowTable = new JTable(data, columnNames); arrowPane = new JScrollPane(arrowTable); arrowPane.setBorder(BorderFactory.createEtchedBorder()); /* end constructing GUI objects for "arrows" tab */ /* construct GUI objects for "objects" tab */ objectLabel = new JLabel("Object(s):"); objectField = new JTextField(15); addObjectButton = new JButton("Add Object"); addObjectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { addObjectButton_actionPerformed(e); } }); objectArea = new JTextArea(); objectArea.setWrapStyleWord(true); objectArea.setEditable(false); for (int i=0; i