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

The following examples show how to use javax.swing.Timer#stop() . 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: AnimatedLayout.java    From pumpernickel with MIT License 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
	Timer timer = (Timer) e.getSource();

	boolean workToDo = false;

	synchronized (container.getTreeLock()) {
		Map<JComponent, Rectangle> destinationMap = getDestinationMap(container);
		for (Entry<JComponent, Rectangle> entry : destinationMap
				.entrySet()) {
			if (nudge(entry.getKey(), entry.getValue()) == false) {
				workToDo = true;
			}
		}
	}
	// on Windows, Ladislav pointed out there's a repaint problem
	container.repaint();

	if (workToDo == false)
		timer.stop();
}
 
Example 2
Source File: DataSourceCaption.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private void createTimer() {
    final Icon[] busyIcons = new Icon[15];

    for (int i = 0; i < busyIcons.length; i++) busyIcons[i] = new ImageIcon(getClass().getResource("/org/graalvm/visualvm/core/ui/resources/busy-icon" + i + ".png"));    // NOI18N
    busyIconTimer = new Timer(ANIMATION_RATE, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (!ANIMATE) {
                if (busyIconTimer != null) busyIconTimer.stop(); // Stop animation
                presenter1.setIcon(new ImageIcon(getClass().getResource("/org/graalvm/visualvm/core/ui/resources/busy-icon4.png")));   // NOI18N
            } else {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                if (!DataSourceCaption.this.isShowing()) return;
                presenter1.setIcon(busyIcons[busyIconIndex]);
            }
        }
    });
}
 
Example 3
Source File: ThreeDeeView.java    From WorldPainter with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public void hierarchyChanged(HierarchyEvent event) {
        if ((event.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0) {
            if (isDisplayable()) {
//                for (Tile tile: dimension.getTiles()) {
//                    threeDeeRenderManager.renderTile(tile);
//                }
                timer = new Timer(250, this);
                timer.start();
            } else {
                timer.stop();
                timer = null;
                threeDeeRenderManager.stop();
                for (Tile tile : dimension.getTiles()) {
                    tile.removeListener(this);
                }
                dimension.removeDimensionListener(this);
            }
        }
    }
 
Example 4
Source File: ProgressLabel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void setupProgress() {
    setIcon(createProgressIcon());
    t = new Timer(100, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Component comp = refComp.get();
            TreeListNode nd = refNode.get();
            if (nd == null && comp == null) {
                t.stop();
                Container p = getParent();
                if (p != null) {
                    p.remove(ProgressLabel.this);
                }
            } else {
                busyIcon.tick();
                ProgressLabel.this.repaint();
                if (nd != null) {
                    nd.fireContentChanged();
                } else {
                    comp.repaint();
                }
            }
        }
    });
    t.setRepeats(true);
    super.setVisible(false);
}
 
Example 5
Source File: WeakTimerListener.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent evt) {
    ActionListener src = (ActionListener)ref.get();
    if (src != null) {
        src.actionPerformed(evt);

    } else { // source listener was garbage collected
        if (evt.getSource() instanceof Timer) {
            Timer timer = (Timer)evt.getSource();
            timer.removeActionListener(this);

            if (stopTimer) {
                timer.stop();
            }
        }
    }
}
 
Example 6
Source File: SearchHistoryPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Creates new form SearchHistoryPanel */
public SearchHistoryPanel(File [] roots, SearchCriteriaPanel criteria) {
    this.bOutSearch = false;
    this.bIncomingSearch = false;
    this.roots = roots;
    this.criteria = criteria;
    this.diffViewFactory = new SearchHistoryTopComponent.DiffResultsViewFactory();
    criteriaVisible = true;
    explorerManager = new ExplorerManager ();
    initComponents();
    initializeFilter();
    filterTimer = new Timer(500, this);
    filterTimer.setRepeats(false);
    filterTimer.stop();
    setupComponents();
    aquaBackgroundWorkaround();
    refreshComponents(true);
}
 
