/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: RemoveFunctorFrame.java Description: This class displays the dialog that is displayed upon close when a category is found that has not been saved or has been modified since it has last been saved. */ //Import statements import java.awt.*; import java.awt.event.*; public class SaveDialog extends Dialog { //GUI components of SaveDialog Panel panel1 = new Panel(); Label titleLabel = new Label(); Label catName = new Label(); Label fileName = new Label(); Label detailsLabel = new Label(); TextArea detailsArea = new TextArea("", 10, 10, TextArea.SCROLLBARS_VERTICAL_ONLY); TextField catField = new TextField(); TextField fileField = new TextField(); Button saveAsButton = new Button(); Button cancelButton = new Button(); Button saveButton = new Button(); GridBagLayout gridBagLayout1 = new GridBagLayout(); GBConstraintsEditor g = new GBConstraintsEditor(); //Category to save Category cat = new Category(); //Main Window frame to get category //data from MainWindow mw; public SaveDialog(Frame frame, String title, boolean modal) //Constructor that allows user to specify the //parent frame, the title of the frame, and the modal { super(frame, title, modal); enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { //Call init method jbInit(); //Add panel created in init to the current //dialog window add(panel1); pack(); } catch (Exception ex) { ex.printStackTrace(); } } public SaveDialog(Frame frame) //Constructor that allows the user to specify the //parent frame only { //Call constructor that accepts frame, title, //and modal as parameters this(frame, "GDCT: Save on Exit", false); } public SaveDialog(Frame frame, boolean modal) //Constructor that allows user to specify the //parent frame and the modal { //Call constructor that accepts frame, title, //and modal as parameters this(frame, "GDCT: Save on Exit", modal); } public SaveDialog(Frame frame, String title) //Constructor that allows user to specify the parent //frame and the title of the frame { //Call constructor that accepts frame, title, //and modal as parameters this(frame, title, false); } public void setCategory(MainWindow temp) //Set the current category file { mw = temp; cat = mw.cat; //Initialize the category name and the file name fields catField.setText(cat.name); //Initialize the text in the details of modification text area if (cat.mod.createCat == true) { detailsArea.setText("This category was created by the GDCT application and has not been saved."); fileField.setText("no filename"); } else if (cat.mod.functorCat == true) { detailsArea.setText("This category was loaded as part of a functor and has not been saved."); fileField.setText("no filename"); } else if (cat.mod.dualCat == true) { detailsArea.setText("This category was created as a dual category and has not been saved."); fileField.setText("no filename"); } else if (cat.mod.downloadCat == true) { detailsArea.setText("This category was downloaded from a server and has not been saved."); fileField.setText("no filename"); } else fileField.setText(cat.filename); if (cat.mod.dataAdded || cat.mod.dataRemoved || (!cat.gml.equals(cat.originalGml)) || cat.mod.nameChanged || cat.mod.madeConfluent) { detailsArea.append("The following modifications have been made to this category:\n"); if (cat.mod.nameChanged) detailsArea.append("-> Category Name was changed\n"); if (cat.mod.dataAdded) detailsArea.append("-> Data was added\n"); if (cat.mod.dataRemoved) detailsArea.append("-> Data was removed\n"); if (!cat.gml.equals(cat.originalGml)) detailsArea.append("-> Graphical Display was changed\n"); if (cat.mod.madeConfluent) detailsArea.append("-> Relations were added to the category through the Make Confluent tool\n"); } else { detailsArea.append("No additional modifications were made to this category.\n"); } } void jbInit() throws Exception //Init method that is called from the constructor { //Initialize the text in the labels panel1.setSize(new Dimension(408, 304)); titleLabel.setText("A Modified File has been Located. . ."); catName.setText("Category Name:"); fileName.setText("File Name:"); detailsLabel.setText("Details of Modifications:"); //Initialize the labels on the save, save as, and cancel buttons saveAsButton.setLabel("Save As"); saveButton.setLabel("Save"); cancelButton.setLabel("Close"); //Create action listeners for save, save as, and cancel buttons saveAsButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { saveAsButton_actionPerformed(e); } }); saveButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { saveButton_actionPerformed(e); } }); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { cancelButton_actionPerformed(e); } }); //Set Text areas to not editable detailsArea.setBackground(Color.white); detailsArea.setEditable(false); catField.setBackground(Color.white); catField.setEditable(false); fileField.setBackground(Color.white); fileField.setEditable(false); //Set layout of dialog to GridBagLayout panel1.setLayout(gridBagLayout1); //Set Location of GUI Components in Layout panel1.add(titleLabel, g.getConstraints(0, 0, 3, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 7, 0, 0), 27, -6)); panel1.add(catName, g.getConstraints(0, 1, 2, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 7, 0, 0), 46, 3)); panel1.add(fileName, g.getConstraints(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 7, 0, 0), 58, 2)); panel1.add(detailsLabel, g.getConstraints(0, 3, 1, 1, 0.0, 0.0 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(6, 7, 0, 0), -10, -5)); panel1.add(detailsArea, g.getConstraints(1, 4, 3, 1, 1.0, 1.0 ,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(-19, 23, 0, 16), -220, -83)); panel1.add(catField, g.getConstraints(2, 1, 2, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 7, 3, 17), 49, -3)); panel1.add(fileField, g.getConstraints(2, 2, 2, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(7, 6, 8, 17), 209, -3)); panel1.add(saveAsButton, g.getConstraints(1, 5, 2, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(14, 0, 20, 0), 49, 7)); panel1.add(cancelButton, g.getConstraints(3, 5, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(13, 18, 20, 15), 68, 8)); panel1.add(saveButton, g.getConstraints(0, 5, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(14, 7, 21, 0), 66, 6)); } protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { dispose(); } super.processWindowEvent(e); } void saveButton_actionPerformed(ActionEvent e) //Action Listener for Save Button { //Save Category information including current display //of category in file String file = cat.filename; if (file != null) { FileProcessing f = new FileProcessing(file, mw, true, true); if (file.endsWith(".cat")) f.saveCATFile(); else f.saveCGLFile(); mw.addRecentCat(file); //Close Save Dialog Window dispose(); } else new MessageDialog(mw, "Error", "Use Save As to save categories that have never been saved before", true); } void saveAsButton_actionPerformed(ActionEvent e) //Action Listener for Save As Button { //Save Category information including current display //of category in file if (cat.filename.endsWith(".cat")) { FileDialog c = new FileDialog(mw, "Save Category File (CAT)", FileDialog.SAVE); c.setVisible(true); String file = c.getFile(); if (file != null) { file = c.getDirectory() + c.getFile(); FileProcessing f = new FileProcessing(file, mw, true, true); f.saveCATFile(); mw.addRecentCat(file); } } else { FileDialog c = new FileDialog(mw, "Save Category File (CGL)", FileDialog.SAVE); c.setVisible(true); String file = c.getFile(); if (file != null) { file = c.getDirectory() + c.getFile(); FileProcessing f = new FileProcessing(file, mw, true, true); f.saveCGLFile(); mw.addRecentCat(file); } } //Close Save Dialog Window dispose(); } void cancelButton_actionPerformed(ActionEvent e) //Action Listener for Cancel Button { //Close Save Dialog Window dispose(); } }