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.io.InvocationConfirmationListener;
import com.rusefi.trigger.TriggerShapeHolder; import com.rusefi.trigger.TriggerShapeHolder;
import com.rusefi.ui.widgets.UpDownImage; import com.rusefi.ui.widgets.UpDownImage;
import com.sun.awt.AWTUtilities;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.util.Date;
import java.util.concurrent.atomic.AtomicReference;
/** /**
* 1/17/2015 * 1/17/2015
*/ */
public class Wizard { public class Wizard {
private final JPanel panel = new JPanel(new BorderLayout());
private final JPanel content = new JPanel(); private final JPanel content = new JPanel();
private final JButton button = new JButton("Trigger Wizard"); private final JButton button = new JButton("Trigger Wizard");
@ -47,7 +51,12 @@ public class Wizard {
CommandQueue.getInstance().write(command, CommandQueue.DEFAULT_TIMEOUT, new InvocationConfirmationListener() { CommandQueue.getInstance().write(command, CommandQueue.DEFAULT_TIMEOUT, new InvocationConfirmationListener() {
@Override @Override
public void onCommandConfirmation() { 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() { public Component createPane() {
JPanel panel = new JPanel(new BorderLayout());
panel.add(button, BorderLayout.NORTH); panel.add(button, BorderLayout.NORTH);
panel.add(content, BorderLayout.CENTER); panel.add(content, BorderLayout.CENTER);
@ -95,21 +103,20 @@ public class Wizard {
button.setEnabled(false); button.setEnabled(false);
applyStep(Wizard.this.TRIGGER_WIZARD_HELLO); applyStep(Wizard.this.TRIGGER_WIZARD_HELLO);
} }
}); });
return panel; return panel;
} }
private void applyStep(WizardStep step) { private void applyStep(WizardStep step) {
Component newContent = getNextContent(step); System.out.println(new Date() + " apply " + step);
Component newContent = getContent(step);
content.removeAll(); content.removeAll();
this.content.add(newContent); content.add(newContent);
UpDownImage.trueRepaint(content); UpDownImage.trueLayout(content);
} }
private Component getNextContent(WizardStep step) { private Component getContent(WizardStep step) {
Component newContent; Component newContent;
if (step == null) { if (step == null) {
newContent = new JLabel("Wizard is done!"); newContent = new JLabel("Wizard is done!");
@ -121,23 +128,31 @@ public class Wizard {
} }
private class WaitForZeroRpm extends WizardStepImpl { private class WaitForZeroRpm extends WizardStepImpl {
public WaitForZeroRpm() { private int counter;
}
@Override @Override
public Component getContent() { public Component getContent() {
double rpm = SensorCentral.getInstance().getValue(Sensor.RPM); double rpm = SensorCentral.getInstance().getValue(Sensor.RPM);
if (rpm == 0) { 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. Waiting " + counter++);
return new JLabel("Current RPM: " + rpm + ", please stop the engine");
}
return null;
} }
} }
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) { public static void trueRepaint(Container control) {
if (control == null) trueLayout(control);
return; // if (control == null)
control.invalidate(); // return;
control.repaint(); // control.invalidate();
// control.repaint();
} }
/** /**
@ -89,6 +90,7 @@ public class UpDownImage extends JPanel {
return; return;
component.invalidate(); component.invalidate();
component.validate(); component.validate();
component.repaint();
} }
public UpDownImage(WaveReport wr, String name) { public UpDownImage(WaveReport wr, String name) {