Example 7
Source File: SearchHistoryPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Creates new form SearchHistoryPanel */
public SearchHistoryPanel(File repository, RepositoryInfo info, File [] roots, SearchCriteriaPanel criteria) {
    this.roots = roots;
    this.repository = repository;
    this.info = info;
    this.criteria = criteria;
    this.diffViewFactory = new SearchHistoryTopComponent.DiffResultsViewFactory();
    criteriaVisible = true;
    explorerManager = new ExplorerManager ();
    initComponents();
    initializeFilter();
    filterTimer = new Timer(500, this);
    filterTimer.setRepeats(false);
    filterTimer.stop();
    setupComponents();
    info.addPropertyChangeListener(list = WeakListeners.propertyChange(this, info));
    aquaBackgroundWorkaround();
    refreshComponents(true);
}
 
Example 8
Source File: AwtEventDispatchThread.java    From mapper with Apache License 2.0 5 votes vote down vote up
private Registration timerReg(final Timer timer) {
  return new Registration() {
    @Override
    protected void doRemove() {
      if (timer.isRunning()) {
        timer.stop();
      }
    }
  };
}
 
Example 9
Source File: PublicMessageFrame.java    From myqq with MIT License 5 votes vote down vote up
/**
 * 显示窗体
 */
public void showFrame()
{
	this.setAlwaysOnTop(true);
	if(chat==null)
		btn打开.setVisible(false);
	int width=350;
	int height=266;
	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	setBounds(screenSize.width-width-3,screenSize.height,width,height);
	setVisible(true);
	Timer timer=new Timer(10, new ActionListener()
	{
		@Override
		public void actionPerformed(ActionEvent e)
		{
			setLocation(getLocation().x, getLocation().y-10);
		}
	});
	timer.start();
	while(true)
	{
		// 25表示任务栏的高度,好奇怪,有的电脑注释掉下面的输出语句就会出现弹窗不停止的奇怪现象
		System.out.println("当前高度:"+getLocation().y+",屏幕高度:"+screenSize.height);
		if(getLocation().y+height<screenSize.height-25)
		{
			timer.stop();
			break;
		}
	}
}
 
Example 10
Source File: CardsPicPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
private void initGUI() {
	renderer = new ReflectionRenderer();
	setBackgroundPainter(new MattePainter(PaintUtils.NIGHT_GRAY, true));

	GestionnaireEvenements interactionManager = new GestionnaireEvenements(this);
	this.addMouseListener(interactionManager);
	this.addMouseMotionListener(interactionManager);
	this.addMouseWheelListener(interactionManager);

	timer = new Timer(30, e -> {
		repaint();

		xScale += xDelta;

		if (xScale > 1 || xScale < -1) {
			xDelta *= -1;

		}

		if (loop > 0 && ((int) xScale == 1 || (int) xScale == -1)) {
			timer.stop();
			launched = false;

		}
		loop++;
	});
}
 
Example 11
Source File: TagManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
TagManager (File repository) {
    this.repository = repository;
    this.panel = new TagManagerPanel();
    panel.tagList.setCellRenderer(new TagRenderer());
    filterTimer = new Timer(300, new ActionListener() {
        @Override
        public void actionPerformed (ActionEvent e) {
            filterTimer.stop();
            applyFilter();
        }
    });
    attachListeners();
}
 
Example 12
Source File: CardDecksPanel.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
public CardDecksPanel() {

        decksJList.setOpaque(false);
        decksJList.setBackground(new Color(0, 0, 0, 1));
        decksJList.setForeground(Color.BLACK);
        decksJList.setFocusable(true);
        decksJList.setCellRenderer(new CardDecksListCellRenderer());
        decksJList.setFont(FontsAndBorders.FONT1);

        // scroll pane for deck names list
        scroller.setViewportView(decksJList);
        scroller.setBorder(null);
        scroller.setOpaque(false);
        scroller.getViewport().setOpaque(false);
        scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        decksJList.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent evt) {
                if (isDoubleClick(evt)) {
                    showSelectedDeck(decksJList.locationToIndex(evt.getPoint()));
                }
            }
        });

        miglayout.setLayoutConstraints("insets 0, flowy");
        setLayout(miglayout);

        // these constraints fix decksButton in CardPanel not resizing correctly
        // when full screen and decksbutton is clicked to re-show image. Ensure you
        // test if these constraints are updated especially if you add an 'h' constraint.
        add(scroller, "w 100%, growy, pushy");

        cooldownTimer = new Timer(TIMER_DELAY_MSECS, e -> {
            cooldownTimer.stop();
            showDecksContainingCard(CardDecksPanel.this.card);
        });

    }
 
