Skip to content

Commit

Permalink
Rudimentary JavaFX GUI and small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MaisiKoleni committed Jan 5, 2019
1 parent b217213 commit 24a3e58
Show file tree
Hide file tree
Showing 19 changed files with 942 additions and 34 deletions.
7 changes: 4 additions & 3 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<classpathentry excluding="**|style/|style/" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-10">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Expand Down
2 changes: 1 addition & 1 deletion .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ org.eclipse.jdt.core.compiler.problem.missingDefaultCase=warning
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=info
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=info
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
Expand Down
49 changes: 48 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.maisikoleni.am2900me</groupId>
<artifactId>Am2900ME</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1</version>
<name>Am2900ME</name>
<description>Emulator for Am2900 Family Microprogramming</description>
<url>https://github.com/MaisiKoleni/Am2900ME</url>
Expand All @@ -22,6 +22,52 @@
<release>10</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>net.maisikoleni.am2900me.ui.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand All @@ -33,4 +79,5 @@
<scope>test</scope>
</dependency>
</dependencies>

</project>
64 changes: 52 additions & 12 deletions src/main/java/net/maisikoleni/am2900me/ui/Main.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package net.maisikoleni.am2900me.ui;

import java.util.ArrayList;
import java.util.List;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import net.maisikoleni.am2900me.logic.Am2900Machine;
import net.maisikoleni.am2900me.logic.MicroprogramMemory;

