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

The following examples show how to use javax.swing.Timer#setCoalesce() . 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: LoaderScreen.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 8 votes vote down vote up
private void init() {
    setLayout(new BorderLayout());
    setBackground(Color.WHITE);
    loadLabel.setHorizontalAlignment(SwingConstants.CENTER);
    loadLabel.setHorizontalTextPosition(SwingConstants.CENTER);
    loadLabel.setVerticalTextPosition(SwingConstants.BOTTOM);

    loadLabel.setBackground(Color.WHITE);
    add(loadLabel, BorderLayout.CENTER);

    tick = new Timer(500, (ActionEvent ae) -> {
        repaint();
    });
    tick.setCoalesce(true);
    tick.setRepeats(true);
}
 
Example 2
Source File: InfoPanel.java    From netbeans with Apache License 2.0 7 votes vote down vote up
private synchronized void makeVisible(boolean animate, final boolean top, final Item lastTop) {
    if (animationRunning) {
        return;
    }
    int height = top ? preferredHeight - tapPanelMinimumHeight : preferredHeight;
    if (!animate) {
        setTop(top);
        if (top && lastTop != null) {
            lastTop.setTop(false);
        }
        scrollPane.setPreferredSize(new Dimension(0, height));
        outerPanel.setPreferredSize(new Dimension(0, height));
        scrollPane.setVisible(true);
        separator.setVisible(true);
    } else {
        scrollPane.setPreferredSize(new Dimension(0, 1));
        outerPanel.setPreferredSize(new Dimension(0, height));
        animationRunning = true;
        isTop = top;
        if (isTop && lastTop != null) {
            lastTop.setTop(false);
        }
        topGapPanel.setVisible(!isTop);
        if (animationRunning) {
            scrollPane.setVisible(true);
            separator.setVisible(true);
            tapPanel.revalidate();
        }
        if (isTop) {
            tapPanel.setBackground(backgroundColor);
        }
        int delta = 1;
        int currHeight = 1;
        Timer animationTimer = new Timer(20, null);
        animationTimer.addActionListener(new AnimationTimerListener(animationTimer, delta, currHeight));
        animationTimer.setCoalesce(false);
        animationTimer.start();
    } // else
}
 
Example 3
Source File: AnnotationSetsView.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public AnnotationSetsView(){
  setHandlers = new ArrayList<SetHandler>();
  tableRows = new ArrayList<Object>();
  visibleAnnotationTypes = new LinkedBlockingQueue<TypeSpec>();
  pendingEvents = new LinkedBlockingQueue<GateEvent>();
  eventMinder = new Timer(EVENTS_HANDLE_DELAY, 
          new HandleDocumentEventsAction());
  eventMinder.setRepeats(true);
  eventMinder.setCoalesce(true);    
}
 
Example 4
Source File: CachedMBeanServerConnectionFactory.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
SnapshotInvocationHandler(MBeanServerConnection conn, int interval) {
    this.conn = conn;
    this.interval = interval;
    if (interval > 0) {
        timer = new Timer(interval, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                intervalElapsed();
            }
        });
        timer.setCoalesce(true);
        timer.start();
    }
}
 
Example 5
Source File: XPlottingViewer.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public Plotter createPlotter(final XMBean xmbean,
                             final String attributeName,
                             String key,
                             JTable table) {
    final Plotter p = new XPlotter(table, Plotter.Unit.NONE) {
        Dimension prefSize = new Dimension(400, 170);
        @Override
        public Dimension getPreferredSize() {
            return prefSize;
        }
        @Override
        public Dimension getMinimumSize() {
            return prefSize;
        }
    };

    p.createSequence(attributeName, attributeName, null, true);

    Timer timer = new Timer(tab.getUpdateInterval(), new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            intervalElapsed(p);
        }
    });
    timer.setCoalesce(true);
    timer.setInitialDelay(0);
    timer.start();
    timerCache.put(key, timer);
    return p;
}
 
