List of usage examples for javax.swing Timer setInitialDelay
public void setInitialDelay(int initialDelay)
Timer
's initial delay, the time in milliseconds to wait after the timer is started before firing the first event. From source file:pipeline.GUI_utils.ListOfPointsView.java
@SuppressWarnings("unchecked") private void checkForDirtiness() { while (!closed) { boolean assumeTableStructureChanged = false; boolean copyOfDirty = false; synchronized (dirty) { try { while (!dirty.get() && !closed) dirty.wait();//from w w w . j a v a2s. c o m } catch (InterruptedException e) { if (closed || frame == null) break; } copyOfDirty = dirty.get(); dirty.set(false); assumeTableStructureChanged = tableStructurePossiblyChanged; tableStructurePossiblyChanged = false; } if (copyOfDirty && !(closed || frame == null)) { Component previousGlassPane = frame.getGlassPane(); final Timer timer = new Timer(2_000, null); timer.setInitialDelay(4_000); final Action t = new AbstractAction() { private static final long serialVersionUID = 1L; private boolean high; private boolean firstRun = true; @Override public void actionPerformed(ActionEvent action) { if (frame == null || !frame.isVisible()) { // The user might have closed the window; just exit timer.stop(); return; } if (firstRun) { firstRun = false; frame.setGlassPane(g); g.setBounds(table.getBounds()); g.setVisible(true); } g.setAlpha(high ? 200 : 100); // table.setBackground(high?darkGrey:lightGrey); high = !high; g.repaint(); } }; timer.addActionListener(t); timer.start(); IPluginIOList<T> localPointsCopy = null; boolean filterUpdating = false; synchronized (dataCopySemaphore) { localPointsCopy = (IPluginIOList<T>) pointsCopy.duplicateStructure(); localPointsCopy.addAllAndLink(pointsCopy); if ((modelEvent != null) && (modelEvent.eventType == PipelineTableModelEvent.FILTER_ADJUSTING)) filterUpdating = true; } silenceUpdates.incrementAndGet(); try { if (assumeTableStructureChanged) { setupTableModel(localPointsCopy); updateColumnDescriptions(); } updateExpr4jModel(); // Now read the values computed by expr4j and update the result to display (but keep the formula), // only for user-defined columns updateComputedCells(); if (!assumeTableStructureChanged) { // Reset filter range because if any new user values are generated the rows // might automatically be filtered out, which is very confusing for the user if (!filterUpdating) table.resetFilterRanges(false); } points.fireValueChanged(false, false); final boolean copyOfAssumeTableStructureChanged = assumeTableStructureChanged; SwingUtilities.invokeLater(() -> { timer.stop(); g.setVisible(false); frame.setGlassPane(previousGlassPane); synchronized (modelSemaphore) { silenceUpdates.incrementAndGet(); try { table.setBackground(Color.WHITE); if (copyOfAssumeTableStructureChanged) { // tableModel.fireTableStructureChanged(); // Not necessary because already indirectly triggered above } else { final ListSelectionModel saveRowSelection, saveColumnSelection; try { saveRowSelection = (ListSelectionModel) ((DefaultListSelectionModel) table .getSelectionModel()).clone(); saveColumnSelection = (ListSelectionModel) ((DefaultListSelectionModel) table .getColumnModel().getSelectionModel()).clone(); } catch (Exception e) { throw new RuntimeException(e); } tableModel.fireTableDataChanged(); Utils.log("Resetting selection", LogLevel.DEBUG); table.setSelectionModel(saveRowSelection); table.getColumnModel().setSelectionModel(saveColumnSelection); } } finally { silenceUpdates.decrementAndGet(); } frame.repaint();// For glass pane } }); } catch (Exception e) { Utils.log("Exception: " + e, LogLevel.WARNING); dirty.set(false); } finally { silenceUpdates.decrementAndGet(); } } } }
From source file:pl.otros.logview.api.gui.LogViewPanelWrapper.java
private void createReadingProgressBar() { progressBar = new JProgressBar(0, 100); progressBar.setStringPainted(true);/*from w w w . j a v a 2 s . com*/ progressBar.setString("Processed ? of ? [?%]"); final Timer t = new Timer(500, e -> { LOGGER.trace("Updating reading progress"); final LoadingDetails loadingDetails = logLoader.getLoadingDetails(dataTableModel); final List<LogLoadingSession> logLoadingSessions = loadingDetails.getLogLoadingSessions(); final List<LoadStatistic> statistics = logLoadingSessions.stream().map(logLoader::getLoadStatistic) .collect(Collectors.toList()); final Long position = statistics.stream().collect(Collectors.summingLong(LoadStatistic::getPosition)); final Long total = statistics.stream().collect(Collectors.summingLong(LoadStatistic::getTotal)); final float percent = (100f) * ((float) position / total); progressBar.setValue((int) percent); final String msg = String.format("Processed %s of %s [%.2f%%]", FileSize.convertToStringRepresentation(position), FileSize.convertToStringRepresentation(total), percent); LOGGER.trace("Updating progress bar with message {}", msg); progressBar.setString(msg); final String tooltip = "<HTML>" + statistics.stream() .map(s -> String.format("Processed %s of %s [%.2f%%] - %s", FileSize.convertToStringRepresentation(s.getPosition()), FileSize.convertToStringRepresentation(s.getTotal()), s.getPercent(), s.getSource().stringForm())) .collect(Collectors.joining("<BR/>")) + "</HTML>"; progressBar.setToolTipText(tooltip); }); t.setRepeats(true); t.setInitialDelay(1000); t.start(); timer = Optional.of(t); }