/**
* JavaFX application entry point.
Expand All @@ -14,27 +17,64 @@
*/
public class Main extends Application {

public static final String DESCRIPTOR = "AM2900ME (v0.0.1)";

private final Am2900Machine machine;
private final List<String> stylesheets = List.of(
getClass().getResource("/style/am2900me_style.css").toExternalForm(),
"com/sun/javafx/scene/control/skin/modena/modena-embedded-performance.css");
private final List<Image> icons = getImages("/icons/µIcon16.png", "/icons/µIcon32.png", "/icons/µIcon128.png");

public Main() {
machine = new Am2900Machine();
}

@Override
public void start(Stage primaryStage) {
// TODO: EVERYTHING EXPERIMENTAL!!
primaryStage.setTitle("AM2900ME");
// Scene scene = new Scene(new MappingPromPanel(machine.getmProm()));
Scene scene = new Scene(new MicroInstrPanel(new MicroprogramMemory()));
scene.getStylesheets().add(getClass().getResource("am2900me_style.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setHeight(600);
primaryStage.setWidth(1050);
primaryStage.show();
public void start(Stage s) {
s.setTitle(DESCRIPTOR + " - Microinstructions");
s.getIcons().addAll(icons);
Scene scene = new Scene(new MicroInstrPanel(machine));
scene.getStylesheets().addAll(stylesheets);
s.setScene(scene);
s.setHeight(800);
s.setWidth(1870);
s.show();
startMPROM();
startRAM();
}

private void startMPROM() {
Stage s = new Stage();
s.getIcons().addAll(icons);
s.setTitle(DESCRIPTOR + " - Mapping PROM");
Scene scene = new Scene(new MappingPromPanel(machine.getmProm()));
scene.getStylesheets().addAll(stylesheets);
s.setScene(scene);
s.setHeight(600);
s.setWidth(450);
s.show();
}

private void startRAM() {
Stage s = new Stage();
s.getIcons().addAll(icons);
s.setTitle(DESCRIPTOR + " - Machine RAM");
Scene scene = new Scene(new RAMPanel(machine.getMachineRam()));
scene.getStylesheets().addAll(stylesheets);
s.setScene(scene);
s.setHeight(600);
s.setWidth(1050);
s.show();
}

@SuppressWarnings("javadoc")
public static void main(String[] args) {
launch(args);
}

public List<Image> getImages(final String... fileNames) {
final ArrayList<Image> images = new ArrayList<>();
for (int i = 0; i < fileNames.length; i++)
images.add(new Image(getClass().getResource(fileNames[i]).toString()));
return images;
}
}
80 changes: 74 additions & 6 deletions src/main/java/net/maisikoleni/am2900me/ui/MappingPromPanel.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
package net.maisikoleni.am2900me.ui;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ReadOnlyIntegerProperty;
import javafx.beans.property.ReadOnlyIntegerWrapper;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.ToolBar;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.layout.BorderPane;
import javafx.stage.FileChooser;
import net.maisikoleni.am2900me.logic.MappingPROM;
import net.maisikoleni.am2900me.util.HexIntStringConverter;

Expand Down Expand Up @@ -42,6 +54,34 @@ public MappingPromPanel(MappingPROM mprom) {
addrTable = new TableView<>(entries);
configureTableView();
setCenter(addrTable);
configureToolbar();
}

private void configureToolbar() {
Button loadFile = new Button("Load from File");
loadFile.setOnAction(e -> {
FileChooser fc = new FileChooser();
File f = fc.showOpenDialog(null);
try {
readCSV(Files.readAllLines(f.toPath()));
} catch (Exception ex) {
Alert a = new Alert(AlertType.ERROR, "Load from File failed:\n" + ex, ButtonType.CLOSE);
a.show();
}
});
Button saveFile = new Button("Save to File");
saveFile.setOnAction(e -> {
FileChooser fc = new FileChooser();
File f = fc.showSaveDialog(null);
try {
Files.write(f.toPath(), toCSV(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (Exception ex) {
Alert a = new Alert(AlertType.ERROR, "Load from File failed:\n" + ex, ButtonType.CLOSE);
a.show();
}
});
ToolBar tb = new ToolBar(loadFile, saveFile);
setTop(tb);
}

private void configureTableView() {
Expand All @@ -63,29 +103,57 @@ private void configureTableView() {
comments.setEditable(true);
comments.setReorderable(false);

// addrTable.getSortOrder().add(opCodes);
addrTable.getColumns().add(opCodes);
addrTable.getColumns().add(mapAddresses);
addrTable.getColumns().add(comments);
addrTable.setEditable(true);
}

@SuppressWarnings("javadoc")
private final Iterable<String> toCSV() {
ArrayList<String> lines = new ArrayList<>();
for (MappingEntry me : entries) {
lines.add(me.toString());
}
return lines;
}

private final void readCSV(Iterable<String> lines) {
for (String line : lines) {
MappingEntry newME = parseME(line);
entries.set(newME.opCode.get(), newME);
}
}

public MappingEntry parseME(String s) {
String[] parts = s.split(",", 3);
MappingEntry me = new MappingEntry(Integer.decode(parts[0]));
me.mappingAddr.set(Integer.decode(parts[1]));
me.comment.set(parts[2]);
return me;
}

public class MappingEntry implements Comparable<MappingEntry> {
static final String PROP_OP_CODE = "opCode";
static final String PROP_ADDRESS = "mappingAddr";
static final String PROP_COMMENT = "comment";

private final IntegerProperty opCode;
private final IntegerProperty mappingAddr;
private final StringProperty comment;
final ReadOnlyIntegerProperty opCode;
final IntegerProperty mappingAddr;
final StringProperty comment;

@SuppressWarnings("synthetic-access")
MappingEntry(int opCode) {
this.opCode = new SimpleIntegerProperty(this, PROP_OP_CODE, opCode);
this.opCode = new ReadOnlyIntegerWrapper(this, PROP_OP_CODE, opCode);
this.mappingAddr = new SimpleIntegerProperty(this, PROP_ADDRESS, opCode << 4);
this.mappingAddr.addListener((obs, o, n) -> MappingPromPanel.this.mprom.set(opCode, n.intValue()));
this.comment = new SimpleStringProperty(this, PROP_COMMENT, "");
MappingPromPanel.this.mprom.set(opCode, mappingAddr.get());
}

@Override
public String toString() {
return HexIntStringConverter.INT_8.toString(opCode.get()) + ","
+ HexIntStringConverter.INT_12.toString(mappingAddr.get()) + "," + comment.get();
}

public final ReadOnlyIntegerProperty opCodeProperty() {
Expand Down
Loading

0 comments on commit 24a3e58

Please sign in to comment.