javax.swing.Timer#setCoalesce ( )源码实例Demo

下面列出了javax.swing.Timer#setCoalesce ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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);
}
 
源代码2 项目: netbeans   文件: InfoPanel.java
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
}
 
源代码3 项目: gate-core   文件: AnnotationSetsView.java
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);    
}
 
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();
    }
}
 
源代码5 项目: visualvm   文件: XPlottingViewer.java
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;
}
 
源代码6 项目: chipster   文件: GBrowserView.java
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();
}
 
源代码7 项目: netbeans   文件: SlideGestureRecognizer.java
AutoSlideTrigger() {
    super();
    slideInTimer = new Timer(200, this);
    slideInTimer.setRepeats(true);
    slideInTimer.setCoalesce(true);
}
 
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();
}
 
源代码9 项目: gate-core   文件: TextualDocumentView.java
@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();
}
 
源代码10 项目: chipster   文件: GBrowserView.java
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();
		}
	}
 
源代码11 项目: chipster   文件: SessionManager.java
/**
 * @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();
}