git-svn-id: http://svn.3splooges.com/romraider-arch/tags/0.3.2 final@228 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d

This commit is contained in:
Jared Gould 2006-08-12 22:45:33 +00:00
commit a0bd1bd5ca
52 changed files with 10276 additions and 0 deletions

484
enginuity/ECUEditor.java Normal file
View File

@ -0,0 +1,484 @@
package enginuity;
import com.sun.org.apache.xerces.internal.parsers.DOMParser;
import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException;
import enginuity.maps.Rom;
import enginuity.maps.Table;
import enginuity.net.URL;
import enginuity.swing.ECUEditorMenuBar;
import enginuity.swing.ECUEditorToolBar;
import enginuity.swing.JProgressPane;
import enginuity.swing.MDIDesktopPane;
import enginuity.swing.RomTree;
import enginuity.swing.RomTreeNode;
import enginuity.swing.RomTreeRootNode;
import enginuity.swing.TableFrame;
import enginuity.xml.DOMRomUnmarshaller;
import enginuity.xml.DOMSettingsBuilder;
import enginuity.xml.DOMSettingsUnmarshaller;
import enginuity.xml.RomNotFoundException;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import javax.swing.*;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;
public class ECUEditor extends JFrame implements WindowListener, PropertyChangeListener {
private RomTreeRootNode imageRoot = new RomTreeRootNode("Open Images");
private RomTree imageList = new RomTree(imageRoot);
private Settings settings = new Settings();
private String version = "0.3.2 Beta";
private String versionDate = "8/12/2006";
private String titleText = "Enginuity v" + version;
private MDIDesktopPane rightPanel = new MDIDesktopPane();
private Rom lastSelectedRom = null;
private JSplitPane splitPane = new JSplitPane();
private ECUEditorToolBar toolBar;
private ECUEditorMenuBar menuBar;
private JProgressPane statusPanel = new JProgressPane();
public ECUEditor() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) { }
// get settings from xml
try {
InputSource src = new InputSource(new FileInputStream(new File("./settings.xml")));
DOMSettingsUnmarshaller domUms = new DOMSettingsUnmarshaller();
DOMParser parser = new DOMParser();
parser.parse(src);
Document doc = parser.getDocument();
settings = domUms.unmarshallSettings(doc.getDocumentElement());
} catch (RuntimeException re) {
// Catching RE specifially will prevent real bugs from being
// presented as a settings file not found exception
throw re;
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "Settings file not found.\n" +
"A new file will be created.", "Error Loading Settings", JOptionPane.INFORMATION_MESSAGE);
}
finally {
BufferedReader br = null;
if (!settings.getRecentVersion().equalsIgnoreCase(version)) {
try {
// new version being used, display release notes
JTextArea releaseNotes = new JTextArea();
releaseNotes.setEditable(false);
releaseNotes.setWrapStyleWord(true);
releaseNotes.setLineWrap(true);
releaseNotes.setFont(new Font("Tahoma", Font.PLAIN, 12));
JScrollPane scroller = new JScrollPane(releaseNotes,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroller.setPreferredSize(new Dimension(600,500));
br = new BufferedReader(new FileReader(settings.getReleaseNotes()));
StringBuffer sb = new StringBuffer();
while (br.ready()) {
sb.append(br.readLine() + "\n");
}
releaseNotes.setText(sb+"");
JOptionPane.showMessageDialog(this, scroller,
"Enginuity " + version + " Release Notes", JOptionPane.INFORMATION_MESSAGE);
} catch (Exception ex) { }
}
if (br != null) {
try {
br.close();
} catch (IOException ioe) {
/* Ignore */
}
}
}
setSize(getSettings().getWindowSize());
setLocation(getSettings().getWindowLocation());
if (getSettings().isWindowMaximized()) setExtendedState(JFrame.MAXIMIZED_BOTH);
JScrollPane rightScrollPane = new JScrollPane(rightPanel,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JScrollPane leftScrollPane = new JScrollPane(imageList,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftScrollPane, rightScrollPane);
splitPane.setDividerSize(2);
splitPane.setDividerLocation(getSettings().getSplitPaneLocation());
splitPane.addPropertyChangeListener(this);
getContentPane().add(splitPane);
rightPanel.setBackground(Color.BLACK);
imageList.setScrollsOnExpand(true);
imageList.setContainer(this);
//create menubar and toolbar
menuBar = new ECUEditorMenuBar(this);
this.setJMenuBar(menuBar);
toolBar = new ECUEditorToolBar(this);
this.add(toolBar, BorderLayout.NORTH);
this.add(statusPanel, BorderLayout.SOUTH);
//set remaining window properties
setIconImage(new ImageIcon("./graphics/enginuity-ico.gif").getImage());
setDefaultCloseOperation(EXIT_ON_CLOSE);
addWindowListener(this);
setTitle(titleText);
setVisible(true);
}
public void handleExit() {
getSettings().setSplitPaneLocation(splitPane.getDividerLocation());
if (getExtendedState() == JFrame.MAXIMIZED_BOTH)
getSettings().setWindowMaximized(true);
else {
getSettings().setWindowMaximized(false);
getSettings().setWindowSize(getSize());
getSettings().setWindowLocation(getLocation());
}
DOMSettingsBuilder builder = new DOMSettingsBuilder();
try {
//JProgressPane progress = new JProgressPane(this, "Saving settings...", "Saving settings...");
builder.buildSettings(settings, new File("./settings.xml"), statusPanel, version);
} catch (IOException ex) {
} finally {
statusPanel.update("Ready...", 0);
repaint();
}
}
public void windowClosing(WindowEvent e) {
handleExit();
}
public void windowOpened(WindowEvent e) { }
public void windowClosed(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public String getVersion() {
return version;
}
public Settings getSettings() {
return settings;
}
public void addRom(Rom input) {
// add to ecu image list pane
RomTreeNode romNode = new RomTreeNode(input, settings.getUserLevel(), settings.isDisplayHighTables());
imageRoot.add(romNode);
imageList.updateUI();
imageList.expandRow(imageList.getRowCount() - 1);
imageList.updateUI();
setLastSelectedRom(input);
if (input.getRomID().isObsolete() && settings.isObsoleteWarning()) {
JPanel infoPanel = new JPanel();
infoPanel.setLayout(new GridLayout(3, 1));
infoPanel.add(new JLabel("A newer version of this ECU revision exists. " +
"Please visit the following link to download the latest revision:"));
infoPanel.add(new URL(getSettings().getRomRevisionURL()));
JCheckBox check = new JCheckBox("Always display this message", true);
check.setHorizontalAlignment(JCheckBox.RIGHT);
check.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
settings.setObsoleteWarning(((JCheckBox)e.getSource()).isSelected());
}
}
);
infoPanel.add(check);
JOptionPane.showMessageDialog(this, infoPanel, "ECU Revision is Obsolete", JOptionPane.INFORMATION_MESSAGE);
}
input.setContainer(this);
imageList.updateUI();
}
public void displayTable(TableFrame frame) {
frame.setVisible(true);
try {
rightPanel.add(frame);
} catch (IllegalArgumentException ex) {
// table is already open, so set focus
frame.requestFocus();
}
frame.setSize(frame.getTable().getFrameSize());
rightPanel.repaint();
}
public void removeDisplayTable(TableFrame frame) {
rightPanel.remove(frame);
rightPanel.repaint();
}
public void closeImage() {
for (int i = 0; i < imageRoot.getChildCount(); i++) {
RomTreeNode romTreeNode = (RomTreeNode)imageRoot.getChildAt(i);
Rom rom = romTreeNode.getRom();
if (rom == lastSelectedRom) {
Vector<Table> romTables = rom.getTables();
for (Iterator j = romTables.iterator(); j.hasNext();) {
Table t = (Table)j.next();
rightPanel.remove(t.getFrame());
}
Vector<TreePath> path = new Vector<TreePath>();
path.add(new TreePath(romTreeNode.getPath()));
imageRoot.remove(i);
imageList.removeDescendantToggledPaths((Enumeration<TreePath>)path.elements());
break;
}
}
imageList.updateUI();
if (imageRoot.getChildCount() > 0) {
setLastSelectedRom(((RomTreeNode)imageRoot.getChildAt(0)).getRom());
} else {
// no other images open
setLastSelectedRom(null);
}
rightPanel.repaint();
}
public void closeAllImages() {
while (imageRoot.getChildCount() > 0) {
closeImage();
}
}
public Rom getLastSelectedRom() {
return lastSelectedRom;
}
public void setLastSelectedRom(Rom lastSelectedRom) {
this.lastSelectedRom = lastSelectedRom;
if (lastSelectedRom == null) {
setTitle(titleText);
} else {
setTitle(titleText + " - " + lastSelectedRom.getFileName());
}
// update filenames
for (int i = 0; i < imageRoot.getChildCount(); i++) {
((RomTreeNode)imageRoot.getChildAt(i)).updateFileName();
}
toolBar.updateButtons();
menuBar.updateMenu();
imageList.updateUI();
}
public ECUEditorToolBar getToolBar() {
return toolBar;
}
public void setToolBar(ECUEditorToolBar toolBar) {
this.toolBar = toolBar;
}
public void setSettings(Settings settings) {
this.settings = settings;
for (int i = 0; i < imageRoot.getChildCount(); i++) {
RomTreeNode rtn = (RomTreeNode)imageRoot.getChildAt(i);
rtn.getRom().setContainer(this);
}
}
public void setUserLevel(int userLevel) {
settings.setUserLevel(userLevel);
imageRoot.setUserLevel(userLevel, settings.isDisplayHighTables());
imageList.updateUI();
}
public Vector<Rom> getImages() {
Vector<Rom> images = new Vector<Rom>();
for (int i = 0; i < imageRoot.getChildCount(); i++) {
RomTreeNode rtn = (RomTreeNode)imageRoot.getChildAt(i);
images.add(rtn.getRom());
}
return images;
}
public void propertyChange(PropertyChangeEvent evt) {
imageList.updateUI();
imageList.repaint();
}
public void openImage(File inputFile) throws XMLParseException, Exception {
try {
update(getGraphics());
statusPanel.update("Parsing ECU definitions...", 0);
repaint();
byte[] input = readFile(inputFile);
DOMRomUnmarshaller domUms = new DOMRomUnmarshaller(settings, this);
DOMParser parser = new DOMParser();
statusPanel.update("Finding ECU definition...", 10);
repaint();
Rom rom;
// parse ecu definition files until result found
for (int i = 0; i < getSettings().getEcuDefinitionFiles().size(); i++) {
InputSource src = new InputSource(new FileInputStream(getSettings().getEcuDefinitionFiles().get(i)));
parser.parse(src);
Document doc = parser.getDocument();
try {
rom = domUms.unmarshallXMLDefinition(doc.getDocumentElement(), input, statusPanel);
statusPanel.update("Populating tables...", 50);
repaint();
rom.populateTables(input, statusPanel);
rom.setFileName(inputFile.getName());
statusPanel.update("Finalizing...", 90);
repaint();
addRom(rom);
rom.setFullFileName(inputFile);
return;
} catch (RomNotFoundException ex) {
// rom was not found in current file, skip to next
}
}
// if code executes to this point, no ROM was found, report to user
JOptionPane.showMessageDialog(this, "ECU Definition Not Found", "Error Loading " + inputFile.getName(), JOptionPane.ERROR_MESSAGE);
} catch (StackOverflowError ex) {
// handles looped inheritance, which will use up all available memory
JOptionPane.showMessageDialog(this, "Looped \"base\" attribute in XML definitions.", "Error Loading ROM", JOptionPane.ERROR_MESSAGE);
} finally {
// remove progress bar
//progress.dispose();
statusPanel.update("Ready...", 0);
}
}
private byte[] readFile(File inputFile) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileInputStream fis = null;
try {
fis = new FileInputStream(inputFile);
byte[] buf = new byte[8192];
int bytesRead = 0;
while ((bytesRead = fis.read(buf)) != -1) {
baos.write(buf, 0, bytesRead);
}
} finally {
if (fis != null) {
fis.close();
}
}
return baos.toByteArray();
}
public static void main(String args[]) {
// try create socket listener for shell opening new files
ServerSocket sock = null; // original server socket
String serverName = "localhost";
Socket clientSocket = null; // socket created by accept
PrintWriter pw = null; // socket output stream
BufferedReader br = null; // socket input stream
int serverPort = 8753;
try {
sock = new java.net.ServerSocket(serverPort); // create socket and bind to port
sock.close();
} catch (Exception ex) {
// pass filename if file present
if (args.length > 0) {
try {
Socket socket = new java.net.Socket(serverName,serverPort); // create socket and connect
pw = new java.io.PrintWriter(socket.getOutputStream(), true); // create reader and writer
br = new java.io.BufferedReader(new java.io.InputStreamReader(socket.getInputStream()));
pw.println(args[0]); // send msg to the server
String answer = br.readLine(); // get data from the server
pw.close(); // close everything
br.close();
socket.close();
} catch (Throwable e) { e.printStackTrace(); }
// after sending filename, exit
System.exit(0);
}
}
// launch editor
ECUEditor editor = new ECUEditor();
// open files, if passed
try {
if (args.length > 0) {
editor.openImage(new File(args[0]));
}
} catch (Exception ex) { ex.printStackTrace(); }
// listen for files
try {
while (true) {
sock = new java.net.ServerSocket(serverPort); // create socket and bind to port
clientSocket = sock.accept(); // wait for client to connect
pw = new java.io.PrintWriter(clientSocket.getOutputStream(),true);
br = new java.io.BufferedReader(
new java.io.InputStreamReader(clientSocket.getInputStream()));
String msg = br.readLine(); // read msg from client
// open file from client
editor.openImage(new File(msg));
pw.close(); // close everything
br.close();
clientSocket.close();
sock.close();
}
} catch (Throwable e) { e.printStackTrace(); }
}
}

280
enginuity/Settings.java Normal file
View File

@ -0,0 +1,280 @@
package enginuity;
import java.awt.*;
import java.io.File;
import java.io.Serializable;
import java.util.Vector;
public class Settings implements Serializable {
private Dimension windowSize = new Dimension(800, 600);
private Point windowLocation = new Point();
private int splitPaneLocation = 150;
private boolean windowMaximized = false;
private String romRevisionURL = "http://www.scoobypedia.co.uk/index.php/Knowledge/ECUVersionCompatibilityList";
private String supportURL = "http://www.enginuity.org";
private String releaseNotes = "release notes.txt";
private String recentVersion = "x";
private Vector<File> ecuDefinitionFiles = new Vector<File>();
private File lastImageDir = new File("images");
private boolean obsoleteWarning = true;
private boolean calcConflictWarning = true;
private boolean debug = false;
private int userLevel = 1;
private boolean saveDebugTables = false;
private boolean displayHighTables = true;
private boolean valueLimitWarning = true;
private Font tableFont = new Font("Arial", Font.BOLD, 12);
private Dimension cellSize = new Dimension(42, 18);
private Color maxColor = new Color(255, 102, 102);
private Color minColor = new Color(153, 153, 255);
private Color highlightColor = new Color(204, 204, 204);
private Color increaseBorder = new Color(255, 0, 0);
private Color decreaseBorder = new Color(0, 0, 255);
private Color axisColor = new Color(255, 255, 255);
private Color warningColor = new Color(255, 0, 0);
private int tableClickCount = 1; // number of clicks to open table
private String loggerPort = "COM4";
private String loggerProtocol = "SSM";
public Settings() {
//center window by default
Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
windowLocation.move(((int)(screenSize.getWidth() - windowSize.getWidth()) / 2),
((int)(screenSize.getHeight() - windowSize.getHeight()) / 2));
}
public Dimension getWindowSize() {
return windowSize;
}
public Point getWindowLocation() {
return windowLocation;
}
public void setWindowSize(Dimension size) {
windowSize.setSize(size);
}
public void setWindowLocation(Point location) {
windowLocation.setLocation(location);
}
public Vector<File> getEcuDefinitionFiles() {
if (ecuDefinitionFiles.isEmpty()) {
// if no files defined, add default
ecuDefinitionFiles.add(new File("ecu_defs.xml"));
}
return ecuDefinitionFiles;
}
public void addEcuDefinitionFile(File ecuDefinitionFile) {
ecuDefinitionFiles.add(ecuDefinitionFile);
}
public void setEcuDefinitionFiles(Vector<File> ecuDefinitionFiles) {
this.ecuDefinitionFiles = ecuDefinitionFiles;
}
public File getLastImageDir() {
return lastImageDir;
}
public void setLastImageDir(File lastImageDir) {
this.lastImageDir = lastImageDir;
}
public int getSplitPaneLocation() {
return splitPaneLocation;
}
public void setSplitPaneLocation(int splitPaneLocation) {
this.splitPaneLocation = splitPaneLocation;
}
public boolean isWindowMaximized() {
return windowMaximized;
}
public void setWindowMaximized(boolean windowMaximized) {
this.windowMaximized = windowMaximized;
}
public String getRomRevisionURL() {
return romRevisionURL;
}
public String getSupportURL() {
return supportURL;
}
public Font getTableFont() {
return tableFont;
}
public void setTableFont(Font tableFont) {
this.tableFont = tableFont;
}
public boolean isObsoleteWarning() {
return obsoleteWarning;
}
public void setObsoleteWarning(boolean obsoleteWarning) {
this.obsoleteWarning = obsoleteWarning;
}
public boolean isDebug() {
return debug;
}
public void setDebug(boolean debug) {
this.debug = debug;
}
public Dimension getCellSize() {
return cellSize;
}
public void setCellSize(Dimension cellSize) {
this.cellSize = cellSize;
}
public Color getMaxColor() {
return maxColor;
}
public void setMaxColor(Color maxColor) {
this.maxColor = maxColor;
}
public Color getMinColor() {
return minColor;
}
public void setMinColor(Color minColor) {
this.minColor = minColor;
}
public Color getHighlightColor() {
return highlightColor;
}
public void setHighlightColor(Color highlightColor) {
this.highlightColor = highlightColor;
}
public boolean isCalcConflictWarning() {
return calcConflictWarning;
}
public void setCalcConflictWarning(boolean calcConflictWarning) {
this.calcConflictWarning = calcConflictWarning;
}
public Color getIncreaseBorder() {
return increaseBorder;
}
public void setIncreaseBorder(Color increaseBorder) {
this.increaseBorder = increaseBorder;
}
public Color getDecreaseBorder() {
return decreaseBorder;
}
public void setDecreaseBorder(Color decreaseBorder) {
this.decreaseBorder = decreaseBorder;
}
public Color getAxisColor() {
return axisColor;
}
public void setAxisColor(Color axisColor) {
this.axisColor = axisColor;
}
public int getUserLevel() {
return userLevel;
}
public void setUserLevel(int userLevel) {
if (userLevel > 5) {
this.userLevel = 5;
} else if (userLevel < 1) {
this.userLevel = 1;
} else {
this.userLevel = userLevel;
}
}
public int getTableClickCount() {
return tableClickCount;
}
public void setTableClickCount(int tableClickCount) {
this.tableClickCount = tableClickCount;
}
public String getRecentVersion() {
return recentVersion;
}
public void setRecentVersion(String recentVersion) {
this.recentVersion = recentVersion;
}
public String getReleaseNotes() {
return releaseNotes;
}
public boolean isSaveDebugTables() {
return saveDebugTables;
}
public void setSaveDebugTables(boolean saveDebugTables) {
this.saveDebugTables = saveDebugTables;
}
public boolean isDisplayHighTables() {
return displayHighTables;
}
public void setDisplayHighTables(boolean displayHighTables) {
this.displayHighTables = displayHighTables;
}
public boolean isValueLimitWarning() {
return valueLimitWarning;
}
public void setValueLimitWarning(boolean valueLimitWarning) {
this.valueLimitWarning = valueLimitWarning;
}
public Color getWarningColor() {
return warningColor;
}
public void setWarningColor(Color warningColor) {
this.warningColor = warningColor;
}
public String getLoggerPort() {
return loggerPort;
}
public void setLoggerPort(String loggerPort) {
this.loggerPort = loggerPort;
}
public String getLoggerProtocol() {
return loggerProtocol;
}
}

View File

