Split HardwareUtility and move to base plugin

This commit is contained in:
peterdell 2021-09-18 01:49:03 +02:00
parent 77f1c60e25
commit ef2ce4ecac
14 changed files with 141 additions and 102 deletions

View File

@ -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 <code>null</code>.
* @return The default file extension, may be empty, not <code>null</code>.
*
* @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 <code>null</code>.
* @return The image path for the hardware image, not empty and not
* <code>null</code>.
*/
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 <code>null</code>.
* @return The image descriptor for the hardware image, not <code>null</code>.
*/
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.
*

View File

@ -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

View File

@ -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

View File

@ -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.

View File

Before

Width:  |  Height:  |  Size: 619 B

After

Width:  |  Height:  |  Size: 619 B

View File

Before

Width:  |  Height:  |  Size: 293 B

After

Width:  |  Height:  |  Size: 293 B

View File

Before

Width:  |  Height:  |  Size: 395 B

After

Width:  |  Height:  |  Size: 395 B

View File

Before

Width:  |  Height:  |  Size: 211 B

After

Width:  |  Height:  |  Size: 211 B

View File

Before

Width:  |  Height:  |  Size: 351 B

After

Width:  |  Height:  |  Size: 351 B

View File

Before

Width:  |  Height:  |  Size: 614 B

After

Width:  |  Height:  |  Size: 614 B

View File

Before

Width:  |  Height:  |  Size: 947 B

After

Width:  |  Height:  |  Size: 947 B

View File

Before

Width:  |  Height:  |  Size: 263 B

After

Width:  |  Height:  |  Size: 263 B

View File

Before

Width:  |  Height:  |  Size: 961 B

After

Width:  |  Height:  |  Size: 961 B

View File

@ -0,0 +1,138 @@
/**
* Copyright (C) 2009 - 2021 <a href="https://www.wudsn.com" target="_top">Peter Dell</a>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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 <code>null</code>.
* @return The default file extension, may be empty, not <code>null</code>.
*
* @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 <code>null</code>.
* @return The image path for the hardware image, not empty and not
* <code>null</code>.
*/
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 <code>null</code>.
* @return The image descriptor for the hardware image, not <code>null</code>.
*/
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;
}
}