/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: SettingServer.java Description: This class displays a frame which allows the user to change the default server, default server category directory, and the default server functor directory, which are used in the loading of files. */ //import statements import java.awt.*; import java.awt.event.*; public class SettingsServer extends Frame { Category c = new Category(); 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(); Button okButton = new Button(); MainWindow ed; Label serverLabel = new Label(); Label catLabel = new Label(); Label funLabel = new Label(); TextField serverField = new TextField(); TextField catField = new TextField(); TextField funField = new TextField(); Checkbox defaultBox = new Checkbox(); TextField cglField = new TextField(); TextField fglField = new TextField(); Label cglLabel = new Label(); Label fglLabel = new Label(); Panel panel1 = new Panel(); Panel panel2 = new Panel(); GridBagLayout gridBagLayout1 = new GridBagLayout(); GridBagLayout gridBagLayout2 = new GridBagLayout(); GridBagLayout gridBagLayout3 = new GridBagLayout(); GBConstraintsEditor g = new GBConstraintsEditor(); public SettingsServer(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) || (e.id == Event.ACTION_EVENT)) { ed.enableMenus(true); hide(); //hide frame dispose(); //free resources return true; } else if (e.key == Event.ENTER) { if (check_enter == 0) check_enter++; else { 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) || (e.key == Event.ENTER)) { 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: Server Settings"); this.setBackground(new Color(192,192,192)); this.setSize(new Dimension(400, 259)); okButton.setLabel("OK"); okButton.setLabel("OK"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { okButton_actionPerformed(e); } }); serverLabel.setText("Server Address:"); catLabel.setText("CAT File Directory: "); funLabel.setText("FUN File Directory:"); cglField.setBackground(Color.white); fglField.setBackground(Color.white); cglLabel.setText("CGL File Directory: "); fglLabel.setText("FGL File Directory: "); panel1.setBackground(new Color(164, 164, 164)); panel2.setBackground(new Color(164, 164, 164)); panel2.setLayout(gridBagLayout2); panel1.setLayout(gridBagLayout1); fglField.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { fglField_actionPerformed(e); } }); defaultBox.setLabel("Use Default Settings"); defaultBox.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(ItemEvent e) { defaultBox_itemStateChanged(e); } }); this.setLayout(gridBagLayout3); serverField.setBackground(Color.white); catField.setBackground(Color.white); funField.setBackground(Color.white); this.add(okButton, g.getConstraints(0, 2, 2, 2, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(6, 178, 8, 14), 164, 8)); this.add(panel1, g.getConstraints(0, 1, 2, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 9, 0, 13), 1, 10)); panel1.add(catLabel, g.getConstraints(0, 0, 2, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 3, 0, 0), -4, 0)); panel1.add(cglLabel, g.getConstraints(0, 1, 2, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 3, 0, 0), -6, 0)); panel1.add(funLabel, g.getConstraints(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 3, 0, 0), -12, 0)); panel1.add(fglLabel, g.getConstraints(0, 3, 2, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 3, 10, 0), -4, 0)); panel1.add(catField, g.getConstraints(2, 0, 1, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 6, 0, 11), 207, 0)); panel1.add(cglField, g.getConstraints(2, 1, 1, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 11), 207, 0)); panel1.add(funField, g.getConstraints(2, 2, 1, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 7, 0, 11), 206, 0)); panel1.add(fglField, g.getConstraints(2, 3, 1, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 10, 11), 207, 0)); this.add(defaultBox, g.getConstraints(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(6, 9, 0, 0), 38, 0)); this.add(panel2, g.getConstraints(0, 0, 2, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(8, 9, 0, 14), 0, 0)); panel2.add(serverLabel, g.getConstraints(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 5, 7, 0), 0, 0)); panel2.add(serverField, g.getConstraints(1, 0, 1, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(6, 17, 6, 11), 206, 0)); serverField.setText(ed.ini.getServer()); catField.setText(ed.ini.getCatDir()); cglField.setText(ed.ini.getCglDir()); funField.setText(ed.ini.getFunDir()); fglField.setText(ed.ini.getFglDir()); funField.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { functorField_actionPerformed(e); } }); } void okButton_actionPerformed(ActionEvent e) { ed.ini.setServer(serverField.getText()); ed.ini.setCatDir(catField.getText()); ed.ini.setCglDir(cglField.getText()); ed.ini.setFunDir(funField.getText()); ed.ini.setFglDir(fglField.getText()); ed.enableMenus(true); hide(); dispose(); } void defaultBox_itemStateChanged(ItemEvent e) { serverField.setText("http://mathcs.mta.ca/research/rosebrugh/gdct/"); catField.setText("cat/"); cglField.setText("cgl/"); funField.setText("fun/"); fglField.setText("fgl/"); defaultBox.setState(false); } void choice1_itemStateChanged(ItemEvent e) { } void functorField_actionPerformed(ActionEvent e) { } void fglField_actionPerformed(ActionEvent e) { } }