/* 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 java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.io.*; import java.util.*; //HelpFrame itself is not a visible component. public class HelpFrame implements ListSelectionListener { //private JLabel picture; private JTextArea helpFileDisplay; private JList list; private JSplitPane splitPane; private JScrollPane listScrollPane; private JScrollPane helpScrollPane; private JFrame frame; public HelpFrame() { //Read image names from a properties file String listData[] = { "About","Add Data","Coequalizer Tool","Create Product","Create Sum" ,"Creating Categories","Creating Functors","Downloading Categories" ,"Downloading Functors","Epimorphism Tool","Equality of Composites","Equalizer Tool" ,"File Format, CAT","File Format, CGL","File Format, FUN","File Format, FGL" ,"File Types, Categories","File Types, Functors",/*"Functor Animation" ,*/"Graphical Display","Initial Object Tool","Isomorphism Tool","Limit Tool","Make Confluent" ,"Make Dual Category","Menu Item Shortcuts","Monomorphism Tool" ,"Opening Categories","Opening Functors", "Partial Order", /*"Print",*/"Product Tool" ,"Pullback Tool","Pushout Tool","Removing Data","Saving Categories","Saving Functors" ,"Settings","Sum Tool","Terminal Object Tool","View GML","Visual Display Controls" }; //Create the list of images and put it in a scroll pane list = new JList(listData); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0); list.addListSelectionListener(this); listScrollPane = new JScrollPane(list); helpFileDisplay = new JTextArea(); helpFileDisplay.setLineWrap(true); helpFileDisplay.setWrapStyleWord(true); helpFileDisplay.setFont(Font.getFont("Times New Roman")); helpScrollPane = new JScrollPane(helpFileDisplay); //Create a split pane with the two scroll panes in it splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listScrollPane, helpScrollPane); splitPane.setOneTouchExpandable(true); splitPane.setDividerLocation(200); //Provide minimum sizes for the two components in the split pane Dimension minimumSize = new Dimension(100, 50); listScrollPane.setMinimumSize(minimumSize); helpScrollPane.setMinimumSize(minimumSize); helpFileDisplay.setText(readFile("help\\about.dat")); helpFileDisplay.setCaretPosition(0); //Provide a preferred size for the split pane splitPane.setPreferredSize(new Dimension(500, 300)); frame = new JFrame("HelpFrame"); //HelpFrame splitPaneDemo = new HelpFrame(); frame.getContentPane().add(this.getSplitPane()); frame.pack(); frame.setLocation(300,200); frame.setVisible(true); } public JSplitPane getSplitPane() { return splitPane; } public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; helpFileDisplay.setFont(Font.getFont("Times New Roman")); JList theList = (JList)e.getSource(); if(theList.getSelectedValue().toString()=="About") { helpFileDisplay.setText(readFile("help\\about.dat")); } else if(theList.getSelectedValue().toString()=="Add Data") { helpFileDisplay.setText(readFile("help\\adddata.dat")); } // else if(theList.getSelectedValue().toString()=="Change Category Name") // { // helpFileDisplay.setText(readFile("help\\chcname.dat")); // } else if(theList.getSelectedValue().toString()=="Coequalizer Tool") { helpFileDisplay.setText(readFile("help\\coeq.dat")); } else if(theList.getSelectedValue().toString()=="Create Product") { helpFileDisplay.setText(readFile("help\\createproduct.dat")); } else if(theList.getSelectedValue().toString()=="Create Sum") { helpFileDisplay.setText(readFile("help\\createsum.dat")); } else if(theList.getSelectedValue().toString()=="Creating Categories") { helpFileDisplay.setText(readFile("help\\ccreate.dat")); } else if(theList.getSelectedValue().toString()=="Creating Functors") { helpFileDisplay.setText(readFile("help\\fcreate.dat")); } else if(theList.getSelectedValue().toString()=="Downloading Categories") { helpFileDisplay.setText(readFile("help\\catload.dat")); } else if(theList.getSelectedValue().toString()=="Downloading Functors") { helpFileDisplay.setText(readFile("help\\funload.dat")); } else if(theList.getSelectedValue().toString()=="Epimorphism Tool") { helpFileDisplay.setText(readFile("help\\epi.dat")); } else if(theList.getSelectedValue().toString()=="Equality of Composites") { helpFileDisplay.setText(readFile("help\\eqcomp.dat")); } else if(theList.getSelectedValue().toString()=="Equalizer Tool") { helpFileDisplay.setText(readFile("help\\eq.dat")); } else if(theList.getSelectedValue().toString()=="File Format, CAT") { helpFileDisplay.setText(readFile("help\\catform.dat")); } else if(theList.getSelectedValue().toString()=="File Format, CGL") { helpFileDisplay.setText(readFile("help\\cglform.dat")); } else if(theList.getSelectedValue().toString()=="File Format, FUN") { helpFileDisplay.setText(readFile("help\\funform.dat")); } else if(theList.getSelectedValue().toString()=="File Format, FGL") { helpFileDisplay.setText(readFile("help\\fglform.dat")); } else if(theList.getSelectedValue().toString()=="File Types, Categories") { helpFileDisplay.setText(readFile("help\\catfiles.dat")); } else if(theList.getSelectedValue().toString()=="File Types, Functors") { helpFileDisplay.setText(readFile("help\\funfiles.dat")); } // else if(theList.getSelectedValue().toString()=="Functor Animation") // { // helpFileDisplay.setText(readFile("help\\funcanim.dat")); // } else if(theList.getSelectedValue().toString()=="Graphical Display") { helpFileDisplay.setText(readFile("help\\graphdis.dat")); } else if(theList.getSelectedValue().toString()=="Initial Object Tool") { helpFileDisplay.setText(readFile("help\\initobj.dat")); } else if(theList.getSelectedValue().toString()=="Isomorphism Tool") { helpFileDisplay.setText(readFile("help\\iso.dat")); } else if(theList.getSelectedValue().toString()=="Limit Tool") { helpFileDisplay.setText(readFile("help\\limit.dat")); } else if(theList.getSelectedValue().toString()=="Make Confluent") { helpFileDisplay.setText(readFile("help\\makeconf.dat")); } else if(theList.getSelectedValue().toString()=="Make Dual Category") { helpFileDisplay.setText(readFile("help\\makedual.dat")); } else if(theList.getSelectedValue().toString()=="Menu Item Shortcuts") { helpFileDisplay.setText(readFile("help\\shortcut.dat")); } else if(theList.getSelectedValue().toString()=="Monomorphism Tool") { helpFileDisplay.setText(readFile("help\\mono.dat")); } else if(theList.getSelectedValue().toString()=="Opening Categories") { helpFileDisplay.setText(readFile("help\\catopen.dat")); } else if(theList.getSelectedValue().toString()=="Opening Functors") { helpFileDisplay.setText(readFile("help\\funopen.dat")); } else if(theList.getSelectedValue().toString()=="Partial Order") { helpFileDisplay.setText(readFile("help\\partialorder.dat")); } // else if(theList.getSelectedValue().toString()=="Print") // { // helpFileDisplay.setText(readFile("help\\print.dat")); // } else if(theList.getSelectedValue().toString()=="Product Tool") { helpFileDisplay.setText(readFile("help\\product.dat")); } else if(theList.getSelectedValue().toString()=="Pullback Tool") { helpFileDisplay.setText(readFile("help\\pullback.dat")); } else if(theList.getSelectedValue().toString()=="Pushout Tool") { helpFileDisplay.setText(readFile("help\\pushout.dat")); } else if(theList.getSelectedValue().toString()=="Removing Data") { helpFileDisplay.setText(readFile("help\\remdata.dat")); } else if(theList.getSelectedValue().toString()=="Saving Categories") { helpFileDisplay.setText(readFile("help\\savecat.dat")); } else if(theList.getSelectedValue().toString()=="Saving Functors") { helpFileDisplay.setText(readFile("help\\savefun.dat")); } else if(theList.getSelectedValue().toString()=="Settings") { helpFileDisplay.setText(readFile("help\\settings.dat")); } else if(theList.getSelectedValue().toString()=="Sum Tool") { helpFileDisplay.setText(readFile("help\\sum.dat")); } else if(theList.getSelectedValue().toString()=="Terminal Object Tool") { helpFileDisplay.setText(readFile("help\\termobj.dat")); } else if(theList.getSelectedValue().toString()=="View GML") { helpFileDisplay.setText(readFile("help\\viewgml.dat")); } else if(theList.getSelectedValue().toString()=="Visual Display Controls") { helpFileDisplay.setText(readFile("help\\viscontrol.dat")); } helpFileDisplay.setCaretPosition(0); } //Function reads in and displays a help topic from a data file private 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); } }