/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: SettingsAnimation.java Description: This class creates a frame that allows the user to change the speed of the auto animate functor as well as allows the user to select the desired color for the highlighted objects and arrows in both category A and category B. */ //import statements import java.awt.*; import java.awt.event.*; public class SettingsAnimation extends Frame { Category c = new Category(); //DefList l = new DefList(); int check_enter = 0; //Objects in the Graphical User Interface(GUI) Button exit = new Button(); MainWindow ed; Button okButton = new Button(); Label label2 = new Label(); TextField animationText = new TextField(); Label ALabel = new Label(); Label BLabel = new Label(); Choice AChoice = new Choice(); Choice BChoice = new Choice(); Button cancelButton = new Button(); Panel panel1 = new Panel(); Label label3 = new Label(); Panel panel2 = new Panel(); Label label1 = new Label(); GridBagLayout gridBagLayout1 = new GridBagLayout(); GridBagLayout gridBagLayout2 = new GridBagLayout(); GridBagLayout gridBagLayout3 = new GridBagLayout(); GBConstraintsEditor g = new GBConstraintsEditor(); public SettingsAnimation(MainWindow edit) //Default Constructor with the parent frame 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; } return super.handleEvent(e); } public boolean action(Event e, Object o) { if ((e.target == exit)) { 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: Functor Animation Settings"); this.setBackground(new Color(192,192,192)); label2.setText("seconds"); ALabel.setText("Category A Color:"); BLabel.setText("Category B Color:"); cancelButton.setLabel("Cancel"); panel1.setBackground(new Color(164, 164, 164)); label3.setText("Auto Animation Speed:"); panel2.setBackground(new Color(164, 164, 164)); label1.setText("Animation Colors:"); panel2.setLayout(gridBagLayout1); panel1.setLayout(gridBagLayout2); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { cancelButton_actionPerformed(e); } }); Font f = ed.objectArea.getFont(); okButton.setLabel("OK"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { okButton_actionPerformed(e); } }); this.setLayout(gridBagLayout3); this.add(okButton, g.getConstraints(1, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(9, 13, 8, 0), 73, 7)); this.add(cancelButton, g.getConstraints(2, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(8, 20, 9, 6), 48, 7)); this.add(panel1, g.getConstraints(0, 0, 1, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 9, 0, 0), -48, 1)); panel1.add(label3, g.getConstraints(0, 0, 3, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 6, 0, 0), 60, 0)); panel1.add(animationText, g.getConstraints(0, 1, 1, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(14, 17, 27, 0), 43, 2)); panel1.add(label2, g.getConstraints(1, 1, 2, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(13, 11, 23, 19), -6, 7)); this.add(panel2, g.getConstraints(1, 0, 2, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 11, 0, 7), -2, 8)); panel2.add(label1, g.getConstraints(0, 0, 2, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); panel2.add(ALabel, g.getConstraints(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 5, 0, 0), -9, 0)); panel2.add(BLabel, g.getConstraints(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 5, 8, 0), -10, 0)); panel2.add(AChoice, g.getConstraints(2, 1, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 10), 73, -3)); panel2.add(BChoice, g.getConstraints(2, 2, 1, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 10, 10), 72, -4)); choiceInitial(AChoice, ed.ini.getAColor()); choiceInitial(BChoice, ed.ini.getBColor()); animationText.setText(ed.ini.getAnimationDelay()/1000 + ""); animationText.selectAll(); } void choiceInitial(Choice c, Color col) //Initialize choice menu { c.add("Red"); c.add("Blue"); c.add("Green"); c.add("Yellow"); if (col.equals(Color.red)) c.select("Red"); if (col.equals(Color.blue)) c.select("Blue"); if (col.equals(Color.green)) c.select("Green"); if (col.equals(Color.yellow)) c.select("Yellow"); } void okButton_actionPerformed(ActionEvent e) //This method is called when the "OK" button is pressed //It closes the text settings frame { try { if (AChoice.getSelectedItem().equals("Red")) ed.ini.setAColor(Color.red); else if (AChoice.getSelectedItem().equals("Blue")) ed.ini.setAColor(Color.blue); else if (AChoice.getSelectedItem().equals("Green")) ed.ini.setAColor(Color.green); else if (AChoice.getSelectedItem().equals("Yellow")) ed.ini.setAColor(Color.yellow); if (BChoice.getSelectedItem().equals("Red")) ed.ini.setBColor(Color.red); else if (BChoice.getSelectedItem().equals("Blue")) ed.ini.setBColor(Color.blue); else if (BChoice.getSelectedItem().equals("Green")) ed.ini.setBColor(Color.green); else if (BChoice.getSelectedItem().equals("Yellow")) ed.ini.setBColor(Color.yellow); ed.ini.setAnimationDelay(Integer.parseInt(animationText.getText()) * 1000); ed.enableMenus(true); hide(); //hide frame dispose(); //free resources } catch (NumberFormatException e1) { new MessageDialog(this, "Error", "Animation speed must be an integer", true); } } void cancelButton_actionPerformed(ActionEvent e) //This method is called when the "Cancel" button is pressed //It closes the text settings frame { ed.enableMenus(true); hide(); //hide frame dispose(); //free resources } }