Example usage for javax.swing Timer start

List of usage examples for javax.swing Timer start

Introduction

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

Prototype

public void start() 

Source Link

Document

Starts the Timer, causing it to start sending action events to its listeners.

Usage

From source file:org.dishevelled.brainstorm.BrainStorm.java

/** {@inheritDoc} */
public void run() {
    JFrame f = new JFrame("Brain storm");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add("Center", this);
    f.setResizable(false);/*from   w w  w.j  a va 2s  .co m*/
    f.setUndecorated(true);
    // hide cursor on linux and windows platforms
    f.setCursor(hiddenCursor);
    GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(f);
    f.validate();

    SwingUtilities.invokeLater(new Runnable() {
        /** {@inheritDoc} */
        public void run() {
            calculatePlaceholderSize();
            calculateTextAreaSize();
            validate();
            textArea.scrollRectToVisible(
                    new Rectangle(0, textArea.getHeight() - 1, textArea.getWidth(), textArea.getHeight()));
        }
    });

    // save every five minutes
    Timer t = new Timer(5 * 60 * 1000, new ActionListener() {
        /** {@inheritDoc} */
        public void actionPerformed(final ActionEvent event) {
            save();
        }
    });
    t.setRepeats(true);
    t.start();
}

From source file:org.domainmath.gui.MainFrame.java

private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
    MainFrame.octavePanel.evaluate("pkg load all;");
    String f = System.getProperty("user.dir") + File.separator + "cache" + File.separator + "pkg_list.xml";
    MainFrame.octavePanel.evaluate("DomainMath_PkgContents('" + f + "');");

    PkgDocFrame pkgDocFrame = new PkgDocFrame(this);
    pkgDocFrame.setLocationRelativeTo(this);
    this.setCursor(new Cursor(Cursor.WAIT_CURSOR));

    ActionListener taskPerformer = (ActionEvent evt1) -> {
        pkgDocFrame.setVisible(true);/*from  w w w .  j  av a 2s . com*/
    };
    javax.swing.Timer t = new javax.swing.Timer(1200, taskPerformer);
    t.setRepeats(false);
    t.start();
    this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}

From source file:org.eobjects.datacleaner.windows.AnalysisJobBuilderWindowImpl.java

private void displayDatastoreSelection() {
    if (isShowing()) {
        if (_datastore == null) {
            if (!_leftPanel.isCollapsed()) {
                _leftPanel.setCollapsed(true);
            }//w  w  w  .j a v  a2 s.  c om
            Timer timer = new Timer(500, new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    _leftPanel.setVisible(false);
                }
            });
            timer.setRepeats(false);
            timer.start();

            _sourceColumnsPanel.setVisible(false);
            _datastoreListPanelRef.get().setVisible(true);
            _datastoreListPanelRef.get().requestSearchFieldFocus();
        }
    }
}

From source file:org.exist.launcher.Launcher.java

public Launcher(final String[] args) {
    if (SystemTray.isSupported()) {
        tray = SystemTray.getSystemTray();
    }//  ww  w  . j  a  va  2 s . c  o m

    captureConsole();

    this.jettyConfig = getJettyConfig();
    final Optional<Path> eXistHome = ConfigurationHelper.getExistHome();
    final Path wrapperConfig;
    if (eXistHome.isPresent()) {
        wrapperConfig = eXistHome.get().resolve("tools/yajsw/conf/wrapper.conf");
    } else {
        wrapperConfig = Paths.get("tools/yajsw/conf/wrapper.conf");
    }

    wrapperProperties = new Properties();
    wrapperProperties.setProperty("wrapper.working.dir", eXistHome.orElse(Paths.get(".")).toString());
    wrapperProperties.setProperty("wrapper.config", wrapperConfig.toString());

    System.setProperty("wrapper.config", wrapperConfig.toString());

    installedAsService();

    boolean initSystemTray = true;
    if (isSystemTraySupported()) {
        initSystemTray = initSystemTray();
    }

    configDialog = new ConfigurationDialog(this::shutdown);

    splash = new SplashScreen(this);
    splash.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent windowEvent) {
            setServiceState();
            if (runningAsService.isPresent()) {
                splash.setStatus("eXist-db is already installed as service! Attaching to it ...");
                final Timer timer = new Timer(3000, (event) -> splash.setVisible(false));
                timer.setRepeats(false);
                timer.start();
            } else {
                if (ConfigurationUtility.isFirstStart()) {
                    splash.setVisible(false);
                    configDialog.open(true);
                    configDialog.requestFocus();
                } else {
                    startJetty();
                }
            }
        }
    });

    final boolean systemTrayReady = tray != null && initSystemTray && tray.getTrayIcons().length > 0;

    SwingUtilities.invokeLater(() -> utilityPanel = new UtilityPanel(Launcher.this, systemTrayReady));
}

