Search in sources :

Example 76 with Timer

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();
}
Also used : Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) SerialMessage(jmri.jmrix.cmri.serial.SerialMessage) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 77 with Timer

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();
}
Also used : Timer(javax.swing.Timer) ActionEvent(java.awt.event.ActionEvent)

Example 78 with Timer

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);
}
Also used : Timer(javax.swing.Timer)

Example 79 with Timer

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);
    }
}
Also used : Timer(javax.swing.Timer) ActionEvent(java.awt.event.ActionEvent)

Example 80 with Timer

use of javax.swing.Timer in project processdash by dtuma.

the class WBSEditor method main.

public static void main(String[] args) {
    args = maybeParseJnlpArgs(args);
    if (isDumpAndExitMode())
        System.setProperty("java.awt.headless", "true");
    ExternalLocationMapper.getInstance().loadDefaultMappings();
    RuntimeUtils.autoregisterPropagatedSystemProperties();
    for (String prop : PROPS_TO_PROPAGATE) RuntimeUtils.addPropagatedSystemProperty(prop, null);
    String[] locations = args;
    boolean bottomUp = Boolean.getBoolean("teamdash.wbs.bottomUp");
    boolean indivMode = Boolean.getBoolean("teamdash.wbs.indiv");
    String indivInitials = System.getProperty("teamdash.wbs.indivInitials");
    boolean showTeam = Boolean.getBoolean("teamdash.wbs.showTeamMemberList");
    boolean readOnly = Boolean.getBoolean("teamdash.wbs.readOnly") || TeamServerSelector.isHistoricalModeEnabled();
    String syncURL = System.getProperty("teamdash.wbs.syncURL");
    String itemHref = System.getProperty("teamdash.wbs.showItem");
    String owner = System.getProperty("teamdash.wbs.owner");
    try {
        createAndShowEditor(locations, bottomUp, indivMode, indivInitials, showTeam, syncURL, true, readOnly, itemHref, owner);
    } catch (HeadlessException he) {
        he.printStackTrace();
        System.exit(1);
    }
    new Timer(DAY_MILLIS, new UsageLogAction()).start();
    maybeNotifyOpened();
}
Also used : HeadlessException(java.awt.HeadlessException) Timer(javax.swing.Timer)

Aggregations

Timer (javax.swing.Timer)130 ActionEvent (java.awt.event.ActionEvent)66 ActionListener (java.awt.event.ActionListener)62 IOException (java.io.IOException)12 JPanel (javax.swing.JPanel)12 JLabel (javax.swing.JLabel)11 BorderLayout (java.awt.BorderLayout)9 Dimension (java.awt.Dimension)9 Point (java.awt.Point)9 Color (java.awt.Color)8 JCheckBox (javax.swing.JCheckBox)8 MouseEvent (java.awt.event.MouseEvent)7 JFrame (javax.swing.JFrame)7 MouseAdapter (java.awt.event.MouseAdapter)6 Window (java.awt.Window)5 JButton (javax.swing.JButton)5 JDialog (javax.swing.JDialog)5 JScrollPane (javax.swing.JScrollPane)5 File (java.io.File)4 Date (java.util.Date)4