Java Code Examples for javax.swing.Timer#setInitialDelay()

The following examples show how to use javax.swing.Timer#setInitialDelay() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CursorBlinker.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public CursorBlinker(FieldPanel panel) {
	this.fieldPanel = panel;

	timer = new Timer(500, new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			if (paintBounds != null) {
				showCursor = !showCursor;
				fieldPanel.paintImmediately(paintBounds);
			}
			else {
				timer.stop();
			}
		}
	});

	// the initial painting is laggy for some reason, so shorten the delay
	timer.setInitialDelay(100);
	timer.start();

}
 
Example 2
Source File: DialogComponentProvider.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void showProgressBar(String localTitle, boolean hasProgress, boolean canCancel,
		int delay) {
	taskMonitorComponent.reset();
	Runnable r = () -> {
		if (delay <= 0) {
			showProgressBar(localTitle, hasProgress, canCancel);
		}
		else {
			showTimer = new Timer(delay, ev -> {
				if (taskScheduler.isBusy()) {
					showProgressBar(localTitle, hasProgress, canCancel);
					showTimer = null;
				}
			});
			showTimer.setInitialDelay(delay);
			showTimer.setRepeats(false);
			showTimer.start();
		}
	};

	SystemUtilities.runSwingNow(r);
}
 
Example 3
Source File: TextEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize timers and handle their ticks.
 */
private void initTimer() {
    timer = new Timer(0, new java.awt.event.ActionListener() {
        // we are called from the AWT thread so put itno other one
        public void actionPerformed(java.awt.event.ActionEvent e) {
            if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("$$ TextEditorSupport::initTimer::actionPerformed: event = " + e);

            RequestProcessor.postRequest( new Runnable() {
                public void run() {
                    syncDocument(false);
                }
            });
        }
    });

    timer.setInitialDelay(getAutoParsingDelay());
    timer.setRepeats(false);
}
 
Example 4
Source File: TumbleItem.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void init() {
    loadAppletParameters();

    // Execute a job on the event-dispatching thread:
    // creating this applet's GUI.
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                createGUI();
            }
        });
    } catch (Exception e) {
        System.err.println("createGUI didn't successfully complete");
    }

    // Set up timer to drive animation events.
    timer = new Timer(speed, this);
    timer.setInitialDelay(pause);
    timer.start();

    // Start loading the images in the background.
    worker.execute();
}
 
Example 5
Source File: BalloonManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
synchronized void startDismissTimer (int timeout) {
    stopDismissTimer();
    currentAlpha = 1.0f;
    dismissTimer = new Timer(DISMISS_REPAINT_REPEAT, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            currentAlpha -= ALPHA_DECREMENT;
            if( currentAlpha <= ALPHA_DECREMENT ) {
                stopDismissTimer();
                dismiss();
            }
            repaint();
        }
    });
    dismissTimer.setInitialDelay (timeout);
    dismissTimer.start();
}
 
Example 6
Source File: ImportForm.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
private void createUIComponents() {
    userAccountPanel = new UserAccountPanel();
    refreshButton = new JButton(AllIcons.Actions.Refresh);

    // Create timer for filtering the list
    timer = new Timer(400, null);
    timer.setInitialDelay(400);
    timer.setActionCommand(CMD_PROJECT_FILTER_CHANGED);
    timer.setRepeats(false);
}
 
Example 7
Source File: AquaScrollBarUI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected void installListeners() {
    fTrackListener = createTrackListener();
    fModelListener = createModelListener();
    fPropertyChangeListener = createPropertyChangeListener();
    fScrollBar.addMouseListener(fTrackListener);
    fScrollBar.addMouseMotionListener(fTrackListener);
    fScrollBar.getModel().addChangeListener(fModelListener);
    fScrollBar.addPropertyChangeListener(fPropertyChangeListener);
    fScrollListener = createScrollListener();
    fScrollTimer = new Timer(kNormalDelay, fScrollListener);
    fScrollTimer.setInitialDelay(kInitialDelay); // default InitialDelay?
}
 
