Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b9997e3edc | ||
|
|
45c8a69d7b | ||
|
|
2e2163fefb | ||
|
|
995b372f55 | ||
|
|
47c87aac56 |
No files matched your search
@@ -7,7 +7,7 @@ SYMON - A 6502 System Simulator
|
|||||||
|
|
||||||
See the file COPYING for license.
|
See the file COPYING for license.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 1.0 About
|
## 1.0 About
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ memory.
|
|||||||
|
|
||||||
### 3.2 Serial Console and CPU Status
|
### 3.2 Serial Console and CPU Status
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
The main window of the simulator acts as the primary Input/Output
|
The main window of the simulator acts as the primary Input/Output
|
||||||
system through a virtual serial terminal. It also provides CPU status.
|
system through a virtual serial terminal. It also provides CPU status.
|
||||||
@@ -100,13 +100,13 @@ see the official datasheet:
|
|||||||
|
|
||||||
- [MOS 6551 ACIA](http://archive.6502.org/datasheets/mos_6551_acia.pdf)
|
- [MOS 6551 ACIA](http://archive.6502.org/datasheets/mos_6551_acia.pdf)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
The console supports font sizes from 10 to 20 points.
|
The console supports font sizes from 10 to 20 points.
|
||||||
|
|
||||||
### 3.3 ROM Loading
|
### 3.3 ROM Loading
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Symon can load any appropriately sized ROM image. The Symon
|
Symon can load any appropriately sized ROM image. The Symon
|
||||||
architecture expects as 16KB (16384 byte) ROM image, while the
|
architecture expects as 16KB (16384 byte) ROM image, while the
|
||||||
@@ -117,32 +117,32 @@ address.
|
|||||||
|
|
||||||
### 3.4 Memory Window
|
### 3.4 Memory Window
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Memory contents can be viewed (and edited) one page at a time through the Memory Window.
|
Memory contents can be viewed (and edited) one page at a time through the Memory Window.
|
||||||
|
|
||||||
### 3.5 Trace Log
|
### 3.5 Trace Log
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
The last 20,000 execution steps are disassembled and logged to the Trace Log
|
The last 20,000 execution steps are disassembled and logged to the Trace Log
|
||||||
Window.
|
Window.
|
||||||
|
|
||||||
### 3.6 Simulator Speeds
|
### 3.6 Simulator Speeds
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Simulated speeds may be set from 1MHz to 8MHz.
|
Simulated speeds may be set from 1MHz to 8MHz.
|
||||||
|
|
||||||
### 3.7 Breakpoints
|
### 3.7 Breakpoints
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Breakpoints can be set and removed through the Breakpoints window.
|
Breakpoints can be set and removed through the Breakpoints window.
|
||||||
|
|
||||||
### 3.8 Experimental 6545 CRTC Video
|
### 3.8 Experimental 6545 CRTC Video
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
This feature is highly experimental. It's possible to open a video window
|
This feature is highly experimental. It's possible to open a video window
|
||||||
from the "View" menu. This window simulates the output of a MOS 6545 CRT
|
from the "View" menu. This window simulates the output of a MOS 6545 CRT
|
||||||
@@ -229,7 +229,18 @@ to specify machine type and CPU type. The options are:
|
|||||||
- `-r`,`-rom <file>`: Use the specified file as the ROM image.
|
- `-r`,`-rom <file>`: Use the specified file as the ROM image.
|
||||||
- `-b`,`-brk`: Halt the simulator on a BRK instruction (default is to continue)
|
- `-b`,`-brk`: Halt the simulator on a BRK instruction (default is to continue)
|
||||||
|
|
||||||
### 4.2 ROM images
|
### 4.2 High-DPI UI scaling
|
||||||
|
|
||||||
|
In certain environments with high-DPI (e.g. 4K) displays, the UI may
|
||||||
|
not automatically scale and appear quite tiny. This can be fixed
|
||||||
|
with the command line argument `-Dsun.java2d.uiScale=<factor>`,
|
||||||
|
for example:
|
||||||
|
|
||||||
|
```
|
||||||
|
java -Dsun.java2d.uiScale=2.0 -jar symon-1.5.0.jar
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.3 ROM images
|
||||||
|
|
||||||
The simulator requires a ROM image loaded into memory to work
|
The simulator requires a ROM image loaded into memory to work
|
||||||
properly. Without a ROM in memory, the simulator will not be able to
|
properly. Without a ROM in memory, the simulator will not be able to
|
||||||
@@ -247,7 +258,7 @@ architecture named 'ehbasic.rom', containing Lee Davison's Enhanced
|
|||||||
*Note*: Presently, EhBASIC only works with the Symon machine
|
*Note*: Presently, EhBASIC only works with the Symon machine
|
||||||
architecture, not with MULTICOMP.
|
architecture, not with MULTICOMP.
|
||||||
|
|
||||||
### 4.3 Loading A Program
|
### 4.4 Loading A Program
|
||||||
|
|
||||||
In addition to ROM images, programs in the form of raw binary object files can
|
In addition to ROM images, programs in the form of raw binary object files can
|
||||||
be loaded directly into memory from "Load Program..." in the File menu.
|
be loaded directly into memory from "Load Program..." in the File menu.
|
||||||
@@ -263,7 +274,7 @@ for testing.
|
|||||||
|
|
||||||
- 'hello.prg' will continuously print "Hello, 6502 World!" to the console.
|
- 'hello.prg' will continuously print "Hello, 6502 World!" to the console.
|
||||||
|
|
||||||
### 4.4 Running
|
### 4.5 Running
|
||||||
|
|
||||||
After loading a program or ROM image, clicking "Run" will start the simulator
|
After loading a program or ROM image, clicking "Run" will start the simulator
|
||||||
running.
|
running.
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="https://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4.0.0.xsd">
|
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.loomcom.symon</groupId>
|
<groupId>com.loomcom.symon</groupId>
|
||||||
<artifactId>symon</artifactId>
|
<artifactId>symon</artifactId>
|
||||||
@@ -15,12 +16,33 @@
|
|||||||
UTF-8
|
UTF-8
|
||||||
</project.reporting.outputEncoding>
|
</project.reporting.outputEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>1.5.16</version>
|
<version>1.5.16</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-cli</groupId>
|
||||||
|
<artifactId>commons-cli</artifactId>
|
||||||
|
<version>1.5.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.formdev</groupId>
|
||||||
|
<artifactId>flatlaf</artifactId>
|
||||||
|
<version>3.7.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.Dansoftowner</groupId>
|
||||||
|
<artifactId>jSystemThemeDetector</artifactId>
|
||||||
|
<version>3.9.1</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
@@ -33,11 +55,6 @@
|
|||||||
<version>4.11.0</version>
|
<version>4.11.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>commons-cli</groupId>
|
|
||||||
<artifactId>commons-cli</artifactId>
|
|
||||||
<version>1.5.0</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -48,7 +65,8 @@
|
|||||||
<version>3.2.0</version>
|
<version>3.2.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<transformers>
|
<transformers>
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
<transformer
|
||||||
|
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
<mainClass>com.loomcom.symon.Main</mainClass>
|
<mainClass>com.loomcom.symon.Main</mainClass>
|
||||||
</transformer>
|
</transformer>
|
||||||
</transformers>
|
</transformers>
|
||||||
@@ -120,4 +138,4 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
@@ -25,19 +25,20 @@
|
|||||||
package com.loomcom.symon;
|
package com.loomcom.symon;
|
||||||
|
|
||||||
import com.loomcom.symon.machines.*;
|
import com.loomcom.symon.machines.*;
|
||||||
|
import com.loomcom.symon.ui.Ui;
|
||||||
|
|
||||||
import org.apache.commons.cli.*;
|
import org.apache.commons.cli.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.UIManager;
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
private final static Logger logger = LoggerFactory.getLogger(Main.class.getName());
|
private final static Logger logger = LoggerFactory.getLogger(Main.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main entry point to the simulator. Creates a simulator and shows the main
|
* Main entry point to the simulator. Creates a simulator and shows the main
|
||||||
* window.
|
* window.
|
||||||
*
|
*
|
||||||
@@ -49,6 +50,7 @@ public class Main {
|
|||||||
|
|
||||||
Options options = new Options();
|
Options options = new Options();
|
||||||
|
|
||||||
|
options.addOption(new Option("h", "help", false, "Print this message."));
|
||||||
options.addOption(new Option("m", "machine", true, "Specify machine type."));
|
options.addOption(new Option("m", "machine", true, "Specify machine type."));
|
||||||
options.addOption(new Option("c", "cpu", true, "Specify CPU type."));
|
options.addOption(new Option("c", "cpu", true, "Specify CPU type."));
|
||||||
options.addOption(new Option("r", "rom", true, "Specify ROM file."));
|
options.addOption(new Option("r", "rom", true, "Specify ROM file."));
|
||||||
@@ -57,11 +59,18 @@ public class Main {
|
|||||||
CommandLineParser parser = new DefaultParser();
|
CommandLineParser parser = new DefaultParser();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
CommandLine line = parser.parse(options, args);
|
CommandLine line = parser.parse(options, args);
|
||||||
InstructionTable.CpuBehavior cpuBehavior = null;
|
InstructionTable.CpuBehavior cpuBehavior = null;
|
||||||
String romFile = null;
|
String romFile = null;
|
||||||
boolean haltOnBreak = false;
|
boolean haltOnBreak = false;
|
||||||
|
|
||||||
|
if (line.hasOption("help")) {
|
||||||
|
HelpFormatter formatter = new HelpFormatter();
|
||||||
|
formatter.printHelp("symon", options, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (line.hasOption("machine")) {
|
if (line.hasOption("machine")) {
|
||||||
String machine = line.getOptionValue("machine").toLowerCase(Locale.ENGLISH);
|
String machine = line.getOptionValue("machine").toLowerCase(Locale.ENGLISH);
|
||||||
switch (machine) {
|
switch (machine) {
|
||||||
@@ -109,28 +118,11 @@ public class Main {
|
|||||||
haltOnBreak = true;
|
haltOnBreak = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ui.initUi();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (machineClass == null) {
|
if (machineClass == null) {
|
||||||
Object[] possibilities = {"Symon", "Multicomp", "Simple", "BenEater"};
|
machineClass = Ui.showMachineSelectionDialog();
|
||||||
String s = (String)JOptionPane.showInputDialog(
|
|
||||||
null,
|
|
||||||
"Please choose the machine type to be emulated:",
|
|
||||||
"Machine selection",
|
|
||||||
JOptionPane.PLAIN_MESSAGE,
|
|
||||||
null,
|
|
||||||
possibilities,
|
|
||||||
"Symon");
|
|
||||||
|
|
||||||
|
|
||||||
if (s != null && s.equals("Multicomp")) {
|
|
||||||
machineClass = MulticompMachine.class;
|
|
||||||
} else if (s != null && s.equals("Simple")) {
|
|
||||||
machineClass = SimpleMachine.class;
|
|
||||||
} else if (s != null && s.equals("BenEater")) {
|
|
||||||
machineClass = BenEaterMachine.class;
|
|
||||||
} else {
|
|
||||||
machineClass = SymonMachine.class;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cpuBehavior == null) {
|
if (cpuBehavior == null) {
|
||||||
@@ -140,9 +132,8 @@ public class Main {
|
|||||||
final Simulator simulator = new Simulator(machineClass, cpuBehavior, romFile, haltOnBreak);
|
final Simulator simulator = new Simulator(machineClass, cpuBehavior, romFile, haltOnBreak);
|
||||||
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
// Create the main UI window:
|
||||||
try {
|
try {
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
||||||
// Create the main UI window
|
|
||||||
simulator.createAndShowUi();
|
simulator.createAndShowUi();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error during Symon UI initialization: {}", e.getMessage());
|
logger.error("Error during Symon UI initialization: {}", e.getMessage());
|
||||||
@@ -150,7 +141,6 @@ public class Main {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Simulator.MainCommand cmd = simulator.waitForCommand();
|
Simulator.MainCommand cmd = simulator.waitForCommand();
|
||||||
|
|
||||||
if (cmd.equals(Simulator.MainCommand.SELECTMACHINE)) {
|
if (cmd.equals(Simulator.MainCommand.SELECTMACHINE)) {
|
||||||
@@ -163,4 +153,5 @@ public class Main {
|
|||||||
logger.error("Could not start Symon. Reason: {}", ex.getMessage());
|
logger.error("Could not start Symon. Reason: {}", ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,6 @@ public class BreakpointsWindow extends JFrame {
|
|||||||
|
|
||||||
final JTable breakpointsTable = new JTable(breakpoints);
|
final JTable breakpointsTable = new JTable(breakpoints);
|
||||||
breakpointsTable.setShowGrid(true);
|
breakpointsTable.setShowGrid(true);
|
||||||
breakpointsTable.setGridColor(Color.LIGHT_GRAY);
|
|
||||||
breakpointsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
breakpointsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
breakpointsTable.getSelectionModel().addListSelectionListener(e -> removeButton.setEnabled(e.getFirstIndex() > -1));
|
breakpointsTable.getSelectionModel().addListSelectionListener(e -> removeButton.setEnabled(e.getFirstIndex() > -1));
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class StatusPanel extends JPanel {
|
|||||||
|
|
||||||
private void createUi() {
|
private void createUi() {
|
||||||
Border emptyBorder = BorderFactory.createEmptyBorder(EMPTY_BORDER, EMPTY_BORDER,
|
Border emptyBorder = BorderFactory.createEmptyBorder(EMPTY_BORDER, EMPTY_BORDER,
|
||||||
EMPTY_BORDER, EMPTY_BORDER);
|
EMPTY_BORDER, EMPTY_BORDER);
|
||||||
Border etchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
|
Border etchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
|
||||||
|
|
||||||
setBorder(BorderFactory.createCompoundBorder(emptyBorder, etchedBorder));
|
setBorder(BorderFactory.createCompoundBorder(emptyBorder, etchedBorder));
|
||||||
@@ -125,16 +125,15 @@ public class StatusPanel extends JPanel {
|
|||||||
|
|
||||||
// Add tool-tip text
|
// Add tool-tip text
|
||||||
carryFlagLabel.setToolTipText("Carry: The last operation caused an overflow " +
|
carryFlagLabel.setToolTipText("Carry: The last operation caused an overflow " +
|
||||||
"from bit 7 of the result or an underflow from bit 0");
|
"from bit 7 of the result or an underflow from bit 0");
|
||||||
zeroFlagLabel.setToolTipText("Zero: The result of the last operation was 0");
|
zeroFlagLabel.setToolTipText("Zero: The result of the last operation was 0");
|
||||||
irqDisableFlagLabel.setToolTipText("Interrupt Disable: Processor will not respond to IRQ");
|
irqDisableFlagLabel.setToolTipText("Interrupt Disable: Processor will not respond to IRQ");
|
||||||
decimalModeFlagLabel.setToolTipText("Decimal Mode");
|
decimalModeFlagLabel.setToolTipText("Decimal Mode");
|
||||||
breakFlagLabel.setToolTipText("Break: BRK instruction occurred");
|
breakFlagLabel.setToolTipText("Break: BRK instruction occurred");
|
||||||
overflowFlagLabel.setToolTipText("Overflow: The result of the last operation was " +
|
overflowFlagLabel.setToolTipText("Overflow: The result of the last operation was " +
|
||||||
"an invalid 2's complement result");
|
"an invalid 2's complement result");
|
||||||
negativeFlagLabel.setToolTipText("Negative: The result of the last operation set bit 7");
|
negativeFlagLabel.setToolTipText("Negative: The result of the last operation set bit 7");
|
||||||
|
|
||||||
|
|
||||||
statusFlagsPanel.add(negativeFlagLabel);
|
statusFlagsPanel.add(negativeFlagLabel);
|
||||||
statusFlagsPanel.add(overflowFlagLabel);
|
statusFlagsPanel.add(overflowFlagLabel);
|
||||||
statusFlagsPanel.add(breakFlagLabel);
|
statusFlagsPanel.add(breakFlagLabel);
|
||||||
@@ -243,7 +242,6 @@ public class StatusPanel extends JPanel {
|
|||||||
constraints.gridy = 1;
|
constraints.gridy = 1;
|
||||||
add(statusFlagsPanel, constraints);
|
add(statusFlagsPanel, constraints);
|
||||||
|
|
||||||
|
|
||||||
constraints.insets = new Insets(5, 0, 0, 0);
|
constraints.insets = new Insets(5, 0, 0, 0);
|
||||||
constraints.gridy = 2;
|
constraints.gridy = 2;
|
||||||
add(opcodeLabel, constraints);
|
add(opcodeLabel, constraints);
|
||||||
@@ -392,13 +390,6 @@ public class StatusPanel extends JPanel {
|
|||||||
textField.setMinimumSize(size);
|
textField.setMinimumSize(size);
|
||||||
textField.setMaximumSize(size);
|
textField.setMaximumSize(size);
|
||||||
textField.setPreferredSize(size);
|
textField.setPreferredSize(size);
|
||||||
textField.setBackground(Color.WHITE);
|
|
||||||
// Although we usually defer to the system look-and-feel, for
|
|
||||||
// these small text fields in particular, we use a Metal
|
|
||||||
// look-and-feel because native look-and-feel breaks very small
|
|
||||||
// text fields under GTK+ (they are drawn with an inner margin
|
|
||||||
// even if the margin is set to 0)
|
|
||||||
textField.setUI(new MetalTextFieldUI());
|
|
||||||
|
|
||||||
return textField;
|
return textField;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2008-2025 Seth J. Morabito <web@loomcom.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.loomcom.symon.ui;
|
||||||
|
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.LookAndFeel;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.UnsupportedLookAndFeelException;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.formdev.flatlaf.FlatDarkLaf;
|
||||||
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
|
import com.formdev.flatlaf.FlatLightLaf;
|
||||||
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
|
import com.jthemedetecor.OsThemeDetector;
|
||||||
|
import com.loomcom.symon.machines.BenEaterMachine;
|
||||||
|
import com.loomcom.symon.machines.MulticompMachine;
|
||||||
|
import com.loomcom.symon.machines.SimpleMachine;
|
||||||
|
import com.loomcom.symon.machines.SymonMachine;
|
||||||
|
|
||||||
|
public final class Ui {
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(Ui.class.getName());
|
||||||
|
|
||||||
|
public static void initUi() throws UnsupportedLookAndFeelException {
|
||||||
|
// Location of properties resources for app-specific UI defaults:
|
||||||
|
FlatLaf.registerCustomDefaultsSource("com.loomcom.symon.themes");
|
||||||
|
|
||||||
|
// Enable automatic scaling, based on system DPI settings:
|
||||||
|
System.setProperty("sun.java2d.uiScale.enabled", "true");
|
||||||
|
System.setProperty("sun.java2d.uiScale", "1x");
|
||||||
|
System.setProperty("flatlaf.uiScale", "1x");
|
||||||
|
|
||||||
|
// OS-specific tweaking:
|
||||||
|
|
||||||
|
if (SystemInfo.isLinux) {
|
||||||
|
logger.debug("Adapting UI for Linux.");
|
||||||
|
|
||||||
|
// Enable custom window decorations:
|
||||||
|
JFrame.setDefaultLookAndFeelDecorated(true);
|
||||||
|
JDialog.setDefaultLookAndFeelDecorated(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (SystemInfo.isMacOS) {
|
||||||
|
logger.debug("Adapting UI for MacOS.");
|
||||||
|
|
||||||
|
// Move menu bar from JFrame window to top of screen:
|
||||||
|
System.setProperty("apple.laf.useScreenMenuBar", "true");
|
||||||
|
// Set name used in screen menu bar (first menu after Apple menu):
|
||||||
|
System.setProperty("apple.awt.application.name", "Symon");
|
||||||
|
// Use current macOS appearance (light/dark) for window title bars:
|
||||||
|
System.setProperty("apple.awt.application.appearance", "system");
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (SystemInfo.isWindows) {
|
||||||
|
logger.debug("Adapting UI for Windows.");
|
||||||
|
}
|
||||||
|
|
||||||
|
UIManager.setLookAndFeel(createLookAndFeel());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Class<?> showMachineSelectionDialog() {
|
||||||
|
Object[] possibilities = { "Symon", "Multicomp", "Simple", "BenEater" };
|
||||||
|
String s = (String) JOptionPane.showInputDialog(
|
||||||
|
null,
|
||||||
|
"Please choose the machine type to be emulated:",
|
||||||
|
"Machine selection",
|
||||||
|
JOptionPane.PLAIN_MESSAGE,
|
||||||
|
null,
|
||||||
|
possibilities,
|
||||||
|
"Symon");
|
||||||
|
|
||||||
|
if (s != null && s.equals("Multicomp")) {
|
||||||
|
return MulticompMachine.class;
|
||||||
|
} else if (s != null && s.equals("Simple")) {
|
||||||
|
return SimpleMachine.class;
|
||||||
|
} else if (s != null && s.equals("BenEater")) {
|
||||||
|
return BenEaterMachine.class;
|
||||||
|
} else {
|
||||||
|
return SymonMachine.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static LookAndFeel createLookAndFeel() {
|
||||||
|
final OsThemeDetector themeDetector = OsThemeDetector.getDetector();
|
||||||
|
final boolean systemThemeIsDark = themeDetector.isDark();
|
||||||
|
|
||||||
|
// Set light/dark mode depending on what can be detected from the system theme:
|
||||||
|
FlatLaf theme;
|
||||||
|
if (systemThemeIsDark) {
|
||||||
|
logger.debug("Using DARK theme.");
|
||||||
|
theme = new FlatDarkLaf();
|
||||||
|
} else {
|
||||||
|
logger.debug("Using LIGHT theme.");
|
||||||
|
theme = new FlatLightLaf();
|
||||||
|
}
|
||||||
|
return theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 191 B After Width: | Height: | Size: 220 B |
|
Before Width: | Height: | Size: 196 B After Width: | Height: | Size: 232 B |
|
Before Width: | Height: | Size: 192 B After Width: | Height: | Size: 224 B |
|
Before Width: | Height: | Size: 183 B After Width: | Height: | Size: 202 B |
|
Before Width: | Height: | Size: 198 B After Width: | Height: | Size: 238 B |
|
Before Width: | Height: | Size: 192 B After Width: | Height: | Size: 221 B |
|
Before Width: | Height: | Size: 198 B After Width: | Height: | Size: 238 B |
@@ -0,0 +1,3 @@
|
|||||||
|
# Loaded for FlatDarkLaf theme only.
|
||||||
|
|
||||||
|
Colors.accent.default = #4B6EAF
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
# Loaded for all FlatLaf themes.
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Loaded for FlatLightLaf theme only.
|
||||||
|
|
||||||
|
Colors.accent.default = #2675BF
|
||||||