From f9dab3f4ea4773268f295225e9c2d5e38d5aca5b Mon Sep 17 00:00:00 2001 From: Amy Wilder Date: Sun, 15 Feb 2026 14:35:53 -0500 Subject: [PATCH 1/3] Add options for exporting circuit images as PNGs --- src/jls/Circuit.java | 104 +++++++++++++-------------- src/jls/JLSStart.java | 160 ++++++++++++++++++++++++------------------ 2 files changed, 143 insertions(+), 121 deletions(-) diff --git a/src/jls/Circuit.java b/src/jls/Circuit.java index 7030ed5..7c804ac 100644 --- a/src/jls/Circuit.java +++ b/src/jls/Circuit.java @@ -42,7 +42,7 @@ /** * The main (container) class for each circuit. - * + * * @author David A. Poplawski */ public class Circuit implements Printable { @@ -68,8 +68,8 @@ public class Circuit implements Printable { private static int lineNumber; // to report errors when reading circuit file private List editHistory = new LinkedList(); - - + + /** * Try to open the file and retrieve the edit history. */ @@ -78,7 +78,7 @@ public List getEditHistory() { } /** * Create a new, empty circuit. - * + * * @param name * The name of this circuit. */ @@ -89,7 +89,7 @@ public Circuit(String name) { /** * Get the directory the circuit file is stored in. - * + * * @return the full path name of the directory. */ public String getDirectory() { @@ -99,7 +99,7 @@ public String getDirectory() { /** * Set the directory the circuit file is store in. - * + * * @param dir * The full path name of the directory. */ @@ -110,7 +110,7 @@ public void setDirectory(String dir) { /** * Get the name of this circuit. - * + * * @return the name of this circuit. */ public String getName() { @@ -120,7 +120,7 @@ public String getName() { /** * Change name of this circuit. - * + * * @param name * New name. */ @@ -131,7 +131,7 @@ public void setName(String name) { /** * Check if circuit has changed. - * + * * @return true if the circuit has changed, false if not. */ public boolean hasChanged() { @@ -166,7 +166,7 @@ public void clear() { /** * Add an element to this circuit. - * + * * @param el * The element to add. */ @@ -179,7 +179,7 @@ public void addElement(Element el) { /** * Delete element from circuit. Do nothing if the element is not in the * circuit. - * + * * @param el * The element to remove. */ @@ -198,10 +198,10 @@ public Set getElements() { /** * Load circuit from file. - * + * * @param scanner * A scanner to read with. - * + * * @return false if there were problems, true if load was successful. */ public boolean load(Scanner input) { @@ -212,13 +212,13 @@ public boolean load(Scanner input) { /** * Load circuit from file. - * + * * @param scanner * A scanner to read with. * @param ln * Unused, except to give a different signature for the recursive * call that doesn't reset the line number counter. - * + * * @return false if there were problems, true if load was successful. */ private boolean load(Scanner input, int ln) { @@ -246,7 +246,7 @@ private boolean load(Scanner input, int ln) { name = input.next(); else input.next(); - + // read circuit and get basic info for each element lineNumber += 1; while (input.hasNext()) { @@ -323,10 +323,10 @@ private boolean load(Scanner input, int ln) { /** * Load an element by reading all of its instance variable values. - * + * * @param instance * An empty object to load. - * + * * @return false if the file is not in the right format, true if it is. */ public boolean loadElement(Element el, Scanner input) { @@ -483,10 +483,10 @@ public boolean loadElement(Element el, Scanner input) { /** * Finish load of circuit. - * + * * @param g * The Graphics object to use. - * + * * @return false if any exceptions occur * @throws Exception */ @@ -570,7 +570,7 @@ public boolean finishLoad(Graphics g) throws Exception { /** * Get the smallest rectangle containing all the elements in the circuit. - * + * * @return the smallest rectangle. */ public Rectangle getBounds() { @@ -592,7 +592,7 @@ public Rectangle getBounds() { /** * Save circuit in file. - * + * * @param output * The file to write to. */ @@ -628,8 +628,8 @@ public void save(PrintWriter output) { * Draw the circuit by drawing every element. First the set of elements not * in the second set are drawn, then the ones in the second set are drawn. * Wires are drawn first in each set. - * - * + * + * * @param g * The graphics object to draw with. * @param second @@ -637,7 +637,7 @@ public void save(PrintWriter output) { * @param ed * The editor window doing the drawing. * @throws Exception - * + * * @param g * The graphics object to draw with. * @param second @@ -688,14 +688,14 @@ public void draw(Graphics g, Set second, SimpleEditor ed) /** * Print the circuit. - * + * * @param g * The graphics object to use * @param format * Page format info. * @param pagenum * Ignored. - * + * * @return Printable.PAGE_EXISTS. */ public int print(Graphics g, PageFormat format, int pagenum) { @@ -756,7 +756,7 @@ public int print(Graphics g, PageFormat format, int pagenum) { /** * Add this circuit to the print book, add any of its state machines, truth * tables and all subcircuits. - * + * * @param book * The book to add to. * @param format @@ -796,9 +796,9 @@ public void addToBook(Book book, PageFormat format) { /** * Export an image of the circuit. - * + * * <<<<<<< HEAD - * + * * @param file * The name of the file to write to. * @throws Exception @@ -807,7 +807,7 @@ public void addToBook(Book book, PageFormat format) { * The name of the file to write to. >>>>>>> * 6fff4f8d5651621bfd72b14010a8a3fdd3ba837a */ - public void exportImage(String file) throws Exception { + public void exportImage(String file, String formatName) throws Exception { // get bounds of actual circuit Rectangle rect = getBounds(); @@ -832,7 +832,7 @@ public void exportImage(String file) throws Exception { // write the image try { - ImageIO.write(image, "JPEG", new File(file)); + ImageIO.write(image, formatName, new File(file)); } catch (Exception ex) { System.out.println("image write exception"); } @@ -856,10 +856,10 @@ public void untouchPuts() { /** * Get an element from the load map. - * + * * @param id * The id of the element. - * + * * @return the element with the given id, or null if not in the map. */ public Element getElementByID(int id) { @@ -870,10 +870,10 @@ public Element getElementByID(int id) { /** * Add a name to the list of names used. If already used in the list, don't * add it. - * + * * @param name * The new name. - * + * * @return false if the name is already in the list, true if not. */ public boolean addName(String name) { @@ -886,10 +886,10 @@ public boolean addName(String name) { /** * See if this circuit already has an element with a given name. - * + * * @param name * The name to check for. - * + * * @return true if the name is already used, false if not. */ public boolean hasName(String name) { @@ -900,7 +900,7 @@ public boolean hasName(String name) { /** * Remove a name from the list of names used. Do nothing if not there to * start with. - * + * * @param name * The name to remove. */ @@ -912,7 +912,7 @@ public void removeName(String name) { /** * Set that this circuit is an imported circuit. This means it cannot be * saved in a file and that pins cannot be added or removed. - * + * * @param sub * The SubCircuit element in the main circuit that refers to this * subcircuit. @@ -924,7 +924,7 @@ public void setImported(SubCircuit sub) { /** * See if this is an imported circuit. - * + * * @return true if it is imported, false otherwise. */ public boolean isImported() { @@ -934,7 +934,7 @@ public boolean isImported() { /** * Get the SubCircuit element referring to this circuit. - * + * * @return the element. */ public SubCircuit getSubElement() { @@ -992,12 +992,12 @@ public void resetAllDelays() { /** * Add a jumpstart to the list of jumpstarts in this circuit. If there is * already one with the given name, do not add it. - * + * * @param name * The name of the jumpstart. * @param start * The jumpstart object. - * + * * @return false if there already is a jumpstart with the given name, true * otherwise. */ @@ -1011,10 +1011,10 @@ public boolean addJumpStart(String name, JumpStart start) { /** * Get the jumpstart with the given name. - * + * * @param name * The name of the desired jumpstart. - * + * * @return the jumpstart, or null if it no jumpstart with the given name * exists. */ @@ -1025,7 +1025,7 @@ public JumpStart getJumpStart(String name) { /** * Get all jump start names in alphabetical order. - * + * * @return the starts. */ public Set getJumpStartNames() { @@ -1035,7 +1035,7 @@ public Set getJumpStartNames() { /** * Remove a jump start from the list. - * + * * @param name * The name of this jump start. */ @@ -1046,7 +1046,7 @@ public void removeJumpStart(String name) { /** * Set the editor of this circuit. - * + * * @param ed * The current editor, or null to indicate not being edited. */ @@ -1057,7 +1057,7 @@ public void setEditor(Editor ed) { /** * Get the editor of this circuit. - * + * * @return The current editor, or null if not being edited. */ public Editor getEditor() { @@ -1076,7 +1076,7 @@ public int getLineNumber() { /** * For debugging, return name and super.toString - * + * * @return string version of this circuit. */ public String toString() { @@ -1087,7 +1087,7 @@ public String toString() { /** * TODO: it looks like this function could use some clean up; hints at * possible circuit encoding improvements. - * + * * @param read * @return */ diff --git a/src/jls/JLSStart.java b/src/jls/JLSStart.java index ee67d0a..867ebc6 100644 --- a/src/jls/JLSStart.java +++ b/src/jls/JLSStart.java @@ -89,7 +89,7 @@ public class JLSStart extends JFrame implements ChangeListener { /** * Parse command line arguments and start up JLS. - * + * * @param args Command line arguments. */ public static void start(String[] args, DefaultExceptionHandler exh) { @@ -131,7 +131,7 @@ public static void start(String[] args, DefaultExceptionHandler exh) { System.out.println(startFile + " is not a valid circuit file name"); System.exit(1); } - + Scanner input = getScannerForFile(startFile); // create new circuit @@ -191,7 +191,7 @@ public static void start(String[] args, DefaultExceptionHandler exh) { batchSim.printTrace(printer); } } - + else if (JLSInfo.imgexport) { // from Zack, for MAC's? System.setProperty("java.awt.headless", "true"); @@ -267,7 +267,7 @@ else if (JLSInfo.imgexport) { System.exit(1); } try { - circ.exportImage(name + ".jpg"); + circ.exportImage(name + ".jpg", "JPEG"); } catch (Exception e) { TellUser.err("Failed to export image for an undetermined reason", true); e.printStackTrace(); @@ -297,7 +297,7 @@ public void run() { /** * Display values of watched elements to stdout. * Descends into subcircuits recursively. - * + * * @param circ The circuit to find watched elements in. * @param qual Qualified name of subcircuit. */ @@ -336,7 +336,7 @@ else if (el instanceof SubCircuit) { /** * Parse command line. - * + * * @param args The command line arguments. */ public static void parseCommandLine(String [] args) { @@ -359,10 +359,10 @@ else if (flag == 'b') { JLSInfo.batch = true; } } - + else if (flag == 'i') { JLSInfo.imgexport = true; - } + } else if (flag == 'r') { if (arg.length() > 2) { @@ -515,13 +515,13 @@ public JLSStart() { // make it look the same everywhere (especially MAC's). try { - - UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); - + + UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); + // If on Mac, swap meta to have copy/paste/cut work String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH); if(OS.indexOf("mac") >=0 || OS.indexOf("darwin")>=0 || OS.indexOf("os x") >=0) { - // Setup file open + // Setup file open Desktop a = Desktop.getDesktop(); a.setOpenFileHandler(new OpenFilesHandler() { @@ -533,14 +533,14 @@ public void openFiles(OpenFilesEvent e) { open(fileName); } } - - }); - + + }); + // Set up copy/paste/cut - // https://stackoverflow.com/questions/1852433/use-default-keymap-of-native-os + // https://stackoverflow.com/questions/1852433/use-default-keymap-of-native-os java.awt.Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { - // Check for Command-C, Command-V, and Command-X on Mac and re-map them to control. + // Check for Command-C, Command-V, and Command-X on Mac and re-map them to control. public void eventDispatched(AWTEvent event) { KeyEvent kev = (KeyEvent) event; if (kev.getID() == KeyEvent.KEY_PRESSED) { @@ -564,8 +564,8 @@ public void eventDispatched(AWTEvent event) { } } } - }, KeyEvent.KEY_EVENT_MASK); - } + }, KeyEvent.KEY_EVENT_MASK); + } } catch (Exception ex) { @@ -640,7 +640,7 @@ public void windowClosing(WindowEvent e) { * root of the subcircuit containment. * If no tab is selected (i.e., all editors have been closed), * then the simulator's circuit is set to null. - * + * * @param event Unused. */ public void stateChanged(ChangeEvent event) { @@ -683,7 +683,7 @@ private void shutdown() { /** * Get currently visible editor. - * + * * @return the currently visible editor, or null if no editor is visible. */ public Editor getVisibleEditor() { @@ -693,7 +693,7 @@ public Editor getVisibleEditor() { /** * Set up file menu. - * + * * @return the file menu created. */ public JMenu fileMenu() { @@ -819,7 +819,7 @@ public void actionPerformed(ActionEvent event) { /** * Set up simulator menu. - * + * * @return the menu. */ public JMenu simMenu() { @@ -876,7 +876,7 @@ public void actionPerformed(ActionEvent event) { /** * Set up global change menu. - * + * * @return the menu. */ public JMenu globalMenu() { @@ -964,7 +964,7 @@ public void actionPerformed(ActionEvent event) { /** * Create help menu. - * + * * @return the menu. */ public JMenu helpMenu() { @@ -985,7 +985,7 @@ public void actionPerformed(ActionEvent event) { help.add(tutorial); JMenuItem tutorial1 = new JMenuItem("Introduction"); String tip1 = "This tutorial demonstrates the " + - "basic drawing capabilities
" + + "basic drawing capabilities
" + "using simple gates and wires, " + "and how to use the simulator  
" + "to watch the circuit in action."; @@ -997,7 +997,7 @@ public void actionPerformed(ActionEvent event) { } }); JMenuItem tutorial2 = new JMenuItem("4-Bit Counter"); - String tip2 = "Demonstrates the use of more complex  
" + + String tip2 = "Demonstrates the use of more complex  
" + "elements and multi-wire connections."; tutorial2.setToolTipText(tip2); tutorial.add(tutorial2); @@ -1090,7 +1090,7 @@ private void newCircuit() { /** * Open an existing circuit. - * + * * @param name The name of the circuit. If null, then prompt user for * the name. */ @@ -1101,7 +1101,7 @@ private void open(String filePath) { // get circuit name from user if parameter is null if (filePath == null) { JFileChooser chooser = new JFileChooser( JLSInfo.getLastSelectedDirectory() ); - + javax.swing.filechooser.FileFilter filter = new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { @@ -1112,9 +1112,9 @@ public String getDescription() { return "JLS Circuit Files"; } }; - + chooser.setFileFilter(filter); - if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) + if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) return; file = chooser.getSelectedFile(); filePath = file.getAbsolutePath(); @@ -1127,7 +1127,7 @@ public String getDescription() { JLSInfo.setLastSelectedDirectory(file.getParent()); } } - + Scanner input = getScannerForFile(filePath); String cname; @@ -1151,7 +1151,7 @@ public String getDescription() { } retrieveEditHistory(filePath, circ); - + // delete checkpoint file if there is one new File(cname + ".jls~").delete(); @@ -1162,7 +1162,7 @@ public String getDescription() { /** * Set up editor window - * + * * @param circ The circuit the editor will edit. * @param name The name of the circuit. */ @@ -1222,7 +1222,7 @@ private void closeVisibleEditor() { /** * Print circuit currently being edited, plus any state machines. - * + * * @param all True to print the entire circuit, false to print just what's visible. */ public void print(boolean all) { @@ -1262,9 +1262,9 @@ public void print(boolean all) { /** * Check for duplicate of circuit already being edited. - * + * * @param name The new name. - * + * * @return true if a duplicate, false if not. */ public boolean duplicateName(String name) { @@ -1280,7 +1280,7 @@ public boolean duplicateName(String name) { return false; } // end of duplicateName method - + private static Scanner testScanner(Scanner toTest){ if (toTest.hasNext() == false) { toTest.close(); @@ -1288,7 +1288,7 @@ private static Scanner testScanner(Scanner toTest){ } return toTest; } - + private static Scanner getZipScanner(String filePath){ try{ ZipFile target = new ZipFile(new File(filePath)); @@ -1299,7 +1299,7 @@ private static Scanner getZipScanner(String filePath){ return null; } } - + private static Scanner getTextScanner(String filePath){ try{ return testScanner(new Scanner(new File(filePath))); @@ -1307,8 +1307,8 @@ private static Scanner getTextScanner(String filePath){ return null; } } - - + + private static void retrieveEditHistory(String filePath, Circuit circuit) { try{ ZipFile target = new ZipFile(new File(filePath)); @@ -1321,37 +1321,37 @@ private static void retrieveEditHistory(String filePath, Circuit circuit) { }catch(Throwable e){ return; } - + } - + private static Scanner getScannerForFile(String filePath){ - + String name; - + name = filePath.replaceAll("\\.jls~$", ""); name = name.replaceAll("\\.jls$", ""); if (Util.isValidFileName(name) == null) { - TellUser.err(name + " is not a valid circuit file name.\n" + TellUser.err(name + " is not a valid circuit file name.\n" + "It must start with a letter and contain letters, " +"digits and underscores.", true); return null; } - + Scanner toReturn = null; - + if((toReturn = getZipScanner(filePath)) != null) return toReturn; - + if((toReturn = getTextScanner(filePath)) != null) return toReturn; - + TellUser.err("Unable to open " + name + "\n", true); return null; } - - + + /** * Import a circuit from a file into this circuit. - * @throws Exception + * @throws Exception */ public void fileImport() throws Exception { @@ -1373,9 +1373,9 @@ public String getDescription() { } }; chooser.setFileFilter(filter); - if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) + if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) return; - + Scanner input = getScannerForFile(chooser.getSelectedFile().getAbsolutePath()); // create new circuit @@ -1401,7 +1401,7 @@ public String getDescription() { /** * Check for parameter file in the current directory, - * + * * @param paramFile The name of the file containing JLS parameters. * @param circuit The circuit to apply the parameters too. */ @@ -1694,7 +1694,7 @@ else if (key.equals("RESET")) { /** * Set the propagation delay of all elements of a certain type * in a circuit and its subcircuits. - * + * * @param circ The circuit. * @param cl The type (class) of element to change. * @param delay The new propagation delay. @@ -1716,7 +1716,7 @@ else if (el.getClass() == cl) { /** * Print the circuit specified in the start file. - * + * * @param justTop True if just the top level of the circuit is to be printed, false if the whole thing. */ private static void printCirc(boolean justTop) { @@ -1725,7 +1725,7 @@ private static void printCirc(boolean justTop) { // create new circuit Circuit circ = new Circuit(name); - + try { circ.finishLoad(null); } catch (Exception e) { @@ -1780,7 +1780,7 @@ private static void printCirc(boolean justTop) { /** * Write an image of the circuit to a file. - * @throws Exception + * @throws Exception */ public void exportImage() throws Exception { @@ -1793,39 +1793,61 @@ public void exportImage() throws Exception { javax.swing.filechooser.FileFilter filter = new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { - return f.getName().endsWith(".jpg") || f.isDirectory(); + String name = f.getName(); + return name.endsWith(".jpg") || name.endsWith(".png") || f.isDirectory(); } public String getDescription() { return "JLS Circuit Images"; } }; + javax.swing.filechooser.FileFilter jpgFilter = + new javax.swing.filechooser.FileFilter() { + public boolean accept(File f) { + return f.getName().endsWith(".jpg") || f.isDirectory(); + } + public String getDescription() { + return "JPEG Images"; + } + }; + javax.swing.filechooser.FileFilter pngFilter = + new javax.swing.filechooser.FileFilter() { + public boolean accept(File f) { + return f.getName().endsWith(".png") || f.isDirectory(); + } + public String getDescription() { + return "PNG Images"; + } + }; + chooser.addChoosableFileFilter(jpgFilter); + chooser.addChoosableFileFilter(pngFilter); chooser.setFileFilter(filter); - if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) + if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) return; String fileName = chooser.getSelectedFile().getName().trim(); + javax.swing.filechooser.FileFilter selectedFilter = chooser.getFileFilter(); if (fileName == null || fileName.equals("")) return; - String tempName = fileName.replaceAll("\\.jpg$",""); + String tempName = fileName.replaceAll("\\.jpg$","").replaceAll("\\.png$", ""); if (!Util.isValidName(tempName)) { JOptionPane.showMessageDialog(JLSInfo.frame,"Invalid file name - must contain only letters, digits & _"); return; } - if (!fileName.endsWith(".jpg")) { - fileName = fileName + ".jpg"; + if (!(fileName.endsWith(".jpg") || fileName.endsWith(".png"))) { + fileName = fileName + (selectedFilter == pngFilter ? ".png" : ".jpg"); } String path = chooser.getCurrentDirectory() + "/"; fileName = path + fileName; JLSInfo.setLastSelectedDirectory(path); // export the image Circuit circ = ed.getCircuit(); - circ.exportImage(fileName); + circ.exportImage(fileName, fileName.endsWith(".png") ? "PNG" : "JPEG"); } // end of exportImage method /** * Break compound name (a.b.c) into components. - * + * * @param name The compound name. - * + * * @return the components of the name, or null if the name is not valid. */ public static Vector parseName(String name) { From 1b0c2511409622084c5712553dfb2c712afa502e Mon Sep 17 00:00:00 2001 From: Amy Wilder Date: Sun, 15 Feb 2026 14:47:14 -0500 Subject: [PATCH 2/3] Revert whitespace removed by IDE (for cleaner squash) --- src/jls/Circuit.java | 100 +++++++++++++++++----------------- src/jls/JLSStart.java | 124 +++++++++++++++++++++--------------------- 2 files changed, 112 insertions(+), 112 deletions(-) diff --git a/src/jls/Circuit.java b/src/jls/Circuit.java index 7c804ac..917a08b 100644 --- a/src/jls/Circuit.java +++ b/src/jls/Circuit.java @@ -42,7 +42,7 @@ /** * The main (container) class for each circuit. - * + * * @author David A. Poplawski */ public class Circuit implements Printable { @@ -68,8 +68,8 @@ public class Circuit implements Printable { private static int lineNumber; // to report errors when reading circuit file private List editHistory = new LinkedList(); - - + + /** * Try to open the file and retrieve the edit history. */ @@ -78,7 +78,7 @@ public List getEditHistory() { } /** * Create a new, empty circuit. - * + * * @param name * The name of this circuit. */ @@ -89,7 +89,7 @@ public Circuit(String name) { /** * Get the directory the circuit file is stored in. - * + * * @return the full path name of the directory. */ public String getDirectory() { @@ -99,7 +99,7 @@ public String getDirectory() { /** * Set the directory the circuit file is store in. - * + * * @param dir * The full path name of the directory. */ @@ -110,7 +110,7 @@ public void setDirectory(String dir) { /** * Get the name of this circuit. - * + * * @return the name of this circuit. */ public String getName() { @@ -120,7 +120,7 @@ public String getName() { /** * Change name of this circuit. - * + * * @param name * New name. */ @@ -131,7 +131,7 @@ public void setName(String name) { /** * Check if circuit has changed. - * + * * @return true if the circuit has changed, false if not. */ public boolean hasChanged() { @@ -166,7 +166,7 @@ public void clear() { /** * Add an element to this circuit. - * + * * @param el * The element to add. */ @@ -179,7 +179,7 @@ public void addElement(Element el) { /** * Delete element from circuit. Do nothing if the element is not in the * circuit. - * + * * @param el * The element to remove. */ @@ -198,10 +198,10 @@ public Set getElements() { /** * Load circuit from file. - * + * * @param scanner * A scanner to read with. - * + * * @return false if there were problems, true if load was successful. */ public boolean load(Scanner input) { @@ -212,13 +212,13 @@ public boolean load(Scanner input) { /** * Load circuit from file. - * + * * @param scanner * A scanner to read with. * @param ln * Unused, except to give a different signature for the recursive * call that doesn't reset the line number counter. - * + * * @return false if there were problems, true if load was successful. */ private boolean load(Scanner input, int ln) { @@ -246,7 +246,7 @@ private boolean load(Scanner input, int ln) { name = input.next(); else input.next(); - + // read circuit and get basic info for each element lineNumber += 1; while (input.hasNext()) { @@ -323,10 +323,10 @@ private boolean load(Scanner input, int ln) { /** * Load an element by reading all of its instance variable values. - * + * * @param instance * An empty object to load. - * + * * @return false if the file is not in the right format, true if it is. */ public boolean loadElement(Element el, Scanner input) { @@ -483,10 +483,10 @@ public boolean loadElement(Element el, Scanner input) { /** * Finish load of circuit. - * + * * @param g * The Graphics object to use. - * + * * @return false if any exceptions occur * @throws Exception */ @@ -570,7 +570,7 @@ public boolean finishLoad(Graphics g) throws Exception { /** * Get the smallest rectangle containing all the elements in the circuit. - * + * * @return the smallest rectangle. */ public Rectangle getBounds() { @@ -592,7 +592,7 @@ public Rectangle getBounds() { /** * Save circuit in file. - * + * * @param output * The file to write to. */ @@ -628,8 +628,8 @@ public void save(PrintWriter output) { * Draw the circuit by drawing every element. First the set of elements not * in the second set are drawn, then the ones in the second set are drawn. * Wires are drawn first in each set. - * - * + * + * * @param g * The graphics object to draw with. * @param second @@ -637,7 +637,7 @@ public void save(PrintWriter output) { * @param ed * The editor window doing the drawing. * @throws Exception - * + * * @param g * The graphics object to draw with. * @param second @@ -688,14 +688,14 @@ public void draw(Graphics g, Set second, SimpleEditor ed) /** * Print the circuit. - * + * * @param g * The graphics object to use * @param format * Page format info. * @param pagenum * Ignored. - * + * * @return Printable.PAGE_EXISTS. */ public int print(Graphics g, PageFormat format, int pagenum) { @@ -756,7 +756,7 @@ public int print(Graphics g, PageFormat format, int pagenum) { /** * Add this circuit to the print book, add any of its state machines, truth * tables and all subcircuits. - * + * * @param book * The book to add to. * @param format @@ -796,9 +796,9 @@ public void addToBook(Book book, PageFormat format) { /** * Export an image of the circuit. - * + * * <<<<<<< HEAD - * + * * @param file * The name of the file to write to. * @throws Exception @@ -856,10 +856,10 @@ public void untouchPuts() { /** * Get an element from the load map. - * + * * @param id * The id of the element. - * + * * @return the element with the given id, or null if not in the map. */ public Element getElementByID(int id) { @@ -870,10 +870,10 @@ public Element getElementByID(int id) { /** * Add a name to the list of names used. If already used in the list, don't * add it. - * + * * @param name * The new name. - * + * * @return false if the name is already in the list, true if not. */ public boolean addName(String name) { @@ -886,10 +886,10 @@ public boolean addName(String name) { /** * See if this circuit already has an element with a given name. - * + * * @param name * The name to check for. - * + * * @return true if the name is already used, false if not. */ public boolean hasName(String name) { @@ -900,7 +900,7 @@ public boolean hasName(String name) { /** * Remove a name from the list of names used. Do nothing if not there to * start with. - * + * * @param name * The name to remove. */ @@ -912,7 +912,7 @@ public void removeName(String name) { /** * Set that this circuit is an imported circuit. This means it cannot be * saved in a file and that pins cannot be added or removed. - * + * * @param sub * The SubCircuit element in the main circuit that refers to this * subcircuit. @@ -924,7 +924,7 @@ public void setImported(SubCircuit sub) { /** * See if this is an imported circuit. - * + * * @return true if it is imported, false otherwise. */ public boolean isImported() { @@ -934,7 +934,7 @@ public boolean isImported() { /** * Get the SubCircuit element referring to this circuit. - * + * * @return the element. */ public SubCircuit getSubElement() { @@ -992,12 +992,12 @@ public void resetAllDelays() { /** * Add a jumpstart to the list of jumpstarts in this circuit. If there is * already one with the given name, do not add it. - * + * * @param name * The name of the jumpstart. * @param start * The jumpstart object. - * + * * @return false if there already is a jumpstart with the given name, true * otherwise. */ @@ -1011,10 +1011,10 @@ public boolean addJumpStart(String name, JumpStart start) { /** * Get the jumpstart with the given name. - * + * * @param name * The name of the desired jumpstart. - * + * * @return the jumpstart, or null if it no jumpstart with the given name * exists. */ @@ -1025,7 +1025,7 @@ public JumpStart getJumpStart(String name) { /** * Get all jump start names in alphabetical order. - * + * * @return the starts. */ public Set getJumpStartNames() { @@ -1035,7 +1035,7 @@ public Set getJumpStartNames() { /** * Remove a jump start from the list. - * + * * @param name * The name of this jump start. */ @@ -1046,7 +1046,7 @@ public void removeJumpStart(String name) { /** * Set the editor of this circuit. - * + * * @param ed * The current editor, or null to indicate not being edited. */ @@ -1057,7 +1057,7 @@ public void setEditor(Editor ed) { /** * Get the editor of this circuit. - * + * * @return The current editor, or null if not being edited. */ public Editor getEditor() { @@ -1076,7 +1076,7 @@ public int getLineNumber() { /** * For debugging, return name and super.toString - * + * * @return string version of this circuit. */ public String toString() { @@ -1087,7 +1087,7 @@ public String toString() { /** * TODO: it looks like this function could use some clean up; hints at * possible circuit encoding improvements. - * + * * @param read * @return */ diff --git a/src/jls/JLSStart.java b/src/jls/JLSStart.java index 867ebc6..957d01e 100644 --- a/src/jls/JLSStart.java +++ b/src/jls/JLSStart.java @@ -89,7 +89,7 @@ public class JLSStart extends JFrame implements ChangeListener { /** * Parse command line arguments and start up JLS. - * + * * @param args Command line arguments. */ public static void start(String[] args, DefaultExceptionHandler exh) { @@ -131,7 +131,7 @@ public static void start(String[] args, DefaultExceptionHandler exh) { System.out.println(startFile + " is not a valid circuit file name"); System.exit(1); } - + Scanner input = getScannerForFile(startFile); // create new circuit @@ -191,7 +191,7 @@ public static void start(String[] args, DefaultExceptionHandler exh) { batchSim.printTrace(printer); } } - + else if (JLSInfo.imgexport) { // from Zack, for MAC's? System.setProperty("java.awt.headless", "true"); @@ -297,7 +297,7 @@ public void run() { /** * Display values of watched elements to stdout. * Descends into subcircuits recursively. - * + * * @param circ The circuit to find watched elements in. * @param qual Qualified name of subcircuit. */ @@ -336,7 +336,7 @@ else if (el instanceof SubCircuit) { /** * Parse command line. - * + * * @param args The command line arguments. */ public static void parseCommandLine(String [] args) { @@ -359,10 +359,10 @@ else if (flag == 'b') { JLSInfo.batch = true; } } - + else if (flag == 'i') { JLSInfo.imgexport = true; - } + } else if (flag == 'r') { if (arg.length() > 2) { @@ -515,13 +515,13 @@ public JLSStart() { // make it look the same everywhere (especially MAC's). try { - - UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); - + + UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); + // If on Mac, swap meta to have copy/paste/cut work String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH); if(OS.indexOf("mac") >=0 || OS.indexOf("darwin")>=0 || OS.indexOf("os x") >=0) { - // Setup file open + // Setup file open Desktop a = Desktop.getDesktop(); a.setOpenFileHandler(new OpenFilesHandler() { @@ -533,14 +533,14 @@ public void openFiles(OpenFilesEvent e) { open(fileName); } } - - }); - + + }); + // Set up copy/paste/cut - // https://stackoverflow.com/questions/1852433/use-default-keymap-of-native-os + // https://stackoverflow.com/questions/1852433/use-default-keymap-of-native-os java.awt.Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { - // Check for Command-C, Command-V, and Command-X on Mac and re-map them to control. + // Check for Command-C, Command-V, and Command-X on Mac and re-map them to control. public void eventDispatched(AWTEvent event) { KeyEvent kev = (KeyEvent) event; if (kev.getID() == KeyEvent.KEY_PRESSED) { @@ -564,8 +564,8 @@ public void eventDispatched(AWTEvent event) { } } } - }, KeyEvent.KEY_EVENT_MASK); - } + }, KeyEvent.KEY_EVENT_MASK); + } } catch (Exception ex) { @@ -640,7 +640,7 @@ public void windowClosing(WindowEvent e) { * root of the subcircuit containment. * If no tab is selected (i.e., all editors have been closed), * then the simulator's circuit is set to null. - * + * * @param event Unused. */ public void stateChanged(ChangeEvent event) { @@ -683,7 +683,7 @@ private void shutdown() { /** * Get currently visible editor. - * + * * @return the currently visible editor, or null if no editor is visible. */ public Editor getVisibleEditor() { @@ -693,7 +693,7 @@ public Editor getVisibleEditor() { /** * Set up file menu. - * + * * @return the file menu created. */ public JMenu fileMenu() { @@ -819,7 +819,7 @@ public void actionPerformed(ActionEvent event) { /** * Set up simulator menu. - * + * * @return the menu. */ public JMenu simMenu() { @@ -876,7 +876,7 @@ public void actionPerformed(ActionEvent event) { /** * Set up global change menu. - * + * * @return the menu. */ public JMenu globalMenu() { @@ -964,7 +964,7 @@ public void actionPerformed(ActionEvent event) { /** * Create help menu. - * + * * @return the menu. */ public JMenu helpMenu() { @@ -985,7 +985,7 @@ public void actionPerformed(ActionEvent event) { help.add(tutorial); JMenuItem tutorial1 = new JMenuItem("Introduction"); String tip1 = "This tutorial demonstrates the " + - "basic drawing capabilities
" + + "basic drawing capabilities
" + "using simple gates and wires, " + "and how to use the simulator  
" + "to watch the circuit in action."; @@ -997,7 +997,7 @@ public void actionPerformed(ActionEvent event) { } }); JMenuItem tutorial2 = new JMenuItem("4-Bit Counter"); - String tip2 = "Demonstrates the use of more complex  
" + + String tip2 = "Demonstrates the use of more complex  
" + "elements and multi-wire connections."; tutorial2.setToolTipText(tip2); tutorial.add(tutorial2); @@ -1090,7 +1090,7 @@ private void newCircuit() { /** * Open an existing circuit. - * + * * @param name The name of the circuit. If null, then prompt user for * the name. */ @@ -1101,7 +1101,7 @@ private void open(String filePath) { // get circuit name from user if parameter is null if (filePath == null) { JFileChooser chooser = new JFileChooser( JLSInfo.getLastSelectedDirectory() ); - + javax.swing.filechooser.FileFilter filter = new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { @@ -1112,9 +1112,9 @@ public String getDescription() { return "JLS Circuit Files"; } }; - + chooser.setFileFilter(filter); - if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) + if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) return; file = chooser.getSelectedFile(); filePath = file.getAbsolutePath(); @@ -1127,7 +1127,7 @@ public String getDescription() { JLSInfo.setLastSelectedDirectory(file.getParent()); } } - + Scanner input = getScannerForFile(filePath); String cname; @@ -1151,7 +1151,7 @@ public String getDescription() { } retrieveEditHistory(filePath, circ); - + // delete checkpoint file if there is one new File(cname + ".jls~").delete(); @@ -1162,7 +1162,7 @@ public String getDescription() { /** * Set up editor window - * + * * @param circ The circuit the editor will edit. * @param name The name of the circuit. */ @@ -1222,7 +1222,7 @@ private void closeVisibleEditor() { /** * Print circuit currently being edited, plus any state machines. - * + * * @param all True to print the entire circuit, false to print just what's visible. */ public void print(boolean all) { @@ -1262,9 +1262,9 @@ public void print(boolean all) { /** * Check for duplicate of circuit already being edited. - * + * * @param name The new name. - * + * * @return true if a duplicate, false if not. */ public boolean duplicateName(String name) { @@ -1280,7 +1280,7 @@ public boolean duplicateName(String name) { return false; } // end of duplicateName method - + private static Scanner testScanner(Scanner toTest){ if (toTest.hasNext() == false) { toTest.close(); @@ -1288,7 +1288,7 @@ private static Scanner testScanner(Scanner toTest){ } return toTest; } - + private static Scanner getZipScanner(String filePath){ try{ ZipFile target = new ZipFile(new File(filePath)); @@ -1299,7 +1299,7 @@ private static Scanner getZipScanner(String filePath){ return null; } } - + private static Scanner getTextScanner(String filePath){ try{ return testScanner(new Scanner(new File(filePath))); @@ -1307,8 +1307,8 @@ private static Scanner getTextScanner(String filePath){ return null; } } - - + + private static void retrieveEditHistory(String filePath, Circuit circuit) { try{ ZipFile target = new ZipFile(new File(filePath)); @@ -1321,37 +1321,37 @@ private static void retrieveEditHistory(String filePath, Circuit circuit) { }catch(Throwable e){ return; } - + } - + private static Scanner getScannerForFile(String filePath){ - + String name; - + name = filePath.replaceAll("\\.jls~$", ""); name = name.replaceAll("\\.jls$", ""); if (Util.isValidFileName(name) == null) { - TellUser.err(name + " is not a valid circuit file name.\n" + TellUser.err(name + " is not a valid circuit file name.\n" + "It must start with a letter and contain letters, " +"digits and underscores.", true); return null; } - + Scanner toReturn = null; - + if((toReturn = getZipScanner(filePath)) != null) return toReturn; - + if((toReturn = getTextScanner(filePath)) != null) return toReturn; - + TellUser.err("Unable to open " + name + "\n", true); return null; } - - + + /** * Import a circuit from a file into this circuit. - * @throws Exception + * @throws Exception */ public void fileImport() throws Exception { @@ -1373,9 +1373,9 @@ public String getDescription() { } }; chooser.setFileFilter(filter); - if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) + if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) return; - + Scanner input = getScannerForFile(chooser.getSelectedFile().getAbsolutePath()); // create new circuit @@ -1401,7 +1401,7 @@ public String getDescription() { /** * Check for parameter file in the current directory, - * + * * @param paramFile The name of the file containing JLS parameters. * @param circuit The circuit to apply the parameters too. */ @@ -1694,7 +1694,7 @@ else if (key.equals("RESET")) { /** * Set the propagation delay of all elements of a certain type * in a circuit and its subcircuits. - * + * * @param circ The circuit. * @param cl The type (class) of element to change. * @param delay The new propagation delay. @@ -1716,7 +1716,7 @@ else if (el.getClass() == cl) { /** * Print the circuit specified in the start file. - * + * * @param justTop True if just the top level of the circuit is to be printed, false if the whole thing. */ private static void printCirc(boolean justTop) { @@ -1725,7 +1725,7 @@ private static void printCirc(boolean justTop) { // create new circuit Circuit circ = new Circuit(name); - + try { circ.finishLoad(null); } catch (Exception e) { @@ -1780,7 +1780,7 @@ private static void printCirc(boolean justTop) { /** * Write an image of the circuit to a file. - * @throws Exception + * @throws Exception */ public void exportImage() throws Exception { @@ -1845,9 +1845,9 @@ public String getDescription() { /** * Break compound name (a.b.c) into components. - * + * * @param name The compound name. - * + * * @return the components of the name, or null if the name is not valid. */ public static Vector parseName(String name) { From 91b97c32f56c07d2db2e822cef1738cada5d2a80 Mon Sep 17 00:00:00 2001 From: Amy Wilder Date: Sun, 15 Feb 2026 14:48:59 -0500 Subject: [PATCH 3/3] Missed a spot --- src/jls/JLSStart.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jls/JLSStart.java b/src/jls/JLSStart.java index 957d01e..48220d5 100644 --- a/src/jls/JLSStart.java +++ b/src/jls/JLSStart.java @@ -1821,7 +1821,7 @@ public String getDescription() { chooser.addChoosableFileFilter(jpgFilter); chooser.addChoosableFileFilter(pngFilter); chooser.setFileFilter(filter); - if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) + if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) return; String fileName = chooser.getSelectedFile().getName().trim(); javax.swing.filechooser.FileFilter selectedFilter = chooser.getFileFilter();