Example usage for javax.swing Timer Timer

List of usage examples for javax.swing Timer Timer

Introduction

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

Prototype

public Timer(int delay, ActionListener listener) 

Source Link

Document

Creates a Timer and initializes both the initial delay and between-event delay to delay milliseconds.

Usage

From source file:org.trzcinka.intellitrac.view.toolwindow.tickets.ticket_editor.BaseTicketEditorForm.java

protected final void showDoneLabel() {
    final String lastText = submitChangesButton.getText();
    submitChangesButton.setText(bundle.getString("tool_window.tickets.ticket_editor.submit_changes.done"));
    int delay = IntelliTracConfiguration.getInstance().getConfiguration().getInt("submit_button_done_delay");
    Timer t = new Timer(delay, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            submitChangesButton.setText(lastText);
        }/*ww  w.j a v  a  2 s. co  m*/
    });
    t.setRepeats(false);
    t.start();

}

From source file:org.ut.biolab.medsavant.client.util.MedSavantWorker.java

/**
 * Workers which want intermittent progress checks should start a timer which will call checkProgress and
 * showProgress intermittently.//from   ww w.j  ava 2 s . c o  m
 */
protected void startProgressTimer() {
    this.progressTimer = new Timer(1000, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            try {
                ProgressStatus status = checkProgress();
                if (status != null) {
                    showProgress(status.fractionCompleted);
                }
            } catch (Exception ex) {
                LOG.info("Ignoring exception thrown while checking for progress.", ex);
            }
        }
    });
    this.progressTimer.start();
}

From source file:org.webcat.plugintester.ui.MainFrameBuilder.java

/**
 * Creates and lays out the Swing components for the window.
 *
 * @param frame the JFrame instance that will contain the components
 *//*  www  . j  a va 2 s.  c o  m*/
private void constructFrame(JFrame frame) {
    GridBagConstraints gridBagConstraints;

    fileChooser = new JFileChooser();
    bottomPanel = new JPanel();
    runButton = new JButton();
    mainPanel = new JPanel();
    JLabel webCatHomeLabel = new JLabel();
    webCatHomeField = new JTextField();
    webCatHomeBrowseButton = new JButton();
    JSeparator jSeparator0 = new JSeparator();
    JLabel submissionLabel = new JLabel();
    submissionField = new JTextField();
    submissionBrowseButton = new JButton();
    JSeparator jSeparator1 = new JSeparator();
    JLabel pluginsLabel = new JLabel();
    JPanel pluginsPanel = new JPanel();
    JScrollPane pluginsScrollPane = new JScrollPane();
    pluginsTable = new JTable();
    pluginAddButton = new JButton();
    pluginRemoveButton = new JButton();
    JSeparator jSeparator2 = new JSeparator();
    JTabbedPane tabPane = new JTabbedPane();
    propertiesPanel = new JPanel();
    JScrollPane propertiesScrollPane = new JScrollPane();
    propertiesEditor = new JEditorPane();
    documentationPanel = new JPanel();
    JScrollPane documentationScrollPane = new JScrollPane();
    documentationEditor = new JEditorPane();

    // File chooser
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    // Bottom panel
    bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 4));

    // Run button
    runButton.setText("Run Plug-ins");
    runButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            runButtonActionPerformed(evt);
        }
    });
    bottomPanel.add(runButton);

    frame.getContentPane().add(bottomPanel, BorderLayout.PAGE_END);

    // Main panel
    mainPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
    mainPanel.setLayout(new GridBagLayout());

    // Web-CAT Home field
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = GridBagConstraints.RELATIVE;
    gridBagConstraints.anchor = GridBagConstraints.LINE_START;
    webCatHomeLabel.setText("Web-CAT Home:");
    mainPanel.add(webCatHomeLabel, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    webCatHomeField.setTransferHandler(new WebCATHomeTransferHandler());
    mainPanel.add(webCatHomeField, gridBagConstraints);

    // Web-CAT Home browse button
    webCatHomeBrowseButton.setText("Browse...");
    webCatHomeBrowseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            webCatHomeBrowseButtonActionPerformed(evt);
        }
    });
    mainPanel.add(webCatHomeBrowseButton, new GridBagConstraints());

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(jSeparator0, gridBagConstraints);

    // Submission field
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = GridBagConstraints.RELATIVE;
    gridBagConstraints.anchor = GridBagConstraints.LINE_START;
    submissionLabel.setText("Submission:");
    mainPanel.add(submissionLabel, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    submissionField.setTransferHandler(new SubmissionTransferHandler());
    mainPanel.add(submissionField, gridBagConstraints);

    // Submission browse button
    submissionBrowseButton.setText("Browse...");
    submissionBrowseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            submissionBrowseButtonActionPerformed(evt);
        }
    });
    mainPanel.add(submissionBrowseButton, new GridBagConstraints());

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(jSeparator1, gridBagConstraints);

    // Plug-ins area
    pluginsLabel.setText("Plug-ins to run:");
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(pluginsLabel, gridBagConstraints);

    pluginsPanel.setPreferredSize(new Dimension(400, 80));
    pluginsPanel.setLayout(new GridBagLayout());

    pluginsModel = new PluginsTableModel();
    pluginsTable.setModel(pluginsModel);
    pluginsTable.setColumnSelectionAllowed(true);
    pluginsTable.getTableHeader().setReorderingAllowed(false);
    pluginsScrollPane.setViewportView(pluginsTable);
    pluginsTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    pluginsTable.getColumnModel().getColumn(0).setResizable(false);
    pluginsScrollPane.setTransferHandler(new PluginsTransferHandler());

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    pluginsPanel.add(pluginsScrollPane, gridBagConstraints);

    pluginAddButton.setText("Add...");
    pluginAddButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pluginAddButtonActionPerformed(evt);
        }
    });
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = GridBagConstraints.PAGE_START;
    pluginsPanel.add(pluginAddButton, gridBagConstraints);

    pluginRemoveButton.setText("Remove");

    pluginRemoveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pluginRemoveButtonActionPerformed(evt);
        }
    });
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = GridBagConstraints.PAGE_START;
    pluginsPanel.add(pluginRemoveButton, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 0.25;
    mainPanel.add(pluginsPanel, gridBagConstraints);
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(jSeparator2, gridBagConstraints);

    tabPane.setPreferredSize(new Dimension(466, 150));

    propertiesPanel.setLayout(new GridBagLayout());

    propertiesEditor.addKeyListener(new KeyAdapter() {
        public void keyTyped(KeyEvent e) {
            propertiesTimer.restart();
        }
    });

    propertiesTimer = new Timer(1000, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateGradingProperties();
        }
    });

    propertiesScrollPane.setViewportView(propertiesEditor);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    propertiesPanel.add(propertiesScrollPane, gridBagConstraints);

    tabPane.addTab("Properties", propertiesPanel);

    documentationPanel.setLayout(new GridBagLayout());

    documentationEditor.setContentType("text/html");
    documentationEditor.setEditable(false);
    documentationScrollPane.setViewportView(documentationEditor);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    documentationPanel.add(documentationScrollPane, gridBagConstraints);

    tabPane.addTab("Documentation", documentationPanel);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.gridheight = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weighty = 1.0;
    mainPanel.add(tabPane, gridBagConstraints);

    frame.getContentPane().add(mainPanel, BorderLayout.CENTER);

    frame.pack();
}

