List of usage examples for javax.swing Timer addActionListener
public void addActionListener(ActionListener listener)
Timer
. From source file:org.datacleaner.windows.FileTransferProgressWindow.java
public void setFinished(String filename) { final int index = getIndex(filename); final String doneText = "Done!"; _infoLabels[index].setText(doneText); for (int i = 0; i < _infoLabels.length; i++) { if (!doneText.equals(_infoLabels[i].getText())) { // return if not all files have transfered return; }/*from ww w . ja va 2s.c om*/ } final Timer timer = new Timer(1500, null); final ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { FileTransferProgressWindow.this.dispose(); timer.stop(); } }; timer.addActionListener(listener); timer.start(); }
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 ww w. j a v a 2 s . com } 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(); } } } }