From source file:org.freeplane.main.application.MapViewDockingWindows.java

public void focusMapViewLater(final MapView mapView) {
    Timer timer = new Timer(40, new ActionListener() {
        int retryCount = 5;

        public void actionPerformed(final ActionEvent event) {
            final Timer eventTimer = (Timer) event.getSource();
            focusMapLater(mapView, eventTimer);
        }//  w w w  .j  a v  a  2 s .co  m

        private void focusMapLater(final MapView mapView, final Timer eventTimer) {
            if (mapView.isShowing()
                    && Controller.getCurrentController().getMapViewManager().getMapViewComponent() == mapView) {
                final NodeView selected = mapView.getSelected();
                if (selected != null) {
                    final Frame frame = JOptionPane.getFrameForComponent(mapView);
                    if (frame.isFocused())
                        selected.requestFocusInWindow();
                    else
                        frame.addWindowFocusListener(new WindowAdapter() {
                            @Override
                            public void windowGainedFocus(WindowEvent e) {
                                frame.removeWindowFocusListener(this);
                                selected.requestFocusInWindow();
                                retryCount = 2;
                                eventTimer.start();
                            }
                        });
                }
            }
            if (retryCount > 1) {
                retryCount--;
                eventTimer.start();
            }
        }
    });
    timer.setRepeats(false);
    timer.start();
}

From source file:org.isatools.isacreatorconfigurator.configui.MenuPanel.java

private void startAnimation() {
    Timer timer = new Timer(75, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            generic.animate();//from   w ww  .  j  a va2  s  . c o  m
            generic.repaint();
        }
    });
    timer.start();
}

From source file:org.tinymediamanager.ui.MainWindow.java

private void checkForUpdate() {
    try {/*  w  ww  .  j a v a2  s  .  co m*/
        final UpdaterTask updateWorker = new UpdaterTask();

        updateWorker.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                if ("state".equals(evt.getPropertyName()) && evt.getNewValue() == StateValue.DONE) {
                    try {
                        boolean update = updateWorker.get();
                        LOGGER.debug("update result was: " + update);
                        if (update) {

                            // we might need this somewhen...
                            if (updateWorker.isForcedUpdate()) {
                                LOGGER.info("Updating (forced)...");
                                closeTmmAndStart(Utils.getPBforTMMupdate());
                                return;
                            }

                            // show whatsnewdialog with the option to update
                            if (StringUtils.isNotBlank(updateWorker.getChangelog())) {
                                UpdateDialog dialog = new UpdateDialog(updateWorker.getChangelog());
                                dialog.setVisible(true);
                            } else {
                                // do the update without changelog popup

                                int answer = JOptionPane.showConfirmDialog(null,
                                        BUNDLE.getString("tmm.update.message"),
                                        BUNDLE.getString("tmm.update.title"), JOptionPane.YES_NO_OPTION);
                                if (answer == JOptionPane.OK_OPTION) {
                                    LOGGER.info("Updating...");

                                    // spawn getdown and exit TMM
                                    closeTmmAndStart(Utils.getPBforTMMupdate());
                                }
                            }
                        }
                    } catch (Exception e) {
                        LOGGER.error("Update task failed!" + e.getMessage());
                    }
                }
            }
        });

        // update task start a few secs after GUI...
        Timer timer = new Timer(5000, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                updateWorker.execute();
            }
        });
        timer.setRepeats(false);
        timer.start();
    } catch (Exception e) {
        LOGGER.error("Update task failed!" + e.getMessage());
    }
}

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);
        }/*from www  .  j  av  a 2 s  .  c o  m*/
    });
    t.setRepeats(false);
    t.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   w  w w.j  a v a2 s . co  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);//www .  j a  va2s.  c  o  m
    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);
}