Example 6
Source File: GBrowserView.java    From chipster with MIT License 5 votes vote down vote up
public void zoomAnimation(final int centerX, final int wheelRotation) {
	stopAnimation();

	mouseAnimationTimer = new Timer(1000 / FPS, new ActionListener() {

		private int i = 2; //Skip some frames to give a head start

		private long startTime = System.currentTimeMillis();
		private int ANIMATION_FRAMES = 15;

		public void actionPerformed(ActionEvent arg0) {

			boolean skipFrame = (i < (ANIMATION_FRAMES - 1)) && System.currentTimeMillis() > startTime + (1000 / FPS) * i;
			boolean done = false;

			do {
				
				done = i >= ANIMATION_FRAMES;
				
				if (!done) {
					zoom(centerX, wheelRotation, skipFrame);
					i++;

				} else {
					stopAnimation();
				}
				
			} while (skipFrame && !done);
		}
	});

	mouseAnimationTimer.setRepeats(true);
	mouseAnimationTimer.setCoalesce(true);
	mouseAnimationTimer.start();
}
 
Example 7
Source File: SlideGestureRecognizer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
AutoSlideTrigger() {
    super();
    slideInTimer = new Timer(200, this);
    slideInTimer.setRepeats(true);
    slideInTimer.setCoalesce(true);
}
 
Example 8
Source File: MinicraftServerThread.java    From minicraft-plus-revived with GNU General Public License v3.0 4 votes vote down vote up
MinicraftServerThread(Socket socket, MinicraftServer serverInstance) {
	super("MinicraftServerThread", socket);
	valid = true;
	
	this.serverInstance = serverInstance;
	if(serverInstance.isFull()) {
		sendError("server at max capacity.");
		super.endConnection();
		return;
	}
	
	client = new RemotePlayer(null, false, socket.getInetAddress(), socket.getPort());
	
	// username is set later
	
	packetTypesToKeep.addAll(InputType.tileUpdates);
	packetTypesToKeep.addAll(InputType.entityUpdates);
	
	pingTimer = new Timer(PING_INTERVAL, e -> {
		if(!isConnected()) {
			pingTimer.stop();
			return;
		}
		
		//if(Game.debug) System.out.println("received ping from "+this+": "+receivedPing+". Previously missed "+missedPings+" pings.");
		
		if(!receivedPing) {
			missedPings++;
			if(missedPings >= MISSED_PING_THRESHOLD) {
				// disconnect from the client; they are taking too long to respond and probably don't exist at this point.
				pingTimer.stop();
				sendError("client ping too slow, server timed out");
				endConnection();
			}
		} else {
			missedPings = 0;
			receivedPing = false;
		}
		
		sendData(InputType.PING, autoPing);
	});
	pingTimer.setRepeats(true);
	pingTimer.setCoalesce(true); // don't try to make up for lost pings.
	pingTimer.start();
	
	start();
}
 
Example 9
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 10
Source File: GBrowserView.java    From chipster with MIT License 4 votes vote down vote up
public void mouseReleased(MouseEvent e) {

		if (dragStarted && dragEndPoint != null && dragLastStartPoint != null && Math.abs(dragEndPoint.getX() - dragLastStartPoint.getX()) > 10 && System.currentTimeMillis() - dragEventTime < DRAG_EXPIRATION_TIME_MS) {

			stopAnimation();

			mouseAnimationTimer = new Timer(1000 / FPS, new ActionListener() {

				private int i = 2; //Skip a few frames to get a head start
				private int ANIMATION_FRAMES = 30;
				private long startTime = System.currentTimeMillis();

				public void actionPerformed(ActionEvent arg0) {
					
					boolean skipFrame = false;
					boolean done = false;

					do {
						double endX = dragEndPoint.getX();
						double startX = dragLastStartPoint.getX();

						double newX = endX - (endX - startX) / (ANIMATION_FRAMES - i);

						dragEndPoint = new Point2D.Double(newX, dragEndPoint.getY());

						skipFrame = (i < (ANIMATION_FRAMES - 1)) && System.currentTimeMillis() > startTime + (1000 / FPS) * i;

						done = i >= ANIMATION_FRAMES;
						
						if (!done) {
							handleDrag(dragLastStartPoint, dragEndPoint, skipFrame);
							i++;
						} else {
							stopAnimation();
						}
						
					} while (skipFrame && !done);
				}
			});
			mouseAnimationTimer.setCoalesce(true);
			mouseAnimationTimer.setRepeats(true);
			mouseAnimationTimer.start();
		}
	}
 
Example 11
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();
}