/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: HelpFrame.java Description: This file is displayed when the user selects the "Help Topics" menu option in the main window. It displays a list help files that are available in text format(as .DAT files). */ //import statements import java.applet.Applet; import java.net.*; import java.io.*; import java.util.*; import java.lang.System; import java.io.StringBufferInputStream; import java.awt.*; import java.awt.event.*; public class HelpFrame extends Frame { public String filename = new String(); int check_enter = 0; Button exit = new Button(); Panel button_panel = new Panel(); GridBagLayout gridBagLayout1 = new GridBagLayout(); GBConstraintsEditor g = new GBConstraintsEditor(); Button exitHelpButton = new Button(); TextField topic = new TextField(); InputStream input; DataInputStream dataInput; Label helpFileLabel = new Label(); TextArea helpFileDisplay = new TextArea("", 10, 10, TextArea.SCROLLBARS_VERTICAL_ONLY); java.awt.List helpFileList = new java.awt.List(); public HelpFrame() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } public boolean handleEvent(Event e) { if ((e.id == Event.WINDOW_DESTROY) || (e.id == Event.ACTION_EVENT)) { setVisible(false); //hide frame dispose(); //free resources return true; } 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.setTitle("Graphical Database for Category Theory Help Files"); this.setBackground(new Color(192,192,192)); this.setSize(new Dimension(588, 511)); exitHelpButton.setLabel("Exit Help Files"); helpFileLabel.setFont(new Font("Dialog", 0, 30)); helpFileLabel.setText("Help Files"); helpFileDisplay.setBackground(Color.white); helpFileDisplay.setEditable(false); Font f = new Font("TimesRoman", Font.BOLD,14); helpFileDisplay.setFont(f); this.setLayout(gridBagLayout1); this.add(topic, g.getConstraints(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 11, 0, 0), 47, 3)); this.add(exitHelpButton, g.getConstraints(0, 3, 1, 2, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(7, 11, 5, 0), 79, 3)); this.add(helpFileLabel, g.getConstraints(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(14, 11, 0, 0), 0, 0)); this.add(helpFileDisplay, g.getConstraints(1, 0, 1, 4, 1.0, 2.0 ,GridBagConstraints.SOUTH, GridBagConstraints.BOTH, new Insets(14, 29, 0, 13), 312, 289)); this.add(helpFileList, g.getConstraints(0, 2, 1, 1, 0.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(8, 11, 0, 0), 47, 283)); helpFileList.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { helpFileList_actionPerformed(e); } }); topic.addKeyListener(new java.awt.event.KeyListener() { public void keyTyped(KeyEvent e) { //topic_actionPerformed(e); } public void keyReleased(KeyEvent e) { topic_actionPerformed(e); } public void keyPressed(KeyEvent e) { //topic_actionPerformed(e); } }); createList(); helpFileList.select(0); helpFileDisplay.setText(readFile("help\\about.dat")); topic.setText("About"); topic.select(0, topic.getText().length()); topic.requestFocus(); } void topic_actionPerformed(KeyEvent e) { String temp = topic.getText(); boolean found = false; for (int i=0; i < helpFileList.getItemCount(); i++) { if (helpFileList.getItem(i).startsWith(temp) && found == false) { helpFileList.select(i); found = true; } } } void helpFileList_actionPerformed(ActionEvent e) //This function is called if an item from the help file //list is selected { if (helpFileList.getSelectedItem().equals("About")) helpFileDisplay.setText(readFile("help\\about.dat")); else if (helpFileList.getSelectedItem().equals("Add Data")) helpFileDisplay.setText(readFile("help\\adddata.dat")); else if (helpFileList.getSelectedItem().equals("Change Category Name")) helpFileDisplay.setText(readFile("help\\chcname.dat")); else if (helpFileList.getSelectedItem().equals("Coequalizer Tool")) helpFileDisplay.setText(readFile("help\\coeq.dat")); else if (helpFileList.getSelectedItem().equals("Creating Categories")) helpFileDisplay.setText(readFile("help\\ccreate.dat")); else if (helpFileList.getSelectedItem().equals("Creating Functors")) helpFileDisplay.setText(readFile("help\\fcreate.dat")); else if (helpFileList.getSelectedItem().equals("Downloading Categories")) helpFileDisplay.setText(readFile("help\\catload.dat")); else if (helpFileList.getSelectedItem().equals("Downloading Functors")) helpFileDisplay.setText(readFile("help\\funload.dat")); else if (helpFileList.getSelectedItem().equals("Epimorphism Tool")) helpFileDisplay.setText(readFile("help\\epi.dat")); else if (helpFileList.getSelectedItem().equals("Equality of Composites")) helpFileDisplay.setText(readFile("help\\eqcomp.dat")); else if (helpFileList.getSelectedItem().equals("Equalizer Tool")) helpFileDisplay.setText(readFile("help\\eq.dat")); else if (helpFileList.getSelectedItem().equals("File Format, CAT")) helpFileDisplay.setText(readFile("help\\catform.dat")); else if (helpFileList.getSelectedItem().equals("File Format, CGL")) helpFileDisplay.setText(readFile("help\\cglform.dat")); else if (helpFileList.getSelectedItem().equals("File Format, FUN")) helpFileDisplay.setText(readFile("help\\funform.dat")); else if (helpFileList.getSelectedItem().equals("File Format, FGL")) helpFileDisplay.setText(readFile("help\\fglform.dat")); else if (helpFileList.getSelectedItem().equals("File Types, Categories")) helpFileDisplay.setText(readFile("help\\catfiles.dat")); else if (helpFileList.getSelectedItem().equals("File Types, Functors")) helpFileDisplay.setText(readFile("help\\funfiles.dat")); else if (helpFileList.getSelectedItem().equals("Functor Animation")) helpFileDisplay.setText(readFile("help\\funcanim.dat")); else if (helpFileList.getSelectedItem().equals("Graphical Display")) helpFileDisplay.setText(readFile("help\\graphdis.dat")); else if (helpFileList.getSelectedItem().equals("Initial Object Tool")) helpFileDisplay.setText(readFile("help\\initobj.dat")); else if (helpFileList.getSelectedItem().equals("Isomorphism Tool")) helpFileDisplay.setText(readFile("help\\iso.dat")); else if (helpFileList.getSelectedItem().equals("Make Confluent")) helpFileDisplay.setText(readFile("help\\makeconf.dat")); else if (helpFileList.getSelectedItem().equals("Make Dual Category")) helpFileDisplay.setText(readFile("help\\makedual.dat")); else if (helpFileList.getSelectedItem().equals("Menu Item Shortcuts")) helpFileDisplay.setText(readFile("help\\shortcut.dat")); else if (helpFileList.getSelectedItem().equals("Monomorphism Tool")) helpFileDisplay.setText(readFile("help\\mono.dat")); else if (helpFileList.getSelectedItem().equals("Opening Categories")) helpFileDisplay.setText(readFile("help\\catopen.dat")); else if (helpFileList.getSelectedItem().equals("Opening Functors")) helpFileDisplay.setText(readFile("help\\funopen.dat")); else if (helpFileList.getSelectedItem().equals("Print")) helpFileDisplay.setText(readFile("help\\print.dat")); else if (helpFileList.getSelectedItem().equals("Product Tool")) helpFileDisplay.setText(readFile("help\\product.dat")); else if (helpFileList.getSelectedItem().equals("Removing Data")) helpFileDisplay.setText(readFile("help\\remdata.dat")); else if (helpFileList.getSelectedItem().equals("Saving Categories")) helpFileDisplay.setText(readFile("help\\savecat.dat")); else if (helpFileList.getSelectedItem().equals("Saving Functors")) helpFileDisplay.setText(readFile("help\\savefun.dat")); else if (helpFileList.getSelectedItem().equals("Settings")) helpFileDisplay.setText(readFile("help\\settings.dat")); else if (helpFileList.getSelectedItem().equals("Sum Tool")) helpFileDisplay.setText(readFile("help\\sum.dat")); else if (helpFileList.getSelectedItem().equals("Terminal Object Tool")) helpFileDisplay.setText(readFile("help\\termobj.dat")); else if (helpFileList.getSelectedItem().equals("View GML")) helpFileDisplay.setText(readFile("help\\viewgml.dat")); else if (helpFileList.getSelectedItem().equals("Visual Display Controls")) helpFileDisplay.setText(readFile("help\\viscontrol.dat")); else helpFileDisplay.setText("The item you have selected is not available in the current version of Category Theory Database Tools This item will be available in a future application version of CTDT."); //Set the cursor to the top of the text area helpFileDisplay helpFileDisplay.setCaretPosition(0); } //Function reads in and displays a help topic from a data file String readFile(String filename) { boolean morelines = true; BufferedReader input; helpFileDisplay.setText(""); String helpfile = new String(); try { input = new BufferedReader(new InputStreamReader(new FileInputStream(filename))); String newline = input.readLine(); while (!newline.equals("END") && !newline.equals("END\n")) { try { helpfile = helpfile + newline + "\n"; newline = input.readLine(); } catch(EOFException eof) { morelines = false; } } input.close(); } catch (IOException e1) { helpFileDisplay.setText("Error: Data File not found!"); } return (helpfile); } public void createList() //Reads list of help files from help file index and outputs it into a list //in the help frame { helpFileList.add("About"); helpFileList.add("Add Data"); helpFileList.add("Change Category Name"); helpFileList.add("Coequalizer Tool"); helpFileList.add("Creating Categories"); helpFileList.add("Creating Functors"); helpFileList.add("Downloading Categories"); helpFileList.add("Downloading Functors"); helpFileList.add("Epimorphism Tool"); helpFileList.add("Equality of Composites"); helpFileList.add("Equalizer Tool"); helpFileList.add("File Format, CAT"); helpFileList.add("File Format, CGL"); helpFileList.add("File Format, FUN"); helpFileList.add("File Format, FGL"); helpFileList.add("File Types, Categories"); helpFileList.add("File Types, Functors"); helpFileList.add("Functor Animation"); helpFileList.add("Graphical Display"); helpFileList.add("Initial Object Tool"); helpFileList.add("Isomorphism Tool"); helpFileList.add("Make Confluent"); helpFileList.add("Make Dual Category"); helpFileList.add("Menu Item Shortcuts"); helpFileList.add("Monomorphism Tool"); helpFileList.add("Opening Categories"); helpFileList.add("Opening Functors"); helpFileList.add("Print"); helpFileList.add("Product Tool"); helpFileList.add("Removing Data"); helpFileList.add("Saving Categories"); helpFileList.add("Saving Functors"); helpFileList.add("Settings"); helpFileList.add("Sum Tool"); helpFileList.add("Terminal Object Tool"); helpFileList.add("View GML"); helpFileList.add("Visual Display Controls"); } }