@ -0,0 +1,303 @@
package enginuity.maps;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.Serializable;
import java.text.DecimalFormat;
import javax.swing.JLabel;
import javax.swing.border.LineBorder;
import org.nfunk.jep.JEP;
public class DataCell extends JLabel implements MouseListener, Serializable {
private double binValue = 0;
private double originalValue = 0;
private Scale scale = new Scale();
private String displayValue = "";
private double realValue = 0;
private Color scaledColor = new Color(0,0,0);
private Color highlightColor = new Color(155,155,255);
private Color increaseBorder = Color.RED;
private Color decreaseBorder = Color.BLUE;
private Boolean selected = false;
private Boolean highlighted = false;
private Table table;
private int x = 0;
private int y = 0;
private double compareValue = 0;
private int compareType = Table.COMPARE_OFF;
private int compareDisplay = Table.COMPARE_ABSOLUTE;
public DataCell() { }
public DataCell(Scale scale) {
this.scale = scale;
this.setHorizontalAlignment(CENTER);
this.setVerticalAlignment(CENTER);
this.setFont(new Font("Arial", Font.BOLD, 12));
this.setBorder(new LineBorder(Color.BLACK, 1));
this.setOpaque(true);
this.setVisible(true);
this.addMouseListener(this);
}
public void updateDisplayValue() {
DecimalFormat formatter = new DecimalFormat(scale.getFormat());
if (getCompareType() == Table.COMPARE_OFF) {
displayValue = formatter.format(calcDisplayValue(binValue, table.getScale().getExpression()));
} else {
if (getCompareDisplay() == Table.COMPARE_ABSOLUTE) {
displayValue = formatter.format(
calcDisplayValue(binValue, table.getScale().getExpression()) -
calcDisplayValue(compareValue, table.getScale().getExpression()));
} else if (getCompareDisplay() == Table.COMPARE_PERCENT) {
double difference = calcDisplayValue(binValue, table.getScale().getExpression()) -
calcDisplayValue(compareValue, table.getScale().getExpression());
if (difference == 0) displayValue = "0%";
else displayValue = (int)(difference / calcDisplayValue(binValue, table.getScale().getExpression()) * 100)+"%";
}
}
setText(displayValue);
}
public double calcDisplayValue(double input, String expression) {
JEP parser = new JEP();
parser.initSymTab(); // clear the contents of the symbol table
parser.addVariable("x", input);
parser.parseExpression(expression);
return parser.getValue();
}
public void setColor(Color color) {
scaledColor = color;
if (!selected) super.setBackground(color);
}
public void setDisplayValue(String displayValue) {
this.displayValue = displayValue;
this.setText(displayValue);
}
public void setBinValue(double binValue) {
this.binValue = binValue;
// make sure it's in range
if (table.getStorageType() != Table.STORAGE_TYPE_FLOAT) {
if (binValue < 0) {
this.setBinValue(0);
} else if (binValue > Math.pow(256, table.getStorageType()) - 1) {
this.setBinValue((int)(Math.pow(256, table.getStorageType()) - 1));
}
}
this.updateDisplayValue();
}
public double getBinValue() {
return binValue;
}
public String toString() {
return displayValue;
}
public Boolean isSelected() {
return selected;
}
public void setSelected(Boolean selected) {
this.selected = selected;
if (selected) {
this.setBackground(getHighlightColor());
table.getFrame().getToolBar().setFineValue(Math.abs(table.getScale().getFineIncrement()));
table.getFrame().getToolBar().setCoarseValue(Math.abs(table.getScale().getCoarseIncrement()));
} else {
this.setBackground(scaledColor);
}
requestFocus();
}
public void setHighlighted(Boolean highlighted) {
if (!table.isStatic()) {
this.highlighted = highlighted;
if (highlighted) {
this.setBackground(getHighlightColor());
} else {
if (!selected) this.setBackground(scaledColor);
}
}
}
public boolean isHighlighted() {
return highlighted;
}
public void mouseEntered(MouseEvent e) {
table.highlight(x, y);
}
public void mousePressed(MouseEvent e) {
if (!table.isStatic()) {
if (!e.isControlDown()) table.clearSelection();
table.startHighlight(x, y);
}
requestFocus();
}
public void mouseReleased(MouseEvent e) {
if (!table.isStatic()) {
table.stopHighlight();
}
}
public void mouseClicked(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void increment(double increment) {
double oldValue = Double.parseDouble(getText());
if (table.getScale().getCoarseIncrement() < 0) increment = 0 - increment;
setRealValue((calcDisplayValue(binValue,
scale.getExpression()) + increment) + "");
// make sure table is incremented if change isnt great enough
int maxValue = (int)Math.pow(8, (double)table.getStorageType());
if (table.getStorageType() != Table.STORAGE_TYPE_FLOAT &&
oldValue == Double.parseDouble(getText()) &&
binValue > 0 &&
binValue < maxValue) {
System.out.println(maxValue + " " + binValue);
increment(increment * 2);
}
table.colorize();
}
public void setTable(Table table) {
this.table = table;
}
public void setXCoord(int x) {
this.x = x;
}
public void setYCoord(int y) {
this.y = y;
}
public double getOriginalValue() {
return originalValue;
}
public void setOriginalValue(double originalValue) {
this.originalValue = originalValue;
if (binValue != getOriginalValue()) {
this.setBorder(new LineBorder(Color.RED, 3));
} else {
this.setBorder(new LineBorder(Color.BLACK, 1));
}
}
public void undo() {
this.setBinValue(originalValue);
}
public void setRevertPoint() {
this.setOriginalValue(binValue);
}
public void setRealValue(String input) {
// create parser
if (!input.equalsIgnoreCase("x")) {
JEP parser = new JEP();
parser.initSymTab(); // clear the contents of the symbol table
parser.addVariable("x", Double.parseDouble(input));
parser.parseExpression(table.getScale().getByteExpression());
if (table.getStorageType() == Table.STORAGE_TYPE_FLOAT) {
this.setBinValue(parser.getValue());
} else {
this.setBinValue((int)Math.round(parser.getValue()));
}
}
}
public Color getHighlightColor() {
return highlightColor;
}
public void setHighlightColor(Color highlightColor) {
this.highlightColor = highlightColor;
}
public Color getIncreaseBorder() {
return increaseBorder;
}
public void setIncreaseBorder(Color increaseBorder) {
this.increaseBorder = increaseBorder;
}
public Color getDecreaseBorder() {
return decreaseBorder;
}
public void setDecreaseBorder(Color decreaseBorder) {
this.decreaseBorder = decreaseBorder;
}
public double getCompareValue() {
return compareValue;
}
public void setCompareValue(double compareValue) {
this.compareValue = compareValue;
}
public int getCompareType() {
return compareType;
}
public void setCompareType(int compareType) {
this.compareType = compareType;
}
public int getCompareDisplay() {
return compareDisplay;
}
public void setCompareRealValue(String input) {
JEP parser = new JEP();
parser.initSymTab(); // clear the contents of the symbol table
parser.addVariable("x", Double.parseDouble(input));
parser.parseExpression(table.getScale().getByteExpression());
this.setCompareValue((int)Math.round(parser.getValue()));
}
public void setCompareDisplay(int compareDisplay) {
this.compareDisplay = compareDisplay;
}
public void refreshValue() {
setBinValue(binValue);
}
public void multiply(double factor) {
setRealValue(Double.parseDouble(getText()) * factor+"");
}
}

157
enginuity/maps/Rom.java Normal file
View File

@ -0,0 +1,157 @@
package enginuity.maps;
import enginuity.ECUEditor;
import enginuity.swing.JProgressPane;
import enginuity.xml.TableNotFoundException;
import java.io.File;
import java.io.Serializable;
import java.util.Vector;
import javax.swing.JOptionPane;
public class Rom implements Serializable {
private RomID romID = new RomID();
private String fileName = "";
private File fullFileName = new File(".");
private Vector<Table> tables = new Vector<Table>();
private ECUEditor container;
private byte[] binData;
public Rom() {
}
public void addTable(Table table) {
for (int i = 0; i < tables.size(); i++) {
if (tables.get(i).getName().equalsIgnoreCase(table.getName())) {
tables.remove(i);
break;
}
}
tables.add(table);
}
public Table getTable(String tableName) throws TableNotFoundException {
for (int i = 0; i < tables.size(); i++) {
if (tables.get(i).getName().equalsIgnoreCase(tableName)) {
return tables.get(i);
}
}
throw new TableNotFoundException();
}
public void removeTable(String tableName) {
for (int i = 0; i < tables.size(); i++) {
if (tables.get(i).getName().equalsIgnoreCase(tableName)) {
tables.remove(i);
}
}
}
public void populateTables(byte[] binData, JProgressPane progress) {
this.binData = binData;
for (int i = 0; i < getTables().size(); i++) {
// update progress
int currProgress = (int)((double)i / (double)getTables().size() * 40);
progress.update("Populating tables...", 40 + currProgress);
try {
// if storageaddress has not been set (or is set to 0) omit table
if (tables.get(i).getStorageAddress() != 0) {
try {
tables.get(i).populateTable(binData);
} catch (ArrayIndexOutOfBoundsException ex) {
System.out.println(tables.get(i).getName() +
" type " + tables.get(i).getType() + " start " +
tables.get(i).getStorageAddress() + " " + binData.length + " filesize");
// table storage address extends beyond end of file
JOptionPane.showMessageDialog(container, "Storage address for table \"" + tables.get(i).getName() +
"\" is out of bounds.\nPlease check ECU definition file.", "ECU Definition Error", JOptionPane.ERROR_MESSAGE);
tables.removeElementAt(i);
i--;
}
} else {
tables.remove(i);
// decrement i because length of vector has changed
i--;
}
} catch (NullPointerException ex) {
JOptionPane.showMessageDialog(container, "There was an error loading table " + tables.get(i).getName(), "ECU Definition Error", JOptionPane.ERROR_MESSAGE);
tables.removeElementAt(i);
}
}
}
public void setRomID(RomID romID) {
this.romID = romID;
}
public RomID getRomID() {
return romID;
}
public String getRomIDString() {
return romID.getXmlid();
}
public String toString() {
String output = "";
output = output + "\n---- Rom ----" + romID.toString();
for (int i = 0; i < getTables().size(); i++) {
output = output + getTables().get(i);
}
output = output + "\n---- End Rom ----";
return output;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public Vector<Table> getTables() {
return tables;
}
public ECUEditor getContainer() {
return container;
}
public void setContainer(ECUEditor container) {
this.container = container;
// apply settings to tables
for (int i = 0; i < tables.size(); i++) {
tables.get(i).applyColorSettings(container.getSettings());
tables.get(i).resize();
}
}
public byte[] saveFile() {
for (int i = 0; i < tables.size(); i++) {
tables.get(i).saveFile(binData);
}
return binData;
}
public int getRealFileSize() {
return binData.length;
}
public File getFullFileName() {
return fullFileName;
}
public void setFullFileName(File fullFileName) {
this.fullFileName = fullFileName;
this.setFileName(fullFileName.getName());
}
}

173
enginuity/maps/RomID.java Normal file
View File

@ -0,0 +1,173 @@
//ECU version definition
package enginuity.maps;
import java.io.Serializable;
public class RomID implements Serializable {
private String xmlid = "";//ID stored in XML
private int internalIdAddress = 0;//address of ECU version in image
private String internalIdString = "";//ID stored in image
private String caseId = "";//ECU hardware version
private String ecuId = "";
private String make = "";//manufacturer
private String market = "";
private String model = "";
private String subModel = "";//trim, ie WRX
private String transmission = "";
private String year = "Unknown";
private String flashMethod = "";//flash method string used for ecuflash
private String memModel = "";//model used for reflashing with ecuflash
private int fileSize = 0;
private int ramOffset = 0;
private boolean obsolete = false; // whether a more recent revision exists
public String toString() {
return "\n ---- RomID " + xmlid + " ----" +
"\n Internal ID Address: " + internalIdAddress +
"\n Internal ID String: " + internalIdString +
"\n Case ID: " + caseId +
"\n ECU ID: " + ecuId +
"\n Make: " + make +
"\n Market: " + market +
"\n Model: " + model +
"\n Submodel: " + subModel +
"\n Transmission: " + transmission +
"\n Year: " + year +
"\n Flash Method: " + flashMethod +
"\n Memory Model: " + memModel +
"\n ---- End RomID " + xmlid + " ----";
}
public RomID() {
}
public String getXmlid() {
return xmlid;
}
public void setXmlid(String xmlid) {
this.xmlid = xmlid;
}
public int getInternalIdAddress() {
return internalIdAddress;
}
public void setInternalIdAddress(int internalIdAddress) {
this.internalIdAddress = internalIdAddress;
}
public String getInternalIdString() {
return internalIdString;
}
public void setInternalIdString(String internalIdString) {
this.internalIdString = internalIdString;
}
public String getCaseId() {
return caseId;
}
public void setCaseId(String caseId) {
this.caseId = caseId;
}
public String getEcuId() {
return ecuId;
}
public void setEcuId(String ecuId) {
this.ecuId = ecuId;
}
public String getMake() {
return make;
}
public void setMake(String make) {
this.make = make;
}
public String getMarket() {
return market;
}
public void setMarket(String market) {
this.market = market;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getSubModel() {
return subModel;
}
public void setSubModel(String subModel) {
this.subModel = subModel;
}
public String getTransmission() {
return transmission;
}
public void setTransmission(String transmission) {
this.transmission = transmission;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public String getFlashMethod() {
return flashMethod;
}
public void setFlashMethod(String flashMethod) {
this.flashMethod = flashMethod;
}
public String getMemModel() {
return memModel;
}
public void setMemModel(String memModel) {
this.memModel = memModel;
}
public int getRamOffset() {
return ramOffset;
}
public void setRamOffset(int ramOffset) {
this.ramOffset = ramOffset;
}
public int getFileSize() {
return fileSize;
}
public void setFileSize(int fileSize) {
this.fileSize = fileSize;
}
public boolean isObsolete() {
return obsolete;
}
public void setObsolete(boolean obsolete) {
this.obsolete = obsolete;
}
}

114
enginuity/maps/Scale.java Normal file
View File

@ -0,0 +1,114 @@
//This object defines the scaling factor and offset for calculating real values
package enginuity.maps;
import java.io.Serializable;
public class Scale implements Serializable {
public static final int LINEAR = 1;
public static final int INVERSE = 2;
private String name = "Default";
private String unit = "0x";
private String expression = "x";
private String byteExpression = "x";
private String format = "#";
private double coarseIncrement = 2;
private double fineIncrement = 1;
private double min = 0;
private double max = 0;
public Scale() {
}
public String toString() {
return "\n ---- Scale ----" +
"\n Name: " + getName() +
"\n Expression: " + getExpression() +
"\n Unit: " + getUnit() +
"\n ---- End Scale ----";
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
public String getExpression() {
return expression;
}
public void setExpression(String expression) {
this.expression = expression;
}
public double getCoarseIncrement() {
return coarseIncrement;
}
public void setCoarseIncrement(double increment) {
this.coarseIncrement = increment;
}
public boolean isReady() {
if (unit == null) return false;
else if (expression == null) return false;
else if (format == null) return false;
else if (coarseIncrement < 1) return false;
return true;
}
public String getByteExpression() {
return byteExpression;
}
public void setByteExpression(String byteExpression) {
this.byteExpression = byteExpression;
}
public double getFineIncrement() {
return fineIncrement;
}
public void setFineIncrement(double fineIncrement) {
this.fineIncrement = fineIncrement;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getMin() {
return min;
}
public void setMin(double min) {
this.min = min;
}
public double getMax() {
return max;
}
public void setMax(double max) {
this.max = max;
}
}

1116
enginuity/maps/Table.java Normal file

File diff suppressed because it is too large Load Diff

130
enginuity/maps/Table1D.java Normal file
View File

@ -0,0 +1,130 @@
package enginuity.maps;
import enginuity.Settings;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JLabel;
public class Table1D extends Table {
private Color axisColor = new Color(255, 255, 255);
public Table1D(Settings settings) {
super(settings);
}
public void populateTable(byte[] input) {
centerLayout.setRows(1);
centerLayout.setColumns(this.getDataSize());
super.populateTable(input);
// add to table
for (int i = 0; i < this.getDataSize(); i++) {
centerPanel.add(this.getDataCell(i));
}
add(new JLabel(name + " (" + scales.get(scaleIndex).getUnit() + ")", JLabel.CENTER), BorderLayout.NORTH);
}
public String toString() {
return super.toString() + " (1D)";
}
public boolean isIsAxis() {
return isAxis;
}
public void setIsAxis(boolean isAxis) {
this.isAxis = isAxis;
}
public void clearSelection() {
super.clearSelection();
//if (isAxis) axisParent.clearSelection();
}
public void clearSelection(boolean calledByParent) {
if (calledByParent) {
super.clearSelection();
} else {
this.clearSelection();
}
}
public void colorize() {
super.colorize();
}
public void cursorUp() {
if (type == Table.TABLE_Y_AXIS) {
if (highlightY > 0 && data[highlightY].isSelected()) selectCellAt(highlightY - 1);
} else if (type == Table.TABLE_X_AXIS) {
// Y axis is on top.. nothing happens
} else if (type == Table.TABLE_1D) {
// no where to move up to
}
}
public void cursorDown() {
if (type == Table.TABLE_Y_AXIS) {
if (axisParent.getType() == Table.TABLE_3D) {
if (highlightY < getDataSize() - 1 && data[highlightY].isSelected()) selectCellAt(highlightY + 1);
} else if (axisParent.getType() == Table.TABLE_2D) {
if (data[highlightY].isSelected()) axisParent.selectCellAt(highlightY);
}
} else if (type == Table.TABLE_X_AXIS && data[highlightY].isSelected()) {
((Table3D)axisParent).selectCellAt(highlightY, this);
} else if (type == Table.TABLE_1D) {
// no where to move down to
}
}
public void cursorLeft() {
if (type == Table.TABLE_Y_AXIS) {
// X axis is on left.. nothing happens
if (axisParent.getType() == Table.TABLE_2D) {
if (data[highlightY].isSelected()) selectCellAt(highlightY - 1);
}
} else if (type == Table.TABLE_X_AXIS && data[highlightY].isSelected()) {
if (highlightY > 0) selectCellAt(highlightY - 1);
} else if (type == Table.TABLE_1D && data[highlightY].isSelected()) {
if (highlightY > 0) selectCellAt(highlightY - 1);
}
}
public void cursorRight() {
if (type == Table.TABLE_Y_AXIS && data[highlightY].isSelected()) {
if (axisParent.getType() == Table.TABLE_3D) ((Table3D)axisParent).selectCellAt(highlightY, this);
else if (axisParent.getType() == Table.TABLE_2D) selectCellAt(highlightY + 1);
} else if (type == Table.TABLE_X_AXIS && data[highlightY].isSelected()) {
if (highlightY < getDataSize() - 1) selectCellAt(highlightY + 1);
} else if (type == Table.TABLE_1D && data[highlightY].isSelected()) {
if (highlightY < getDataSize() - 1) selectCellAt(highlightY + 1);
}
}
public void startHighlight(int x, int y) {
if (isAxis) axisParent.clearSelection();
super.startHighlight(x, y);
}
public StringBuffer getTableAsString() {
StringBuffer output = new StringBuffer("");
for (int i = 0; i < getDataSize(); i++) {
output.append(data[i].getText());
if (i < getDataSize() - 1) output.append("\t");
}
return output;
}
public String getCellAsString(int index) {
return data[index].getText();
}
public Color getAxisColor() {
return axisColor;
}
public void setAxisColor(Color axisColor) {
this.axisColor = axisColor;
}
}

258
enginuity/maps/Table2D.java Normal file
View File

@ -0,0 +1,258 @@
package enginuity.maps;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.KeyListener;
import java.io.IOException;
import java.util.StringTokenizer;
import javax.swing.JLabel;
import enginuity.Settings;
import enginuity.swing.TableFrame;
public class Table2D extends Table {
private Table1D axis = new Table1D(new Settings());
public Table2D(Settings settings) {
super(settings);
verticalOverhead += 18;
}
public Table1D getAxis() {
return axis;
}
public void setAxis(Table1D axis) {
this.axis = axis;
}
public String toString() {
return super.toString() + " (2D)";// + axis;
}
public void colorize() {
super.colorize();
axis.colorize();
}
public void setFrame(TableFrame frame) {
this.frame = frame;
axis.setFrame(frame);
frame.setSize(getFrameSize());
}
public Dimension getFrameSize() {
int height = verticalOverhead + cellHeight * 2;
int width = horizontalOverhead + data.length * cellWidth;
if (height < minHeight) height = minHeight;
if (width < minWidth) width = minWidth;
return new Dimension(width, height);
}
public void applyColorSettings(Settings settings) {
this.setAxisColor(settings.getAxisColor());
axis.applyColorSettings(settings);
super.applyColorSettings(settings);
}
public void populateTable(byte[] input) throws ArrayIndexOutOfBoundsException {
centerLayout.setRows(2);
centerLayout.setColumns(this.getDataSize());
try {
axis.setRom(container);
axis.populateTable(input);
super.populateTable(input);
} catch (ArrayIndexOutOfBoundsException ex) {
throw new ArrayIndexOutOfBoundsException();
}
// add to table
for (int i = 0; i < this.getDataSize(); i++) {
centerPanel.add(axis.getDataCell(i));
}
for (int i = 0; i < this.getDataSize(); i++) {
centerPanel.add(this.getDataCell(i));
}
add(new JLabel(axis.getName() + " (" + axis.getScale().getUnit() + ")", JLabel.CENTER), BorderLayout.NORTH);
if (axis.isStatic()) add(new JLabel(axis.getName(), JLabel.CENTER), BorderLayout.NORTH);
else add(new JLabel(axis.getName() + " (" + axis.getScale().getUnit() + ")", JLabel.CENTER), BorderLayout.NORTH);
add(new JLabel(scales.get(scaleIndex).getUnit(), JLabel.CENTER), BorderLayout.SOUTH);
//this.colorize();
}
public void increment(double increment) {
super.increment(increment);
axis.increment(increment);
}
public void multiply(double factor) {
super.multiply(factor);
axis.multiply(factor);
}
public void clearSelection() {
axis.clearSelection(true);
for (int i = 0; i < data.length; i++) {
data[i].setSelected(false);
}
}
public void setRevertPoint() {
super.setRevertPoint();
axis.setRevertPoint();
}
public void undoAll() {
super.undoAll();
axis.undoAll();
}
public void undoSelected() {
super.undoSelected();
axis.undoSelected();
}
public byte[] saveFile(byte[] binData) {
binData = super.saveFile(binData);
binData = axis.saveFile(binData);
return binData;
}
public void setRealValue(String realValue) {
axis.setRealValue(realValue);
super.setRealValue(realValue);
}
public void addKeyListener(KeyListener listener) {
super.addKeyListener(listener);
axis.addKeyListener(listener);
}
public void selectCellAt(int y, Table1D axisType) {
selectCellAt(y);
}
public void cursorUp() {
if (!axis.isStatic() && data[highlightY].isSelected()) axis.selectCellAt(highlightY);
}
public void cursorDown() {
axis.cursorDown();
}
public void cursorLeft() {
if (highlightY > 0 && data[highlightY].isSelected()) selectCellAt(highlightY - 1);
else axis.cursorLeft();
}
public void cursorRight() {
if (highlightY < data.length - 1 && data[highlightY].isSelected()) selectCellAt(highlightY + 1);
else axis.cursorRight();
}
public void startHighlight(int x, int y) {
axis.clearSelection();
super.startHighlight(x, y);
}
public void copySelection() {
super.copySelection();
axis.copySelection();
}
public void copyTable() {
// create string
String newline = System.getProperty("line.separator");
StringBuffer output = new StringBuffer("[Table2D]" + newline);
output.append(axis.getTableAsString() + newline);
output.append(super.getTableAsString());
//copy to clipboard
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(output+""), null);
}
public void paste() {
StringTokenizer st = new StringTokenizer("");
String input = "";
try {
input = (String)Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor);
st = new StringTokenizer(input);
} catch (UnsupportedFlavorException ex) { /* wrong paste type -- do nothing */
} catch (IOException ex) { }
String pasteType = st.nextToken();
if (pasteType.equalsIgnoreCase("[Table2D]")) { // Paste table
String newline = System.getProperty("line.separator");
String axisValues = "[Table1D]" + newline + st.nextToken(newline);
String dataValues = "[Table1D]" + newline + st.nextToken(newline);
// put axis in clipboard and paste
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(axisValues+""), null);
axis.paste();
// put datavalues in clipboard and paste
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(dataValues+""), null);
super.paste();
// reset clipboard
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(input+""), null);
} else if (pasteType.equalsIgnoreCase("[Selection1D]")) { // paste selection
if (data[highlightY].isSelected()) {
super.paste();
} else {
axis.paste();
}
}
}
public void pasteCompare() {
StringTokenizer st = new StringTokenizer("");
String input = "";
try {
input = (String)Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor);
st = new StringTokenizer(input);
} catch (UnsupportedFlavorException ex) { /* wrong paste type -- do nothing */
} catch (IOException ex) { }
String pasteType = st.nextToken();
if (pasteType.equalsIgnoreCase("[Table2D]")) { // Paste table
String newline = System.getProperty("line.separator");
String axisValues = "[Table1D]" + newline + st.nextToken(newline);
String dataValues = "[Table1D]" + newline + st.nextToken(newline);
// put axis in clipboard and paste
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(axisValues+""), null);
axis.pasteCompare();
// put datavalues in clipboard and paste
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(dataValues+""), null);
super.pasteCompare();
// reset clipboard
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(input+""), null);
}
}
public void setAxisColor(Color axisColor) {
axis.setAxisColor(axisColor);
}
public void validateScaling() {
super.validateScaling();
axis.validateScaling();
}
public void setScaleIndex(int scaleIndex) {
super.setScaleIndex(scaleIndex);
axis.setScaleByName(getScale().getName());
}
}

849
enginuity/maps/Table3D.java Normal file
View File

