Skip to content

Commit

Permalink
- Rework the XSD to a more logical definition
Browse files Browse the repository at this point in the history
  • Loading branch information
jsanchezv committed Nov 30, 2016
1 parent 2b20d37 commit e9ed7ec
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 70 deletions.
6 changes: 3 additions & 3 deletions src/gui/CommandLineOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package gui;

import configuration.JSpeccySettingsType;
import configuration.JSpeccySettings;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -19,8 +19,8 @@
* @author jsanchez
*/
public class CommandLineOptions {
JSpeccySettingsType settings;
CommandLineOptions(JSpeccySettingsType config) {
JSpeccySettings settings;
CommandLineOptions(JSpeccySettings config) {
settings = config;
}

Expand Down
29 changes: 7 additions & 22 deletions src/gui/JSpeccy.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

package gui;

import configuration.JSpeccySettingsType;
import configuration.ObjectFactory;
import configuration.JSpeccySettings;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.RenderingHints;
Expand Down Expand Up @@ -45,7 +44,6 @@
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.xml.bind.JAXB;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import machine.Keyboard.JoystickModel;
Expand All @@ -71,7 +69,7 @@ public class JSpeccy extends javax.swing.JFrame {
private JFileChooser loadImageDlg, saveImageDlg, IF2RomDlg;
private RecentFilesMgr recentFilesMgr;
private ListSelectionModel lsm;
private JSpeccySettingsType settings;
private JSpeccySettings settings;
private SettingsDialog settingsDialog;
private MicrodriveDialog microdriveDialog;
private MemoryBrowserDialog memoryBrowserDialog;
Expand Down Expand Up @@ -485,10 +483,7 @@ private void readSettingsFile() {

// unmarshal a po instance document into a tree of Java content
// objects composed of classes from the configuration package.
JAXBElement<?> settingsElement =
(JAXBElement<?>) unmsh.unmarshal(new FileInputStream(System.getProperty("user.home") + "/JSpeccy.xml"));

settings = (JSpeccySettingsType) settingsElement.getValue();
settings = (JSpeccySettings) unmsh.unmarshal(new FileInputStream(System.getProperty("user.home") + "/JSpeccy.xml"));
} catch (JAXBException jexcpt) {
System.out.println("Something during unmarshalling go very bad!");
readed = false;
Expand All @@ -512,10 +507,7 @@ private void readSettingsFile() {

// unmarshal a po instance document into a tree of Java content
// objects composed of classes from the configuration package.
JAXBElement<?> settingsElement =
(JAXBElement<?>) unmsh.unmarshal(new FileInputStream(System.getProperty("user.home") + "/JSpeccy.xml"));

settings = (JSpeccySettingsType) settingsElement.getValue();
settings = (JSpeccySettings) unmsh.unmarshal(new FileInputStream(System.getProperty("user.home") + "/JSpeccy.xml"));
} catch (JAXBException jexcpt) {
System.out.println("Something go very very badly with unmarshalling!");
} catch (FileNotFoundException ioexcpt) {
Expand All @@ -526,7 +518,7 @@ private void readSettingsFile() {
}

private void saveRecentFiles() {
JSpeccySettingsType toSave = null;
JSpeccySettings toSave = null;
if (!settings.getEmulatorSettings().isAutosaveConfigOnExit()) {
try {
// create a JAXBContext capable of handling classes generated into
Expand All @@ -538,10 +530,7 @@ private void saveRecentFiles() {

// unmarshal a po instance document into a tree of Java content
// objects composed of classes from the configuration package.
JAXBElement<?> settingsElement =
(JAXBElement<?>) unmsh.unmarshal(new FileInputStream(System.getProperty("user.home") + "/JSpeccy.xml"));

toSave = (JSpeccySettingsType) settingsElement.getValue();
toSave = (JSpeccySettings) unmsh.unmarshal(new FileInputStream(System.getProperty("user.home") + "/JSpeccy.xml"));
} catch (JAXBException jexcpt) {
System.out.println("Something during unmarshalling go very bad!");
} catch (FileNotFoundException ioexcpt) {
Expand Down Expand Up @@ -594,12 +583,8 @@ private void saveRecentFiles() {
try {
BufferedOutputStream fOut =
new BufferedOutputStream(new FileOutputStream(System.getProperty("user.home") + "/JSpeccy.xml"));
// create an element for marshalling
JAXBElement<JSpeccySettingsType> confElement =
(new ObjectFactory()).createJSpeccySettings(toSave);

// create a Marshaller and marshal to conf. file
JAXB.marshal(confElement, fOut);
JAXB.marshal(toSave, fOut);
try {
fOut.close();
} catch (IOException ex) {
Expand Down
11 changes: 5 additions & 6 deletions src/gui/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingUtilities;
import javax.xml.bind.JAXB;
import javax.xml.bind.JAXBElement;

/**
*
* @author jsanchez
*/
public class SettingsDialog extends javax.swing.JPanel {

private JSpeccySettingsType settings;
private JSpeccySettings settings;
private JDialog settingsDialog;

/** Creates new form SettingsDialog */
public SettingsDialog(JSpeccySettingsType userSettings) {
public SettingsDialog(JSpeccySettings userSettings) {
initComponents();
settings = userSettings;
}
Expand Down Expand Up @@ -798,11 +797,11 @@ private void saveSettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {
BufferedOutputStream fOut =
new BufferedOutputStream(new FileOutputStream(System.getProperty("user.home") + "/JSpeccy.xml"));
// create an element for marshalling
JAXBElement<JSpeccySettingsType> confElement =
(new ObjectFactory()).createJSpeccySettings(settings);
// JAXBElement<JSpeccySettingsType> confElement =
// (new ObjectFactory()).createJSpeccySettings(settings);

// create a Marshaller and marshal to conf. file
JAXB.marshal(confElement, fOut);
JAXB.marshal(settings, fOut);
try {
fOut.close();
} catch (IOException ex) {
Expand Down
6 changes: 3 additions & 3 deletions src/machine/Memory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package machine;

import configuration.JSpeccySettingsType;
import configuration.JSpeccySettings;
import configuration.MemoryType;
import java.io.BufferedInputStream;
import java.io.File;
Expand Down Expand Up @@ -56,10 +56,10 @@ public final class Memory {
private boolean model128k, pagingLocked, plus3RamMode;
private boolean multifacePaged, multifaceLocked;
private MachineTypes spectrumModel;
private final JSpeccySettingsType settings;
private final JSpeccySettings settings;
private final Random random;

public Memory(JSpeccySettingsType memSettings) {
public Memory(JSpeccySettings memSettings) {
spectrumModel = null;
settings = memSettings;
random = new Random();
Expand Down
6 changes: 3 additions & 3 deletions src/machine/Spectrum.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package machine;

import configuration.JSpeccySettingsType;
import configuration.JSpeccySettings;
import configuration.SpectrumType;
import gui.JSpeccyScreen;
import java.awt.Graphics2D;
Expand Down Expand Up @@ -63,14 +63,14 @@ public class Spectrum implements Runnable, z80core.MemIoOps, z80core.NotifyOps {
private JoystickModel joystickModel;
private JoystickRaw joystick1, joystick2;

private final JSpeccySettingsType settings;
private final JSpeccySettings settings;
private final SpectrumType specSettings;
/* Config vars */
private boolean issue2, saveTrap, loadTrap, flashload;
private boolean connectedIF1;
private final Interface1 if1;

public Spectrum(JSpeccySettingsType config) {
public Spectrum(JSpeccySettings config) {
clock = Clock.getInstance();
settings = config;
specSettings = settings.getSpectrumSettings();
Expand Down
2 changes: 1 addition & 1 deletion src/schema/JSpeccy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!--
Document : JSpeccy.xml
Created on : 7 de mayo de 2016, 0:09
Created on : 30 de noviembre de 2016, 20:58
Author : jsanchez
Description:
Purpose of the document follows.
Expand Down
33 changes: 17 additions & 16 deletions src/schema/JSpeccy.xsd
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.netbeans.org/schema/JSpeccy"
xmlns:tns="http://xml.netbeans.org/schema/JSpeccy">
<xsd:element name="JSpeccySettings" type="tns:JSpeccySettingsType"/>
<xsd:element name="JSpeccySettings">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="SpectrumSettings" type="tns:SpectrumType"/>
<xsd:element name="MemorySettings" type="tns:MemoryType"/>
<xsd:element name="TapeSettings" type="tns:TapeSettingsType"/>
<xsd:element name="KeyboardJoystickSettings" type="tns:KeyboardJoystickType"/>
<xsd:element name="AY8912Settings" type="tns:AY8912Type"/>
<xsd:element name="RecentFilesSettings" type="tns:RecentFilesType"/>
<xsd:element name="Interface1Settings" type="tns:Interface1Type"/>
<xsd:element name="EmulatorSettings" type="tns:EmulatorSettingsType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="SpectrumType">
<xsd:sequence>
<xsd:element name="AYEnabled48k" type="xsd:boolean" default="false"/>
Expand Down Expand Up @@ -82,7 +95,7 @@
<xsd:element name="Rom128k1" type="xsd:string" default="128-1.rom"/>
<xsd:element name="RomPlus20" type="xsd:string" default="plus2-0.rom"/>
<xsd:element name="RomPlus21" type="xsd:string" default="plus2-1.rom"/>
<xsd:element name="RomPlus2a0" default="plus2a-0.rom" type="xsd:string"></xsd:element>
<xsd:element name="RomPlus2a0" default="plus2a-0.rom" type="xsd:string"/>
<xsd:element name="RomPlus2a1" default="plus2a-1.rom" type="xsd:string"/>
<xsd:element name="RomPlus2a2" default="plus2a-2.rom" type="xsd:string"/>
<xsd:element name="RomPlus2a3" default="plus2a-3.rom" type="xsd:string"/>
Expand All @@ -104,7 +117,7 @@
<xsd:element name="highSamplingFreq" type="xsd:boolean" default="false"/>
<xsd:element name="flashLoad" type="xsd:boolean" default="false"/>
<xsd:element name="autoLoadTape" type="xsd:boolean" default="true"/>
<xsd:element name="invertedEar" type="xsd:boolean" default="false"></xsd:element>
<xsd:element name="invertedEar" type="xsd:boolean" default="false"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="KeyboardJoystickType">
Expand Down Expand Up @@ -133,18 +146,6 @@
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="JSpeccySettingsType">
<xsd:sequence>
<xsd:element name="SpectrumSettings" type="tns:SpectrumType"/>
<xsd:element name="MemorySettings" type="tns:MemoryType"/>
<xsd:element name="TapeSettings" type="tns:TapeSettingsType"/>
<xsd:element name="KeyboardJoystickSettings" type="tns:KeyboardJoystickType"/>
<xsd:element name="AY8912Settings" type="tns:AY8912Type"/>
<xsd:element name="RecentFilesSettings" type="tns:RecentFilesType"/>
<xsd:element name="Interface1Settings" type="tns:Interface1Type"/>
<xsd:element name="EmulatorSettings" type="tns:EmulatorSettingsType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="RecentFilesType">
<xsd:sequence>
<xsd:element name="recentFile" type="xsd:string" minOccurs="0" maxOccurs="5"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.netbeans.org/schema/JSpeccy"
xmlns:tns="http://xml.netbeans.org/schema/JSpeccy">
<xsd:element name="JSpeccySettings" type="tns:JSpeccySettingsType"/>
<xsd:element name="JSpeccySettings">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="SpectrumSettings" type="tns:SpectrumType"/>
<xsd:element name="MemorySettings" type="tns:MemoryType"/>
<xsd:element name="TapeSettings" type="tns:TapeSettingsType"/>
<xsd:element name="KeyboardJoystickSettings" type="tns:KeyboardJoystickType"/>
<xsd:element name="AY8912Settings" type="tns:AY8912Type"/>
<xsd:element name="RecentFilesSettings" type="tns:RecentFilesType"/>
<xsd:element name="Interface1Settings" type="tns:Interface1Type"/>
<xsd:element name="EmulatorSettings" type="tns:EmulatorSettingsType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="SpectrumType">
<xsd:sequence>
<xsd:element name="AYEnabled48k" type="xsd:boolean" default="false"/>
Expand Down Expand Up @@ -82,7 +95,7 @@
<xsd:element name="Rom128k1" type="xsd:string" default="128-1.rom"/>
<xsd:element name="RomPlus20" type="xsd:string" default="plus2-0.rom"/>
<xsd:element name="RomPlus21" type="xsd:string" default="plus2-1.rom"/>
<xsd:element name="RomPlus2a0" default="plus2a-0.rom" type="xsd:string"/>
<xsd:element name="RomPlus2a0" default="plus2a-0.rom" type="xsd:string"></xsd:element>
<xsd:element name="RomPlus2a1" default="plus2a-1.rom" type="xsd:string"/>
<xsd:element name="RomPlus2a2" default="plus2a-2.rom" type="xsd:string"/>
<xsd:element name="RomPlus2a3" default="plus2a-3.rom" type="xsd:string"/>
Expand All @@ -104,7 +117,7 @@
<xsd:element name="highSamplingFreq" type="xsd:boolean" default="false"/>
<xsd:element name="flashLoad" type="xsd:boolean" default="false"/>
<xsd:element name="autoLoadTape" type="xsd:boolean" default="true"/>
<xsd:element name="invertedEar" type="xsd:boolean" default="false"/>
<xsd:element name="invertedEar" type="xsd:boolean" default="false"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="KeyboardJoystickType">
Expand Down Expand Up @@ -133,18 +146,6 @@
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="JSpeccySettingsType">
<xsd:sequence>
<xsd:element name="SpectrumSettings" type="tns:SpectrumType"/>
<xsd:element name="MemorySettings" type="tns:MemoryType"/>
<xsd:element name="TapeSettings" type="tns:TapeSettingsType"/>
<xsd:element name="KeyboardJoystickSettings" type="tns:KeyboardJoystickType"/>
<xsd:element name="AY8912Settings" type="tns:AY8912Type"/>
<xsd:element name="RecentFilesSettings" type="tns:RecentFilesType"/>
<xsd:element name="Interface1Settings" type="tns:Interface1Type"/>
<xsd:element name="EmulatorSettings" type="tns:EmulatorSettingsType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="RecentFilesType">
<xsd:sequence>
<xsd:element name="recentFile" type="xsd:string" minOccurs="0" maxOccurs="5"/>
Expand Down

0 comments on commit e9ed7ec

Please sign in to comment.