updated ramtune test app

git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@637 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
kascade 2007-04-19 23:32:21 +00:00
parent ee8d191bd7
commit 0796ab184f
2 changed files with 122 additions and 28 deletions

View File

@ -890,6 +890,7 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
EcuLogger ecuLogger = new EcuLogger(settings); EcuLogger ecuLogger = new EcuLogger(settings);
// set remaining window properties // set remaining window properties
ecuLogger.pack();
ecuLogger.setSize(settings.getLoggerWindowSize()); ecuLogger.setSize(settings.getLoggerWindowSize());
ecuLogger.setIconImage(new ImageIcon("./graphics/enginuity-ico.gif").getImage()); ecuLogger.setIconImage(new ImageIcon("./graphics/enginuity-ico.gif").getImage());
ecuLogger.setDefaultCloseOperation(defaultCloseOperation); ecuLogger.setDefaultCloseOperation(defaultCloseOperation);

View File

@ -10,24 +10,31 @@ import static enginuity.util.ThreadUtil.sleep;
import static javax.swing.BorderFactory.createLoweredBevelBorder; import static javax.swing.BorderFactory.createLoweredBevelBorder;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import static javax.swing.JOptionPane.ERROR_MESSAGE; import static javax.swing.JOptionPane.ERROR_MESSAGE;
import static javax.swing.JOptionPane.showMessageDialog; import static javax.swing.JOptionPane.showMessageDialog;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane;
import static javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER;
import static javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;
import static javax.swing.border.BevelBorder.LOWERED;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import static java.awt.BorderLayout.CENTER;
import static java.awt.BorderLayout.NORTH;
import static java.awt.BorderLayout.SOUTH;
import static java.awt.BorderLayout.WEST; import static java.awt.BorderLayout.WEST;
import java.awt.Component; import java.awt.Component;
import java.awt.FlowLayout; import java.awt.FlowLayout;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import static java.awt.GridBagConstraints.BOTH;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
@ -40,13 +47,13 @@ import java.io.Writer;
* This is a test app! Use at your own risk!! * This is a test app! Use at your own risk!!
* It borrows some functionality from the logger which should be rewritten/removed before being released!! * It borrows some functionality from the logger which should be rewritten/removed before being released!!
*/ */
public final class RamWriter extends JFrame implements WindowListener { public final class RamTuneTestApp extends JFrame implements WindowListener {
private Settings settings = new Settings(); private Settings settings = new Settings();
private SerialPortComboBox portsComboBox = new SerialPortComboBox(settings); private SerialPortComboBox portsComboBox = new SerialPortComboBox(settings);
private JLabel messageLabel = new JLabel(); private JLabel messageLabel = new JLabel();
private JLabel connectionStatusLabel = new JLabel(); private JLabel connectionStatusLabel = new JLabel();
public RamWriter(String title) { public RamTuneTestApp(String title) {
super(title); super(title);
initUserInterface(); initUserInterface();
startPortRefresherThread(); startPortRefresherThread();
@ -64,30 +71,114 @@ public final class RamWriter extends JFrame implements WindowListener {
private void initUserInterface() { private void initUserInterface() {
// setup main panel // setup main panel
JPanel mainPanel = new JPanel(new BorderLayout()); JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(buildControlToolbar(), NORTH); JPanel contentPanel = buildContentPanel();
mainPanel.add(buildInputPanel(), CENTER); mainPanel.add(contentPanel, BorderLayout.CENTER);
mainPanel.add(buildStatusBar(), SOUTH); mainPanel.add(buildStatusBar(), BorderLayout.SOUTH);
// add to container // add to container
getContentPane().add(mainPanel); getContentPane().add(mainPanel);
} }
private JPanel buildControlToolbar() { private JPanel buildContentPanel() {
JPanel controlPanel = new JPanel(new FlowLayout()); GridBagLayout gridBagLayout = new GridBagLayout();
controlPanel.add(buildPortsComboBox()); JPanel mainPanel = new JPanel(gridBagLayout);
return controlPanel; GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = BOTH;
constraints.insets = new Insets(3, 5, 3, 5);
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 1;
constraints.weighty = 1;
mainPanel.add(buildComPortPanel(), constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 1;
constraints.weighty = 1;
mainPanel.add(buildInputPanel(), constraints);
constraints.gridx = 0;
constraints.gridy = 2;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 1;
constraints.weighty = 1;
mainPanel.add(buildOutputPanel(), constraints);
return mainPanel;
} }
private Component buildInputPanel() { private Component buildInputPanel() {
JPanel inputPanel = new JPanel(new BorderLayout(3, 3)); GridBagLayout gridBagLayout = new GridBagLayout();
inputPanel.add(new JTextField(), NORTH); JPanel inputPanel = new JPanel(gridBagLayout);
inputPanel.add(new JTextArea(10, 50), CENTER); inputPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), "ECU Command"));
inputPanel.add(buildWriteButton(), SOUTH); GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = BOTH;
constraints.insets = new Insets(0, 5, 5, 5);
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 2;
constraints.gridheight = 1;
constraints.weightx = 1;
constraints.weighty = 1;
inputPanel.add(buildCommandComboBox(), constraints);
JPanel addressPanel = new JPanel(new FlowLayout());
addressPanel.add(new JLabel("Address:"));
addressPanel.add(new JTextField(6));
addressPanel.add(new JLabel("eg. 200000"));
constraints.gridx = 3;
constraints.gridy = 0;
constraints.gridwidth = 2;
constraints.gridheight = 1;
constraints.weightx = 1;
constraints.weighty = 1;
inputPanel.add(addressPanel, constraints);
JTextArea dataField = new JTextArea(10, 30);
dataField.setLineWrap(true);
dataField.setBorder(new BevelBorder(LOWERED));
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 5;
constraints.gridheight = 1;
constraints.weightx = 1;
constraints.weighty = 1;
inputPanel.add(new JScrollPane(dataField, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER), constraints);
constraints.gridx = 0;
constraints.gridy = 2;
constraints.gridwidth = 5;
constraints.gridheight = 1;
constraints.weightx = 1;
constraints.weighty = 1;
inputPanel.add(buildSendButton(), constraints);
return inputPanel; return inputPanel;
} }
private JButton buildWriteButton() { private JComboBox buildCommandComboBox() {
JButton button = new JButton("Write to ECU"); return new JComboBox(new Object[] {"ECU Init", "Read", "Write"});
}
private Component buildOutputPanel() {
JTextArea responseField = new JTextArea(10, 30);
responseField.setLineWrap(true);
responseField.setEditable(false);
responseField.setBorder(new BevelBorder(LOWERED));
JScrollPane responseScrollPane = new JScrollPane(responseField, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER);
responseScrollPane.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), "ECU Response"));
return responseScrollPane;
}
private JButton buildSendButton() {
JButton button = new JButton("Send Command");
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
connect(); connect();
@ -112,7 +203,7 @@ public final class RamWriter extends JFrame implements WindowListener {
GridBagConstraints constraints = new GridBagConstraints(); GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.WEST; constraints.anchor = GridBagConstraints.WEST;
constraints.fill = GridBagConstraints.BOTH; constraints.fill = BOTH;
JPanel messagePanel = new JPanel(new BorderLayout()); JPanel messagePanel = new JPanel(new BorderLayout());
messagePanel.setBorder(createLoweredBevelBorder()); messagePanel.setBorder(createLoweredBevelBorder());
@ -140,11 +231,13 @@ public final class RamWriter extends JFrame implements WindowListener {
return statusBar; return statusBar;
} }
private JPanel buildPortsComboBox() { private JPanel buildComPortPanel() {
JPanel comboBoxPanel = new JPanel(new FlowLayout()); JPanel comboBoxPanel = new JPanel(new FlowLayout());
comboBoxPanel.add(new JLabel("COM Port:")); comboBoxPanel.add(new JLabel("COM Port:"));
comboBoxPanel.add(portsComboBox); comboBoxPanel.add(portsComboBox);
return comboBoxPanel; JPanel panel = new JPanel(new BorderLayout());
panel.add(comboBoxPanel, WEST);
return panel;
} }
private void reportError(Exception e) { private void reportError(Exception e) {
@ -189,13 +282,13 @@ public final class RamWriter extends JFrame implements WindowListener {
LookAndFeelManager.initLookAndFeel(); LookAndFeelManager.initLookAndFeel();
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
RamWriter ramWriter = new RamWriter("RAM Writer - Test App"); RamTuneTestApp ramTuneTestApp = new RamTuneTestApp("RAM Writer - Test App");
ramWriter.setSize(400, 400); ramTuneTestApp.setIconImage(new ImageIcon("./graphics/enginuity-ico.gif").getImage());
ramWriter.setIconImage(new ImageIcon("./graphics/enginuity-ico.gif").getImage()); ramTuneTestApp.setDefaultCloseOperation(EXIT_ON_CLOSE);
ramWriter.setDefaultCloseOperation(EXIT_ON_CLOSE); ramTuneTestApp.addWindowListener(ramTuneTestApp);
ramWriter.addWindowListener(ramWriter); ramTuneTestApp.setLocation(100, 100);
ramWriter.setLocation(100, 100); ramTuneTestApp.pack();
ramWriter.setVisible(true); ramTuneTestApp.setVisible(true);
} }
}); });
} }