@ -0,0 +1,849 @@
package enginuity.maps;
import enginuity.Settings;
import enginuity.swing.TableFrame;
import enginuity.swing.VTextIcon;
import static enginuity.util.ColorScaler.getScaledColor;
import enginuity.xml.RomAttributeParser;
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.KeyListener;
import java.io.IOException;
import java.util.StringTokenizer;
public class Table3D extends Table {
private Table1D xAxis = new Table1D(new Settings());
private Table1D yAxis = new Table1D(new Settings());
private DataCell[][] data = new DataCell[1][1];
private boolean swapXY = false;
private boolean flipX = false;
private boolean flipY = false;
public Table3D(Settings settings) {
super(settings);
verticalOverhead += 39;
horizontalOverhead += 10;
}
public Table1D getXAxis() {
return xAxis;
}
public void setXAxis(Table1D xAxis) {
this.xAxis = xAxis;
}
public Table1D getYAxis() {
return yAxis;
}
public void setYAxis(Table1D yAxis) {
this.yAxis = yAxis;
}
public boolean isSwapXY() {
return swapXY;
}
public void setSwapXY(boolean swapXY) {
this.swapXY = swapXY;
}
public boolean getFlipX() {
return flipX;
}
public void setFlipX(boolean flipX) {
this.flipX = flipX;
}
public boolean getFlipY() {
return flipY;
}
public void setFlipY(boolean flipY) {
this.flipY = flipY;
}
public void setSizeX(int size) {
data = new DataCell[size][data[0].length];
centerLayout.setColumns(size + 1);
}
public int getSizeX() {
return data.length;
}
public void setSizeY(int size) {
data = new DataCell[data.length][size];
centerLayout.setRows(size + 1);
}
public int getSizeY() {
return data[0].length;
}
public void populateTable(byte[] input) throws NullPointerException, ArrayIndexOutOfBoundsException {
// fill first empty cell
centerPanel.add(new JLabel());
if (!beforeRam) {
ramOffset = container.getRomID().getRamOffset();
}
// temporarily remove lock
boolean tempLock = locked;
locked = false;
// populate axiis
try {
xAxis.setRom(container);
xAxis.populateTable(input);
yAxis.setRom(container);
yAxis.populateTable(input);
} catch (ArrayIndexOutOfBoundsException ex) {
throw new ArrayIndexOutOfBoundsException();
}
for (int i = 0; i < xAxis.getDataSize(); i++) {
centerPanel.add(xAxis.getDataCell(i));
}
int offset = 0;
for (int x = 0; x < yAxis.getDataSize(); x++) {
centerPanel.add(yAxis.getDataCell(x));
for (int y = 0; y < xAxis.getDataSize(); y++) {
data[y][x] = new DataCell(scales.get(scaleIndex));
data[y][x].setTable(this);
// populate data cells
if (storageType == STORAGE_TYPE_FLOAT) { //float storage type
byte[] byteValue = new byte[4];
byteValue[0] = input[storageAddress + offset * 4 - ramOffset];
byteValue[1] = input[storageAddress + offset * 4 - ramOffset + 1];
byteValue[2] = input[storageAddress + offset * 4 - ramOffset + 2];
byteValue[3] = input[storageAddress + offset * 4 - ramOffset + 3];
data[y][x].setBinValue(RomAttributeParser.byteToFloat(byteValue, endian));
} else { // integer storage type
data[y][x].setBinValue(
RomAttributeParser.parseByteValue(input,
endian,
storageAddress + offset * storageType - ramOffset,
storageType));
}
// show locked cell
if (tempLock) {
data[y][x].setForeground(Color.GRAY);
}
centerPanel.add(data[y][x]);
data[y][x].setXCoord(y);
data[y][x].setYCoord(x);
data[y][x].setOriginalValue(data[y][x].getBinValue());
offset++;
}
}
// reset locked status
locked = tempLock;
GridLayout topLayout = new GridLayout(2, 1);
JPanel topPanel = new JPanel(topLayout);
this.add(topPanel, BorderLayout.NORTH);
topPanel.add(new JLabel(name, JLabel.CENTER), BorderLayout.NORTH);
topPanel.add(new JLabel(xAxis.getName() + " (" + xAxis.getScale().getUnit() + ")", JLabel.CENTER), BorderLayout.NORTH);
JLabel yLabel = new JLabel();
yLabel.setFont(new Font("Arial", Font.BOLD, 12));
VTextIcon icon = new VTextIcon(yLabel, yAxis.getName() + " (" + yAxis.getScale().getUnit() + ")", VTextIcon.ROTATE_LEFT);
yLabel.setIcon(icon);
add(yLabel, BorderLayout.WEST);
add(new JLabel(getScale().getUnit(), JLabel.CENTER), BorderLayout.SOUTH);
}
public void colorize() {
if (compareType == COMPARE_OFF) {
if (!isStatic && !isAxis) {
double high = Double.MIN_VALUE;
double low = Double.MAX_VALUE;
if (getScale().getMax() != 0 || getScale().getMin() != 0) {
// set min and max values if they are set in scale
high = getScale().getMax();
low = getScale().getMin();
} else {
// min/max not set in scale
for (DataCell[] column : data) {
for (DataCell cell : column) {
if (Double.parseDouble(cell.getText()) > high) {
high = Double.parseDouble(cell.getText());
}
if (Double.parseDouble(cell.getText()) < low) {
low = Double.parseDouble(cell.getText());
}
}
}
}
for (DataCell[] column : data) {
for (DataCell cell : column) {
if (Double.parseDouble(cell.getText()) > high ||
Double.parseDouble(cell.getText()) < low) {
// value exceeds limit
cell.setColor(settings.getWarningColor());
} else {
// limits not set, scale based on table values
double scale = 0;
if (high - low == 0) {
// if all values are the same, color will be middle value
scale = .5;
} else {
scale = (Double.parseDouble(cell.getText()) - low) / (high - low);
}
cell.setColor(getScaledColor(scale, settings));
}
}
}
}
} else { // comparing is on
if (!isStatic) {
double high = Double.MIN_VALUE;
// determine ratios
for (DataCell[] column : data) {
for (DataCell cell : column) {
if (Math.abs(cell.getBinValue() - cell.getOriginalValue()) > high) {
high = Math.abs(cell.getBinValue() - cell.getOriginalValue());
}
}
}
// colorize
for (DataCell[] column : data) {
for (DataCell cell : column) {
double cellDifference = Math.abs(cell.getBinValue() - cell.getOriginalValue());
double scale;
if (high == 0) {
scale = 0;
} else {
scale = cellDifference / high;
}
if (scale == 0) {
cell.setColor(UNCHANGED_VALUE_COLOR);
} else {
cell.setColor(getScaledColor(scale, settings));
}
// set border
if (cell.getBinValue() > cell.getOriginalValue()) {
cell.setBorder(new LineBorder(settings.getIncreaseBorder()));
} else if (cell.getBinValue() < cell.getOriginalValue()) {
cell.setBorder(new LineBorder(settings.getDecreaseBorder()));
} else {
cell.setBorder(new LineBorder(Color.BLACK, 1));
}
}
}
}
xAxis.colorize();
yAxis.colorize();
}
// colorize borders
if (!isStatic) {
for (DataCell[] column : data) {
for (DataCell cell : column) {
if (cell.getBinValue() > cell.getOriginalValue()) {
cell.setBorder(new LineBorder(settings.getIncreaseBorder()));
} else if (cell.getBinValue() < cell.getOriginalValue()) {
cell.setBorder(new LineBorder(settings.getDecreaseBorder()));
} else {
cell.setBorder(new LineBorder(Color.BLACK, 1));
}
}
}
}
}
public void compare(int compareType) {
this.compareType = compareType;
for (DataCell[] column : data) {
for (DataCell cell : column) {
if (compareType == Table.COMPARE_ORIGINAL) {
cell.setCompareValue(cell.getOriginalValue());
}
cell.setCompareType(compareType);
cell.setCompareDisplay(compareDisplay);
cell.updateDisplayValue();
}
}
colorize();
}
public void setFrame(TableFrame frame) {
this.frame = frame;
xAxis.setFrame(frame);
yAxis.setFrame(frame);
frame.setSize(getFrameSize());
}
public Dimension getFrameSize() {
int height = verticalOverhead + cellHeight * data[0].length;
int width = horizontalOverhead + data.length * cellWidth;
if (height < minHeight) {
height = minHeight;
}
if (width < minWidth) {
width = minWidth;
}
return new Dimension(width, height);
}
public String toString() {
return super.toString() + " (3D)";/* +
"\n Flip X: " + flipX +
"\n Size X: " + data.length +
"\n Flip Y: " + flipY +
"\n Size Y: " + data[0].length +
"\n Swap X/Y: " + swapXY +
xAxis +
yAxis;*/
}
public void increment(double increment) {
if (!isStatic && !locked) {
for (int x = 0; x < this.getSizeX(); x++) {
for (int y = 0; y < this.getSizeY(); y++) {
if (data[x][y].isSelected()) {
data[x][y].increment(increment);
}
}
}
}
xAxis.increment(increment);
yAxis.increment(increment);
}
public void multiply(double factor) {
if (!isStatic && !locked) {
for (int x = 0; x < this.getSizeX(); x++) {
for (int y = 0; y < this.getSizeY(); y++) {
if (data[x][y].isSelected()) {
data[x][y].multiply(factor);
}
}
}
}
xAxis.multiply(factor);
yAxis.multiply(factor);
colorize();
}
public void clearSelection() {
xAxis.clearSelection(true);
yAxis.clearSelection(true);
for (int x = 0; x < this.getSizeX(); x++) {
for (int y = 0; y < this.getSizeY(); y++) {
data[x][y].setSelected(false);
}
}
}
public void highlight(int xCoord, int yCoord) {
if (highlight) {
for (int x = 0; x < this.getSizeX(); x++) {
for (int y = 0; y < this.getSizeY(); y++) {
if (((y >= highlightY && y <= yCoord) ||
(y <= highlightY && y >= yCoord)) &&
((x >= highlightX && x <= xCoord) ||
(x <= highlightX && x >= xCoord))) {
data[x][y].setHighlighted(true);
} else {
data[x][y].setHighlighted(false);
}
}
}
}
}
public void stopHighlight() {
highlight = false;
// loop through, selected and un-highlight
for (int x = 0; x < this.getSizeX(); x++) {
for (int y = 0; y < this.getSizeY(); y++) {
if (data[x][y].isHighlighted()) {
data[x][y].setSelected(true);
data[x][y].setHighlighted(false);
}
}
}
}
public void setRevertPoint() {
for (int x = 0; x < this.getSizeX(); x++) {
for (int y = 0; y < this.getSizeY(); y++) {
data[x][y].setOriginalValue(data[x][y].getBinValue());
}
}
yAxis.setRevertPoint();
xAxis.setRevertPoint();
colorize();
}
public void undoAll() {
for (int x = 0; x < this.getSizeX(); x++) {
for (int y = 0; y < this.getSizeY(); y++) {
data[x][y].setBinValue(data[x][y].getOriginalValue());
}
}
yAxis.undoAll();
xAxis.undoAll();
colorize();
}
public void undoSelected() {
for (int x = 0; x < this.getSizeX(); x++) {
for (int y = 0; y < this.getSizeY(); y++) {
if (data[x][y].isSelected()) {
data[x][y].setBinValue(data[x][y].getOriginalValue());
}
}
}
yAxis.undoSelected();
xAxis.undoSelected();
colorize();
}
public byte[] saveFile(byte[] binData) {
if (!isStatic // save if table is not static
&& // and user level is great enough
userLevel <= settings.getUserLevel()
&& // and table is not in debug mode, unless saveDebugTables is true
(userLevel < 5
||
settings.isSaveDebugTables())) {
binData = xAxis.saveFile(binData);
binData = yAxis.saveFile(binData);
int offset = 0;
for (int x = 0; x < yAxis.getDataSize(); x++) {
for (int y = 0; y < xAxis.getDataSize(); y++) {
// determine output byte values
byte[] output;
if (storageType != STORAGE_TYPE_FLOAT) {
output = RomAttributeParser.parseIntegerValue((int) data[y][x].getBinValue(), endian, storageType);
for (int z = 0; z < storageType; z++) {
binData[offset * storageType + z + storageAddress - ramOffset] = output[z];
}
} else { // float
output = RomAttributeParser.floatToByte((float) data[y][x].getBinValue(), endian);
for (int z = 0; z < 4; z++) {
binData[offset * 4 + z + storageAddress - ramOffset] = output[z];
}
}
offset++;
}
}
}
return binData;
}
public void setRealValue(String realValue) {
if (!isStatic && !locked) {
for (int x = 0; x < this.getSizeX(); x++) {
for (int y = 0; y < this.getSizeY(); y++) {
if (data[x][y].isSelected()) {
data[x][y].setRealValue(realValue);
}
}
}
}
xAxis.setRealValue(realValue);
yAxis.setRealValue(realValue);
colorize();
}
public void addKeyListener(KeyListener listener) {
xAxis.addKeyListener(listener);
yAxis.addKeyListener(listener);
for (int x = 0; x < this.getSizeX(); x++) {
for (int y = 0; y < this.getSizeY(); y++) {
data[x][y].addKeyListener(listener);
}
}
}
public void selectCellAt(int y, Table1D axisType) {
if (axisType.getType() == TABLE_Y_AXIS) {
selectCellAt(0, y);
} else { // y axis
selectCellAt(y, 0);
}
}
public void selectCellAt(int x, int y) {
clearSelection();
data[x][y].setSelected(true);
highlightX = x;
highlightY = y;
}
public void cursorUp() {
if (highlightY > 0 && data[highlightX][highlightY].isSelected()) {
selectCellAt(highlightX, highlightY - 1);
} else if (!xAxis.isStatic() && data[highlightX][highlightY].isSelected()) {
xAxis.selectCellAt(highlightX);
} else {
xAxis.cursorUp();
yAxis.cursorUp();
}
}
public void cursorDown() {
if (highlightY < getSizeY() - 1 && data[highlightX][highlightY].isSelected()) {
selectCellAt(highlightX, highlightY + 1);
} else {
xAxis.cursorDown();
yAxis.cursorDown();
}
}
public void cursorLeft() {
if (highlightX > 0 && data[highlightX][highlightY].isSelected()) {
selectCellAt(highlightX - 1, highlightY);
} else if (!yAxis.isStatic() && data[highlightX][highlightY].isSelected()) {
yAxis.selectCellAt(highlightY);
} else {
xAxis.cursorLeft();
yAxis.cursorLeft();
}
}
public void cursorRight() {
if (highlightX < getSizeX() - 1 && data[highlightX][highlightY].isSelected()) {
selectCellAt(highlightX + 1, highlightY);
} else {
xAxis.cursorRight();
yAxis.cursorRight();
}
}
public void startHighlight(int x, int y) {
xAxis.clearSelection();
yAxis.clearSelection();
super.startHighlight(x, y);
}
public void copySelection() {
// find bounds of selection
// coords[0] = x min, y min, x max, y max
boolean copy = false;
int[] coords = new int[4];
coords[0] = this.getSizeX();
coords[1] = this.getSizeY();
for (int x = 0; x < this.getSizeX(); x++) {
for (int y = 0; y < this.getSizeY(); y++) {
if (data[x][y].isSelected()) {
if (x < coords[0]) {
coords[0] = x;
copy = true;
}
if (x > coords[2]) {
coords[2] = x;
copy = true;
}
if (y < coords[1]) {
coords[1] = y;
copy = true;
}
if (y > coords[3]) {
coords[3] = y;
copy = true;
}
}
}
}
// make string of selection
if (copy) {
String newline = System.getProperty("line.separator");
StringBuffer output = new StringBuffer("[Selection3D]" + newline);
for (int y = coords[1]; y <= coords[3]; y++) {
for (int x = coords[0]; x <= coords[2]; x++) {
if (data[x][y].isSelected()) {
output.append(data[x][y].getText());
} else {
output.append("x"); // x represents non-selected cell
}
if (x < coords[2]) {
output.append("\t");
}
}
if (y < coords[3]) {
output.append(newline);
}
//copy to clipboard
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(String.valueOf(output)), null);
}
} else {
xAxis.copySelection();
yAxis.copySelection();
}
}
public void copyTable() {
// create string
String newline = System.getProperty("line.separator");
StringBuffer output = new StringBuffer("[Table3D]" + newline);
output.append(xAxis.getTableAsString()).append(newline);
for (int y = 0; y < getSizeY(); y++) {
output.append(yAxis.getCellAsString(y)).append("\t");
for (int x = 0; x < getSizeX(); x++) {
output.append(data[x][y].getText());
if (x < getSizeX() - 1) {
output.append("\t");
}
}
if (y < getSizeY() - 1) {
output.append(newline);
}
}
//copy to clipboard
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(String.valueOf(output)), null);
}
public void paste() {
StringTokenizer st = new StringTokenizer("");
String input = "";
try {
input = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor);
st = new StringTokenizer(input);
} catch (UnsupportedFlavorException ex) { /* wrong paste type -- do nothing */
} catch (IOException ex) {
}
String pasteType = st.nextToken();
if ("[Table3D]".equalsIgnoreCase(pasteType)) { // Paste table
String newline = System.getProperty("line.separator");
String xAxisValues = "[Table1D]" + newline + st.nextToken(newline);
// build y axis and data values
StringBuffer yAxisValues = new StringBuffer("[Table1D]" + newline + st.nextToken("\t"));
StringBuffer dataValues = new StringBuffer("[Table3D]" + newline + st.nextToken("\t") + st.nextToken(newline));
while (st.hasMoreTokens()) {
yAxisValues.append("\t").append(st.nextToken("\t"));
dataValues.append(newline).append(st.nextToken("\t")).append(st.nextToken(newline));
}
// put x axis in clipboard and paste
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(xAxisValues), null);
xAxis.paste();
// put y axis in clipboard and paste
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(String.valueOf(yAxisValues)), null);
yAxis.paste();
// put datavalues in clipboard and paste
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(String.valueOf(dataValues)), null);
pasteValues();
// reset clipboard
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(input), null);
} else if ("[Selection3D]".equalsIgnoreCase(pasteType)) { // paste selection
pasteValues();
} else if ("[Selection1D]".equalsIgnoreCase(pasteType)) { // paste selection
xAxis.paste();
yAxis.paste();
}
}
public void pasteCompare() {
StringTokenizer st = new StringTokenizer("");
String input = "";
try {
input = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor);
st = new StringTokenizer(input);
} catch (UnsupportedFlavorException ex) { /* wrong paste type -- do nothing */
} catch (IOException ex) {
}
String pasteType = st.nextToken();
if ("[Table3D]".equalsIgnoreCase(pasteType)) { // Paste table
String newline = System.getProperty("line.separator");
String xAxisValues = "[Table1D]" + newline + st.nextToken(newline);
StringBuffer yAxisValues = new StringBuffer("");
StringBuffer dataValues = new StringBuffer("");
while (st.hasMoreTokens()) {
StringTokenizer currentLine = new StringTokenizer(st.nextToken(newline));
yAxisValues.append(currentLine.nextToken("\t")).append("\t");
//dataValues.append(currentLine.nextToken(newline));
while (currentLine.hasMoreTokens()) {
dataValues.append(currentLine.nextToken()).append("\t");
}
dataValues.append(newline);
}
// put x axis in clipboard and paste
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(xAxisValues), null);
xAxis.pasteCompare();
// put y axis in clipboard and paste
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(yAxisValues.toString()), null);
yAxis.pasteCompare();
// put datavalues in clipboard and paste
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(dataValues.toString()), null);
pasteCompareValues();
// reset clipboard
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(input), null);
}
colorize();
}
public void pasteCompareValues() {
StringTokenizer st = new StringTokenizer("");
try {
String input = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor);
st = new StringTokenizer(input);
} catch (UnsupportedFlavorException ex) { /* wrong paste type -- do nothing */
} catch (IOException ex) {
}
// set values
for (int y = 0; y < getSizeY(); y++) {
if (st.hasMoreTokens()) {
for (int x = 0; x < getSizeX(); x++) {
String currentToken = st.nextToken();
data[x][y].setCompareRealValue(currentToken);
}
}
}
}
public void pasteValues() {
StringTokenizer st = new StringTokenizer("");
String newline = System.getProperty("line.separator");
try {
String input = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor);
st = new StringTokenizer(input);
} catch (UnsupportedFlavorException ex) { /* wrong paste type -- do nothing */
} catch (IOException ex) {
}
String pasteType = st.nextToken();
// figure paste start cell
int startX = 0;
int startY = 0;
// if pasting a table, startX and Y at 0, else highlight is start
if ("[Selection3D]".equalsIgnoreCase(pasteType)) {
startX = highlightX;
startY = highlightY;
}
// set values
for (int y = startY; y < getSizeY(); y++) {
if (st.hasMoreTokens()) {
StringTokenizer currentLine = new StringTokenizer(st.nextToken(newline));
for (int x = startX; x < getSizeX(); x++) {
if (currentLine.hasMoreTokens()) {
String currentToken = currentLine.nextToken();
try {
if (!data[x][y].getText().equalsIgnoreCase(currentToken)) {
data[x][y].setRealValue(currentToken);
}
} catch (ArrayIndexOutOfBoundsException ex) { /* copied table is larger than current table*/ }
}
}
}
}
}
public void applyColorSettings(Settings settings) {
// apply settings to cells
this.settings = settings;
for (int y = 0; y < getSizeY(); y++) {
for (int x = 0; x < getSizeX(); x++) {
this.setMaxColor(settings.getMaxColor());
this.setMinColor(settings.getMinColor());
data[x][y].setHighlightColor(settings.getHighlightColor());
data[x][y].setIncreaseBorder(settings.getIncreaseBorder());
data[x][y].setDecreaseBorder(settings.getDecreaseBorder());
data[x][y].setFont(settings.getTableFont());
data[x][y].repaint();
}
}
this.setAxisColor(settings.getAxisColor());
xAxis.applyColorSettings(settings);
yAxis.applyColorSettings(settings);
cellHeight = (int) settings.getCellSize().getHeight();
cellWidth = (int) settings.getCellSize().getWidth();
validateScaling();
resize();
colorize();
}
public void setAxisColor(Color axisColor) {
xAxis.setAxisColor(axisColor);
yAxis.setAxisColor(axisColor);
}
public void validateScaling() {
super.validateScaling();
xAxis.validateScaling();
yAxis.validateScaling();
}
public void refreshValues() {
if (!isStatic && !isAxis) {
for (DataCell[] column : data) {
for (DataCell cell : column) {
cell.refreshValue();
}
}
}
}
public void setScaleIndex(int scaleIndex) {
super.setScaleIndex(scaleIndex);
xAxis.setScaleByName(getScale().getName());
yAxis.setScaleByName(getScale().getName());
}
}

View File

@ -0,0 +1,104 @@
package enginuity.maps;
import enginuity.Settings;
import enginuity.xml.RomAttributeParser;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.util.StringTokenizer;
import javax.swing.JCheckBox;
import javax.swing.JTextArea;
public class TableSwitch extends Table {
private byte[] on = new byte[0];
private byte[] off = new byte[0];
private JCheckBox checkbox = new JCheckBox("Enabled", true); // checkbox selected by default
public TableSwitch(Settings settings) {
super(settings);
storageType = 1;
removeAll();
setLayout(new BorderLayout());
}
public void setDataSize(int size) {
on = new byte[size];
off = new byte[size];
}
public void populateTable(byte[] input) {
for (int i = 0; i < on.length; i++) {
// check each byte -- if it doesn't match "on", it's off
if (!beforeRam) ramOffset = container.getRomID().getRamOffset();
if (on[i] != input[storageAddress - ramOffset + i]) {
checkbox.setSelected(false);
break;
}
}
}
public void setName(String name) {
super.setName(name);
checkbox.setText("Enable " + name);
add(checkbox, BorderLayout.NORTH);
}
public void setDescription(String description) {
super.setDescription(description);
JTextArea descriptionArea = new JTextArea(description);
descriptionArea.setOpaque(false);
descriptionArea.setEditable(false);
descriptionArea.setWrapStyleWord(true);
descriptionArea.setLineWrap(true);
add(descriptionArea, BorderLayout.CENTER);
}
public byte[] saveFile(byte[] input) {
if (checkbox.isSelected()) { // switch is on
for (int i = 0; i < on.length; i++) {
input[storageAddress - ramOffset + i] = on[i];
}
} else { // switch is off
for (int i = 0; i < on.length; i++) {
input[storageAddress - ramOffset + i] = off[i];
}
}
return input;
}
public void setOnValues(String input) {
StringTokenizer tokens = new StringTokenizer(input);
for (int i = 0; i < off.length; i++) {
on[i] = (byte)RomAttributeParser.parseHexString(tokens.nextToken());
}
}
public void setOffValues(String input) {
StringTokenizer tokens = new StringTokenizer(input);
for (int i = 0; i < off.length; i++) {
off[i] = (byte)RomAttributeParser.parseHexString(tokens.nextToken());
}
}
public Dimension getFrameSize() {
int height = verticalOverhead + 75;
int width = horizontalOverhead;
if (height < minHeight) height = minHeight;
if (width < minWidth) width = minWidth;
return new Dimension(width, height);
}
public void colorize() { }
public void cursorUp() { }
public void cursorDown() { }
public void cursorLeft() { }
public void cursorRight() { }
public void setAxisColor(Color color) { }
}

View File

@ -0,0 +1,53 @@
package enginuity.net;
import java.io.IOException;
public class BrowserControl {
public static void displayURL(String url) {
boolean windows = isWindowsPlatform();
String cmd = null;
try {
if (windows) {
// cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
Runtime.getRuntime().exec(cmd);
}
else {
cmd = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")";
Process p = Runtime.getRuntime().exec(cmd);
try {
int exitCode = p.waitFor();
if (exitCode != 0)
{
cmd = UNIX_PATH + " " + url;
Runtime.getRuntime().exec(cmd);
}
}
catch(InterruptedException x) {
System.err.println("Error bringing up browser, cmd='" +
cmd + "'");
System.err.println("Caught: " + x);
}
}
}
catch(IOException x) {
// couldn't exec browser
System.err.println("Could not invoke browser, command=" + cmd);
System.err.println("Caught: " + x);
}
}
public static boolean isWindowsPlatform() {
String os = System.getProperty("os.name");
if ( os != null && os.startsWith(WIN_ID))
return true;
else
return false;
}
private static final String WIN_ID = "Windows";
private static final String WIN_PATH = "rundll32";
private static final String WIN_FLAG = "url.dll,FileProtocolHandler";
private static final String UNIX_PATH = "netscape";
private static final String UNIX_FLAG = "-remote openURL";
}

41
enginuity/net/URL.java Normal file
View File

@ -0,0 +1,41 @@
package enginuity.net;
import enginuity.net.BrowserControl;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JLabel;
public class URL extends JLabel implements MouseListener {
String url = "";
public URL(String url) {
super(url);
this.url = url;
this.setFont(new Font("Arial", Font.PLAIN, 12));
this.addMouseListener(this);
}
public void paint (Graphics g) {
super.paint(g);
Font f = getFont();
FontMetrics fm = getFontMetrics(f);
int x1 = 0;
int y1 = fm.getHeight() + 3;
int x2 = fm.stringWidth(getText());
if (getText().length() > 0)
g.drawLine(x1, y1, x2, y1);
}
public void mouseClicked(MouseEvent e) {
BrowserControl.displayURL(url);
}
public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
}

View File

@ -0,0 +1,22 @@
package enginuity.swing;
import enginuity.maps.Rom;
import javax.swing.tree.DefaultMutableTreeNode;
public class CategoryTreeNode extends DefaultMutableTreeNode {
private Rom rom;
public CategoryTreeNode(String name, Rom rom) {
super(name);
this.setRom(rom);
}
public Rom getRom() {
return rom;
}
public void setRom(Rom rom) {
this.rom = rom;
}
}

View File

@ -0,0 +1,32 @@
package enginuity.swing;
import enginuity.net.URL;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class DebugPanel extends JPanel {
public DebugPanel(Exception ex, String url) {
setLayout(new BorderLayout());
JPanel top = new JPanel(new GridLayout(7, 1));
top.add(new JLabel("Enginuity has encountered an exception. Please review the details below."));
top.add(new JLabel("If you are unable to fix this problem please visit the following website"));
top.add(new JLabel("and provide these details and the steps that lead to this error."));
top.add(new JLabel());
top.add(new URL(url));
top.add(new JLabel());
top.add(new JLabel("Details:"));
add(top, BorderLayout.NORTH);
JTextArea output = new JTextArea(ex.getMessage());
add(output, BorderLayout.CENTER);
output.setAutoscrolls(true);
output.setRows(10);
output.setColumns(40);
ex.printStackTrace();
}
}

View File

@ -0,0 +1,146 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
<Property name="title" type="java.lang.String" value="Definition File Manager"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" alignment="0" pref="448" max="32767" attributes="1"/>
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="btnSave" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnApply" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnUndo" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="defLabel" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="btnMoveDown" linkSize="1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnMoveUp" linkSize="1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace pref="80" max="32767" attributes="0"/>
<Component id="btnAddDefinition" linkSize="1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnRemoveDefinition" linkSize="1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="defLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" max="-2" attributes="1"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnMoveUp" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnMoveDown" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnRemoveDefinition" alignment="3" min="-2" pref="23" max="-2" attributes="0"/>
<Component id="btnAddDefinition" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnSave" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnApply" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnUndo" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JList" name="definitionList">
<Properties>
<Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
<StringArray count="0"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="defLabel">
<Properties>
<Property name="text" type="java.lang.String" value="ECU Definition File Priority"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnMoveUp">
<Properties>
<Property name="text" type="java.lang.String" value="Move Up"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnMoveDown">
<Properties>
<Property name="text" type="java.lang.String" value="Move Down"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnAddDefinition">
<Properties>
<Property name="text" type="java.lang.String" value="Add..."/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnRemoveDefinition">
<Properties>
<Property name="text" type="java.lang.String" value="Remove"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnSave">
<Properties>
<Property name="text" type="java.lang.String" value="Save"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnCancel">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnApply">
<Properties>
<Property name="text" type="java.lang.String" value="Apply"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnUndo">
<Properties>
<Property name="text" type="java.lang.String" value="Undo"/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,239 @@
package enginuity.swing;
import enginuity.ECUEditor;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Vector;
import javax.swing.JFileChooser;
import javax.swing.ListSelectionModel;
public class DefinitionManager extends javax.swing.JFrame implements ActionListener {
public static int MOVE_UP = 0;
public static int MOVE_DOWN = 1;
ECUEditor parent;
Vector<String> fileNames;
public DefinitionManager(ECUEditor parent) {
initComponents();
this.parent = parent;
initSettings();
definitionList.setFont(new Font("Tahoma", Font.PLAIN, 11));
definitionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
btnCancel.addActionListener(this);
btnSave.addActionListener(this);
btnAddDefinition.addActionListener(this);
btnRemoveDefinition.addActionListener(this);
btnMoveUp.addActionListener(this);
btnMoveDown.addActionListener(this);
btnApply.addActionListener(this);
btnUndo.addActionListener(this);
}
private void initSettings() {
// add definitions to list
Vector<File> definitionFiles = parent.getSettings().getEcuDefinitionFiles();
fileNames = new Vector<String>();
for (int i = 0; i < definitionFiles.size(); i++) {
fileNames.add(definitionFiles.get(i).getAbsolutePath());
}
updateListModel();
}
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
definitionList = new javax.swing.JList();
defLabel = new javax.swing.JLabel();
btnMoveUp = new javax.swing.JButton();
btnMoveDown = new javax.swing.JButton();
btnAddDefinition = new javax.swing.JButton();
btnRemoveDefinition = new javax.swing.JButton();
btnSave = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
btnApply = new javax.swing.JButton();
btnUndo = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Definition File Manager");
jScrollPane1.setViewportView(definitionList);
defLabel.setText("ECU Definition File Priority");
btnMoveUp.setText("Move Up");
btnMoveDown.setText("Move Down");
btnAddDefinition.setText("Add...");
btnRemoveDefinition.setText("Remove");
btnSave.setText("Save");
btnCancel.setText("Cancel");
btnApply.setText("Apply");
btnUndo.setText("Undo");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(layout.createSequentialGroup()
.add(btnSave)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(btnApply)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(btnUndo)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(btnCancel))
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(defLabel)
.add(layout.createSequentialGroup()
.add(btnMoveDown)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(btnMoveUp)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 80, Short.MAX_VALUE)
.add(btnAddDefinition)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(btnRemoveDefinition)))
.addContainerGap())
);
layout.linkSize(new java.awt.Component[] {btnAddDefinition, btnMoveDown, btnMoveUp, btnRemoveDefinition}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(defLabel)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(btnMoveUp)
.add(btnMoveDown)
.add(btnRemoveDefinition, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnAddDefinition))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(btnSave)
.add(btnApply)
.add(btnUndo)
.add(btnCancel))
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnCancel) {
dispose();
} else if (e.getSource() == btnSave) {
saveSettings();
dispose();
} else if (e.getSource() == btnApply) {
saveSettings();
} else if (e.getSource() == btnMoveUp) {
moveSelection(MOVE_UP);
} else if (e.getSource() == btnMoveDown) {
moveSelection(MOVE_DOWN);
} else if (e.getSource() == btnAddDefinition) {
addFile();
} else if (e.getSource() == btnRemoveDefinition) {
removeSelection();
} else if (e.getSource() == btnUndo) {
initSettings();
}
}
public void saveSettings() {
Vector<File> output = new Vector<File>();
// create file vector
for (int i = 0; i < fileNames.size(); i++) {
output.add(new File(fileNames.get(i)));
}
// save
parent.getSettings().setEcuDefinitionFiles(output);
}
public void addFile() {
JFileChooser fc = new JFileChooser("./");
fc.setFileFilter(new XMLFilter());
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
fileNames.add(fc.getSelectedFile().getAbsolutePath());
updateListModel();
}
}
public void moveSelection(int direction) {
int selectedIndex = definitionList.getSelectedIndex();
String fileName = fileNames.get(selectedIndex);
if (direction == MOVE_UP && selectedIndex > 0) {
fileNames.remove(selectedIndex);
fileNames.add(--selectedIndex, fileName);
} else if (direction == MOVE_DOWN && selectedIndex < definitionList.getModel().getSize()){
fileNames.remove(selectedIndex);
fileNames.add(++selectedIndex, fileName);
}
updateListModel();
definitionList.setSelectedIndex(selectedIndex);
}
public void removeSelection() {
fileNames.remove(definitionList.getSelectedIndex());
updateListModel();
}
public void updateListModel() {
definitionList.setListData(fileNames);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAddDefinition;
private javax.swing.JButton btnApply;
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnMoveDown;
private javax.swing.JButton btnMoveUp;
private javax.swing.JButton btnRemoveDefinition;
private javax.swing.JButton btnSave;
private javax.swing.JButton btnUndo;
private javax.swing.JLabel defLabel;
private javax.swing.JList definitionList;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,305 @@
package enginuity.swing;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.management.modelmbean.XMLParseException;
import javax.swing.ButtonGroup;
import javax.swing.JFileChooser;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JSeparator;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import com.sun.org.apache.xerces.internal.parsers.DOMParser;
import enginuity.ECUEditor;
import enginuity.definitions.DefinitionEditor;
import enginuity.maps.Rom;
import enginuity.xml.DOMRomUnmarshaller;
import enginuity.xml.RomNotFoundException;
public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
private JMenu fileMenu = new JMenu("File");
private JMenuItem openImage = new JMenuItem("Open Image");
private JMenuItem saveImage = new JMenuItem("Save Image");
private JMenuItem refreshImage = new JMenuItem("Refresh Image");
private JMenuItem closeImage = new JMenuItem("Close Image");
private JMenuItem closeAll = new JMenuItem("Close All Images");
private JMenuItem exit = new JMenuItem("Exit");
private JMenu editMenu = new JMenu("Edit");
private JMenuItem defManager = new JMenuItem("ECU Definition Manager");
private JMenuItem settings = new JMenuItem("Settings");
private JMenuItem editDefinition = new JMenuItem("Edit ECU Definitions");
private JMenu viewMenu = new JMenu("View");
private JMenuItem romProperties = new JMenuItem("ECU Image Properties");
private ButtonGroup levelGroup = new ButtonGroup();
private JMenu levelMenu = new JMenu("User Level");
private JRadioButtonMenuItem level1 = new JRadioButtonMenuItem("1 Beginner");
private JRadioButtonMenuItem level2 = new JRadioButtonMenuItem("2 Intermediate");
private JRadioButtonMenuItem level3 = new JRadioButtonMenuItem("3 Advanced");
private JRadioButtonMenuItem level4 = new JRadioButtonMenuItem("4 Highest");
private JRadioButtonMenuItem level5 = new JRadioButtonMenuItem("5 Debug Mode");
private JMenu helpMenu = new JMenu("Help");
private JMenuItem about = new JMenuItem("About Enginuity");
private ECUEditor parent;
public ECUEditorMenuBar(ECUEditor parent) {
this.parent = parent;
// file menu items
add(fileMenu);
fileMenu.setMnemonic('F');
openImage.setMnemonic('O');
saveImage.setMnemonic('S');
refreshImage.setMnemonic('R');
closeImage.setMnemonic('C');
closeAll.setMnemonic('A');
exit.setMnemonic('X');
fileMenu.add(openImage);
fileMenu.add(saveImage);
fileMenu.add(refreshImage);
fileMenu.add(new JSeparator());
fileMenu.add(closeImage);
fileMenu.add(closeAll);
fileMenu.add(new JSeparator());
fileMenu.add(exit);
openImage.addActionListener(this);
saveImage.addActionListener(this);
refreshImage.addActionListener(this);
closeImage.addActionListener(this);
closeAll.addActionListener(this);
exit.addActionListener(this);
// edit menu items
add(editMenu);
editMenu.setMnemonic('E');
defManager.setMnemonic('D');
settings.setMnemonic('S');
editDefinition.setMnemonic('E');
editMenu.add(new JSeparator());
editMenu.add(defManager);
editMenu.add(settings);
editMenu.add(editDefinition);
settings.addActionListener(this);
defManager.addActionListener(this);
editDefinition.addActionListener(this);
// view menu items
add(viewMenu);
viewMenu.setMnemonic('V');
romProperties.setMnemonic('P');
levelMenu.setMnemonic('U');
level1.setMnemonic('1');
level2.setMnemonic('2');
level3.setMnemonic('3');
level4.setMnemonic('4');
level5.setMnemonic('5');
viewMenu.add(romProperties);
viewMenu.add(levelMenu);
levelMenu.add(level1);
levelMenu.add(level2);
levelMenu.add(level3);
levelMenu.add(level4);
levelMenu.add(level5);
romProperties.addActionListener(this);
level1.addActionListener(this);
level2.addActionListener(this);
level3.addActionListener(this);
level4.addActionListener(this);
level5.addActionListener(this);
levelGroup.add(level1);
levelGroup.add(level2);
levelGroup.add(level3);
levelGroup.add(level4);
levelGroup.add(level5);
// select correct userlevel button
if (parent.getSettings().getUserLevel() == 1) level1.setSelected(true);
else if (parent.getSettings().getUserLevel() == 2) level2.setSelected(true);
else if (parent.getSettings().getUserLevel() == 3) level3.setSelected(true);
else if (parent.getSettings().getUserLevel() == 4) level4.setSelected(true);
else if (parent.getSettings().getUserLevel() == 5) level5.setSelected(true);
// help menu stuff
add(helpMenu);
helpMenu.setMnemonic('H');
about.setMnemonic('A');
helpMenu.add(about);
about.addActionListener(this);
// disable unused buttons! 0.3.1
about.setEnabled(false);
editDefinition.setEnabled(false);
this.updateMenu();
}
public void updateMenu() {
String file = "";
try {
file = " " + parent.getLastSelectedRom().getFileName() + " ";
} catch (NullPointerException ex) { }
if (file.equals("")) {
saveImage.setEnabled(false);
closeImage.setEnabled(false);
closeAll.setEnabled(false);
romProperties.setEnabled(false);
} else {
saveImage.setEnabled(true);
closeImage.setEnabled(true);
closeAll.setEnabled(true);
romProperties.setEnabled(true);
}
saveImage.setText("Save" + file);
refreshImage.setText("Refresh" + file);
closeImage.setText("Close" + file);
romProperties.setText(file + "Properties");
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == openImage) {
try {
openImageDialog();
} catch (Exception ex) {
JOptionPane.showMessageDialog(parent, new DebugPanel(ex,
parent.getSettings().getSupportURL()), "Exception", JOptionPane.ERROR_MESSAGE);
}
} else if (e.getSource() == saveImage) {
try {
this.saveImage(parent.getLastSelectedRom());
} catch (Exception ex) {
JOptionPane.showMessageDialog(parent, new DebugPanel(ex,
parent.getSettings().getSupportURL()), "Exception", JOptionPane.ERROR_MESSAGE);
}
} else if (e.getSource() == closeImage) {
this.closeImage();
} else if (e.getSource() == closeAll) {
this.closeAllImages();
} else if (e.getSource() == exit) {
parent.handleExit();
System.exit(0);
} else if (e.getSource() == romProperties) {
JOptionPane.showMessageDialog(parent, (Object)(new RomPropertyPanel(parent.getLastSelectedRom())),
parent.getLastSelectedRom().getRomIDString() + " Properties", JOptionPane.INFORMATION_MESSAGE);
} else if (e.getSource() == refreshImage) {
try {
refreshImage();
} catch (Exception ex) {
JOptionPane.showMessageDialog(parent, new DebugPanel(ex,
parent.getSettings().getSupportURL()), "Exception", JOptionPane.ERROR_MESSAGE);
}
} else if (e.getSource() == settings) {
SettingsForm form = new SettingsForm(parent);
form.setLocationRelativeTo(parent);
form.setVisible(true);
} else if (e.getSource() == defManager) {
DefinitionManager form = new DefinitionManager(parent);
form.setLocationRelativeTo(parent);
form.setVisible(true);
} else if (e.getSource() == level1) {
parent.setUserLevel(1);
} else if (e.getSource() == level2) {
parent.setUserLevel(2);
} else if (e.getSource() == level3) {
parent.setUserLevel(3);
} else if (e.getSource() == level4) {
parent.setUserLevel(4);
} else if (e.getSource() == level5) {
parent.setUserLevel(5);
} else if (e.getSource() == editDefinition) {
new DefinitionEditor(parent);
}
}
public void refreshImage() throws Exception {
if (parent.getLastSelectedRom() != null) {
File file = parent.getLastSelectedRom().getFullFileName();
parent.closeImage();
parent.openImage(file);
}
}
public void openImageDialog() throws XMLParseException, Exception {
JFileChooser fc = new JFileChooser(parent.getSettings().getLastImageDir());
fc.setFileFilter(new ECUImageFilter());
if (fc.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
parent.openImage(fc.getSelectedFile());
parent.getSettings().setLastImageDir(fc.getCurrentDirectory());
}
}
public void closeImage() {
parent.closeImage();
}
public void closeAllImages() {
parent.closeAllImages();
}
public void saveImage(Rom input) throws XMLParseException, Exception {
if (parent.getLastSelectedRom() != null) {
JFileChooser fc = new JFileChooser(parent.getSettings().getLastImageDir());
fc.setFileFilter(new ECUImageFilter());
if (fc.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) {
boolean save = true;
if (fc.getSelectedFile().exists()) {
if (JOptionPane.showConfirmDialog(parent, fc.getSelectedFile().getName() + " already exists! Overwrite?") == JOptionPane.CANCEL_OPTION) {
save = false;
}
}
if (save) {
byte[] output = parent.getLastSelectedRom().saveFile();
FileOutputStream fos = null;
try {
fos = new FileOutputStream(fc.getSelectedFile());
fos.write(output);
}
finally {
if (fos != null) {
fos.close();
}
}
parent.getLastSelectedRom().setFullFileName(fc.getSelectedFile().getAbsoluteFile());
parent.setLastSelectedRom(parent.getLastSelectedRom());
}
}
}
}
}