Example 8
Source File: BusySpinnerPanel.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
public BusySpinnerPanel() {
    timer = new Timer(40, new TimerListener(this));
    timer.setRepeats(true);
    timer.setInitialDelay(40);
    timer.setDelay(40);
    start(false);
}
 
Example 9
Source File: DashboardPanel.java    From zencash-swing-wallet-ui with MIT License 5 votes vote down vote up
public LatestTransactionsPanel()
	throws InterruptedException, IOException, WalletCallException
{
	final JPanel content = new JPanel();
	content.setLayout(new BorderLayout(3,  3));
	content.add(new JLabel(langUtil.getString("panel.dashboard.transactions.label")),
			    BorderLayout.NORTH);
	transactionList = new LatestTransactionsList();
	JPanel tempPanel = new JPanel(new BorderLayout(0,  0));
	tempPanel.add(transactionList, BorderLayout.NORTH);
	content.add(tempPanel, BorderLayout.CENTER); 
	
	// Pre-fill transaction list once
	this.transactions = getTransactionsDataFromWallet();
	transactionList.updateTransactions(this.transactions);
	
	ActionListener al = new ActionListener() 
	{
		@Override
		public void actionPerformed(ActionEvent e) 
		{
			LatestTransactionsPanel.this.transactions = transactionGatheringThread.getLastData();
			if (LatestTransactionsPanel.this.transactions != null)
			{
				transactionList.updateTransactions(LatestTransactionsPanel.this.transactions);
			}
		}
	};
	
	Timer latestTransactionsTimer =  new Timer(8000, al);
	latestTransactionsTimer.setInitialDelay(8000);
	latestTransactionsTimer.start();
				
	this.setLayout(new GridLayout(1, 1));
	this.add(content);
}
 
Example 10
Source File: AquaScrollBarUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void installListeners() {
    fTrackListener = createTrackListener();
    fModelListener = createModelListener();
    fPropertyChangeListener = createPropertyChangeListener();
    fScrollBar.addMouseListener(fTrackListener);
    fScrollBar.addMouseMotionListener(fTrackListener);
    fScrollBar.getModel().addChangeListener(fModelListener);
    fScrollBar.addPropertyChangeListener(fPropertyChangeListener);
    fScrollListener = createScrollListener();
    fScrollTimer = new Timer(kNormalDelay, fScrollListener);
    fScrollTimer.setInitialDelay(kInitialDelay); // default InitialDelay?
}
 
Example 11
Source File: KLHandler.java    From AndrOBD with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Default constructor
 */
public KLHandler()
{
	// set the logger object
	log = Logger.getLogger("com.fr3ts0n.prot.kl");

	commTimer = new Timer(commTimeoutTime, commTimeoutHandler);
	commTimer.setInitialDelay(commTimeoutTime);
	commTimer.stop();
}
 
Example 12
Source File: AquaScrollBarUI.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void installListeners() {
    fTrackListener = createTrackListener();
    fModelListener = createModelListener();
    fPropertyChangeListener = createPropertyChangeListener();
    fScrollBar.addMouseListener(fTrackListener);
    fScrollBar.addMouseMotionListener(fTrackListener);
    fScrollBar.getModel().addChangeListener(fModelListener);
    fScrollBar.addPropertyChangeListener(fPropertyChangeListener);
    fScrollListener = createScrollListener();
    fScrollTimer = new Timer(kNormalDelay, fScrollListener);
    fScrollTimer.setInitialDelay(kInitialDelay); // default InitialDelay?
}
 
Example 13
Source File: KLHandlerGeneric.java    From AndrOBD with GNU General Public License v3.0 5 votes vote down vote up
/**
 * construct with connecting to device
 *
 * @param device device to connect
 */
