diff --git a/.settings/org.sonarlint.eclipse.core.prefs b/.settings/org.sonarlint.eclipse.core.prefs new file mode 100644 index 0000000..6c51637 --- /dev/null +++ b/.settings/org.sonarlint.eclipse.core.prefs @@ -0,0 +1,2 @@ +autoEnabled=false +eclipse.preferences.version=1 diff --git a/Mars4_5_1Unofficial.jar b/Mars4_5_1Unofficial.jar index 1de93e4..9c3bb02 100644 Binary files a/Mars4_5_1Unofficial.jar and b/Mars4_5_1Unofficial.jar differ diff --git a/mars/Settings.java b/mars/Settings.java index b648396..b006a3c 100644 --- a/mars/Settings.java +++ b/mars/Settings.java @@ -11,6 +11,7 @@ import mars.util.EditorFont; import mars.venus.editors.jeditsyntax.SyntaxStyle; import mars.venus.editors.jeditsyntax.SyntaxUtilities; +import mars.venus.editors.jeditsyntax.tokenmarker.Token; /* * Copyright (c) 2003-2013, Pete Sanderson and Kenneth Vollmar @@ -159,11 +160,7 @@ public class Settings extends Observable { public static final int SELF_MODIFYING_CODE_ENABLED = 20; // NOTE: key sequence must match up with labels above which are used for array indexes! - private static String[] booleanSettingsKeys = { "ExtendedAssembler", "BareMachine", "AssembleOnOpen", "AssembleAll", - "LabelWindowVisibility", "DisplayAddressesInHex", "DisplayValuesInHex", "LoadExceptionHandler", - "DelayedBranching", "EditorLineNumbersDisplayed", "WarningsAreErrors", "ProgramArguments", - "DataSegmentHighlighting", "RegistersHighlighting", "StartAtMain", "EditorCurrentLineHighlighting", - "PopupInstructionGuidance", "PopupSyscallInput", "GenericTextEditor", "AutoIndent", "SelfModifyingCode" }; + private static String[] booleanSettingsKeys = { "ExtendedAssembler", "BareMachine", "AssembleOnOpen", "AssembleAll", "LabelWindowVisibility", "DisplayAddressesInHex", "DisplayValuesInHex", "LoadExceptionHandler", "DelayedBranching", "EditorLineNumbersDisplayed", "WarningsAreErrors", "ProgramArguments", "DataSegmentHighlighting", "RegistersHighlighting", "StartAtMain", "EditorCurrentLineHighlighting", "PopupInstructionGuidance", "PopupSyscallInput", "GenericTextEditor", "AutoIndent", "SelfModifyingCode" }; /** * Last resort default values for boolean settings; will use only if neither the @@ -172,8 +169,7 @@ public class Settings extends Observable { * position. */ public static boolean[] defaultBooleanSettingsValues = { // match the above list by position - true, false, false, false, false, true, true, false, false, true, false, false, true, true, false, true, - true, false, false, true, false }; + true, false, false, false, false, true, true, false, false, true, false, false, true, true, false, true, true, false, false, true, false }; // STRING SETTINGS. Each array position has associated name. /** Current specified exception handler file (a MIPS assembly source file) */ @@ -194,8 +190,7 @@ public class Settings extends Observable { */ public static final int EDITOR_POPUP_PREFIX_LENGTH = 6; // Match the above by position. - private static final String[] stringSettingsKeys = { "ExceptionHandler", "TextColumnOrder", "LabelSortState", - "MemoryConfiguration", "CaretBlinkRate", "EditorTabSize", "EditorPopupPrefixLength" }; + private static final String[] stringSettingsKeys = { "ExceptionHandler", "TextColumnOrder", "LabelSortState", "MemoryConfiguration", "CaretBlinkRate", "EditorTabSize", "EditorPopupPrefixLength" }; /** * Last resort default values for String settings; will use only if neither the @@ -220,15 +215,9 @@ public class Settings extends Observable { /** Font for register highlighted background */ public static final int REGISTER_HIGHLIGHT_FONT = 6; - private static final String[] fontFamilySettingsKeys = { "EditorFontFamily", "EvenRowFontFamily", - "OddRowFontFamily", " TextSegmentHighlightFontFamily", "TextSegmentDelayslotHighightFontFamily", - "DataSegmentHighlightFontFamily", "RegisterHighlightFontFamily" }; - private static final String[] fontStyleSettingsKeys = { "EditorFontStyle", "EvenRowFontStyle", "OddRowFontStyle", - " TextSegmentHighlightFontStyle", "TextSegmentDelayslotHighightFontStyle", "DataSegmentHighlightFontStyle", - "RegisterHighlightFontStyle" }; - private static final String[] fontSizeSettingsKeys = { "EditorFontSize", "EvenRowFontSize", "OddRowFontSize", - " TextSegmentHighlightFontSize", "TextSegmentDelayslotHighightFontSize", "DataSegmentHighlightFontSize", - "RegisterHighlightFontSize" }; + private static final String[] fontFamilySettingsKeys = { "EditorFontFamily", "EvenRowFontFamily", "OddRowFontFamily", " TextSegmentHighlightFontFamily", "TextSegmentDelayslotHighightFontFamily", "DataSegmentHighlightFontFamily", "RegisterHighlightFontFamily" }; + private static final String[] fontStyleSettingsKeys = { "EditorFontStyle", "EvenRowFontStyle", "OddRowFontStyle", " TextSegmentHighlightFontStyle", "TextSegmentDelayslotHighightFontStyle", "DataSegmentHighlightFontStyle", "RegisterHighlightFontStyle" }; + private static final String[] fontSizeSettingsKeys = { "EditorFontSize", "EvenRowFontSize", "OddRowFontSize", " TextSegmentHighlightFontSize", "TextSegmentDelayslotHighightFontSize", "DataSegmentHighlightFontSize", "RegisterHighlightFontSize" }; /** * Last resort default values for Font settings; will use only if neither the @@ -241,10 +230,8 @@ public class Settings extends Observable { // Changed default font family from "Courier New" to "Monospaced" after receiving reports that Mac were not // correctly rendering the left parenthesis character in the editor or text segment display. // See http://www.mirthcorp.com/community/issues/browse/MIRTH-1921?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel - private static final String[] defaultFontFamilySettingsValues = { "Monospaced", "Monospaced", "Monospaced", - "Monospaced", "Monospaced", "Monospaced", "Monospaced" }; - private static final String[] defaultFontStyleSettingsValues = { "Plain", "Plain", "Plain", "Plain", "Plain", - "Plain", "Plain" }; + private static final String[] defaultFontFamilySettingsValues = { "Monospaced", "Monospaced", "Monospaced", "Monospaced", "Monospaced", "Monospaced", "Monospaced" }; + private static final String[] defaultFontStyleSettingsValues = { "Plain", "Plain", "Plain", "Plain", "Plain", "Plain", "Plain" }; private static final String[] defaultFontSizeSettingsValues = { "12", "12", "12", "12", "12", "12", "12", }; // COLOR SETTINGS. Each array position has associated name. @@ -273,18 +260,13 @@ public class Settings extends Observable { /** RGB color for register highlighted foreground */ public static final int REGISTER_HIGHLIGHT_FOREGROUND = 11; // Match the above by position. - private static final String[] colorSettingsKeys = { "EvenRowBackground", "EvenRowForeground", "OddRowBackground", - "OddRowForeground", "TextSegmentHighlightBackground", "TextSegmentHighlightForeground", - "TextSegmentDelaySlotHighlightBackground", "TextSegmentDelaySlotHighlightForeground", - "DataSegmentHighlightBackground", "DataSegmentHighlightForeground", "RegisterHighlightBackground", - "RegisterHighlightForeground" }; + private static final String[] colorSettingsKeys = { "EvenRowBackground", "EvenRowForeground", "OddRowBackground", "OddRowForeground", "TextSegmentHighlightBackground", "TextSegmentHighlightForeground", "TextSegmentDelaySlotHighlightBackground", "TextSegmentDelaySlotHighlightForeground", "DataSegmentHighlightBackground", "DataSegmentHighlightForeground", "RegisterHighlightBackground", "RegisterHighlightForeground" }; /** * Last resort default values for color settings; will use only if neither the * Preferences nor the properties file work. If you wish to change, do so before * instantiating the Settings object. Must match key by list position. */ - private static String[] defaultColorSettingsValues = { "0x00e0e0e0", "0", "0x00ffffff", "0", "0x00ffff99", "0", - "0x0033ff00", "0", "0x0099ccff", "0", "0x0099cc55", "0" }; + private static String[] defaultColorSettingsValues = { "0x00e0e0e0", "0", "0x00ffffff", "0", "0x00ffff99", "0", "0x0033ff00", "0", "0x0099ccff", "0", "0x0099cc55", "0" }; private final boolean[] booleanSettingsValues; private final String[] stringSettingsValues; @@ -300,9 +282,7 @@ public class Settings extends Observable { * will set based on defaults stored in Settings.properties file. If file * problems, will set based on defaults stored in this class. */ - public Settings() { - this(true); - } + public Settings() { this(true); } /** * Create Settings object and set to saved values. If saved values not found, @@ -310,7 +290,7 @@ public Settings() { * problems, will set based on defaults stored in this class. * * @param gui true if running the graphical IDE, false if running from command - * line. Ignored as of release 3.6 but retained for compatability. + * line. Ignored as of release 3.6 but retained for compatability. */ public Settings(final boolean gui) { @@ -343,28 +323,26 @@ public Settings(final boolean gui) { */ public boolean getBackSteppingEnabled() { return Globals.program != null && Globals.program.getBackStepper() != null && Globals.program.getBackStepper() - .enabled(); + .enabled(); } /** * Reset settings to default values, as described in the constructor comments. * * @param gui true if running from GUI IDE and false if running from command - * mode. Ignored as of release 3.6 but retained for compatibility. + * mode. Ignored as of release 3.6 but retained for compatibility. */ - public void reset(final boolean gui) { - initialize(); - } + public void reset(final boolean gui) { initialize(); } /* ************************************************************************** This section contains all code related to syntax highlighting styles settings. A style includes 3 components: color, bold (t/f), italic (t/f) - + The fallback defaults will come not from an array here, but from the existing static method SyntaxUtilities.getDefaultSyntaxStyles() in the mars.venus.editors.jeditsyntax package. It returns an array of SyntaxStyle objects. - + */ private String[] syntaxStyleColorSettingsValues; private boolean[] syntaxStyleBoldSettingsValues; @@ -387,13 +365,17 @@ public void setEditorSyntaxStyleByPosition(final int index, final SyntaxStyle sy } public SyntaxStyle getEditorSyntaxStyleByPosition(final int index) { - return new SyntaxStyle(getColorValueByPosition(index, syntaxStyleColorSettingsValues), - syntaxStyleItalicSettingsValues[index], syntaxStyleBoldSettingsValues[index]); + return new SyntaxStyle( + getSyntaxColorValueByPosition(index, syntaxStyleColorSettingsValues), + syntaxStyleItalicSettingsValues[index], + syntaxStyleBoldSettingsValues[index]); } public SyntaxStyle getDefaultEditorSyntaxStyleByPosition(final int index) { - return new SyntaxStyle(getColorValueByPosition(index, defaultSyntaxStyleColorSettingsValues), - defaultSyntaxStyleItalicSettingsValues[index], defaultSyntaxStyleBoldSettingsValues[index]); + return new SyntaxStyle( + getSyntaxColorValueByPosition(index, defaultSyntaxStyleColorSettingsValues), + defaultSyntaxStyleItalicSettingsValues[index], + defaultSyntaxStyleBoldSettingsValues[index]); } private void saveEditorSyntaxStyle(final int index) { @@ -434,7 +416,7 @@ private void initializeEditorSyntaxStyles() { syntaxStyleBoldSettingsKeys[i] = SYNTAX_STYLE_BOLD_PREFIX + i; syntaxStyleItalicSettingsKeys[i] = SYNTAX_STYLE_ITALIC_PREFIX + i; syntaxStyleColorSettingsValues[i] = defaultSyntaxStyleColorSettingsValues[i] = syntaxStyle[i] - .getColorAsHexString(); + .getColorAsHexString(); syntaxStyleBoldSettingsValues[i] = defaultSyntaxStyleBoldSettingsValues[i] = syntaxStyle[i].isBold(); syntaxStyleItalicSettingsValues[i] = defaultSyntaxStyleItalicSettingsValues[i] = syntaxStyle[i].isItalic(); } @@ -442,12 +424,15 @@ private void initializeEditorSyntaxStyles() { private void getEditorSyntaxStyleSettingsFromPreferences() { for (int i = 0; i < syntaxStyleColorSettingsKeys.length; i++) { - syntaxStyleColorSettingsValues[i] = preferences.get(syntaxStyleColorSettingsKeys[i], - syntaxStyleColorSettingsValues[i]); - syntaxStyleBoldSettingsValues[i] = preferences.getBoolean(syntaxStyleBoldSettingsKeys[i], - syntaxStyleBoldSettingsValues[i]); - syntaxStyleItalicSettingsValues[i] = preferences.getBoolean(syntaxStyleItalicSettingsKeys[i], - syntaxStyleItalicSettingsValues[i]); + syntaxStyleColorSettingsValues[i] = preferences.get( + syntaxStyleColorSettingsKeys[i], + syntaxStyleColorSettingsValues[i]); + syntaxStyleBoldSettingsValues[i] = preferences.getBoolean( + syntaxStyleBoldSettingsKeys[i], + syntaxStyleBoldSettingsValues[i]); + syntaxStyleItalicSettingsValues[i] = preferences.getBoolean( + syntaxStyleItalicSettingsKeys[i], + syntaxStyleItalicSettingsValues[i]); } } // ********************************************************************************* @@ -478,8 +463,7 @@ public boolean getBooleanSetting(final int id) { * * @return true if only bare machine instructions allowed, false otherwise. * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. - * Settings.BARE_MACHINE_ENABLED) + * boolean setting ID (e.g. Settings.BARE_MACHINE_ENABLED) */ @Deprecated public boolean getBareMachineEnabled() { return booleanSettingsValues[BARE_MACHINE_ENABLED]; } @@ -491,8 +475,7 @@ public boolean getBooleanSetting(final int id) { * * @return true if pseudo-instructions and formats permitted, false otherwise. * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. - * Settings.EXTENDED_ASSEMBLER_ENABLED) + * boolean setting ID (e.g. Settings.EXTENDED_ASSEMBLER_ENABLED) */ @Deprecated public boolean getExtendedAssemblerEnabled() { return booleanSettingsValues[EXTENDED_ASSEMBLER_ENABLED]; } @@ -503,10 +486,9 @@ public boolean getBooleanSetting(final int id) { * MIPSter. * * @return true if file is to be automatically assembled upon opening and false - * otherwise. + * otherwise. * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. - * Settings.ASSEMBLE_ON_OPEN_ENABLED) + * boolean setting ID (e.g. Settings.ASSEMBLE_ON_OPEN_ENABLED) */ @Deprecated public boolean getAssembleOnOpenEnabled() { return booleanSettingsValues[ASSEMBLE_ON_OPEN_ENABLED]; } @@ -516,10 +498,9 @@ public boolean getBooleanSetting(final int id) { * hexadecimal. * * @return true if addresses are displayed in hexadecimal and false otherwise - * (decimal). + * (decimal). * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. - * Settings.DISPLAY_ADDRESSES_IN_HEX) + * boolean setting ID (e.g. Settings.DISPLAY_ADDRESSES_IN_HEX) */ @Deprecated public boolean getDisplayAddressesInHex() { return booleanSettingsValues[DISPLAY_ADDRESSES_IN_HEX]; } @@ -529,10 +510,9 @@ public boolean getBooleanSetting(final int id) { * hexadecimal. * * @return true if values are displayed in hexadecimal and false otherwise - * (decimal). + * (decimal). * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. - * Settings.DISPLAY_VALUES_IN_HEX) + * boolean setting ID (e.g. Settings.DISPLAY_VALUES_IN_HEX) */ @Deprecated public boolean getDisplayValuesInHex() { return booleanSettingsValues[DISPLAY_VALUES_IN_HEX]; } @@ -545,10 +525,9 @@ public boolean getBooleanSetting(final int id) { * opened. * * @return true if all files are to be assembled, false if only the file open in - * editor. + * editor. * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. - * Settings.ASSEMBLE_ALL_ENABLED) + * boolean setting ID (e.g. Settings.ASSEMBLE_ALL_ENABLED) */ @Deprecated public boolean getAssembleAllEnabled() { return booleanSettingsValues[ASSEMBLE_ALL_ENABLED]; } @@ -558,10 +537,9 @@ public boolean getBooleanSetting(final int id) { * file) will be automatically included in each assemble operation. * * @return true if exception handler is to be included in assemble, false - * otherwise. + * otherwise. * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. - * Settings.EXCEPTION_HANDLER_ENABLED) + * boolean setting ID (e.g. Settings.EXCEPTION_HANDLER_ENABLED) */ @Deprecated public boolean getExceptionHandlerEnabled() { return booleanSettingsValues[EXCEPTION_HANDLER_ENABLED]; } @@ -575,8 +553,7 @@ public boolean getBooleanSetting(final int id) { * * @return true if delayed branching is enabled, false otherwise. * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. - * Settings.DELAYED_BRANCHING_ENABLED) + * boolean setting ID (e.g. Settings.DELAYED_BRANCHING_ENABLED) */ @Deprecated public boolean getDelayedBranchingEnabled() { return booleanSettingsValues[DELAYED_BRANCHING_ENABLED]; } @@ -587,8 +564,7 @@ public boolean getBooleanSetting(final int id) { * * @return true if label window is to be displayed, false otherwise. * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. - * Settings.LABEL_WINDOW_VISIBILITY) + * boolean setting ID (e.g. Settings.LABEL_WINDOW_VISIBILITY) */ @Deprecated public boolean getLabelWindowVisibility() { return booleanSettingsValues[LABEL_WINDOW_VISIBILITY]; } @@ -598,8 +574,7 @@ public boolean getBooleanSetting(final int id) { * * @return true if line numbers are to be displayed, false otherwise. * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. - * Settings.EDITOR_LINE_NUMBERS_DISPLAYED) + * boolean setting ID (e.g. Settings.EDITOR_LINE_NUMBERS_DISPLAYED) */ @Deprecated public boolean getEditorLineNumbersDisplayed() { return booleanSettingsValues[EDITOR_LINE_NUMBERS_DISPLAYED]; } @@ -610,8 +585,7 @@ public boolean getBooleanSetting(final int id) { * * @return true if warnings are considered errors, false otherwise. * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. - * Settings.WARNINGS_ARE_ERRORS) + * boolean setting ID (e.g. Settings.WARNINGS_ARE_ERRORS) */ @Deprecated public boolean getWarningsAreErrors() { return booleanSettingsValues[WARNINGS_ARE_ERRORS]; } @@ -621,7 +595,7 @@ public boolean getBooleanSetting(final int id) { * * @return true if program arguments can be entered/used, false otherwise. * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. Settings.PROGRAM_ARGUMENTS) + * boolean setting ID (e.g. Settings.PROGRAM_ARGUMENTS) */ @Deprecated public boolean getProgramArguments() { return booleanSettingsValues[PROGRAM_ARGUMENTS]; } @@ -632,8 +606,7 @@ public boolean getBooleanSetting(final int id) { * * @return true if highlighting is to be applied, false otherwise. * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. - * Settings.DATA_SEGMENT_HIGHLIGHTING) + * boolean setting ID (e.g. Settings.DATA_SEGMENT_HIGHLIGHTING) */ @Deprecated public boolean getDataSegmentHighlighting() { return booleanSettingsValues[DATA_SEGMENT_HIGHLIGHTING]; } @@ -644,8 +617,7 @@ public boolean getBooleanSetting(final int id) { * * @return true if highlighting is to be applied, false otherwise. * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. - * Settings.REGISTERS_HIGHLIGHTING) + * boolean setting ID (e.g. Settings.REGISTERS_HIGHLIGHTING) */ @Deprecated public boolean getRegistersHighlighting() { return booleanSettingsValues[REGISTERS_HIGHLIGHTING]; } @@ -656,7 +628,7 @@ public boolean getBooleanSetting(final int id) { * * @return true if it initializes to 'main', false otherwise. * @deprecated Use getBooleanSetting(int id) with the appropriate - * boolean setting ID (e.g. Settings.START_AT_MAIN) + * boolean setting ID (e.g. Settings.START_AT_MAIN) */ @Deprecated public boolean getStartAtMain() { return booleanSettingsValues[START_AT_MAIN]; } @@ -672,7 +644,7 @@ public boolean getBooleanSetting(final int id) { * Returns identifier of current built-in memory configuration. * * @return String identifier of current built-in memory configuration, empty if - * none. + * none. */ public String getMemoryConfiguration() { return stringSettingsValues[MEMORY_CONFIGURATION]; } @@ -692,8 +664,10 @@ public boolean getBooleanSetting(final int id) { */ public Font getFontByPosition(final int fontSettingPosition) { if (fontSettingPosition >= 0 && fontSettingPosition < fontFamilySettingsValues.length) { - return EditorFont.createFontFromStringValues(fontFamilySettingsValues[fontSettingPosition], - fontStyleSettingsValues[fontSettingPosition], fontSizeSettingsValues[fontSettingPosition]); + return EditorFont.createFontFromStringValues( + fontFamilySettingsValues[fontSettingPosition], + fontStyleSettingsValues[fontSettingPosition], + fontSizeSettingsValues[fontSettingPosition]); } else { return null; } @@ -707,9 +681,10 @@ public Font getFontByPosition(final int fontSettingPosition) { */ public Font getDefaultFontByPosition(final int fontSettingPosition) { if (fontSettingPosition >= 0 && fontSettingPosition < defaultFontFamilySettingsValues.length) { - return EditorFont.createFontFromStringValues(defaultFontFamilySettingsValues[fontSettingPosition], - defaultFontStyleSettingsValues[fontSettingPosition], - defaultFontSizeSettingsValues[fontSettingPosition]); + return EditorFont.createFontFromStringValues( + defaultFontFamilySettingsValues[fontSettingPosition], + defaultFontStyleSettingsValues[fontSettingPosition], + defaultFontSizeSettingsValues[fontSettingPosition]); } else { return null; } @@ -794,11 +769,9 @@ public int getEditorPopupPrefixLength() { * * @param key the Setting key * @return corresponding Color, or null if key not found or value not valid - * color + * color */ - public Color getColorSettingByKey(final String key) { - return getColorValueByKey(key, colorSettingsValues); - } + public Color getColorSettingByKey(final String key) { return getColorValueByKey(key, colorSettingsValues); } /** * Get default Color value for specified settings key. Returns null if key is @@ -806,7 +779,7 @@ public Color getColorSettingByKey(final String key) { * * @param key the Setting key * @return corresponding default Color, or null if key not found or value not - * valid color + * valid color */ public Color getDefaultColorSettingByKey(final String key) { return getColorValueByKey(key, defaultColorSettingsValues); @@ -818,7 +791,7 @@ public Color getDefaultColorSettingByKey(final String key) { * * @param position the Setting name (see list of static constants) * @return corresponding Color, or null if argument invalid or value not valid - * color + * color */ public Color getColorSettingByPosition(final int position) { return getColorValueByPosition(position, colorSettingsValues); @@ -830,7 +803,7 @@ public Color getColorSettingByPosition(final int position) { * * @param position the Setting name (see list of static constants) * @return corresponding default Color, or null if argument invalid or value not - * valid color + * valid color */ public Color getDefaultColorSettingByPosition(final int position) { return getColorValueByPosition(position, defaultColorSettingsValues); @@ -843,7 +816,7 @@ public Color getDefaultColorSettingByPosition(final int position) { /** * Set value of a boolean setting given its id and the value. * - * @param id int containing the setting's identifier (constants listed above) + * @param id int containing the setting's identifier (constants listed above) * @param value boolean value to store * @throws IllegalArgumentException if identifier is not valid. */ @@ -862,8 +835,8 @@ public void setBooleanSetting(final int id, final boolean value) { * * @param value True to permit, false otherwise. * @deprecated Use setBooleanSetting(int id, boolean value) with - * the appropriate boolean setting ID (e.g. - * Settings.EXTENDED_ASSEMBLER_ENABLED) + * the appropriate boolean setting ID (e.g. + * Settings.EXTENDED_ASSEMBLER_ENABLED) */ @Deprecated public void setExtendedAssemblerEnabled(final boolean value) { @@ -878,8 +851,8 @@ public void setExtendedAssemblerEnabled(final boolean value) { * * @param value True to automatically assemble, false otherwise. * @deprecated Use setBooleanSetting(int id, boolean value) with - * the appropriate boolean setting ID (e.g. - * Settings.ASSEMBLE_ON_OPEN_ENABLED) + * the appropriate boolean setting ID (e.g. + * Settings.ASSEMBLE_ON_OPEN_ENABLED) */ @Deprecated public void setAssembleOnOpenEnabled(final boolean value) { @@ -894,13 +867,11 @@ public void setAssembleOnOpenEnabled(final boolean value) { * * @param value True to assemble all, false otherwise. * @deprecated Use setBooleanSetting(int id, boolean value) with - * the appropriate boolean setting ID (e.g. - * Settings.ASSEMBLE_ALL_ENABLED) + * the appropriate boolean setting ID (e.g. + * Settings.ASSEMBLE_ALL_ENABLED) */ @Deprecated - public void setAssembleAllEnabled(final boolean value) { - internalSetBooleanSetting(ASSEMBLE_ALL_ENABLED, value); - } + public void setAssembleAllEnabled(final boolean value) { internalSetBooleanSetting(ASSEMBLE_ALL_ENABLED, value); } /** * Establish setting for whether addresses in the Execute pane will be displayed @@ -908,8 +879,8 @@ public void setAssembleAllEnabled(final boolean value) { * * @param value True to display addresses in hexadecimal, false for decimal. * @deprecated Use setBooleanSetting(int id, boolean value) with - * the appropriate boolean setting ID (e.g. - * Settings.DISPLAY_ADDRESSES_IN_HEX) + * the appropriate boolean setting ID (e.g. + * Settings.DISPLAY_ADDRESSES_IN_HEX) */ @Deprecated public void setDisplayAddressesInHex(final boolean value) { @@ -922,13 +893,11 @@ public void setDisplayAddressesInHex(final boolean value) { * * @param value True to display values in hexadecimal, false for decimal. * @deprecated Use setBooleanSetting(int id, boolean value) with - * the appropriate boolean setting ID (e.g. - * Settings.DISPLAY_VALUES_IN_HEX) + * the appropriate boolean setting ID (e.g. + * Settings.DISPLAY_VALUES_IN_HEX) */ @Deprecated - public void setDisplayValuesInHex(final boolean value) { - internalSetBooleanSetting(DISPLAY_VALUES_IN_HEX, value); - } + public void setDisplayValuesInHex(final boolean value) { internalSetBooleanSetting(DISPLAY_VALUES_IN_HEX, value); } /** * Establish setting for whether the labels window (i.e. symbol table) will be @@ -937,8 +906,8 @@ public void setDisplayValuesInHex(final boolean value) { * * @param value True to dispay labels window, false otherwise. * @deprecated Use setBooleanSetting(int id, boolean value) with - * the appropriate boolean setting ID (e.g. - * Settings.LABEL_WINDOW_VISIBILITY) + * the appropriate boolean setting ID (e.g. + * Settings.LABEL_WINDOW_VISIBILITY) */ @Deprecated public void setLabelWindowVisibility(final boolean value) { @@ -952,8 +921,8 @@ public void setLabelWindowVisibility(final boolean value) { * * @param value True to assemble exception handler, false otherwise. * @deprecated Use setBooleanSetting(int id, boolean value) with - * the appropriate boolean setting ID (e.g. - * Settings.EXCEPTION_HANDLER_ENABLED) + * the appropriate boolean setting ID (e.g. + * Settings.EXCEPTION_HANDLER_ENABLED) */ @Deprecated public void setExceptionHandlerEnabled(final boolean value) { @@ -969,8 +938,8 @@ public void setExceptionHandlerEnabled(final boolean value) { * * @param value True to enable delayed branching, false otherwise. * @deprecated Use setBooleanSetting(int id, boolean value) with - * the appropriate boolean setting ID (e.g. - * Settings.DELAYED_BRANCHING_ENABLED) + * the appropriate boolean setting ID (e.g. + * Settings.DELAYED_BRANCHING_ENABLED) */ @Deprecated @@ -984,8 +953,8 @@ public void setDelayedBranchingEnabled(final boolean value) { * * @param value True to display line numbers, false otherwise. * @deprecated Use setBooleanSetting(int id, boolean value) with - * the appropriate boolean setting ID (e.g. - * Settings.EDITOR_LINE_NUMBERS_DISPLAYED) + * the appropriate boolean setting ID (e.g. + * Settings.EDITOR_LINE_NUMBERS_DISPLAYED) */ @Deprecated public void setEditorLineNumbersDisplayed(final boolean value) { @@ -997,26 +966,22 @@ public void setEditorLineNumbersDisplayed(final boolean value) { * * @param value True to consider warnings to be errors, false otherwise. * @deprecated Use setBooleanSetting(int id, boolean value) with - * the appropriate boolean setting ID (e.g. - * Settings.WARNINGS_ARE_ERRORS) + * the appropriate boolean setting ID (e.g. + * Settings.WARNINGS_ARE_ERRORS) */ @Deprecated - public void setWarningsAreErrors(final boolean value) { - internalSetBooleanSetting(WARNINGS_ARE_ERRORS, value); - } + public void setWarningsAreErrors(final boolean value) { internalSetBooleanSetting(WARNINGS_ARE_ERRORS, value); } /** * Establish setting for whether program arguments can be ented/used. * * @param value True if program arguments can be entered/used, false otherwise. * @deprecated Use setBooleanSetting(int id, boolean value) with - * the appropriate boolean setting ID (e.g. - * Settings.PROGRAM_ARGUMENTS) + * the appropriate boolean setting ID (e.g. + * Settings.PROGRAM_ARGUMENTS) */ @Deprecated - public void setProgramArguments(final boolean value) { - internalSetBooleanSetting(PROGRAM_ARGUMENTS, value); - } + public void setProgramArguments(final boolean value) { internalSetBooleanSetting(PROGRAM_ARGUMENTS, value); } /** * Establish setting for whether highlighting is to be applied to Data Segment @@ -1024,8 +989,8 @@ public void setProgramArguments(final boolean value) { * * @param value True if highlighting is to be applied, false otherwise. * @deprecated Use setBooleanSetting(int id, boolean value) with - * the appropriate boolean setting ID (e.g. - * Settings.DATA_SEGMENT_HIGHLIGHTING) + * the appropriate boolean setting ID (e.g. + * Settings.DATA_SEGMENT_HIGHLIGHTING) */ @Deprecated public void setDataSegmentHighlighting(final boolean value) { @@ -1038,8 +1003,8 @@ public void setDataSegmentHighlighting(final boolean value) { * * @param value True if highlighting is to be applied, false otherwise. * @deprecated Use setBooleanSetting(int id, boolean value) with - * the appropriate boolean setting ID (e.g. - * Settings.REGISTERS_HIGHLIGHTING) + * the appropriate boolean setting ID (e.g. + * Settings.REGISTERS_HIGHLIGHTING) */ @Deprecated public void setRegistersHighlighting(final boolean value) { @@ -1052,21 +1017,18 @@ public void setRegistersHighlighting(final boolean value) { * * @param value True if PC set to address of 'main', false otherwise. * @deprecated Use setBooleanSetting(int id, boolean value) with - * the appropriate boolean setting ID (e.g. - * Settings.START_AT_MAIN) + * the appropriate boolean setting ID (e.g. Settings.START_AT_MAIN) */ @Deprecated - public void setStartAtMain(final boolean value) { - internalSetBooleanSetting(START_AT_MAIN, value); - } + public void setStartAtMain(final boolean value) { internalSetBooleanSetting(START_AT_MAIN, value); } /** * Temporarily establish boolean setting. This setting will NOT be written to * persisent store! Currently this is used only when running MARS from the * command line * - * @param id setting identifier. These are defined for this class as static - * final int. + * @param id setting identifier. These are defined for this class as static + * final int. * @param value True to enable the setting, false otherwise. */ public void setBooleanSettingNonPersistent(final int id, final boolean value) { @@ -1085,9 +1047,9 @@ public void setBooleanSettingNonPersistent(final int id, final boolean value) { * * @param value True to enabled delayed branching, false otherwise. * @deprecated Use - * setBooleanSettingNonPersistent(int id, boolean value) - * with the appropriate boolean setting ID (e.g. - * Settings.DELAYED_BRANCHING_ENABLED) + * setBooleanSettingNonPersistent(int id, boolean value) with the + * appropriate boolean setting ID (e.g. + * Settings.DELAYED_BRANCHING_ENABLED) */ @Deprecated public void setDelayedBranchingEnabledNonPersistent(final boolean value) { @@ -1102,38 +1064,36 @@ public void setDelayedBranchingEnabledNonPersistent(final boolean value) { * * @param newFilename name of exception handler file */ - public void setExceptionHandler(final String newFilename) { - setStringSetting(EXCEPTION_HANDLER, newFilename); - } + public void setExceptionHandler(final String newFilename) { setStringSetting(EXCEPTION_HANDLER, newFilename); } /** * Store the identifier of the memory configuration. * * @param config A string that identifies the current built-in memory - * configuration + * configuration */ - public void setMemoryConfiguration(final String config) { - setStringSetting(MEMORY_CONFIGURATION, config); - } + public void setMemoryConfiguration(final String config) { setStringSetting(MEMORY_CONFIGURATION, config); } /** * Set the caret blinking rate in milliseconds. Rate of 0 means no blinking. * * @param rate blink rate in milliseconds */ - public void setCaretBlinkRate(final int rate) { - setStringSetting(CARET_BLINK_RATE, "" + rate); - } + public void setCaretBlinkRate(final int rate) { setStringSetting( + CARET_BLINK_RATE, + "" + + rate); } /** * Set the tab size in characters. * * @param size tab size in characters. */ - public void setEditorTabSize(final int size) { - setStringSetting(EDITOR_TAB_SIZE, "" + size); - } + public void setEditorTabSize(final int size) { setStringSetting( + EDITOR_TAB_SIZE, + "" + + size); } /** * Set number of letters to be matched by editor's instruction guide before @@ -1144,7 +1104,10 @@ public void setEditorTabSize(final int size) { * @param number of letters (should be 1 or 2). */ public void setEditorPopupPrefixLength(final int length) { - setStringSetting(EDITOR_POPUP_PREFIX_LENGTH, "" + length); + setStringSetting( + EDITOR_POPUP_PREFIX_LENGTH, + "" + + length); } /** @@ -1154,15 +1117,13 @@ public void setEditorPopupPrefixLength(final int length) { * * @param font Font object to be used by text editor. */ - public void setEditorFont(final Font font) { - setFontByPosition(EDITOR_FONT, font); - } + public void setEditorFont(final Font font) { setFontByPosition(EDITOR_FONT, font); } /** * Store a Font setting * * @param fontSettingPosition Constant that identifies the item the font goes - * with + * with * @font The font to set that item to */ public void setFontByPosition(final int fontSettingPosition, final Font font) { @@ -1190,7 +1151,8 @@ public void setFontByPosition(final int fontSettingPosition, final Font font) { public void setTextColumnOrder(final int[] columnOrder) { String stringifiedOrder = new String(); for (int i = 0; i < columnOrder.length; i++) { - stringifiedOrder += Integer.toString(columnOrder[i]) + " "; + stringifiedOrder += Integer.toString(columnOrder[i]) + + " "; } setStringSetting(TEXT_COLUMN_ORDER, stringifiedOrder); } @@ -1202,14 +1164,12 @@ public void setTextColumnOrder(final int[] columnOrder) { * @param state The current labels window sorting state, as a String. */ - public void setLabelSortState(final String state) { - setStringSetting(LABEL_SORT_STATE, state); - } + public void setLabelSortState(final String state) { setStringSetting(LABEL_SORT_STATE, state); } /** * Set Color object for specified settings key. Has no effect if key is invalid. * - * @param key the Setting key + * @param key the Setting key * @param color the Color to save */ public void setColorSettingByKey(final String key, final Color color) { @@ -1226,10 +1186,12 @@ public void setColorSettingByKey(final String key, final Color color) { * effect if invalid. * * @param position the Setting name (see list of static constants) - * @param color the Color to save + * @param color the Color to save */ public void setColorSettingByPosition(final int position, final Color color) { - if (position >= 0 && position < colorSettingsKeys.length) { setColorSetting(position, color); } + if (position >= 0 && position < colorSettingsKeys.length) { + setColorSetting(position, color); + } } ///////////////////////////////////////////////////////////////////////// @@ -1247,7 +1209,7 @@ private void initialize() { applyDefaultSettings(); if (!readSettingsFromPropertiesFile(settingsFile)) { System.out.println( - "MARS System error: unable to read Settings.properties defaults. Using built-in defaults."); + "MARS System error: unable to read Settings.properties defaults. Using built-in defaults."); } getSettingsFromPreferences(); } @@ -1289,8 +1251,10 @@ private void setStringSetting(final int settingIndex, final String value) { // Used by setter methods for color-based settings private void setColorSetting(final int settingIndex, final Color color) { - colorSettingsValues[settingIndex] = Binary.intToHexString(color.getRed() << 16 | color.getGreen() << 8 | color - .getBlue()); + colorSettingsValues[settingIndex] = Binary.intToHexString( + color.getRed() << 16 + | color.getGreen() << 8 + | color.getBlue()); saveColorSetting(settingIndex); } @@ -1317,6 +1281,19 @@ private Color getColorValueByPosition(final int position, final String[] values) return color; } + // Use only for syntax style!! + private Color getSyntaxColorValueByPosition(final int position, final String[] values) { + Color color = null; + if (position >= 0 && position < Token.ID_COUNT) { + try { + color = Color.decode(values[position]); + } catch (final NumberFormatException nfe) { + color = null; + } + } + return color; + } + // Maybe someday I'll convert the whole shebang to use Maps. In the meantime, we use // linear search of array. Not a huge deal as settings are little-used. // Returns index or -1 if not found. @@ -1356,7 +1333,9 @@ private boolean readSettingsFromPropertiesFile(final String filename) { } for (int i = 0; i < stringSettingsKeys.length; i++) { settingValue = Globals.getPropertyEntry(filename, stringSettingsKeys[i]); - if (settingValue != null) { stringSettingsValues[i] = defaultStringSettingsValues[i] = settingValue; } + if (settingValue != null) { + stringSettingsValues[i] = defaultStringSettingsValues[i] = settingValue; + } } for (int i = 0; i < fontFamilySettingsValues.length; i++) { settingValue = Globals.getPropertyEntry(filename, fontFamilySettingsKeys[i]); @@ -1374,7 +1353,9 @@ private boolean readSettingsFromPropertiesFile(final String filename) { } for (int i = 0; i < colorSettingsKeys.length; i++) { settingValue = Globals.getPropertyEntry(filename, colorSettingsKeys[i]); - if (settingValue != null) { colorSettingsValues[i] = defaultColorSettingsValues[i] = settingValue; } + if (settingValue != null) { + colorSettingsValues[i] = defaultColorSettingsValues[i] = settingValue; + } } } catch (final Exception e) { return false; diff --git a/mars/venus/EditPane.java b/mars/venus/EditPane.java index 2a31175..70d9e21 100644 --- a/mars/venus/EditPane.java +++ b/mars/venus/EditPane.java @@ -98,6 +98,7 @@ public EditPane(final VenusUI appFrame) { } else { sourceCode = new JEditBasedTextArea(this, lineNumbers); } + // sourceCode is responsible for its own scrolling this.add(sourceCode.getOuterComponent(), BorderLayout.CENTER); @@ -113,12 +114,18 @@ public void insertUpdate(final DocumentEvent evt) { if (FileStatus.get() == FileStatus.OPENING) { setFileStatus(FileStatus.NOT_EDITED); FileStatus.set(FileStatus.NOT_EDITED); - if (showingLineNumbers()) { lineNumbers.setText(getLineNumbersList(sourceCode.getDocument())); } + if (showingLineNumbers()) { + lineNumbers.setText(getLineNumbersList(sourceCode.getDocument())); + } return; } // End of 9-Aug-2011 modification. - if (getFileStatus() == FileStatus.NEW_NOT_EDITED) { setFileStatus(FileStatus.NEW_EDITED); } - if (getFileStatus() == FileStatus.NOT_EDITED) { setFileStatus(FileStatus.EDITED); } + if (getFileStatus() == FileStatus.NEW_NOT_EDITED) { + setFileStatus(FileStatus.NEW_EDITED); + } + if (getFileStatus() == FileStatus.NOT_EDITED) { + setFileStatus(FileStatus.EDITED); + } if (getFileStatus() == FileStatus.NEW_EDITED) { mainUI.editor.setTitle("", getFilename(), getFileStatus()); } else { @@ -138,18 +145,16 @@ public void insertUpdate(final DocumentEvent evt) { Globals.getGui().getMainPane().getExecutePane().clearPane(); // DPS 9-Aug-2011 - if (showingLineNumbers()) { lineNumbers.setText(getLineNumbersList(sourceCode.getDocument())); } + if (showingLineNumbers()) { + lineNumbers.setText(getLineNumbersList(sourceCode.getDocument())); + } } @Override - public void removeUpdate(final DocumentEvent evt) { - insertUpdate(evt); - } + public void removeUpdate(final DocumentEvent evt) { insertUpdate(evt); } @Override - public void changedUpdate(final DocumentEvent evt) { - insertUpdate(evt); - } + public void changedUpdate(final DocumentEvent evt) { insertUpdate(evt); } }); showLineNumbers = new JCheckBox("Show Line Numbers"); @@ -193,13 +198,11 @@ public void changedUpdate(final DocumentEvent evt) { /** * For initalizing the source code when opening an ASM file * - * @param s String containing text + * @param s String containing text * @param editable set true if code is editable else false */ - public void setSourceCode(final String s, final boolean editable) { - sourceCode.setSourceCode(s, editable); - } + public void setSourceCode(final String s, final boolean editable) { sourceCode.setSourceCode(s, editable); } /** * Get rid of any accumulated undoable edits. It is useful to call this method @@ -208,9 +211,7 @@ public void setSourceCode(final String s, final boolean editable) { * a freshly-opened file to appear with its Undo action enabled. But it will * unless you call this after setting the text. */ - public void discardAllUndoableEdits() { - sourceCode.discardAllUndoableEdits(); - } + public void discardAllUndoableEdits() { sourceCode.discardAllUndoableEdits(); } /** * Form string with source code line numbers. Resulting string is HTML, for @@ -228,9 +229,14 @@ public String getLineNumbersList(final javax.swing.text.Document doc) { final String lineStr = Integer.toString(i); final int leadingSpaces = digits - lineStr.length(); if (leadingSpaces == 0) { - lineNumberList.append(lineStr + " 
"); + lineNumberList.append( + lineStr + + " 
"); } else { - lineNumberList.append(spaces.substring(0, leadingSpaces * 6) + lineStr + " 
"); + lineNumberList.append( + spaces.substring(0, leadingSpaces * 6) + + lineStr + + " 
"); } } lineNumberList.append("
"); @@ -272,9 +278,7 @@ public int getSourceLineCount() { * * @param FileStatus the status constant from class FileStatus */ - public void setFileStatus(final int fileStatus) { - this.fileStatus.setFileStatus(fileStatus); - } + public void setFileStatus(final int fileStatus) { this.fileStatus.setFileStatus(fileStatus); } /** * Get the editing status for this EditPane's associated document. This will be @@ -296,16 +300,12 @@ public void setFileStatus(final int fileStatus) { /** * Delegates to corresponding FileStatus method */ - public void setPathname(final String pathname) { - fileStatus.setPathname(pathname); - } + public void setPathname(final String pathname) { fileStatus.setPathname(pathname); } /** * Delegates to corresponding FileStatus method */ - public boolean hasUnsavedEdits() { - return fileStatus.hasUnsavedEdits(); - } + public boolean hasUnsavedEdits() { return fileStatus.hasUnsavedEdits(); } /** * Delegates to corresponding FileStatus method @@ -316,16 +316,12 @@ public boolean hasUnsavedEdits() { * Delegates to text area's requestFocusInWindow method. */ - public void tellEditingComponentToRequestFocusInWindow() { - sourceCode.requestFocusInWindow(); - } + public void tellEditingComponentToRequestFocusInWindow() { sourceCode.requestFocusInWindow(); } /** * Delegates to corresponding FileStatus method */ - public void updateStaticFileStatus() { - fileStatus.updateStaticFileStatus(); - } + public void updateStaticFileStatus() { fileStatus.updateStaticFileStatus(); } /** * get the manager in charge of Undo and Redo operations @@ -380,39 +376,29 @@ public void selectAllText() { /** * Undo previous edit */ - public void undo() { - sourceCode.undo(); - } + public void undo() { sourceCode.undo(); } /** * Redo previous edit */ - public void redo() { - sourceCode.redo(); - } + public void redo() { sourceCode.redo(); } /** * Update state of Edit menu's Undo menu item. */ - public void updateUndoState() { - mainUI.editUndoAction.updateUndoState(); - } + public void updateUndoState() { mainUI.editUndoAction.updateUndoState(); } /** * Update state of Edit menu's Redo menu item. */ - public void updateRedoState() { - mainUI.editRedoAction.updateRedoState(); - } + public void updateRedoState() { mainUI.editRedoAction.updateRedoState(); } /** * get editor's line number display status * * @return true if editor is current displaying line numbers, false otherwise. */ - public boolean showingLineNumbers() { - return showLineNumbers.isSelected(); - } + public boolean showingLineNumbers() { return showLineNumbers.isSelected(); } /** * enable or disable checkbox that controls display of line numbers @@ -431,9 +417,7 @@ public void setShowLineNumbersEnabled(final boolean enabled) { * * @param pos Offset into the text stream of caret. */ - public void displayCaretPosition(final int pos) { - displayCaretPosition(convertStreamPositionToLineColumn(pos)); - } + public void displayCaretPosition(final int pos) { displayCaretPosition(convertStreamPositionToLineColumn(pos)); } /** * Display cursor coordinates @@ -441,7 +425,11 @@ public void displayCaretPosition(final int pos) { * @param p Point object with x-y (column, line number) coordinates of cursor */ public void displayCaretPosition(final Point p) { - caretPositionLabel.setText("Line: " + p.y + " Column: " + p.x); + caretPositionLabel.setText( + "Line: " + + p.y + + " Column: " + + p.x); } /** @@ -472,10 +460,10 @@ public Point convertStreamPositionToLineColumn(final int position) { * Given line and column (position in the line) numbers, calculate its byte * stream position in text being edited. * - * @param line Line number in file (starts with 1) + * @param line Line number in file (starts with 1) * @param column Position within that line (starts with 1) * @return corresponding stream position. Returns -1 if there is no - * corresponding position. + * corresponding position. */ public int convertLineColumnToStreamPosition(final int line, final int column) { final String textStream = sourceCode.getText(); @@ -499,8 +487,7 @@ public int convertLineColumnToStreamPosition(final int line, final int column) { * consistent with line numbers displayed by the editor. * * @param line The desired line number of this TextPane's text. Numbering starts - * at 1, and nothing will happen if the parameter value is less than - * 1 + * at 1, and nothing will happen if the parameter value is less than 1 */ public void selectLine(final int line) { if (line > 0) { @@ -521,9 +508,8 @@ public void selectLine(final int line) { * Select the specified editor text line. Lines are numbered starting with 1, * consistent with line numbers displayed by the editor. * - * @param line The desired line number of this TextPane's text. Numbering - * starts at 1, and nothing will happen if the parameter value is - * less than 1 + * @param line The desired line number of this TextPane's text. Numbering starts + * at 1, and nothing will happen if the parameter value is less than 1 * @param column Desired column at which to place the cursor. */ public void selectLine(final int line, final int column) { @@ -538,7 +524,7 @@ public void selectLine(final int line, final int column) { * at the current cursor location, and wraps around when the end of the string * is reached. * - * @param find the text to locate in the string + * @param find the text to locate in the string * @param caseSensitive true if search is to be case-sensitive, false otherwise * @return TEXT_FOUND or TEXT_NOT_FOUND, depending on the result. */ @@ -552,16 +538,15 @@ public int doFindText(final String find, final boolean caseSensitive) { * then find and select the next occurrence if any. Otherwise it performs a find * operation. The replace can be undone with one undo operation. * - * @param find the text to locate in the string - * @param replace the text to replace the find text with - if the find - * text exists + * @param find the text to locate in the string + * @param replace the text to replace the find text with - if the find text + * exists * @param caseSensitive true for case sensitive. false to ignore case * @return Returns TEXT_FOUND if not initially at end of selected match and - * matching occurrence is found. Returns TEXT_NOT_FOUND if the text is - * not matched. Returns TEXT_REPLACED_NOT_FOUND_NEXT if replacement is - * successful but there are no additional matches. Returns - * TEXT_REPLACED_FOUND_NEXT if reaplacement is successful and there is - * at least one additional match. + * matching occurrence is found. Returns TEXT_NOT_FOUND if the text is not + * matched. Returns TEXT_REPLACED_NOT_FOUND_NEXT if replacement is successful + * but there are no additional matches. Returns TEXT_REPLACED_FOUND_NEXT if + * reaplacement is successful and there is at least one additional match. */ public int doReplace(final String find, final String replace, final boolean caseSensitive) { return sourceCode.doReplace(find, replace, caseSensitive); @@ -572,9 +557,9 @@ public int doReplace(final String find, final String replace, final boolean case * search. All replacements are bundled into one CompoundEdit, so one Undo * operation will undo all of them. * - * @param find the text to locate in the string - * @param replace the text to replace the find text with - if the find - * text exists + * @param find the text to locate in the string + * @param replace the text to replace the find text with - if the find text + * exists * @param caseSensitive true for case sensitive. false to ignore case * @return the number of occurrences that were matched and replaced. */ @@ -589,8 +574,8 @@ public int doReplaceAll(final String find, final String replace, final boolean c @Override public void update(final Observable fontChanger, final Object arg) { sourceCode.setFont(Globals.getSettings().getEditorFont()); - sourceCode.setLineHighlightEnabled(Globals.getSettings().getBooleanSetting( - Settings.EDITOR_CURRENT_LINE_HIGHLIGHTING)); + sourceCode.setLineHighlightEnabled( + Globals.getSettings().getBooleanSetting(Settings.EDITOR_CURRENT_LINE_HIGHLIGHTING)); sourceCode.setCaretBlinkRate(Globals.getSettings().getCaretBlinkRate()); sourceCode.setTabSize(Globals.getSettings().getEditorTabSize()); sourceCode.updateSyntaxStyles(); @@ -612,8 +597,11 @@ public void update(final Observable fontChanger, final Object arg) { * font for source code. */ private Font getLineNumberFont(final Font sourceFont) { - return sourceCode.getFont().getStyle() == Font.PLAIN ? sourceFont - : new Font(sourceFont.getFamily(), Font.PLAIN, sourceFont.getSize()); + return sourceCode.getFont().getStyle() == Font.PLAIN ? sourceFont : new Font( + sourceFont.getFamily(), + Font.PLAIN, + sourceFont.getSize()); } + public void updateColors() { sourceCode.updateColors(); } } diff --git a/mars/venus/EditTabbedPane.java b/mars/venus/EditTabbedPane.java index a42f44f..07a0e0b 100644 --- a/mars/venus/EditTabbedPane.java +++ b/mars/venus/EditTabbedPane.java @@ -104,9 +104,7 @@ public EditTabbedPane(final VenusUI appFrame, final Editor editor, final MainPan * * @param editPane The EditPane tab to become current. */ - public void setCurrentEditTab(final EditPane editPane) { - setSelectedComponent(editPane); - } + public void setCurrentEditTab(final EditPane editPane) { setSelectedComponent(editPane); } /** * If the given file is open in the tabbed pane, make it the current tab. If not @@ -115,17 +113,21 @@ public void setCurrentEditTab(final EditPane editPane) { * * @param file File object for the desired file. * @return EditPane for the specified file, or null if file is unable to be - * opened in an EditPane + * opened in an EditPane */ public EditPane getCurrentEditTabForFile(final File file) { EditPane result = null; final EditPane tab = getEditPaneForFile(file.getPath()); if (tab != null) { - if (tab != getCurrentEditTab()) { setCurrentEditTab(tab); } + if (tab != getCurrentEditTab()) { + setCurrentEditTab(tab); + } return tab; } // If no return yet, then file is not open. Try to open it. - if (openFile(file)) { result = getCurrentEditTab(); } + if (openFile(file)) { + result = getCurrentEditTab(); + } return result; } @@ -162,9 +164,7 @@ public void newFile() { * * @return true if file was opened, false otherwise. */ - public boolean openFile() { - return fileOpener.openFile(); - } + public boolean openFile() { return fileOpener.openFile(); } /** * Carries out all necessary operations to open the specified file in the @@ -172,9 +172,7 @@ public boolean openFile() { * * @return true if file was opened, false otherwise. */ - public boolean openFile(final File file) { - return fileOpener.openFile(file); - } + public boolean openFile(final File file) { return fileOpener.openFile(file); } /** * Carries out all necessary operations to implement the Close operation from @@ -213,7 +211,9 @@ public boolean closeAllFiles() { final EditPane[] tabs = new EditPane[tabCount]; for (int i = 0; i < tabCount; i++) { tabs[i] = (EditPane) getComponentAt(i); - if (tabs[i].hasUnsavedEdits()) { unsavedChanges = true; } + if (tabs[i].hasUnsavedEdits()) { + unsavedChanges = true; + } } if (unsavedChanges) { switch (confirm("one or more files")) { @@ -276,7 +276,9 @@ private boolean saveFile(final EditPane editPane) { if (editPane != null) { if (editPane.isNew()) { final File theFile = saveAsFile(editPane); - if (theFile != null) { editPane.setPathname(theFile.getPath()); } + if (theFile != null) { + editPane.setPathname(theFile.getPath()); + } return theFile != null; } final File theFile = new File(editPane.getPathname()); @@ -285,8 +287,12 @@ private boolean saveFile(final EditPane editPane) { outFileStream.write(editPane.getSource(), 0, editPane.getSource().length()); outFileStream.close(); } catch (final java.io.IOException c) { - JOptionPane.showMessageDialog(null, "Save operation could not be completed due to an error:\n" + c, - "Save Operation Failed", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog( + null, + "Save operation could not be completed due to an error:\n" + + c, + "Save Operation Failed", + JOptionPane.ERROR_MESSAGE); return false; } return true; @@ -341,7 +347,9 @@ private File saveAsFile(final EditPane editPane) { } } final String paneFile = editPane.getFilename(); - if (paneFile != null) { saveDialog.setSelectedFile(new File(paneFile)); } + if (paneFile != null) { + saveDialog.setSelectedFile(new File(paneFile)); + } // end of 13-July-2011 code. saveDialog.setDialogTitle("Save As"); @@ -350,9 +358,14 @@ private File saveAsFile(final EditPane editPane) { theFile = saveDialog.getSelectedFile(); operationOK = true; if (theFile.exists()) { - final int overwrite = JOptionPane.showConfirmDialog(mainUI, "File " + theFile.getName() - + " already exists. Do you wish to overwrite it?", "Overwrite existing file?", - JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); + final int overwrite = JOptionPane.showConfirmDialog( + mainUI, + "File " + + theFile.getName() + + " already exists. Do you wish to overwrite it?", + "Overwrite existing file?", + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.WARNING_MESSAGE); switch (overwrite) { case JOptionPane.YES_OPTION: operationOK = true; @@ -374,8 +387,12 @@ private File saveAsFile(final EditPane editPane) { outFileStream.write(editPane.getSource(), 0, editPane.getSource().length()); outFileStream.close(); } catch (final java.io.IOException c) { - JOptionPane.showMessageDialog(null, "Save As operation could not be completed due to an error:\n" + c, - "Save As Operation Failed", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog( + null, + "Save As operation could not be completed due to an error:\n" + + c, + "Save As Operation Failed", + JOptionPane.ERROR_MESSAGE); return null; } } @@ -436,7 +453,9 @@ public void remove(EditPane editPane) { } // When last file is closed, menu is unable to respond to mnemonics // and accelerators. Let's have it request focus so it may do so. - if (getTabCount() == 0) { mainUI.haveMenuRequestFocus(); } + if (getTabCount() == 0) { + mainUI.haveMenuRequestFocus(); + } } // Handy little utility to update the title on the current tab and the frame title bar @@ -463,7 +482,7 @@ private void updateTitles(final EditPane editPane) { * * @param pathname Pathname for desired file * @return the EditPane for this file if it is open in the editor, or null if - * not. + * not. */ public EditPane getEditPaneForFile(final String pathname) { EditPane openPane = null; @@ -482,7 +501,7 @@ public EditPane getEditPaneForFile(final String pathname) { * them. * * @return true if no unsaved edits or if user chooses to save them or not; - * false if there are unsaved edits and user cancels the operation. + * false if there are unsaved edits and user cancels the operation. */ public boolean editsSavedOrAbandoned() { final EditPane currentPane = getCurrentEditTab(); @@ -503,9 +522,14 @@ public boolean editsSavedOrAbandoned() { } private int confirm(final String name) { - return JOptionPane.showConfirmDialog(mainUI, "Changes to " + name - + " will be lost unless you save. Do you wish to save all changes now?", "Save program changes?", - JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); + return JOptionPane.showConfirmDialog( + mainUI, + "Changes to " + + name + + " will be lost unless you save. Do you wish to save all changes now?", + "Save program changes?", + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.WARNING_MESSAGE); } private class FileOpener { @@ -603,7 +627,9 @@ private boolean openFile(File theFile) { int lineNumber = 1; String line = Globals.program.getSourceLine(lineNumber++); while (line != null) { - fileContents.append(line + "\n"); + fileContents.append( + line + + "\n"); line = Globals.program.getSourceLine(lineNumber++); } editPane.setSourceCode(fileContents.toString(), true); @@ -657,7 +683,7 @@ private void setChoosableFileFilters() { // See if a new filter has been added to the master list. If so, // regenerate the fileChooser list from the master list. if (fileFilterCount < fileFilterList.size() || fileFilterList.size() != fileChooser - .getChoosableFileFilters().length) { + .getChoosableFileFilters().length) { fileFilterCount = fileFilterList.size(); // First, "deactivate" the listener, because our addChoosableFileFilter // calls would otherwise activate it! We want it to be triggered only @@ -674,7 +700,9 @@ private void setChoosableFileFilters() { fileChooser.addChoosableFileFilter((FileFilter) fileFilterList.get(i)); } // Restore listener. - if (activeListener) { fileChooser.addPropertyChangeListener(listenForUserAddedFileFilter); } + if (activeListener) { + fileChooser.addPropertyChangeListener(listenForUserAddedFileFilter); + } } }////////////////////////////////////////////////////////////////////////////////// // Private inner class for special property change listener. DPS 9 July 2008. diff --git a/mars/venus/Editor.java b/mars/venus/Editor.java index bf56a1e..39019f2 100644 --- a/mars/venus/Editor.java +++ b/mars/venus/Editor.java @@ -83,8 +83,8 @@ public Editor(final VenusUI ui) { * Get name of current directory for Open operation. * * @return String containing directory pathname. Returns null if there is no - * EditTabbedPane. Returns default, directory MARS is launched from, if - * no Opens have been performed. + * EditTabbedPane. Returns default, directory MARS is launched from, if no Opens + * have been performed. */ public String getCurrentOpenDirectory() { return currentOpenDirectory; } @@ -94,9 +94,8 @@ public Editor(final VenusUI ui) { * directory will be displayed when Open dialog is launched. * * @param currentOpenDirectory String containing pathname for current Open - * directory. If it does not exist or is not a - * directory, the default (MARS launch directory) - * will be used. + * directory. If it does not exist or is not a directory, the default (MARS + * launch directory) will be used. */ void setCurrentOpenDirectory(final String currentOpenDirectory) { @@ -112,8 +111,8 @@ void setCurrentOpenDirectory(final String currentOpenDirectory) { * Get name of current directory for Save or Save As operation. * * @return String containing directory pathname. Returns null if there is no - * EditTabbedPane. Returns default, directory MARS is launched from, if - * no Save or Save As operations have been performed. + * EditTabbedPane. Returns default, directory MARS is launched from, if no Save + * or Save As operations have been performed. */ public String getCurrentSaveDirectory() { return currentSaveDirectory; } @@ -123,9 +122,8 @@ void setCurrentOpenDirectory(final String currentOpenDirectory) { * directory will be displayed when Save dialog is launched. * * @param currentSaveDirectory String containing pathname for current Save - * directory. If it does not exist or is not a - * directory, the default (MARS launch directory) - * will be used. + * directory. If it does not exist or is not a directory, the default (MARS + * launch directory) will be used. */ void setCurrentSaveDirectory(final String currentSaveDirectory) { @@ -144,7 +142,9 @@ void setCurrentSaveDirectory(final String currentSaveDirectory) { */ public String getNextDefaultFilename() { newUsageCount++; - return "mips" + newUsageCount + ".asm"; + return "mips" + + newUsageCount + + ".asm"; } /** @@ -155,8 +155,8 @@ public String getNextDefaultFilename() { * name and path will be followed with an '*'. If newly-created file has not yet * been saved, the title bar will show (temporary) file name but not path. * - * @param path Full pathname for file - * @param name Name of file (last component of path) + * @param path Full pathname for file + * @param name Name of file (last component of path) * @param status Edit status of file. See FileStatus static constants. */ public void setTitle(final String path, final String name, final int status) { @@ -164,9 +164,12 @@ public void setTitle(final String path, final String name, final int status) { mainUI.setTitle(mainUIbaseTitle); } else { final String edited = status == FileStatus.NEW_EDITED || status == FileStatus.EDITED ? "*" : " "; - final String titleName = status == FileStatus.NEW_EDITED || status == FileStatus.NEW_NOT_EDITED ? name - : path; - mainUI.setTitle(titleName + edited + " - " + mainUIbaseTitle); + final String titleName = status == FileStatus.NEW_EDITED || status == FileStatus.NEW_NOT_EDITED ? name : path; + mainUI.setTitle( + titleName + + edited + + " - " + + mainUIbaseTitle); editTabbedPane.setTitleAt(editTabbedPane.getSelectedIndex(), name + edited); } } @@ -174,63 +177,49 @@ public void setTitle(final String path, final String name, final int status) { /** * Perform "new" operation to create an empty tab. */ - public void newFile() { - editTabbedPane.newFile(); - } + public void newFile() { editTabbedPane.newFile(); } /** * Perform "close" operation on current tab's file. * * @return true if succeeded, else false. */ - public boolean close() { - return editTabbedPane.closeCurrentFile(); - } + public boolean close() { return editTabbedPane.closeCurrentFile(); } /** * Close all currently open files. * * @return true if succeeded, else false. */ - public boolean closeAll() { - return editTabbedPane.closeAllFiles(); - } + public boolean closeAll() { return editTabbedPane.closeAllFiles(); } /** * Perform "save" operation on current tab's file. * * @return true if succeeded, else false. */ - public boolean save() { - return editTabbedPane.saveCurrentFile(); - } + public boolean save() { return editTabbedPane.saveCurrentFile(); } /** * Perform "save as" operation on current tab's file. * * @return true if succeeded, else false. */ - public boolean saveAs() { - return editTabbedPane.saveAsCurrentFile(); - } + public boolean saveAs() { return editTabbedPane.saveAsCurrentFile(); } /** * Perform save operation on all open files (tabs). * * @return true if succeeded, else false. */ - public boolean saveAll() { - return editTabbedPane.saveAllFiles(); - } + public boolean saveAll() { return editTabbedPane.saveAllFiles(); } /** * Open file in a new tab. * * @return true if succeeded, else false. */ - public boolean open() { - return editTabbedPane.openFile(); - } + public boolean open() { return editTabbedPane.openFile(); } /** * Called by several of the Action objects when there is potential loss of @@ -240,10 +229,18 @@ public boolean open() { * File->New, File->Open, File->Close, and File->Exit. * * @return false means user selected Cancel so caller should do that. Return of - * true means caller can proceed (edits were saved or discarded). + * true means caller can proceed (edits were saved or discarded). */ - public boolean editsSavedOrAbandoned() { - return editTabbedPane.editsSavedOrAbandoned(); + public boolean editsSavedOrAbandoned() { return editTabbedPane.editsSavedOrAbandoned(); } + + public void updateAll() { + int size = editTabbedPane.getTabCount(); + for (int i = 0; i < size; i++) { + if (editTabbedPane.getComponentAt(i) instanceof EditPane) { + EditPane p = (EditPane) editTabbedPane.getComponentAt(i); + p.updateColors(); + } + } } } diff --git a/mars/venus/SettingsEditorAction.java b/mars/venus/SettingsEditorAction.java index 5eceb67..602f811 100644 --- a/mars/venus/SettingsEditorAction.java +++ b/mars/venus/SettingsEditorAction.java @@ -43,6 +43,7 @@ import mars.venus.editors.jeditsyntax.SyntaxStyle; import mars.venus.editors.jeditsyntax.SyntaxUtilities; import mars.venus.editors.jeditsyntax.tokenmarker.MIPSTokenMarker; +import mars.venus.editors.jeditsyntax.tokenmarker.Token; /* * Copyright (c) 2003-2011, Pete Sanderson and Kenneth Vollmar @@ -91,8 +92,7 @@ public class SettingsEditorAction extends GuiAction { /** * Create a new SettingsEditorAction. Has all the GuiAction parameters. */ - public SettingsEditorAction(final String name, final Icon icon, final String descrip, final Integer mnemonic, - final KeyStroke accel, final VenusUI gui) { + public SettingsEditorAction(final String name, final Icon icon, final String descrip, final Integer mnemonic, final KeyStroke accel, final VenusUI gui) { super(name, icon, descrip, mnemonic, accel, gui); } @@ -102,15 +102,20 @@ public SettingsEditorAction(final String name, final Icon icon, final String des */ @Override public void actionPerformed(final ActionEvent e) { - editorDialog = new EditorFontDialog(Globals.getGui(), "Text Editor Settings", true, Globals.getSettings() - .getEditorFont()); + editorDialog = new EditorFontDialog( + Globals.getGui(), + "Text Editor Settings", + true, + Globals.getSettings().getEditorFont()); editorDialog.setVisible(true); } private static final int gridVGap = 2; private static final int gridHGap = 2; - private static final Border ColorSelectButtonEnabledBorder = new BevelBorder(BevelBorder.RAISED, Color.WHITE, + private static final Border ColorSelectButtonEnabledBorder = new BevelBorder( + BevelBorder.RAISED, + Color.WHITE, Color.GRAY); private static final Border ColorSelectButtonDisabledBorder = new LineBorder(Color.GRAY, 2); @@ -129,10 +134,7 @@ public void actionPerformed(final ActionEvent e) { private static final String BLINK_SAMPLE_TOOL_TIP_TEXT = "Displays current blinking rate"; private static final String CURRENT_LINE_HIGHLIGHT_TOOL_TIP_TEXT = "Check, to highlight line currently being edited"; private static final String AUTO_INDENT_TOOL_TIP_TEXT = "Check, to enable auto-indent to previous line when Enter key is pressed"; - private static final String[] POPUP_GUIDANCE_TOOL_TIP_TEXT = { - "Turns off instruction and directive guide popup while typing", - "Generates instruction guide popup after first letter of potential instruction is typed", - "Generates instruction guide popup after second letter of potential instruction is typed" }; + private static final String[] POPUP_GUIDANCE_TOOL_TIP_TEXT = { "Turns off instruction and directive guide popup while typing", "Generates instruction guide popup after first letter of potential instruction is typed", "Generates instruction guide popup after second letter of potential instruction is typed" }; // Concrete font chooser class. private class EditorFontDialog extends AbstractFontSettingDialog { @@ -166,6 +168,9 @@ private class EditorFontDialog extends AbstractFontSettingDialog { private int initialEditorTabSize, initialCaretBlinkRate, initialPopupGuidance; private boolean initialLineHighlighting, initialGenericTextEditor, initialAutoIndent; + private int editorLineRow = -1; + private int editorSelRow = -1; + public EditorFontDialog(final Frame owner, final String title, final boolean modality, final Font font) { super(owner, title, modality, font); if (Globals.getSettings().getBooleanSetting(Settings.GENERIC_TEXT_EDITOR)) { @@ -244,15 +249,17 @@ protected Component buildControlPanel() { @Override protected void apply(final Font font) { Globals.getSettings().setBooleanSetting(Settings.GENERIC_TEXT_EDITOR, genericEditorCheck.isSelected()); - Globals.getSettings().setBooleanSetting(Settings.EDITOR_CURRENT_LINE_HIGHLIGHTING, lineHighlightCheck - .isSelected()); + Globals.getSettings() + .setBooleanSetting(Settings.EDITOR_CURRENT_LINE_HIGHLIGHTING, lineHighlightCheck.isSelected()); Globals.getSettings().setBooleanSetting(Settings.AUTO_INDENT, autoIndentCheck.isSelected()); Globals.getSettings().setCaretBlinkRate(((Integer) blinkRateSpinSelector.getValue())); Globals.getSettings().setEditorTabSize(tabSizeSelector.getValue()); if (syntaxStylesAction) { for (int i = 0; i < syntaxStyleIndex.length; i++) { - Globals.getSettings().setEditorSyntaxStyleByPosition(syntaxStyleIndex[i], new SyntaxStyle(samples[i] - .getForeground(), italic[i].isSelected(), bold[i].isSelected())); + Globals.getSettings() + .setEditorSyntaxStyleByPosition( + syntaxStyleIndex[i], + new SyntaxStyle(samples[i].getForeground(), italic[i].isSelected(), bold[i].isSelected())); } syntaxStylesAction = false; // reset } @@ -268,6 +275,7 @@ protected void apply(final Font font) { break; } } + mainUI.getEditor().updateAll(); } // User has clicked "Reset" button. Put everything back to initial state. @@ -298,14 +306,21 @@ private JPanel buildOtherSettingsPanel() { // Tab size selector initialEditorTabSize = Globals.getSettings().getEditorTabSize(); tabSizeSelector = new JSlider(Editor.MIN_TAB_SIZE, Editor.MAX_TAB_SIZE, initialEditorTabSize); - tabSizeSelector.setToolTipText("Use slider to select tab size from " + Editor.MIN_TAB_SIZE + " to " - + Editor.MAX_TAB_SIZE + "."); + tabSizeSelector.setToolTipText( + "Use slider to select tab size from " + + Editor.MIN_TAB_SIZE + + " to " + + Editor.MAX_TAB_SIZE + + "."); tabSizeSelector.addChangeListener(e -> { final Integer value = new Integer(((JSlider) e.getSource()).getValue()); tabSizeSpinSelector.setValue(value); }); - final SpinnerNumberModel tabSizeSpinnerModel = new SpinnerNumberModel(initialEditorTabSize, - Editor.MIN_TAB_SIZE, Editor.MAX_TAB_SIZE, 1); + final SpinnerNumberModel tabSizeSpinnerModel = new SpinnerNumberModel( + initialEditorTabSize, + Editor.MIN_TAB_SIZE, + Editor.MAX_TAB_SIZE, + 1); tabSizeSpinSelector = new JSpinner(tabSizeSpinnerModel); tabSizeSpinSelector.setToolTipText(TAB_SIZE_TOOL_TIP_TEXT); tabSizeSpinSelector.addChangeListener(e -> { @@ -314,8 +329,8 @@ private JPanel buildOtherSettingsPanel() { }); // highlighting of current line - initialLineHighlighting = Globals.getSettings().getBooleanSetting( - Settings.EDITOR_CURRENT_LINE_HIGHLIGHTING); + initialLineHighlighting = Globals.getSettings() + .getBooleanSetting(Settings.EDITOR_CURRENT_LINE_HIGHLIGHTING); lineHighlightCheck = new JCheckBox("Highlight the line currently being edited"); lineHighlightCheck.setSelected(initialLineHighlighting); lineHighlightCheck.setToolTipText(CURRENT_LINE_HIGHLIGHT_TOOL_TIP_TEXT); @@ -335,8 +350,11 @@ private JPanel buildOtherSettingsPanel() { blinkCaret = blinkSample.getCaret(); blinkCaret.setBlinkRate(initialCaretBlinkRate); blinkCaret.setVisible(true); - final SpinnerNumberModel blinkRateSpinnerModel = new SpinnerNumberModel(initialCaretBlinkRate, - Editor.MIN_BLINK_RATE, Editor.MAX_BLINK_RATE, 100); + final SpinnerNumberModel blinkRateSpinnerModel = new SpinnerNumberModel( + initialCaretBlinkRate, + Editor.MIN_BLINK_RATE, + Editor.MAX_BLINK_RATE, + 100); blinkRateSpinSelector = new JSpinner(blinkRateSpinnerModel); blinkRateSpinSelector.setToolTipText(BLINK_SPINNER_TOOL_TIP_TEXT); blinkRateSpinSelector.addChangeListener(e -> { @@ -375,9 +393,9 @@ private JPanel buildOtherSettingsPanel() { popupGuidanceOptions[i].setToolTipText(POPUP_GUIDANCE_TOOL_TIP_TEXT[i]); popupGuidanceButtons.add(popupGuidanceOptions[i]); } - initialPopupGuidance = Globals.getSettings().getBooleanSetting(Settings.POPUP_INSTRUCTION_GUIDANCE) - ? Globals.getSettings().getEditorPopupPrefixLength() - : 0; + initialPopupGuidance = Globals.getSettings() + .getBooleanSetting(Settings.POPUP_INSTRUCTION_GUIDANCE) ? Globals.getSettings() + .getEditorPopupPrefixLength() : 0; popupGuidanceOptions[initialPopupGuidance].setSelected(true); new JPanel(new GridLayout(3, 1)); rightColumnSettingsPanel.setBorder(BorderFactory.createTitledBorder("Popup Instruction Guide")); @@ -401,7 +419,9 @@ private JPanel buildSyntaxStylePanel() { int count = 0; // Count the number of actual styles specified for (int i = 0; i < labels.length; i++) { - if (labels[i] != null) { count++; } + if (labels[i] != null) { + count++; + } } // create new arrays (no gaps) for grid display, refer to original index syntaxStyleIndex = new int[count]; @@ -429,7 +449,17 @@ private JPanel buildSyntaxStylePanel() { samples[count].setBackground(Color.WHITE); samples[count].setToolTipText(SAMPLE_TOOL_TIP_TEXT); foregroundButtons[count] = new ColorSelectButton(); // defined in SettingsHighlightingAction - foregroundButtons[count].addActionListener(new ForegroundChanger(count)); + if (i == Token.EDITOR_BG) { + foregroundButtons[count].addActionListener(new BackgroundChanger(count)); + } else if (i == Token.EDITOR_LINE) { + foregroundButtons[count].addActionListener(new ForegroundChanger(count)); + editorLineRow = count; + } else if (i == Token.EDITOR_SELECTION) { + foregroundButtons[count].addActionListener(new ForegroundChanger(count)); + editorSelRow = count; + } else { + foregroundButtons[count].addActionListener(new ForegroundChanger(count)); + } foregroundButtons[count].setToolTipText(FOREGROUND_TOOL_TIP_TEXT); final BoldItalicChanger boldItalicChanger = new BoldItalicChanger(count); bold[count] = new JToggleButton(BOLD_BUTTON_TOOL_TIP_TEXT, false); @@ -440,9 +470,18 @@ private JPanel buildSyntaxStylePanel() { italic[count].setFont(italicFont); italic[count].addActionListener(boldItalicChanger); italic[count].setToolTipText(ITALIC_TOOL_TIP_TEXT); + if (i == Token.EDITOR_BG || i == Token.EDITOR_LINE || i == Token.EDITOR_SELECTION) { + samples[count].setVisible(false); + bold[count].setVisible(false); + italic[count].setVisible(false); + } label[count] = labels[i]; useDefault[count] = new JCheckBox(); - useDefault[count].addItemListener(new DefaultChanger(count)); + if (i == Token.EDITOR_BG) { + useDefault[count].addItemListener(new DefaultChangerEditorBG(count)); + } else { + useDefault[count].addItemListener(new DefaultChanger(count)); + } useDefault[count].setToolTipText(DEFAULT_TOOL_TIP_TEXT); count++; } @@ -488,18 +527,27 @@ private void initializeSyntaxStyleChangeables() { final int i = syntaxStyleIndex[count]; samples[count].setFont(previewFont); samples[count].setForeground(initialStyles[i].getColor()); + if (count != editorLineRow && count != editorSelRow) { + samples[count].setBackground(initialStyles[Token.EDITOR_BG].getColor()); + } foregroundButtons[count].setBackground(initialStyles[i].getColor()); foregroundButtons[count].setEnabled(true); currentStyles[count] = initialStyles[i]; bold[count].setSelected(initialStyles[i].isBold()); if (bold[count].isSelected()) { final Font f = samples[count].getFont(); - samples[count].setFont(f.deriveFont(f.getStyle() ^ Font.BOLD)); + samples[count].setFont( + f.deriveFont( + f.getStyle() + ^ Font.BOLD)); } italic[count].setSelected(initialStyles[i].isItalic()); if (italic[count].isSelected()) { final Font f = samples[count].getFont(); - samples[count].setFont(f.deriveFont(f.getStyle() ^ Font.ITALIC)); + samples[count].setFont( + f.deriveFont( + f.getStyle() + ^ Font.ITALIC)); } useDefault[count].setSelected(initialStyles[i].toString().equals(defaultStyles[i].toString())); if (useDefault[count].isSelected()) { @@ -513,8 +561,16 @@ private void initializeSyntaxStyleChangeables() { // set the foreground color, bold and italic of sample (a JLabel) private void setSampleStyles(final JLabel sample, final SyntaxStyle style) { Font f = previewFont; - if (style.isBold()) { f = f.deriveFont(f.getStyle() ^ Font.BOLD); } - if (style.isItalic()) { f = f.deriveFont(f.getStyle() ^ Font.ITALIC); } + if (style.isBold()) { + f = f.deriveFont( + f.getStyle() + ^ Font.BOLD); + } + if (style.isItalic()) { + f = f.deriveFont( + f.getStyle() + ^ Font.ITALIC); + } sample.setFont(f); sample.setForeground(style.getColor()); } @@ -525,27 +581,39 @@ private class BoldItalicChanger implements ActionListener { private final int row; - public BoldItalicChanger(final int row) { - this.row = row; - } + public BoldItalicChanger(final int row) { this.row = row; } @Override public void actionPerformed(final ActionEvent e) { final Font f = samples[row].getFont(); if (e.getActionCommand() == BOLD_BUTTON_TOOL_TIP_TEXT) { if (bold[row].isSelected()) { - samples[row].setFont(f.deriveFont(f.getStyle() | Font.BOLD)); + samples[row].setFont( + f.deriveFont( + f.getStyle() + | Font.BOLD)); } else { - samples[row].setFont(f.deriveFont(f.getStyle() ^ Font.BOLD)); + samples[row].setFont( + f.deriveFont( + f.getStyle() + ^ Font.BOLD)); } } else { if (italic[row].isSelected()) { - samples[row].setFont(f.deriveFont(f.getStyle() | Font.ITALIC)); + samples[row].setFont( + f.deriveFont( + f.getStyle() + | Font.ITALIC)); } else { - samples[row].setFont(f.deriveFont(f.getStyle() ^ Font.ITALIC)); + samples[row].setFont( + f.deriveFont( + f.getStyle() + ^ Font.ITALIC)); } } - currentStyles[row] = new SyntaxStyle(foregroundButtons[row].getBackground(), italic[row].isSelected(), + currentStyles[row] = new SyntaxStyle( + foregroundButtons[row].getBackground(), + italic[row].isSelected(), bold[row].isSelected()); syntaxStylesAction = true; @@ -558,37 +626,56 @@ public void actionPerformed(final ActionEvent e) { // private class ForegroundChanger implements ActionListener { - private final int row; + protected final int row; + protected Color selection; - public ForegroundChanger(final int pos) { - row = pos; - } + public ForegroundChanger(final int pos) { row = pos; } @Override public void actionPerformed(final ActionEvent e) { final JButton button = (JButton) e.getSource(); - final Color newColor = JColorChooser.showDialog(null, "Set Text Color", button.getBackground()); - if (newColor != null) { - button.setBackground(newColor); - samples[row].setForeground(newColor); + selection = JColorChooser.showDialog(null, "Set Text Color", button.getBackground()); + if (selection != null) { + button.setBackground(selection); + samples[row].setForeground(selection); } - currentStyles[row] = new SyntaxStyle(button.getBackground(), italic[row].isSelected(), bold[row] - .isSelected()); + currentStyles[row] = new SyntaxStyle( + button.getBackground(), + italic[row].isSelected(), + bold[row].isSelected()); syntaxStylesAction = true; } } + ///////////////////////////////////////////////////////////////// + // + // Class that handles click on only the editor background selection button + // + private class BackgroundChanger extends ForegroundChanger { + + public BackgroundChanger(final int pos) { super(pos); } + + @Override + public void actionPerformed(final ActionEvent e) { + super.actionPerformed(e); + for (JLabel c : samples) { + if (c.getText().equals("")) { + continue; + } + c.setBackground(selection); + } + } + } + ///////////////////////////////////////////////////////////////// // // Class that handles action (check, uncheck) on the Default checkbox. // private class DefaultChanger implements ItemListener { - private final int row; + protected final int row; - public DefaultChanger(final int pos) { - row = pos; - } + public DefaultChanger(final int pos) { row = pos; } @Override public void itemStateChanged(final ItemEvent e) { @@ -597,8 +684,10 @@ public void itemStateChanged(final ItemEvent e) { foregroundButtons[row].setEnabled(false); bold[row].setEnabled(false); italic[row].setEnabled(false); - currentStyles[row] = new SyntaxStyle(foregroundButtons[row].getBackground(), italic[row] - .isSelected(), bold[row].isSelected()); + currentStyles[row] = new SyntaxStyle( + foregroundButtons[row].getBackground(), + italic[row].isSelected(), + bold[row].isSelected()); final SyntaxStyle defaultStyle = defaultStyles[syntaxStyleIndex[row]]; setSampleStyles(samples[row], defaultStyle); foregroundButtons[row].setBackground(defaultStyle.getColor()); @@ -616,6 +705,34 @@ public void itemStateChanged(final ItemEvent e) { syntaxStylesAction = true; } } + + ///////////////////////////////////////////////////////////////// + // + // Class that handles action (check, uncheck) on the Default checkbox. + // + private class DefaultChangerEditorBG extends DefaultChanger { + + public DefaultChangerEditorBG(final int pos) { super(pos); } + + @Override + public void itemStateChanged(final ItemEvent e) { + super.itemStateChanged(e); + Color bg; + if (e.getStateChange() == ItemEvent.SELECTED) { + final SyntaxStyle defaultStyle = defaultStyles[syntaxStyleIndex[row]]; + bg = defaultStyle.getColor(); + } else { + bg = currentStyles[row].getColor(); + } + for (int i = 0; i < samples.length; i++) { + if (samples[i].getText().equals("")) { + continue; + } + samples[i].setBackground(bg); + } + } + } + } } diff --git a/mars/venus/VenusUI.java b/mars/venus/VenusUI.java index 1345699..174d856 100644 --- a/mars/venus/VenusUI.java +++ b/mars/venus/VenusUI.java @@ -155,11 +155,14 @@ public VenusUI(final String s) { final double registersWidthPct = screenWidth < 1000.0 ? 0.18 : 0.22; final double registersHeightPct = screenWidth < 1000.0 ? 0.72 : 0.80; - final Dimension messagesPanePreferredSize = new Dimension((int) (screenWidth * messageWidthPct), + final Dimension messagesPanePreferredSize = new Dimension( + (int) (screenWidth * messageWidthPct), (int) (screenHeight * messageHeightPct)); - final Dimension mainPanePreferredSize = new Dimension((int) (screenWidth * mainWidthPct), (int) (screenHeight - * mainHeightPct)); - final Dimension registersPanePreferredSize = new Dimension((int) (screenWidth * registersWidthPct), + final Dimension mainPanePreferredSize = new Dimension( + (int) (screenWidth * mainWidthPct), + (int) (screenHeight * mainHeightPct)); + final Dimension registersPanePreferredSize = new Dimension( + (int) (screenWidth * registersWidthPct), (int) (screenHeight * registersHeightPct)); // the "restore" size (window control button that toggles with maximize) @@ -169,7 +172,10 @@ public VenusUI(final String s) { Globals.initialize(true); // image courtesy of NASA/JPL. - final URL im = this.getClass().getResource(Globals.imagesPath + "RedMars16.gif"); + final URL im = this.getClass() + .getResource( + Globals.imagesPath + + "RedMars16.gif"); if (im == null) { System.out.println("Internal Error: images folder or file not found"); System.exit(0); @@ -236,9 +242,7 @@ public VenusUI(final String s) { addWindowListener(new WindowAdapter() { @Override - public void windowOpened(final WindowEvent e) { - mainUI.setExtendedState(Frame.MAXIMIZED_BOTH); - } + public void windowOpened(final WindowEvent e) { mainUI.setExtendedState(Frame.MAXIMIZED_BOTH); } }); // This is invoked when exiting the app through the X icon. It will in turn @@ -247,7 +251,9 @@ public void windowOpened(final WindowEvent e) { @Override public void windowClosing(final WindowEvent e) { - if (mainUI.editor.closeAll()) { System.exit(0); } + if (mainUI.editor.closeAll()) { + System.exit(0); + } } }); @@ -269,138 +275,393 @@ private void createActionObjects() { final Toolkit tk = Toolkit.getDefaultToolkit(); final Class cs = this.getClass(); try { - fileNewAction = new FileNewAction("New", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath - + "New22.png"))), "Create a new file for editing", new Integer(KeyEvent.VK_N), KeyStroke - .getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI); - fileOpenAction = new FileOpenAction("Open ...", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath - + "Open22.png"))), "Open a file for editing", new Integer(KeyEvent.VK_O), KeyStroke.getKeyStroke( - KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI); - fileCloseAction = new FileCloseAction("Close", null, "Close the current file", new Integer(KeyEvent.VK_C), + fileNewAction = new FileNewAction( + "New", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "New22.png"))), + "Create a new file for editing", + new Integer(KeyEvent.VK_N), + KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + mainUI); + fileOpenAction = new FileOpenAction( + "Open ...", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Open22.png"))), + "Open a file for editing", + new Integer(KeyEvent.VK_O), + KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + mainUI); + fileCloseAction = new FileCloseAction( + "Close", + null, + "Close the current file", + new Integer(KeyEvent.VK_C), KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI); - fileCloseAllAction = new FileCloseAllAction("Close All", null, "Close all open files", new Integer( - KeyEvent.VK_L), null, mainUI); - fileSaveAction = new FileSaveAction("Save", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath - + "Save22.png"))), "Save the current file", new Integer(KeyEvent.VK_S), KeyStroke.getKeyStroke( - KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI); - fileSaveAsAction = new FileSaveAsAction("Save as ...", new ImageIcon(tk.getImage(cs.getResource( - Globals.imagesPath + "SaveAs22.png"))), "Save current file with different name", new Integer( - KeyEvent.VK_A), null, mainUI); - fileSaveAllAction = new FileSaveAllAction("Save All", null, "Save all open files", new Integer( - KeyEvent.VK_V), null, mainUI); - fileDumpMemoryAction = new FileDumpMemoryAction("Dump Memory ...", new ImageIcon(tk.getImage(cs.getResource( - Globals.imagesPath + "Dump22.png"))), "Dump machine code or data in an available format", - new Integer(KeyEvent.VK_D), KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit() - .getMenuShortcutKeyMask()), mainUI); - filePrintAction = new FilePrintAction("Print ...", new ImageIcon(tk.getImage(cs.getResource( - Globals.imagesPath + "Print22.gif"))), "Print current file", new Integer(KeyEvent.VK_P), null, + fileCloseAllAction = new FileCloseAllAction( + "Close All", + null, + "Close all open files", + new Integer(KeyEvent.VK_L), + null, + mainUI); + fileSaveAction = new FileSaveAction( + "Save", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Save22.png"))), + "Save the current file", + new Integer(KeyEvent.VK_S), + KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + mainUI); + fileSaveAsAction = new FileSaveAsAction( + "Save as ...", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "SaveAs22.png"))), + "Save current file with different name", + new Integer(KeyEvent.VK_A), + null, + mainUI); + fileSaveAllAction = new FileSaveAllAction( + "Save All", + null, + "Save all open files", + new Integer(KeyEvent.VK_V), + null, + mainUI); + fileDumpMemoryAction = new FileDumpMemoryAction( + "Dump Memory ...", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Dump22.png"))), + "Dump machine code or data in an available format", + new Integer(KeyEvent.VK_D), + KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + mainUI); + filePrintAction = new FilePrintAction( + "Print ...", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Print22.gif"))), + "Print current file", + new Integer(KeyEvent.VK_P), + null, mainUI); fileExitAction = new FileExitAction("Exit", null, "Exit Mars", new Integer(KeyEvent.VK_X), null, mainUI); - editUndoAction = new EditUndoAction("Undo", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath - + "Undo22.png"))), "Undo last edit", new Integer(KeyEvent.VK_U), KeyStroke.getKeyStroke( - KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI); - editRedoAction = new EditRedoAction("Redo", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath - + "Redo22.png"))), "Redo last edit", new Integer(KeyEvent.VK_R), KeyStroke.getKeyStroke( - KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI); - editCutAction = new EditCutAction("Cut", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath - + "Cut22.gif"))), "Cut", new Integer(KeyEvent.VK_C), KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit - .getDefaultToolkit().getMenuShortcutKeyMask()), mainUI); - editCopyAction = new EditCopyAction("Copy", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath - + "Copy22.png"))), "Copy", new Integer(KeyEvent.VK_O), KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit - .getDefaultToolkit().getMenuShortcutKeyMask()), mainUI); - editPasteAction = new EditPasteAction("Paste", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath - + "Paste22.png"))), "Paste", new Integer(KeyEvent.VK_P), KeyStroke.getKeyStroke(KeyEvent.VK_V, - Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI); - editFindReplaceAction = new EditFindReplaceAction("Find/Replace", new ImageIcon(tk.getImage(cs.getResource( - Globals.imagesPath + "Find22.png"))), "Find/Replace", new Integer(KeyEvent.VK_F), KeyStroke - .getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI); - editSelectAllAction = new EditSelectAllAction("Select All", null, //new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Find22.png"))), - "Select All", new Integer(KeyEvent.VK_A), KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit - .getDefaultToolkit().getMenuShortcutKeyMask()), mainUI); - runAssembleAction = new RunAssembleAction("Assemble", new ImageIcon(tk.getImage(cs.getResource( - Globals.imagesPath + "Assemble22.png"))), "Assemble the current file and clear breakpoints", - new Integer(KeyEvent.VK_A), KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), mainUI); - runGoAction = new RunGoAction("Go", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath - + "Play22.png"))), "Run the current program", new Integer(KeyEvent.VK_G), KeyStroke.getKeyStroke( - KeyEvent.VK_F5, 0), mainUI); - runStepAction = new RunStepAction("Step", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath - + "StepForward22.png"))), "Run one step at a time", new Integer(KeyEvent.VK_T), KeyStroke - .getKeyStroke(KeyEvent.VK_F7, 0), mainUI); - runBackstepAction = new RunBackstepAction("Backstep", new ImageIcon(tk.getImage(cs.getResource( - Globals.imagesPath + "StepBack22.png"))), "Undo the last step", new Integer(KeyEvent.VK_B), - KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0), mainUI); - runPauseAction = new RunPauseAction("Pause", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath - + "Pause22.png"))), "Pause the currently running program", new Integer(KeyEvent.VK_P), KeyStroke - .getKeyStroke(KeyEvent.VK_F9, 0), mainUI); - runStopAction = new RunStopAction("Stop", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath - + "Stop22.png"))), "Stop the currently running program", new Integer(KeyEvent.VK_S), KeyStroke - .getKeyStroke(KeyEvent.VK_F11, 0), mainUI); - runResetAction = new RunResetAction("Reset", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath - + "Reset22.png"))), "Reset MIPS memory and registers", new Integer(KeyEvent.VK_R), KeyStroke - .getKeyStroke(KeyEvent.VK_F12, 0), mainUI); - runClearBreakpointsAction = new RunClearBreakpointsAction("Clear all breakpoints", null, - "Clears all execution breakpoints set since the last assemble.", new Integer(KeyEvent.VK_K), + editUndoAction = new EditUndoAction( + "Undo", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Undo22.png"))), + "Undo last edit", + new Integer(KeyEvent.VK_U), + KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + mainUI); + editRedoAction = new EditRedoAction( + "Redo", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Redo22.png"))), + "Redo last edit", + new Integer(KeyEvent.VK_R), + KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + mainUI); + editCutAction = new EditCutAction( + "Cut", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Cut22.gif"))), + "Cut", + new Integer(KeyEvent.VK_C), + KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + mainUI); + editCopyAction = new EditCopyAction( + "Copy", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Copy22.png"))), + "Copy", + new Integer(KeyEvent.VK_O), + KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + mainUI); + editPasteAction = new EditPasteAction( + "Paste", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Paste22.png"))), + "Paste", + new Integer(KeyEvent.VK_P), + KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + mainUI); + editFindReplaceAction = new EditFindReplaceAction( + "Find/Replace", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Find22.png"))), + "Find/Replace", + new Integer(KeyEvent.VK_F), + KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + mainUI); + editSelectAllAction = new EditSelectAllAction( + "Select All", + null, //new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath+"Find22.png"))), + "Select All", + new Integer(KeyEvent.VK_A), + KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + mainUI); + runAssembleAction = new RunAssembleAction( + "Assemble", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Assemble22.png"))), + "Assemble the current file and clear breakpoints", + new Integer(KeyEvent.VK_A), + KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), + mainUI); + runGoAction = new RunGoAction( + "Go", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Play22.png"))), + "Run the current program", + new Integer(KeyEvent.VK_G), + KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0), + mainUI); + runStepAction = new RunStepAction( + "Step", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "StepForward22.png"))), + "Run one step at a time", + new Integer(KeyEvent.VK_T), + KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0), + mainUI); + runBackstepAction = new RunBackstepAction( + "Backstep", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "StepBack22.png"))), + "Undo the last step", + new Integer(KeyEvent.VK_B), + KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0), + mainUI); + runPauseAction = new RunPauseAction( + "Pause", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Pause22.png"))), + "Pause the currently running program", + new Integer(KeyEvent.VK_P), + KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0), + mainUI); + runStopAction = new RunStopAction( + "Stop", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Stop22.png"))), + "Stop the currently running program", + new Integer(KeyEvent.VK_S), + KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0), + mainUI); + runResetAction = new RunResetAction( + "Reset", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Reset22.png"))), + "Reset MIPS memory and registers", + new Integer(KeyEvent.VK_R), + KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0), + mainUI); + runClearBreakpointsAction = new RunClearBreakpointsAction( + "Clear all breakpoints", + null, + "Clears all execution breakpoints set since the last assemble.", + new Integer(KeyEvent.VK_K), KeyStroke.getKeyStroke(KeyEvent.VK_K, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), mainUI); - runToggleBreakpointsAction = new RunToggleBreakpointsAction("Toggle all breakpoints", null, - "Disable/enable all breakpoints without clearing (can also click Bkpt column header)", new Integer( - KeyEvent.VK_T), KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit() - .getMenuShortcutKeyMask()), mainUI); - settingsLabelAction = new SettingsLabelAction("Show Labels Window (symbol table)", null, - "Toggle visibility of Labels window (symbol table) in the Execute tab", null, null, mainUI); - settingsPopupInputAction = new SettingsPopupInputAction("Popup dialog for input syscalls (5,6,7,8,12)", + runToggleBreakpointsAction = new RunToggleBreakpointsAction( + "Toggle all breakpoints", + null, + "Disable/enable all breakpoints without clearing (can also click Bkpt column header)", + new Integer(KeyEvent.VK_T), + KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), + mainUI); + settingsLabelAction = new SettingsLabelAction( + "Show Labels Window (symbol table)", + null, + "Toggle visibility of Labels window (symbol table) in the Execute tab", + null, + null, + mainUI); + settingsPopupInputAction = new SettingsPopupInputAction( + "Popup dialog for input syscalls (5,6,7,8,12)", null, "If set, use popup dialog for input syscalls (5,6,7,8,12) instead of cursor in Run I/O window", - null, null, mainUI); + null, + null, + mainUI); - settingsValueDisplayBaseAction = new SettingsValueDisplayBaseAction("Values displayed in hexadecimal", null, - "Toggle between hexadecimal and decimal display of memory/register values", null, null, mainUI); + settingsValueDisplayBaseAction = new SettingsValueDisplayBaseAction( + "Values displayed in hexadecimal", + null, + "Toggle between hexadecimal and decimal display of memory/register values", + null, + null, + mainUI); settingsAddressDisplayBaseAction = new SettingsAddressDisplayBaseAction( - "Addresses displayed in hexadecimal", null, - "Toggle between hexadecimal and decimal display of memory addresses", null, null, mainUI); - settingsExtendedAction = new SettingsExtendedAction("Permit extended (pseudo) instructions and formats", - null, "If set, MIPS extended (pseudo) instructions are formats are permitted.", null, null, mainUI); - settingsAssembleOnOpenAction = new SettingsAssembleOnOpenAction("Assemble file upon opening", null, + "Addresses displayed in hexadecimal", + null, + "Toggle between hexadecimal and decimal display of memory addresses", + null, + null, + mainUI); + settingsExtendedAction = new SettingsExtendedAction( + "Permit extended (pseudo) instructions and formats", + null, + "If set, MIPS extended (pseudo) instructions are formats are permitted.", + null, + null, + mainUI); + settingsAssembleOnOpenAction = new SettingsAssembleOnOpenAction( + "Assemble file upon opening", + null, "If set, a file will be automatically assembled as soon as it is opened. File Open dialog will show most recently opened file.", - null, null, mainUI); - settingsAssembleAllAction = new SettingsAssembleAllAction("Assemble all files in directory", null, + null, + null, + mainUI); + settingsAssembleAllAction = new SettingsAssembleAllAction( + "Assemble all files in directory", + null, "If set, all files in current directory will be assembled when Assemble operation is selected.", - null, null, mainUI); + null, + null, + mainUI); settingsWarningsAreErrorsAction = new SettingsWarningsAreErrorsAction( - "Assembler warnings are considered errors", null, - "If set, assembler warnings will be interpreted as errors and prevent successful assembly.", null, - null, mainUI); + "Assembler warnings are considered errors", + null, + "If set, assembler warnings will be interpreted as errors and prevent successful assembly.", + null, + null, + mainUI); settingsStartAtMainAction = new SettingsStartAtMainAction( - "Initialize Program Counter to global 'main' if defined", null, + "Initialize Program Counter to global 'main' if defined", + null, "If set, assembler will initialize Program Counter to text address globally labeled 'main', if defined.", - null, null, mainUI); + null, + null, + mainUI); settingsProgramArgumentsAction = new SettingsProgramArgumentsAction( - "Program arguments provided to MIPS program", null, - "If set, program arguments for MIPS program can be entered in border of Text Segment window.", null, - null, mainUI); - settingsDelayedBranchingAction = new SettingsDelayedBranchingAction("Delayed branching", null, - "If set, delayed branching will occur during MIPS execution.", null, null, mainUI); - settingsSelfModifyingCodeAction = new SettingsSelfModifyingCodeAction("Self-modifying code", null, - "If set, the MIPS program can write and branch to both text and data segments.", null, null, + "Program arguments provided to MIPS program", + null, + "If set, program arguments for MIPS program can be entered in border of Text Segment window.", + null, + null, mainUI); - settingsEditorAction = new SettingsEditorAction("Editor...", null, "View and modify text editor settings.", - null, null, mainUI); - settingsHighlightingAction = new SettingsHighlightingAction("Highlighting...", null, - "View and modify Execute Tab highlighting colors", null, null, mainUI); - settingsThemesAction = new SettingsThemesAction("Themes...", null, "View and modify MARS themes", null, null, + settingsDelayedBranchingAction = new SettingsDelayedBranchingAction( + "Delayed branching", + null, + "If set, delayed branching will occur during MIPS execution.", + null, + null, mainUI); - settingsExceptionHandlerAction = new SettingsExceptionHandlerAction("Exception Handler...", null, - "If set, the specified exception handler file will be included in all Assemble operations.", null, - null, mainUI); - settingsMemoryConfigurationAction = new SettingsMemoryConfigurationAction("Memory Configuration...", null, - "View and modify memory segment base addresses for simulated MIPS.", null, null, mainUI); - helpHelpAction = new HelpHelpAction("Help", new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath - + "Help22.png"))), "Help", new Integer(KeyEvent.VK_H), KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), + settingsSelfModifyingCodeAction = new SettingsSelfModifyingCodeAction( + "Self-modifying code", + null, + "If set, the MIPS program can write and branch to both text and data segments.", + null, + null, + mainUI); + settingsEditorAction = new SettingsEditorAction( + "Editor...", + null, + "View and modify text editor settings.", + null, + null, + mainUI); + settingsHighlightingAction = new SettingsHighlightingAction( + "Highlighting...", + null, + "View and modify Execute Tab highlighting colors", + null, + null, + mainUI); + settingsThemesAction = new SettingsThemesAction( + "Themes...", + null, + "View and modify MARS themes", + null, + null, + mainUI); + settingsExceptionHandlerAction = new SettingsExceptionHandlerAction( + "Exception Handler...", + null, + "If set, the specified exception handler file will be included in all Assemble operations.", + null, + null, + mainUI); + settingsMemoryConfigurationAction = new SettingsMemoryConfigurationAction( + "Memory Configuration...", + null, + "View and modify memory segment base addresses for simulated MIPS.", + null, + null, + mainUI); + helpHelpAction = new HelpHelpAction( + "Help", + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Help22.png"))), + "Help", + new Integer(KeyEvent.VK_H), + KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), mainUI); helpAboutAction = new HelpAboutAction("About ...", null, "Information about Mars", null, null, mainUI); } catch (final NullPointerException e) { System.out.println( - "Internal Error: images folder not found, or other null pointer exception while creating Action objects"); + "Internal Error: images folder not found, or other null pointer exception while creating Action objects"); e.printStackTrace(); System.exit(0); } @@ -431,25 +692,75 @@ private JMenuBar setUpMenuBar() { // slight bug: user typing alt-H activates help menu item directly, not help menu fileNew = new JMenuItem(fileNewAction); - fileNew.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "New16.png")))); + fileNew.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "New16.png")))); fileOpen = new JMenuItem(fileOpenAction); - fileOpen.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Open16.png")))); + fileOpen.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Open16.png")))); fileClose = new JMenuItem(fileCloseAction); - fileClose.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif")))); + fileClose.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "MyBlank16.gif")))); fileCloseAll = new JMenuItem(fileCloseAllAction); - fileCloseAll.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif")))); + fileCloseAll.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "MyBlank16.gif")))); fileSave = new JMenuItem(fileSaveAction); - fileSave.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Save16.png")))); + fileSave.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Save16.png")))); fileSaveAs = new JMenuItem(fileSaveAsAction); - fileSaveAs.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "SaveAs16.png")))); + fileSaveAs.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "SaveAs16.png")))); fileSaveAll = new JMenuItem(fileSaveAllAction); - fileSaveAll.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif")))); + fileSaveAll.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "MyBlank16.gif")))); fileDumpMemory = new JMenuItem(fileDumpMemoryAction); - fileDumpMemory.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Dump16.png")))); + fileDumpMemory.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Dump16.png")))); filePrint = new JMenuItem(filePrintAction); - filePrint.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Print16.gif")))); + filePrint.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Print16.gif")))); fileExit = new JMenuItem(fileExitAction); - fileExit.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif")))); + fileExit.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "MyBlank16.gif")))); file.add(fileNew); file.add(fileOpen); file.add(fileClose); @@ -458,26 +769,63 @@ private JMenuBar setUpMenuBar() { file.add(fileSave); file.add(fileSaveAs); file.add(fileSaveAll); - if (new mars.mips.dump.DumpFormatLoader().loadDumpFormats().size() > 0) { file.add(fileDumpMemory); } + if (new mars.mips.dump.DumpFormatLoader().loadDumpFormats().size() > 0) { + file.add(fileDumpMemory); + } file.addSeparator(); file.add(filePrint); file.addSeparator(); file.add(fileExit); editUndo = new JMenuItem(editUndoAction); - editUndo.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Undo16.png"))));//"Undo16.gif")))); + editUndo.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Undo16.png"))));//"Undo16.gif")))); editRedo = new JMenuItem(editRedoAction); - editRedo.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Redo16.png"))));//"Redo16.gif")))); + editRedo.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Redo16.png"))));//"Redo16.gif")))); editCut = new JMenuItem(editCutAction); - editCut.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Cut16.gif")))); + editCut.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Cut16.gif")))); editCopy = new JMenuItem(editCopyAction); - editCopy.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Copy16.png"))));//"Copy16.gif")))); + editCopy.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Copy16.png"))));//"Copy16.gif")))); editPaste = new JMenuItem(editPasteAction); - editPaste.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Paste16.png"))));//"Paste16.gif")))); + editPaste.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Paste16.png"))));//"Paste16.gif")))); editFindReplace = new JMenuItem(editFindReplaceAction); - editFindReplace.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Find16.png"))));//"Paste16.gif")))); + editFindReplace.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Find16.png"))));//"Paste16.gif")))); editSelectAll = new JMenuItem(editSelectAllAction); - editSelectAll.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif")))); + editSelectAll.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "MyBlank16.gif")))); edit.add(editUndo); edit.add(editRedo); edit.addSeparator(); @@ -489,23 +837,68 @@ private JMenuBar setUpMenuBar() { edit.add(editSelectAll); runAssemble = new JMenuItem(runAssembleAction); - runAssemble.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Assemble16.png"))));//"MyAssemble16.gif")))); + runAssemble.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Assemble16.png"))));//"MyAssemble16.gif")))); runGo = new JMenuItem(runGoAction); - runGo.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Play16.png"))));//"Play16.gif")))); + runGo.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Play16.png"))));//"Play16.gif")))); runStep = new JMenuItem(runStepAction); - runStep.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "StepForward16.png"))));//"MyStepForward16.gif")))); + runStep.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "StepForward16.png"))));//"MyStepForward16.gif")))); runBackstep = new JMenuItem(runBackstepAction); - runBackstep.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "StepBack16.png"))));//"MyStepBack16.gif")))); + runBackstep.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "StepBack16.png"))));//"MyStepBack16.gif")))); runReset = new JMenuItem(runResetAction); - runReset.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Reset16.png"))));//"MyReset16.gif")))); + runReset.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Reset16.png"))));//"MyReset16.gif")))); runStop = new JMenuItem(runStopAction); - runStop.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Stop16.png"))));//"Stop16.gif")))); + runStop.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Stop16.png"))));//"Stop16.gif")))); runPause = new JMenuItem(runPauseAction); - runPause.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Pause16.png"))));//"Pause16.gif")))); + runPause.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Pause16.png"))));//"Pause16.gif")))); runClearBreakpoints = new JMenuItem(runClearBreakpointsAction); - runClearBreakpoints.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif")))); + runClearBreakpoints.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "MyBlank16.gif")))); runToggleBreakpoints = new JMenuItem(runToggleBreakpointsAction); - runToggleBreakpoints.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif")))); + runToggleBreakpoints.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "MyBlank16.gif")))); run.add(runAssemble); run.add(runGo); @@ -535,8 +928,8 @@ private JMenuBar setUpMenuBar() { settingsDelayedBranching = new JCheckBoxMenuItem(settingsDelayedBranchingAction); settingsDelayedBranching.setSelected(Globals.getSettings().getDelayedBranchingEnabled()); settingsSelfModifyingCode = new JCheckBoxMenuItem(settingsSelfModifyingCodeAction); - settingsSelfModifyingCode.setSelected(Globals.getSettings().getBooleanSetting( - Settings.SELF_MODIFYING_CODE_ENABLED)); + settingsSelfModifyingCode.setSelected( + Globals.getSettings().getBooleanSetting(Settings.SELF_MODIFYING_CODE_ENABLED)); settingsAssembleOnOpen = new JCheckBoxMenuItem(settingsAssembleOnOpenAction); settingsAssembleOnOpen.setSelected(Globals.getSettings().getAssembleOnOpenEnabled()); settingsAssembleAll = new JCheckBoxMenuItem(settingsAssembleAllAction); @@ -575,9 +968,19 @@ private JMenuBar setUpMenuBar() { settings.add(settingsMemoryConfiguration); helpHelp = new JMenuItem(helpHelpAction); - helpHelp.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "Help16.png"))));//"Help16.gif")))); + helpHelp.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "Help16.png"))));//"Help16.gif")))); helpAbout = new JMenuItem(helpAboutAction); - helpAbout.setIcon(new ImageIcon(tk.getImage(cs.getResource(Globals.imagesPath + "MyBlank16.gif")))); + helpAbout.setIcon( + new ImageIcon( + tk.getImage( + cs.getResource( + Globals.imagesPath + + "MyBlank16.gif")))); help.add(helpHelp); help.addSeparator(); help.add(helpAbout); @@ -587,7 +990,9 @@ private JMenuBar setUpMenuBar() { menuBar.add(run); menuBar.add(settings); final JMenu toolMenu = new ToolLoader().buildToolsMenu(); - if (toolMenu != null) { menuBar.add(toolMenu); } + if (toolMenu != null) { + menuBar.add(toolMenu); + } menuBar.add(help); // experiment with popup menu for settings. 3 Aug 2006 PS @@ -653,7 +1058,9 @@ JToolBar setUpToolBar() { toolBar.add(Open); toolBar.add(Save); toolBar.add(SaveAs); - if (new mars.mips.dump.DumpFormatLoader().loadDumpFormats().size() > 0) { toolBar.add(DumpMemory); } + if (new mars.mips.dump.DumpFormatLoader().loadDumpFormats().size() > 0) { + toolBar.add(DumpMemory); + } toolBar.add(Print); toolBar.add(new JToolBar.Separator()); toolBar.add(Undo); @@ -717,7 +1124,9 @@ void setMenuState(final int status) { case FileStatus.OPENING:// This is a temporary state. DPS 9-Aug-2011 break; default: - System.out.println("Invalid File Status: " + status); + System.out.println( + "Invalid File Status: " + + status); break; } } @@ -892,8 +1301,8 @@ void setMenuStateRunnable() { runAssembleAction.setEnabled(true); runGoAction.setEnabled(true); runStepAction.setEnabled(true); - runBackstepAction.setEnabled(Globals.getSettings().getBackSteppingEnabled() && !Globals.program.getBackStepper() - .empty() ? true : false); + runBackstepAction.setEnabled( + Globals.getSettings().getBackSteppingEnabled() && !Globals.program.getBackStepper().empty() ? true : false); runResetAction.setEnabled(true); runStopAction.setEnabled(false); runPauseAction.setEnabled(false); @@ -963,8 +1372,8 @@ void setMenuStateTerminated() { runAssembleAction.setEnabled(true); runGoAction.setEnabled(false); runStepAction.setEnabled(false); - runBackstepAction.setEnabled(Globals.getSettings().getBackSteppingEnabled() && !Globals.program.getBackStepper() - .empty() ? true : false); + runBackstepAction.setEnabled( + Globals.getSettings().getBackSteppingEnabled() && !Globals.program.getBackStepper().empty() ? true : false); runResetAction.setEnabled(true); runStopAction.setEnabled(false); runPauseAction.setEnabled(false); @@ -1076,18 +1485,14 @@ void setMenuStateTerminated() { /** * Have the menu request keyboard focus. DPS 5-4-10 */ - public void haveMenuRequestFocus() { - menu.requestFocus(); - } + public void haveMenuRequestFocus() { menu.requestFocus(); } /** * Send keyboard event to menu for possible processing. DPS 5-4-10 * * @param evt KeyEvent for menu component to consider for processing. */ - public void dispatchEventToMenu(final KeyEvent evt) { - menu.dispatchEvent(evt); - } + public void dispatchEventToMenu(final KeyEvent evt) { menu.dispatchEvent(evt); } // pop up menu experiment 3 Aug 2006. Keep for possible later revival. private void setupPopupMenu() { diff --git a/mars/venus/editors/MARSTextEditingArea.java b/mars/venus/editors/MARSTextEditingArea.java index e3d7826..105daa5 100644 --- a/mars/venus/editors/MARSTextEditingArea.java +++ b/mars/venus/editors/MARSTextEditingArea.java @@ -126,4 +126,6 @@ public interface MARSTextEditingArea { void updateSyntaxStyles(); Component getOuterComponent(); + + void updateColors(); } diff --git a/mars/venus/editors/generic/GenericTextArea.java b/mars/venus/editors/generic/GenericTextArea.java index 7f49a45..a2e4452 100644 --- a/mars/venus/editors/generic/GenericTextArea.java +++ b/mars/venus/editors/generic/GenericTextArea.java @@ -73,10 +73,12 @@ public GenericTextArea(final EditPane editPain, final JComponent lineNumbers) { final JPanel source = new JPanel(new BorderLayout()); source.add(lineNumbers, BorderLayout.WEST); source.add(this, BorderLayout.CENTER); - editAreaScrollPane = new JScrollPane(source, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, + editAreaScrollPane = new JScrollPane( + source, + ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); - editAreaScrollPane.getVerticalScrollBar().setUnitIncrement(sourceCode.getFontMetrics(sourceCode.getFont()) - .getHeight()); + editAreaScrollPane.getVerticalScrollBar() + .setUnitIncrement(sourceCode.getFontMetrics(sourceCode.getFont()).getHeight()); undoManager = new UndoManager(); @@ -118,7 +120,9 @@ public void updateSyntaxStyles() {} */ @Override public void setCaretBlinkRate(final int rate) { - if (rate >= 0) { getCaret().setBlinkRate(rate); } + if (rate >= 0) { + getCaret().setBlinkRate(rate); + } } @Override @@ -127,7 +131,7 @@ public void setCaretBlinkRate(final int rate) { /** * For initalizing the source code when opening an ASM file * - * @param s String containing text + * @param s String containing text * @param editable set true if code is editable else false **/ @@ -139,23 +143,23 @@ public void setSourceCode(final String s, final boolean editable) { setEnabled(editable); getCaret().setVisible(editable); setCaretPosition(0); - if (editable) { this.requestFocusInWindow(); } + if (editable) { + this.requestFocusInWindow(); + } } /** * Tell UndoManager to discard all its collected undoable edits. */ @Override - public void discardAllUndoableEdits() { - undoManager.discardAllEdits(); - } + public void discardAllUndoableEdits() { undoManager.discardAllEdits(); } /** * Override inherited setText to temporarily remove UndoableEditListener because * this operation is not undoable. * * @param s String with new contents for the editing area. Replaces current - * content. + * content. */ @Override public void setText(final String s) { @@ -170,9 +174,7 @@ public void setText(final String s) { * @param vis true to display caret, false to hide it */ @Override - public void setCaretVisible(final boolean vis) { - getCaret().setVisible(vis); - } + public void setCaretVisible(final boolean vis) { getCaret().setVisible(vis); } /** * Control selection visibility @@ -180,9 +182,7 @@ public void setCaretVisible(final boolean vis) { * @param vis true to display selection, false to hide it */ @Override - public void setSelectionVisible(final boolean vis) { - getCaret().setSelectionVisible(vis); - } + public void setSelectionVisible(final boolean vis) { getCaret().setSelectionVisible(vis); } /** * Returns the undo manager for this editing area @@ -200,7 +200,9 @@ public void undo() { try { undoManager.undo(); } catch (final CannotUndoException ex) { - System.out.println("Unable to undo: " + ex); + System.out.println( + "Unable to undo: " + + ex); ex.printStackTrace(); } setCaretVisible(true); @@ -214,7 +216,9 @@ public void redo() { try { undoManager.redo(); } catch (final CannotRedoException ex) { - System.out.println("Unable to redo: " + ex); + System.out.println( + "Unable to redo: " + + ex); ex.printStackTrace(); } setCaretVisible(true); @@ -235,7 +239,7 @@ public void redo() { * at the current cursor location, and wraps around when the end of the string * is reached. * - * @param find the text to locate in the string + * @param find the text to locate in the string * @param caseSensitive true if search is to be case-sensitive, false otherwise * @return TEXT_FOUND or TEXT_NOT_FOUND, depending on the result. */ @@ -260,9 +264,9 @@ public int doFindText(final String find, final boolean caseSensitive) { * reached during the search, will wrap around to the beginning one time. * * @return next indexed position of found text or -1 if not found - * @param input the string to search - * @param find the string to find - * @param start the character position to start the search + * @param input the string to search + * @param find the string to find + * @param start the character position to start the search * @param caseSensitive true for case sensitive. false to ignore case */ public int nextIndex(final String input, final String find, final int start, final boolean caseSensitive) { @@ -271,12 +275,16 @@ public int nextIndex(final String input, final String find, final int start, fin if (caseSensitive) { // indexOf() returns -1 if not found textPosn = input.indexOf(find, start); // If not found from non-starting cursor position, wrap around - if (start > 0 && textPosn < 0) { textPosn = input.indexOf(find); } + if (start > 0 && textPosn < 0) { + textPosn = input.indexOf(find); + } } else { final String lowerCaseText = input.toLowerCase(); textPosn = lowerCaseText.indexOf(find.toLowerCase(), start); // If not found from non-starting cursor position, wrap around - if (start > 0 && textPosn < 0) { textPosn = lowerCaseText.indexOf(find.toLowerCase()); } + if (start > 0 && textPosn < 0) { + textPosn = lowerCaseText.indexOf(find.toLowerCase()); + } } } return textPosn; @@ -288,16 +296,15 @@ public int nextIndex(final String input, final String find, final int start, fin * then find and select the next occurrence if any. Otherwise it performs a find * operation. The replace can be undone with one undo operation. * - * @param find the text to locate in the string - * @param replace the text to replace the find text with - if the find - * text exists + * @param find the text to locate in the string + * @param replace the text to replace the find text with - if the find text + * exists * @param caseSensitive true for case sensitive. false to ignore case * @return Returns TEXT_FOUND if not initially at end of selected match and - * matching occurrence is found. Returns TEXT_NOT_FOUND if the text is - * not matched. Returns TEXT_REPLACED_NOT_FOUND_NEXT if replacement is - * successful but there are no additional matches. Returns - * TEXT_REPLACED_FOUND_NEXT if reaplacement is successful and there is - * at least one additional match. + * matching occurrence is found. Returns TEXT_NOT_FOUND if the text is not + * matched. Returns TEXT_REPLACED_NOT_FOUND_NEXT if replacement is successful + * but there are no additional matches. Returns TEXT_REPLACED_FOUND_NEXT if + * reaplacement is successful and there is at least one additional match. */ @Override public int doReplace(final String find, final String replace, final boolean caseSensitive) { @@ -305,7 +312,7 @@ public int doReplace(final String find, final String replace, final boolean case // Will perform a "find" and return, unless positioned at the end of // a selected "find" result. if (find == null || !find.equals(sourceCode.getSelectedText()) || sourceCode.getSelectionEnd() != sourceCode - .getCaretPosition()) { + .getCaretPosition()) { return doFindText(find, caseSensitive); } // We are positioned at end of selected "find". Rreplace and find next. @@ -334,9 +341,9 @@ public int doReplace(final String find, final String replace, final boolean case * search. All replacements are bundled into one CompoundEdit, so one Undo * operation will undo all of them. * - * @param find the text to locate in the string - * @param replace the text to replace the find text with - if the find - * text exists + * @param find the text to locate in the string + * @param replace the text to replace the find text with - if the find text + * exists * @param caseSensitive true for case sensitive. false to ignore case * @return the number of occurrences that were matched and replaced. */ @@ -353,11 +360,15 @@ public int doReplaceAll(final String find, final String replace, final boolean c // nextIndex() will wrap around, which causes infinite loop if // find string is a substring of replacement string. This // statement will prevent that. - if (nextPosn < findPosn) { break; } + if (nextPosn < findPosn) { + break; + } sourceCode.grabFocus(); sourceCode.setSelectionStart(nextPosn); // posn cursor at word start sourceCode.setSelectionEnd(nextPosn + find.length()); //select found text - if (compoundEdit == null) { compoundEdit = new CompoundEdit(); } + if (compoundEdit == null) { + compoundEdit = new CompoundEdit(); + } sourceCode.replaceSelection(replace); findPosn = nextPosn + replace.length(); // set for next search replaceCount++; @@ -376,4 +387,7 @@ public int doReplaceAll(final String find, final String replace, final boolean c // ///////////////////////////// End Find/Replace methods ////////////////////////// + @Override + public void updateColors() {} + } diff --git a/mars/venus/editors/jeditsyntax/JEditBasedTextArea.java b/mars/venus/editors/jeditsyntax/JEditBasedTextArea.java index e323ea1..17f1423 100644 --- a/mars/venus/editors/jeditsyntax/JEditBasedTextArea.java +++ b/mars/venus/editors/jeditsyntax/JEditBasedTextArea.java @@ -67,9 +67,7 @@ public JEditBasedTextArea(final EditPane editPain, final JComponent lineNumbers) } @Override - public void setFont(final Font f) { - getPainter().setFont(f); - } + public void setFont(final Font f) { getPainter().setFont(f); } @Override public Font getFont() { return getPainter().getFont(); } @@ -84,9 +82,7 @@ public void setFont(final Font f) { * @param highlight true to enable line highlighting, false to disable. */ @Override - public void setLineHighlightEnabled(final boolean highlight) { - getPainter().setLineHighlightEnabled(highlight); - } + public void setLineHighlightEnabled(final boolean highlight) { getPainter().setLineHighlightEnabled(highlight); } /** * Set the caret blinking rate in milliseconds. If rate is 0 will disable @@ -96,7 +92,9 @@ public void setLineHighlightEnabled(final boolean highlight) { */ @Override public void setCaretBlinkRate(final int rate) { - if (rate == 0) { caretBlinks = false; } + if (rate == 0) { + caretBlinks = false; + } if (rate > 0) { caretBlinks = true; caretBlinkRate = rate; @@ -112,17 +110,13 @@ public void setCaretBlinkRate(final int rate) { * @param chars number of characters */ @Override - public void setTabSize(final int chars) { - painter.setTabSize(chars); - } + public void setTabSize(final int chars) { painter.setTabSize(chars); } /** * Update the syntax style table, which is obtained from SyntaxUtilities. */ @Override - public void updateSyntaxStyles() { - painter.setStyles(SyntaxUtilities.getCurrentSyntaxStyles()); - } + public void updateSyntaxStyles() { painter.setStyles(SyntaxUtilities.getCurrentSyntaxStyles()); } @Override public Component getOuterComponent() { return this; } @@ -135,9 +129,7 @@ public void updateSyntaxStyles() { * unless you call this after setting the text. */ @Override - public void discardAllUndoableEdits() { - undoManager.discardAllEdits(); - } + public void discardAllUndoableEdits() { undoManager.discardAllEdits(); } /** * Display caret position on the edit pane. @@ -146,9 +138,7 @@ public void discardAllUndoableEdits() { */ @Override - public void caretUpdate(final CaretEvent e) { - editPane.displayCaretPosition(((MutableCaretEvent) e).getDot()); - } + public void caretUpdate(final CaretEvent e) { editPane.displayCaretPosition(((MutableCaretEvent) e).getDot()); } /** * Same as setSelectedText but named for compatibility with JTextComponent @@ -157,9 +147,7 @@ public void caretUpdate(final CaretEvent e) { * @param replacementText The replacement text for the selection */ @Override - public void replaceSelection(final String replacementText) { - setSelectedText(replacementText); - } + public void replaceSelection(final String replacementText) { setSelectedText(replacementText); } // // @@ -178,7 +166,9 @@ public void setSourceCode(final String s, final boolean editable) { setEnabled(editable); //this.getCaret().setVisible(editable); setCaretPosition(0); - if (editable) { this.requestFocusInWindow(); } + if (editable) { + this.requestFocusInWindow(); + } } /** @@ -200,7 +190,9 @@ public void undo() { try { undoManager.undo(); } catch (final CannotUndoException ex) { - System.out.println("Unable to undo: " + ex); + System.out.println( + "Unable to undo: " + + ex); ex.printStackTrace(); } unredoing = false; @@ -218,7 +210,9 @@ public void redo() { try { undoManager.redo(); } catch (final CannotRedoException ex) { - System.out.println("Unable to redo: " + ex); + System.out.println( + "Unable to redo: " + + ex); ex.printStackTrace(); } unredoing = false; @@ -238,7 +232,7 @@ public void redo() { * at the current cursor location, and wraps around when the end of the string * is reached. * - * @param find the text to locate in the string + * @param find the text to locate in the string * @param caseSensitive true if search is to be case-sensitive, false otherwise * @return TEXT_FOUND or TEXT_NOT_FOUND, depending on the result. */ @@ -264,9 +258,9 @@ public int doFindText(final String find, final boolean caseSensitive) { * reached during the search, will wrap around to the beginning one time. * * @return next indexed position of found text or -1 if not found - * @param input the string to search - * @param find the string to find - * @param start the character position to start the search + * @param input the string to search + * @param find the string to find + * @param start the character position to start the search * @param caseSensitive true for case sensitive. false to ignore case */ public int nextIndex(final String input, final String find, final int start, final boolean caseSensitive) { @@ -275,12 +269,16 @@ public int nextIndex(final String input, final String find, final int start, fin if (caseSensitive) { // indexOf() returns -1 if not found textPosn = input.indexOf(find, start); // If not found from non-starting cursor position, wrap around - if (start > 0 && textPosn < 0) { textPosn = input.indexOf(find); } + if (start > 0 && textPosn < 0) { + textPosn = input.indexOf(find); + } } else { final String lowerCaseText = input.toLowerCase(); textPosn = lowerCaseText.indexOf(find.toLowerCase(), start); // If not found from non-starting cursor position, wrap around - if (start > 0 && textPosn < 0) { textPosn = lowerCaseText.indexOf(find.toLowerCase()); } + if (start > 0 && textPosn < 0) { + textPosn = lowerCaseText.indexOf(find.toLowerCase()); + } } } return textPosn; @@ -292,16 +290,15 @@ public int nextIndex(final String input, final String find, final int start, fin * then find and select the next occurrence if any. Otherwise it performs a find * operation. The replace can be undone with one undo operation. * - * @param find the text to locate in the string - * @param replace the text to replace the find text with - if the find - * text exists + * @param find the text to locate in the string + * @param replace the text to replace the find text with - if the find text + * exists * @param caseSensitive true for case sensitive. false to ignore case * @return Returns TEXT_FOUND if not initially at end of selected match and - * matching occurrence is found. Returns TEXT_NOT_FOUND if the text is - * not matched. Returns TEXT_REPLACED_NOT_FOUND_NEXT if replacement is - * successful but there are no additional matches. Returns - * TEXT_REPLACED_FOUND_NEXT if reaplacement is successful and there is - * at least one additional match. + * matching occurrence is found. Returns TEXT_NOT_FOUND if the text is not + * matched. Returns TEXT_REPLACED_NOT_FOUND_NEXT if replacement is successful + * but there are no additional matches. Returns TEXT_REPLACED_FOUND_NEXT if + * reaplacement is successful and there is at least one additional match. */ @Override public int doReplace(final String find, final String replace, final boolean caseSensitive) { @@ -309,7 +306,7 @@ public int doReplace(final String find, final String replace, final boolean case // Will perform a "find" and return, unless positioned at the end of // a selected "find" result. if (find == null || !find.equals(sourceCode.getSelectedText()) || sourceCode.getSelectionEnd() != sourceCode - .getCaretPosition()) { + .getCaretPosition()) { return doFindText(find, caseSensitive); } // We are positioned at end of selected "find". Rreplace and find next. @@ -340,9 +337,9 @@ public int doReplace(final String find, final String replace, final boolean case * search. All replacements are bundled into one CompoundEdit, so one Undo * operation will undo all of them. * - * @param find the text to locate in the string - * @param replace the text to replace the find text with - if the find - * text exists + * @param find the text to locate in the string + * @param replace the text to replace the find text with - if the find text + * exists * @param caseSensitive true for case sensitive. false to ignore case * @return the number of occurrences that were matched and replaced. */ @@ -359,13 +356,17 @@ public int doReplaceAll(final String find, final String replace, final boolean c // nextIndex() will wrap around, which causes infinite loop if // find string is a substring of replacement string. This // statement will prevent that. - if (nextPosn < findPosn) { break; } + if (nextPosn < findPosn) { + break; + } sourceCode.grabFocus(); sourceCode.setSelectionStart(nextPosn); // posn cursor at word start sourceCode.setSelectionEnd(nextPosn + find.length()); //select found text // Need to repeat start due to quirk in JEditTextArea implementation of setSelectionStart. sourceCode.setSelectionStart(nextPosn); - if (compoundEdit == null) { compoundEdit = new CompoundEdit(); } + if (compoundEdit == null) { + compoundEdit = new CompoundEdit(); + } sourceCode.replaceSelection(replace); findPosn = nextPosn + replace.length(); // set for next search replaceCount++; @@ -384,6 +385,9 @@ public int doReplaceAll(final String find, final String replace, final boolean c // ///////////////////////////// End Find/Replace methods ////////////////////////// + @Override + public void updateColors() { painter.updateColors(); } + // ////////////////////////////////////////////////////////////////// diff --git a/mars/venus/editors/jeditsyntax/SyntaxUtilities.java b/mars/venus/editors/jeditsyntax/SyntaxUtilities.java index a6a1682..1b6e2eb 100644 --- a/mars/venus/editors/jeditsyntax/SyntaxUtilities.java +++ b/mars/venus/editors/jeditsyntax/SyntaxUtilities.java @@ -36,12 +36,11 @@ public class SyntaxUtilities { * Checks if a subregion of a Segment is equal to a string. * * @param ignoreCase True if case should be ignored, false otherwise - * @param text The segment - * @param offset The offset into the segment - * @param match The string to match + * @param text The segment + * @param offset The offset into the segment + * @param match The string to match */ - public static boolean regionMatches(final boolean ignoreCase, final Segment text, final int offset, - final String match) { + public static boolean regionMatches(final boolean ignoreCase, final Segment text, final int offset, final String match) { final int length = offset + match.length(); final char[] textArray = text.array; if (length > text.offset + text.count) { return false; } @@ -62,12 +61,11 @@ public static boolean regionMatches(final boolean ignoreCase, final Segment text * array. * * @param ignoreCase True if case should be ignored, false otherwise - * @param text The segment - * @param offset The offset into the segment - * @param match The character array to match + * @param text The segment + * @param offset The offset into the segment + * @param match The character array to match */ - public static boolean regionMatches(final boolean ignoreCase, final Segment text, final int offset, - final char[] match) { + public static boolean regionMatches(final boolean ignoreCase, final Segment text, final int offset, final char[] match) { final int length = offset + match.length; final char[] textArray = text.array; if (length > text.offset + text.count) { return false; } @@ -105,6 +103,9 @@ public static SyntaxStyle[] getDefaultSyntaxStyles() { styles[Token.OPERATOR] = new SyntaxStyle(Color.black, false, true); styles[Token.INVALID] = new SyntaxStyle(Color.red, false, false); styles[Token.MACRO_ARG] = new SyntaxStyle(new Color(150, 150, 0), false, false); + styles[Token.EDITOR_BG] = new SyntaxStyle(new Color(255, 255, 255), false, false); + styles[Token.EDITOR_LINE] = new SyntaxStyle(new Color(238, 238, 238), false, false); + styles[Token.EDITOR_SELECTION] = new SyntaxStyle(new Color(204, 204, 255), false, false); return styles; } @@ -129,6 +130,9 @@ public static SyntaxStyle[] getCurrentSyntaxStyles() { styles[Token.OPERATOR] = Globals.getSettings().getEditorSyntaxStyleByPosition(Token.OPERATOR); styles[Token.INVALID] = Globals.getSettings().getEditorSyntaxStyleByPosition(Token.INVALID); styles[Token.MACRO_ARG] = Globals.getSettings().getEditorSyntaxStyleByPosition(Token.MACRO_ARG); + styles[Token.EDITOR_BG] = Globals.getSettings().getEditorSyntaxStyleByPosition(Token.EDITOR_BG); + styles[Token.EDITOR_LINE] = Globals.getSettings().getEditorSyntaxStyleByPosition(Token.EDITOR_LINE); + styles[Token.EDITOR_SELECTION] = Globals.getSettings().getEditorSyntaxStyleByPosition(Token.EDITOR_SELECTION); return styles; } @@ -136,31 +140,36 @@ public static SyntaxStyle[] getCurrentSyntaxStyles() { * Paints the specified line onto the graphics context. Note that this method * munges the offset and count values of the segment. * - * @param line The line segment - * @param tokens The token list for the line - * @param styles The syntax style list + * @param line The line segment + * @param tokens The token list for the line + * @param styles The syntax style list * @param expander The tab expander used to determine tab stops. May be null - * @param gfx The graphics context - * @param x The x co-ordinate - * @param y The y co-ordinate + * @param gfx The graphics context + * @param x The x co-ordinate + * @param y The y co-ordinate * @return The x co-ordinate, plus the width of the painted string */ public static boolean popupShowing = false; public static Popup popup; - public static int paintSyntaxLine(final Segment line, Token tokens, final SyntaxStyle[] styles, - final TabExpander expander, final Graphics gfx, int x, final int y) { + public static int paintSyntaxLine(final Segment line, Token tokens, final SyntaxStyle[] styles, final TabExpander expander, final Graphics gfx, int x, final int y) { final Font defaultFont = gfx.getFont(); final Color defaultColor = gfx.getColor(); for (;;) { final byte id = tokens.id; - if (id == Token.END) { break; } + if (id == Token.END) { + break; + } final int length = tokens.length; if (id == Token.NULL) { - if (!defaultColor.equals(gfx.getColor())) { gfx.setColor(defaultColor); } - if (!defaultFont.equals(gfx.getFont())) { gfx.setFont(defaultFont); } + if (!defaultColor.equals(gfx.getColor())) { + gfx.setColor(defaultColor); + } + if (!defaultFont.equals(gfx.getFont())) { + gfx.setFont(defaultFont); + } } else { styles[id].setGraphicsFlags(gfx, defaultFont); } @@ -220,7 +229,13 @@ class InstructionMouseEvent extends MouseEvent { public InstructionMouseEvent(final Component component, final int x, final int y, final Segment line) { super(component, MouseEvent.MOUSE_MOVED, new java.util.Date().getTime(), 0, x, y, 0, false); - System.out.println("Create InstructionMouseEvent " + x + " " + y + " " + line); + System.out.println( + "Create InstructionMouseEvent " + + x + + " " + + y + + " " + + line); this.line = line; } diff --git a/mars/venus/editors/jeditsyntax/TextAreaPainter.java b/mars/venus/editors/jeditsyntax/TextAreaPainter.java index 7446605..d50914a 100644 --- a/mars/venus/editors/jeditsyntax/TextAreaPainter.java +++ b/mars/venus/editors/jeditsyntax/TextAreaPainter.java @@ -63,17 +63,22 @@ public TextAreaPainter(final JEditTextArea textArea, final TextAreaDefaults defa setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); setFont(new Font("Courier New" /*"Monospaced"*/, Font.PLAIN, 14)); - setForeground(Color.black); - setBackground(Color.white); + Color bg = SyntaxUtilities.getCurrentSyntaxStyles()[Token.EDITOR_BG].getColor(); + Color line = SyntaxUtilities.getCurrentSyntaxStyles()[Token.EDITOR_LINE].getColor(); + Color selection = SyntaxUtilities.getCurrentSyntaxStyles()[Token.EDITOR_SELECTION].getColor(); + Color fg = new Color(255 - bg.getRed(), 255 - bg.getGreen(), 255 - bg.getBlue()); + + setForeground(fg); + setBackground(bg); tabSizeChars = defaults.tabSize; blockCaret = defaults.blockCaret; styles = defaults.styles; cols = defaults.cols; rows = defaults.rows; - caretColor = defaults.caretColor; - selectionColor = defaults.selectionColor; - lineHighlightColor = defaults.lineHighlightColor; + caretColor = fg; // was defaults.caretColor + selectionColor = selection; // was defaults.selectionColor + lineHighlightColor = line; // was defaults.lineHighlightColor lineHighlight = defaults.lineHighlight; bracketHighlightColor = defaults.bracketHighlightColor; bracketHighlight = defaults.bracketHighlight; @@ -181,7 +186,7 @@ public final void setLineHighlightColor(final Color lineHighlightColor) { * Enables or disables current line highlighting. * * @param lineHighlight True if current line highlight should be enabled, false - * otherwise + * otherwise */ public final void setLineHighlightEnabled(final boolean lineHighlight) { this.lineHighlight = lineHighlight; @@ -216,7 +221,7 @@ public final void setBracketHighlightColor(final Color bracketHighlightColor) { * highlighted. * * @param bracketHighlight True if bracket highlighting should be enabled, false - * otherwise + * otherwise */ public final void setBracketHighlightEnabled(final boolean bracketHighlight) { this.bracketHighlight = bracketHighlight; @@ -232,7 +237,7 @@ public final void setBracketHighlightEnabled(final boolean bracketHighlight) { * Sets if the caret should be drawn as a block, false otherwise. * * @param blockCaret True if the caret should be drawn as a block, false - * otherwise. + * otherwise. */ public final void setBlockCaretEnabled(final boolean blockCaret) { this.blockCaret = blockCaret; @@ -300,16 +305,16 @@ public interface Highlight { * Called after the highlight painter has been added. * * @param textArea The text area - * @param next The painter this one should delegate to + * @param next The painter this one should delegate to */ void init(JEditTextArea textArea, Highlight next); /** * This should paint the highlight and delgate to the next highlight painter. * - * @param gfx The graphics context + * @param gfx The graphics context * @param line The line number - * @param y The y co-ordinate of the line + * @param y The y co-ordinate of the line */ void paintHighlight(Graphics gfx, int line, int y); @@ -382,8 +387,9 @@ public void paint(final Graphics gfx) { // Added 4/6/10 DPS to set antialiasing for text rendering - smoother letters // Second one says choose algorithm for quality over speed - ((Graphics2D) gfx).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, - RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + ((Graphics2D) gfx).setRenderingHint( + RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_ON); ((Graphics2D) gfx).setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); tabSize = fm.charWidth(' ') * tabSizeChars; // was: ((Integer)textArea.getDocument().getProperty(PlainDocument.tabSizeAttribute)).intValue(); @@ -416,7 +422,13 @@ public void paint(final Graphics gfx) { repaint(0, h, getWidth(), getHeight() - h); } } catch (final Exception e) { - System.err.println("Error repainting line" + " range {" + firstInvalid + "," + lastInvalid + "}:"); + System.err.println( + "Error repainting line" + + " range {" + + firstInvalid + + "," + + lastInvalid + + "}:"); e.printStackTrace(); } } @@ -434,11 +446,14 @@ public final void invalidateLine(final int line) { * Marks a range of lines as needing a repaint. * * @param firstLine The first line to invalidate - * @param lastLine The last line to invalidate + * @param lastLine The last line to invalidate */ public final void invalidateLineRange(final int firstLine, final int lastLine) { - repaint(0, textArea.lineToY(firstLine) + fm.getMaxDescent() + fm.getLeading(), getWidth(), (lastLine - firstLine - + 1) * fm.getHeight()); + repaint( + 0, + textArea.lineToY(firstLine) + fm.getMaxDescent() + fm.getLeading(), + getWidth(), + (lastLine - firstLine + 1) * fm.getHeight()); } /** @@ -452,7 +467,7 @@ public final void invalidateSelectedLines() { * Implementation of TabExpander interface. Returns next tab stop after a * specified point. * - * @param x The x co-ordinate + * @param x The x co-ordinate * @param tabOffset Ignored * @return The next tab stop after x */ @@ -528,8 +543,7 @@ public Dimension getPreferredSize() { } } - protected void paintPlainLine(final Graphics gfx, final int line, final Font defaultFont, final Color defaultColor, - int x, int y) { + protected void paintPlainLine(final Graphics gfx, final int line, final Font defaultFont, final Color defaultColor, int x, int y) { paintHighlight(gfx, line, y); textArea.getLineText(line, currentLine); @@ -546,8 +560,7 @@ protected void paintPlainLine(final Graphics gfx, final int line, final Font def } // private int count=0; - protected void paintSyntaxLine(final Graphics gfx, final TokenMarker tokenMarker, final int line, - final Font defaultFont, final Color defaultColor, int x, int y) {//System.out.println("paintSyntaxLine line "+ line); + protected void paintSyntaxLine(final Graphics gfx, final TokenMarker tokenMarker, final int line, final Font defaultFont, final Color defaultColor, int x, int y) {//System.out.println("paintSyntaxLine line "+ line); textArea.getLineText(currentLineIndex, currentLine); currentLineTokens = tokenMarker.markTokens(currentLine, currentLineIndex); @@ -576,11 +589,17 @@ protected void paintSyntaxLine(final Graphics gfx, final TokenMarker tokenMarker paintLineHighlight(gfx, line, y); } - if (highlights != null) { highlights.paintHighlight(gfx, line, y); } + if (highlights != null) { + highlights.paintHighlight(gfx, line, y); + } - if (bracketHighlight && line == textArea.getBracketLine()) { paintBracketHighlight(gfx, line, y); } + if (bracketHighlight && line == textArea.getBracketLine()) { + paintBracketHighlight(gfx, line, y); + } - if (line == textArea.getCaretLine()) { paintCaret(gfx, line, y); } + if (line == textArea.getCaretLine()) { + paintCaret(gfx, line, y); + } } protected void paintLineHighlight(final Graphics gfx, final int line, int y) {//System.out.println("paintLineHighlight "+ (++count)); @@ -605,11 +624,15 @@ protected void paintSyntaxLine(final Graphics gfx, final TokenMarker tokenMarker int x1, x2; if (textArea.isSelectionRectangular()) { final int lineLen = textArea.getLineLength(line); - x1 = textArea._offsetToX(line, Math.min(lineLen, selectionStart - textArea.getLineStartOffset( - selectionStartLine))); - x2 = textArea._offsetToX(line, Math.min(lineLen, selectionEnd - textArea.getLineStartOffset( - selectionEndLine))); - if (x1 == x2) { x2++; } + x1 = textArea._offsetToX( + line, + Math.min(lineLen, selectionStart - textArea.getLineStartOffset(selectionStartLine))); + x2 = textArea._offsetToX( + line, + Math.min(lineLen, selectionEnd - textArea.getLineStartOffset(selectionEndLine))); + if (x1 == x2) { + x2++; + } } else if (selectionStartLine == selectionEndLine) { x1 = textArea._offsetToX(line, selectionStart - lineStart); x2 = textArea._offsetToX(line, selectionEnd - lineStart); @@ -659,4 +682,18 @@ protected void paintCaret(final Graphics gfx, final int line, int y) { } } } + + public void updateColors() { + Color bg = SyntaxUtilities.getCurrentSyntaxStyles()[Token.EDITOR_BG].getColor(); + Color line = SyntaxUtilities.getCurrentSyntaxStyles()[Token.EDITOR_LINE].getColor(); + Color selection = SyntaxUtilities.getCurrentSyntaxStyles()[Token.EDITOR_SELECTION].getColor(); + Color fg = new Color(255 - bg.getRed(), 255 - bg.getGreen(), 255 - bg.getBlue()); + + setForeground(fg); + setBackground(bg); + + setCaretColor(fg); + setSelectionColor(selection); + setLineHighlightColor(line); + } } diff --git a/mars/venus/editors/jeditsyntax/tokenmarker/MIPSTokenMarker.java b/mars/venus/editors/jeditsyntax/tokenmarker/MIPSTokenMarker.java index 8ab2ef6..332bd52 100644 --- a/mars/venus/editors/jeditsyntax/tokenmarker/MIPSTokenMarker.java +++ b/mars/venus/editors/jeditsyntax/tokenmarker/MIPSTokenMarker.java @@ -29,13 +29,9 @@ */ public class MIPSTokenMarker extends TokenMarker { - public MIPSTokenMarker() { - this(getKeywords()); - } + public MIPSTokenMarker() { this(getKeywords()); } - public MIPSTokenMarker(final KeywordMap keywords) { - this.keywords = keywords; - } + public MIPSTokenMarker(final KeywordMap keywords) { this.keywords = keywords; } public static String[] getMIPSTokenLabels() { if (tokenLabels == null) { @@ -49,6 +45,9 @@ public static String[] getMIPSTokenLabels() { tokenLabels[Token.KEYWORD3] = "Register"; tokenLabels[Token.INVALID] = "In-progress, invalid"; tokenLabels[Token.MACRO_ARG] = "Macro parameter"; + tokenLabels[Token.EDITOR_BG] = "Background"; + tokenLabels[Token.EDITOR_LINE] = "Line"; + tokenLabels[Token.EDITOR_SELECTION] = "Selection"; } return tokenLabels; } @@ -65,6 +64,9 @@ public static String[] getMIPSTokenExamples() { tokenExamples[Token.KEYWORD3] = "$zero"; tokenExamples[Token.INVALID] = "\"Regi"; tokenExamples[Token.MACRO_ARG] = "%arg"; + tokenExamples[Token.EDITOR_BG] = ""; + tokenExamples[Token.EDITOR_LINE] = ""; + tokenExamples[Token.EDITOR_SELECTION] = ""; } return tokenExamples; } @@ -136,8 +138,8 @@ else if(doKeyword(line,i,c)) //String lab = new String(array, lastOffset, i1-lastOffset-1).trim(); boolean validIdentifier = false; try { - validIdentifier = mars.assembler.TokenTypes.isValidIdentifier(new String(array, lastOffset, i1 - - lastOffset - 1).trim()); + validIdentifier = mars.assembler.TokenTypes.isValidIdentifier( + new String(array, lastOffset, i1 - lastOffset - 1).trim()); } catch (final StringIndexOutOfBoundsException e) { validIdentifier = false; } @@ -184,11 +186,15 @@ else if(doKeyword(line,i,c)) } break; default: - throw new InternalError("Invalid state: " + token); + throw new InternalError( + "Invalid state: " + + token); } } - if (token == Token.NULL) { doKeyword(line, length, '\0'); } + if (token == Token.NULL) { + doKeyword(line, length, '\0'); + } switch (token) { case Token.LITERAL1: @@ -198,7 +204,9 @@ else if(doKeyword(line,i,c)) break; case Token.KEYWORD2: addToken(length - lastOffset, token); - if (!backslash) { token = Token.NULL; } + if (!backslash) { + token = Token.NULL; + } default: addToken(length - lastOffset, token); break; @@ -210,7 +218,7 @@ else if(doKeyword(line,i,c)) /** * Construct and return any appropriate help information for the given token. * - * @param token the pertinent Token object + * @param token the pertinent Token object * @param tokenText the source String that matched to the token * @return ArrayList of PopupHelpItem objects, one per match. */ @@ -248,17 +256,16 @@ public ArrayList getTokenExactMatchHelp(final Token token, final String tokenTex * Construct and return any appropriate help information for prefix match based * on current line's token list. * - * @param line String containing current line + * @param line String containing current line * @param tokenList first Token on current line (head of linked list) - * @param token the pertinent Token object + * @param token the pertinent Token object * @param tokenText the source String that matched to the token in previous - * parameter + * parameter * @return ArrayList of PopupHelpItem objects, one per match. */ @Override - public ArrayList getTokenPrefixMatchHelp(final String line, final Token tokenList, final Token token, - final String tokenText) { + public ArrayList getTokenPrefixMatchHelp(final String line, final Token tokenList, final Token token, final String tokenText) { // CASE: Unlikely boundary case... if (tokenList == null || tokenList.id == Token.END) { return null; } @@ -292,8 +299,9 @@ public ArrayList getTokenPrefixMatchHelp(final String line, final Token tokenLis // instructions for which this is a prefix, so do a prefix match on current token. if (token != null && token.id == Token.KEYWORD1) { if (moreThanOneKeyword) { - return keywordType == Token.KEYWORD1 ? getTextFromInstructionMatch(keywordTokenText, true) - : getTextFromDirectiveMatch(keywordTokenText, true); + return keywordType == Token.KEYWORD1 ? getTextFromInstructionMatch( + keywordTokenText, + true) : getTextFromDirectiveMatch(keywordTokenText, true); } else { return getTextFromInstructionMatch(tokenText, false); } @@ -304,8 +312,9 @@ public ArrayList getTokenPrefixMatchHelp(final String line, final Token tokenLis // directives for which this is a prefix, so do a prefix match on current token. if (token != null && token.id == Token.KEYWORD2) { if (moreThanOneKeyword) { - return keywordType == Token.KEYWORD1 ? getTextFromInstructionMatch(keywordTokenText, true) - : getTextFromDirectiveMatch(keywordTokenText, true); + return keywordType == Token.KEYWORD1 ? getTextFromInstructionMatch( + keywordTokenText, + true) : getTextFromDirectiveMatch(keywordTokenText, true); } else { return getTextFromDirectiveMatch(tokenText, false); } @@ -428,7 +437,7 @@ private ArrayList getTextFromInstructionMatch(final String tokenText, final bool * mnemonics, assembler directives, and register names. * * @return KeywordMap where key is the keyword and associated value is the token - * type (e.g. Token.KEYWORD1). + * type (e.g. Token.KEYWORD1). */ public static KeywordMap getKeywords() { @@ -448,11 +457,14 @@ public static KeywordMap getKeywords() { final mars.mips.hardware.Register[] registerFile = mars.mips.hardware.RegisterFile.getRegisters(); for (int i = 0; i < registerFile.length; i++) { cKeywords.add(registerFile[i].getName(), Token.KEYWORD3); - cKeywords.add("$" + i, Token.KEYWORD3); // also recognize $0, $1, $2, etc + cKeywords.add( + "$" + + i, + Token.KEYWORD3); // also recognize $0, $1, $2, etc } // add Coprocessor 1 (floating point) register file final mars.mips.hardware.Register[] coprocessor1RegisterFile = mars.mips.hardware.Coprocessor1 - .getRegisters(); + .getRegisters(); for (int i = 0; i < coprocessor1RegisterFile.length; i++) { cKeywords.add(coprocessor1RegisterFile[i].getName(), Token.KEYWORD3); } @@ -480,7 +492,9 @@ private boolean doKeyword(final Segment line, final int i, final char c) { // if (id == Token.KEYWORD1 && tokenListContainsKeyword()) { // } // else { - if (lastKeyword != lastOffset) { addToken(lastKeyword - lastOffset, Token.NULL); } + if (lastKeyword != lastOffset) { + addToken(lastKeyword - lastOffset, Token.NULL); + } addToken(len, id); lastOffset = i; // } @@ -494,13 +508,21 @@ private boolean tokenListContainsKeyword() { boolean result = false; String str = ""; while (token != null) { - str += "" + token.id + "(" + token.length + ") "; + str += "" + + token.id + + "(" + + token.length + + ") "; if (token.id == Token.KEYWORD1 || token.id == Token.KEYWORD2 || token.id == Token.KEYWORD3) { result = true; } token = token.next; } - System.out.println("" + result + " " + str); + System.out.println( + "" + + result + + " " + + str); return result; } } diff --git a/mars/venus/editors/jeditsyntax/tokenmarker/Token.java b/mars/venus/editors/jeditsyntax/tokenmarker/Token.java index c947908..bc85749 100644 --- a/mars/venus/editors/jeditsyntax/tokenmarker/Token.java +++ b/mars/venus/editors/jeditsyntax/tokenmarker/Token.java @@ -96,10 +96,25 @@ public class Token { */ public static final byte MACRO_ARG = 11; + /** + * Editor background color token. Added for MARS 4.5.1Unofficial. + */ + public static final byte EDITOR_BG = 12; + + /** + * Editor selected line background color token. Added for MARS 4.5.1Unofficial. + */ + public static final byte EDITOR_LINE = 13; + + /** + * Editor selection color token. Added for MARS 4.5.1Unofficial. + */ + public static final byte EDITOR_SELECTION = 14; + /** * The total number of defined token ids. */ - public static final byte ID_COUNT = 12; + public static final byte ID_COUNT = 15; /** * The first id that can be used for internal state in a token marker. @@ -136,7 +151,7 @@ public class Token { * Creates a new token. * * @param length The length of the token - * @param id The id of the token + * @param id The id of the token */ public Token(final int length, final byte id) { this.length = length; @@ -147,7 +162,9 @@ public Token(final int length, final byte id) { * Returns a string representation of this token. */ @Override - public String toString() { - return "[id=" + id + ",length=" + length + "]"; - } + public String toString() { return "[id=" + + id + + ",length=" + + length + + "]"; } }