View File

@ -0,0 +1,100 @@
package enginuity.swing;
import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JToolBar;
import javax.swing.border.LineBorder;
import enginuity.ECUEditor;
import javax.swing.JFileChooser;
public class ECUEditorToolBar extends JToolBar implements ActionListener {
private ECUEditor parent;
private JButton openImage = new JButton(new ImageIcon("./graphics/icon-open.png"));
private JButton saveImage = new JButton(new ImageIcon("./graphics/icon-save.png"));
private JButton refreshImage = new JButton(new ImageIcon("./graphics/icon-refresh.png"));
private JButton closeImage = new JButton(new ImageIcon("./graphics/icon-close.png"));
public ECUEditorToolBar(ECUEditor parent) {
super();
this.parent = parent;
this.setFloatable(false);
this.add(openImage);
this.add(saveImage);
this.add(closeImage);
this.add(refreshImage);
openImage.setMaximumSize(new Dimension(58,50));
openImage.setBorder(new LineBorder(new Color(150,150,150), 0));
saveImage.setMaximumSize(new Dimension(50,50));
saveImage.setBorder(new LineBorder(new Color(150,150,150), 0));
closeImage.setMaximumSize(new Dimension(50,50));
closeImage.setBorder(new LineBorder(new Color(150,150,150), 0));
refreshImage.setMaximumSize(new Dimension(50,50));
refreshImage.setBorder(new LineBorder(new Color(150,150,150), 0));
updateButtons();
openImage.addActionListener(this);
saveImage.addActionListener(this);
closeImage.addActionListener(this);
refreshImage.addActionListener(this);
}
public void updateButtons() {
String file = "";
try {
file = " " + parent.getLastSelectedRom().getFileName();
} catch (NullPointerException ex) { }
openImage.setToolTipText("Open Image");
saveImage.setToolTipText("Save" + file);
refreshImage.setToolTipText("Refresh" + file + " from saved copy");
closeImage.setToolTipText("Close" + file);
if (file.equals("")) {
saveImage.setEnabled(false);
refreshImage.setEnabled(false);
closeImage.setEnabled(false);
} else {
saveImage.setEnabled(true);
refreshImage.setEnabled(true);
closeImage.setEnabled(true);
}
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == openImage) {
try {
((ECUEditorMenuBar)parent.getJMenuBar()).openImageDialog();
} catch (Exception ex) {
JOptionPane.showMessageDialog(parent, new DebugPanel(ex,
parent.getSettings().getSupportURL()), "Exception", JOptionPane.ERROR_MESSAGE);
}
} else if (e.getSource() == saveImage) {
try {
((ECUEditorMenuBar)parent.getJMenuBar()).saveImage(parent.getLastSelectedRom());
} catch (Exception ex) {
JOptionPane.showMessageDialog(parent, new DebugPanel(ex,
parent.getSettings().getSupportURL()), "Exception", JOptionPane.ERROR_MESSAGE);
}
} else if (e.getSource() == closeImage) {
((ECUEditorMenuBar)parent.getJMenuBar()).closeImage();
} else if (e.getSource() == refreshImage) {
try {
((ECUEditorMenuBar)parent.getJMenuBar()).refreshImage();
} catch (Exception ex) {
JOptionPane.showMessageDialog(parent, new DebugPanel(ex,
parent.getSettings().getSupportURL()), "Exception", JOptionPane.ERROR_MESSAGE);
}
}
}
}

View File

@ -0,0 +1,89 @@
package enginuity.swing;
import java.io.File;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.swing.filechooser.FileFilter;
public class ECUImageFilter extends FileFilter {
private Hashtable<String, ECUImageFilter> filters = null;
private String description = null;
private String fullDescription = null;
private boolean useExtensionsInDescription = true;
public ECUImageFilter() {
this.filters = new Hashtable<String, ECUImageFilter>();
this.addExtension("bin");
this.addExtension("hex");
this.setDescription("ECU Image Files");
}
public boolean accept(File f) {
if (f != null) {
if (f.isDirectory()) {
return true;
}
String extension = getExtension(f);
if (extension != null && filters.get(getExtension(f)) != null) {
return true;
}
;
}
return false;
}
public String getExtension(File f) {
if (f != null) {
String filename = f.getName();
int i = filename.lastIndexOf('.');
if (i > 0 && i < filename.length() - 1) {
return filename.substring(i + 1).toLowerCase();
}
}
return null;
}
public void addExtension(String extension) {
filters.put(extension.toLowerCase(), this);
fullDescription = null;
}
public String getDescription() {
if (fullDescription == null) {
if (description == null || isExtensionListInDescription()) {
fullDescription = description == null ? "(" : description
+ " (";
// build the description from the extension list
Enumeration extensions = filters.keys();
if (extensions != null) {
fullDescription += "." + (String) extensions.nextElement();
while (extensions.hasMoreElements()) {
fullDescription += ", ."
+ (String) extensions.nextElement();
}
}
fullDescription += ")";
}
else {
fullDescription = description;
}
}
return fullDescription;
}
public void setDescription(String description) {
this.description = description;
fullDescription = null;
}
public void setExtensionListInDescription(boolean b) {
useExtensionsInDescription = b;
fullDescription = null;
}
public boolean isExtensionListInDescription() {
return useExtensionsInDescription;
}
}

View File

@ -0,0 +1,36 @@
package enginuity.swing;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
public class JProgressPane extends JPanel {
JLabel label = new JLabel();
JProgressBar progressBar = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100);
public JProgressPane() {
this.setPreferredSize(new Dimension(500, 18));
this.setLayout(new BorderLayout(1, 2));
label.setHorizontalAlignment(JLabel.CENTER);
label.setText(" Ready...");
label.setFont(new Font("Tahoma", Font.PLAIN, 11));
label.setHorizontalAlignment(JLabel.LEFT);
progressBar.setMinimumSize(new Dimension(200, 50));
this.add(progressBar, BorderLayout.WEST);
this.add(label, BorderLayout.CENTER);
}
public void update(String status, int percent) {
label.setText(" " + status);
progressBar.setValue(percent);
repaint();
this.update(this.getGraphics());
}
}

View File

@ -0,0 +1,68 @@
package enginuity.swing;
import enginuity.maps.Rom;
import enginuity.maps.Table;
import java.awt.Component;
import java.awt.Dimension;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
public class JTableChooser extends JOptionPane {
JPanel displayPanel = new JPanel();
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Open Images");
JTree displayTree = new JTree(rootNode);
public boolean showChooser(Vector<Rom> roms, Component parent, Table targetTable) {
for (int i = 0; i < roms.size(); i++) {
Rom rom = roms.get(i);
DefaultMutableTreeNode romNode = new DefaultMutableTreeNode(rom.getFileName());
rootNode.add(romNode);
for (int j = 0; j < rom.getTables().size(); j++) {
Table table = rom.getTables().get(j);
TableChooserTreeNode tableNode = new TableChooserTreeNode(table.getName(), table);
// categories
boolean categoryExists = false;
for (int k = 0; k < romNode.getChildCount(); k++) {
if (romNode.getChildAt(k).toString().equalsIgnoreCase(table.getCategory())) {
((DefaultMutableTreeNode)romNode.getChildAt(k)).add(tableNode);
categoryExists = true;
break;
}
}
if (!categoryExists) {
DefaultMutableTreeNode categoryNode = new DefaultMutableTreeNode(table.getCategory());
romNode.add(categoryNode);
categoryNode.add(tableNode);
}
}
}
displayPanel.setPreferredSize(new Dimension(350, 400));
displayPanel.setMinimumSize(new Dimension(350, 400));
displayTree.setPreferredSize(new Dimension(330, 400));
displayTree.setMinimumSize(new Dimension(330, 400));
displayTree.setRootVisible(true);
displayTree.updateUI();
displayPanel.add(new JScrollPane(displayTree));
Object[] values = { "Compare", "Cancel" };
if ((showOptionDialog(parent, displayPanel, "Select a Map", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, values, values[0]) == 0 &&
(displayTree.getLastSelectedPathComponent() instanceof TableChooserTreeNode))) {
((TableChooserTreeNode)displayTree.getLastSelectedPathComponent()).getTable().copyTable();
return true;
} else {
return false;
}
}
}

View File

@ -0,0 +1,217 @@
package enginuity.swing;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Point;
import java.beans.PropertyVetoException;
import javax.swing.DefaultDesktopManager;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.JViewport;
/**
* An extension of WDesktopPane that supports often used MDI functionality. This
* class also handles setting scroll bars for when windows move too far to the left or
* bottom, providing the MDIDesktopPane is in a ScrollPane.
*/
public class MDIDesktopPane extends JDesktopPane {
private static int FRAME_OFFSET=20;
private MDIDesktopManager manager;
public MDIDesktopPane() {
manager=new MDIDesktopManager(this);
setDesktopManager(manager);
setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
}
public void setBounds(int x, int y, int w, int h) {
super.setBounds(x,y,w,h);
checkDesktopSize();
}
public Component add(JInternalFrame frame) {
JInternalFrame[] array = getAllFrames();
Point p;
int w;
int h;
Component retval=super.add(frame);
checkDesktopSize();
if (array.length > 0) {
p = array[0].getLocation();
p.x = p.x + FRAME_OFFSET;
p.y = p.y + FRAME_OFFSET;
}
else {
p = new Point(0, 0);
}
frame.setLocation(p.x, p.y);
if (frame.isResizable()) {
w = getWidth() - (getWidth()/3);
h = getHeight() - (getHeight()/3);
if (w < frame.getMinimumSize().getWidth()) w = (int)frame.getMinimumSize().getWidth();
if (h < frame.getMinimumSize().getHeight()) h = (int)frame.getMinimumSize().getHeight();
frame.setSize(w, h);
}
moveToFront(frame);
frame.setVisible(true);
try {
frame.setSelected(true);
} catch (PropertyVetoException e) {
frame.toBack();
}
return retval;
}
public void remove(Component c) {
super.remove(c);
checkDesktopSize();
}
/**
* Cascade all internal frames
*/
public void cascadeFrames() {
int x = 0;
int y = 0;
JInternalFrame allFrames[] = getAllFrames();
manager.setNormalSize();
int frameHeight = (getBounds().height - 5) - allFrames.length * FRAME_OFFSET;
int frameWidth = (getBounds().width - 5) - allFrames.length * FRAME_OFFSET;
for (int i = allFrames.length - 1; i >= 0; i--) {
allFrames[i].setSize(frameWidth,frameHeight);
allFrames[i].setLocation(x,y);
x = x + FRAME_OFFSET;
y = y + FRAME_OFFSET;
}
}
/**
* Tile all internal frames
*/
public void tileFrames() {
java.awt.Component allFrames[] = getAllFrames();
manager.setNormalSize();
int frameHeight = getBounds().height/allFrames.length;
int y = 0;
for (int i = 0; i < allFrames.length; i++) {
allFrames[i].setSize(getBounds().width,frameHeight);
allFrames[i].setLocation(0,y);
y = y + frameHeight;
}
}
/**
* Sets all component size properties ( maximum, minimum, preferred)
* to the given dimension.
*/
public void setAllSize(Dimension d){
setMinimumSize(d);
setMaximumSize(d);
setPreferredSize(d);
}
/**
* Sets all component size properties ( maximum, minimum, preferred)
* to the given width and height.
*/
public void setAllSize(int width, int height){
setAllSize(new Dimension(width,height));
}
private void checkDesktopSize() {
if (getParent()!=null&&isVisible()) manager.resizeDesktop();
}
}
/**
* Private class used to replace the standard DesktopManager for JDesktopPane.
* Used to provide scrollbar functionality.
*/
class MDIDesktopManager extends DefaultDesktopManager {
private MDIDesktopPane desktop;
public MDIDesktopManager(MDIDesktopPane desktop) {
this.desktop = desktop;
}
public void endResizingFrame(JComponent f) {
super.endResizingFrame(f);
resizeDesktop();
}
public void endDraggingFrame(JComponent f) {
super.endDraggingFrame(f);
resizeDesktop();
}
public void setNormalSize() {
JScrollPane scrollPane=getScrollPane();
int x = 0;
int y = 0;
Insets scrollInsets = getScrollPaneInsets();
if (scrollPane != null) {
Dimension d = scrollPane.getVisibleRect().getSize();
if (scrollPane.getBorder() != null) {
d.setSize(d.getWidth() - scrollInsets.left - scrollInsets.right,
d.getHeight() - scrollInsets.top - scrollInsets.bottom);
}
d.setSize(d.getWidth() - 20, d.getHeight() - 20);
desktop.setAllSize(x,y);
scrollPane.invalidate();
scrollPane.validate();
}
}
private Insets getScrollPaneInsets() {
JScrollPane scrollPane=getScrollPane();
if (scrollPane==null) return new Insets(0,0,0,0);
else return getScrollPane().getBorder().getBorderInsets(scrollPane);
}
private JScrollPane getScrollPane() {
if (desktop.getParent() instanceof JViewport) {
JViewport viewPort = (JViewport)desktop.getParent();
if (viewPort.getParent() instanceof JScrollPane)
return (JScrollPane)viewPort.getParent();
}
return null;
}
protected void resizeDesktop() {
int x = 0;
int y = 0;
JScrollPane scrollPane = getScrollPane();
Insets scrollInsets = getScrollPaneInsets();
if (scrollPane != null) {
JInternalFrame allFrames[] = desktop.getAllFrames();
for (int i = 0; i < allFrames.length; i++) {
if (allFrames[i].getX()+allFrames[i].getWidth()>x) {
x = allFrames[i].getX() + allFrames[i].getWidth();
}
if (allFrames[i].getY()+allFrames[i].getHeight()>y) {
y = allFrames[i].getY() + allFrames[i].getHeight();
}
}
Dimension d=scrollPane.getVisibleRect().getSize();
if (scrollPane.getBorder() != null) {
d.setSize(d.getWidth() - scrollInsets.left - scrollInsets.right,
d.getHeight() - scrollInsets.top - scrollInsets.bottom);
}
if (x <= d.getWidth()) x = ((int)d.getWidth()) - 20;
if (y <= d.getHeight()) y = ((int)d.getHeight()) - 20;
desktop.setAllSize(x,y);
scrollPane.invalidate();
scrollPane.validate();
}
}
}

View File

@ -0,0 +1,130 @@
package enginuity.swing;
import enginuity.maps.Rom;
import enginuity.maps.Table;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;
public class RomCellRenderer implements TreeCellRenderer {
JLabel fileName;
JLabel carInfo;
DefaultTreeCellRenderer defaultRenderer = new DefaultTreeCellRenderer();
public RomCellRenderer() {
fileName = new JLabel(" ");
fileName.setFont(new Font("Tahoma", Font.BOLD, 11));
fileName.setHorizontalAlignment(JLabel.CENTER);
carInfo = new JLabel(" ");
carInfo.setFont(new Font("Tahoma", Font.PLAIN, 10));
carInfo.setHorizontalAlignment(JLabel.CENTER);
}
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected, boolean expanded, boolean leaf, int row,
boolean hasFocus) {
Component returnValue = null;
if (value != null && value instanceof RomTreeNode) {
Object userObject = ((DefaultMutableTreeNode)value).getUserObject();
if (userObject instanceof Rom) {
Rom rom = (Rom) userObject;
if (expanded) fileName.setText("- " + rom.getFileName());
else fileName.setText("+ " + rom.getFileName());
carInfo.setText(rom.getRomIDString() + ", " +
rom.getRomID().getCaseId() + "; " +
rom.getRomID().getYear() + " " +
rom.getRomID().getMake() + " " +
rom.getRomID().getModel() + " " +
rom.getRomID().getSubModel() + ", " +
rom.getRomID().getTransmission()
);
JPanel renderer = new JPanel(new GridLayout(2,1));
renderer.add(fileName);
renderer.add(carInfo);
if (selected) {
renderer.setBackground(new Color(220,220,255));
renderer.setBorder(BorderFactory.createLineBorder(new Color(0,0,225)));
} else {
renderer.setBorder(BorderFactory.createLineBorder(new Color(220,0,0)));
renderer.setBackground(new Color(255,210,210));
}
renderer.setPreferredSize(new Dimension(tree.getParent().getWidth(), 30));
renderer.setMaximumSize(new Dimension(tree.getParent().getWidth(), 30));
renderer.setEnabled(tree.isEnabled());
returnValue = renderer;
}
} else if (value != null && value instanceof TableTreeNode) {
Table table = (Table)((DefaultMutableTreeNode)value).getUserObject();
JPanel renderer = new JPanel(new GridLayout(1,1));
renderer.setBorder(BorderFactory.createLineBorder(Color.WHITE));
JLabel tableName = new JLabel("");
renderer.setBackground(Color.WHITE);
// display icon
if (table.getType() == Table.TABLE_1D) {
tableName = new JLabel(table.getName()+" ", new ImageIcon("./graphics/1d.gif"), JLabel.LEFT);
} else if (table.getType() == Table.TABLE_2D) {
tableName = new JLabel(table.getName()+" ", new ImageIcon("./graphics/2d.gif"), JLabel.LEFT);
} else if (table.getType() == Table.TABLE_3D) {
tableName = new JLabel(table.getName()+" ", new ImageIcon("./graphics/3d.gif"), JLabel.LEFT);
} else if (table.getType() == Table.TABLE_SWITCH) {
tableName = new JLabel(table.getName()+" ", new ImageIcon("./graphics/switch.gif"), JLabel.LEFT);
}
// set color
renderer.add(tableName);
tableName.setFont(new Font("Tahoma", Font.PLAIN, 11));
if (selected) {
renderer.setBackground(new Color(220,220,255));
renderer.setBorder(BorderFactory.createLineBorder(new Color(0,0,225)));
}
if (table.getUserLevel() == 5) {
tableName.setForeground(new Color(255,150,150));
tableName.setFont(new Font("Tahoma", Font.ITALIC, 11));
} else if (table.getUserLevel() > table.getRom().getContainer().getSettings().getUserLevel()) {
tableName.setForeground(new Color(185,185,185));
tableName.setFont(new Font("Tahoma", Font.ITALIC, 11));
}
returnValue = renderer;
}
if (returnValue == null) {
returnValue = defaultRenderer.getTreeCellRendererComponent(tree,
value, selected, expanded, leaf, row, hasFocus);
}
return returnValue;
}
}

View File