private KLHandlerGeneric(String device)
{
	try
	{
		setDeviceName(device);
	} catch (Exception ex)
	{
		log.log(Level.SEVERE,"", ex);
	}
	commTimer = new Timer(commTimeoutTime, commTimeoutHandler);
	commTimer.setInitialDelay(commTimeoutTime);
	commTimer.stop();
}
 
Example 14
Source File: AnimatedGraphics.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Set up and start the timer
 */
public AnimatedGraphics() {
    Timer timer = new Timer(30, this);
    // initial delay while window gets set up
    timer.setInitialDelay(1000);
    animStartTime = 1000 + System.nanoTime() / 1000000;
    timer.start();
}
 
Example 15
Source File: AquaScrollBarUI.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected void installListeners() {
    fTrackListener = createTrackListener();
    fModelListener = createModelListener();
    fPropertyChangeListener = createPropertyChangeListener();
    fScrollBar.addMouseListener(fTrackListener);
    fScrollBar.addMouseMotionListener(fTrackListener);
    fScrollBar.getModel().addChangeListener(fModelListener);
    fScrollBar.addPropertyChangeListener(fPropertyChangeListener);
    fScrollListener = createScrollListener();
    fScrollTimer = new Timer(kNormalDelay, fScrollListener);
    fScrollTimer.setInitialDelay(kInitialDelay); // default InitialDelay?
}
 
Example 16
Source File: AquaScrollBarUI.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected void installListeners() {
    fTrackListener = createTrackListener();
    fModelListener = createModelListener();
    fPropertyChangeListener = createPropertyChangeListener();
    fScrollBar.addMouseListener(fTrackListener);
    fScrollBar.addMouseMotionListener(fTrackListener);
    fScrollBar.getModel().addChangeListener(fModelListener);
    fScrollBar.addPropertyChangeListener(fPropertyChangeListener);
    fScrollListener = createScrollListener();
    fScrollTimer = new Timer(kNormalDelay, fScrollListener);
    fScrollTimer.setInitialDelay(kInitialDelay); // default InitialDelay?
}
 
Example 17
Source File: TextualDocumentView.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void initGUI() {
  // textView = new JEditorPane();
  // textView.setContentType("text/plain");
  // textView.setEditorKit(new RawEditorKit());

  textView = new JTextArea();
  textView.setAutoscrolls(false);
  textView.setLineWrap(true);
  textView.setWrapStyleWord(true);
  // the selection is hidden when the focus is lost for some system
  // like Linux, so we make sure it stays
  // it is needed when doing a selection in the search textfield
  textView.setCaret(new PermanentSelectionCaret());
  scroller = new JScrollPane(textView);

  textView.setText(document.getContent().toString());
  textView.getDocument().addDocumentListener(swingDocListener);
  // display and put the caret at the beginning of the file
  SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
      try {
        if(textView.modelToView(0) != null) {
          textView.scrollRectToVisible(textView.modelToView(0));
        }
        textView.select(0, 0);
        textView.requestFocus();
      } catch(BadLocationException e) {
        e.printStackTrace();
      }
    }
  });
  // contentPane = new JPanel(new BorderLayout());
  // contentPane.add(scroller, BorderLayout.CENTER);

  // //get a pointer to the annotation list view used to display
  // //the highlighted annotations
  // Iterator horizViewsIter = owner.getHorizontalViews().iterator();
  // while(annotationListView == null && horizViewsIter.hasNext()){
  // DocumentView aView = (DocumentView)horizViewsIter.next();
  // if(aView instanceof AnnotationListView)
  // annotationListView = (AnnotationListView)aView;
  // }
  highlightsMinder = new Timer(BLINK_DELAY, new UpdateHighlightsAction());
  highlightsMinder.setInitialDelay(HIGHLIGHT_DELAY);
  highlightsMinder.setDelay(BLINK_DELAY);
  highlightsMinder.setRepeats(true);
  highlightsMinder.setCoalesce(true);
  highlightsMinder.start();

  // blinker = new Timer(this.getClass().getCanonicalName() +
  // "_blink_timer",
  // true);
  // final BlinkAction blinkAction = new BlinkAction();
  // blinker.scheduleAtFixedRate(new TimerTask(){
  // public void run() {
  // blinkAction.actionPerformed(null);
  // }
  // }, 0, BLINK_DELAY);
  initListeners();
}
 
