Example usage for javax.swing Timer setInitialDelay

List of usage examples for javax.swing Timer setInitialDelay

Introduction

In this page you can find the example usage for javax.swing Timer setInitialDelay.

Prototype

public void setInitialDelay(int initialDelay) 

Source Link

Document

Sets the Timer's initial delay, the time in milliseconds to wait after the timer is started before firing the first event.

Usage

From source file:subterranean.crimson.server.graphics.graphs.LineChart.java

public LineChart() {

    super(new BorderLayout());

    final TimeSeriesCollection dataset = new TimeSeriesCollection(this.s1);
    final JFreeChart chart = createChart(dataset);

    Timer timer = new Timer(900, this);
    timer.setInitialDelay(0);

    // Sets background color of chart
    chart.setBackgroundPaint(Color.LIGHT_GRAY);

    // Created Chartpanel for chart area
    final ChartPanel chartPanel = new ChartPanel(chart);

    // Added chartpanel to main panel
    add(chartPanel);//from   w ww . ja v  a2 s  . c  om

    timer.start();

}

From source file:events.WindowEventDemo.java

public void windowClosing(WindowEvent e) {
    displayMessage("WindowListener method called: windowClosing.");
    //A pause so user can see the message before
    //the window actually closes.
    ActionListener task = new ActionListener() {
        boolean alreadyDisposed = false;

        public void actionPerformed(ActionEvent e) {
            if (frame.isDisplayable()) {
                alreadyDisposed = true;/*  w  w  w  .j a  va 2  s .  com*/
                frame.dispose();
            }
        }
    };
    Timer timer = new Timer(500, task); //fire every half second
    timer.setInitialDelay(2000); //first delay 2 seconds
    timer.setRepeats(false);
    timer.start();
}

From source file:Main.java

public ClockPane() {
    setLayout(new BorderLayout());
    tickTock();/* ww w.j a  v a2 s  .c  o  m*/
    add(clock);
    Timer timer = new Timer(500, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tickTock();
        }
    });
    timer.setRepeats(true);
    timer.setCoalesce(true);
    timer.setInitialDelay(0);
    timer.start();
}

From source file:WindowEventDemo.java

public void windowClosing(WindowEvent e) {
    displayMessage("WindowListener method called: windowClosing.");

    //A pause so user can see the message before
    //the window actually closes.
    ActionListener task = new ActionListener() {
        boolean alreadyDisposed = false;

        public void actionPerformed(ActionEvent e) {
            if (!alreadyDisposed) {
                alreadyDisposed = true;//from w w  w  .  j a va  2 s.co  m
                frame.dispose();
            } else { //make sure the program exits
                System.exit(0);
            }
        }
    };
    Timer timer = new Timer(500, task); //fire every half second
    timer.setInitialDelay(2000); //first delay 2 seconds
    timer.start();
}

From source file:WindowEventDemo.java

public void windowClosing(WindowEvent e) {
    displayMessage("WindowListener method called: windowClosing.");
    // A pause so user can see the message before
    // the window actually closes.
    ActionListener task = new ActionListener() {
        boolean alreadyDisposed = false;

        public void actionPerformed(ActionEvent e) {
            if (frame.isDisplayable()) {
                alreadyDisposed = true;//from w w w .j  av  a2  s .  c om
                frame.dispose();
            }
        }
    };
    Timer timer = new Timer(500, task); // fire every half second
    timer.setInitialDelay(2000); // first delay 2 seconds
    timer.setRepeats(false);
    timer.start();
}

From source file:llc.rockford.webcast.EC2Driver.java

public EC2Driver(String[] args) {
    parseCommandLine(args);/*from   www .j a  v a2 s  .c  o  m*/
    createAndShowGUI();
    applicationState = new ApplicationState(this);

    new InitializeWorker(ec2Handle.getEc2Handle(), applicationState).execute();

    Timer timer = new Timer(5000, this);
    timer.setInitialDelay(3000);
    timer.start();

    broadcaster = new StreamBroadcaster(amazonProperties);

    // add shut down hooks to terminate amazon EC2 instance
    // to prevent over billing
    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            new TerminateInstanceWorker(ec2Handle.getEc2Handle(), applicationState, amazonProperties).execute();
        }
    });

}

From source file:SplashScreen.java

/**
 * Open the splash screen and keep it open for the specified duration
 * or until close() is called explicitly.
 *//*from   w ww. ja  v a  2  s  .  com*/
public void open(int nMilliseconds) {
    if (image_ == null)
        return;

    Timer timer = new Timer(Integer.MAX_VALUE, new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            ((Timer) event.getSource()).stop();
            close();
        };
    });

    timer.setInitialDelay(nMilliseconds);
    timer.start();

    setBounds(x_, y_, width_, height_);
    setVisible(true);
}

From source file:org.micromanager.CRISP.CRISPFrame.java

private void CalibrateButton_ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CalibrateButton_ActionPerformed
    try {/*from   w ww .ja  v  a2 s .  co m*/
        core_.setProperty(CRISP_, "CRISP State", "loG_cal");

        String state = "";
        int counter = 0;
        while (!state.equals("loG_cal") && counter < 50) {
            state = core_.getProperty(CRISP_, "CRISP State");
            Thread.sleep(100);
        }
        Double snr = new Double(core_.getProperty(CRISP_, "Signal Noise Ratio"));

        if (snr < 2.0)
            ReportingUtils.showMessage("Signal Noise Ratio is smaller than 2.0.  "
                    + "Focus on your sample, increase LED intensity and try again.");

        core_.setProperty(CRISP_, "CRISP State", "Dither");

        String value = core_.getProperty(CRISP_, "Dither Error");

        final JLabel jl = new JLabel();
        final JLabel jlA = new JLabel();
        final JLabel jlB = new JLabel();
        final String msg1 = "Value:  ";
        final String msg2 = "Adjust the detector lateral adjustment screw until the value is > 100 or"
                + "< -100 and stable.";
        jlA.setText(msg1);
        jl.setText(value);
        jl.setAlignmentX(JLabel.CENTER);

        Object[] msg = { msg1, jl, msg2 };

        ActionListener al = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    jl.setText(core_.getProperty(CRISP_, "Dither Error"));
                } catch (Exception ex) {
                    ReportingUtils.logError("Error while getting CRISP dither Error");
                }
            }
        };

        Timer timer = new Timer(100, al);
        timer.setInitialDelay(500);
        timer.start();

        /*JOptionPane optionPane = new JOptionPane(new JLabel("Hello World",JLabel.CENTER));
        JDialog dialog = optionPane.createDialog("");
        dialog.setModal(true);
        dialog.setVisible(true); */

        JOptionPane.showMessageDialog(null, msg, "CRISP Calibration", JOptionPane.OK_OPTION);

        timer.stop();

        core_.setProperty(CRISP_, "CRISP State", "gain_Cal");

        counter = 0;
        while (!state.equals("Ready") && counter < 50) {
            state = core_.getProperty(CRISP_, "CRISP State");
            Thread.sleep(100);
        }
        // ReportingUtils.showMessage("Calibration failed. Focus, make sure that the NA variable is set correctly and try again.");

    } catch (Exception ex) {
        ReportingUtils.showMessage(
                "Calibration failed. Focus, make sure that the NA variable is set correctly and try again.");
    }
}

From source file:edu.mit.fss.examples.visual.gui.WorldWindVisualization.java

/**
 * Instantiates a new world wind visualization.
 *
 * @throws OrekitException the orekit exception
 */// www  .  ja va2s  .  co  m
public WorldWindVisualization() throws OrekitException {
    logger.trace("Creating Orekit reference frames.");
    eme = ReferenceFrame.EME2000.getOrekitFrame();
    itrf = ReferenceFrame.ITRF2008.getOrekitFrame();
    // world wind frame is a fixed rotation from Earth inertial frame
    wwj = new Frame(itrf, new Transform(date, new Rotation(RotationOrder.ZXZ, 0, -Math.PI / 2, -Math.PI / 2)),
            "World Wind");

    logger.trace("Creating World Window GL canvas and adding to panel.");
    wwd = new WorldWindowGLCanvas();
    wwd.setModel(new BasicModel());
    wwd.setPreferredSize(new Dimension(800, 600));
    setLayout(new BorderLayout());
    add(wwd, BorderLayout.CENTER);

    logger.trace("Creating and adding a renderable layer.");
    displayLayer = new RenderableLayer();
    wwd.getModel().getLayers().add(displayLayer);

    logger.trace("Creating and adding a marker layer.");
    markerLayer = new MarkerLayer();
    // allow markers above/below surface
    markerLayer.setOverrideMarkerElevation(false);
    wwd.getModel().getLayers().add(markerLayer);

    logger.trace("Creating and adding a sun renderable.");
    Vector3D position = sun.getPVCoordinates(date, wwj).getPosition();
    sunShape = new Ellipsoid(wwd.getModel().getGlobe().computePositionFromPoint(convert(position)), 696000000.,
            696000000., 696000000.);
    ShapeAttributes sunAttributes = new BasicShapeAttributes();
    sunAttributes.setInteriorMaterial(Material.YELLOW);
    sunAttributes.setInteriorOpacity(1.0);
    sunShape.setAttributes(sunAttributes);
    displayLayer.addRenderable(sunShape);

    logger.trace("Creating and adding a terminator.");
    LatLon antiSun = LatLon.fromRadians(-sunShape.getCenterPosition().getLatitude().radians,
            FastMath.PI + sunShape.getCenterPosition().getLongitude().radians);
    // set radius to a quarter Earth chord at the anti-sun position less
    // a small amount (100 m) to avoid graphics problems
    terminatorShape = new SurfaceCircle(antiSun,
            wwd.getModel().getGlobe().getRadiusAt(antiSun) * FastMath.PI / 2 - 100);
    ShapeAttributes nightAttributes = new BasicShapeAttributes();
    nightAttributes.setInteriorMaterial(Material.BLACK);
    nightAttributes.setInteriorOpacity(0.5);
    terminatorShape.setAttributes(nightAttributes);
    displayLayer.addRenderable(terminatorShape);

    logger.trace("Creating and adding a panel for buttons.");
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    buttonPanel.add(new JCheckBox(new AbstractAction("Inertial Frame") {
        private static final long serialVersionUID = 2287109397693524964L;

        @Override
        public void actionPerformed(ActionEvent e) {
            setInertialFrame(((JCheckBox) e.getSource()).isSelected());
        }
    }));
    buttonPanel.add(new JButton(editOptionsAction));
    add(buttonPanel, BorderLayout.SOUTH);

    logger.trace(
            "Creating a timer to rotate the sun renderable, " + "terminator surface circle, and stars layer.");
    Timer rotationTimer = new Timer(15, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            wwd.redraw();
            try {
                BasicOrbitView wwdView;
                if (wwd.getView() instanceof BasicOrbitView) {
                    wwdView = (BasicOrbitView) wwd.getView();
                } else {
                    return;
                }

                // rotate camera to simulate inertial frame
                if (wwd.getView().isAnimating() || !inertialFrame.get()) {
                    // update eme datum
                    rotationDatum = wwj.getTransformTo(eme, date)
                            .transformPosition(convert(wwdView.getCenterPoint()));
                } else if (inertialFrame.get()) {
                    Position newCenter = wwd.getModel().getGlobe().computePositionFromPoint(
                            convert(eme.getTransformTo(wwj, date).transformPosition(rotationDatum)));
                    // move to eme datum
                    wwdView.setCenterPosition(newCenter);
                }

                // rotate stars layer
                for (Layer layer : wwd.getModel().getLayers()) {
                    if (layer instanceof StarsLayer) {
                        StarsLayer stars = (StarsLayer) layer;
                        // find the EME coordinates of (0,0)
                        Vector3D emeDatum = wwj.getTransformTo(eme, date).transformPosition(convert(
                                wwd.getModel().getGlobe().computePointFromLocation(LatLon.fromDegrees(0, 0))));
                        // find the WWJ coordinates the equivalent point in ITRF
                        Vector3D wwjDatum = itrf.getTransformTo(wwj, date).transformPosition(emeDatum);
                        // set the longitude offset to the opposite of 
                        // the difference in longitude (i.e. from 0)
                        stars.setLongitudeOffset(wwd.getModel().getGlobe()
                                .computePositionFromPoint(convert(wwjDatum)).getLongitude().multiply(-1));
                    }
                }
            } catch (OrekitException ex) {
                logger.error(ex);
            }
        }
    });
    // set initial 2-second delay for initialization
    rotationTimer.setInitialDelay(2000);
    rotationTimer.start();
}

From source file:neembuu.uploader.NeembuuUploader.java

/**
 * Creates new form NeembuuUploader/*from  w  ww. ja  v  a2 s. co m*/
 */
private NeembuuUploader() {
    //An error message will be printed. 
    //Saying 
    //java.lang.ClassNotFoundException: neembuu.release1.ui.mc.EmotionIconProviderImpl
    //please ignore it.
    mainComponent = new MainComponentImpl(this);
    //mainComponent = new NonUIMainComponent(); << When running in command line mode

    NULogger.getLogger().log(Level.INFO, "{0}: Starting up..", getClass().getName());

    //Display the splashscreen until the NeembuuUploader is initialized
    //NeembuuUploaderSplashScreen.getInstance().setVisible(true);

    //Setup NeembuuUploaderProperties.. Create the file if it doesn't exist.
    NeembuuUploaderProperties.setUp();

    //Initialize components
    initComponents();
    initSorting();
    initNotification();
    setUpTrayIcon();

    setUpFileChooser();

    setUpHttpClient();
    setupTabs();

    //map each checkbox to its class in the hashmap variable
    //NULogger.getLogger().info("Setting checkbox operations");
    //checkBoxOperations();

    //Load previously saved state
    //loadSavedState();

    //This 3rd party code is to enable Drag n Drop of files
    FileDrop fileDrop = new FileDrop(this, new FileDrop.Listener() {

        @Override
        public void filesDropped(java.io.File[] filesSelected) {
            //Ignore directories
            for (File file : filesSelected) {
                if (file.isFile()) {
                    files.add(file);
                }
            }
            if (files.isEmpty()) {
                return;
            }
            //If one file is dropped, display its name.. If more than one dropped, display the number of files selected
            if (files.size() == 1) {
                inputFileTextField.setText(files.get(0) + "");
            } else {
                inputFileTextField.setText(files.size() + " " + Translation.T().nfilesselected());
            }
            NULogger.getLogger().info("Files Dropped");
        }
    });

    //Timer is used to periodically refresh the table so that the progress will appear smoothly.
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            //Update every 1s
            Timer autoUpdate = new Timer(1000, new ActionListener() {
                //Check if the queue is locked. If not, repaint.

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (!QueueManager.getInstance().isQueueLocked()) {
                        //Should not call firetablerowsupdated as it'll lose the selection of rows.                             //
                        //So repaint is called.
                        neembuuUploaderTable.repaint();
                    }
                }
            });
            //Unnecessary.. but waits for 3 seconds within which other threads will get more juice and initialize faster..
            //reduced from 10 to 3 as I moved to faster pc
            autoUpdate.setInitialDelay(3000);
            //Start the timer.
            autoUpdate.start();
            NULogger.getLogger().info("Timer started..");
        }
    });

    //By now everything is loaded, so no need of splashscreen anymore,, dispose it. :)
    //NeembuuUploaderSplashScreen.getInstance().dispose();
    NULogger.getLogger().info("Splash screen disposed..");

    //Make the NeembuuUploader appear in center of screen.
    setLocationRelativeTo(null);

    selectFileButton.requestFocus();

    setVisible(true);
    ThemeCheck.apply(this);

    selectFileButton.setBorder(BorderFactory.createEmptyBorder());
    selectFileButton.setContentAreaFilled(false);
    selectFileButton.setToolTipText(Translation.T().selectFileButton());
    selectFileButton.setFocusPainted(false);

    selectFolderButton.setBorder(BorderFactory.createEmptyBorder());
    selectFolderButton.setContentAreaFilled(false);
    selectFolderButton.setToolTipText("Select Folder");
    selectFolderButton.setFocusPainted(false);

    getLogButton.setBorder(BorderFactory.createEmptyBorder());
    getLogButton.setContentAreaFilled(false);
    getLogButton.setToolTipText("Copy \"nu.log\" to the clipboard");
    getLogButton.setFocusPainted(false);

    checkifLKSOn();
    // starting a thread from a constructor is a bad way to do it
    // however, we dont have enough options here.
}