@ -0,0 +1,307 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="lblFilename" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="fileName" min="-2" pref="302" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblECURevision" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblEcuVersion" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblFilesize" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="fileSize" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="ecuVersion" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="xmlID" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblYear" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblModel" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblSubmodel" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblTransmission" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblMarket" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblMake" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="7" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="make" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="market" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="year" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="transmission" min="-2" max="-2" attributes="0"/>
<Component id="submodel" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Component id="model" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace min="-2" pref="32" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblInternalId" min="-2" max="-2" attributes="0"/>
<Component id="lblStorageAddress" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="53" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="internalID" min="-2" max="-2" attributes="0"/>
<Component id="storageAddress" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="36" max="-2" attributes="0"/>
</Group>
<Component id="lblTables" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jScrollPane1" alignment="0" min="-2" pref="226" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="-2" pref="21" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" alignment="0" groupAlignment="3" attributes="0">
<Component id="lblFilename" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="fileName" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="40" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblECURevision" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="xmlID" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblInternalId" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="internalID" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="ecuVersion" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblEcuVersion" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="storageAddress" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblStorageAddress" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblFilesize" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="fileSize" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="lblTables" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblMake" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="make" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblMarket" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="market" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblYear" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="year" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblModel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="model" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblSubmodel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="submodel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblTransmission" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="transmission" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Component id="jScrollPane1" min="0" pref="0" max="32767" attributes="1"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblFilename">
<Properties>
<Property name="text" type="java.lang.String" value="Filename:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="fileName">
<Properties>
<Property name="text" type="java.lang.String" value="Filename"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblECURevision">
<Properties>
<Property name="text" type="java.lang.String" value="ECU Revision:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="xmlID">
<Properties>
<Property name="text" type="java.lang.String" value="XMLID"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblFilesize">
<Properties>
<Property name="text" type="java.lang.String" value="Filesize:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="fileSize">
<Properties>
<Property name="text" type="java.lang.String" value="999kb"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblEcuVersion">
<Properties>
<Property name="text" type="java.lang.String" value="ECU Version:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="ecuVersion">
<Properties>
<Property name="text" type="java.lang.String" value="ECUVER"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblInternalId">
<Properties>
<Property name="text" type="java.lang.String" value="Internal ID:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="internalID">
<Properties>
<Property name="text" type="java.lang.String" value="INTERNAL"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblStorageAddress">
<Properties>
<Property name="text" type="java.lang.String" value="ID Storage Address:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="storageAddress">
<Properties>
<Property name="text" type="java.lang.String" value="0x00"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblMake">
<Properties>
<Property name="text" type="java.lang.String" value="Make:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblMarket">
<Properties>
<Property name="text" type="java.lang.String" value="Market:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblTransmission">
<Properties>
<Property name="text" type="java.lang.String" value="Transmission:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblModel">
<Properties>
<Property name="text" type="java.lang.String" value="Model:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblSubmodel">
<Properties>
<Property name="text" type="java.lang.String" value="Submodel:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblYear">
<Properties>
<Property name="text" type="java.lang.String" value="Year:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="make">
<Properties>
<Property name="text" type="java.lang.String" value="Make"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="market">
<Properties>
<Property name="text" type="java.lang.String" value="Market"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="year">
<Properties>
<Property name="text" type="java.lang.String" value="Year"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="model">
<Properties>
<Property name="text" type="java.lang.String" value="Model"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="submodel">
<Properties>
<Property name="text" type="java.lang.String" value="Submodel"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="transmission">
<Properties>
<Property name="text" type="java.lang.String" value="Transmission"/>
</Properties>
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JList" name="tableList">
<Properties>
<Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
<StringArray count="5">
<StringItem index="0" value="Item 1"/>
<StringItem index="1" value="Item 2"/>
<StringItem index="2" value="Item 3"/>
<StringItem index="3" value="Item 4"/>
<StringItem index="4" value="Item 5"/>
</StringArray>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="lblTables">
<Properties>
<Property name="text" type="java.lang.String" value="Tables:"/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,264 @@
package enginuity.swing;
import enginuity.maps.Rom;
public class RomPropertyPanel extends javax.swing.JPanel {
Rom rom = new Rom();
public RomPropertyPanel(Rom rom) {
initComponents();
// populate fields
fileName.setText(rom.getFileName());
xmlID.setText(rom.getRomID().getXmlid());
ecuVersion.setText(rom.getRomID().getCaseId());
fileSize.setText((rom.getRealFileSize() / 1024) + "kb");
internalID.setText(rom.getRomID().getInternalIdString());
storageAddress.setText("0x" + Integer.toHexString(rom.getRomID().getInternalIdAddress()));
make.setText(rom.getRomID().getMake());
market.setText(rom.getRomID().getMarket());
year.setText(rom.getRomID().getYear()+"");
model.setText(rom.getRomID().getModel());
submodel.setText(rom.getRomID().getSubModel());
transmission.setText(rom.getRomID().getTransmission());
tableList.setListData(rom.getTables());
}
//prevent bad constructor
private RomPropertyPanel() { }
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
lblFilename = new javax.swing.JLabel();
fileName = new javax.swing.JLabel();
lblECURevision = new javax.swing.JLabel();
xmlID = new javax.swing.JLabel();
lblFilesize = new javax.swing.JLabel();
fileSize = new javax.swing.JLabel();
lblEcuVersion = new javax.swing.JLabel();
ecuVersion = new javax.swing.JLabel();
lblInternalId = new javax.swing.JLabel();
internalID = new javax.swing.JLabel();
lblStorageAddress = new javax.swing.JLabel();
storageAddress = new javax.swing.JLabel();
lblMake = new javax.swing.JLabel();
lblMarket = new javax.swing.JLabel();
lblTransmission = new javax.swing.JLabel();
lblModel = new javax.swing.JLabel();
lblSubmodel = new javax.swing.JLabel();
lblYear = new javax.swing.JLabel();
make = new javax.swing.JLabel();
market = new javax.swing.JLabel();
year = new javax.swing.JLabel();
model = new javax.swing.JLabel();
submodel = new javax.swing.JLabel();
transmission = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
tableList = new javax.swing.JList();
lblTables = new javax.swing.JLabel();
lblFilename.setText("Filename:");
fileName.setText("Filename");
lblECURevision.setText("ECU Revision:");
xmlID.setText("XMLID");
lblFilesize.setText("Filesize:");
fileSize.setText("999kb");
lblEcuVersion.setText("ECU Version:");
ecuVersion.setText("ECUVER");
lblInternalId.setText("Internal ID:");
internalID.setText("INTERNAL");
lblStorageAddress.setText("ID Storage Address:");
storageAddress.setText("0x00");
lblMake.setText("Make:");
lblMarket.setText("Market:");
lblTransmission.setText("Transmission:");
lblModel.setText("Model:");
lblSubmodel.setText("Submodel:");
lblYear.setText("Year:");
make.setText("Make");
market.setText("Market");
year.setText("Year");
model.setText("Model");
submodel.setText("Submodel");
transmission.setText("Transmission");
tableList.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
jScrollPane1.setViewportView(tableList);
lblTables.setText("Tables:");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(lblFilename)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(fileName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 302, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(lblECURevision)
.add(lblEcuVersion)
.add(lblFilesize))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(fileSize)
.add(ecuVersion)
.add(xmlID)))
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(lblYear)
.add(lblModel)
.add(lblSubmodel)
.add(lblTransmission)
.add(lblMarket)
.add(lblMake))
.add(7, 7, 7)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(make)
.add(market)
.add(year)
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(transmission)
.add(submodel)))
.add(model))))
.add(32, 32, 32)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(lblInternalId)
.add(lblStorageAddress))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 53, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(internalID)
.add(storageAddress))
.add(36, 36, 36))
.add(lblTables)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(21, 21, 21)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblFilename)
.add(fileName))
.add(layout.createSequentialGroup()
.add(40, 40, 40)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblECURevision)
.add(xmlID)
.add(lblInternalId)
.add(internalID))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(ecuVersion)
.add(lblEcuVersion)
.add(storageAddress)
.add(lblStorageAddress))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblFilesize)
.add(fileSize))))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(lblTables)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblMake)
.add(make))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblMarket)
.add(market))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblYear)
.add(year))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblModel)
.add(model))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblSubmodel)
.add(submodel))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblTransmission)
.add(transmission)))
.add(jScrollPane1, 0, 0, Short.MAX_VALUE))
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel ecuVersion;
private javax.swing.JLabel fileName;
private javax.swing.JLabel fileSize;
private javax.swing.JLabel internalID;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lblECURevision;
private javax.swing.JLabel lblEcuVersion;
private javax.swing.JLabel lblFilename;
private javax.swing.JLabel lblFilesize;
private javax.swing.JLabel lblInternalId;
private javax.swing.JLabel lblMake;
private javax.swing.JLabel lblMarket;
private javax.swing.JLabel lblModel;
private javax.swing.JLabel lblStorageAddress;
private javax.swing.JLabel lblSubmodel;
private javax.swing.JLabel lblTables;
private javax.swing.JLabel lblTransmission;
private javax.swing.JLabel lblYear;
private javax.swing.JLabel make;
private javax.swing.JLabel market;
private javax.swing.JLabel model;
private javax.swing.JLabel storageAddress;
private javax.swing.JLabel submodel;
private javax.swing.JList tableList;
private javax.swing.JLabel transmission;
private javax.swing.JLabel xmlID;
private javax.swing.JLabel year;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,74 @@
package enginuity.swing;
import enginuity.ECUEditor;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Enumeration;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
public class RomTree extends JTree implements MouseListener {
private ECUEditor container;
public RomTree (DefaultMutableTreeNode input) {
super(input);
setRootVisible(false);
setRowHeight(0);
addMouseListener(this);
setCellRenderer(new RomCellRenderer());
setFont(new Font("Tahoma", Font.PLAIN, 11));
}
public ECUEditor getContainer() {
return container;
}
public void setContainer(ECUEditor container) {
this.container = container;
}
public void mouseClicked(MouseEvent e) {
try {
Object selectedRow = getPathForLocation(e.getX(), e.getY()).getLastPathComponent();
if (e.getClickCount() >= container.getSettings().getTableClickCount() &&
selectedRow instanceof TableTreeNode) {
TableTreeNode node = (TableTreeNode)selectedRow;
if (!(node.getTable().getUserLevel() > container.getSettings().getUserLevel())) {
container.displayTable(node.getFrame());
}
}
if (selectedRow instanceof TableTreeNode) {
TableTreeNode node = (TableTreeNode)getLastSelectedPathComponent();
container.setLastSelectedRom(node.getTable().getRom());
} else if (selectedRow instanceof CategoryTreeNode) {
CategoryTreeNode node = (CategoryTreeNode)getLastSelectedPathComponent();
container.setLastSelectedRom(node.getRom());
} else if (selectedRow instanceof RomTreeNode) {
RomTreeNode node = (RomTreeNode)getLastSelectedPathComponent();
container.setLastSelectedRom(node.getRom());
}
} catch (NullPointerException ex) { }
}
public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void removeDescendantToggledPaths(Enumeration<TreePath> toRemove) {
super.removeDescendantToggledPaths(toRemove);
}
}

View File

@ -0,0 +1,98 @@
package enginuity.swing;
import java.util.Vector;
import javax.swing.tree.DefaultMutableTreeNode;
import enginuity.maps.Rom;
import enginuity.maps.Table;
import java.util.Enumeration;
public class RomTreeNode extends DefaultMutableTreeNode {
private Rom rom = new Rom();
public RomTreeNode(Rom rom, int userLevel, boolean isDisplayHighTables) {
setRom(rom);
refresh(userLevel, isDisplayHighTables);
updateFileName();
}
public void refresh(int userLevel, boolean isDisplayHighTables) {
removeAllChildren();
Vector<Table> tables = rom.getTables();
for (int i = 0; i < tables.size(); i++) {
Table table = tables.get(i);
add(table);
if (isDisplayHighTables || userLevel >= table.getUserLevel()) {
boolean categoryExists = false;
for (int j = 0; j < getChildCount(); j++) {
if (getChildAt(j).toString().equals(table.getCategory())) {
// add to appropriate category
TableTreeNode tableNode = new TableTreeNode(table);
getChildAt(j).add(tableNode);
categoryExists = true;
break;
}
}
if (!categoryExists) { // if category does not already exist, create it
add(new CategoryTreeNode(table.getCategory(), table.getRom()));
TableTreeNode tableNode = new TableTreeNode(table);
getLastChild().add(tableNode);
}
}
}
}
public void removeAllChildren() {
// close all table windows
// loop through categories first
for (int i = 0; i < getChildCount(); i++) {
DefaultMutableTreeNode category = getChildAt(i);
// loop through tables in each category
for (Enumeration j = category.children(); j.hasMoreElements();) {
((TableTreeNode)j.nextElement()).getFrame().dispose();
}
}
// removeAllChildren
super.removeAllChildren();
}
public void updateFileName() {
setUserObject(rom);
}
public void add(Table table) {
TableFrame frame = new TableFrame(table);
table.setFrame(frame);
}
public DefaultMutableTreeNode getChildAt(int i) {
return (DefaultMutableTreeNode)super.getChildAt(i);
}
public DefaultMutableTreeNode getLastChild() {
return (DefaultMutableTreeNode)super.getLastChild();
}
public Rom getRom() {
return rom;
}
public void setRom(Rom rom) {
this.rom = rom;
}
}

View File

@ -0,0 +1,16 @@
package enginuity.swing;
import javax.swing.tree.DefaultMutableTreeNode;
public class RomTreeRootNode extends DefaultMutableTreeNode {
public RomTreeRootNode(String name) {
super(name);
}
public void setUserLevel(int userLevel, boolean isDisplayHighTables) {
for (int i = 0; i < getChildCount(); i++) {
((RomTreeNode)getChildAt(i)).refresh(userLevel, isDisplayHighTables);
}
}
}

View File

@ -0,0 +1,545 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
<Property name="title" type="java.lang.String" value="Enginuity Settings"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/>
</Property>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="11" style="0"/>
</Property>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel1" min="0" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="reset" min="-2" max="-2" attributes="1"/>
<EmptySpace pref="34" max="32767" attributes="0"/>
<Component id="btnApply" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnOk" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="calcConflictWarning" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="obsoleteWarning" alignment="0" min="-2" max="-2" attributes="1"/>
<Group type="102" alignment="0" attributes="0">
<Component id="tableClickCount" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="debug" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="tableClickCount" alignment="3" min="-2" pref="18" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="obsoleteWarning" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="calcConflictWarning" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="debug" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="34" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnApply" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="reset" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnOk" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JCheckBox" name="obsoleteWarning">
<Properties>
<Property name="text" type="java.lang.String" value="Warn me when opening out of date ECU image revision"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="0" right="0" top="0"/>
</Border>
</Property>
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
<Insets value="[0, 0, 0, 0]"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="calcConflictWarning">
<Properties>
<Property name="text" type="java.lang.String" value="Warn me when real and byte value calculations conflict"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="0" right="0" top="0"/>
</Border>
</Property>
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
<Insets value="[0, 0, 0, 0]"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="debug">
<Properties>
<Property name="text" type="java.lang.String" value="Debug mode"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="0" right="0" top="0"/>
</Border>
</Property>
<Property name="enabled" type="boolean" value="false"/>
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
<Insets value="[0, 0, 0, 0]"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnCancel">
<Properties>
<Property name="mnemonic" type="int" value="67"/>
<Property name="text" type="java.lang.String" value="Cancel"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnOk">
<Properties>
<Property name="mnemonic" type="int" value="79"/>
<Property name="text" type="java.lang.String" value="OK"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnApply">
<Properties>
<Property name="mnemonic" type="int" value="65"/>
<Property name="text" type="java.lang.String" value="Apply"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="reset">
<Properties>
<Property name="text" type="java.lang.String" value="Restore Defaults"/>
</Properties>
</Component>
<Container class="javax.swing.JPanel" name="jPanel1">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
<TitledBorder title="Table Display"/>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel2" alignment="0" max="32767" attributes="0"/>
<Component id="jPanel3" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Group type="103" alignment="1" groupAlignment="0" attributes="0">
<Component id="saveDebugTables" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="displayHighTables" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="valueLimitWarning" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblCellHeight" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblFont" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="btnChooseFont" alignment="0" min="-2" max="-2" attributes="1"/>
<Group type="102" alignment="0" attributes="0">
<Component id="cellHeight" min="-2" pref="50" max="-2" attributes="0"/>
<EmptySpace pref="18" max="32767" attributes="0"/>
<Component id="lblCellWidth" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cellWidth" min="-2" pref="50" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</Group>
<EmptySpace pref="71" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jPanel2" min="-2" max="-2" attributes="1"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel3" min="-2" max="-2" attributes="1"/>
<EmptySpace min="-2" pref="19" max="-2" attributes="0"/>
<Component id="saveDebugTables" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="displayHighTables" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="valueLimitWarning" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="16" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblCellWidth" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cellWidth" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblCellHeight" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cellHeight" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblFont" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnChooseFont" alignment="3" min="-2" pref="18" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel2">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
<TitledBorder title="Background"/>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Component id="lblWarning" min="-2" max="-2" attributes="0"/>
<Group type="103" alignment="1" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="4" max="-2" attributes="0"/>
<Component id="lblMin" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="lblMax" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="maxColor" min="-2" pref="50" max="-2" attributes="0"/>
<EmptySpace pref="22" max="32767" attributes="0"/>
<Component id="lblHighlight" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="highlightColor" min="-2" pref="50" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="minColor" min="-2" pref="50" max="-2" attributes="0"/>
<EmptySpace pref="55" max="32767" attributes="0"/>
<Component id="lblAxis" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="axisColor" min="-2" pref="50" max="-2" attributes="0"/>
</Group>
<Component id="warningColor" alignment="0" min="-2" pref="50" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblMax" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="maxColor" alignment="3" min="-2" pref="15" max="-2" attributes="0"/>
<Component id="highlightColor" alignment="3" min="-2" pref="15" max="-2" attributes="0"/>
<Component id="lblHighlight" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblMin" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="minColor" alignment="3" min="-2" pref="15" max="-2" attributes="0"/>
<Component id="axisColor" alignment="3" min="-2" pref="15" max="-2" attributes="0"/>
<Component id="lblAxis" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="warningColor" alignment="3" min="-2" pref="15" max="-2" attributes="0"/>
<Component id="lblWarning" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblAxis">
<Properties>
<Property name="text" type="java.lang.String" value="Axis Cell:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblHighlight">
<Properties>
<Property name="text" type="java.lang.String" value="Highlighted Cell:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblMin">
<Properties>
<Property name="text" type="java.lang.String" value="Minimum Value:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblMax">
<Properties>
<Property name="text" type="java.lang.String" value="Maximum Value:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="maxColor">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="ff" type="rgb"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
<LineBorder/>
</Border>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="minColor">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="ff" type="rgb"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
<LineBorder/>
</Border>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="highlightColor">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="ff" type="rgb"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
<LineBorder/>
</Border>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="axisColor">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="ff" type="rgb"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
<LineBorder/>
</Border>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="warningColor">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="ff" type="rgb"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
<LineBorder/>
</Border>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblWarning">
<Properties>
<Property name="text" type="java.lang.String" value="Warning:"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel3">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
<TitledBorder title="Cell Borders"/>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="lblIncrease" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="increaseColor" min="-2" pref="50" max="-2" attributes="0"/>
<EmptySpace pref="59" max="32767" attributes="0"/>
<Component id="lblDecrease" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="decreaseColor" min="-2" pref="50" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="decreaseColor" alignment="3" min="-2" pref="15" max="-2" attributes="0"/>
<Component id="lblDecrease" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblIncrease" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="increaseColor" alignment="3" min="-2" pref="15" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblIncrease">
<Properties>
<Property name="text" type="java.lang.String" value="Increased:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="increaseColor">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="ff" type="rgb"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
<LineBorder/>
</Border>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="decreaseColor">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="ff" type="rgb"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
<LineBorder/>
</Border>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblDecrease">
<Properties>
<Property name="text" type="java.lang.String" value="Decreased:"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="lblCellHeight">
<Properties>
<Property name="text" type="java.lang.String" value="Cell Height:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="cellHeight">
</Component>
<Component class="javax.swing.JTextField" name="cellWidth">
</Component>
<Component class="javax.swing.JLabel" name="lblCellWidth">
<Properties>
<Property name="text" type="java.lang.String" value="Cell Width:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblFont">
<Properties>
<Property name="text" type="java.lang.String" value="Font:"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnChooseFont">
<Properties>
<Property name="text" type="java.lang.String" value="Choose"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="saveDebugTables">
<Properties>
<Property name="text" type="java.lang.String" value="Save changes made on tables in debug mode"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="0" right="0" top="0"/>
</Border>
</Property>
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
<Insets value="[0, 0, 0, 0]"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="displayHighTables">
<Properties>
<Property name="text" type="java.lang.String" value="List tables that are above my userlevel"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="0" right="0" top="0"/>
</Border>
</Property>
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
<Insets value="[0, 0, 0, 0]"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="valueLimitWarning">
<Properties>
<Property name="text" type="java.lang.String" value="Warn when values exceed limits"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="0" right="0" top="0"/>
</Border>
</Property>
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
<Insets value="[0, 0, 0, 0]"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="click to open tables"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="tableClickCount">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="2">
<StringItem index="0" value="Single"/>
<StringItem index="1" value="Double"/>
</StringArray>
</Property>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,553 @@
package enginuity.swing;
import ZoeloeSoft.projects.JFontChooser.JFontChooser;
import enginuity.ECUEditor;
import enginuity.Settings;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import javax.swing.JColorChooser;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
public class SettingsForm extends JFrame implements MouseListener {
Settings settings;
ECUEditor parent;
public SettingsForm(ECUEditor parent) {
this.parent = parent;
settings = parent.getSettings();
initComponents();
initSettings();
maxColor.addMouseListener(this);
minColor.addMouseListener(this);
highlightColor.addMouseListener(this);
axisColor.addMouseListener(this);
increaseColor.addMouseListener(this);
decreaseColor.addMouseListener(this);
warningColor.addMouseListener(this);
btnOk.addMouseListener(this);
btnApply.addMouseListener(this);
btnCancel.addMouseListener(this);
btnChooseFont.addMouseListener(this);
reset.addMouseListener(this);
tableClickCount.setBackground(Color.WHITE);
}
private void initSettings() {
obsoleteWarning.setSelected(settings.isObsoleteWarning());
calcConflictWarning.setSelected(settings.isCalcConflictWarning());
displayHighTables.setSelected(settings.isDisplayHighTables());
saveDebugTables.setSelected(settings.isSaveDebugTables());
debug.setSelected(settings.isDebug());
maxColor.setBackground(settings.getMaxColor());
minColor.setBackground(settings.getMinColor());
highlightColor.setBackground(settings.getHighlightColor());
axisColor.setBackground(settings.getAxisColor());
increaseColor.setBackground(settings.getIncreaseBorder());
decreaseColor.setBackground(settings.getDecreaseBorder());
cellWidth.setText(((int)settings.getCellSize().getWidth())+"");
cellHeight.setText(((int)settings.getCellSize().getHeight())+"");
btnChooseFont.setFont(settings.getTableFont());
btnChooseFont.setText(settings.getTableFont().getFontName());
if (settings.getTableClickCount() == 1) { // single click opens table
tableClickCount.setSelectedIndex(0);
} else { // double click opens table
tableClickCount.setSelectedIndex(1);
}
valueLimitWarning.setSelected(settings.isValueLimitWarning());
warningColor.setBackground(settings.getWarningColor());
}
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
obsoleteWarning = new javax.swing.JCheckBox();
calcConflictWarning = new javax.swing.JCheckBox();
debug = new javax.swing.JCheckBox();
btnCancel = new javax.swing.JButton();
btnOk = new javax.swing.JButton();
btnApply = new javax.swing.JButton();
reset = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
lblAxis = new javax.swing.JLabel();
lblHighlight = new javax.swing.JLabel();
lblMin = new javax.swing.JLabel();
lblMax = new javax.swing.JLabel();
maxColor = new javax.swing.JLabel();
minColor = new javax.swing.JLabel();
highlightColor = new javax.swing.JLabel();
axisColor = new javax.swing.JLabel();
warningColor = new javax.swing.JLabel();
lblWarning = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
lblIncrease = new javax.swing.JLabel();
increaseColor = new javax.swing.JLabel();
decreaseColor = new javax.swing.JLabel();
lblDecrease = new javax.swing.JLabel();
lblCellHeight = new javax.swing.JLabel();
cellHeight = new javax.swing.JTextField();
cellWidth = new javax.swing.JTextField();
lblCellWidth = new javax.swing.JLabel();
lblFont = new javax.swing.JLabel();
btnChooseFont = new javax.swing.JButton();
saveDebugTables = new javax.swing.JCheckBox();
displayHighTables = new javax.swing.JCheckBox();
valueLimitWarning = new javax.swing.JCheckBox();
jLabel1 = new javax.swing.JLabel();
tableClickCount = new javax.swing.JComboBox();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Enginuity Settings");
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
setFont(new java.awt.Font("Tahoma", 0, 11));
obsoleteWarning.setText("Warn me when opening out of date ECU image revision");
obsoleteWarning.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
obsoleteWarning.setMargin(new java.awt.Insets(0, 0, 0, 0));
calcConflictWarning.setText("Warn me when real and byte value calculations conflict");
calcConflictWarning.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
calcConflictWarning.setMargin(new java.awt.Insets(0, 0, 0, 0));
debug.setText("Debug mode");
debug.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
debug.setEnabled(false);
debug.setMargin(new java.awt.Insets(0, 0, 0, 0));
btnCancel.setMnemonic('C');
btnCancel.setText("Cancel");
btnOk.setMnemonic('O');
btnOk.setText("OK");
btnApply.setMnemonic('A');
btnApply.setText("Apply");
reset.setText("Restore Defaults");
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Table Display"));
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Background"));
lblAxis.setText("Axis Cell:");
lblHighlight.setText("Highlighted Cell:");
lblMin.setText("Minimum Value:");
lblMax.setText("Maximum Value:");
maxColor.setBackground(new java.awt.Color(255, 0, 0));
maxColor.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
maxColor.setOpaque(true);
minColor.setBackground(new java.awt.Color(255, 0, 0));
minColor.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
minColor.setOpaque(true);
highlightColor.setBackground(new java.awt.Color(255, 0, 0));
highlightColor.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
highlightColor.setOpaque(true);
axisColor.setBackground(new java.awt.Color(255, 0, 0));
axisColor.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
axisColor.setOpaque(true);
warningColor.setBackground(new java.awt.Color(255, 0, 0));
warningColor.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
warningColor.setOpaque(true);
lblWarning.setText("Warning:");
org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(lblWarning)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.add(4, 4, 4)
.add(lblMin))
.add(lblMax)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.add(maxColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 22, Short.MAX_VALUE)
.add(lblHighlight)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(highlightColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(jPanel2Layout.createSequentialGroup()
.add(minColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 55, Short.MAX_VALUE)
.add(lblAxis)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(axisColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(warningColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblMax)
.add(maxColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(highlightColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(lblHighlight))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblMin)
.add(minColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(axisColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(lblAxis))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(warningColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(lblWarning)))
);
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Cell Borders"));
lblIncrease.setText("Increased:");
increaseColor.setBackground(new java.awt.Color(255, 0, 0));
increaseColor.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
increaseColor.setOpaque(true);
decreaseColor.setBackground(new java.awt.Color(255, 0, 0));
decreaseColor.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
decreaseColor.setOpaque(true);
lblDecrease.setText("Decreased:");
org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3Layout.createSequentialGroup()
.addContainerGap()
.add(lblIncrease)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(increaseColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 59, Short.MAX_VALUE)
.add(lblDecrease)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(decreaseColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(decreaseColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(lblDecrease)
.add(lblIncrease)
.add(increaseColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
);
lblCellHeight.setText("Cell Height:");
lblCellWidth.setText("Cell Width:");
lblFont.setText("Font:");
btnChooseFont.setText("Choose");
saveDebugTables.setText("Save changes made on tables in debug mode");
saveDebugTables.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
saveDebugTables.setMargin(new java.awt.Insets(0, 0, 0, 0));
displayHighTables.setText("List tables that are above my userlevel");
displayHighTables.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
displayHighTables.setMargin(new java.awt.Insets(0, 0, 0, 0));
valueLimitWarning.setText("Warn when values exceed limits");
valueLimitWarning.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
valueLimitWarning.setMargin(new java.awt.Insets(0, 0, 0, 0));
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(saveDebugTables)
.add(displayHighTables)
.add(valueLimitWarning))
.add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(lblCellHeight)
.add(lblFont))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(btnChooseFont)
.add(jPanel1Layout.createSequentialGroup()
.add(cellHeight, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 18, Short.MAX_VALUE)
.add(lblCellWidth)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(cellWidth, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(71, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(19, 19, 19)
.add(saveDebugTables)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(displayHighTables)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(valueLimitWarning)
.add(16, 16, 16)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblCellWidth)
.add(cellWidth, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(lblCellHeight)
.add(cellHeight, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblFont)
.add(btnChooseFont, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
);
jLabel1.setText("click to open tables");
tableClickCount.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Single", "Double" }));
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.addContainerGap()
.add(reset)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 34, Short.MAX_VALUE)
.add(btnApply)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(btnOk)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(btnCancel))
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, calcConflictWarning)
.add(org.jdesktop.layout.GroupLayout.LEADING, obsoleteWarning)
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.add(tableClickCount, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel1))
.add(org.jdesktop.layout.GroupLayout.LEADING, debug))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(tableClickCount, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(obsoleteWarning)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(calcConflictWarning)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(debug)
.add(17, 17, 17)
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 34, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(btnCancel)
.add(btnApply)
.add(reset)
.add(btnOk))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
public void mouseClicked(MouseEvent e) {
if (e.getSource() == maxColor) {
Color color = JColorChooser.showDialog(this.getContentPane(),
"Background Color", settings.getMaxColor());
if (color != null) {
maxColor.setBackground(color);
}
}
else if (e.getSource() == minColor) {
Color color = JColorChooser.showDialog(this.getContentPane(),
"Background Color", settings.getMinColor());
if (color != null) {
minColor.setBackground(color);
}
}
else if (e.getSource() == highlightColor) {
Color color = JColorChooser.showDialog(this.getContentPane(),
"Background Color", settings.getHighlightColor());
if (color != null) {
highlightColor.setBackground(color);
}
}
else if (e.getSource() == axisColor) {
Color color = JColorChooser.showDialog(this.getContentPane(),
"Background Color", settings.getAxisColor());
if (color != null) {
axisColor.setBackground(color);
}
}
else if (e.getSource() == increaseColor) {
Color color = JColorChooser.showDialog(this.getContentPane(),
"Background Color", settings.getIncreaseBorder());
if (color != null) {
increaseColor.setBackground(color);
}
}
else if (e.getSource() == decreaseColor) {
Color color = JColorChooser.showDialog(this.getContentPane(),
"Background Color", settings.getDecreaseBorder());
if (color != null) {
decreaseColor.setBackground(color);
}
}
else if (e.getSource() == warningColor) {
Color color = JColorChooser.showDialog(this.getContentPane(),
"Warning Color", settings.getWarningColor());
if (color != null) {
warningColor.setBackground(color);
}
}
else if (e.getSource() == btnApply) {
applySettings();
}
else if (e.getSource() == btnOk) {
applySettings();
this.dispose();
}
else if (e.getSource() == btnCancel) {
this.dispose();
}
else if (e.getSource() == btnChooseFont) {
JFontChooser fc = new JFontChooser(this);
fc.setLocationRelativeTo(this);
if (fc.showDialog(settings.getTableFont()) == JFontChooser.OK_OPTION) {
btnChooseFont.setFont(fc.getFont());
btnChooseFont.setText(fc.getFont().getFontName());
}
}
else if (e.getSource() == reset) {
settings = new Settings();
initSettings();
}
}
public void applySettings() {
try {
Integer.parseInt(cellHeight.getText());
} catch (NumberFormatException ex) {
// number formatted imporperly, reset
cellHeight.setText((int)(settings.getCellSize().getHeight())+"");
}
try {
Integer.parseInt(cellWidth.getText());
} catch (NumberFormatException ex) {
// number formatted imporperly, reset
cellWidth.setText((int)(settings.getCellSize().getWidth())+"");
}
settings.setObsoleteWarning(obsoleteWarning.isSelected());
settings.setCalcConflictWarning(calcConflictWarning.isSelected());
settings.setDisplayHighTables(displayHighTables.isSelected());
settings.setSaveDebugTables(saveDebugTables.isSelected());
settings.setDebug(debug.isSelected());
settings.setMaxColor(maxColor.getBackground());
settings.setMinColor(minColor.getBackground());
settings.setHighlightColor(highlightColor.getBackground());
settings.setAxisColor(axisColor.getBackground());
settings.setIncreaseBorder(increaseColor.getBackground());
settings.setDecreaseBorder(decreaseColor.getBackground());
settings.setCellSize(new Dimension(Integer.parseInt(cellWidth.getText()),
Integer.parseInt(cellHeight.getText())));
settings.setTableFont(btnChooseFont.getFont());
if (tableClickCount.getSelectedIndex() == 0) { // single click opens table
settings.setTableClickCount(1);
} else { // double click opens table
settings.setTableClickCount(2);
}
settings.setValueLimitWarning(valueLimitWarning.isSelected());
settings.setWarningColor(warningColor.getBackground());
parent.setSettings(settings);
}
public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel axisColor;
private javax.swing.JButton btnApply;
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnChooseFont;
private javax.swing.JButton btnOk;
private javax.swing.JCheckBox calcConflictWarning;
private javax.swing.JTextField cellHeight;
private javax.swing.JTextField cellWidth;
private javax.swing.JCheckBox debug;
private javax.swing.JLabel decreaseColor;
private javax.swing.JCheckBox displayHighTables;
private javax.swing.JLabel highlightColor;
private javax.swing.JLabel increaseColor;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JLabel lblAxis;
private javax.swing.JLabel lblCellHeight;
private javax.swing.JLabel lblCellWidth;
private javax.swing.JLabel lblDecrease;
private javax.swing.JLabel lblFont;
private javax.swing.JLabel lblHighlight;
private javax.swing.JLabel lblIncrease;
private javax.swing.JLabel lblMax;
private javax.swing.JLabel lblMin;
private javax.swing.JLabel lblWarning;
private javax.swing.JLabel maxColor;
private javax.swing.JLabel minColor;
private javax.swing.JCheckBox obsoleteWarning;
private javax.swing.JButton reset;
private javax.swing.JCheckBox saveDebugTables;
private javax.swing.JComboBox tableClickCount;
private javax.swing.JCheckBox valueLimitWarning;
private javax.swing.JLabel warningColor;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,20 @@
package enginuity.swing;
import enginuity.maps.Table;
import javax.swing.tree.DefaultMutableTreeNode;
public class TableChooserTreeNode extends DefaultMutableTreeNode {
private Table table;
public TableChooserTreeNode(String text, Table table) {
super(text);
this.table = table;
}
private TableChooserTreeNode() { }
public Table getTable() {
return table;
}
}

