List of usage examples for javax.swing Timer setRepeats
public void setRepeats(boolean flag)
flag
is false
, instructs the Timer
to send only one action event to its listeners. From source file:com.qframework.core.ServerkoParse.java
public void loadModule(final String resptype) { Timer t = new javax.swing.Timer(0, new ActionListener() { public void actionPerformed(ActionEvent e) { execLoadModule(resptype);/*from w w w . j a v a 2 s . co m*/ } }); t.setRepeats(false); t.start(); }
From source file:com.qframework.core.ServerkoParse.java
public void loadModule2(final String resptype) { Timer t = new javax.swing.Timer(0, new ActionListener() { public void actionPerformed(ActionEvent e) { execLoadModule2(resptype);//from w w w. ja v a 2s . c o m } }); //t.setIntialDelay(delay); t.setRepeats(false); t.start(); }
From source file:com.qframework.core.ServerkoParse.java
public void loadScript(final String resptype, int time) { Timer t = new javax.swing.Timer(time, new ActionListener() { public void actionPerformed(ActionEvent e) { execLoadModule2(resptype);// w w w .java2 s. c o m } }); //t.setIntialDelay(delay); t.setRepeats(false); t.start(); }
From source file:net.sf.jabref.gui.MainTableSelectionListener.java
private void updatePreview(final BibtexEntry toShow, final boolean changedPreview, int repeats) { if (workingOnPreview) { if (repeats > 0) { return; // We've already waited once. Give up on this selection. }//from w ww .j ava2s .c o m Timer t = new Timer(50, actionEvent -> updatePreview(toShow, changedPreview, 1)); t.setRepeats(false); t.start(); return; } EventList<BibtexEntry> list = table.getSelected(); // Check if the entry to preview is still selected: if ((list.size() != 1) || (list.get(0) != toShow)) { return; } final int mode = panel.getMode(); workingOnPreview = true; SwingUtilities.invokeLater(() -> { preview.setEntry(toShow); // If nothing was already shown, set the preview and move the separator: if (changedPreview || (mode == BasePanel.SHOWING_NOTHING)) { panel.showPreview(preview); panel.adjustSplitter(); } workingOnPreview = false; }); }
From source file:fr.duminy.jbackup.core.JBackupImpl.java
@Override public Timer shutdown(final TerminationListener listener) throws InterruptedException { executor.shutdown();// w w w . ja va 2 s .c o m Timer timer = null; if (listener != null) { timer = new Timer(0, null); timer.setDelay((int) TimeUnit.SECONDS.toMillis(1)); final Timer finalTimer = timer; timer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (executor.isTerminated()) { listener.terminated(); finalTimer.stop(); } } }); timer.setRepeats(true); timer.start(); } return timer; }
From source file:org.leo.benchmark.Benchmark.java
/** * Execute the current run code loop times. * /*from w w w . ja va 2 s. c o m*/ * @param run code to run * @param loop number of time to run the code * @param taskName name displayed at the end of the task */ @SuppressWarnings({ "unchecked", "rawtypes" }) private void execute(BenchRunnable run, int loop, String taskName) { System.out.print(taskName + " ... "); // set default context collection.clear(); collection.addAll(defaultCtx); // warmup warmUp(); isTimeout = false; // timeout timer Timer timer = new Timer((int) timeout, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { isTimeout = true; // to raise a ConcurrentModificationException or a // NoSuchElementException to interrupt internal work in the List collection.clear(); } }); timer.setRepeats(false); timer.start(); long startTime = System.nanoTime(); int i; for (i = 0; i < loop && !isTimeout; i++) { try { run.run(i); } catch (Exception e) { // on purpose so ignore it } } timer.stop(); long time = isTimeout ? timeout * 1000000 : System.nanoTime() - startTime; System.out.println((isTimeout ? "Timeout (>" + time + "ns) after " + i + " loop(s)" : time + "ns")); // restore default context, // the collection instance might have been // corrupted by the timeout so create a new instance try { Constructor<? extends Collection> constructor = collection.getClass() .getDeclaredConstructor((Class<?>[]) null); constructor.setAccessible(true); collection = constructor.newInstance(); // update the reference if (collection instanceof List) { list = (List<String>) collection; } } catch (Exception e1) { e1.printStackTrace(); } // store the results for display Map<Class<? extends Collection<?>>, Long> currentBench = benchResults.get(taskName); if (currentBench == null) { currentBench = new HashMap<Class<? extends Collection<?>>, Long>(); benchResults.put(taskName, currentBench); } currentBench.put((Class<? extends Collection<String>>) collection.getClass(), time); // little gc to clean up all the stuff System.gc(); }
From source file:me.mayo.telnetkek.MainPanel.java
private void writeToConsoleImmediately(final ConsoleMessage message, final boolean isTelnetError) { SwingUtilities.invokeLater(() -> { if (isTelnetError && chkIgnoreErrors.isSelected()) { return; }//from w w w .j ava 2 s . c o m final StyledDocument styledDocument = mainOutput.getStyledDocument(); int startLength = styledDocument.getLength(); try { styledDocument.insertString(styledDocument.getLength(), message.getMessage() + System.lineSeparator(), StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, message.getColor())); } catch (BadLocationException ex) { throw new RuntimeException(ex); } if (MainPanel.this.chkAutoScroll.isSelected() && MainPanel.this.mainOutput.getSelectedText() == null) { final JScrollBar vScroll = mainOutputScoll.getVerticalScrollBar(); if (!vScroll.getValueIsAdjusting()) { if (vScroll.getValue() + vScroll.getModel().getExtent() >= (vScroll.getMaximum() - 50)) { MainPanel.this.mainOutput.setCaretPosition(startLength); final Timer timer = new Timer(10, (ActionEvent ae) -> { vScroll.setValue(vScroll.getMaximum()); }); timer.setRepeats(false); timer.start(); } } } }); }
From source file:FileTreeDragSource.java
public void dragDropEnd(DragSourceDropEvent dsde) { DnDUtils.debugPrintln("Drag Source: drop completed, drop action = " + DnDUtils.showActions(dsde.getDropAction()) + ", success: " + dsde.getDropSuccess()); // If the drop action was ACTION_MOVE, // the tree might need to be updated. if (dsde.getDropAction() == DnDConstants.ACTION_MOVE) { final File[] draggedFiles = dragFiles; final TreePath[] draggedPaths = paths; Timer tm = new Timer(200, new ActionListener() { public void actionPerformed(ActionEvent evt) { // Check whether each of the dragged files exists. // If it does not, we need to remove the node // that represents it from the tree. for (int i = 0; i < draggedFiles.length; i++) { if (draggedFiles[i].exists() == false) { // Remove this node DefaultMutableTreeNode node = (DefaultMutableTreeNode) draggedPaths[i] .getLastPathComponent(); ((DefaultTreeModel) tree.getModel()).removeNodeFromParent(node); }//from ww w.j av a 2s .c om } } }); tm.setRepeats(false); tm.start(); } }
From source file:com.qframework.core.GameonApp.java
private void onTextInput(final String resptype, final String respdata) { Timer t = new javax.swing.Timer(50, new ActionListener() { public void actionPerformed(ActionEvent e) { JTextField area = new JTextField(resptype); area.setFocusable(true);//ww w . ja v a 2s . c o m area.requestFocus(); Object options[] = new Object[] { area }; Frame parent = null; if (mAppContext != null) parent = (Frame) SwingUtilities.getAncestorOfClass(java.awt.Frame.class, mAppContext); else parent = (Frame) SwingUtilities.getAncestorOfClass(java.awt.Frame.class, mAppletContext); int option = JOptionPane.showOptionDialog(parent, options, "", JOptionPane.YES_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null); if (option == JOptionPane.YES_OPTION) { String truncated = area.getText().replaceAll("[^A-Za-z0-9:.@ ]", ""); String script = respdata + "('" + truncated + "' , 1);"; mScript.execScript(script); } else { String script = respdata + "(undefined, 1);"; mScript.execScript(script); } } }); t.setRepeats(false); t.start(); }
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 w w w . j av a 2 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(); }