package mars.venus; import mars.*; import mars.assembler.*; import mars.mips.instructions.*; import java.util.*; import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.html.*; /* Copyright (c) 2003-2008, Pete Sanderson and Kenneth Vollmar Developed by Pete Sanderson (psanderson@otterbein.edu) and Kenneth Vollmar (kenvollmar@missouristate.edu) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. (MIT license, http://www.opensource.org/licenses/mit-license.html) */ /** * Action for the Help -> Help menu item */ public class HelpHelpAction extends GuiAction { public HelpHelpAction(String name, Icon icon, String descrip, Integer mnemonic, KeyStroke accel, VenusUI gui) { super(name, icon, descrip, mnemonic, accel, gui); } // ideally read or computed from config file... private Dimension getSize() { return new Dimension(800,600); } // Light gray background color for alternating lines of the instruction lists static Color altBackgroundColor = new Color(0xEE,0xEE,0xEE); /** * Separates Instruction name descriptor from detailed (operation) description * in help string. */ public static final String descriptionDetailSeparator = ":"; /** * Displays tabs with categories of information */ public void actionPerformed(ActionEvent e) { JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab("MIPS", createMipsHelpInfoPanel()); tabbedPane.addTab("MARS", createMarsHelpInfoPanel()); tabbedPane.addTab("License", createCopyrightInfoPanel()); tabbedPane.addTab("Bugs/Comments", createHTMLHelpPanel("BugReportingHelp.html")); tabbedPane.addTab("Acknowledgements", createHTMLHelpPanel("Acknowledgements.html")); tabbedPane.addTab("Instruction Set Song", createHTMLHelpPanel("MIPSInstructionSetSong.html")); // Create non-modal dialog. Based on java.sun.com "How to Make Dialogs", DialogDemo.java final JDialog dialog = new JDialog(mainUI, "MARS "+Globals.version+" Help"); // assure the dialog goes away if user clicks the X dialog.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { dialog.setVisible(false); dialog.dispose(); } }); //Add a "close" button to the non-modal help dialog. JButton closeButton = new JButton("Close"); closeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); dialog.dispose(); } }); JPanel closePanel = new JPanel(); closePanel.setLayout(new BoxLayout(closePanel,BoxLayout.LINE_AXIS)); closePanel.add(Box.createHorizontalGlue()); closePanel.add(closeButton); closePanel.add(Box.createHorizontalGlue()); closePanel.setBorder(BorderFactory.createEmptyBorder(0,0,5,5)); JPanel contentPane = new JPanel(); contentPane.setLayout(new BoxLayout(contentPane,BoxLayout.PAGE_AXIS)); contentPane.add(tabbedPane); contentPane.add(Box.createRigidArea(new Dimension(0,5))); contentPane.add(closePanel); contentPane.setOpaque(true); dialog.setContentPane(contentPane); //Show it. dialog.setSize(this.getSize()); dialog.setLocationRelativeTo(mainUI); dialog.setVisible(true); ////////////////////////////////////////////////////////////////// } // Create panel containing Help Info read from html document. private JPanel createHTMLHelpPanel(String filename) { JPanel helpPanel = new JPanel(new BorderLayout()); JScrollPane helpScrollPane; JEditorPane helpDisplay; try { InputStream is = this.getClass().getResourceAsStream(Globals.helpPath+filename); BufferedReader in = new BufferedReader(new InputStreamReader(is)); String line; StringBuffer text = new StringBuffer(); while ( (line=in.readLine()) != null ) { text.append(line+"\n"); } in.close(); helpDisplay = new JEditorPane("text/html",text.toString()); helpDisplay.setEditable(false); helpDisplay.setCaretPosition(0); // assure top of document displayed helpScrollPane = new JScrollPane(helpDisplay, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); helpDisplay.addHyperlinkListener(new HelpHyperlinkListener()); } catch (Exception ie) { helpScrollPane = new JScrollPane( new JLabel("Error ("+ie+"): "+filename+" contents could not be loaded.")); } helpPanel.add(helpScrollPane); return helpPanel; } // Set up the copyright notice for display. private JPanel createCopyrightInfoPanel() { JPanel marsCopyrightInfo = new JPanel(new BorderLayout()); JScrollPane marsCopyrightScrollPane; JEditorPane marsCopyrightDisplay; try { InputStream is = this.getClass().getResourceAsStream("/MARSlicense.txt"); BufferedReader in = new BufferedReader(new InputStreamReader(is)); String line; StringBuffer text = new StringBuffer("
");
while ( (line=in.readLine()) != null ) {
text.append(line+"\n");
}
in.close();
text.append("");
marsCopyrightDisplay = new JEditorPane("text/html",text.toString());
marsCopyrightDisplay.setEditable(false);
marsCopyrightDisplay.setCaretPosition(0); // assure top of document displayed
marsCopyrightScrollPane = new JScrollPane(marsCopyrightDisplay, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
}
catch (Exception ioe) {
marsCopyrightScrollPane = new JScrollPane(
new JLabel("Error: license contents could not be loaded."));
}
marsCopyrightInfo.add(marsCopyrightScrollPane);
return marsCopyrightInfo;
}
// Set up MARS help tab. Subtabs get their contents from HTML files.
private JPanel createMarsHelpInfoPanel() {
JPanel marsHelpInfo = new JPanel(new BorderLayout());
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab("Intro", createHTMLHelpPanel("MarsHelpIntro.html"));
tabbedPane.addTab("IDE", createHTMLHelpPanel("MarsHelpIDE.html"));
tabbedPane.addTab("Debugging", createHTMLHelpPanel("MarsHelpDebugging.html"));
tabbedPane.addTab("Settings", createHTMLHelpPanel("MarsHelpSettings.html"));
tabbedPane.addTab("Tools", createHTMLHelpPanel("MarsHelpTools.html"));
tabbedPane.addTab("Command", createHTMLHelpPanel("MarsHelpCommand.html"));
tabbedPane.addTab("Limits", createHTMLHelpPanel("MarsHelpLimits.html"));
tabbedPane.addTab("History", createHTMLHelpPanel("MarsHelpHistory.html"));
marsHelpInfo.add(tabbedPane);
return marsHelpInfo;
}
// Set up MIPS help tab. Most contents are generated from instruction set info.
private JPanel createMipsHelpInfoPanel() {
JPanel mipsHelpInfo = new JPanel(new BorderLayout());
String helpRemarksColor = "CCFF99";
// Introductory remarks go at the top as a label
String helpRemarks =
"| Operand Key for Example Instructions | "+ "|
|---|---|
| label, target | any textual label | "+ "
| $t1, $t2, $t3 | any integer register | " + "
| $f2, $f4, $f6 | even-numbered floating point register | "+ "
| $f0, $f1, $f3 | any floating point register | "+ "
| $8 | any Coprocessor 0 register | "+ "
| 1 | condition flag (0 to 7) | " + "
| 10 | unsigned 5-bit integer (0 to 31) | "+ "
| -100 | signed 16-bit integer (-32768 to 32767) | " + "
| 100 | unsigned 16-bit integer (0 to 65535) | " + "
| 100000 | signed 32-bit integer (-2147483648 to 2147483647) | " + "
| Load & Store addressing mode, basic instructions | " + "|
| -100($t2) | sign-extended 16-bit integer added to contents of $t2 | " + "
| Load & Store addressing modes, pseudo instructions | " + "|
| ($t2) | contents of $t2 | " + "
| -100 | signed 16-bit integer | " + "
| 100 | unsigned 16-bit integer | " + "
| 100000 | signed 32-bit integer | " + "
| 100($t2) | zero-extended unsigned 16-bit integer added to contents of $t2 | " + "
| 100000($t2) | signed 32-bit integer added to contents of $t2 | " + "
| label | 32-bit address of label | " + "
| label($t2) | 32-bit address of label added to contents of $t2 | " + "
| label+100000 | 32-bit integer added to label's address | " + "
| label+100000($t2) | sum of 32-bit integer, label's address, and contents of $t2 | "+ "