Example 13
Source File: ShelveChangesSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private PatchNameListener (ShelveChangesPanel panel, JButton okButton, Dialog dialog) {
    this.panel = panel;
    this.button = okButton;
    this.dialog = dialog;
    timer = new Timer(300, this);
    timer.stop();
}
 
Example 14
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 15
Source File: ProgressMonitorWrapper.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
public ProgressMonitorWrapper(String msg, Runnable task) {
	pbar = new ProgressMonitor(null, msg, "Elapsed: 0 secs", 0, 4);
	start_time = System.currentTimeMillis();
	timer = new Timer(500, this);
	timer.start();

	thread = new Thread(() -> {
		task.run();
		timer.stop();
		pbar.close();
	});
	thread.start();
}
 
Example 16
Source File: KLHandlerGeneric.java    From AndrOBD with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Default constructor
 */
public KLHandlerGeneric()
{
	// set the logger object
	log = Logger.getLogger("com.fr3ts0n.prot.kl");

	commTimer = new Timer(commTimeoutTime, commTimeoutHandler);
	commTimer.setInitialDelay(commTimeoutTime);
	commTimer.stop();
}
 
Example 17
Source File: XPlottingViewer.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {
    plotterCache.remove(key);
    Timer t = timerCache.remove(key);
    t.stop();
    ((XMBeanAttributes) table).collapse(attributeName, this);
}
 
Example 18
Source File: AnimatedIcon.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public AnimatedIcon(List<? extends Icon> icons, int frameDelay, int framesToSkip) {
	this.iconList = icons;
	this.skipFrames = framesToSkip;
	timer = new Timer(frameDelay, new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			if (--paintCounter <= 0) {
				timer.stop();
				return;
			}

			if (skipFrameCount > 0) {
				skipFrameCount--;
				return;
			}
			if (++currentIconIndex >= iconList.size()) {
				currentIconIndex = 0;
				skipFrameCount = skipFrames;
			}
			if (component != null) {
				component.repaint();
			}
		}
	});

	for (Icon icon : iconList) {
		width = Math.max(width, icon.getIconWidth());
		height = Math.max(height, icon.getIconHeight());
	}
}
 
Example 19
Source File: ShakeWindow.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
    * punishes the User by moving the Chatwindow around for 10 seconds
    */
   public void startRandomMovement(final int seconds)
   {
if(window instanceof JFrame){
           JFrame f = (JFrame)window;
           f.setState(Frame.NORMAL);
           f.setVisible(true);
       }
       SparkManager.getNativeManager().flashWindow(window);
       
       final long startTime = System.currentTimeMillis()/1000L;
       
moveTimer = new Timer(5, e -> {
   Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

   double x = Math.random()*10000 % d.getWidth();
   double y = Math.random()*10000 % d.getHeight();
   int xx = Math.round(Math.round(x));
   int yy = Math.round(Math.round(y));
   window.setLocation(xx,yy);
   window.repaint();

   long now = System.currentTimeMillis()/1000L;
   long diff = now-startTime;
   System.out.println(diff);
   if(diff > seconds)
   {
       moveTimer.stop();
   }

       } );

moveTimer.start();

   }
 
Example 20
Source File: FadeInFadeOutHelper.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
public FadeInFadeOutHelper() {
    componentToHighlightTimer = new Timer(50, e -> {

        if (componentToHighlightFadeOut) {
            if (componentToHighlightPosition > 0) {
                componentToHighlightPosition -= 40;
            } else {
                componentToHighlightFadeOut = false;
                componentToHighlight = componentToHighlightNext;
            }
        } else {
            if (componentToHighlightNext != null) {
                componentToHighlight = componentToHighlightNext;
                componentToHighlightNext = null;
            }
            if (componentToHighlight != null) {
                Dimension theSize = componentToHighlight.getSize();
                if (componentToHighlightPosition < theSize.width + 10) {
                    int theStep = theSize.width + 10 - componentToHighlightPosition;
                    if (theStep > 40) {
                        theStep = 40;
                    }
                    componentToHighlightPosition += theStep;
                } else {
                    componentToHighlightTimer.stop();
                }
            } else {
                componentToHighlightTimer.stop();
            }
        }

        doRepaint();
    });
    componentToHighlightWaitTimer = new Timer(1000, e -> componentToHighlightTimer.start());
    componentToHighlightWaitTimer.setRepeats(false);
}