/* Copyright: (C) 2002 Brigham Young University This program is free software; you can redistribute it and/or modify it under the terms of the Open Source Software License Agreement for JHDL. You should have received a copy of the Open Source Software License for JHDL along with this program. If you have not, download the License Agreement at http://www.jhdl.org/license.html or write to: Brad Hutchings 459 Clyde Bldg Brigham Young University Provo, UT 84602 */ /** File: AccumCVT.java (Accumulator Circuit Visualization Tool) * This class extends the cvt (circuit visualization tool) class in * order to modify and customize its form and function. * This is a demonstration of how to customize JHDL execution * environments for a particular application. * @author Anthony L. Slade */ import java.awt.BorderLayout; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTextField; import byucc.jhdl.apps.Viewers.Schematic.SchematicViewerPanel; import byucc.jhdl.base.Cell; import byucc.jhdl.util.cli.CLInterpreter; public class AccumCVT extends cvt { public AccumCVT(Cell cl) { super(cl); customView.setSimulatorCallback((tbNBitAccum)cl); interp = getInterp(); setControlFunctions(); // Add one extra panel to demonstrate how one might use the // specialized viewers available in byucc.jhdl.apps.Viewers and // its subpackages. Schematic viewers, memory viewers, waveform // viewers, etc. are all examples of special-purpose viewers that // a custom circuit visualization tool might use to create a tool // that is most useful for the given application. contentPanel.add("Schematic", new SchematicViewerPanel(((tbNBitAccum)cl).design)); } JTabbedPane contentPanel; /** Method required by the ViewerFrame class.*/ protected Container buildContentPanel() { Container defaultContents = super.buildContentPanel(); contentPanel = new JTabbedPane(); contentPanel.add("Custom View",creatCustomView()); contentPanel.add("Standard View",defaultContents); return contentPanel; } private Container creatCustomView() { customView = new CustomAccumView(); JPanel customViewPanel = new JPanel(new BorderLayout()); customViewPanel.add(customView,BorderLayout.CENTER); JPanel controlStrip = new JPanel(); BoxLayout bl = new BoxLayout(controlStrip,BoxLayout.X_AXIS); controlStrip.setLayout(bl); resetButton = new JButton("Reset"); cycleButton = new JButton("Cycle"); inputField = new JTextField("2",20); setInputButton = new JButton("Set Input"); fileInputBox = new JCheckBox("Input From File",false); controlStrip.add(resetButton); controlStrip.add(cycleButton); controlStrip.add(inputField); controlStrip.add(setInputButton); controlStrip.add(fileInputBox); customViewPanel.add(controlStrip,BorderLayout.NORTH); return customViewPanel; } private void setControlFunctions() { resetButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { interp.parseCommand("reset"); } }); cycleButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { interp.parseCommand("cycle"); } }); setInputButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { String command = "put "; if ( !fileInputBox.isSelected() ) { command += "input "; } interp.parseCommand(command+inputField.getText()); } }); } /** JComponent that shows a custom view of the accumulator */ private CustomAccumView customView; /** Used to control the behavior of the circuit */ private JButton resetButton, cycleButton, setInputButton; /** Used to enter input values for the input wire */ private JTextField inputField; /** If selected, the input should come from a file */ private JCheckBox fileInputBox; /** Command line interpreter */ private CLInterpreter interp; }