use of javax.swing.Timer in project JMRI by JMRI.
the class VSDSound method newTimer.
protected Timer newTimer(int time, boolean repeat, ActionListener al) {
// make sure the time is > zero
time = Math.max(1, time);
t = new Timer(time, al);
t.setInitialDelay(time);
t.setRepeats(repeat);
return (t);
}
use of javax.swing.Timer in project JMRI by JMRI.
the class DiagnosticFrame method runWraparoundTest.
/**
* Local Method to run a Wraparound Test
*/
@SuppressFBWarnings(value = "SBSC_USE_STRINGBUFFER_CONCATENATION")
protected // though it would be good to fix it if you're working in this area
void runWraparoundTest() {
// Display Status Message
statusText1.setText("Running Wraparound Test");
statusText1.setVisible(true);
// Set up timer to update output pattern periodically
wrapTimer = new Timer(100, new ActionListener() {
@Override
public void actionPerformed(ActionEvent evnt) {
if (testRunning && !testSuspended) {
if (waitingOnInput) {
count--;
if (count == 0) {
statusText2.setText("Time Out Error - no response after 5 seconds.");
statusText2.setVisible(true);
}
} else {
// compare input with previous output if needed
if (needInputTest) {
needInputTest = false;
boolean comparisonError = false;
// compare input and output bytes
int j = 0;
for (int i = begInByte; i <= endInByte; i++, j++) {
if (inBytes[i] != wrapBytes[j]) {
comparisonError = true;
}
}
if (comparisonError) {
// report error and suspend test
statusText1.setText("Test Suspended for Error - Stop or Continue?");
statusText1.setVisible(true);
StringBuilder st = new StringBuilder("Compare Error - Out Bytes (hex):");
for (int i = begOutByte; i <= endOutByte; i++) {
st.append(" ");
st.append(Integer.toHexString((outBytes[i]) & 0x000000ff));
}
st.append(" In Bytes (hex):");
for (int i = begInByte; i <= endInByte; i++) {
st.append(" ");
st.append(Integer.toHexString((inBytes[i]) & 0x000000ff));
}
statusText2.setText(new String(st));
statusText2.setVisible(true);
numErrors++;
testSuspended = true;
return;
}
}
// send next output pattern
outBytes[curOutByte] = (byte) curOutValue;
if (isSMINI) {
// If SMINI, send same pattern to both output cards
if (curOutByte > 2) {
outBytes[curOutByte - 3] = (byte) curOutValue;
} else {
outBytes[curOutByte + 3] = (byte) curOutValue;
}
}
SerialMessage m = createOutPacket();
// wait for signal to settle down if filter delay
m.setTimeout(50 + filterDelay);
_memo.getTrafficController().sendSerialMessage(m, curFrame);
// update Status area
short[] outBitPattern = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
String[] portID = { "A", "B", "C", "D" };
StringBuilder st = new StringBuilder("Port: ");
st.append(portID[curOutByte - begOutByte]);
st.append(", Pattern: ");
for (int j = 0; j < 8; j++) {
if ((curOutValue & outBitPattern[j]) != 0) {
st.append("X ");
} else {
st.append("O ");
}
}
statusText2.setText(new String(st));
statusText2.setVisible(true);
// set up for testing input returned
int k = 0;
for (int i = begOutByte; i <= endOutByte; i++, k++) {
wrapBytes[k] = outBytes[i];
}
waitingOnInput = true;
needInputTest = true;
count = 50;
// send poll
_memo.getTrafficController().sendSerialMessage(SerialMessage.getPoll(ua), curFrame);
// update output pattern for next entry
curOutValue++;
if (curOutValue > 255) {
// Move to the next byte
curOutValue = 0;
outBytes[curOutByte] = 0;
if (isSMINI) {
// If SMINI, clear ports of both output cards
if (curOutByte > 2) {
outBytes[curOutByte - 3] = 0;
} else {
outBytes[curOutByte + 3] = 0;
}
}
curOutByte++;
if (curOutByte > endOutByte) {
// Pattern complete, recycle to first port (byte)
curOutByte = begOutByte;
numIterations++;
}
}
}
}
}
});
// start timer
wrapTimer.start();
}
use of javax.swing.Timer in project JMRI by JMRI.
the class SensorIcon method flashSensor.
public synchronized void flashSensor(int tps, int state1, int state2) {
if ((flashTimer != null) && flashTimer.isRunning()) {
return;
}
//Set the maximum number of state changes to 10 per second
if (tps > 10) {
tps = 10;
} else if (tps <= 0) {
return;
}
if ((_state2nameMap.get(state1) == null) || _state2nameMap.get(state2) == null) {
log.error("one or other of the states passed for flash is null");
return;
} else if (state1 == state2) {
log.debug("Both states to flash between are the same, therefore no flashing will occur");
return;
}
int interval = (1000 / tps) / 2;
flashStateOn = state1;
flashStateOff = state2;
if (taskPerformer == null) {
taskPerformer = (ActionEvent evt) -> {
if (flashon) {
flashon = false;
displayState(flashStateOn);
} else {
flashon = true;
displayState(flashStateOff);
}
};
}
flashTimer = new Timer(interval, taskPerformer);
flashTimer.start();
}
use of javax.swing.Timer in project JMRI by JMRI.
the class EngineSound method newTimer.
@Override
protected Timer newTimer(int time, boolean repeat, ActionListener al) {
t = new Timer(time, al);
t.setRepeats(repeat);
return (t);
}
use of javax.swing.Timer in project JMRI by JMRI.
the class ProfileManagerDialog method formWindowOpened.
//GEN-LAST:event_btnUseExistingActionPerformed
private void formWindowOpened(WindowEvent evt) {
//GEN-FIRST:event_formWindowOpened
countDown = ProfileManager.getDefault().getAutoStartActiveProfileTimeout();
countDownLbl.setText(Integer.toString(countDown));
timer = new Timer(1000, (ActionEvent e) -> {
if (countDown > 0) {
countDown--;
countDownLbl.setText(Integer.toString(countDown));
} else {
setVisible(false);
ProfileManager.getDefault().setActiveProfile(profiles.getSelectedValue());
log.info("Automatically starting with profile " + ProfileManager.getDefault().getActiveProfile().getId() + " after timeout.");
timer.stop();
countDown = -1;
dispose();
}
});
timer.setRepeats(true);
if (profiles.getModel().getSize() > 0 && null != ProfileManager.getDefault().getActiveProfile() && countDown > 0) {
timer.start();
} else {
countDownLbl.setVisible(false);
btnSelect.setEnabled(false);
}
}
Aggregations