auto-sync

This commit is contained in:
rusEfi 2015-01-18 20:04:16 -06:00
parent 3b96cfc360
commit b3bca9752c
2 changed files with 38 additions and 21 deletions

View File

@ -7,15 +7,19 @@ import com.rusefi.io.CommandQueue;
import com.rusefi.io.InvocationConfirmationListener;
import com.rusefi.trigger.TriggerShapeHolder;
import com.rusefi.ui.widgets.UpDownImage;
import com.sun.awt.AWTUtilities;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.Date;
import java.util.concurrent.atomic.AtomicReference;
/**
* 1/17/2015
*/
public class Wizard {
private final JPanel panel = new JPanel(new BorderLayout());
private final JPanel content = new JPanel();
private final JButton button = new JButton("Trigger Wizard");
@ -47,7 +51,12 @@ public class Wizard {
CommandQueue.getInstance().write(command, CommandQueue.DEFAULT_TIMEOUT, new InvocationConfirmationListener() {
@Override
public void onCommandConfirmation() {
applyStep(nextStep);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
applyStep(nextStep);
}
});
}
});
@ -84,7 +93,6 @@ public class Wizard {
}
public Component createPane() {
JPanel panel = new JPanel(new BorderLayout());
panel.add(button, BorderLayout.NORTH);
panel.add(content, BorderLayout.CENTER);
@ -95,21 +103,20 @@ public class Wizard {
button.setEnabled(false);
applyStep(Wizard.this.TRIGGER_WIZARD_HELLO);
}
});
return panel;
}
private void applyStep(WizardStep step) {
Component newContent = getNextContent(step);
System.out.println(new Date() + " apply " + step);
Component newContent = getContent(step);
content.removeAll();
this.content.add(newContent);
UpDownImage.trueRepaint(content);
content.add(newContent);
UpDownImage.trueLayout(content);
}
private Component getNextContent(WizardStep step) {
private Component getContent(WizardStep step) {
Component newContent;
if (step == null) {
newContent = new JLabel("Wizard is done!");
@ -121,23 +128,31 @@ public class Wizard {
}
private class WaitForZeroRpm extends WizardStepImpl {
public WaitForZeroRpm() {
}
private int counter;
@Override
public Component getContent() {
double rpm = SensorCentral.getInstance().getValue(Sensor.RPM);
if (rpm == 0) {
return getNextContent(nextStep);
return Wizard.this.getContent(nextStep);
}
scheduleRepaint(1000, this);
if (rpm != 0) {
return new JLabel("Current RPM: " + rpm + ", please stop the engine");
}
return null;
return new JLabel("Current RPM: " + rpm + ", please stop the engine. Waiting " + counter++);
}
}
private void scheduleRepaint(int timeoutMs, final WizardStep step) {
final AtomicReference<Timer> tHolder = new AtomicReference<>();
Timer t = new Timer(timeoutMs, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
tHolder.get().stop();
applyStep(step);
}
});
tHolder.set(t);
t.start();
}
}

View File

@ -75,10 +75,11 @@ public class UpDownImage extends JPanel {
}
public static void trueRepaint(Container control) {
if (control == null)
return;
control.invalidate();
control.repaint();
trueLayout(control);
// if (control == null)
// return;
// control.invalidate();
// control.repaint();
}
/**
@ -89,6 +90,7 @@ public class UpDownImage extends JPanel {
return;
component.invalidate();
component.validate();
component.repaint();
}
public UpDownImage(WaveReport wr, String name) {