From ef2ce4ecac58df90b280e6ec329b66989a87d0e8 Mon Sep 17 00:00:00 2001 From: peterdell Date: Sat, 18 Sep 2021 01:49:03 +0200 Subject: [PATCH] Split HardwareUtility and move to base plugin --- .../com/wudsn/ide/asm/HardwareUtility.java | 99 ------------- ...AssemblerEditorCompileCommandDelegate.java | 2 +- .../help/AssemblerHelpContentProducer.java | 2 +- .../AssemblerPreferencesInitializer.java | 2 +- .../icons/hardware-apple2-16x16.gif | Bin .../icons/hardware-atari2600-16x16.gif | Bin .../icons/hardware-atari7800-16x16.gif | Bin .../icons/hardware-atari8bit-16x16.gif | Bin .../icons/hardware-atari8bit-32x32.gif | Bin .../icons/hardware-c64-16x16.gif | Bin .../icons/hardware-generic-16x16.gif | Bin .../icons/hardware-nes-16x16.gif | Bin .../icons/hardware-test-16x16.gif | Bin .../ide/base/hardware/HardwareUtility.java | 138 ++++++++++++++++++ 14 files changed, 141 insertions(+), 102 deletions(-) rename {com.wudsn.ide.asm => com.wudsn.ide.base}/icons/hardware-apple2-16x16.gif (100%) rename {com.wudsn.ide.asm => com.wudsn.ide.base}/icons/hardware-atari2600-16x16.gif (100%) rename {com.wudsn.ide.asm => com.wudsn.ide.base}/icons/hardware-atari7800-16x16.gif (100%) rename {com.wudsn.ide.asm => com.wudsn.ide.base}/icons/hardware-atari8bit-16x16.gif (100%) rename {com.wudsn.ide.asm => com.wudsn.ide.base}/icons/hardware-atari8bit-32x32.gif (100%) rename {com.wudsn.ide.asm => com.wudsn.ide.base}/icons/hardware-c64-16x16.gif (100%) rename {com.wudsn.ide.asm => com.wudsn.ide.base}/icons/hardware-generic-16x16.gif (100%) rename {com.wudsn.ide.asm => com.wudsn.ide.base}/icons/hardware-nes-16x16.gif (100%) rename {com.wudsn.ide.asm => com.wudsn.ide.base}/icons/hardware-test-16x16.gif (100%) create mode 100644 com.wudsn.ide.base/src/com/wudsn/ide/base/hardware/HardwareUtility.java diff --git a/com.wudsn.ide.asm/src/com/wudsn/ide/asm/HardwareUtility.java b/com.wudsn.ide.asm/src/com/wudsn/ide/asm/HardwareUtility.java index 02632a30..3c6cc3d7 100644 --- a/com.wudsn.ide.asm/src/com/wudsn/ide/asm/HardwareUtility.java +++ b/com.wudsn.ide.asm/src/com/wudsn/ide/asm/HardwareUtility.java @@ -38,105 +38,6 @@ public final class HardwareUtility { private HardwareUtility() { } - /** - * Gets the default file extension for executable files on a hardware. - * - * @param hardware The hardware, not null. - * @return The default file extension, may be empty, not null. - * - * @since 1.6.1 - */ - public static String getDefaultFileExtension(Hardware hardware) { - if (hardware == null) { - throw new IllegalArgumentException("Parameter 'hardware' must not be null."); - } - switch (hardware) { - case APPLE2: - // AppleDos 3.3 binary file - // start-lo,start-hi,length-lo,length-hi,data - return ".b"; - case ATARI2600: - // Atari VCS ROM cartridge - return ".bin"; - case ATARI7800: - // Atari 7800 ROM cartridge - return ".bin"; - case ATARI8BIT: - // AtariDOS 2.5 compound file, - // $ff,$ff,start-lo,start-hi,end-lo,end-hi,data - return ".xex"; - case C64: - // C64 program file - // start-lo,start-hi,data - return ".prg"; - case NES: - // NES ROM file - return ".nes"; - case TEST: - return ".tst"; - default: - return ""; - } - } - - /** - * Gets the image path for a hardware image. - * - * @param hardware The hardware, not null. - * @return The image path for the hardware image, not empty and not - * null. - */ - public static String getImagePath(Hardware hardware) { - if (hardware == null) { - throw new IllegalArgumentException("Parameter 'hardware' must not be null."); - } - String path; - switch (hardware) { - case GENERIC: - path = "hardware-generic-16x16.gif"; - break; - case APPLE2: - path = "hardware-apple2-16x16.gif"; - break; - case ATARI2600: - path = "hardware-atari2600-16x16.gif"; - break; - case ATARI7800: - path = "hardware-atari7800-16x16.gif"; - break; - case ATARI8BIT: - path = "hardware-atari8bit-16x16.gif"; - break; - case C64: - path = "hardware-c64-16x16.gif"; - break; - case NES: - path = "hardware-nes-16x16.gif"; - break; - case TEST: - path = "hardware-test-16x16.gif"; - break; - default: - throw new IllegalArgumentException("Unknown hardware " + hardware + "."); - } - return path; - } - - /** - * Gets the image descriptor for a hardware image. - * - * @param hardware The hardware, not null. - * @return The image descriptor for the hardware image, not null. - */ - public static ImageDescriptor getImageDescriptor(Hardware hardware) { - if (hardware == null) { - throw new IllegalArgumentException("Parameter 'hardware' must not be null."); - } - ImageDescriptor result; - result = AssemblerPlugin.getInstance().getImageDescriptor(getImagePath(hardware)); - return result; - } - /** * Gets the compiler file writer a hardware. * diff --git a/com.wudsn.ide.asm/src/com/wudsn/ide/asm/editor/AssemblerEditorCompileCommandDelegate.java b/com.wudsn.ide.asm/src/com/wudsn/ide/asm/editor/AssemblerEditorCompileCommandDelegate.java index ea2b6997..86c6e6c9 100644 --- a/com.wudsn.ide.asm/src/com/wudsn/ide/asm/editor/AssemblerEditorCompileCommandDelegate.java +++ b/com.wudsn.ide.asm/src/com/wudsn/ide/asm/editor/AssemblerEditorCompileCommandDelegate.java @@ -36,7 +36,6 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2; import com.wudsn.ide.asm.AssemblerPlugin; -import com.wudsn.ide.asm.HardwareUtility; import com.wudsn.ide.asm.Texts; import com.wudsn.ide.asm.preferences.CompilerPreferences; import com.wudsn.ide.asm.runner.RunnerDefinition; @@ -44,6 +43,7 @@ import com.wudsn.ide.asm.runner.RunnerId; import com.wudsn.ide.asm.runner.RunnerRegistry; import com.wudsn.ide.base.common.StringUtility; import com.wudsn.ide.base.hardware.Hardware; +import com.wudsn.ide.base.hardware.HardwareUtility; /** * Delegate class to provide a dynamic drop-down menu for the toolbar based on diff --git a/com.wudsn.ide.asm/src/com/wudsn/ide/asm/help/AssemblerHelpContentProducer.java b/com.wudsn.ide.asm/src/com/wudsn/ide/asm/help/AssemblerHelpContentProducer.java index 95fa9d17..6f9b3845 100644 --- a/com.wudsn.ide.asm/src/com/wudsn/ide/asm/help/AssemblerHelpContentProducer.java +++ b/com.wudsn.ide.asm/src/com/wudsn/ide/asm/help/AssemblerHelpContentProducer.java @@ -44,7 +44,6 @@ import org.eclipse.help.IHelpContentProducer; import com.wudsn.ide.asm.AssemblerPlugin; import com.wudsn.ide.asm.CPU; -import com.wudsn.ide.asm.HardwareUtility; import com.wudsn.ide.asm.Texts; import com.wudsn.ide.asm.compiler.Compiler; import com.wudsn.ide.asm.compiler.CompilerDefinition; @@ -65,6 +64,7 @@ import com.wudsn.ide.base.common.HexUtility; import com.wudsn.ide.base.common.StringUtility; import com.wudsn.ide.base.common.TextUtility; import com.wudsn.ide.base.hardware.Hardware; +import com.wudsn.ide.base.hardware.HardwareUtility; /** * Dynamic help content provider. Uses static pages and the meta data from the diff --git a/com.wudsn.ide.asm/src/com/wudsn/ide/asm/preferences/AssemblerPreferencesInitializer.java b/com.wudsn.ide.asm/src/com/wudsn/ide/asm/preferences/AssemblerPreferencesInitializer.java index ffd9344b..d51e359e 100644 --- a/com.wudsn.ide.asm/src/com/wudsn/ide/asm/preferences/AssemblerPreferencesInitializer.java +++ b/com.wudsn.ide.asm/src/com/wudsn/ide/asm/preferences/AssemblerPreferencesInitializer.java @@ -29,7 +29,6 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Display; import com.wudsn.ide.asm.AssemblerPlugin; -import com.wudsn.ide.asm.HardwareUtility; import com.wudsn.ide.asm.compiler.CompilerDefinition; import com.wudsn.ide.asm.compiler.CompilerOutputFolderMode; import com.wudsn.ide.asm.compiler.CompilerRegistry; @@ -37,6 +36,7 @@ import com.wudsn.ide.asm.editor.AssemblerContentAssistProcessorDefaultCase; import com.wudsn.ide.asm.editor.AssemblerEditorCompileCommandPositioningMode; import com.wudsn.ide.asm.runner.RunnerId; import com.wudsn.ide.base.hardware.Hardware; +import com.wudsn.ide.base.hardware.HardwareUtility; /** * Initializer for setting defaults values in the preferences. diff --git a/com.wudsn.ide.asm/icons/hardware-apple2-16x16.gif b/com.wudsn.ide.base/icons/hardware-apple2-16x16.gif similarity index 100% rename from com.wudsn.ide.asm/icons/hardware-apple2-16x16.gif rename to com.wudsn.ide.base/icons/hardware-apple2-16x16.gif diff --git a/com.wudsn.ide.asm/icons/hardware-atari2600-16x16.gif b/com.wudsn.ide.base/icons/hardware-atari2600-16x16.gif similarity index 100% rename from com.wudsn.ide.asm/icons/hardware-atari2600-16x16.gif rename to com.wudsn.ide.base/icons/hardware-atari2600-16x16.gif diff --git a/com.wudsn.ide.asm/icons/hardware-atari7800-16x16.gif b/com.wudsn.ide.base/icons/hardware-atari7800-16x16.gif similarity index 100% rename from com.wudsn.ide.asm/icons/hardware-atari7800-16x16.gif rename to com.wudsn.ide.base/icons/hardware-atari7800-16x16.gif diff --git a/com.wudsn.ide.asm/icons/hardware-atari8bit-16x16.gif b/com.wudsn.ide.base/icons/hardware-atari8bit-16x16.gif similarity index 100% rename from com.wudsn.ide.asm/icons/hardware-atari8bit-16x16.gif rename to com.wudsn.ide.base/icons/hardware-atari8bit-16x16.gif diff --git a/com.wudsn.ide.asm/icons/hardware-atari8bit-32x32.gif b/com.wudsn.ide.base/icons/hardware-atari8bit-32x32.gif similarity index 100% rename from com.wudsn.ide.asm/icons/hardware-atari8bit-32x32.gif rename to com.wudsn.ide.base/icons/hardware-atari8bit-32x32.gif diff --git a/com.wudsn.ide.asm/icons/hardware-c64-16x16.gif b/com.wudsn.ide.base/icons/hardware-c64-16x16.gif similarity index 100% rename from com.wudsn.ide.asm/icons/hardware-c64-16x16.gif rename to com.wudsn.ide.base/icons/hardware-c64-16x16.gif diff --git a/com.wudsn.ide.asm/icons/hardware-generic-16x16.gif b/com.wudsn.ide.base/icons/hardware-generic-16x16.gif similarity index 100% rename from com.wudsn.ide.asm/icons/hardware-generic-16x16.gif rename to com.wudsn.ide.base/icons/hardware-generic-16x16.gif diff --git a/com.wudsn.ide.asm/icons/hardware-nes-16x16.gif b/com.wudsn.ide.base/icons/hardware-nes-16x16.gif similarity index 100% rename from com.wudsn.ide.asm/icons/hardware-nes-16x16.gif rename to com.wudsn.ide.base/icons/hardware-nes-16x16.gif diff --git a/com.wudsn.ide.asm/icons/hardware-test-16x16.gif b/com.wudsn.ide.base/icons/hardware-test-16x16.gif similarity index 100% rename from com.wudsn.ide.asm/icons/hardware-test-16x16.gif rename to com.wudsn.ide.base/icons/hardware-test-16x16.gif diff --git a/com.wudsn.ide.base/src/com/wudsn/ide/base/hardware/HardwareUtility.java b/com.wudsn.ide.base/src/com/wudsn/ide/base/hardware/HardwareUtility.java new file mode 100644 index 00000000..f4598243 --- /dev/null +++ b/com.wudsn.ide.base/src/com/wudsn/ide/base/hardware/HardwareUtility.java @@ -0,0 +1,138 @@ +/** + * Copyright (C) 2009 - 2021 Peter Dell + * + * This file is part of WUDSN IDE. + * + * WUDSN IDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * WUDSN IDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WUDSN IDE. If not, see . + */ +package com.wudsn.ide.base.hardware; + +import org.eclipse.jface.resource.ImageDescriptor; + +import com.wudsn.ide.base.BasePlugin; + +/** + * Map value of {@link Hardware} to icon paths and descriptors. + * + * @author Peter Dell + * + */ +public final class HardwareUtility { + + /** + * Creation is private. + */ + private HardwareUtility() { + } + + /** + * Gets the default file extension for executable files on a hardware. + * + * @param hardware The hardware, not null. + * @return The default file extension, may be empty, not null. + * + * @since 1.6.1 + */ + public static String getDefaultFileExtension(Hardware hardware) { + if (hardware == null) { + throw new IllegalArgumentException("Parameter 'hardware' must not be null."); + } + switch (hardware) { + case APPLE2: + // AppleDos 3.3 binary file + // start-lo,start-hi,length-lo,length-hi,data + return ".b"; + case ATARI2600: + // Atari VCS ROM cartridge + return ".bin"; + case ATARI7800: + // Atari 7800 ROM cartridge + return ".bin"; + case ATARI8BIT: + // AtariDOS 2.5 compound file, + // $ff,$ff,start-lo,start-hi,end-lo,end-hi,data + return ".xex"; + case C64: + // C64 program file + // start-lo,start-hi,data + return ".prg"; + case NES: + // NES ROM file + return ".nes"; + case TEST: + return ".tst"; + default: + return ""; + } + } + + /** + * Gets the image path for a hardware image. + * + * @param hardware The hardware, not null. + * @return The image path for the hardware image, not empty and not + * null. + */ + public static String getImagePath(Hardware hardware) { + if (hardware == null) { + throw new IllegalArgumentException("Parameter 'hardware' must not be null."); + } + String path; + switch (hardware) { + case GENERIC: + path = "hardware-generic-16x16.gif"; + break; + case APPLE2: + path = "hardware-apple2-16x16.gif"; + break; + case ATARI2600: + path = "hardware-atari2600-16x16.gif"; + break; + case ATARI7800: + path = "hardware-atari7800-16x16.gif"; + break; + case ATARI8BIT: + path = "hardware-atari8bit-16x16.gif"; + break; + case C64: + path = "hardware-c64-16x16.gif"; + break; + case NES: + path = "hardware-nes-16x16.gif"; + break; + case TEST: + path = "hardware-test-16x16.gif"; + break; + default: + throw new IllegalArgumentException("Unknown hardware " + hardware + "."); + } + return path; + } + + /** + * Gets the image descriptor for a hardware image. + * + * @param hardware The hardware, not null. + * @return The image descriptor for the hardware image, not null. + */ + public static ImageDescriptor getImageDescriptor(Hardware hardware) { + if (hardware == null) { + throw new IllegalArgumentException("Parameter 'hardware' must not be null."); + } + ImageDescriptor result; + result = BasePlugin.getInstance().getImageDescriptor(getImagePath(hardware)); + return result; + } + +}