List of usage examples for javax.swing Timer Timer
public Timer(int delay, ActionListener listener)
From source file:org.apache.cayenne.modeler.util.LongRunningTask.java
/** * Configures the task to run in a separate thread, and immediately exits the method. * This method is allowed to be invoked from EventDispatchThread. *///from www .j av a2 s .co m public void start() { // prepare... setCanceled(false); this.finished = false; Thread task = new Thread(new Runnable() { public void run() { internalExecute(); } }); Timer progressDisplayTimer = new Timer(DEFAULT_MS_TO_DECIDE_TO_POPUP, new ActionListener() { public void actionPerformed(ActionEvent e) { showProgress(); } }); progressDisplayTimer.setRepeats(false); // start progressDisplayTimer.start(); task.start(); }
From source file:org.apache.cayenne.modeler.util.LongRunningTask.java
/** * Starts progress dialog if the task is not finished yet. *//*from w w w . ja v a 2 s . com*/ protected synchronized void showProgress() { LOGGER.debug("will show progress..."); if (finished) { return; } int currentValue = getCurrentValue(); if (!isCanceled() && currentValue < getMaxValue()) { LOGGER.debug("task still in progress, will show progress dialog..."); this.dialog = new ProgressDialog(frame, "Progress...", title); this.dialog.getCancelButton().addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setCanceled(true); } }); dialog.getProgressBar().setMinimum(getMinValue()); dialog.getProgressBar().setMaximum(getMaxValue()); updateProgress(); this.taskPollingTimer = new Timer(500, new ActionListener() { public void actionPerformed(ActionEvent e) { updateProgress(); } }); this.taskPollingTimer.start(); this.dialog.setVisible(true); } }
From source file:org.datacleaner.windows.AnalysisJobBuilderWindowImpl.java
private void updateLeftPanelVisibility(boolean show) { if (show) {//from ww w . j a v a 2s . c om _leftPanel.setVisible(true); if (_leftPanel.isCollapsed()) { _leftPanel.setCollapsed(false); } } else { if (!_leftPanel.isCollapsed()) { _leftPanel.setCollapsed(true); } final Timer timer = new Timer(500, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (_leftPanel.isCollapsed()) { _leftPanel.setVisible(false); } } }); timer.setRepeats(false); timer.start(); } }
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 www .ja va 2s.c o m } 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:org.datavyu.controllers.AutosaveC.java
public static void setInterval(int interval) { if (interval == 0) { if (timer != null) { timer.stop();//from w ww .j a va 2s . c om timer = null; } return; } interval *= 60000; if (timer == null) { timer = new Timer(interval, new AutosaveC()); timer.start(); } else { timer.setDelay(interval); } }
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);/*w w w .j a v a2 s. c o 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.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 a 2 s. c o m*/ 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(); }//from w ww . j a v a 2s . co 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); }/*from 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.intermine.install.swing.ProjectEditor.java
/** * Common initialisation: lays out the child components and wires up the necessary * event listeners. //w ww. ja v a2s . co m */ private void init() { setName("Project Editor Frame"); setTitle(Messages.getMessage("projecteditor.title")); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener(new MyWindowListener()); modelViewerFrame = new JFrame(); modelViewerFrame.setName("Model Viewer Frame"); modelViewer = new ModelViewer(); modelViewerFrame.setContentPane(modelViewer); modelViewerFrame.setTitle(Messages.getMessage("modelviewer.title")); modelViewerFrame.setSize(800, 600); newMineDialog = new NewMineDialog(this); createDatabaseDialog = new CreateDatabaseDialog(this); newMineDialog.setCreateDatabaseDialog(createDatabaseDialog); createPropertiesDialog = new CreatePropertiesDialog(this); createDatabaseDialog.setCreatePropertiesDialog(createPropertiesDialog); makeMineDialog = new MakeMineDialog(this); createPropertiesDialog.setMakeMineDialog(makeMineDialog); addSourceDialog = new AddSourceDialog(this); newDerivedSourceDialog = new NewDerivedTypeDialog(this); addSourceDialog.setNewDerivedDialog(newDerivedSourceDialog); postProcessorDialog = new PostProcessorDialog(this); buildProjectDialog = new BuildProjectDialog(this); preferencesDialog = new PreferencesDialog(this); ProjectListener projectListener = new MyProjectListener(); addSourceDialog.addProjectListener(projectListener); newDerivedSourceDialog.addProjectListener(projectListener); postProcessorDialog.addProjectListener(projectListener); sourcePanel.addProjectListener(projectListener); makeMineDialog.addProjectListener(projectListener); addProjectListener(projectListener); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu fileMenu = new JMenu(Messages.getMessage("file")); fileMenu.setMnemonic(KeyEvent.VK_P); menuBar.add(fileMenu); fileMenu.add(new NewMineAction()); fileMenu.add(new OpenAction()); fileMenu.addSeparator(); fileMenu.add(saveAction); fileMenu.addSeparator(); fileMenu.add(buildProjectAction); JMenu editMenu = new JMenu(Messages.getMessage("edit")); editMenu.setMnemonic(KeyEvent.VK_E); menuBar.add(editMenu); editMenu.add(addSourceAction); editMenu.add(deleteSourceAction); editMenu.addSeparator(); editMenu.add(postProcessorAction); JMenu viewMenu = new JMenu(Messages.getMessage("view")); viewMenu.setMnemonic(KeyEvent.VK_M); menuBar.add(viewMenu); viewMenu.add(new ViewModelAction()); JMenu toolsMenu = new JMenu(Messages.getMessage("tools")); toolsMenu.setMnemonic(KeyEvent.VK_T); menuBar.add(toolsMenu); toolsMenu.add(new PreferencesAction()); sourceListModel = new SourceListModel(); sourceList = new JList(sourceListModel); Container cp = getContentPane(); cp.setLayout(new BorderLayout()); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); cp.add(splitPane, BorderLayout.CENTER); initButtonPanel(); Box vbox = Box.createVerticalBox(); vbox.add(sourcePanel); vbox.add(buttonPanel); splitPane.setLeftComponent(new JScrollPane(sourceList)); splitPane.setRightComponent(vbox); splitPane.setDividerLocation(200); initStatusPanel(); cp.add(statusPanel, BorderLayout.SOUTH); sourceList.setCellRenderer(new SourceListRenderer()); sourceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); sourceList.addListSelectionListener(new SourceListSelectionListener()); statusMessageClearTimer = new Timer(4000, new StatusMessageClearer()); statusMessageClearTimer.setInitialDelay(4000); statusMessageClearTimer.setRepeats(false); setSize(800, 600); }