Example 18
Source File: DashboardPanel.java    From zencash-swing-wallet-ui with MIT License 4 votes vote down vote up
public ExchangeRatePanel(StatusUpdateErrorReporter errorReporter)
{			
	// Start the thread to gather the exchange data
	this.zenDataGatheringThread = new DataGatheringThread<JsonObject>(
		new DataGatheringThread.DataGatherer<JsonObject>() 
		{
			public JsonObject gatherData()
				throws Exception
			{
				long start = System.currentTimeMillis();
				JsonObject exchangeData = ExchangeRatePanel.this.getExchangeDataFromRemoteService();
				long end = System.currentTimeMillis();
				Log.info("Gathering of ZEN Exchange data done in " + (end - start) + "ms." );
					
				return exchangeData;
			}
		}, 
		errorReporter, 60000, true);
	
	this.setLayout(new FlowLayout(FlowLayout.LEFT, 3, 18));
	this.recreateExchangeTable();
	
	// Start the timer to update the table
	ActionListener alExchange = new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e)
		{
			try
			{					
				ExchangeRatePanel.this.recreateExchangeTable();
			} catch (Exception ex)
			{
				Log.error("Unexpected error: ", ex);
				DashboardPanel.this.errorReporter.reportError(ex);
			}
		}
	};
	Timer t = new Timer(30000, alExchange); // TODO: add timer for disposal ???
	t.setInitialDelay(1000);
	t.start();
}
 
Example 19
Source File: GhidraSwingTimer.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public GhidraSwingTimer(int initialDelay, int delay, TimerCallback callback) {
	this.callback = callback;
	timer = new Timer(delay, this);
	timer.setInitialDelay(initialDelay);
}
 
Example 20
Source File: SessionManager.java    From chipster with MIT License 4 votes vote down vote up
/**
 * @param dataManager
 * @param taskExecutor 
 * @param fileBrokerClient
 * @param callback
 *            if null, SessionChangedEvents are ignored and error messages
 *            are thrown as RuntimeExceptions
 * @throws IOException
 */
public SessionManager(final DataManager dataManager,
		TaskExecutor taskExecutor, FileBrokerClient fileBrokerClient, SessionManagerCallback callback)
		throws IOException {
	this.dataManager = dataManager;
	this.taskExecutor = taskExecutor;
	this.fileBrokerClient = fileBrokerClient;
	if (callback == null) {
		this.callback = new BasicSessionManagerCallback();
	} else {
		this.callback = callback;
	}

	// Remember changes to confirm close only when necessary and to backup
	// when necessary
	dataManager.addDataChangeListener(new DataChangeListener() {
		public void dataChanged(DataChangeEvent event) {
			unsavedChanges = true;
			unbackuppedChanges = true;
		}
	});

	// Start checking if background backup is needed
	aliveSignalFile = new File(dataManager.getRepository(), "i_am_alive");
	aliveSignalFile.createNewFile();
	aliveSignalFile.deleteOnExit();

	Timer timer = new Timer(SESSION_BACKUP_INTERVAL, new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			aliveSignalFile.setLastModified(System.currentTimeMillis()); // touch
																			// the
																			// file
			if (unbackuppedChanges) {

				File sessionFile = UserSession.findBackupFile(
						dataManager.getRepository(), true);
				sessionFile.deleteOnExit();

				try {
					saveLightweightSession(sessionFile);

				} catch (Exception e1) {
					logger.warn(e1); // do not care that much about failing
										// session backups
				}
			}
			unbackuppedChanges = false;
		}
	});

	timer.setCoalesce(true);
	timer.setRepeats(true);
	timer.setInitialDelay(SESSION_BACKUP_INTERVAL);
	timer.start();
}