diff --git a/ecu_defs/ecu_defs.xml b/ecu_defs/ecu_defs.xml new file mode 100644 index 00000000..800830e1 --- /dev/null +++ b/ecu_defs/ecu_defs.xml @@ -0,0 +1,43 @@ + + + + + + A4TF400E + 200 + A4TF400E + AH792 + 1234567890 + Subaru + USDM + Impreza + WRX + Manual + 2004 + wrx04 + unknown + + + +
+ +
+ + +
+ "This is a map of base ignition values." + + + + "RPM at which limiter turns on and off." +
+ on + off +
+ + + + "Injector flow rating in cc/min" +
+
+
\ No newline at end of file diff --git a/graphics/enginuity-ico.gif b/graphics/enginuity-ico.gif new file mode 100644 index 00000000..77ad35b8 Binary files /dev/null and b/graphics/enginuity-ico.gif differ diff --git a/license.txt b/license.txt new file mode 100644 index 00000000..e44079ed --- /dev/null +++ b/license.txt @@ -0,0 +1,340 @@ +GNU GENERAL PUBLIC LICENSE +Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +Preamble + +The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and +modification follow. + +GNU GENERAL PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + +a) You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any +part thereof, to be licensed as a whole at no charge to all third +parties under the terms of this License. + +c) If the modified program normally reads commands interactively +when run, you must cause it, when started running for such +interactive use in the most ordinary way, to print or display an +announcement including an appropriate copyright notice and a +notice that there is no warranty (or else, saying that you provide +a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this +License. (Exception: if the Program itself is interactive but +does not normally print such an announcement, your work based on +the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections +1 and 2 above on a medium customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your +cost of physically performing source distribution, a complete +machine-readable copy of the corresponding source code, to be +distributed under the terms of Sections 1 and 2 above on a medium +customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is +allowed only for noncommercial distribution and only if you +received the program in object code or executable form with such +an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + +5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + +7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + +10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + +NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + +Copyright (C) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + +Gnomovision version 69, Copyright (C) year name of author +Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in the program +`Gnomovision' (which makes passes at compilers) written by James Hacker. + +, 1 April 1989 +Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. \ No newline at end of file diff --git a/release notes.txt b/release notes.txt new file mode 100644 index 00000000..de3ff8bd --- /dev/null +++ b/release notes.txt @@ -0,0 +1,52 @@ +Enginuity is a full featured Engine Control Unit editing application for tuning SSP2 Subarus, meant to be used in conjuction with datalogging and ECU flash and dump utilities. Enginuity will give you full control over timing, fuel, boost and many other parameters in your ECU, competing with very expensive and proprietary software. Enginuity will remove your need for piggyback systems designed to control these functions, and, in most cases, work as well as any stand alone engine management. Reflashing your stock ECU also has the added benefit of a manufacturer tested base map, giving you top notch performance and saving time tuning idle and low throttle applications. + +You must have version 1.5.0 of the Java Runtime Environment installed! It is available from http://java.sun.com/j2se/1.5.0/download.jsp under the name JDK 5.0 Update 5. + +Enginuity is currently in ALPHA TEST status, meaning it is untested and not intended for use by inexperienced users. In addition to being incomplete and untested, only experienced tuners with the required tools (ie, wideband oxygen sensor) should modify an ECU image. As with any engine management, changes could result in severe engine damage. Use at your own risk. + +Until Enginuity reaches a mature point, releases will be quite frequent and will usually contain significant changes. However, some times I may release a revision to add a single feature I'd like users to have, or maybe just to add a certain ECU version. Until more features are complete, version support will be quite limited. If you'd like your ECU version to be added, please visit openecu.org and post a message in the Technical Tuning Software forum, with your image attached. + +.20a Release Notes +------------------ +As of this version, Enginuity has been completely rewritten and has NOT been tested thoroughly. This release is intended ONLY AS AN ALPHA TEST RELEASE and to be used ONLY BY EXPERIENCED USERS WILLING TO ACCEPT THE RISK. PLEASE register and report any bugs encountered at www.enginuity.org. More information about Enginuity and how to help test is available at www.enginuity.org. + +Changes: +-------- +.20a (2/11/2006) +---------------- +-Completely rewritten +-XML ECU definitions +-View multiple images and tables + + +.14a (11/26/2005) +------------------ +-Improved axis cell modification +-Fixed absolute value calculations + +.13a +----- +-Revised text entry of values +-Added EUDM WRX support +-Improved multiple cell selection +-Improved axis cell modification +-Axis cell changes can be saved + +Supported ECU Versions/Version Added +---------------------- +2004/2005 USDM WRX: +-A4TF300E .13a +-A4TF400E .13a +-A4TF800E .13a +-A4TF500F .13a +-A4TF510F .13a +-A4TF800F .13a + +2002/2003 USDM WRX: +-A4TC300L .13a +-A4SGC00C .13a +-A4SGD10C .13a +-A4SG900C .13a + +2003 EUDM WRX: +-A4TE001G .13a \ No newline at end of file diff --git a/src/Enginuity/ECUEditor.java b/src/Enginuity/ECUEditor.java new file mode 100644 index 00000000..d5400ed0 --- /dev/null +++ b/src/Enginuity/ECUEditor.java @@ -0,0 +1,174 @@ +package Enginuity; + +import Enginuity.Maps.Rom; +import Enginuity.Maps.Table; +import Enginuity.SwingComponents.ECUEditorToolBar; +import Enginuity.SwingComponents.ECUEditorMenuBar; +import Enginuity.SwingComponents.RomTree; +import Enginuity.SwingComponents.RomTreeNode; +import Enginuity.SwingComponents.TableFrame; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import javax.swing.ImageIcon; +import javax.swing.JDesktopPane; +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import java.util.Vector; +import javax.swing.tree.DefaultMutableTreeNode; + +public class ECUEditor extends JFrame implements WindowListener { + + private JScrollPane imagePane = new JScrollPane(); + private DefaultMutableTreeNode imageRoot = new DefaultMutableTreeNode("ECU Images"); + private RomTree imageList = new RomTree(imageRoot); + private Vector images = new Vector(); + private Settings settings = new Settings(); + private String version = new String(".20 Alpha"); + private String titleText = new String("Enginuity v" + version); + private JDesktopPane rightPanel = new JDesktopPane(); + private Rom lastSelectedRom = null; + private ECUEditorToolBar toolBar; + private ECUEditorMenuBar menuBar; + + public ECUEditor() { + //load settings from disk + try { + ObjectInputStream in = new ObjectInputStream( + new FileInputStream(new File("./settings.dat"))); + settings = (Settings)in.readObject(); + in.close(); + } catch (FileNotFoundException ex) { + } catch (IOException ex) { + } catch (ClassNotFoundException ex) { + } + setSize(getSettings().getWindowSize()[0], getSettings().getWindowSize()[1]); + setLocation(getSettings().getWindowLocation()[0], getSettings().getWindowLocation()[1]); + + 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); + JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftScrollPane, rightScrollPane); + splitPane.setDividerSize(4); + splitPane.setDividerLocation(150); + 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); + + //set remaining window properties + setIconImage(new ImageIcon("./graphics/enginuity-ico.gif").getImage()); + setDefaultCloseOperation(EXIT_ON_CLOSE); + addWindowListener(this); + setTitle(titleText); + setVisible(true); + } + + public void windowClosing(WindowEvent e) { + getSettings().setWindowSize(getSize().width, getSize().height); + getSettings().setWindowLocation(getLocation().x, getLocation().y); + try { + ObjectOutputStream out = new ObjectOutputStream( + new FileOutputStream(new File("./settings.dat"))); + out.writeObject(getSettings()); + out.close(); + } catch (FileNotFoundException ex) { + ex.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + 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 static void main(String args[]) { + new ECUEditor(); + } + + public String getVersion() { + return version; + } + + public Settings getSettings() { + return settings; + } + + public void addRom(Rom input) { + // add to image vector + images.add(input); + input.setContainer(this); + + // add to ecu image list pane + RomTreeNode node = new RomTreeNode(input); + imageRoot.add(node); + imageList.updateUI(); + + // add tables + Vector tables = input.getTables(); + RomTreeNode[] tableNodes = new RomTreeNode[tables.size()]; + for (int i = 0; i < tables.size(); i++) { + tableNodes[i] = new RomTreeNode(tables.get(i)); + node.add(tableNodes[i]); + + TableFrame frame = new TableFrame(tables.get(i)); + rightPanel.add(frame); + } + imageList.expandRow(imageList.getRowCount() - 1); + imageList.updateUI(); + this.setLastSelectedRom(input); + } + + public void closeImage() { + for (int i = 0; i < images.size(); i++) { + if (images.get(i) == lastSelectedRom) { + images.remove(i); + } + } + for (int i = 0; i < imageRoot.getChildCount(); i++) { + if (((RomTreeNode)imageRoot.getChildAt(i)).getRom() == lastSelectedRom) { + imageRoot.remove((DefaultMutableTreeNode)imageRoot.getChildAt(i)); + } + } + imageList.updateUI(); + setLastSelectedRom(null); + } + + public Rom getLastSelectedRom() { + return lastSelectedRom; + } + + public void setLastSelectedRom(Rom lastSelectedRom) { + this.lastSelectedRom = lastSelectedRom; + if (lastSelectedRom == null) { + this.setTitle(titleText); + } else { + this.setTitle(titleText + " - " + lastSelectedRom.getFileName()); + } + } + + public ECUEditorToolBar getToolBar() { + return toolBar; + } + + public void setToolBar(ECUEditorToolBar toolBar) { + this.toolBar = toolBar; + } +} \ No newline at end of file diff --git a/src/Enginuity/Exceptions/RomNotFoundException.java b/src/Enginuity/Exceptions/RomNotFoundException.java new file mode 100644 index 00000000..2c76efcd --- /dev/null +++ b/src/Enginuity/Exceptions/RomNotFoundException.java @@ -0,0 +1,8 @@ +package Enginuity.Exceptions; + +public class RomNotFoundException extends Exception { + + public RomNotFoundException() { + } + +} diff --git a/src/Enginuity/Maps/DataCell.java b/src/Enginuity/Maps/DataCell.java new file mode 100644 index 00000000..3d607b50 --- /dev/null +++ b/src/Enginuity/Maps/DataCell.java @@ -0,0 +1,177 @@ +package Enginuity.Maps; + +import java.awt.Color; +import java.awt.Font; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +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 { + + private int binValue = 0; + private int originalValue = 0; + private Scale scale = new Scale(); + private String realValue = ""; + private Color scaledColor = new Color(0,0,0); + private Color highlightColor = new Color(155,155,255); + private Boolean selected = false; + private Boolean highlighted = false; + private Table table; + private int x = 0; + private int y = 0; + + public DataCell() { + this(new Scale()); + } + + 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 calcRealValue() { + DecimalFormat formatter = new DecimalFormat(scale.getFormat()); + + // create parser + JEP parser = new JEP(); + parser.initSymTab(); // clear the contents of the symbol table + parser.addStandardConstants(); + parser.addComplex(); // among other things adds i to the symbol table + parser.addVariable("x", binValue); + parser.parseExpression(scale.getExpression()); + + realValue = formatter.format(parser.getValue()); + this.setText(realValue); + } + + public void setColor(Color color) { + scaledColor = color; + if (!selected) super.setBackground(color); + } + + public void setRealValue(String realValue) { + this.realValue = realValue; + this.setText(realValue); + } + + public void setBinValue(int binValue) { + this.binValue = binValue; + // make sure it's in range + 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.calcRealValue(); + if (binValue != getOriginalValue()) { + this.setBorder(new LineBorder(Color.RED, 3)); + } else { + this.setBorder(new LineBorder(Color.BLACK, 1)); + } + } + + public int getBinValue() { + return binValue; + } + + public String toString() { + return realValue; + } + + public Boolean isSelected() { + return selected; + } + + public void setSelected(Boolean selected) { + this.selected = selected; + if (selected) { + this.setBackground(highlightColor); + } else { + this.setBackground(scaledColor); + } + } + + public void setHighlighted(Boolean highlighted) { + if (!table.isStatic()) { + this.highlighted = highlighted; + if (highlighted) { + this.setBackground(highlightColor); + } 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); + } + } + public void mouseReleased(MouseEvent e) { + if (!table.isStatic()) { + table.stopHighlight(); + } + } + public void mouseClicked(MouseEvent e) { + //this.setSelected(!selected); + } + public void mouseExited(MouseEvent e) { } + + public void increment() { + this.setBinValue(binValue + scale.getIncrement()); + } + + public void decrement() { + this.setBinValue(binValue - scale.getIncrement()); + } + + 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 int getOriginalValue() { + return originalValue; + } + + public void setOriginalValue(int 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); + } +} \ No newline at end of file diff --git a/src/Enginuity/Maps/ECUDefinitionCollection.java b/src/Enginuity/Maps/ECUDefinitionCollection.java new file mode 100644 index 00000000..43e93585 --- /dev/null +++ b/src/Enginuity/Maps/ECUDefinitionCollection.java @@ -0,0 +1,71 @@ +package Enginuity.Maps; + +import Enginuity.Exceptions.RomNotFoundException; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Vector; +import javax.swing.JOptionPane; + +public class ECUDefinitionCollection { + + Vector roms = new Vector(); + + public ECUDefinitionCollection() { } + + public void addRom(Rom input) { + roms.add(input); + } + + public Rom getRom(String romid) throws RomNotFoundException { // find rom by romid from xml + for (int i = 0; i < roms.size(); i++) { + if (roms.get(i).getRomIDString().equalsIgnoreCase(romid)) { + return roms.get(i); + } + } + //rom not found + throw new RomNotFoundException(); + } + + public Rom getRom(byte[] input) throws RomNotFoundException { // find rom by romid in data file + // search for ECU version in roms vector + for (int i = 0; i < roms.size(); i++) { + String xmlID = roms.get(i).getRomID().getXmlid(); + int idAddress = roms.get(i).getRomID().getInternalIdAddress(); + String ecuID = new String(input, idAddress, xmlID.length()); + + if (ecuID.equalsIgnoreCase(xmlID)) { + return roms.get(i); + } + } + throw new RomNotFoundException(); + } + + public Rom parseRom(File input) throws IOException, RomNotFoundException { + + // load file + Rom rom = new Rom(); + + // find ECU version definition + FileInputStream inputStream = new FileInputStream(input); + byte[] binData = new byte[inputStream.available()]; + inputStream.read(binData); + inputStream.close(); + + rom = this.getRom(binData); + + // populate tables + rom.populateTables(binData); + + return rom; + } + + public String toString() { + String output = ""; + for (int i = 0; i < roms.size(); i++) { + output = output + "\n" + roms.get(i).toString(); + } + return output; + } +} \ No newline at end of file diff --git a/src/Enginuity/Maps/Rom.java b/src/Enginuity/Maps/Rom.java new file mode 100644 index 00000000..2a48525a --- /dev/null +++ b/src/Enginuity/Maps/Rom.java @@ -0,0 +1,80 @@ +//base ECU version + +package Enginuity.Maps; + +import Enginuity.ECUEditor; +import java.util.Vector; + +public class Rom { + + private RomID romID; + private String fileName = ""; + private Vector
tables = new Vector
(); + private ECUEditor container; + private byte[] binData; + + public Rom() { + } + + public void addTable(Table table) { + getTables().add(table); + } + + public void populateTables(byte[] binData) { + this.binData = binData; + for (int i = 0; i < getTables().size(); i++) { + //System.out.println("Populating table " + tables.get(i).getName()); + getTables().get(i).populateTable(binData); + } + } + + 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
getTables() { + return tables; + } + + public ECUEditor getContainer() { + return container; + } + + public void setContainer(ECUEditor container) { + this.container = container; + } + + public byte[] saveFile() { + for (int i = 0; i < tables.size(); i++) { + tables.get(i).saveFile(binData); + } + return binData; + } +} \ No newline at end of file diff --git a/src/Enginuity/Maps/RomID.java b/src/Enginuity/Maps/RomID.java new file mode 100644 index 00000000..b60076c9 --- /dev/null +++ b/src/Enginuity/Maps/RomID.java @@ -0,0 +1,144 @@ +//ECU version definition + +package Enginuity.Maps; + +public class RomID { + + private String xmlid;//ID stored in XML + private int internalIdAddress;//address of ECU version in image + private String internalIdString;//ID stored in image + private String caseId;//ECU hardware firstion + private String ecuId; + private String make;//manufacturer + private String market; + private String model; + private String subModel;//trim, ie WRX + private String transmission; + private int year; + private String flashMethod;//flash method string used for ecuflash + private String memModel;//model used for reflashing with ecuflash + + 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 int getYear() { + return year; + } + + public void setYear(int 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; + } +} \ No newline at end of file diff --git a/src/Enginuity/Maps/Scale.java b/src/Enginuity/Maps/Scale.java new file mode 100644 index 00000000..4bba1606 --- /dev/null +++ b/src/Enginuity/Maps/Scale.java @@ -0,0 +1,57 @@ +//This object defines the scaling factor and offset for calculating real values + +package Enginuity.Maps; + +public class Scale { + + public static final int LINEAR = 0; + public static final int INVERSE = 1; + + private String unit; + private String expression; + private String format; + private int increment; + + public Scale() { + } + + public String toString() { + return "\n ---- Scale ----" + + "\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 int getIncrement() { + return increment; + } + + public void setIncrement(int increment) { + this.increment = increment; + } +} \ No newline at end of file diff --git a/src/Enginuity/Maps/Table.java b/src/Enginuity/Maps/Table.java new file mode 100644 index 00000000..2855385c --- /dev/null +++ b/src/Enginuity/Maps/Table.java @@ -0,0 +1,336 @@ +package Enginuity.Maps; + +import Enginuity.Maps.XML.RomAttributeParser; +import Enginuity.SwingComponents.TableFrame; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.GridLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; + +public abstract class Table extends JPanel { + + public static final int ENDIAN_LITTLE= 0; + public static final int ENDIAN_BIG = 1; + public static final int TABLE_1D = 1; + public static final int TABLE_2D = 2; + public static final int TABLE_3D = 3; + public static final int TABLE_X_AXIS = 4; + public static final int TABLE_Y_AXIS = 5; + + protected String name; + protected int type; + protected String category; + protected String description; + protected Scale scale; + protected int storageAddress; + protected int storageType;//number of bytes per cell + protected int endian; + protected boolean flip; + protected DataCell[] data = new DataCell[0]; + protected boolean isStatic = false; + protected BorderLayout borderLayout = new BorderLayout(); + protected GridLayout centerLayout = new GridLayout(1,1,1,1); + protected JPanel centerPanel = new JPanel(centerLayout); + protected TableFrame frame; + protected int verticalOverhead = 96; + protected int horizontalOverhead = 2; + protected int cellHeight = 23; + protected int cellWidth = 45; + protected int minHeight = 100; + protected int minWidth = 200; + protected Rom container; + protected int highlightX; + protected int highlightY; + protected boolean highlight = false; + protected Table axisParent; + + public Table() { + this.setLayout(borderLayout); + this.add(centerPanel, BorderLayout.CENTER); + centerPanel.setVisible(true); + } + + public void populateTable(byte[] input) { + if (!isStatic) { + for (int i = 0; i < data.length; i++) { + if (data[i] == null) { + data[i] = new DataCell(scale); + data[i].setTable(this); + data[i].setBinValue(RomAttributeParser.parseByteValue(input, endian, storageAddress + i * storageType, storageType)); + centerPanel.add(data[i]); + data[i].setYCoord(i); + data[i].setOriginalValue(data[i].getBinValue()); + } + } + } + try { + this.add(new JLabel(name + " (" + scale.getUnit() + ")", JLabel.CENTER), BorderLayout.NORTH); + } catch (NullPointerException e) { + //need to deal with this later + } + this.colorize(); + } + + public int getType() { + return type; + } + + public DataCell getDataCell(int location) { + return data[location]; + } + + public void setType(int type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Scale getScale() { + return scale; + } + + public void setScale(Scale scale) { + this.scale = scale; + } + + public int getStorageAddress() { + return storageAddress; + } + + public void setStorageAddress(int storageAddress) { + this.storageAddress = storageAddress; + } + + public int getStorageType() { + return storageType; + } + + public void setStorageType(int storageType) { + this.storageType = storageType; + } + + public int getEndian() { + return endian; + } + + public void setEndian(int endian) { + this.endian = endian; + } + + public void setDataSize(int size) { + data = new DataCell[size]; + } + + public int getDataSize() { + return data.length; + } + + public boolean getFlip() { + return flip; + } + + public void setFlip(boolean flipY) { + this.flip = flip; + } + public String toString() { + String output = "\n ---- Table " + name + " ----" + + scale + + "\n Category: " + category + + "\n Type: " + type + + "\n Description: " + description + + "\n Storage Address: " + Integer.toHexString(storageAddress) + + "\n Storage Type: " + storageType + + "\n Endian: " + endian + + "\n Flip: " + flip + + "\n ---- End Table " + name + " ----"; + for (int i = 0; i < data.length; i++) { + if (data[i] != null) { + output = output + "\nData: " + data[i]; + } + } + + return output; + } + + public boolean isStatic() { + return isStatic; + } + + public void setIsStatic(boolean isStatic) { + this.isStatic = isStatic; + } + + public void addStaticDataCell(DataCell input) { + if (isStatic) { + for (int i = 0; i < data.length; i++) { + if (data[i] == null) { + data[i] = input; + break; + } + } + } + } + + public void colorize() { + if (!isStatic) { + int high = 0; + int low = 999999999; + for (int i = 0; i < data.length; i++) { + if (data[i].getBinValue() > high) { + high = data[i].getBinValue(); + } + if (data[i].getBinValue() < low) { + low = data[i].getBinValue(); + } + } + for (int i = 0; i < data.length; i++) { + int range = high - low; + if (range == 0) range = 1; + double scale = ((data[i].getBinValue() - low) / range); + int g = (int)(255 - (255 - 140) * scale); + data[i].setColor(new Color(255, g, 125)); + } + } + } + + public void setFrame(TableFrame frame) { + this.frame = frame; + int height = verticalOverhead + cellHeight; + int width = horizontalOverhead + data.length * cellWidth; + if (height < minHeight) height = minHeight; + if (width < minWidth) width = minWidth; + frame.setSize(width, height); + } + + public TableFrame getFrame() { + return frame; + } + + public void increment() { + if (!isStatic) { + for (int i = 0; i < data.length; i++) { + if (data[i].isSelected()) data[i].increment(); + } + } + } + + public void decrement() { + if (!isStatic) { + for (int i = 0; i < data.length; i++) { + if (data[i].isSelected()) data[i].decrement(); + } + } + } + + public Rom getContainer() { + return container; + } + + public void setContainer(Rom container) { + this.container = container; + } + + public void clearSelection() { + for (int i = 0; i < data.length; i++) { + data[i].setSelected(false); + } + } + + public void startHighlight(int x, int y) { + this.highlightY = y; + this.highlightX = x; + highlight = true; + highlight(x, y); + } + + public void highlight(int x, int y) { + if (highlight) { + for (int i = 0; i < data.length; i++) { + if ((i >= highlightY && i <= y) || (i <= highlightY && i >= y)) { + data[i].setHighlighted(true); + } else { + data[i].setHighlighted(false); + } + } + } + } + + public void stopHighlight() { + highlight = false; + // loop through, selected and un-highlight + for (int i = 0; i < data.length; i++) { + if (data[i].isHighlighted()) { + data[i].setSelected(true); + data[i].setHighlighted(false); + } + } + } + + public Table getAxisParent() { + return axisParent; + } + + public void setAxisParent(Table axisParent) { + this.axisParent = axisParent; + } + + public void setRevertPoint() { + if (!isStatic) { + for (int i = 0; i < data.length; i++) { + data[i].setOriginalValue(data[i].getBinValue()); + } + } + } + + public void undoAll() { + if (!isStatic) { + for (int i = 0; i < data.length; i++) { + data[i].setBinValue(data[i].getOriginalValue()); + } + } + } + + public void undoSelected() { + if (!isStatic) { + for (int i = 0; i < data.length; i++) { + if (data[i].isSelected()) data[i].setBinValue(data[i].getOriginalValue()); + } + } + } + + public byte[] saveFile(byte[] binData) { + if (!isStatic) { + for (int i = 0; i < data.length; i++) { + // need to deal with storage type (num bytes) + byte[] output = RomAttributeParser.parseIntegerValue(data[i].getBinValue(), endian, storageType); + for (int z = 0; z < storageType; z++) { + binData[i * storageType + z + storageAddress] = output[z]; + } + } + } + return binData; + } +} \ No newline at end of file diff --git a/src/Enginuity/Maps/Table1D.java b/src/Enginuity/Maps/Table1D.java new file mode 100644 index 00000000..b7c78d04 --- /dev/null +++ b/src/Enginuity/Maps/Table1D.java @@ -0,0 +1,59 @@ +package Enginuity.Maps; + +import java.awt.Color; + +public class Table1D extends Table { + + private boolean isAxis = false; + + public Table1D() { + super(); + } + + 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)); + } + this.colorize(); + } + + public String toString() { + return super.toString() + ""; + } + + 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() { + if (!isAxis) { + super.colorize(); + } else { + for (int i = 0; i < this.getDataSize(); i++) { + data[i].setColor(Color.WHITE); + } + } + } +} \ No newline at end of file diff --git a/src/Enginuity/Maps/Table2D.java b/src/Enginuity/Maps/Table2D.java new file mode 100644 index 00000000..509fae4f --- /dev/null +++ b/src/Enginuity/Maps/Table2D.java @@ -0,0 +1,92 @@ +package Enginuity.Maps; + +import Enginuity.SwingComponents.TableFrame; + +public class Table2D extends Table { + + private Table1D axis; + + public Table2D() { + super(); + } + + public Table1D getAxis() { + return axis; + } + + public void setAxis(Table1D axis) { + this.axis = axis; + } + + public String toString() { + return super.toString() + axis; + } + + public void colorize() { + super.colorize(); + axis.colorize(); + } + + public void setFrame(TableFrame frame) { + this.frame = frame; + int height = verticalOverhead + cellHeight * 2; + int width = horizontalOverhead + data.length * cellWidth; + if (height < minHeight) height = minHeight; + if (width < minWidth) width = minWidth; + frame.setSize(width, height); + } + + public void populateTable(byte[] input) { + centerLayout.setRows(2); + centerLayout.setColumns(this.getDataSize()); + axis.populateTable(input); + super.populateTable(input); + + // 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)); + } + this.colorize(); + } + + public void increment() { + super.increment(); + axis.increment(); + } + + public void decrement() { + super.decrement(); + axis.decrement(); + } + + 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; + } +} \ No newline at end of file diff --git a/src/Enginuity/Maps/Table3D.java b/src/Enginuity/Maps/Table3D.java new file mode 100644 index 00000000..bdeed074 --- /dev/null +++ b/src/Enginuity/Maps/Table3D.java @@ -0,0 +1,284 @@ +package Enginuity.Maps; + +import Enginuity.Maps.XML.RomAttributeParser; +import Enginuity.SwingComponents.TableFrame; +import Enginuity.SwingComponents.VTextIcon; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Font; +import java.awt.GridLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; + +public class Table3D extends Table { + + private Table1D xAxis; + private Table1D yAxis; + private DataCell[][] data = new DataCell[1][1]; + private boolean swapXY; + private boolean flipX; + private boolean flipY; + + public Table3D() { + super(); + verticalOverhead += 2; + horizontalOverhead += 5; + } + + 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 isFlipX() { + return flipX; + } + + public void setFlipX(boolean flipX) { + this.flipX = flipX; + } + + public boolean isFlipY() { + 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 { + // fill first empty cell + centerPanel.add(new JLabel()); + + // populate axiis + xAxis.populateTable(input); + yAxis.populateTable(input); + 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(scale); + data[y][x].setTable(this); + data[y][x].setBinValue( + RomAttributeParser.parseByteValue(input, + endian, + storageAddress + offset * storageType, + storageType)); + centerPanel.add(data[y][x]); + data[y][x].setXCoord(y); + data[y][x].setYCoord(x); + data[y][x].setOriginalValue(data[y][x].getBinValue()); + offset++; + } + } + this.colorize(); + + GridLayout topLayout = new GridLayout(2,1); + JPanel topPanel = new JPanel(topLayout); + this.add(topPanel, BorderLayout.NORTH); + topPanel.add(new JLabel(name + " (" + scale.getUnit() + ")", 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); + this.add(yLabel, BorderLayout.WEST); + } + + public void colorize() { + if (!isStatic) { + int high = 0; + int low = 999999999; + for (int x = 0; x < data.length; x++) { + for (int y = 0; y < data[0].length; y++) { + if (data[x][y].getBinValue() > high) { + high = data[x][y].getBinValue(); + } else if (data[x][y].getBinValue() < low) { + low = data[x][y].getBinValue(); + } + } + } + for (int x = 0; x < data.length; x++) { + for (int y = 0; y < data[0].length; y++) { + double scale = (double)(data[x][y].getBinValue() - low) / (high - low); + int g = (int)(255 - (255 - 140) * scale); + data[x][y].setColor(new Color(255, g, 125)); + } + } + } + } + + public void setFrame(TableFrame frame) { + this.frame = frame; + int height = verticalOverhead + cellHeight * data[0].length; + int width = horizontalOverhead + data.length * cellWidth; + if (height < minHeight) height = minHeight; + if (width < minWidth) width = minWidth; + frame.setSize(width, height); + } + + public String toString() { + return super.toString() + + "\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() { + if (!isStatic) { + 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(); + } + } + } + xAxis.increment(); + yAxis.increment(); + } + + public void decrement() { + if (!isStatic) { + for (int x = 0; x < this.getSizeX(); x++) { + for (int y = 0; y < this.getSizeY(); y++) { + if (data[x][y].isSelected()) data[x][y].decrement(); + } + } + } + xAxis.decrement(); + yAxis.decrement(); + } + + 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(); + } + + 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(); + } + + 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(); + } + + + public byte[] saveFile(byte[] binData) { + 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++) { + byte[] output = RomAttributeParser.parseIntegerValue(data[y][x].getBinValue(), endian, storageType); + for (int z = 0; z < storageType; z++) { + binData[offset * storageType + storageAddress] = output[z]; + offset++; + } + } + } + return binData; + } +} \ No newline at end of file diff --git a/src/Enginuity/Maps/XML/DOMRomUnmarshaller.java b/src/Enginuity/Maps/XML/DOMRomUnmarshaller.java new file mode 100644 index 00000000..23055e10 --- /dev/null +++ b/src/Enginuity/Maps/XML/DOMRomUnmarshaller.java @@ -0,0 +1,231 @@ +//DOM XML parser for ROMs + +package Enginuity.Maps.XML; + +import Enginuity.Maps.*; +import Enginuity.Maps.ECUDefinitionCollection; +import javax.management.modelmbean.XMLParseException; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class DOMRomUnmarshaller { + + ECUDefinitionCollection roms = new ECUDefinitionCollection(); + + public DOMRomUnmarshaller() { } + + public ECUDefinitionCollection unmarshallXMLDefinition (Node rootNode) throws XMLParseException { + Node n; + NodeList nodes = rootNode.getChildNodes(); + + for (int i = 0; i 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) { + return Integer.parseInt(input.substring(4)) / 8; + } + + 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")) { + return Table.TABLE_3D; + } else if (input.equalsIgnoreCase("2D")) { + return Table.TABLE_2D; + } else if (input.equalsIgnoreCase("X Axis") || input.equalsIgnoreCase("Static X Axis")) { + return Table.TABLE_X_AXIS; + } else if (input.equalsIgnoreCase("Y Axis") || input.equalsIgnoreCase("Static Y Axis")) { + return Table.TABLE_Y_AXIS; + } else { + return Table.TABLE_1D; + } + } + + public static int parseByteValue(byte[] input, int endian, int address, int length) { + int output = 0; + if (endian == Table.ENDIAN_LITTLE) { + for (int i = 0; i < length; i++) { + output += (input[address + i] & 0xff) << 8 * (length - i - 1); + } + } else { + for (int i = 0; i < length; i++) { + output += (input[address + length - i - 1] & 0xff) << 8 * (length - i - 1); + } + } + return output; + } + + 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_LITTLE) { + //output[i] = byteArray[i + length]; + output[i] = byteArray[4 - length + i]; + } else { // big endian + output[length - 1 - i] = byteArray[4 - length + i]; + } + } + return output; + } +} \ No newline at end of file diff --git a/src/Enginuity/Settings.java b/src/Enginuity/Settings.java new file mode 100644 index 00000000..1672961a --- /dev/null +++ b/src/Enginuity/Settings.java @@ -0,0 +1,59 @@ +package Enginuity; + +import java.awt.Dimension; +import java.io.File; +import java.io.Serializable; + +public class Settings implements Serializable { + + private int[] windowSize = new int[2]; + private int[] windowLocation = new int[2]; + private File ecuDefinitionFile = new File("./ecu_defs.xml"); + private File ecuBaseFile = new File("./ecu_base.xml"); + private File lastImageDir = new File("./images"); + private boolean debug = true; + + public Settings() { + windowSize[0] = 800; + windowSize[1] = 600; + + //center window by default + Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); + windowLocation[0] = (int)(screenSize.getWidth() - windowSize[0]) / 2; + windowLocation[1] = (int)(screenSize.getHeight() - windowSize[1]) / 2; + } + + public int[] getWindowSize() { + return windowSize; + } + + public int[] getWindowLocation() { + return windowLocation; + } + + public void setWindowSize(int x, int y) { + windowSize[0] = x; + windowSize[1] = y; + } + + public void setWindowLocation(int x, int y) { + windowLocation[0] = x; + windowLocation[1] = y; + } + + public File getEcuDefinitionFile() { + return ecuDefinitionFile; + } + + public void setEcuDefinitionFile(File ecuDefinitionFile) { + this.ecuDefinitionFile = ecuDefinitionFile; + } + + public File getLastImageDir() { + return lastImageDir; + } + + public void setLastImageDir(File lastImageDir) { + this.lastImageDir = lastImageDir; + } +} \ No newline at end of file diff --git a/src/Enginuity/SwingComponents/ECUEditorMenuBar.java b/src/Enginuity/SwingComponents/ECUEditorMenuBar.java new file mode 100644 index 00000000..6e5a23ab --- /dev/null +++ b/src/Enginuity/SwingComponents/ECUEditorMenuBar.java @@ -0,0 +1,148 @@ +package Enginuity.SwingComponents; + +import Enginuity.*; +import Enginuity.Exceptions.RomNotFoundException; +import Enginuity.Maps.ECUDefinitionCollection; +import Enginuity.Maps.Rom; +import Enginuity.Maps.XML.DOMRomUnmarshaller; +import com.sun.org.apache.xerces.internal.parsers.DOMParser; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import javax.management.modelmbean.XMLParseException; +import javax.swing.JFileChooser; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JSeparator; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +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 closeImage = new JMenuItem("Close Image"); + private JMenuItem exit = new JMenuItem("Exit"); + private ECUEditor parent; + + public ECUEditorMenuBar(ECUEditor parent) { + this.parent = parent; + + add(fileMenu); + fileMenu.setMnemonic('F'); + openImage.setMnemonic('O'); + saveImage.setMnemonic('S'); + closeImage.setMnemonic('C'); + exit.setMnemonic('X'); + + openImage.addActionListener(this); + saveImage.addActionListener(this); + closeImage.addActionListener(this); + exit.addActionListener(this); + + fileMenu.add(openImage); + fileMenu.add(saveImage); + fileMenu.add(closeImage); + fileMenu.add(new JSeparator()); + fileMenu.add(exit); + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource() == openImage) { + try { + this.openImageDialog(); + } catch (XMLParseException ex) { + new JOptionPane(ex, JOptionPane.ERROR_MESSAGE); + } + } else if (e.getSource() == saveImage) { + try { + this.saveImage(parent.getLastSelectedRom()); + } catch (XMLParseException ex) { + new JOptionPane(ex, JOptionPane.ERROR_MESSAGE); + } + } else if (e.getSource() == closeImage) { + this.closeImage(); + } else if (e.getSource() == exit) { + System.exit(0); + } + } + + public void closeImage() { + parent.closeImage(); + } + + public void saveImage(Rom input) throws XMLParseException { + if (parent.getLastSelectedRom() != null) { + JFileChooser fc = new JFileChooser(parent.getSettings().getLastImageDir()); + + if (fc.showSaveDialog(parent) == fc.APPROVE_OPTION) { + boolean save = true; + if (fc.getSelectedFile().exists()) { + if (new JOptionPane().showConfirmDialog(parent, fc.getSelectedFile().getName() + " already exists! Overwrite?") == JOptionPane.CANCEL_OPTION) { + save = false; + } + } + if (save) { + try { + byte[] output = parent.getLastSelectedRom().saveFile(); + FileOutputStream fos = new FileOutputStream(fc.getSelectedFile()); + fos.write(output); + fos.close(); + + } catch (FileNotFoundException ex) { + ex.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); + } + parent.closeImage(); + openImage(fc.getSelectedFile()); + } + } + } + } + + public void openImageDialog() throws XMLParseException { + JFileChooser fc = new JFileChooser(parent.getSettings().getLastImageDir()); + if (fc.showOpenDialog(parent) == fc.APPROVE_OPTION) { + openImage(fc.getSelectedFile()); + } + parent.getSettings().setLastImageDir(fc.getCurrentDirectory()); + } + + public void openImage(File input) throws XMLParseException { + try { + ECUDefinitionCollection roms = new ECUDefinitionCollection(); + InputSource src = new InputSource(new FileInputStream(parent.getSettings().getEcuDefinitionFile())); + DOMRomUnmarshaller domUms = new DOMRomUnmarshaller(); + DOMParser parser = new DOMParser(); + parser.parse(src); + Document doc = parser.getDocument(); + + roms = domUms.unmarshallXMLDefinition(doc.getDocumentElement()); + Rom ecuImage = roms.parseRom(input); + ecuImage.setFileName(input.getName()); + + parent.addRom(ecuImage); + //System.out.println("File opened: " + ecuImage.getFileName()); + + } catch (FileNotFoundException ex) { + ex.printStackTrace(); + } catch (SAXException ex) { + ex.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); + } catch (RomNotFoundException ex) { + new JOptionPane().showMessageDialog(parent, "ECU Definition Not Found", input.getName() + " - Error", JOptionPane.ERROR_MESSAGE); + } + + } +} \ No newline at end of file diff --git a/src/Enginuity/SwingComponents/ECUEditorToolBar.java b/src/Enginuity/SwingComponents/ECUEditorToolBar.java new file mode 100644 index 00000000..c6197249 --- /dev/null +++ b/src/Enginuity/SwingComponents/ECUEditorToolBar.java @@ -0,0 +1,48 @@ +package Enginuity.SwingComponents; + +import Enginuity.ECUEditor; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.management.modelmbean.XMLParseException; +import javax.swing.JButton; +import javax.swing.JOptionPane; +import javax.swing.JToolBar; + +public class ECUEditorToolBar extends JToolBar implements ActionListener { + + private ECUEditor parent; + private JButton openImage = new JButton("Open"); + private JButton saveImage = new JButton("Save"); + private JButton closeImage = new JButton("Close"); + + public ECUEditorToolBar(ECUEditor parent) { + super(); + this.parent = parent; + this.setFloatable(false); + this.add(openImage); + this.add(saveImage); + this.add(closeImage); + + openImage.addActionListener(this); + saveImage.addActionListener(this); + closeImage.addActionListener(this); + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource() == openImage) { + try { + ((ECUEditorMenuBar)parent.getJMenuBar()).openImageDialog(); + } catch (XMLParseException ex) { + new JOptionPane(ex, JOptionPane.ERROR_MESSAGE); + } + } else if (e.getSource() == saveImage) { + try { + ((ECUEditorMenuBar)parent.getJMenuBar()).saveImage(parent.getLastSelectedRom()); + } catch (XMLParseException ex) { + new JOptionPane(ex, JOptionPane.ERROR_MESSAGE); + } + } else if (e.getSource() == closeImage) { + ((ECUEditorMenuBar)parent.getJMenuBar()).closeImage(); + } + } +} \ No newline at end of file diff --git a/src/Enginuity/SwingComponents/RomTree.java b/src/Enginuity/SwingComponents/RomTree.java new file mode 100644 index 00000000..fa6e473a --- /dev/null +++ b/src/Enginuity/SwingComponents/RomTree.java @@ -0,0 +1,62 @@ +package Enginuity.SwingComponents; + +import Enginuity.*; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.beans.PropertyVetoException; +import javax.swing.JTree; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; + +public class RomTree extends JTree implements MouseListener, TreeSelectionListener { + + private ECUEditor container; + + public RomTree (DefaultMutableTreeNode input) { + super(input); + this.setRootVisible(false); + this.addMouseListener(this); + this.addTreeSelectionListener(this); + } + + public ECUEditor getContainer() { + return container; + } + + public void setContainer(ECUEditor container) { + this.container = container; + } + + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + try { + RomTreeNode node = (RomTreeNode)this.getLastSelectedPathComponent(); + node.getTable().getFrame().setVisible(true); + node.getTable().getFrame().setSelected(true); + } catch (PropertyVetoException ex) { + } catch (ClassCastException ex) { + } 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 valueChanged(TreeSelectionEvent e) { + try { + RomTreeNode node = (RomTreeNode)this.getLastSelectedPathComponent(); + if (node.getRom() != null) { + container.setLastSelectedRom(node.getRom()); + } else if (node.getTable() != null) { + container.setLastSelectedRom(node.getTable().getContainer()); + } + } catch (NullPointerException ex) { + // node wasn't table or rom (do nothing) + } catch (ClassCastException ex) { + // node wasn't table or rom (do nothing) + } + } +} \ No newline at end of file diff --git a/src/Enginuity/SwingComponents/RomTreeNode.java b/src/Enginuity/SwingComponents/RomTreeNode.java new file mode 100644 index 00000000..ad36e3b9 --- /dev/null +++ b/src/Enginuity/SwingComponents/RomTreeNode.java @@ -0,0 +1,42 @@ +package Enginuity.SwingComponents; + +import Enginuity.Maps.Rom; +import Enginuity.Maps.Table; +import javax.swing.tree.DefaultMutableTreeNode; + +public class RomTreeNode extends DefaultMutableTreeNode { + + private String type; + private Rom rom; + private Table table; + + public RomTreeNode(Rom rom) { + super(rom.getFileName()); + this.rom = rom; + } + + public RomTreeNode(Table table) { + super(table.getName() + " (" + table.getType() + "D)"); + this.table = table; + } + + 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; + } +} \ No newline at end of file diff --git a/src/Enginuity/SwingComponents/TableFrame.java b/src/Enginuity/SwingComponents/TableFrame.java new file mode 100644 index 00000000..5369d2b1 --- /dev/null +++ b/src/Enginuity/SwingComponents/TableFrame.java @@ -0,0 +1,37 @@ +package Enginuity.SwingComponents; + +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; + + public TableFrame(Table table) { + super(table.getContainer().getFileName() + " - " + table.getName(), true, true); + this.table = table; + this.add(table); + this.setFrameIcon(null); + this.setBorder(BorderFactory.createBevelBorder(0)); + this.setVisible(false); + this.add(new TableToolBar(table), BorderLayout.NORTH); + this.setJMenuBar(new TableMenuBar(table)); + this.setDefaultCloseOperation(this.HIDE_ON_CLOSE); + table.setFrame(this); + this.addInternalFrameListener(this); + } + + public void internalFrameActivated(InternalFrameEvent e) { + table.getContainer().getContainer().setLastSelectedRom(table.getContainer()); + } + public void internalFrameOpened(InternalFrameEvent e) { } + public void internalFrameClosing(InternalFrameEvent e) { } + public void internalFrameClosed(InternalFrameEvent e) { } + public void internalFrameIconified(InternalFrameEvent e) { } + public void internalFrameDeiconified(InternalFrameEvent e) { } + public void internalFrameDeactivated(InternalFrameEvent e) { } +} \ No newline at end of file diff --git a/src/Enginuity/SwingComponents/TableMenuBar.java b/src/Enginuity/SwingComponents/TableMenuBar.java new file mode 100644 index 00000000..2ca61d62 --- /dev/null +++ b/src/Enginuity/SwingComponents/TableMenuBar.java @@ -0,0 +1,78 @@ +package Enginuity.SwingComponents; + +import Enginuity.Maps.Table; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JSeparator; + +public class TableMenuBar extends JMenuBar implements ActionListener { + + private Table table; + private JMenu fileMenu = new JMenu("Table"); + private JMenuItem compare = new JMenuItem("Compare"); + private JMenuItem copy = new JMenuItem("Copy"); + private JMenuItem graph = new JMenuItem("View Graph"); + private JMenuItem overlay = new JMenuItem("Overlay Log"); + 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 close = new JMenuItem("Close Table"); + + public TableMenuBar(Table table) { + super(); + this.table = table; + this.add(fileMenu); + fileMenu.setText(table.getName()); + close.setText("Close " + table.getName()); + fileMenu.add(compare); + fileMenu.add(copy); + fileMenu.add(graph); + fileMenu.add(overlay); + fileMenu.add(new JSeparator()); + fileMenu.add(undoSel); + fileMenu.add(undoAll); + fileMenu.add(revert); + fileMenu.add(new JSeparator()); + fileMenu.add(close); + + compare.addActionListener(this); + graph.addActionListener(this); + overlay.addActionListener(this); + copy.addActionListener(this); + undoSel.addActionListener(this); + undoAll.addActionListener(this); + revert.addActionListener(this); + close.addActionListener(this); + + fileMenu.setMnemonic('F'); + compare.setMnemonic('P'); + graph.setMnemonic('G'); + overlay.setMnemonic('L'); + copy.setMnemonic('O'); + undoSel.setMnemonic('U'); + undoAll.setMnemonic('A'); + revert.setMnemonic('R'); + close.setMnemonic('C'); + + compare.setEnabled(false); + graph.setEnabled(false); + overlay.setEnabled(false); + copy.setEnabled(false); + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource() == undoAll) { + table.undoAll(); + System.out.println("undo"); + } else if (e.getSource() == revert) { + table.setRevertPoint(); + } else if (e.getSource() == undoSel) { + table.undoSelected(); + } else if (e.getSource() == close) { + table.getFrame().setVisible(false); + } + } +} \ No newline at end of file diff --git a/src/Enginuity/SwingComponents/TableToolBar.java b/src/Enginuity/SwingComponents/TableToolBar.java new file mode 100644 index 00000000..ce237e8a --- /dev/null +++ b/src/Enginuity/SwingComponents/TableToolBar.java @@ -0,0 +1,37 @@ +package Enginuity.SwingComponents; + +import Enginuity.Maps.Table; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import javax.swing.JButton; +import javax.swing.JToolBar; + +public class TableToolBar extends JToolBar implements MouseListener { + + private JButton increment = new JButton(" + "); + private JButton decrement = new JButton(" - "); + private Table table; + + public TableToolBar(Table table) { + this.table = table; + this.setFloatable(false); + this.add(increment); + this.add(decrement); + increment.addMouseListener(this); + decrement.addMouseListener(this); + } + + public void mouseClicked(MouseEvent e) { + if (e.getSource() == increment) { + table.increment(); + } else if (e.getSource() == decrement) { + table.decrement(); + } + table.colorize(); + } + + public void mousePressed(MouseEvent e) { } + public void mouseReleased(MouseEvent e) { } + public void mouseEntered(MouseEvent e) { } + public void mouseExited(MouseEvent e) { } +} \ No newline at end of file diff --git a/src/Enginuity/SwingComponents/VTextIcon.java b/src/Enginuity/SwingComponents/VTextIcon.java new file mode 100644 index 00000000..14ff7dc2 --- /dev/null +++ b/src/Enginuity/SwingComponents/VTextIcon.java @@ -0,0 +1,296 @@ +package Enginuity.SwingComponents; + +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 VTextIcon for the specified component + * with the specified label. + * 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 VTextIcon for the specified component + * with the specified label. + * 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; +} diff --git a/src/Enginuity/TestDrivers/ByteArrayTest.java b/src/Enginuity/TestDrivers/ByteArrayTest.java new file mode 100644 index 00000000..39311669 --- /dev/null +++ b/src/Enginuity/TestDrivers/ByteArrayTest.java @@ -0,0 +1,18 @@ +package Enginuity.TestDrivers; + +import Enginuity.Maps.Table; +import Enginuity.Maps.XML.RomAttributeParser; + +public class ByteArrayTest { + + public ByteArrayTest() { + } + + public static void main(String args[]) { + int testValue = 2230; + System.out.println("Test value: " + testValue); + byte[] output = RomAttributeParser.parseIntegerValue(testValue, Table.ENDIAN_LITTLE, 2); + System.out.println((output[0] & 0xff) + " " + (output[1] & 0xff)); + System.out.println(RomAttributeParser.parseByteValue(output, Table.ENDIAN_LITTLE, 0, 2)); + } +} \ No newline at end of file diff --git a/src/Enginuity/TestDrivers/JEPTestDriver.java b/src/Enginuity/TestDrivers/JEPTestDriver.java new file mode 100644 index 00000000..24ba55db --- /dev/null +++ b/src/Enginuity/TestDrivers/JEPTestDriver.java @@ -0,0 +1,31 @@ +package Enginuity.TestDrivers; + +import org.nfunk.jep.*; +import org.nfunk.jep.type.*; + +public class JEPTestDriver { + + private JEP myParser = new JEP(); + + public JEPTestDriver() { + + String expression = "14.7/(1 + (x / 128))"; + double xValue = 255; + + myParser.initSymTab(); // clear the contents of the symbol table + myParser.addStandardConstants(); + myParser.addComplex(); // among other things adds i to the symbol table + myParser.addVariable("x", xValue); + myParser.parseExpression(expression); + double result = myParser.getValue(); + + System.out.println(expression); + System.out.println("x = " + xValue); + System.out.println(result); + + } + + public static void main(String[] args) { + new JEPTestDriver(); + } +} \ No newline at end of file diff --git a/src/Enginuity/TestDrivers/TreeExample.java b/src/Enginuity/TestDrivers/TreeExample.java new file mode 100644 index 00000000..e3823607 --- /dev/null +++ b/src/Enginuity/TestDrivers/TreeExample.java @@ -0,0 +1,48 @@ +package Enginuity.TestDrivers; + +// Imports +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.tree.TreeNode; + +class TreeExample + extends JFrame + { + // Instance attributes used in this example + private JPanel topPanel; + private JTree tree; + private JScrollPane scrollPane; + + // Constructor of main frame + public TreeExample() + { + // Set the frame characteristics + setTitle( "Simple Tree Application" ); + setSize( 300, 300 ); + setBackground( Color.gray ); + + // Create a panel to hold all other components + topPanel = new JPanel(); + topPanel.setLayout( new BorderLayout() ); + getContentPane().add( topPanel ); + + // Create a new tree control + tree = new JTree(); + + //tree.add(new JTreeNode(); + + // Add the listbox to a scrolling pane + scrollPane = new JScrollPane(); + scrollPane.getViewport().add( tree ); + topPanel.add( scrollPane, BorderLayout.CENTER ); + } + + // Main entry point for this example + public static void main( String args[] ) + { + // Create an instance of the test application + TreeExample mainFrame = new TreeExample(); + mainFrame.setVisible( true ); + } +} \ No newline at end of file diff --git a/src/Enginuity/TestDrivers/XMLTestDriver.java b/src/Enginuity/TestDrivers/XMLTestDriver.java new file mode 100644 index 00000000..3b2d9e8f --- /dev/null +++ b/src/Enginuity/TestDrivers/XMLTestDriver.java @@ -0,0 +1,45 @@ +// Just a driver to test the XML parser + +package Enginuity.TestDrivers; + +import Enginuity.Maps.Rom; +import Enginuity.Maps.ECUDefinitionCollection; +import java.io.File; +import java.io.FileInputStream; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; +import com.sun.org.apache.xerces.internal.parsers.DOMParser; + +public class XMLTestDriver { + + public static void main(String[] args) { + /*ECUDefinitionCollection roms = null; + + try { + + // Parse XML + System.out.println("Parsing XML..."); + InputSource src = new InputSource(new FileInputStream(new File("./ecu_defs.xml"))); + + DOMRomUnmarshaller domUms = new DOMRomUnmarshaller(); + DOMParser parser = new DOMParser(); + parser.parse(src); + Document doc = parser.getDocument(); + + roms = domUms.unmarshallXMLDefinition(doc.getDocumentElement()); + System.out.println(roms.toString()); + + // Open image and find ECU version + System.out.println("Opening Image..."); + Rom ecuImage = roms.parseRom(new File("./A4TF400E.hex")); + + String output = ecuImage.getRomIDString(); + System.out.println("Found ECU Version: " + output); + System.out.println("Done."); + + } catch(Exception e) { + System.err.println("Exception: " + e); + }*/ + System.out.println(Double.parseDouble("-12")); + } +} \ No newline at end of file