auto-sync

This commit is contained in:
rusEfi 2015-02-03 11:06:06 -06:00
parent b9eb97d485
commit 8facb8491a
5 changed files with 54 additions and 16 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -20,10 +20,11 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
* 12/25/12 * 12/25/12
* (c) Andrey Belomutskiy 2013-2015 * (c) Andrey Belomutskiy 2013-2015
* *
* @see PortLookupFrame
* @see WavePanel * @see WavePanel
*/ */
public class Launcher extends FrameHelper { public class Launcher extends FrameHelper {
public static final int CONSOLE_VERSION = 20150130; public static final int CONSOLE_VERSION = 20150203;
public static final boolean SHOW_STIMULATOR = true; public static final boolean SHOW_STIMULATOR = true;
public static final String TAB_INDEX = "main_tab"; public static final String TAB_INDEX = "main_tab";
private final String port; private final String port;
@ -67,6 +68,7 @@ public class Launcher extends FrameHelper {
tabbedPane.setSelectedIndex(selectedIndex); tabbedPane.setSelectedIndex(selectedIndex);
} }
PortLookupFrame.setAppIcon(frame);
showFrame(tabbedPane); showFrame(tabbedPane);
} }
@ -124,7 +126,7 @@ public class Launcher extends FrameHelper {
} else { } else {
for (String p : SerialPortList.getPortNames()) for (String p : SerialPortList.getPortNames())
MessagesCentral.getInstance().postMessage(Launcher.class, "Available port: " + p); MessagesCentral.getInstance().postMessage(Launcher.class, "Available port: " + p);
PortLookupFrame.chooseSerialPort(); new PortLookupFrame().chooseSerialPort();
} }
} catch (Throwable e) { } catch (Throwable e) {

View File

@ -11,6 +11,9 @@ import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -23,17 +26,38 @@ import java.util.List;
* 2/14/14 * 2/14/14
*/ */
public class PortLookupFrame { public class PortLookupFrame {
// todo: figure out a better way to work with absolute path
public static final String APPICON_PNG = "../../appicon.png";
private static final String LINK_TEXT = "rusEfi (c) 2012-2015";
private static final String URI = "http://rusefi.com/?java_console";
public static final String RUS_EFI_C_2012_2014 = "rusEfi (c) 2012-2015"; private final JFrame frame;
public static final String URI = "http://rusefi.com/?java_console"; private boolean isProceeding;
public static void chooseSerialPort() { public PortLookupFrame() {
frame = new JFrame(Launcher.CONSOLE_VERSION + ": Serial port selection");
frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent ev) {
if (!isProceeding)
System.exit(0);
}
});
setAppIcon(frame);
}
public static void setAppIcon(JFrame frame) {
ImageIcon icon = loadIcon(APPICON_PNG);
if (icon != null)
frame.setIconImage(icon.getImage());
}
public void chooseSerialPort() {
List<String> ports = new ArrayList<>(); List<String> ports = new ArrayList<>();
ports.addAll(Arrays.asList(SerialPortList.getPortNames())); ports.addAll(Arrays.asList(SerialPortList.getPortNames()));
ports.addAll(TcpConnector.getAvailablePorts()); ports.addAll(TcpConnector.getAvailablePorts());
final JFrame frame = new JFrame(Launcher.CONSOLE_VERSION + ": Serial port selection");
JPanel content = new JPanel(new BorderLayout()); JPanel content = new JPanel(new BorderLayout());
final JPanel upperPanel = new JPanel(new FlowLayout()); final JPanel upperPanel = new JPanel(new FlowLayout());
@ -46,7 +70,7 @@ public class PortLookupFrame {
buttonLogViewer.addActionListener(new ActionListener() { buttonLogViewer.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
frame.dispose(); disposeFrameAndProceed();
new Launcher(LinkManager.LOG_VIEWER); new Launcher(LinkManager.LOG_VIEWER);
} }
}); });
@ -54,11 +78,11 @@ public class PortLookupFrame {
upperPanel.add(buttonLogViewer); upperPanel.add(buttonLogViewer);
JPanel centerPanel = new JPanel(new FlowLayout()); JPanel centerPanel = new JPanel(new FlowLayout());
centerPanel.add(SimulatorHelper.createSimulatorComponent(frame)); centerPanel.add(SimulatorHelper.createSimulatorComponent(this));
JPanel lowerPanel = new JPanel(new FlowLayout()); JPanel lowerPanel = new JPanel(new FlowLayout());
lowerPanel.add(new URLLabel(RUS_EFI_C_2012_2014, URI)); lowerPanel.add(new URLLabel(LINK_TEXT, URI));
content.add(upperPanel, BorderLayout.NORTH); content.add(upperPanel, BorderLayout.NORTH);
content.add(centerPanel, BorderLayout.CENTER); content.add(centerPanel, BorderLayout.CENTER);
content.add(lowerPanel, BorderLayout.SOUTH); content.add(lowerPanel, BorderLayout.SOUTH);
@ -70,7 +94,12 @@ public class PortLookupFrame {
UiUtils.centerWindow(frame); UiUtils.centerWindow(frame);
} }
private static void addPortSelection(List<String> ports, final JFrame frame, JPanel panel) { public void disposeFrameAndProceed() {
isProceeding = true;
frame.dispose();
}
private void addPortSelection(List<String> ports, final JFrame frame, JPanel panel) {
final JComboBox<String> comboPorts = new JComboBox<>(); final JComboBox<String> comboPorts = new JComboBox<>();
for (final String port : ports) for (final String port : ports)
comboPorts.addItem(port); comboPorts.addItem(port);
@ -81,9 +110,17 @@ public class PortLookupFrame {
connect.addActionListener(new ActionListener() { connect.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
frame.dispose(); disposeFrameAndProceed();
new Launcher(comboPorts.getSelectedItem().toString()); new Launcher(comboPorts.getSelectedItem().toString());
} }
}); });
} }
public static ImageIcon loadIcon(String strPath) {
URL imgURL = PortLookupFrame.class.getResource(strPath);
if (imgURL != null)
return new ImageIcon(imgURL);
else
return null;
}
} }

View File

@ -43,24 +43,22 @@ public class SimulatorHelper {
} }
public static JComponent createSimulatorComponent(final JFrame frame) { public static JComponent createSimulatorComponent(final PortLookupFrame portSelector) {
if (!SimulatorHelper.isBinaryHere()) if (!SimulatorHelper.isBinaryHere())
return new JLabel(SimulatorHelper.BINARY + " not found"); return new JLabel(SimulatorHelper.BINARY + " not found");
if (TcpConnector.isTcpPortOpened()) if (TcpConnector.isTcpPortOpened())
return new JLabel("Port " + TcpConnector.DEFAULT_PORT + " already busy. Simulator running?"); return new JLabel("Port " + TcpConnector.DEFAULT_PORT + " already busy. Simulator running?");
JButton simulatorButton = new JButton("Start Simulator"); JButton simulatorButton = new JButton("Start Simulator");
simulatorButton.addActionListener(new ActionListener() { simulatorButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
frame.dispose(); portSelector.disposeFrameAndProceed();
startSimulator(); startSimulator();
} }
}); });
return simulatorButton; return simulatorButton;
} }

View File

@ -4,6 +4,7 @@
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />