List of usage examples for javax.swing Timer Timer
public Timer(int delay, ActionListener listener)
From source file:MainProgram.MainProgram.java
public void StopWatchInitializer() throws InterruptedException { stopWatch = new StopWatch(); stopWatchSplitting = stopWatch.toString().split("\\."); timer = new Timer(1000, updateLabelListener); timer.start();//from w w w. j av a 2 s . c o m timer.setRepeats(true); }
From source file:MainProgram.MainProgram.java
public void mailCheckTimeInitializer() throws InterruptedException { checkMailTimer = new Timer(1000, mailCheckListener); }
From source file:course_generator.frmMain.java
/** * Creates new form frmMain ------------------------------- !!!! Everything * start here !!!! ------------------------ *///from w w w . j av a2 s.com public frmMain(String args[]) { // Initialize data DataDir = Utils.GetHomeDir(); Track = new TrackData(); Resume = new ResumeData(); Settings = new CgSettings(); ModelTableMain = new TrackDataModel(Track, Settings); ModelTableResume = new ResumeModel(Resume, Settings); dataset = new XYSeriesCollection(); // dataset = CreateDataset(); chart = CreateChartProfil(dataset); // -- Load configuration LoadConfig(); // -- Set the language if (Settings.Language.equalsIgnoreCase("FR")) { Locale.setDefault(Locale.FRANCE); } else if (Settings.Language.equalsIgnoreCase("EN")) { Locale.setDefault(Locale.US); } // -- Set default font setUIFont(new javax.swing.plaf.FontUIResource("Tahoma", // Settings.DefaultFont.getFontName(), // //"Tahoma" Font.PLAIN, // Settings.DefaultFont.getStyle(), // Font.PLAIN, 14)); // Settings.DefaultFont.getSize())); //24)); // -- Initialize the string resource for internationalization bundle = java.util.ResourceBundle.getBundle("course_generator/Bundle"); // -- Configure the main form initComponents(); // -- Set the icon of the application setIconImage(createImageIcon("/course_generator/images/cg.png", "").getImage()); // -- Set the preferred column width for (int i = 0; i < 15; i++) { TableMain.getColumnModel().getColumn(i).setPreferredWidth(Settings.TableMainColWidth[i]); } RefreshTableMain(); // -- Set the windows size and center it in the screen - Not tested on // multi-screen configuration Rectangle r = getBounds(); r.width = Settings.MainWindowWidth; r.height = Settings.MainWindowHeight; Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); r.x = (screensize.width - r.width) / 2; r.y = (screensize.height - r.height) / 2; setBounds(r); // -- Set the left panel width SplitPaneMain.setDividerLocation(Settings.VertSplitPosition); SplitPaneMainRight.setDividerLocation(Settings.HorizSplitPosition); // -- Tests - To Remove... // -- Configure the tile source for the map MapViewer.setTileSource(new Thunderforest_Outdoors()); //TODO Switch to OpenTopomap //MapViewer.setTileSource(new OpenTopoMap()); // -- Set the counter in order near the end in order to start the // connection test cmptInternetConnexion = Settings.ConnectionTimeout - 1; // -- Start the 1 second timer timer1s = new Timer(1000, new TimerActionListener()); timer1s.start(); // -- Refresh RefreshMruCGX(); RefreshMruGPX(); RefreshStatusbar(Track); }
From source file:com.dbschools.quickquiz.client.giver.MainWindow.java
private void sendQuestion() { final String question = (String) cbxQuestions.getSelectedItem(); getQuizState().setQuestion(question); btnSendQuestion.setEnabled(false);/* w w w .j a v a 2s . com*/ final Integer timeLimitFieldValue = getTimeLimitProcessedValue(); resetTakers(Quiz.RESET_LAST_RESPONSES); numTakersWhenMsgSent.set(quizChannel.getView().size() - 1); numAnswersReceived.set(0); logger.debug("Sending question"); sendAsync(quizChannel, null, new QuestionMsg(question, timeLimitFieldValue)); countdownMeter.countDown(timeLimitFieldValue); questionTimeoutTimer = new Timer(timeLimitFieldValue * 1000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { endQuestion(); } }); questionTimeoutTimer.setRepeats(false); questionTimeoutTimer.start(); }
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 w w .j av a2 s . com*/ 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:de.quadrillenschule.azocamsyncd.astromode.gui.AstroModeJPanel.java
private void startAstroModejButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startAstroModejButtonActionPerformed if (status == Status.PAUSED) { SmartPhoneWrapper.checkConnection(); // updateTablejButtonActionPerformed(evt); ftpConnection.addFTPConnectionListenerOnce(this); final AstroModeJPanel acf = this; if (updateTimer != null) { updateTimer.stop();//from w w w . java 2s .c o m } updateTimer = new Timer(0, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { AstroModeBackgroundUpdater ambu = new AstroModeBackgroundUpdater(updateTimer, acf); ambu.start(); } }); updateTimer.start(); status = Status.RUNNING; } else { ftpConnection.removeFTPConnectionListener(this); status = Status.PAUSED; updateTimer.stop(); } startAstroModejButton.setText(status.name()); }
From source file:de.cismet.cids.custom.objecteditors.wunda_blau.WebDavPicturePanel.java
/** * Creates new form WebDavPicturePanel.// w w w.j a v a 2 s. c om * * @param editable DOCUMENT ME! * @param urlProp DOCUMENT ME! * @param beanCollProp DOCUMENT ME! * @param bildClassName DOCUMENT ME! * @param numberProp DOCUMENT ME! * @param geoFieldProp DOCUMENT ME! * @param connectionContext DOCUMENT ME! */ public WebDavPicturePanel(final boolean editable, final String urlProp, final String beanCollProp, final String bildClassName, final String numberProp, final String geoFieldProp, final ConnectionContext connectionContext) { this.beanCollProp = beanCollProp; this.bildClassName = bildClassName; this.numberProp = numberProp; this.geoFieldProp = geoFieldProp; this.connectionContext = connectionContext; String webdavDirectory = null; WebDavHelper webdavHelper = null; try { final ResourceBundle bundle = ResourceBundle.getBundle("WebDav"); String pass = bundle.getString("password"); if ((pass != null) && pass.startsWith(PasswordEncrypter.CRYPT_PREFIX)) { pass = PasswordEncrypter.decryptString(pass); } final String user = bundle.getString("user"); webdavDirectory = bundle.getString(urlProp); webdavHelper = new WebDavHelper(Proxy.fromPreferences(), user, pass, false); } catch (final Exception ex) { final String message = "Fehler beim Initialisieren der Bilderablage."; LOG.error(message, ex); ObjectRendererUtils.showExceptionWindowToUser(message, ex, null); } this.webdavDirectory = webdavDirectory; this.webdavHelper = webdavHelper; initComponents(); fileChooser.setFileFilter(new FileFilter() { @Override public boolean accept(final File f) { return f.isDirectory() || IMAGE_FILE_PATTERN.matcher(f.getName()).matches(); } @Override public String getDescription() { return "Bilddateien"; } }); fileChooser.setMultiSelectionEnabled(true); listRepaintListener = new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent evt) { lstFotos.repaint(); } }; lstFotos.getModel().addListDataListener(new ListDataListener() { @Override public void intervalAdded(final ListDataEvent e) { defineButtonStatus(); } @Override public void intervalRemoved(final ListDataEvent e) { defineButtonStatus(); } @Override public void contentsChanged(final ListDataEvent e) { defineButtonStatus(); } }); timer = new Timer(300, new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { if (resizeListenerEnabled) { // if (isShowing()) { if (currentResizeWorker != null) { currentResizeWorker.cancel(true); } currentResizeWorker = new ImageResizeWorker(); CismetThreadPool.execute(currentResizeWorker); // } else { // timer.restart(); // } } } }); timer.setRepeats(false); btnAddImg.setVisible(editable); btnRemoveImg.setVisible(editable); }
From source file:com.sshtools.shift.FileTransferDialog.java
/** * * * @param fileSize//from w w w .j a va 2s .co m * @param from */ public void started(long fileSize, String from) { try { Method m = progressbar.getClass().getMethod("setIndeterminate", new Class[] { boolean.class }); Object[] args = new Object[] { new Boolean(false) }; m.invoke(progressbar, args); } catch (Throwable ex) { } String str; str = source + ((getFileCount() <= 1) ? "" : (" (" + String.valueOf(filesTransfered + 1) + " of " + String.valueOf(getFileCount()) + " files)")); lblPathValue.setText(str); lastUpdate = System.currentTimeMillis(); this.fileSize = fileSize; // Determine the transfer rate every second and update necessary controls lblTimeLeftValuer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent evt) { synchronized (lock) { if (elaspedTime < 1000) { transfer = bytesSoFar + completedTransfers; } else { transfer = (bytesSoFar + completedTransfers) / (elaspedTime / 1000); } lblTransferRateValue.setText(formatKb1.format( transfer / 1024) + " KB/Sec"); long bytesLeft = FileTransferDialog.this.totalBytes - (completedTransfers + bytesSoFar); long secondsLeft = (long) (bytesLeft / transfer); setTitle(formatKb.format( (double) (((double) (completedTransfers + bytesSoFar) / totalBytes)) * 100) + "% Complete - " + title); String estimatedTime; if (secondsLeft < 60) { estimatedTime = String.valueOf(secondsLeft) + " sec"; } else if (secondsLeft < 3600) { estimatedTime = String.valueOf(secondsLeft / 60) + " min " + String.valueOf(secondsLeft % 60) + " sec"; } else { estimatedTime = String.valueOf(secondsLeft / 3600) + " hrs " + String.valueOf((secondsLeft % 3600) / 60) + " min " + String.valueOf((secondsLeft % 3600) % 60) + " sec"; } // Work out how much lblTimeLeftValue is left if (((completedTransfers + bytesSoFar) / 1073741824) > 0) { // Were in the gigabytes lblTimeLeftValue.setText(estimatedTime + " (" + formatMb.format( (double) (completedTransfers + bytesSoFar) / 1073741824) + " GB of " + formattedTotal + " copied)"); } else if (((completedTransfers + bytesSoFar) / 1048576) > 0) { // Were in the megabytes lblTimeLeftValue.setText(estimatedTime + " (" + formatMb.format( (double) (completedTransfers + bytesSoFar) / 1048576) + " MB of " + formattedTotal + " copied)"); } else { // Were still in Kilobytes lblTimeLeftValue.setText(estimatedTime + " (" + formatKb.format( (double) (completedTransfers + bytesSoFar) / 1024) + " KB of " + formattedTotal + " copied)"); } } } }); lblTimeLeftValuer.start(); }
From source file:com.willwinder.universalgcodesender.GrblController.java
/** * Create a timer which will execute GRBL's position polling mechanism. *//*from ww w . ja v a 2s. c o m*/ private Timer createPositionPollTimer() { // Action Listener for GRBL's polling mechanism. ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { try { if (outstandingPolls == 0) { outstandingPolls++; comm.sendByteImmediately(GrblUtils.GRBL_STATUS_COMMAND); } else { // If a poll is somehow lost after 20 intervals, // reset for sending another. outstandingPolls++; if (outstandingPolls >= 20) { outstandingPolls = 0; } } } catch (Exception ex) { dispatchConsoleMessage(MessageType.INFO, Localization.getString("controller.exception.sendingstatus") + " (" + ex.getMessage() + ")\n"); ex.printStackTrace(); } } }); } }; return new Timer(this.getStatusUpdateRate(), actionListener); }
From source file:junk.gui.HazardDataSetCalcCondorApp.java
/** * This function is called when user submits the calculation * @param e/* w w w .j a va 2s .co m*/ */ void addButton_actionPerformed(ActionEvent e) { calcProgress = new CalcProgressBar("HazardMap Application", "Initializing Calculation ..."); // check that user has entered a valid email address String email = emailText.getText(); if (email.trim().equalsIgnoreCase("")) { JOptionPane.showMessageDialog(this, "Please Enter email Address"); return; } if (email.indexOf("@") == -1 || email.indexOf(".") == -1) { JOptionPane.showMessageDialog(this, "Please Enter valid email Address"); return; } timer = new Timer(100, new ActionListener() { public void actionPerformed(ActionEvent evt) { if (step == 1) calcProgress.setProgressMessage("Checking if calculation have been done earlier ..."); else if (step == 2) calcProgress.setProgressMessage("Setting ERF on server ..."); else if (step == 3) calcProgress.setProgressMessage("Submitting Calculations , Please wait ..."); else if (step == 0) { addButton.setEnabled(true); timer.stop(); calcProgress.dispose(); calcProgress = null; } } }); Thread t = new Thread(this); t.start(); }