View File

@ -0,0 +1,57 @@
package enginuity.swing;
import enginuity.swing.TableMenuBar;
import enginuity.swing.TableToolBar;
import enginuity.maps.Table;
import java.awt.BorderLayout;
import javax.swing.BorderFactory;
import javax.swing.JInternalFrame;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
public class TableFrame extends JInternalFrame implements InternalFrameListener {
private Table table;
private TableToolBar toolBar;
public TableFrame(Table table) {
super(table.getRom().getFileName() + " - " + table.getName(), true, true);
setTable(table);
add(table);
setFrameIcon(null);
setBorder(BorderFactory.createBevelBorder(0));
setVisible(false);
toolBar = new TableToolBar(table, this);
add(toolBar, BorderLayout.NORTH);
setJMenuBar(new TableMenuBar(table));
setDefaultCloseOperation(HIDE_ON_CLOSE);
table.setFrame(this);
addInternalFrameListener(this);
}
public TableToolBar getToolBar() {
return toolBar;
}
public void internalFrameActivated(InternalFrameEvent e) {
getTable().getRom().getContainer().setLastSelectedRom(getTable().getRom());
}
public void internalFrameOpened(InternalFrameEvent e) { }
public void internalFrameClosing(InternalFrameEvent e) {
getTable().getRom().getContainer().removeDisplayTable(this);
}
public void internalFrameClosed(InternalFrameEvent e) { }
public void internalFrameIconified(InternalFrameEvent e) { }
public void internalFrameDeiconified(InternalFrameEvent e) { }
public void internalFrameDeactivated(InternalFrameEvent e) { }
public Table getTable() {
return table;
}
public void setTable(Table table) {
this.table = table;
}
}

View File

@ -0,0 +1,173 @@
package enginuity.swing;
import enginuity.maps.Table;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JSeparator;
public class TableMenuBar extends JMenuBar implements ActionListener {
private Table table;
private JMenu fileMenu = new JMenu("Table");
private JMenuItem graph = new JMenuItem("View Graph");
private JMenuItem overlay = new JMenuItem("Overlay Log");
private JMenu compareMenu = new JMenu("Compare");
private JRadioButtonMenuItem compareOriginal = new JRadioButtonMenuItem("Show Changes");
private JRadioButtonMenuItem compareMap = new JRadioButtonMenuItem("Compare to Another Map");
private JRadioButtonMenuItem compareOff = new JRadioButtonMenuItem("Off");
private JMenu compareDisplay = new JMenu("Display");
private JRadioButtonMenuItem comparePercent = new JRadioButtonMenuItem("Percent Difference");
private JRadioButtonMenuItem compareAbsolute = new JRadioButtonMenuItem("Absolute Difference");
private JMenuItem close = new JMenuItem("Close Table");
private JMenu editMenu = new JMenu("Edit");
private JMenuItem undoSel = new JMenuItem("Undo Selected Changes");
private JMenuItem undoAll = new JMenuItem("Undo All Changes");
private JMenuItem revert = new JMenuItem("Set Revert Point");
private JMenuItem copySel = new JMenuItem("Copy Selection");
private JMenuItem copyTable = new JMenuItem("Copy Table");
private JMenuItem paste = new JMenuItem("Paste");
private JMenu viewMenu = new JMenu("View");
private JMenuItem tableProperties = new JMenuItem("Table Properties");
private ButtonGroup compareGroup = new ButtonGroup();
private ButtonGroup compareDisplayGroup = new ButtonGroup();
public TableMenuBar(Table table) {
super();
this.table = table;
this.add(fileMenu);
fileMenu.add(graph);
fileMenu.add(overlay);
fileMenu.add(compareMenu);
compareMenu.add(compareOriginal);
compareMenu.add(compareMap);
compareMenu.add(compareOff);
compareMenu.add(new JSeparator());
compareMenu.add(compareDisplay);
compareDisplay.add(comparePercent);
compareDisplay.add(compareAbsolute);
fileMenu.add(new JSeparator());
fileMenu.add(close);
close.setText("Close " + table.getName());
compareMenu.setMnemonic('C');
compareOriginal.setMnemonic('C');
compareMap.setMnemonic('M');
compareOff.setMnemonic('O');
compareOff.setSelected(true);
compareDisplay.setMnemonic('D');
comparePercent.setMnemonic('P');
compareAbsolute.setMnemonic('A');
compareAbsolute.setSelected(true);
compareGroup.add(compareOriginal);
compareGroup.add(compareMap);
compareGroup.add(compareOff);
compareDisplayGroup.add(comparePercent);
compareDisplayGroup.add(compareAbsolute);
compareOriginal.addActionListener(this);
compareMap.addActionListener(this);
compareOff.addActionListener(this);
comparePercent.addActionListener(this);
compareAbsolute.addActionListener(this);
this.add(editMenu);
editMenu.add(undoSel);
editMenu.add(undoAll);
editMenu.add(revert);
editMenu.add(new JSeparator());
editMenu.add(copySel);
editMenu.add(copyTable);
editMenu.add(new JSeparator());
editMenu.add(paste);
editMenu.setMnemonic('E');
copySel.setMnemonic('C');
copyTable.setMnemonic('T');
paste.setMnemonic('P');
copySel.addActionListener(this);
copyTable.addActionListener(this);
paste.addActionListener(this);
this.add(viewMenu);
viewMenu.add(tableProperties);
viewMenu.setMnemonic('V');
tableProperties.setMnemonic('P');
tableProperties.addActionListener(this);
graph.addActionListener(this);
overlay.addActionListener(this);
undoSel.addActionListener(this);
undoAll.addActionListener(this);
revert.addActionListener(this);
close.addActionListener(this);
fileMenu.setMnemonic('F');
fileMenu.setMnemonic('T');
graph.setMnemonic('G');
overlay.setMnemonic('L');
undoSel.setMnemonic('U');
undoAll.setMnemonic('A');
revert.setMnemonic('R');
close.setMnemonic('X');
graph.setEnabled(false);
overlay.setEnabled(false);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == undoAll) {
table.undoAll();
} else if (e.getSource() == revert) {
table.setRevertPoint();
} else if (e.getSource() == undoSel) {
table.undoSelected();
} else if (e.getSource() == close) {
table.getFrame().dispose();
} else if (e.getSource() == tableProperties) {
JOptionPane.showMessageDialog(table, (Object)(new TablePropertyPanel(table)),
table.getName() + " Table Properties", JOptionPane.INFORMATION_MESSAGE);
} else if (e.getSource() == copySel) {
table.copySelection();
} else if (e.getSource() == copyTable) {
table.copyTable();
} else if (e.getSource() == paste) {
table.paste();
} else if (e.getSource() == compareOff) {
table.compare(Table.COMPARE_OFF);
} else if (e.getSource() == compareOriginal) {
table.compare(Table.COMPARE_ORIGINAL);
} else if (e.getSource() == compareMap) {
JTableChooser chooser = new JTableChooser();
if (chooser.showChooser(table.getRom().getContainer().getImages(), table.getRom().getContainer(), table) == true) {
table.pasteCompare();
table.compare(Table.COMPARE_TABLE);
}
} else if (e.getSource() == compareAbsolute) {
table.setCompareDisplay(Table.COMPARE_ABSOLUTE);
} else if (e.getSource() == comparePercent) {
table.setCompareDisplay(Table.COMPARE_PERCENT);
}
}
}

View File

@ -0,0 +1,400 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<Properties>
<Property name="autoscrolls" type="boolean" value="true"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="12" style="0"/>
</Property>
<Property name="inheritsPopupMenu" type="boolean" value="true"/>
</Properties>
<AuxValues>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jPanel1" min="-2" max="-2" attributes="1"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel2" max="32767" attributes="1"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblCategory" min="-2" max="-2" attributes="0"/>
<Component id="lblTable" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="category" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="110" max="-2" attributes="0"/>
<Component id="jLabel5" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="userLevel" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="tableName" pref="321" max="32767" attributes="0"/>
</Group>
</Group>
<Component id="jPanel3" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="tableName" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblTable" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblCategory" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="category" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel5" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="userLevel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="jPanel2" max="32767" attributes="1"/>
<Component id="jPanel1" alignment="0" max="32767" attributes="1"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel3" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblTable">
<Properties>
<Property name="text" type="java.lang.String" value="Table:"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="tableName">
<Properties>
<Property name="text" type="java.lang.String" value="Tablename (3D)"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblCategory">
<Properties>
<Property name="text" type="java.lang.String" value="Category:"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="category">
<Properties>
<Property name="text" type="java.lang.String" value="Category"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Container class="javax.swing.JPanel" name="jPanel1">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
<TitledBorder>
<Border PropertyName="innerBorder" info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
<TitledBorder title="Conversion"/>
</Border>
</TitledBorder>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblUnit" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblByteToReal" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblRealToByte" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="14" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="2" pref="2" max="2" attributes="0"/>
<Component id="unit" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="byteToReal" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="realToByte" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="coarse" min="-2" max="-2" attributes="0"/>
<Component id="fine" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="27" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="unit" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="byteToReal" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="realToByte" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="lblUnit" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="lblByteToReal" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="lblRealToByte" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="coarse" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="fine" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblUnit">
<Properties>
<Property name="text" type="java.lang.String" value="Unit:"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="unit">
<Properties>
<Property name="text" type="java.lang.String" value="unit"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblByteToReal">
<Properties>
<Property name="text" type="java.lang.String" value="Byte to Real:"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="byteToReal">
<Properties>
<Property name="text" type="java.lang.String" value="bytetoreal"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="realToByte">
<Properties>
<Property name="text" type="java.lang.String" value="realtobyte"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblRealToByte">
<Properties>
<Property name="text" type="java.lang.String" value="Real to Byte:"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="Coarse adjust:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="Fine adjust:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="coarse">
<Properties>
<Property name="text" type="java.lang.String" value="coarse"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="fine">
<Properties>
<Property name="text" type="java.lang.String" value="fine"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel2">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
<TitledBorder title="Storage"/>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblStorageAddress" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblStorageSize" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblEndian" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="endian" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="storageSize" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="storageAddress" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="28" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblStorageSize" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="storageSize" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblStorageAddress" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="storageAddress" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblEndian" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="endian" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="37" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblStorageAddress">
<Properties>
<Property name="text" type="java.lang.String" value="Storage Address:"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblStorageSize">
<Properties>
<Property name="text" type="java.lang.String" value="Storage Size:"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblEndian">
<Properties>
<Property name="text" type="java.lang.String" value="Endian:"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="endian">
<Properties>
<Property name="text" type="java.lang.String" value="little"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="storageSize">
<Properties>
<Property name="text" type="java.lang.String" value="uint16"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="storageAddress">
<Properties>
<Property name="text" type="java.lang.String" value="0x00"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel3">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
<TitledBorder title="Description"/>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" alignment="1" pref="360" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jScrollPane1" pref="102" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="null"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTextArea" name="description">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="d8" green="e9" red="ec" type="rgb"/>
</Property>
<Property name="columns" type="int" value="20"/>
<Property name="editable" type="boolean" value="false"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="11" style="0"/>
</Property>
<Property name="lineWrap" type="boolean" value="true"/>
<Property name="rows" type="int" value="5"/>
<Property name="text" type="java.lang.String" value="Description"/>
<Property name="wrapStyleWord" type="boolean" value="true"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="null"/>
</Property>
<Property name="opaque" type="boolean" value="false"/>
<Property name="requestFocusEnabled" type="boolean" value="false"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="jLabel5">
<Properties>
<Property name="text" type="java.lang.String" value="User Level:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="userLevel">
<Properties>
<Property name="text" type="java.lang.String" value="Beginner"/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,322 @@
package enginuity.swing;
import enginuity.maps.Table;
public class TablePropertyPanel extends javax.swing.JPanel {
public TablePropertyPanel(Table table) {
initComponents();
setVisible(true);
tableName.setText(table.getName() + " (" + table.getType() + "D)");
category.setText(table.getCategory());
unit.setText(table.getScale().getUnit());
byteToReal.setText(table.getScale().getExpression());
realToByte.setText(table.getScale().getByteExpression());
storageSize.setText("uint" + (table.getStorageType() * 8));
storageAddress.setText("0x" + Integer.toHexString(table.getStorageAddress()));
if (table.getEndian() == Table.ENDIAN_BIG) endian.setText("big");
else endian.setText("little");
description.setText(table.getDescription());
fine.setText(table.getScale().getFineIncrement()+"");
coarse.setText(table.getScale().getCoarseIncrement()+"");
if (table.getUserLevel() == 1) userLevel.setText("Beginner");
else if (table.getUserLevel() == 1) userLevel.setText("Intermediate");
else if (table.getUserLevel() == 1) userLevel.setText("Advanced");
else if (table.getUserLevel() == 1) userLevel.setText("All");
else if (table.getUserLevel() == 1) userLevel.setText("Debug");
}
private TablePropertyPanel() { }
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
lblTable = new javax.swing.JLabel();
tableName = new javax.swing.JLabel();
lblCategory = new javax.swing.JLabel();
category = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
lblUnit = new javax.swing.JLabel();
unit = new javax.swing.JLabel();
lblByteToReal = new javax.swing.JLabel();
byteToReal = new javax.swing.JLabel();
realToByte = new javax.swing.JLabel();
lblRealToByte = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
coarse = new javax.swing.JLabel();
fine = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
lblStorageAddress = new javax.swing.JLabel();
lblStorageSize = new javax.swing.JLabel();
lblEndian = new javax.swing.JLabel();
endian = new javax.swing.JLabel();
storageSize = new javax.swing.JLabel();
storageAddress = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
description = new javax.swing.JTextArea();
jLabel5 = new javax.swing.JLabel();
userLevel = new javax.swing.JLabel();
setAutoscrolls(true);
setFont(new java.awt.Font("Tahoma", 0, 12));
setInheritsPopupMenu(true);
lblTable.setText("Table:");
lblTable.setFocusable(false);
tableName.setText("Tablename (3D)");
tableName.setFocusable(false);
lblCategory.setText("Category:");
lblCategory.setFocusable(false);
category.setText("Category");
category.setFocusable(false);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder("Conversion")));
lblUnit.setText("Unit:");
lblUnit.setFocusable(false);
unit.setText("unit");
unit.setFocusable(false);
lblByteToReal.setText("Byte to Real:");
lblByteToReal.setFocusable(false);
byteToReal.setText("bytetoreal");
byteToReal.setFocusable(false);
realToByte.setText("realtobyte");
realToByte.setFocusable(false);
lblRealToByte.setText("Real to Byte:");
lblRealToByte.setFocusable(false);
jLabel1.setText("Coarse adjust:");
jLabel2.setText("Fine adjust:");
coarse.setText("coarse");
fine.setText("fine");
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(lblUnit)
.add(lblByteToReal)
.add(lblRealToByte)
.add(jLabel1)
.add(jLabel2))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 14, Short.MAX_VALUE)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(2, 2, 2)
.add(unit))
.add(byteToReal)
.add(realToByte)
.add(coarse)
.add(fine))
.add(27, 27, 27))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jPanel1Layout.createSequentialGroup()
.add(unit)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(byteToReal)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(realToByte))
.add(jPanel1Layout.createSequentialGroup()
.add(lblUnit)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(lblByteToReal)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(lblRealToByte)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(coarse))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(fine)))
);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Storage"));
lblStorageAddress.setText("Storage Address:");
lblStorageAddress.setFocusable(false);
lblStorageSize.setText("Storage Size:");
lblStorageSize.setFocusable(false);
lblEndian.setText("Endian:");
lblEndian.setFocusable(false);
endian.setText("little");
endian.setFocusable(false);
storageSize.setText("uint16");
storageSize.setFocusable(false);
storageAddress.setText("0x00");
storageAddress.setFocusable(false);
org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(lblStorageAddress)
.add(lblStorageSize)
.add(lblEndian))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(endian)
.add(storageSize)
.add(storageAddress))
.addContainerGap(28, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblStorageSize)
.add(storageSize))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblStorageAddress)
.add(storageAddress))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblEndian)
.add(endian))
.addContainerGap(37, Short.MAX_VALUE))
);
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Description"));
jScrollPane1.setBorder(null);
description.setBackground(new java.awt.Color(236, 233, 216));
description.setColumns(20);
description.setEditable(false);
description.setFont(new java.awt.Font("Tahoma", 0, 11));
description.setLineWrap(true);
description.setRows(5);
description.setText("Description");
description.setWrapStyleWord(true);
description.setBorder(null);
description.setOpaque(false);
description.setRequestFocusEnabled(false);
jScrollPane1.setViewportView(description);
org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel3Layout.createSequentialGroup()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
.addContainerGap())
);
jLabel5.setText("User Level:");
userLevel.setText("Beginner");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(lblCategory)
.add(lblTable))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(category)
.add(110, 110, 110)
.add(jLabel5)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(userLevel))
.add(tableName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)))
.add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(tableName)
.add(lblTable))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(lblCategory)
.add(category)
.add(jLabel5)
.add(userLevel))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel byteToReal;
private javax.swing.JLabel category;
private javax.swing.JLabel coarse;
private javax.swing.JTextArea description;
private javax.swing.JLabel endian;
private javax.swing.JLabel fine;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lblByteToReal;
private javax.swing.JLabel lblCategory;
private javax.swing.JLabel lblEndian;
private javax.swing.JLabel lblRealToByte;
private javax.swing.JLabel lblStorageAddress;
private javax.swing.JLabel lblStorageSize;
private javax.swing.JLabel lblTable;
private javax.swing.JLabel lblUnit;
private javax.swing.JLabel realToByte;
private javax.swing.JLabel storageAddress;
private javax.swing.JLabel storageSize;
private javax.swing.JLabel tableName;
private javax.swing.JLabel unit;
private javax.swing.JLabel userLevel;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,245 @@
package enginuity.swing;
import enginuity.maps.Scale;
import enginuity.maps.Table;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.border.LineBorder;
public class TableToolBar extends JToolBar implements MouseListener, ItemListener {
private JButton incrementFine = new JButton(new ImageIcon("./graphics/icon-incfine.png"));
private JButton decrementFine = new JButton(new ImageIcon("./graphics/icon-decfine.png"));
private JButton incrementCoarse = new JButton(new ImageIcon("./graphics/icon-inccoarse.png"));
private JButton decrementCoarse = new JButton(new ImageIcon("./graphics/icon-deccoarse.png"));
private JButton setValue = new JButton("Set");
private JButton multiply = new JButton("Mul");
private JFormattedTextField incrementByFine = new JFormattedTextField(new DecimalFormat("#.####"));
private JFormattedTextField incrementByCoarse = new JFormattedTextField(new DecimalFormat("#.####"));
private JFormattedTextField setValueText = new JFormattedTextField(new DecimalFormat("#.####"));
private JComboBox scaleSelection = new JComboBox();
private Table table;
private TableFrame frame;
public TableToolBar(Table table, TableFrame frame) {
this.table = table;
this.setFrame(frame);
this.setFloatable(false);
this.add(incrementFine);
this.add(decrementFine);
this.add(incrementByFine);
this.add(new JLabel(" "));
this.add(incrementCoarse);
this.add(decrementCoarse);
this.add(new JLabel(" "));
this.add(incrementByCoarse);
this.add(new JLabel(" "));
this.add(setValueText);
this.add(new JLabel(" "));
this.add(setValue);
this.add(multiply);
this.add(new JLabel(" "));
//this.add(scaleSelection);
incrementFine.setMaximumSize(new Dimension(33,33));
incrementFine.setBorder(new LineBorder(new Color(150,150,150), 1));
decrementFine.setMaximumSize(new Dimension(33,33));
decrementFine.setBorder(new LineBorder(new Color(150,150,150), 1));
incrementCoarse.setMaximumSize(new Dimension(33,33));
incrementCoarse.setBorder(new LineBorder(new Color(150,150,150), 1));
decrementCoarse.setMaximumSize(new Dimension(33,33));
decrementCoarse.setBorder(new LineBorder(new Color(150,150,150), 1));
setValue.setMaximumSize(new Dimension(33,23));
setValue.setBorder(new LineBorder(new Color(150,150,150), 1));
multiply.setMaximumSize(new Dimension(33,23));
multiply.setBorder(new LineBorder(new Color(150,150,150), 1));
scaleSelection.setMaximumSize(new Dimension(80,23));
scaleSelection.setFont(new Font("Tahoma", Font.PLAIN, 11));
incrementByFine.setAlignmentX(JTextArea.CENTER_ALIGNMENT);
incrementByFine.setAlignmentY(JTextArea.CENTER_ALIGNMENT);
incrementByFine.setMaximumSize(new Dimension(45, 23));
incrementByCoarse.setAlignmentX(JTextArea.CENTER_ALIGNMENT);
incrementByCoarse.setAlignmentY(JTextArea.CENTER_ALIGNMENT);
incrementByCoarse.setMaximumSize(new Dimension(45, 23));
setValueText.setAlignmentX(JTextArea.CENTER_ALIGNMENT);
setValueText.setAlignmentY(JTextArea.CENTER_ALIGNMENT);
setValueText.setMaximumSize(new Dimension(45, 23));
incrementFine.setToolTipText("Increment Value (Fine)");
decrementFine.setToolTipText("Decrement Value (Fine)");
incrementCoarse.setToolTipText("Increment Value (Coarse)");
decrementCoarse.setToolTipText("Decrement Value (Coarse)");
setValue.setToolTipText("Set Absolute Value");
setValueText.setToolTipText("Set Absolute Value");
incrementByFine.setToolTipText("Fine Value Adjustment");
incrementByCoarse.setToolTipText("Coarse Value Adjustment");
multiply.setToolTipText("Multiply Value");
incrementFine.addMouseListener(this);
decrementFine.addMouseListener(this);
incrementCoarse.addMouseListener(this);
decrementCoarse.addMouseListener(this);
setValue.addMouseListener(this);
multiply.addMouseListener(this);
scaleSelection.addItemListener(this);
try {
incrementByFine.setValue(Math.abs(table.getScale().getFineIncrement()));
incrementByCoarse.setValue(Math.abs(table.getScale().getCoarseIncrement()));
} catch (Exception ex) {
// scaling units haven't been added yet -- no problem
}
// key binding actions
Action enterAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
getTable().requestFocus();
setValue();
}
};
// set input mapping
InputMap im = getInputMap(WHEN_IN_FOCUSED_WINDOW);
KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
im.put(enter, "enterAction");
getActionMap().put(im.get(enter), enterAction);
incrementFine.getInputMap().put(enter, "enterAction");
decrementFine.getInputMap().put(enter, "enterAction");
incrementCoarse.getInputMap().put(enter, "enterAction");
decrementCoarse.getInputMap().put(enter, "enterAction");
incrementByFine.getInputMap().put(enter, "enterAction");
incrementByCoarse.getInputMap().put(enter, "enterAction");
setValueText.getInputMap().put(enter, "enterAction");
setValue.getInputMap().put(enter, "enterAction");
incrementFine.getInputMap().put(enter, "enterAction");
setScales(table.getScales());
}
public Table getTable() {
return table;
}
public void setScales(Vector<Scale> scales) {
// remove item listener to avoid null pointer exception when populating
scaleSelection.removeItemListener(this);
for (int i = 0; i < scales.size(); i++) {
scaleSelection.addItem(scales.get(i).getName());
}
// and put it back
scaleSelection.addItemListener(this);
}
public void mouseClicked(MouseEvent e) {
if (e.getSource() == incrementCoarse) incrementCoarse();
else if (e.getSource() == decrementCoarse) decrementCoarse();
else if (e.getSource() == incrementFine) incrementFine();
else if (e.getSource() == decrementFine) decrementFine();
else if (e.getSource() == multiply) multiply();
else if (e.getSource() == setValue) setValue();
table.colorize();
}
public void setValue() {
table.setRealValue(setValueText.getText()+"");
}
public void multiply() {
table.multiply(Double.parseDouble(setValueText.getText()));
}
public void incrementFine() {
table.increment(Double.parseDouble(incrementByFine.getValue()+""));
}
public void decrementFine() {
table.increment(0 - Double.parseDouble(incrementByFine.getValue()+""));
}
public void incrementCoarse() {
table.increment(Double.parseDouble(incrementByCoarse.getValue()+""));
}
public void decrementCoarse() {
table.increment(0 - Double.parseDouble(incrementByCoarse.getValue()+""));
}
public void setCoarseValue(double input) {
incrementByCoarse.setText(input+"");
try {
incrementByCoarse.commitEdit();
} catch (ParseException ex) { }
}
public void setFineValue(double input) {
incrementByFine.setText(input+"");
try {
incrementByFine.commitEdit();
} catch (ParseException ex) { }
}
public void focusSetValue(char input) {
setValueText.requestFocus();
setValueText.setText(input+"");
}
public void setInputMap(InputMap im) {
incrementFine.setInputMap(WHEN_FOCUSED, im);
decrementFine.setInputMap(WHEN_FOCUSED, im);
incrementCoarse.setInputMap(WHEN_FOCUSED, im);
decrementCoarse.setInputMap(WHEN_FOCUSED, im);
setValue.setInputMap(WHEN_FOCUSED, im);
}
public void mousePressed(MouseEvent e) { }
public void mouseReleased(MouseEvent e) { }
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public TableFrame getFrame() {
return frame;
}
public void setFrame(TableFrame frame) {
this.frame = frame;
}
public void itemStateChanged(ItemEvent e) {
// scale changed
if (e.getSource() == scaleSelection) {
table.setScaleIndex(scaleSelection.getSelectedIndex());
}
}
}

View File