From source file:phex.gui.tabs.download.DownloadOverviewPanel.java

private JPanel buildProgressPanel() {
    JPanel subPanel = new JPanel();
    CellConstraints cc = new CellConstraints();
    FormLayout layout = new FormLayout("d, 2dlu, d, 2dlu, fill:d:grow, 2dlu, right:25dlu", // columns
            "p"); //rows
    PanelBuilder panelBuilder = new PanelBuilder(layout, subPanel);

    progressIconLabel = new JLabel(Localizer.getString("DownloadOverview_Progress"));
    panelBuilder.add(progressIconLabel, cc.xy(3, 1));

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                progressIconLabel.setIcon(defProgressIcon);
            } catch (Throwable th) {
                NLogger.error(DownloadOverviewPanel.class, th, th);
            }// www . ja  v a  2  s.  c o  m
        }
    };
    resetProgressTwinkleTimer = new Timer(175, actionListener);
    resetProgressTwinkleTimer.setRepeats(false);

    progressBar = new MultiScopeProgressBar();
    panelBuilder.add(progressBar, cc.xy(5, 1));

    progressLabel = new JLabel(" 100 %");
    panelBuilder.add(progressLabel, cc.xy(7, 1));

    return subPanel;
}

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  ww  .  j  a  va2 s  . 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 .ja  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);
}

From source file:skoa.helpers.ConfiguracionGraficas.java

private void insertarBarraProgreso() {
    progressBar = new JProgressBar();//Barra de progresin indefinida.
    progressBar.setIndeterminate(true);// ww w  . j av a  2  s  .c om
    progressBar.setVisible(true);
    progressBar.setString("Procesando...");
    progressBar.setStringPainted(true);
    obtenidos.add(progressBar);
    datos.removeAll();
    ruta_graficos = ruta_jar + "\\Consultas\\" + NombreCarpetaActual;
    graf = new Graficos(ruta_graficos, consultasDuales);
    graf.start();
    barra = new Timer(100, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            cargarVista();
        }
    });
    barra.start();
    //cargarVista();
}

From source file:storybook.action.ActionHandler.java

public void handleFileSave() {//new OK
    WaitDialog dlg = new WaitDialog(mainFrame, I18N.getMsg("msg.file.saving"));
    Timer timer = new Timer(500, new DisposeDialogAction(dlg));
    timer.setRepeats(false);// w ww. ja v a  2  s .c  o m
    timer.start();
    SwingUtil.showModalDialog(dlg, mainFrame);
}

From source file:storybook.SbApp.java

public void renameFile(final MainFrame mainFrame, File file) {
    trace("SbApp.renameFile(" + mainFrame.getName() + "," + file.getAbsolutePath() + ")");
    try {//from   ww  w .ja va 2  s . c o  m
        FileUtils.copyFile(mainFrame.getDbFile().getFile(), file);
        DbFile dbFile = new DbFile(file);
        OpenFileAction act = new OpenFileAction("", dbFile);
        act.actionPerformed(null);
        Timer t1 = new Timer(1000, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                mainFrame.close();
            }
        });
        t1.setRepeats(false);
        t1.start();
        Timer t2 = new Timer(4000, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                mainFrame.getDbFile().getFile().delete();
            }
        });
        t2.setRepeats(false);
        t2.start();
    } catch (IOException e) {
        error("SbApp.renameFile(" + mainFrame.getName() + "," + file.getName() + ")", e);
    }
}

From source file:storybook.toolkit.swing.SwingUtil.java

/**
 * Flashes the given {@link Component} for 250 milliseconds.
 *
 * @param comp the component to flash//w  w w.j av  a  2 s.  co m
 */
public static void flashComponent(JComponent comp) {
    synchronized (flashIsRunning) {
        if (flashIsRunning)
            return;
        flashIsRunning = true;
        FlashThread flash = new FlashThread(comp);
        SwingUtilities.invokeLater(flash);
        FlashThread flash2 = new FlashThread(comp, true);
        Timer timer = new Timer(1000, flash2);
        timer.setRepeats(false);
        timer.start();
    }
}