auto-sync
This commit is contained in:
parent
ae8d49c435
commit
84474c5281
|
@ -32,7 +32,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
|
||||||
* @see com.rusefi.StartupFrame
|
* @see com.rusefi.StartupFrame
|
||||||
*/
|
*/
|
||||||
public class Launcher {
|
public class Launcher {
|
||||||
public static final int CONSOLE_VERSION = 20151026;
|
public static final int CONSOLE_VERSION = 20151117;
|
||||||
public static final boolean SHOW_STIMULATOR = false;
|
public static final boolean SHOW_STIMULATOR = false;
|
||||||
private static final String TAB_INDEX = "main_tab";
|
private static final String TAB_INDEX = "main_tab";
|
||||||
protected static final String PORT_KEY = "port";
|
protected static final String PORT_KEY = "port";
|
||||||
|
|
|
@ -7,9 +7,10 @@ import com.rusefi.maintenance.EraseChip;
|
||||||
import com.rusefi.maintenance.FirmwareFlasher;
|
import com.rusefi.maintenance.FirmwareFlasher;
|
||||||
import com.rusefi.maintenance.ProcessStatusWindow;
|
import com.rusefi.maintenance.ProcessStatusWindow;
|
||||||
import com.rusefi.ui.util.HorizontalLine;
|
import com.rusefi.ui.util.HorizontalLine;
|
||||||
import com.rusefi.ui.util.UiUtils;
|
|
||||||
import com.rusefi.ui.util.URLLabel;
|
import com.rusefi.ui.util.URLLabel;
|
||||||
|
import com.rusefi.ui.util.UiUtils;
|
||||||
import jssc.SerialPortList;
|
import jssc.SerialPortList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.putgemin.VerticalFlowLayout;
|
import org.putgemin.VerticalFlowLayout;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
@ -41,6 +42,25 @@ public class StartupFrame {
|
||||||
private static final String URI = "http://rusefi.com/?java_console";
|
private static final String URI = "http://rusefi.com/?java_console";
|
||||||
|
|
||||||
private final JFrame frame;
|
private final JFrame frame;
|
||||||
|
private final Timer scanPortsTimes = new Timer(1000, new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
findAndApplyPorts();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
private final JPanel connectPanel = new JPanel(new FlowLayout());
|
||||||
|
// todo: move this line to the connectPanel
|
||||||
|
private HorizontalLine horizontalLine = new HorizontalLine();
|
||||||
|
private final JComboBox<String> comboPorts = new JComboBox<>();
|
||||||
|
@NotNull
|
||||||
|
private List<String> currentlyDisplayedPorts = new ArrayList<>();
|
||||||
|
private boolean isFirstTimeApplyingPorts = true;
|
||||||
|
JPanel leftPanel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this flag tells us if we are closing the startup frame in order to proceed with console start or if we are
|
||||||
|
* closing the application.
|
||||||
|
*/
|
||||||
private boolean isProceeding;
|
private boolean isProceeding;
|
||||||
|
|
||||||
public StartupFrame() {
|
public StartupFrame() {
|
||||||
|
@ -54,6 +74,7 @@ public class StartupFrame {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setAppIcon(frame);
|
setAppIcon(frame);
|
||||||
|
scanPortsTimes.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setAppIcon(JFrame frame) {
|
public static void setAppIcon(JFrame frame) {
|
||||||
|
@ -63,20 +84,29 @@ public class StartupFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void chooseSerialPort() {
|
public void chooseSerialPort() {
|
||||||
List<String> ports = new ArrayList<>();
|
|
||||||
ports.addAll(Arrays.asList(SerialPortList.getPortNames()));
|
|
||||||
ports.addAll(TcpConnector.getAvailablePorts());
|
|
||||||
|
|
||||||
JPanel leftPanel = new JPanel(new VerticalFlowLayout());
|
leftPanel = new JPanel(new VerticalFlowLayout());
|
||||||
leftPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10),
|
leftPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10),
|
||||||
BorderFactory.createLineBorder(Color.darkGray)));
|
BorderFactory.createLineBorder(Color.darkGray)));
|
||||||
|
|
||||||
if (!ports.isEmpty()) {
|
connectPanel.add(comboPorts);
|
||||||
final JPanel connectPanel = new JPanel(new FlowLayout());
|
final JComboBox<String> comboSpeeds = createSpeedCombo();
|
||||||
addPortSelection(ports, connectPanel);
|
|
||||||
leftPanel.add(connectPanel);
|
final JButton connect = new JButton("Connect");
|
||||||
leftPanel.add(new HorizontalLine());
|
connectPanel.add(connect);
|
||||||
|
connect.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
disposeFrameAndProceed();
|
||||||
|
PortHolder.BAUD_RATE = Integer.parseInt((String) comboSpeeds.getSelectedItem());
|
||||||
|
new Launcher(comboPorts.getSelectedItem().toString());
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
leftPanel.add(connectPanel);
|
||||||
|
leftPanel.add(horizontalLine);
|
||||||
|
|
||||||
|
findAndApplyPorts();
|
||||||
|
|
||||||
final JButton buttonLogViewer = new JButton();
|
final JButton buttonLogViewer = new JButton();
|
||||||
buttonLogViewer.setText("Start " + LinkManager.LOG_VIEWER);
|
buttonLogViewer.setText("Start " + LinkManager.LOG_VIEWER);
|
||||||
|
@ -123,32 +153,40 @@ public class StartupFrame {
|
||||||
UiUtils.centerWindow(frame);
|
UiUtils.centerWindow(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void findAndApplyPorts() {
|
||||||
|
List<String> ports = findAllAvailablePorts();
|
||||||
|
if (!currentlyDisplayedPorts.equals(ports) || isFirstTimeApplyingPorts) {
|
||||||
|
isFirstTimeApplyingPorts = false;
|
||||||
|
connectPanel.setVisible(!ports.isEmpty());
|
||||||
|
// panel.add(comboSpeeds); // todo: finish speed selector UI component
|
||||||
|
horizontalLine.setVisible(!ports.isEmpty());
|
||||||
|
|
||||||
|
addPortSelection(ports);
|
||||||
|
currentlyDisplayedPorts = ports;
|
||||||
|
UiUtils.trueLayout(connectPanel);
|
||||||
|
frame.pack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private List<String> findAllAvailablePorts() {
|
||||||
|
List<String> ports = new ArrayList<>();
|
||||||
|
ports.addAll(Arrays.asList(SerialPortList.getPortNames()));
|
||||||
|
ports.addAll(TcpConnector.getAvailablePorts());
|
||||||
|
return ports;
|
||||||
|
}
|
||||||
|
|
||||||
public void disposeFrameAndProceed() {
|
public void disposeFrameAndProceed() {
|
||||||
isProceeding = true;
|
isProceeding = true;
|
||||||
frame.dispose();
|
frame.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPortSelection(List<String> ports, JPanel panel) {
|
private void addPortSelection(List<String> ports) {
|
||||||
final JComboBox<String> comboPorts = new JComboBox<>();
|
comboPorts.removeAll();
|
||||||
for (final String port : ports)
|
for (final String port : ports)
|
||||||
comboPorts.addItem(port);
|
comboPorts.addItem(port);
|
||||||
panel.add(comboPorts);
|
|
||||||
String defaultPort = getConfig().getRoot().getProperty(Launcher.PORT_KEY);
|
String defaultPort = getConfig().getRoot().getProperty(Launcher.PORT_KEY);
|
||||||
comboPorts.setSelectedItem(defaultPort);
|
comboPorts.setSelectedItem(defaultPort);
|
||||||
|
|
||||||
final JComboBox<String> comboSpeeds = createSpeedCombo();
|
|
||||||
// panel.add(comboSpeeds);
|
|
||||||
|
|
||||||
final JButton connect = new JButton("Connect");
|
|
||||||
panel.add(connect);
|
|
||||||
connect.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
disposeFrameAndProceed();
|
|
||||||
PortHolder.BAUD_RATE = Integer.parseInt((String) comboSpeeds.getSelectedItem());
|
|
||||||
new Launcher(comboPorts.getSelectedItem().toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JComboBox<String> createSpeedCombo() {
|
private static JComboBox<String> createSpeedCombo() {
|
||||||
|
|
Loading…
Reference in New Issue