/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Matt Graves, Jesse Tweedle Mount Allison University 2003 File: CreateCategoryDialog.java Description: Displays an internal frame to prompt the user for new category information. Then stores the information in a new category and somehow sends it back to the calling program. */ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.beans.*; public class CreateCategoryDialog extends JInternalFrame { //--------- GUI Objects for DialogBox ------------------------------------------ private Category category_; // private String category_gml; private JButton doneButton; private JButton cancelButton; private JTabbedPane tabs; private JLabel categoryLabel; private JTextField categoryField; private IniSettings ini; private Container contentPane; private boolean newCategoryCreated; private InputCheck ic; //------------------------------------------------------------------------------ //--------- GUI Objects for "Objects" Tab -------------------------------------- private int num_objects; private String[] objects; private JPanel objectPanel; private JButton addObjectButton; private JTable objectTable; private JLabel objectLabel; private JTextField objectField; private JScrollPane objectPane; //------------------------------------------------------------------------------ //--------- GUI Objects for "Arrows" Tab --------------------------------------- private int num_arrows; private int[][] arrDC; private String[] arrows; private JPanel arrowPanel; private JButton addArrowButton; private JTable arrowTable; private JComboBox domainBox; private JComboBox codomainBox; private JLabel arrowLabel; private JLabel domainLabel; private JLabel codomainLabel; private JTextField arrowField; private JScrollPane arrowPane; //------------------------------------------------------------------------------ //--------- GUI Objects for "Relations" Tab ------------------------------------ private int num_relations; private String[] relations; private JPanel relationPanel; private JButton addRelationButton; private JLabel relationLabel; private JTextField relationField; private JTextArea relationArea; private JScrollPane relationPane; //------------------------------------------------------------------------------ //--------- GUI Objects for "Comments" Tab ------------------------------------- private JPanel commentPanel; private JLabel commentLabel; private JTextArea commentArea; private JScrollPane commentPane; //------------------------------------------------------------------------------ public CreateCategoryDialog(IniSettings ini2) { super("Create Category", true, //resizable true, //closable false, //maximizable false);//iconifiable setPreferredSize(new Dimension(480, 320)); // -- temporary storage of category information -- ini = ini2; category_ = new Category(); // category_gml = "graph [\ndirected 1\n]\n"; objects = new String[ini.getMAXWORD()]; arrows = new String[ini.getMAXARR()]; arrDC = new int[ini.getMAXARR()][ini.getMAXARR()]; relations = new String[ini.getRELLEN()]; newCategoryCreated = false; ic = new InputCheck(); // ----------------------------------------------- //--------- Initialize GUI Objects for CreateCategoryDialog -------------------- contentPane = getContentPane(); tabs = new JTabbedPane(JTabbedPane.TOP); categoryLabel = new JLabel("Category Name:"); categoryField = new JTextField(15); doneButton = new JButton("Create Category"); 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 initialization of CreateCategoryDialog -------------------- //--------- Initialize GUI Objects for "Objects" tab --------------------------- //----------- Initialize Button/Label Information 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); } }); //---------------------------------------------------------------------------- //-------------- Initialize Table Information for "Objects" tab --------------- objectTable = new JTable(10, 5); objectPane = new JScrollPane(objectTable); objectPane.setBorder(BorderFactory.createEtchedBorder()); //---------------------------------------------------------------------------- //-------------- End initialization of "Objects" tab --------------------------- //--------- Initialize GUI Objects for "Arrows" tab --------------------------- //----------- Initialize Button/Label Information for "Arrows" 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); } }); //---------------------------------------------------------------------------- //-------------- Initialize ComboBox Information for "Arrows" tab ------------ domainBox = new JComboBox(); codomainBox = new JComboBox(); domainBox.setEditable(false); codomainBox.setEditable(false); domainBox.setBackground(Color.white); codomainBox.setBackground(Color.white); //---------------------------------------------------------------------------- //-------------- Initialize Table Information for "Arrows" tab --------------- String[][] data = new String[50][3]; for (int i=0; i<50; i++) { for (int j=0; j<3; j++) data[i][j] = ""; } String[] columnNames = {"Arrow Name", "Domain of Arrow", "Codomain of Arrow"}; arrowTable = new JTable(data, columnNames); arrowPane = new JScrollPane(arrowTable); arrowPane.setBorder(BorderFactory.createEtchedBorder()); //---------------------------------------------------------------------------- //-------------- End initialization of "Arrows" tab ---------------------------- //--------- Initialize GUI Objects for "Relations" tab ------------------------- //----------- Initialize Button/Label Information for "Relations" tab -------- relationLabel = new JLabel("Relation(s):"); relationField = new JTextField(15); addRelationButton = new JButton("Add Relation"); addRelationButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { addRelationButton_actionPerformed(e); } }); //---------------------------------------------------------------------------- //-------------- Initialize TextArea Information for "Relations" tab --------- relationArea = new JTextArea(5, 5); relationPane = new JScrollPane(relationArea); relationPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); relationArea.setLineWrap(true); relationArea.setWrapStyleWord(true); relationArea.setEditable(false); relationPane.setBorder(BorderFactory.createEtchedBorder()); //---------------------------------------------------------------------------- //-------------- End initialization of "Relations" tab ------------------------- //--------- Initialize GUI Objects for "Comments" tab -------------------------- //----------- Initialize Button/Label Information for "Comments" tab --------- commentLabel = new JLabel("Comment(s):"); //---------------------------------------------------------------------------- //-------------- Initialize TextArea Information for "Comments" tab ---------- commentArea = new JTextArea(5, 5); commentPane = new JScrollPane(commentArea); commentPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); commentArea.setLineWrap(true); commentArea.setWrapStyleWord(true); commentPane.setBorder(BorderFactory.createEtchedBorder()); //---------------------------------------------------------------------------- //-------------- End initialization of "Comments" tab -------------------------- //--------- Layout information for "Objects" tab ------------------------------- objectPanel = new JPanel(new GridBagLayout()); objectPanel.add(objectLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.1 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); objectPanel.add(objectField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.1 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(3, 3, 3, 3), 0, 0)); objectPanel.add(addObjectButton, new GridBagConstraints(2, 0, 1, 1, 1.0, 0.1 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); objectPanel.add(objectPane, new GridBagConstraints(0, 1, 10, 10, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 3, 3, 3), 0, 0)); //-------------- End layout of "Objects" tab ----------------------------------- //--------- Layout information for "Arrows" tab -------------------------------- arrowPanel = new JPanel(new GridBagLayout()); // -- First Row -- // arrowPanel.add(arrowLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); arrowPanel.add(domainLabel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); arrowPanel.add(codomainLabel, new GridBagConstraints(2, 0, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); // -- Second Row -- // arrowPanel.add(arrowField, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(3, 3, 3, 3), 0, 0)); arrowPanel.add(domainBox, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(3, 3, 3, 3), 0, 0)); arrowPanel.add(codomainBox, new GridBagConstraints(2, 1, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(3, 3, 3, 3), 0, 0)); // -- Third Row -- // arrowPanel.add(addArrowButton, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); // -- Fourth Row -- // arrowPanel.add(arrowPane, new GridBagConstraints(0, 3, 10, 10, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 3, 3, 3), 0, 0)); //-------------- End layout of "Arrows" tab ------------------------------------ //--------- Layout information for "Relations" tab ----------------------------- relationPanel = new JPanel(new GridBagLayout()); relationPanel.add(relationLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); relationPanel.add(relationField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(3, 3, 3, 3), 0, 0)); relationPanel.add(addRelationButton, new GridBagConstraints(2, 0, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(3, 3, 3, 3), 0, 0)); relationPanel.add(relationPane, new GridBagConstraints(0, 1, 3, 3, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 3, 3, 3), 0, 0)); //-------------- End layout of "Relations" tab --------------------------------- //--------- Layout information for "Comments" tab ------------------------------ commentPanel = new JPanel(new BorderLayout()); commentPanel.add(commentLabel, BorderLayout.NORTH); commentPanel.add(commentPane, BorderLayout.CENTER); //-------------- End layout of "Comments" tab ---------------------------------- //--------- Layout information for CreateCategoryDialog ------------------------ tabs.add(objectPanel, "Objects"); tabs.add(arrowPanel, "Arrows"); tabs.add(relationPanel, "Relations"); tabs.add(commentPanel, "Comments"); contentPane.setLayout(new GridBagLayout()); // -- Tabs -- // contentPane.add(tabs, new GridBagConstraints(0, 0, 10, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(3, 3, 3, 3), 0, 0)); // -- Category Name/Field/Button Info -- // contentPane.add(categoryLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 3, 3, 3), 0, 0)); contentPane.add(categoryField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(7, 7, 7, 7), 0, 0)); contentPane.add(doneButton, new GridBagConstraints(2, 1, 1, 1, 0.5, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(7, 7, 7, 7), 0, 0)); contentPane.add(cancelButton, new GridBagConstraints(3, 1, 1, 1, 0.5, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(7, 7, 7, 7), 0, 0)); //-------------- End layout of CreateCategoryDialog ---------------------------- } // ------- End of CreateCategoryDialog constructor ------------------------ private void addObjectButton_actionPerformed(ActionEvent e) { String objectName = objectField.getText(); // check object name for other stuff if (ic.check(objectName)) { objects[num_objects++] = objectName; int row = (int)num_objects/(objectTable.getColumnCount()+1); int column = (int)(num_objects-row)%objectTable.getColumnCount(); // add object to table objectTable.setValueAt(objectName, row, column); // add object to do/codomain combo boxes domainBox.addItem(objectName); codomainBox.addItem(objectName); objectField.setText(""); } } private void addArrowButton_actionPerformed(ActionEvent e) { String arrowName = arrowField.getText(); int domainIndex = domainBox.getSelectedIndex(); int codomainIndex = codomainBox.getSelectedIndex(); // check arrow name/do/codomain for other stuff if (ic.check(arrowName)) { arrows[num_arrows] = arrowName; arrDC[num_arrows][0] = domainIndex; arrDC[num_arrows][1] = codomainIndex; arrowTable.setValueAt(arrowName, num_arrows, 0); arrowTable.setValueAt((String)domainBox.getSelectedItem(), num_arrows, 1); arrowTable.setValueAt((String)codomainBox.getSelectedItem(), num_arrows++, 2); arrowField.setText(""); } } private void addRelationButton_actionPerformed(ActionEvent e) { String relationName = relationField.getText(); if (category_.get_rel(relationName) == null) { relations[num_relations++] = relationName; relationArea.append(relationName + "\n"); relationField.setText(""); } else JOptionPane.showInternalMessageDialog(this.getDesktopPane(), relationName + " is not a valid relation.", "Error", JOptionPane.ERROR_MESSAGE); } private void cancelButton_actionPerformed(ActionEvent e) { try {this.setClosed(true);} catch (PropertyVetoException PVE) {} } private void doneButton_actionPerformed(ActionEvent e) { String name = categoryField.getText(); // add all other stuff to new category with cat.name = name if (ic.check(name)) { category_.name = name; setObjects(); setArrows(); setRelations(); setComments(); category_.setGML(); category_.mod.isCreated(); ((MainWindow2)getDesktopPane().getParent().getParent().getParent()).createCategoryInternalFrame(category_); try {this.setClosed(true);} catch (PropertyVetoException PVE) {} } } private void setObjects() { category_.obj = objects; category_.num_objects = num_objects; } private void setArrows() { category_.arrow = arrows; category_.arr = arrDC; category_.num_arrows = num_arrows; } private void setRelations() { Relation[] relations_ = new Relation[num_relations]; for (int i=0; i