/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: SettingsText.java Description: This class displays a frame that allows the user to change the font as well as change the style and size of the font. */ //import statements import java.awt.*; import borland.jbcl.layout.*; import java.awt.event.*; import borland.jbcl.control.*; public class SettingsText 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(); MainWindow ed = new MainWindow(); Checkbox createCategoryBox = new Checkbox(); Checkbox displayCategoryBox = new Checkbox(); Checkbox createFunctorBox = new Checkbox(); Checkbox displayFunctorBox = new Checkbox(); Button fontButton = new Button(); Button okButton = new Button(); Label createCategoryLabel = new Label(); Label displayCategoryLabel = new Label(); Label createFunctorLabel = new Label(); Label displayFunctorLabel = new Label(); FontChooser fontChooser1 = new FontChooser(); Panel panel1 = new Panel(); Label label1 = new Label(); GridBagLayout gridBagLayout1 = new GridBagLayout(); GridBagLayout gridBagLayout2 = new GridBagLayout(); public SettingsText(MainWindow edit) //Default Constructor with the parent frame as a parameter { ed = edit; try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } public boolean handleEvent(Event e) { if ((e.id == Event.WINDOW_DESTROY))//|| (e.id == Event.ACTION_EVENT)) { hide(); //hide frame dispose(); //free resources return true; } /*else if (e.key == Event.ENTER) { if (check_enter == 0) check_enter++; else { 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)) { hide(); //hide frame dispose(); //free resources return true; } return false; } private void jbInit() throws Exception //This function intializes the GUI { this.setTitle("GDCT: Text Settings"); this.setBackground(new Color(192,192,192)); Font f = ed.objectArea.getFont(); createCategoryBox.setLabel("Create Category Text"); displayCategoryBox.setLabel("Display Category Text"); createFunctorBox.setLabel("Create Functor Text"); displayFunctorBox.setLabel("Display Functor Text"); createCategoryLabel.setText(fontProperties(ed.viewbox)); displayCategoryLabel.setText(fontProperties(ed.objectArea)); createFunctorLabel.setText(fontProperties(ed.functorDisplayArea)); displayFunctorLabel.setText(fontProperties(ed.functorObjectArea)); panel1.setBackground(new Color(164, 164, 164)); label1.setText("Text Areas:"); panel1.setLayout(gridBagLayout1); okButton.setLabel("OK"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { okButton_actionPerformed(e); } }); createCategoryLabel.setFont(new Font("Dialog", 0, 12)); displayCategoryLabel.setFont(new Font("Dialog", 0, 12)); createFunctorLabel.setFont(new Font("Dialog", 0, 12)); displayFunctorLabel.setFont(new Font("Dialog", 0, 12)); fontButton.setLabel("Set Font"); fontButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { fontButton_actionPerformed(e); } }); this.setLayout(gridBagLayout2); this.add(fontButton, new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(8, 157, 10, 0), 85, 9)); this.add(okButton, new GridBagConstraints2(1, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(8, 6, 10, 11), 114, 9)); this.add(panel1, new GridBagConstraints2(0, 0, 2, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(7, 10, 0, 10), -4, 1)); panel1.add(createCategoryBox, new GridBagConstraints2(0, 1, 3, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 20, 0, 0), 0, 0)); panel1.add(label1, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 8, 0, 0), 0, 0)); panel1.add(displayCategoryBox, new GridBagConstraints2(0, 2, 3, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 20, 0, 0), 0, 0)); panel1.add(createCategoryLabel, new GridBagConstraints2(3, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 9, 0, 0), 239, -4)); panel1.add(displayCategoryLabel, new GridBagConstraints2(3, 2, 2, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 11, 0, 10), 244, -2)); panel1.add(createFunctorBox, new GridBagConstraints2(0, 3, 2, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 19, 0, 0), 0, 0)); panel1.add(displayFunctorBox, new GridBagConstraints2(0, 4, 2, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 19, 16, 0), 0, 0)); panel1.add(createFunctorLabel, new GridBagConstraints2(3, 3, 2, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 11, 0, 11), 243, -2)); panel1.add(displayFunctorLabel, new GridBagConstraints2(3, 4, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 16, 0), 243, 0)); } String fontProperties(TextArea t) //This method returns a sting containing the font //properties of the given TextArea { String temp = t.getFont().toString(); int i = 0; boolean firstComma = false; int begin = 0; int end = 0; while ((temp.charAt(i) != ']') && (i != temp.length())) { if ((temp.charAt(i) == ',') && (firstComma == false)) { begin = i + 1; firstComma = true; } i++; } end = i; return("[ " + temp.substring(begin, end) + " ]"); } void okButton_actionPerformed(ActionEvent e) //This method is called when the "OK" button is pressed //It closes the text settings frame { hide(); //hide frame dispose(); //free resources } void fontButton_actionPerformed(ActionEvent e) //This method is called when the "Set Font" button is pressed { if (createCategoryBox.getState() == true) { fontChooser1.setFrame(this); fontChooser1.setTitle("Create Category Font"); fontChooser1.show(); ed.viewbox.setFont(fontChooser1.getValue()); ed.categoryNameField.setFont(fontChooser1.getValue()); ed.catInputField.setFont(fontChooser1.getValue()); createCategoryBox.setState(false); createCategoryLabel.setText(fontProperties(ed.viewbox)); validate(); } if (displayCategoryBox.getState() == true) { fontChooser1.setFrame(this); fontChooser1.setTitle("Display Category Font"); fontChooser1.show(); ed.categoryChoice.setFont(fontChooser1.getValue()); ed.objectArea.setFont(fontChooser1.getValue()); ed.arrowArea.setFont(fontChooser1.getValue()); ed.relationArea.setFont(fontChooser1.getValue()); ed.commentArea.setFont(fontChooser1.getValue()); displayCategoryBox.setState(false); displayCategoryLabel.setText(fontProperties(ed.objectArea)); validate(); } if (createFunctorBox.getState() == true) { fontChooser1.setFrame(this); fontChooser1.setTitle("Create Category Font"); fontChooser1.show(); ed.functorInputField.setFont(fontChooser1.getValue()); ed.functorToChoice.setFont(fontChooser1.getValue()); ed.functorFromChoice.setFont(fontChooser1.getValue()); ed.functorNameField.setFont(fontChooser1.getValue()); ed.functorDisplayArea.setFont(fontChooser1.getValue()); createFunctorBox.setState(false); createFunctorLabel.setText(fontProperties(ed.functorDisplayArea)); validate(); } if (displayFunctorBox.getState() == true) { fontChooser1.setFrame(this); fontChooser1.setTitle("Display Functor Font"); fontChooser1.show(); ed.functorChoice.setFont(fontChooser1.getValue()); ed.functorObjectArea.setFont(fontChooser1.getValue()); ed.functorArrowArea.setFont(fontChooser1.getValue()); displayFunctorBox.setState(false); displayFunctorLabel.setText(fontProperties(ed.functorObjectArea)); validate(); } } }