@ -0,0 +1,57 @@
package enginuity.swing;
import enginuity.maps.Rom;
import enginuity.maps.Table;
import javax.swing.tree.DefaultMutableTreeNode;
public class TableTreeNode extends DefaultMutableTreeNode {
private String type;
private Rom rom;
private Table table;
private String toolTip;
private TableFrame frame;
public TableTreeNode(Table table) {
//super(table.getName() + " (" + table.getType() + "D)");
super(table);
this.table = table;
this.frame = table.getFrame();
}
public String getType() {
return type;
}
public Rom getRom() {
return rom;
}
public void setRom(Rom rom) {
this.rom = rom;
}
public Table getTable() {
return table;
}
public void setTable(Table table) {
this.table = table;
}
public void setToolTipText(String input) {
toolTip = input;
}
public String getToolTipText() {
return toolTip;
}
public TableFrame getFrame() {
return frame;
}
public void setFrame(TableFrame frame) {
this.frame = frame;
}
}

View File

@ -0,0 +1,296 @@
package enginuity.swing;
import java.awt.*;
import javax.swing.*;
import java.beans.*;
/**
VTextIcon is an Icon implementation which draws a short string vertically.
It's useful for JTabbedPanes with LEFT or RIGHT tabs but can be used in any
component which supports Icons, such as JLabel or JButton
You can provide a hint to indicate whether to rotate the string
to the left or right, or not at all, and it checks to make sure
that the rotation is legal for the given string
(for example, Chinese/Japanese/Korean scripts have special rules when
drawn vertically and should never be rotated)
*/
public class VTextIcon extends Component implements Icon, PropertyChangeListener {
String fLabel;
String[] fCharStrings; // for efficiency, break the fLabel into one-char strings to be passed to drawString
int[] fCharWidths; // Roman characters should be centered when not rotated (Japanese fonts are monospaced)
int[] fPosition; // Japanese half-height characters need to be shifted when drawn vertically
int fWidth, fHeight, fCharHeight, fDescent; // Cached for speed
int fRotation;
Component fComponent;
static final int POSITION_NORMAL = 0;
static final int POSITION_TOP_RIGHT = 1;
static final int POSITION_FAR_TOP_RIGHT = 2;
public static final int ROTATE_DEFAULT = 0x00;
public static final int ROTATE_NONE = 0x01;
public static final int ROTATE_LEFT = 0x02;
public static final int ROTATE_RIGHT = 0x04;
/**
* Creates a <code>VTextIcon</code> for the specified <code>component</code>
* with the specified <code>label</code>.
* It sets the orientation to the default for the string
* @see #verifyRotation
*/
public VTextIcon(Component component, String label) {
this(component, label, ROTATE_DEFAULT);
}
/**
* Creates a <code>VTextIcon</code> for the specified <code>component</code>
* with the specified <code>label</code>.
* It sets the orientation to the provided value if it's legal for the string
* @see #verifyRotation
*/
public VTextIcon(Component component, String label, int rotateHint) {
fComponent = component;
fLabel = label;
fRotation = verifyRotation(label, rotateHint);
calcDimensions();
fComponent.addPropertyChangeListener(this);
}
/**
* sets the label to the given string, updating the orientation as needed
* and invalidating the layout if the size changes
* @see #verifyRotation
*/
public void setLabel(String label) {
fLabel = label;
fRotation = verifyRotation(label, fRotation); // Make sure the current rotation is still legal
recalcDimensions();
}
/**
* Checks for changes to the font on the fComponent
* so that it can invalidate the layout if the size changes
*/
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
if("font".equals(prop)) {
recalcDimensions();
}
}
/**
* Calculates the dimensions. If they've changed,
* invalidates the component
*/
void recalcDimensions() {
int wOld = getIconWidth();
int hOld = getIconHeight();
calcDimensions();
if (wOld != getIconWidth() || hOld != getIconHeight())
fComponent.invalidate();
}
void calcDimensions() {
FontMetrics fm = fComponent.getFontMetrics(fComponent.getFont());
fCharHeight = fm.getAscent() + fm.getDescent();
fDescent = fm.getDescent();
if (fRotation == ROTATE_NONE) {
int len = fLabel.length();
char data[] = new char[len];
fLabel.getChars(0, len, data, 0);
// if not rotated, width is that of the widest char in the string
fWidth = 0;
// we need an array of one-char strings for drawString
fCharStrings = new String[len];
fCharWidths = new int[len];
fPosition = new int[len];
char ch;
for (int i = 0; i < len; i++) {
ch = data[i];
fCharWidths[i] = fm.charWidth(ch);
if (fCharWidths[i] > fWidth)
fWidth = fCharWidths[i];
fCharStrings[i] = new String(data, i, 1);
// small kana and punctuation
if (sDrawsInTopRight.indexOf(ch) >= 0) // if ch is in sDrawsInTopRight
fPosition[i] = POSITION_TOP_RIGHT;
else if (sDrawsInFarTopRight.indexOf(ch) >= 0)
fPosition[i] = POSITION_FAR_TOP_RIGHT;
else
fPosition[i] = POSITION_NORMAL;
}
// and height is the font height * the char count, + one extra leading at the bottom
fHeight = fCharHeight * len + fDescent;
}
else {
// if rotated, width is the height of the string
fWidth = fCharHeight;
// and height is the width, plus some buffer space
fHeight = fm.stringWidth(fLabel) + 2*kBufferSpace;
}
}
/**
* Draw the icon at the specified location. Icon implementations
* may use the Component argument to get properties useful for
* painting, e.g. the foreground or background color.
*/
public void paintIcon(Component c, Graphics g, int x, int y) {
// We don't insist that it be on the same Component
g.setColor(c.getForeground());
g.setFont(c.getFont());
if (fRotation == ROTATE_NONE) {
int yPos = y + fCharHeight;
for (int i = 0; i < fCharStrings.length; i++) {
// Special rules for Japanese - "half-height" characters (like ya, yu, yo in combinations)
// should draw in the top-right quadrant when drawn vertically
// - they draw in the bottom-left normally
int tweak;
switch (fPosition[i]) {
case POSITION_NORMAL:
// Roman fonts should be centered. Japanese fonts are always monospaced.
g.drawString(fCharStrings[i], x+((fWidth-fCharWidths[i])/2), yPos);
break;
case POSITION_TOP_RIGHT:
tweak = fCharHeight/3; // Should be 2, but they aren't actually half-height
g.drawString(fCharStrings[i], x+(tweak/2), yPos-tweak);
break;
case POSITION_FAR_TOP_RIGHT:
tweak = fCharHeight - fCharHeight/3;
g.drawString(fCharStrings[i], x+(tweak/2), yPos-tweak);
break;
}
yPos += fCharHeight;
}
}
else if (fRotation == ROTATE_LEFT) {
g.translate(x+fWidth,y+fHeight);
((Graphics2D)g).rotate(-NINETY_DEGREES);
g.drawString(fLabel, kBufferSpace, -fDescent);
((Graphics2D)g).rotate(NINETY_DEGREES);
g.translate(-(x+fWidth),-(y+fHeight));
}
else if (fRotation == ROTATE_RIGHT) {
g.translate(x,y);
((Graphics2D)g).rotate(NINETY_DEGREES);
g.drawString(fLabel, kBufferSpace, -fDescent);
((Graphics2D)g).rotate(-NINETY_DEGREES);
g.translate(-x,-y);
}
}
/**
* Returns the icon's width.
*
* @return an int specifying the fixed width of the icon.
*/
public int getIconWidth() {
return fWidth;
}
/**
* Returns the icon's height.
*
* @return an int specifying the fixed height of the icon.
*/
public int getIconHeight() {
return fHeight;
}
/**
verifyRotation
returns the best rotation for the string (ROTATE_NONE, ROTATE_LEFT, ROTATE_RIGHT)
This is public static so you can use it to test a string without creating a VTextIcon
from http://www.unicode.org/unicode/reports/tr9/tr9-3.html
When setting text using the Arabic script in vertical lines,
it is more common to employ a horizontal baseline that
is rotated by 90¡ counterclockwise so that the characters
are ordered from top to bottom. Latin text and numbers
may be rotated 90¡ clockwise so that the characters
are also ordered from top to bottom.
Rotation rules
- Roman can rotate left, right, or none - default right (counterclockwise)
- CJK can't rotate
- Arabic must rotate - default left (clockwise)
from the online edition of _The Unicode Standard, Version 3.0_, file ch10.pdf page 4
Ideographs are found in three blocks of the Unicode Standard...
U+4E00-U+9FFF, U+3400-U+4DFF, U+F900-U+FAFF
Hiragana is U+3040-U+309F, katakana is U+30A0-U+30FF
from http://www.unicode.org/unicode/faq/writingdirections.html
East Asian scripts are frequently written in vertical lines
which run from top-to-bottom and are arrange columns either
from left-to-right (Mongolian) or right-to-left (other scripts).
Most characters use the same shape and orientation when displayed
horizontally or vertically, but many punctuation characters
will change their shape when displayed vertically.
Letters and words from other scripts are generally rotated through
ninety degree angles so that they, too, will read from top to bottom.
That is, letters from left-to-right scripts will be rotated clockwise
and letters from right-to-left scripts counterclockwise, both
through ninety degree angles.
Unlike the bidirectional case, the choice of vertical layout
is usually treated as a formatting style; therefore,
the Unicode Standard does not define default rendering behavior
for vertical text nor provide directionality controls designed to override such behavior
*/
public static int verifyRotation(String label, int rotateHint) {
boolean hasCJK = false;
boolean hasMustRotate = false; // Arabic, etc
int len = label.length();
char data[] = new char[len];
char ch;
label.getChars(0, len, data, 0);
for (int i = 0; i < len; i++) {
ch = data[i];
if ((ch >= '\u4E00' && ch <= '\u9FFF') ||
(ch >= '\u3400' && ch <= '\u4DFF') ||
(ch >= '\uF900' && ch <= '\uFAFF') ||
(ch >= '\u3040' && ch <= '\u309F') ||
(ch >= '\u30A0' && ch <= '\u30FF') )
hasCJK = true;
if ((ch >= '\u0590' && ch <= '\u05FF') || // Hebrew
(ch >= '\u0600' && ch <= '\u06FF') || // Arabic
(ch >= '\u0700' && ch <= '\u074F') ) // Syriac
hasMustRotate = true;
}
// If you mix Arabic with Chinese, you're on your own
if (hasCJK)
return DEFAULT_CJK;
int legal = hasMustRotate ? LEGAL_MUST_ROTATE : LEGAL_ROMAN;
if ((rotateHint & legal) > 0)
return rotateHint;
// The hint wasn't legal, or it was zero
return hasMustRotate ? DEFAULT_MUST_ROTATE : DEFAULT_ROMAN;
}
// The small kana characters and Japanese punctuation that draw in the top right quadrant:
// small a, i, u, e, o, tsu, ya, yu, yo, wa (katakana only) ka ke
static final String sDrawsInTopRight =
"\u3041\u3043\u3045\u3047\u3049\u3063\u3083\u3085\u3087\u308E" + // hiragana
"\u30A1\u30A3\u30A5\u30A7\u30A9\u30C3\u30E3\u30E5\u30E7\u30EE\u30F5\u30F6"; // katakana
static final String sDrawsInFarTopRight = "\u3001\u3002"; // comma, full stop
static final int DEFAULT_CJK = ROTATE_NONE;
static final int LEGAL_ROMAN = ROTATE_NONE | ROTATE_LEFT | ROTATE_RIGHT;
static final int DEFAULT_ROMAN = ROTATE_RIGHT;
static final int LEGAL_MUST_ROTATE = ROTATE_LEFT | ROTATE_RIGHT;
static final int DEFAULT_MUST_ROTATE = ROTATE_LEFT;
static final double NINETY_DEGREES = Math.toRadians(90.0);
static final int kBufferSpace = 5;
}

View File

@ -0,0 +1,89 @@
package enginuity.swing;
import java.io.File;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.swing.filechooser.FileFilter;
public class XMLFilter extends FileFilter {
private Hashtable<String, FileFilter> filters = null;
private String description = null;
private String fullDescription = null;
private boolean useExtensionsInDescription = true;
public XMLFilter() {
this.filters = new Hashtable<String, FileFilter>();
this.addExtension("xml");
this.setDescription("ECU Definition Files");
}
public boolean accept(File f) {
if (f != null) {
if (f.isDirectory()) {
return true;
}
String extension = getExtension(f);
if (extension != null && filters.get(getExtension(f)) != null) {
return true;
}
;
}
return false;
}
public String getExtension(File f) {
if (f != null) {
String filename = f.getName();
int i = filename.lastIndexOf('.');
if (i > 0 && i < filename.length() - 1) {
return filename.substring(i + 1).toLowerCase();
}
;
}
return null;
}
public void addExtension(String extension) {
filters.put(extension.toLowerCase(), this);
fullDescription = null;
}
public String getDescription() {
if (fullDescription == null) {
if (description == null || isExtensionListInDescription()) {
fullDescription = description == null ? "(" : description
+ " (";
// build the description from the extension list
Enumeration extensions = filters.keys();
if (extensions != null) {
fullDescription += "." + (String) extensions.nextElement();
while (extensions.hasMoreElements()) {
fullDescription += ", ."
+ (String) extensions.nextElement();
}
}
fullDescription += ")";
}
else {
fullDescription = description;
}
}
return fullDescription;
}
public void setDescription(String description) {
this.description = description;
fullDescription = null;
}
public void setExtensionListInDescription(boolean b) {
useExtensionsInDescription = b;
fullDescription = null;
}
public boolean isExtensionListInDescription() {
return useExtensionsInDescription;
}
}

View File

@ -0,0 +1,37 @@
package enginuity.util;
public final class ByteUtil {
private ByteUtil() {
}
public static int asInt(byte[] bytes) {
int i = 0;
for (int j = 0; j < bytes.length; j++) {
if (j > 0) {
i <<= 8;
}
i |= bytes[j] & 0xFF;
}
return i;
}
@SuppressWarnings({"UnnecessaryBoxing"})
public static byte asByte(int i) {
return Integer.valueOf(i).byteValue();
}
@SuppressWarnings({"UnnecessaryBoxing"})
public static int asInt(byte b) {
return Byte.valueOf(b).intValue();
}
public static byte[] asBytes(int i) {
byte[] b = new byte[4];
for (int j = 0; j < 4; j++) {
int offset = (b.length - 1 - j) * 8;
b[j] = (byte) ((i >>> offset) & 0xFF);
}
return b;
}
}

View File

@ -0,0 +1,37 @@
package enginuity.util;
import enginuity.Settings;
import java.awt.*;
public final class ColorScaler {
private ColorScaler() {
}
public static Color getScaledColor(double scale, Settings settings) {
Color minColor = settings.getMinColor();
Color maxColor = settings.getMaxColor();
float[] minColorHSB = new float[3];
float[] maxColorHSB = new float[3];
Color.RGBtoHSB(minColor.getRed(),
minColor.getGreen(),
minColor.getBlue(),
minColorHSB);
Color.RGBtoHSB(maxColor.getRed(),
maxColor.getGreen(),
maxColor.getBlue(),
maxColorHSB);
float h = minColorHSB[0] + (maxColorHSB[0] - minColorHSB[0]) * (float)scale;
float s = minColorHSB[1] + (maxColorHSB[1] - minColorHSB[1]) * (float)scale;
float b = minColorHSB[2] + (maxColorHSB[2] - minColorHSB[2]) * (float)scale;
return Color.getHSBColor(h, s, b);
}
}

View File

@ -0,0 +1,66 @@
package enginuity.util;
public final class HexUtil {
private HexUtil() {
}
public static String asHex(byte in[]) {
return bytesToHex(in).toUpperCase();
}
public static byte[] asBytes(String hex) {
if (hex.startsWith("0x")) {
hex = hex.substring(2);
}
return hexToBytes(hex);
}
public static String bytesToHex(byte[] bs, int off, int length) {
StringBuffer sb = new StringBuffer(length * 2);
bytesToHexAppend(bs, off, length, sb);
return sb.toString();
}
public static void bytesToHexAppend(byte[] bs, int off, int length, StringBuffer sb) {
sb.ensureCapacity(sb.length() + length * 2);
for (int i = off; (i < (off + length)) && (i < bs.length); i++) {
sb.append(Character.forDigit((bs[i] >>> 4) & 0xf, 16));
sb.append(Character.forDigit(bs[i] & 0xf, 16));
}
}
public static String bytesToHex(byte[] bs) {
return bytesToHex(bs, 0, bs.length);
}
public static byte[] hexToBytes(String s) {
return hexToBytes(s, 0);
}
public static byte[] hexToBytes(String s, int off) {
byte[] bs = new byte[off + (1 + s.length()) / 2];
hexToBytes(s, bs, off);
return bs;
}
public static void hexToBytes(String s, byte[] out, int off) throws NumberFormatException, IndexOutOfBoundsException {
int slen = s.length();
if ((slen % 2) != 0) {
s = '0' + s;
}
if (out.length < off + slen / 2) {
throw new IndexOutOfBoundsException("Output buffer too small for input (" + out.length + "<" + off + slen / 2 + ")");
}
// Safe to assume the string is even length
byte b1, b2;
for (int i = 0; i < slen; i += 2) {
b1 = (byte) Character.digit(s.charAt(i), 16);
b2 = (byte) Character.digit(s.charAt(i + 1), 16);
if ((b1 < 0) || (b2 < 0)) {
throw new NumberFormatException();
}
out[off + i / 2] = (byte) (b1 << 4 | b2);
}
}
}

View File

@ -0,0 +1,51 @@
package enginuity.util;
import java.util.Collection;
public final class ParamChecker {
private ParamChecker() {
}
public static void checkNotNull(Object param, String paramName) {
if (param == null) {
throw new IllegalArgumentException("Parameter " + paramName + " must not be null");
}
}
public static void checkNotNull(Object... params) {
for (int i = 0; i < params.length; i++) {
checkNotNull(params[i], "arg" + i);
}
}
public static void checkNotNullOrEmpty(String param, String paramName) {
if (param == null || param.length() == 0) {
throw new IllegalArgumentException("Parameter " + paramName + " must not be null or empty");
}
}
public static void checkNotNullOrEmpty(Object[] param, String paramName) {
if (param == null || param.length == 0) {
throw new IllegalArgumentException("Parameter " + paramName + " must not be null or empty");
}
}
public static void checkNotNullOrEmpty(Collection<?> param, String paramName) {
if (param == null || param.isEmpty()) {
throw new IllegalArgumentException("Parameter " + paramName + " must not be null or empty");
}
}
public static void checkGreaterThanZero(int param, String paramName) {
if (param <= 0) {
throw new IllegalArgumentException("Parameter " + paramName + " must be > 0");
}
}
public static void checkNotNullOrEmpty(byte[] param, String paramName) {
if (param == null || param.length == 0) {
throw new IllegalArgumentException("Parameter " + paramName + " must not be null or empty");
}
}
}

View File

@ -0,0 +1,509 @@
//DOM XML parser for ROMs
package enginuity.xml;
import enginuity.ECUEditor;
import enginuity.Settings;
import javax.management.modelmbean.XMLParseException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import enginuity.maps.DataCell;
import enginuity.maps.Rom;
import enginuity.maps.RomID;
import enginuity.maps.Scale;
import enginuity.maps.Table;
import enginuity.maps.Table1D;
import enginuity.maps.Table2D;
import enginuity.maps.Table3D;
import enginuity.maps.TableSwitch;
import enginuity.swing.DebugPanel;
import enginuity.swing.JProgressPane;
import java.util.Vector;
import javax.swing.JOptionPane;
public class DOMRomUnmarshaller {
private JProgressPane progress = null;
private Vector<Scale> scales = new Vector<Scale>();
private Settings settings;
private ECUEditor parent;
public DOMRomUnmarshaller(Settings settings, ECUEditor parent) {
this.settings = settings;
this.parent = parent;
}
public Rom unmarshallXMLDefinition (Node rootNode, byte[] input, JProgressPane progress) throws RomNotFoundException, XMLParseException, StackOverflowError, Exception {
this.progress = progress;
Node n;
NodeList nodes = rootNode.getChildNodes();
// unmarshall scales first
for (int i = 0; i < nodes.getLength(); i++) {
n = nodes.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("scalingbase")) {
scales.add(unmarshallScale(n, new Scale()));
}
}
// now unmarshall roms
for (int i = 0; i < nodes.getLength(); i++) {
n = nodes.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("rom")) {
Node n2;
NodeList nodes2 = n.getChildNodes();
for (int z = 0; z < nodes2.getLength(); z++) {
n2 = nodes2.item(z);
if (n2.getNodeType() == Node.ELEMENT_NODE && n2.getNodeName().equalsIgnoreCase("romid")) {
RomID romID = unmarshallRomID(n2, new RomID());
if (romID.getInternalIdString().length() > 0 && foundMatch(romID, input)) {
Rom output = unmarshallRom(n, new Rom());
//set ram offset
output.getRomID().setRamOffset(output.getRomID().getFileSize() - input.length);
return output;
}
}
}
}
}
throw new RomNotFoundException();
}
public static boolean foundMatch(RomID romID, byte[] file) {
String idString = romID.getInternalIdString();
// romid is hex string
if (idString.length() > 2 && idString.substring(0,2).equalsIgnoreCase("0x")) {
try {
// put romid in to byte array to check for match
idString = idString.substring(2); // remove "0x"
int[] romIDBytes = new int[idString.length() / 2];
for (int i = 0; i < romIDBytes.length; i++) {
// check to see if each byte matches
if ((file[romID.getInternalIdAddress() + i] & 0xff) !=
Integer.parseInt(idString.substring(i * 2, i * 2 + 2), 16)) {
return false;
}
}
// if no mismatched bytes found, return true
return true;
} catch (Exception ex) {
// if any exception is encountered, names do not match
ex.printStackTrace();
return false;
}
// else romid is NOT hex string
} else {
try {
String ecuID = new String(file, romID.getInternalIdAddress(), romID.getInternalIdString().length());
return foundMatchByString(romID, ecuID);
} catch (Exception ex) {
// if any exception is encountered, names do not match
return false;
}
}
}
public static boolean foundMatchByString(RomID romID, String ecuID) {
try {
if (ecuID.equalsIgnoreCase(romID.getInternalIdString())) {
return true;
} else {
return false;
}
} catch (Exception ex) {
// if any exception is encountered, names do not match
return false;
}
}
public static void main(String args[]) {
DOMRomUnmarshaller um = new DOMRomUnmarshaller(new Settings(), new ECUEditor());
um.parent.dispose();
RomID romID = new RomID();
romID.setInternalIdString("Asdfd");
byte[] file = "Asdfd".getBytes();
System.out.println(foundMatch(romID, file));
file[0] = 1;
file[1] = 1;
file[2] = 1;
file[3] = 1;
System.out.println(foundMatch(romID, file));
romID.setInternalIdString("0x010101");
System.out.println(foundMatch(romID, file));
}
public Rom unmarshallRom (Node rootNode, Rom rom) throws XMLParseException, RomNotFoundException, StackOverflowError, Exception {
Node n;
NodeList nodes = rootNode.getChildNodes();
progress.update("Creating tables...", 15);
if (!unmarshallAttribute(rootNode, "base", "none").equalsIgnoreCase("none")) {
rom = getBaseRom(rootNode.getParentNode(), unmarshallAttribute(rootNode, "base", "none"), rom);
rom.getRomID().setObsolete(false);
}
for (int i = 0; i < nodes.getLength(); i++) {
n = nodes.item(i);
// update progress
int currProgress = (int)((double)i / (double)nodes.getLength() * 40);
progress.update("Creating tables...", 10 + currProgress);
if (n.getNodeType() == Node.ELEMENT_NODE) {
if (n.getNodeName().equalsIgnoreCase("romid")) {
rom.setRomID(unmarshallRomID(n, rom.getRomID()));
} else if (n.getNodeName().equalsIgnoreCase("table")) {
Table table = null;
try {
table = rom.getTable(unmarshallAttribute(n, "name", "unknown"));
} catch (TableNotFoundException e) { /* table does not already exist (do nothing) */ }
try {
table = unmarshallTable(n, table, rom);
table.setRom(rom);
rom.addTable(table);
} catch (TableIsOmittedException ex) {
// table is not supported in inherited def (skip)
if (table != null) {
rom.removeTable(table.getName());
}
} catch (XMLParseException ex) { ex.printStackTrace();}
} else { /* unexpected element in Rom (skip)*/ }
} else { /* unexpected node-type in Rom (skip)*/ }
}
return rom;
}
public Rom getBaseRom(Node rootNode, String xmlID, Rom rom) throws XMLParseException, RomNotFoundException, StackOverflowError, Exception {
Node n;
NodeList nodes = rootNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
n = nodes.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("rom")) {
Node n2;
NodeList nodes2 = n.getChildNodes();
for (int z = 0; z < nodes2.getLength(); z++) {
n2 = nodes2.item(z);
if (n2.getNodeType() == Node.ELEMENT_NODE && n2.getNodeName().equalsIgnoreCase("romid")) {
RomID romID = unmarshallRomID(n2, new RomID());
if (romID.getXmlid().equalsIgnoreCase(xmlID)) {
Rom returnrom = unmarshallRom(n, rom);
returnrom.getRomID().setObsolete(false);
return returnrom;
}
}
}
}
}
throw new RomNotFoundException();
}
public RomID unmarshallRomID (Node romIDNode, RomID romID) {
Node n;
NodeList nodes = romIDNode.getChildNodes();
for (int i=0; i < nodes.getLength(); i++){
n = nodes.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
if (n.getNodeName().equalsIgnoreCase("xmlid")){
romID.setXmlid(unmarshallText(n));
} else if (n.getNodeName().equalsIgnoreCase("internalidaddress")) {
romID.setInternalIdAddress(RomAttributeParser.parseHexString(unmarshallText(n)));
} else if (n.getNodeName().equalsIgnoreCase("internalidstring")) {
romID.setInternalIdString(unmarshallText(n));
if (romID.getInternalIdString() == null) romID.setInternalIdString("");
} else if (n.getNodeName().equalsIgnoreCase("caseid")) {
romID.setCaseId(unmarshallText(n));
} else if (n.getNodeName().equalsIgnoreCase("ecuid")) {
romID.setEcuId(unmarshallText(n));
} else if (n.getNodeName().equalsIgnoreCase("make")) {
romID.setMake(unmarshallText(n));
} else if (n.getNodeName().equalsIgnoreCase("market")) {
romID.setMarket(unmarshallText(n));
} else if (n.getNodeName().equalsIgnoreCase("model")) {
romID.setModel(unmarshallText(n));
} else if (n.getNodeName().equalsIgnoreCase("submodel")) {
romID.setSubModel(unmarshallText(n));
} else if (n.getNodeName().equalsIgnoreCase("transmission")) {
romID.setTransmission(unmarshallText(n));
} else if (n.getNodeName().equalsIgnoreCase("year")) {
romID.setYear(unmarshallText(n));
} else if (n.getNodeName().equalsIgnoreCase("flashmethod")) {
romID.setFlashMethod(unmarshallText(n));
} else if (n.getNodeName().equalsIgnoreCase("memmodel")) {
romID.setMemModel(unmarshallText(n));
} else if (n.getNodeName().equalsIgnoreCase("filesize")) {
romID.setFileSize(RomAttributeParser.parseFileSize(unmarshallText(n)));
} else if (n.getNodeName().equalsIgnoreCase("obsolete")) {
romID.setObsolete(Boolean.parseBoolean(unmarshallText(n)));
} else { /* unexpected element in RomID (skip) */ }
} else { /* unexpected node-type in RomID (skip) */ }
}
return romID;
}
private Table unmarshallTable(Node tableNode, Table table, Rom rom) throws XMLParseException, TableIsOmittedException, Exception {
if (unmarshallAttribute(tableNode, "omit", "false").equalsIgnoreCase("true")) { // remove table if omitted
throw new TableIsOmittedException();
}
if (!unmarshallAttribute(tableNode, "base", "none").equalsIgnoreCase("none")) { // copy base table for inheritance
try {
table = (Table)ObjectCloner.deepCopy((Object)rom.getTable(unmarshallAttribute(tableNode, "base", "none")));
} catch (TableNotFoundException ex) { /* table not found, do nothing */
} catch (NullPointerException ex) {
JOptionPane.showMessageDialog(parent, new DebugPanel(ex,
parent.getSettings().getSupportURL()), "Exception", JOptionPane.ERROR_MESSAGE);
}
}
try {
if (table.getType() < 1) { }
} catch (NullPointerException ex) { // if type is null or less than 0, create new instance (otherwise it is inherited)
if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("3D")) {
table = new Table3D(settings);
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("2D")) {
table = new Table2D(settings);
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("1D")) {
table = new Table1D(settings);
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("X Axis") ||
unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("Y Axis")) {
table = new Table1D(settings);
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("Static Y Axis") ||
unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("Static X Axis")) {
table = new Table1D(settings);
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("Switch")) {
table = new TableSwitch(settings);
} else {
throw new XMLParseException("Error loading table.");
}
}
// unmarshall table attributes
table.setName(unmarshallAttribute(tableNode, "name", table.getName()));
table.setType(RomAttributeParser.parseTableType(unmarshallAttribute(tableNode, "type", table.getType())));
if (unmarshallAttribute(tableNode, "beforeram", "false").equalsIgnoreCase("true")) table.setBeforeRam(true);
if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("Static X Axis") ||
unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("Static Y Axis")) {
table.setIsStatic(true);
((Table1D)table).setIsAxis(true);
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("X Axis") ||
unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("Y Axis")) {
((Table1D)table).setIsAxis(true);
}
table.setCategory(unmarshallAttribute(tableNode, "category", table.getCategory()));
table.setStorageType(RomAttributeParser.parseStorageType(unmarshallAttribute(tableNode, "storagetype", table.getStorageType())));
table.setEndian(RomAttributeParser.parseEndian(unmarshallAttribute(tableNode, "endian", table.getEndian())));
table.setStorageAddress(RomAttributeParser.parseHexString(unmarshallAttribute(tableNode, "storageaddress", table.getStorageAddress())));
table.setDescription(unmarshallAttribute(tableNode, "description", table.getDescription()));
table.setDataSize(Integer.parseInt(unmarshallAttribute(tableNode, "sizey", unmarshallAttribute(tableNode, "sizex", table.getDataSize()))));
table.setFlip(Boolean.parseBoolean(unmarshallAttribute(tableNode, "flipy", unmarshallAttribute(tableNode, "flipx", table.getFlip()+""))));
table.setUserLevel(Integer.parseInt(unmarshallAttribute(tableNode, "userlevel", table.getUserLevel())));
table.setLocked(Boolean.parseBoolean(unmarshallAttribute(tableNode, "locked", table.isLocked()+"")));
if (table.getType() == Table.TABLE_3D) {
((Table3D)table).setFlipX(Boolean.parseBoolean(unmarshallAttribute(tableNode, "flipx", ((Table3D)table).getFlipX()+"")));
((Table3D)table).setFlipY(Boolean.parseBoolean(unmarshallAttribute(tableNode, "flipy", ((Table3D)table).getFlipY()+"")));
((Table3D)table).setSizeX(Integer.parseInt(unmarshallAttribute(tableNode, "sizex", ((Table3D)table).getSizeX())));
((Table3D)table).setSizeY(Integer.parseInt(unmarshallAttribute(tableNode, "sizey", ((Table3D)table).getSizeY())));
}
Node n;
NodeList nodes = tableNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
n = nodes.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
if (n.getNodeName().equalsIgnoreCase("table")) {
if (table.getType() == Table.TABLE_2D) { // if table is 2D, parse axis
if (RomAttributeParser.parseTableType(unmarshallAttribute(n, "type", "unknown")) == Table.TABLE_Y_AXIS ||
RomAttributeParser.parseTableType(unmarshallAttribute(n, "type", "unknown")) == Table.TABLE_X_AXIS) {
Table1D tempTable = (Table1D)unmarshallTable(n, ((Table2D)table).getAxis(), rom);
if (tempTable.getDataSize() != table.getDataSize()) tempTable.setDataSize(table.getDataSize());
tempTable.setData(((Table2D)table).getAxis().getData());
tempTable.setAxisParent(table);
((Table2D)table).setAxis(tempTable);
}
} else if (table.getType() == Table.TABLE_3D) { // if table is 3D, populate axiis
if (RomAttributeParser.parseTableType(unmarshallAttribute(n, "type", "unknown")) == Table.TABLE_X_AXIS) {
Table1D tempTable = (Table1D)unmarshallTable(n, ((Table3D)table).getXAxis(), rom);
if (tempTable.getDataSize() != ((Table3D)table).getSizeX()) tempTable.setDataSize(((Table3D)table).getSizeX());
tempTable.setData(((Table3D)table).getXAxis().getData());
tempTable.setAxisParent(table);
((Table3D)table).setXAxis(tempTable);
} else if (RomAttributeParser.parseTableType(unmarshallAttribute(n, "type", "unknown")) == Table.TABLE_Y_AXIS) {
Table1D tempTable = (Table1D)unmarshallTable(n, ((Table3D)table).getYAxis(), rom);
if (tempTable.getDataSize() != ((Table3D)table).getSizeY()) tempTable.setDataSize(((Table3D)table).getSizeY());
tempTable.setData(((Table3D)table).getYAxis().getData());
tempTable.setAxisParent(table);
((Table3D)table).setYAxis(tempTable);
}
}
} else if (n.getNodeName().equalsIgnoreCase("scaling")) {
// check whether scale already exists. if so, modify, else use new instance
Scale baseScale = new Scale();
try {
baseScale = table.getScaleByName(unmarshallAttribute(n, "name", "x"));
} catch (Exception ex) { }
table.setScale(unmarshallScale(n, baseScale));
} else if (n.getNodeName().equalsIgnoreCase("data")) {
// parse and add data to table
DataCell dataCell = new DataCell();
dataCell.setDisplayValue(unmarshallText(n));
dataCell.setTable(table);
((Table1D)table).addStaticDataCell(dataCell);
} else if (n.getNodeName().equalsIgnoreCase("description")) {
table.setDescription(unmarshallText(n));
} else if (n.getNodeName().equalsIgnoreCase("state")) {
// set on/off values for switch type
if (this.unmarshallAttribute(n, "name", "").equalsIgnoreCase("on")) {
((TableSwitch)table).setOnValues(unmarshallAttribute(n, "data", "0"));
} else if (this.unmarshallAttribute(n, "name", "").equalsIgnoreCase("off")) {
((TableSwitch)table).setOffValues(unmarshallAttribute(n, "data", "0"));
}
} else { /*unexpected element in Table (skip) */ }
} else { /* unexpected node-type in Table (skip) */ }
}
return table;
}
private Scale unmarshallScale (Node scaleNode, Scale scale) {
// look for base scale first
String base = unmarshallAttribute(scaleNode, "base", "none");
if (!base.equalsIgnoreCase("none")) {
for (int i = 0; i < scales.size(); i++) {
// check whether name matches base and set scale if so
if (scales.get(i).getName().equalsIgnoreCase(base)) {
try {
scale = (Scale)ObjectCloner.deepCopy((Object)scales.get(i));
} catch (Exception ex) {
JOptionPane.showMessageDialog(parent, new DebugPanel(ex,
parent.getSettings().getSupportURL()), "Exception", JOptionPane.ERROR_MESSAGE);
}
}
}
}
// set remaining attributes
scale.setName(unmarshallAttribute(scaleNode, "name", scale.getName()));
scale.setUnit(unmarshallAttribute(scaleNode, "units", scale.getUnit()));
scale.setExpression(unmarshallAttribute(scaleNode, "expression", scale.getExpression()));
scale.setByteExpression(unmarshallAttribute(scaleNode, "to_byte", scale.getByteExpression()));
scale.setFormat(unmarshallAttribute(scaleNode, "format", "#"));
scale.setMax(Double.parseDouble(unmarshallAttribute(scaleNode, "max", "0")));
scale.setMin(Double.parseDouble(unmarshallAttribute(scaleNode, "min", "0")));
// get coarse increment with new attribute name (coarseincrement), else look for old (increment)
scale.setCoarseIncrement(Double.parseDouble(unmarshallAttribute(scaleNode, "coarseincrement",
unmarshallAttribute(scaleNode, "increment", scale.getCoarseIncrement()+"")+"")));
scale.setFineIncrement(Double.parseDouble(unmarshallAttribute(scaleNode,
"fineincrement", scale.getFineIncrement()+"")));
return scale;
}
private String unmarshallText(Node textNode) {
StringBuffer buf = new StringBuffer();
Node n;
NodeList nodes = textNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++){
n = nodes.item(i);
if (n.getNodeType() == Node.TEXT_NODE) {
buf.append(n.getNodeValue());
} else {
// expected a text-only node (skip)
}
}
return buf.toString();
}
private String unmarshallAttribute(Node node, String name, String defaultValue) {
Node n = node.getAttributes().getNamedItem(name);
return (n!=null)?(n.getNodeValue()):(defaultValue);
}
private String unmarshallAttribute(Node node, String name, int defaultValue) {
return unmarshallAttribute(node, name, defaultValue+"");
}
}

