From 42524619af578827c3336a40898793f312fe6177 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Thu, 14 Jan 2021 17:28:42 +1000 Subject: [PATCH] shortuts --- .../applefile/ApplesoftBasicProgram.java | 148 +++++++++--------- .../diskbrowser/applefile/SubLine.java | 6 +- .../bytezone/diskbrowser/gui/MenuHandler.java | 6 + 3 files changed, 83 insertions(+), 77 deletions(-) diff --git a/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java b/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java index 601358c..f8e0f07 100644 --- a/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java +++ b/src/com/bytezone/diskbrowser/applefile/ApplesoftBasicProgram.java @@ -41,11 +41,11 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons final List stringsLine = new ArrayList<> (); final List stringsText = new ArrayList<> (); - String formatLeft; - String formatLineNumber; - String formatRight; - String formatCall; - int maxDigits; + private final String formatLeft; + private final String formatLineNumber; + private final String formatRight; + final String formatCall; + private final int maxDigits; // ---------------------------------------------------------------------------------// public ApplesoftBasicProgram (String name, byte[] buffer) @@ -77,15 +77,15 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons for (String symbol : subline.getFunctions ()) checkFunction (symbol, line.lineNumber); for (int targetLine : subline.getGosubLines ()) - addXref (line.lineNumber, targetLine, gosubLines); + addNumberInt (line.lineNumber, targetLine, gosubLines); for (int targetLine : subline.getGotoLines ()) - addXref (line.lineNumber, targetLine, gotoLines); + addNumberInt (line.lineNumber, targetLine, gotoLines); for (int num : subline.getConstantsInt ()) addNumberInt (line.lineNumber, num, constantsInt); for (float num : subline.getConstantsFloat ()) addNumberFloat (line.lineNumber, num, constantsFloat); if (subline.callTarget != null) - addXref (line.lineNumber, subline.callTarget, callLines); + addString (line.lineNumber, subline.callTarget, callLines); } } endPtr = ptr; @@ -146,53 +146,40 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons } // ---------------------------------------------------------------------------------// - private void addXref (int sourceLine, int targetLine, Map> map) + private void addNumberInt (int sourceLine, Integer key, Map> map) // ---------------------------------------------------------------------------------// { - List lines = map.get (targetLine); + List lines = map.get (key); if (lines == null) { lines = new ArrayList<> (); - map.put (targetLine, lines); + map.put (key, lines); } lines.add (sourceLine); } // ---------------------------------------------------------------------------------// - private void addNumberInt (int sourceLine, Integer num, Map> map) + private void addNumberFloat (int sourceLine, Float key, Map> map) // ---------------------------------------------------------------------------------// { - List lines = map.get (num); + List lines = map.get (key); if (lines == null) { lines = new ArrayList<> (); - map.put (num, lines); + map.put (key, lines); } lines.add (sourceLine); } // ---------------------------------------------------------------------------------// - private void addNumberFloat (int sourceLine, Float num, Map> map) + private void addString (int sourceLine, String key, Map> map) // ---------------------------------------------------------------------------------// { - List lines = map.get (num); + List lines = map.get (key); if (lines == null) { lines = new ArrayList<> (); - map.put (num, lines); - } - lines.add (sourceLine); - } - - // ---------------------------------------------------------------------------------// - private void addXref (int sourceLine, String target, Map> map) - // ---------------------------------------------------------------------------------// - { - List lines = map.get (target); - if (lines == null) - { - lines = new ArrayList<> (); - map.put (target, lines); + map.put (key, lines); } lines.add (sourceLine); } @@ -371,10 +358,10 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons // Check for a wrappable PRINT or INPUT statement // (see FROM MACHINE LANGUAGE TO BASIC on DOSToolkit2eB.dsk) - if (basicPreferences.wrapPrintAt > 0 + if (basicPreferences.wrapPrintAt > 0 // not currently used && (subline.is (TOKEN_PRINT) || subline.is (TOKEN_INPUT)) - && countChars (text, Utility.ASCII_QUOTE) == 2 // just start and end quotes - && countChars (text, Utility.ASCII_CARET) == 0) // no control characters + && countChars (text, Utility.ASCII_QUOTE) == 2 // just start and end quotes + && countChars (text, Utility.ASCII_CARET) == 0) // no control characters wrapPrint (fullText, text, lineText); else fullText.append (text + "\n"); @@ -404,7 +391,8 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons insertBlankLine = false; } - // Reset alignment value if we just left an IF - the indentation will be different now + // Reset alignment value if we just left an IF + // - the indentation will be different now if (ifIndent > 0) alignEqualsPos = 0; } @@ -425,40 +413,52 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons private void addXref (StringBuilder fullText) // ---------------------------------------------------------------------------------// { - if (basicPreferences.showSymbols && !symbolLines.isEmpty ()) - showSymbolsLeft (fullText, symbolLines, "Var"); + if (basicPreferences.showSymbols) + { + if (!symbolLines.isEmpty ()) + showSymbolsLeft (fullText, symbolLines, "Var"); - if (basicPreferences.showSymbols && !arrayLines.isEmpty ()) - showSymbolsLeft (fullText, arrayLines, "Array"); + if (!arrayLines.isEmpty ()) + showSymbolsLeft (fullText, arrayLines, "Array"); + } - if (basicPreferences.showDuplicateSymbols && !uniqueSymbols.isEmpty ()) - showDuplicates (fullText, uniqueSymbols, "Var"); + if (basicPreferences.showDuplicateSymbols) + { + if (!uniqueSymbols.isEmpty ()) + showDuplicates (fullText, uniqueSymbols, "Var"); - if (basicPreferences.showDuplicateSymbols && !uniqueArrays.isEmpty ()) - showDuplicates (fullText, uniqueArrays, "Array"); + if (!uniqueArrays.isEmpty ()) + showDuplicates (fullText, uniqueArrays, "Array"); + } if (basicPreferences.showFunctions && !functionLines.isEmpty ()) showSymbolsLeft (fullText, functionLines, "Fnction"); - if (basicPreferences.showConstants && !constantsInt.isEmpty ()) - showSymbolsRightInt (fullText, constantsInt, "Integer"); - - if (basicPreferences.showConstants && !constantsFloat.isEmpty ()) - showSymbolsRightFloat (fullText, constantsFloat, "Float"); - - if (basicPreferences.showConstants && stringsLine.size () > 0) + if (basicPreferences.showConstants) { - heading (fullText, formatRight, "Line", "String"); - for (int i = 0; i < stringsLine.size (); i++) - fullText.append (String.format (formatRight + "%s%n", stringsLine.get (i), - stringsText.get (i))); + if (!constantsInt.isEmpty ()) + showSymbolsRightInt (fullText, constantsInt, "Integer"); + + if (!constantsFloat.isEmpty ()) + showSymbolsRightFloat (fullText, constantsFloat, "Float"); + + if (stringsLine.size () > 0) + { + heading (fullText, formatRight, "Line", "String"); + for (int i = 0; i < stringsLine.size (); i++) + fullText.append (String.format (formatRight + "%s%n", stringsLine.get (i), + stringsText.get (i))); + } } - if (basicPreferences.showXref && !gosubLines.isEmpty ()) - showSymbolsRight (fullText, gosubLines, "GOSUB"); + if (basicPreferences.showXref) + { + if (!gosubLines.isEmpty ()) + showSymbolsRight (fullText, gosubLines, "GOSUB"); - if (basicPreferences.showXref && !gotoLines.isEmpty ()) - showSymbolsRight (fullText, gotoLines, "GOTO"); + if (!gotoLines.isEmpty ()) + showSymbolsRight (fullText, gotoLines, "GOTO"); + } if (basicPreferences.showCalls && !callLines.isEmpty ()) showSymbolsLeft (fullText, callLines, "CALL"); @@ -643,23 +643,23 @@ public class ApplesoftBasicProgram extends BasicProgram implements ApplesoftCons else fullText.append (text + "\n"); } - else // old method - { - int first = text.indexOf ("\"") + 1; - int last = text.indexOf ("\"", first + 1) - 1; - if ((last - first) > basicPreferences.wrapPrintAt) - { - int ptr = first + basicPreferences.wrapPrintAt; - do - { - fullText.append (text.substring (0, ptr) - + "\n ".substring (0, first + 1)); - text.delete (0, ptr); - ptr = basicPreferences.wrapPrintAt; - } while (text.length () > basicPreferences.wrapPrintAt); - } - fullText.append (text + "\n"); - } + // else // old method + // { + // int first = text.indexOf ("\"") + 1; + // int last = text.indexOf ("\"", first + 1) - 1; + // if ((last - first) > basicPreferences.wrapPrintAt) + // { + // int ptr = first + basicPreferences.wrapPrintAt; + // do + // { + // fullText.append (text.substring (0, ptr) + // + "\n ".substring (0, first + 1)); + // text.delete (0, ptr); + // ptr = basicPreferences.wrapPrintAt; + // } while (text.length () > basicPreferences.wrapPrintAt); + // } + // fullText.append (text + "\n"); + // } } // ---------------------------------------------------------------------------------// diff --git a/src/com/bytezone/diskbrowser/applefile/SubLine.java b/src/com/bytezone/diskbrowser/applefile/SubLine.java index 9922496..fe49cd5 100644 --- a/src/com/bytezone/diskbrowser/applefile/SubLine.java +++ b/src/com/bytezone/diskbrowser/applefile/SubLine.java @@ -323,14 +323,14 @@ public class SubLine implements ApplesoftConstants { b = (byte) chunk.charAt (0); if (Utility.isDigit (b) || b == Utility.ASCII_MINUS || b == Utility.ASCII_DOT) - { addNumber (chunk); - } - else if (Utility.isLetter (b)) + else if (Utility.isLetter (b)) // quoted strings are already handled { parent.parent.stringsText.add (chunk); parent.parent.stringsLine.add (parent.lineNumber); } + else if (b != Utility.ASCII_QUOTE) + System.out.println ("Unknown data: " + chunk); } break; diff --git a/src/com/bytezone/diskbrowser/gui/MenuHandler.java b/src/com/bytezone/diskbrowser/gui/MenuHandler.java index 37ee3b3..119b06b 100755 --- a/src/com/bytezone/diskbrowser/gui/MenuHandler.java +++ b/src/com/bytezone/diskbrowser/gui/MenuHandler.java @@ -3,6 +3,7 @@ package com.bytezone.diskbrowser.gui; import java.awt.Desktop; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.Enumeration; @@ -375,6 +376,11 @@ class MenuHandler implements DiskSelectionListener, FileSelectionListener, QuitL saveDiskItem.setAction (saveTempFileAction); saveSectorsItem.setAction (saveSectorsAction); + + KeyStroke keyStroke1 = KeyStroke.getKeyStroke (KeyEvent.VK_S, KeyEvent.ALT_DOWN_MASK); + showAllFormatItem.setAccelerator (keyStroke1); + KeyStroke keyStroke2 = KeyStroke.getKeyStroke (KeyEvent.VK_L, KeyEvent.ALT_DOWN_MASK); + showAllXrefItem.setAccelerator (keyStroke2); } // ---------------------------------------------------------------------------------//