View File

@ -0,0 +1,201 @@
package enginuity.xml;
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
import enginuity.Settings;
import enginuity.swing.JProgressPane;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Vector;
import javax.imageio.metadata.IIOMetadataNode;
public class DOMSettingsBuilder {
public void buildSettings (Settings settings, File output, JProgressPane progress, String versionNumber) throws IOException {
IIOMetadataNode settingsNode = new IIOMetadataNode("settings");
// create settings
progress.update("Saving window settings...", 20);
settingsNode.appendChild(buildWindow(settings));
progress.update("Saving file settings...", 40);
settingsNode.appendChild(buildFiles(settings));
progress.update("Saving options...", 60);
settingsNode.appendChild(buildOptions(settings, versionNumber));
progress.update("Saving display settings...", 80);
settingsNode.appendChild(buildTableDisplay(settings));
OutputFormat of = new OutputFormat("XML","ISO-8859-1",true);
of.setIndent(1);
of.setIndenting(true);
progress.update("Writing to file...", 90);
FileOutputStream fos = new FileOutputStream(output);
XMLSerializer serializer = new XMLSerializer(fos,of);
serializer.serialize(settingsNode);
fos.flush();
fos.close();
}
public IIOMetadataNode buildWindow(Settings settings) {
IIOMetadataNode windowSettings = new IIOMetadataNode("window");
// window size
IIOMetadataNode size = new IIOMetadataNode("size");
size.setAttribute("x", ((int)settings.getWindowSize().getHeight())+"");
size.setAttribute("y", ((int)settings.getWindowSize().getWidth())+"");
windowSettings.appendChild(size);
// window location
IIOMetadataNode location = new IIOMetadataNode("location");
location.setAttribute("x", ((int)settings.getWindowLocation().getX())+"");
location.setAttribute("y", ((int)settings.getWindowLocation().getY())+"");
windowSettings.appendChild(location);
// splitpane location
IIOMetadataNode splitpane = new IIOMetadataNode("splitpane");
splitpane.setAttribute("location", settings.getSplitPaneLocation()+"");
windowSettings.appendChild(splitpane);
return windowSettings;
}
public IIOMetadataNode buildFiles(Settings settings) {
IIOMetadataNode files = new IIOMetadataNode("files");
// image directory
IIOMetadataNode imageDir = new IIOMetadataNode("image_dir");
imageDir.setAttribute("path", settings.getLastImageDir().getAbsolutePath());
files.appendChild(imageDir);
// ecu definition files
Vector<File> defFiles = settings.getEcuDefinitionFiles();
for (int i = 0; i < defFiles.size(); i++) {
IIOMetadataNode ecuDef = new IIOMetadataNode("ecudefinitionfile");
ecuDef.setAttribute("name", defFiles.get(i).getAbsolutePath());
files.appendChild(ecuDef);
}
return files;
}
public IIOMetadataNode buildOptions(Settings settings, String versionNumber) {
IIOMetadataNode options = new IIOMetadataNode("options");
// obsolete warning
IIOMetadataNode obsoleteWarning = new IIOMetadataNode("obsoletewarning");
obsoleteWarning.setAttribute("value", settings.isObsoleteWarning()+"");
options.appendChild(obsoleteWarning);
// calcultion conflicting warning
IIOMetadataNode calcConflictWarning = new IIOMetadataNode("calcconflictwarning");
calcConflictWarning.setAttribute("value", settings.isCalcConflictWarning()+"");
options.appendChild(calcConflictWarning);
// debug mode
IIOMetadataNode debug = new IIOMetadataNode("debug");
debug.setAttribute("value", settings.isDebug()+"");
options.appendChild(debug);
// userlevel
IIOMetadataNode userLevel = new IIOMetadataNode("userlevel");
userLevel.setAttribute("value", settings.getUserLevel()+"");
options.appendChild(userLevel);
// table click count
IIOMetadataNode tableClickCount = new IIOMetadataNode("tableclickcount");
tableClickCount.setAttribute("value", settings.getTableClickCount()+"");
options.appendChild(tableClickCount);
// last version used
IIOMetadataNode version = new IIOMetadataNode("version");
version.setAttribute("value", versionNumber);
options.appendChild(version);
// save debug level tables
IIOMetadataNode saveDebugTables = new IIOMetadataNode("savedebugtables");
saveDebugTables.setAttribute("value", settings.isSaveDebugTables()+"");
options.appendChild(saveDebugTables);
// display tables higher than userlevel
IIOMetadataNode displayHighTables = new IIOMetadataNode("displayhightables");
displayHighTables.setAttribute("value", settings.isDisplayHighTables()+"");
options.appendChild(displayHighTables);
// warning when exceeding limits
IIOMetadataNode valueLimitWarning = new IIOMetadataNode("valuelimitwarning");
valueLimitWarning.setAttribute("value", settings.isValueLimitWarning()+"");
options.appendChild(valueLimitWarning);
return options;
}
public IIOMetadataNode buildTableDisplay(Settings settings) {
IIOMetadataNode tableDisplay = new IIOMetadataNode("tabledisplay");
// font
IIOMetadataNode font = new IIOMetadataNode("font");
font.setAttribute("face", settings.getTableFont().getName());
font.setAttribute("size", settings.getTableFont().getSize()+"");
font.setAttribute("decoration", settings.getTableFont().getStyle()+"");
tableDisplay.appendChild(font);
// table cell size
IIOMetadataNode cellSize = new IIOMetadataNode("cellsize");
cellSize.setAttribute("height", ((int)settings.getCellSize().getHeight())+"");
cellSize.setAttribute("width", ((int)settings.getCellSize().getWidth())+"");
tableDisplay.appendChild(cellSize);
// colors
IIOMetadataNode colors = new IIOMetadataNode("colors");
// max
IIOMetadataNode max = new IIOMetadataNode("max");
max.setAttribute("r", settings.getMaxColor().getRed()+"");
max.setAttribute("g", settings.getMaxColor().getGreen()+"");
max.setAttribute("b", settings.getMaxColor().getBlue()+"");
colors.appendChild(max);
// min
IIOMetadataNode min = new IIOMetadataNode("min");
min.setAttribute("r", settings.getMinColor().getRed()+"");
min.setAttribute("g", settings.getMinColor().getGreen()+"");
min.setAttribute("b", settings.getMinColor().getBlue()+"");
colors.appendChild(min);
// highlight
IIOMetadataNode highlight = new IIOMetadataNode("highlight");
highlight.setAttribute("r", settings.getHighlightColor().getRed()+"");
highlight.setAttribute("g", settings.getHighlightColor().getGreen()+"");
highlight.setAttribute("b", settings.getHighlightColor().getBlue()+"");
colors.appendChild(highlight);
// increased cell border
IIOMetadataNode increaseBorder = new IIOMetadataNode("increaseborder");
increaseBorder.setAttribute("r", settings.getIncreaseBorder().getRed()+"");
increaseBorder.setAttribute("g", settings.getIncreaseBorder().getGreen()+"");
increaseBorder.setAttribute("b", settings.getIncreaseBorder().getBlue()+"");
colors.appendChild(increaseBorder);
// decreased cell border
IIOMetadataNode decreaseBorder = new IIOMetadataNode("decreaseborder");
decreaseBorder.setAttribute("r", settings.getDecreaseBorder().getRed()+"");
decreaseBorder.setAttribute("g", settings.getDecreaseBorder().getGreen()+"");
decreaseBorder.setAttribute("b", settings.getDecreaseBorder().getBlue()+"");
colors.appendChild(decreaseBorder);
// axis cells
IIOMetadataNode axis = new IIOMetadataNode("axis");
axis.setAttribute("r", settings.getAxisColor().getRed()+"");
axis.setAttribute("g", settings.getAxisColor().getGreen()+"");
axis.setAttribute("b", settings.getAxisColor().getBlue()+"");
colors.appendChild(axis);
// warning cells
IIOMetadataNode warning = new IIOMetadataNode("warning");
warning.setAttribute("r", settings.getWarningColor().getRed()+"");
warning.setAttribute("g", settings.getWarningColor().getGreen()+"");
warning.setAttribute("b", settings.getWarningColor().getBlue()+"");
colors.appendChild(warning);
tableDisplay.appendChild(colors);
return tableDisplay;
}
}

View File

@ -0,0 +1,221 @@
package enginuity.xml;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.io.File;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import enginuity.Settings;
public class DOMSettingsUnmarshaller {
public Settings unmarshallSettings (Node rootNode) {
Settings settings = new Settings();
Node n;
NodeList nodes = rootNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
n = nodes.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("window")) {
settings = unmarshallWindow(n, settings);
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("options")) {
settings = unmarshallOptions(n, settings);
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("files")) {
settings = unmarshallFiles(n, settings);
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("tabledisplay")) {
settings = unmarshallTableDisplay(n, settings);
}
}
return settings;
}
public Settings unmarshallWindow (Node windowNode, Settings settings) {
Node n;
NodeList nodes = windowNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
n = nodes.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("size")) {
settings.setWindowSize(new Dimension(unmarshallAttribute(n, "y", 600),
unmarshallAttribute(n, "x", 800)));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("location")) {
// set default location in top left screen if no settings file found
settings.setWindowLocation(new Point(unmarshallAttribute(n, "x", 0),
unmarshallAttribute(n, "y", 0)));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("splitpane")) {
settings.setSplitPaneLocation(unmarshallAttribute(n, "location", 150));
}
}
return settings;
}
public Settings unmarshallFiles (Node urlNode, Settings settings) {
Node n;
NodeList nodes = urlNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
n = nodes.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("ecudefinitionfile")) {
settings.addEcuDefinitionFile(new File(unmarshallAttribute(n, "name", "ecu_defs.xml")));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("image_dir")) {
settings.setLastImageDir(new File(unmarshallAttribute(n, "path", "ecu_defs.xml")));
}
}
return settings;
}
public Settings unmarshallOptions (Node optionNode, Settings settings) {
Node n;
NodeList nodes = optionNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
n = nodes.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("obsoletewarning")) {
settings.setObsoleteWarning(Boolean.parseBoolean(unmarshallAttribute(n, "value", "true")));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("debug")) {
settings.setDebug(Boolean.parseBoolean(unmarshallAttribute(n, "value", "true")));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("calcconflictwarning")) {
settings.setCalcConflictWarning(Boolean.parseBoolean(unmarshallAttribute(n, "value", "true")));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("userlevel")) {
settings.setUserLevel(unmarshallAttribute(n, "value", 1));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("tableclickcount")) {
settings.setTableClickCount(unmarshallAttribute(n, "value", 2));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("version")) {
settings.setRecentVersion(unmarshallAttribute(n, "value", ""));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("savedebugtables")) {
settings.setSaveDebugTables(Boolean.parseBoolean(unmarshallAttribute(n, "value", "false")));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("displayhightables")) {
settings.setDisplayHighTables(Boolean.parseBoolean(unmarshallAttribute(n, "value", "false")));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("valuelimitwarning")) {
settings.setValueLimitWarning(Boolean.parseBoolean(unmarshallAttribute(n, "value", "true")));
}
}
return settings;
}
public Settings unmarshallTableDisplay (Node tableDisplayNode, Settings settings) {
Node n;
NodeList nodes = tableDisplayNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
n = nodes.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("font")) {
settings.setTableFont(new Font(unmarshallAttribute(n, "face", "Arial"),
unmarshallAttribute(n, "decoration", Font.BOLD),
unmarshallAttribute(n, "size", 12)));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("cellsize")) {
settings.setCellSize(new Dimension(unmarshallAttribute(n, "x", 42),
unmarshallAttribute(n, "y", 18)));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("colors")) {
settings = unmarshallColors(n, settings);
}
}
return settings;
}
public Settings unmarshallColors(Node colorNode, Settings settings) {
Node n;
NodeList nodes = colorNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
n = nodes.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("max")) {
settings.setMaxColor(unmarshallColor(n));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("min")) {
settings.setMinColor(unmarshallColor(n));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("highlight")) {
settings.setHighlightColor(unmarshallColor(n));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("increaseborder")) {
settings.setIncreaseBorder(unmarshallColor(n));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("decreaseborder")) {
settings.setDecreaseBorder(unmarshallColor(n));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("axis")) {
settings.setAxisColor(unmarshallColor(n));
} else if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("warning")) {
settings.setWarningColor(unmarshallColor(n));
}
}
return settings;
}
public Color unmarshallColor(Node colorNode) {
return new Color(unmarshallAttribute(colorNode, "r", 155),
unmarshallAttribute(colorNode, "g", 155),
unmarshallAttribute(colorNode, "b", 155));
}
private String unmarshallText(Node textNode) {
StringBuffer buf = new StringBuffer();
Node n;
NodeList nodes = textNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
n = nodes.item(i);
if (n.getNodeType() == Node.TEXT_NODE) {
buf.append(n.getNodeValue());
}
else {
// expected a text-only node (skip)
}
}
return buf.toString();
}
private String unmarshallAttribute(Node node, String name, String defaultValue) {
Node n = node.getAttributes().getNamedItem(name);
return (n != null) ? (n.getNodeValue()) : (defaultValue);
}
private Double unmarshallAttribute(Node node, String name, double defaultValue) {
return Double.parseDouble(unmarshallAttribute(node, name, defaultValue+""));
}
private int unmarshallAttribute(Node node, String name, int defaultValue) {
return Integer.parseInt(unmarshallAttribute(node, name, defaultValue+""));
}
private boolean unmarshallAttribute(Node node, String name, boolean defaultValue) {
return Boolean.parseBoolean(unmarshallAttribute(node, name, defaultValue+""));
}
}

View File

@ -0,0 +1,37 @@
package enginuity.xml;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class ObjectCloner {
// so that nobody can accidentally create an ObjectCloner object
private ObjectCloner() {}
// returns a deep copy of an object
public static Object deepCopy(Object oldObj) throws Exception {
ObjectOutputStream oos = null;
ObjectInputStream ois = null;
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bos);
// serialize and pass the object
oos.writeObject(oldObj);
oos.flush();
ByteArrayInputStream bin = new ByteArrayInputStream(bos
.toByteArray());
ois = new ObjectInputStream(bin);
// return the new object
return ois.readObject();
}
finally {
if (oos != null) {
oos.close();
}
if (ois != null) {
ois.close();
}
}
}
}

View File

@ -0,0 +1,131 @@
// Parses attributes from ROM XML
package enginuity.xml;
import enginuity.maps.Table;
import enginuity.maps.Scale;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public abstract class RomAttributeParser {
public RomAttributeParser() {
}
public static int parseEndian(String input) {
if (input.equalsIgnoreCase("big") || input.equalsIgnoreCase(Table.ENDIAN_BIG+"")) {
return Table.ENDIAN_BIG;
} else if (input.equalsIgnoreCase("little") || input.equalsIgnoreCase(Table.ENDIAN_LITTLE+"")) {
return Table.ENDIAN_LITTLE;
} else {
return Table.ENDIAN_LITTLE;
}
}
public static int parseHexString(String input) {
if (input.equals("0")) return 0;
else if (input.length() > 2 && input.substring(0,2).equalsIgnoreCase("0x")) {
return Integer.parseInt(input.substring(2), 16);
} else {
return Integer.parseInt(input, 16);
}
}
public static int parseStorageType(String input) {
if (input.equalsIgnoreCase("float")) {
return Table.STORAGE_TYPE_FLOAT;
} else if (input.length() > 4 && input.substring(0,4).equalsIgnoreCase("uint")) {
return Integer.parseInt(input.substring(4)) / 8;
} else {
return Integer.parseInt(input);
}
}
public static int parseScaleType(String input) {
if (input.equalsIgnoreCase("inverse")) {
return Scale.INVERSE;
} else {
return Scale.LINEAR;
}
}
public static int parseTableType(String input) {
if (input.equalsIgnoreCase("3D") || input.equalsIgnoreCase(Table.TABLE_3D+"")) {
return Table.TABLE_3D;
} else if (input.equalsIgnoreCase("2D") || input.equalsIgnoreCase(Table.TABLE_2D+"")) {
return Table.TABLE_2D;
} else if (input.equalsIgnoreCase("X Axis") || input.equalsIgnoreCase("Static X Axis") || input.equalsIgnoreCase(Table.TABLE_X_AXIS+"")) {
return Table.TABLE_X_AXIS;
} else if (input.equalsIgnoreCase("Y Axis") || input.equalsIgnoreCase("Static Y Axis") || input.equalsIgnoreCase(Table.TABLE_Y_AXIS+"")) {
return Table.TABLE_Y_AXIS;
} else {
return Table.TABLE_1D;
}
}
public static int parseByteValue(byte[] input, int endian, int address, int length) throws ArrayIndexOutOfBoundsException {
try {
int output = 0;
if (endian == Table.ENDIAN_BIG) {
for (int i = 0; i < length; i++) {
output += (input[address + i] & 0xff) << 8 * (length - i - 1);
}
} else { // little endian
for (int i = 0; i < length; i++) {
output += (input[address + length - i - 1] & 0xff) << 8 * (length - i - 1);
}
}
return output;
} catch (ArrayIndexOutOfBoundsException ex) {
throw new ArrayIndexOutOfBoundsException();
}
}
public static byte[] parseIntegerValue(int input, int endian, int length) {
byte[] byteArray = new byte[4];
byteArray[0] = (byte)((input >> 24) & 0x000000FF);
byteArray[1] = (byte)((input >> 16) & 0x0000FF);
byteArray[2] = (byte)((input >> 8) & 0x00FF);
byteArray[3] = (byte)(input & 0xFF );
byte[] output = new byte[length];
for (int i = 0; i < length; i++) {
if (endian == Table.ENDIAN_BIG) {
//output[i] = byteArray[i + length];
output[i] = byteArray[4 - length + i];
} else { // little endian
output[length - 1 - i] = byteArray[4 - length + i];
}
}
return output;
}
public static int parseFileSize(String input) throws NumberFormatException {
try {
return Integer.parseInt(input);
} catch (NumberFormatException ex) {
if (input.substring(input.length() - 2).equalsIgnoreCase("kb")) {
return Integer.parseInt(input.substring(0, input.length() - 2)) * 1024;
} else if (input.substring(input.length() - 2).equalsIgnoreCase("mb")) {
return Integer.parseInt(input.substring(0, input.length() - 2)) * 1024 * 1024;
}
throw new NumberFormatException();
}
}
public static byte[] floatToByte(float input, int endian) {
byte[] output = new byte[4];
ByteBuffer bb = ByteBuffer.wrap(output, 0, 4);
if (endian == Table.ENDIAN_LITTLE) bb.order(ByteOrder.BIG_ENDIAN);
bb.putFloat(input);
return bb.array();
}
public static float byteToFloat(byte[] input, int endian) {
ByteBuffer bb = ByteBuffer.wrap(input, 0, 4);
if (endian == Table.ENDIAN_LITTLE) bb.order(ByteOrder.BIG_ENDIAN);
return bb.getFloat();
}
}

View File

@ -0,0 +1,7 @@
package enginuity.xml;
public class RomNotFoundException extends Exception {
public RomNotFoundException() {
}
}

View File

@ -0,0 +1,10 @@
package enginuity.xml;
public class TableIsOmittedException extends Exception {
public TableIsOmittedException() { }
public String getMessage() {
return "Table omitted.";
}
}

View File

@ -0,0 +1,7 @@
package enginuity.xml;
public class TableNotFoundException extends Exception {
public String getMessage() {
return "Table not found.";
}
}