javax.swing.Timer Java Examples

The following examples show how to use javax.swing.Timer. 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: MapRenderer.java    From open-ig with GNU Lesser General Public License v3.0 7 votes vote down vote up
/** Preset. */
public MapRenderer() {
	setOpaque(true);
	addMouseListener(ma);
	addMouseMotionListener(ma);
	addMouseListener(sma);
	addMouseMotionListener(sma);
	animationTimer = new Timer(100, new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			//wrap animation index
			if (animation == Integer.MAX_VALUE) {
				animation = -1;
			}
			animation++;
			if (surface != null && surface.buildings.size() > 0) {
				boolean blink0 = blink;
				blink = (animation % 10) >= 5;
				if (blink0 != blink || (animation % 3 == 0)) {
					repaint();
				}
			}
		}
	});
	animationTimer.start();
}
 
Example #2
Source File: RTStatsTimer.java    From mts with GNU General Public License v3.0 6 votes vote down vote up
public RTStatsTimer(){

        // We call the constructer of the parent-class
        super();

        // We get the configuration of GUI_REFRESH_INTERVAL
        double interval = Config.getConfigByName("tester.properties").getDouble("stats.GUI_REFRESH_INTERVAL", 1);

        // We create a new timer with this config value as interval
        clock = new Timer((int)(interval * 1000), this);

        // We want an action repeating
        clock.setRepeats(true);

        // We start the timer
        clock.start();

        // We record this in the logger
        GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.CORE, "Refresh interval for real-times statistics is ", interval, "s");
    }
 
Example #3
Source File: TextGrid.java    From jclic with GNU General Public License v2.0 6 votes vote down vote up
/** Creates new TextGridBox */
public TextGrid(AbstractBox parent, JComponent container, double setX, double setY, int setNcw, int setNch,
    double setCellW, double setCellH, BoxBase boxBase, boolean setBorder) {
  super(parent, container, boxBase);
  x = setX;
  y = setY;
  nCols = Math.max(1, setNcw);
  nRows = Math.max(1, setNch);
  cellWidth = Math.max(setCellW, MIN_CELL_SIZE);
  cellHeight = Math.max(setCellH, MIN_CELL_SIZE);
  width = cellWidth * nCols;
  height = cellHeight * nRows;
  chars = new char[nRows][nCols];
  attributes = new int[nRows][nCols];
  preferredBounds.setRect(getBounds());
  setBorder(setBorder);
  cursorTimer = new Timer(500, this);
  cursorTimer.setRepeats(true);
  cursorEnabled = false;
  useCursor = false;
  wildTransparent = false;
  answers = null;
}
 
Example #4
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 #5
Source File: BranchSelector.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public BranchSelector (File repository) {
    this.repository = repository;
    panel = new BranchSelectorPanel();
    panel.branchList.setCellRenderer(new RevisionRenderer());
    
    filterTimer = new Timer(300, new ActionListener() {
        @Override
        public void actionPerformed (ActionEvent e) {
            filterTimer.stop();
            applyFilter();
        }
    });
    panel.txtFilter.getDocument().addDocumentListener(this);
    panel.branchList.addListSelectionListener(this);
    panel.jPanel1.setVisible(false);
    cancelButton = new JButton();
    org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(BranchSelector.class, "CTL_BranchSelector_Action_Cancel")); // NOI18N
    cancelButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(BranchSelector.class, "ACSD_BranchSelector_Action_Cancel")); // NOI18N
    cancelButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(BranchSelector.class, "ACSN_BranchSelector_Action_Cancel")); // NOI18N
}
 
Example #6
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 #7
Source File: AnimatedLayout.java    From pumpernickel with MIT License 6 votes vote down vote up
@Override
public void layoutContainer(Container parent) {
	JComponent jc = (JComponent) parent;
	install(jc);
	Timer timer = (Timer) jc.getClientProperty(PROPERTY_TIMER);
	Boolean layoutImmediately = (Boolean) jc
			.getClientProperty(PROPERTY_LAYOUT_IMMEDIATELY);
	if (layoutImmediately == null)
		layoutImmediately = false;
	if (layoutImmediately) {
		layoutContainerImmediately(jc);
		if (parent.isShowing())
			jc.putClientProperty(PROPERTY_LAYOUT_IMMEDIATELY, false);
	} else {
		if (!timer.isRunning())
			timer.start();
	}
}
 
Example #8
Source File: MainToolbar.java    From Quelea with GNU General Public License v3.0 6 votes vote down vote up
public void startRecording() {
        recordAudioButton.setSelected(true);
        recording = true;
//        getItems().add(pb);
        getItems().add(recordingPathTextField);
        recordAudioButton.setText("Recording...");
        recordAudioButton.setSelected(true);
        recordingsHandler = new RecordButtonHandler();
        recordingsHandler.passVariables("rec", pb, recordingPathTextField, recordAudioButton);
        final int interval = 1000; // 1000 ms
        recCount = new Timer(interval, (java.awt.event.ActionEvent e) -> {
            recTime += interval;
            setTime(recTime, recordAudioButton);
        });
        recCount.start();
    }
 
Example #9
Source File: RPToast.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
public void fadeOut() {
	final Timer timer = new Timer(FADE_REFRESH_RATE, null);
	timer.setRepeats(true);
	timer.addActionListener(new ActionListener() {
		private float opacity = MAX_OPACITY;

		@Override
		public void actionPerformed(ActionEvent e) {
			opacity -= OPACITY_INCREMENT;
			setOpacity(Math.max(opacity, 0));
			if (opacity <= 0) {
				timer.stop();
				setVisible(false);
				dispose();
			}
		}
	});
	setOpacity(MAX_OPACITY);
	timer.start();
}
 
Example #10
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 #11
Source File: MultipleContextsFunctionalTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
TestWindow(final int num) {
    super("Test Window [" + num + "]");
    setMinimumSize(new Dimension(300, 200));
    setLocation(100 + 400 * (num - 1), 100);

    setLayout(new BorderLayout());
    JLabel textBlock = new JLabel("Lorem ipsum dolor sit amet...");
    add(textBlock);

    btn = new JButton("TEST");
    add(btn, BorderLayout.SOUTH);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();

    t = new Timer(INTERVAL, this);
    t.setRepeats(false);
}
 
Example #12
Source File: MultipleContextsFunctionalTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
TestWindow(final int num) {
    super("Test Window [" + num + "]");
    setMinimumSize(new Dimension(300, 200));
    setLocation(100 + 400 * (num - 1), 100);

    setLayout(new BorderLayout());
    JLabel textBlock = new JLabel("Lorem ipsum dolor sit amet...");
    add(textBlock);

    btn = new JButton("TEST");
    add(btn, BorderLayout.SOUTH);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();

    t = new Timer(INTERVAL, this);
    t.setRepeats(false);
}
 
Example #13
Source File: SlideManager.java    From JCommunique with MIT License 6 votes vote down vote up
public void animate(Notification note, Location loc, double delay, double slideDelta, boolean slideIn) {
	m_note = note;
	m_x = note.getX();
	m_y = note.getY();
	m_delta = Math.abs(slideDelta);
	m_slideIn = slideIn;
	m_startLocation = loc;
	if (m_slideIn) {
		m_stopX = m_standardScreen.getX(m_startLocation, note);
		m_stopY = m_standardScreen.getY(m_startLocation, note);
	} else {
		m_stopX = m_noPaddingScreen.getX(m_startLocation, note);
		m_stopY = m_noPaddingScreen.getY(m_startLocation, note);
	}

	Timer timer = new Timer((int) delay, this);
	timer.start();
}
 
Example #14
Source File: DragWindow.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Timer createInitialEffect() {
    final Timer timer = new Timer(100, null);
    timer.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if( contentAlpha < 1.0f ) {
                contentAlpha += ALPHA_INCREMENT;
            } else {
                timer.stop();
            }
            if( contentAlpha > 1.0f )
                contentAlpha = 1.0f;
            repaintImageBuffer();
            repaint();
        }
    });
    timer.setInitialDelay(0);
    return timer;
}
 
Example #15
Source File: RotatingIcon.java    From btdex with GNU General Public License v3.0 6 votes vote down vote up
public RotatingIcon(Icon icon) {
	delegateIcon = icon;
	
	rotatingTimer = new Timer( 200, new ActionListener() {
		@Override
		public void actionPerformed( ActionEvent e ) {
			angleInDegrees = angleInDegrees + 40;
			if ( angleInDegrees == 360 ){
				angleInDegrees = 0;
			}
			
			for(DefaultTableModel model : cells.keySet()) {
				for(Point c : cells.get(model))
					model.fireTableCellUpdated(c.x, c.y);					
			}
		}
	} );
	rotatingTimer.setRepeats( false );
	rotatingTimer.start();
}
 
Example #16
Source File: DragWindow.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Timer createNoDropEffect() {
    final Timer timer = new Timer(100, null);
    timer.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if( contentAlpha > NO_DROP_ALPHA ) {
                contentAlpha -= ALPHA_INCREMENT;
            } else {
                timer.stop();
            }
            if( contentAlpha < NO_DROP_ALPHA )
                contentAlpha = NO_DROP_ALPHA;
            repaintImageBuffer();
            repaint();
        }
    });
    timer.setInitialDelay(0);
    return timer;
}
 
Example #17
Source File: StaffApplication.java    From RemoteSupportTool with Apache License 2.0 6 votes vote down vote up
@Override
public void start() {
    monitoringTimer = new Timer(1000, e -> {
        if (uploadMonitor == null || downloadMonitor == null)
            return;
        try {
            frame.setRates(downloadMonitor.getAverageRate(), uploadMonitor.getAverageRate());

            Date minAge = new Date(System.currentTimeMillis() - 2000);
            downloadMonitor.removeOldSamples(minAge);
            uploadMonitor.removeOldSamples(minAge);
        } catch (Exception ex) {
            LOGGER.warn("Can't upload monitoring!", ex);
        }
    });
    monitoringTimer.setRepeats(true);
    monitoringTimer.start();

    super.start();
}
 
Example #18
Source File: MemoryView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the Form
 */
public MemoryView() {
    initComponents();

    setTitle(bundle.getString("TXT_TITLE"));
    doGarbage.setText(bundle.getString("TXT_GARBAGE"));
    doRefresh.setText(bundle.getString("TXT_REFRESH"));
    doClose.setText(bundle.getString("TXT_CLOSE"));

    txtTime.setText(bundle.getString("TXT_TIME"));
    doTime.setText(bundle.getString("TXT_SET_TIME"));
    time.setText(String.valueOf(UPDATE_TIME));
    time.selectAll();
    time.requestFocus();

    updateStatus();

    timer = new Timer(UPDATE_TIME, new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            updateStatus();
        }
    });
    timer.setRepeats(true);

    pack();
}
 
Example #19
Source File: ExportDialog.java    From GiantTrees with GNU General Public License v3.0 5 votes vote down vote up
public ExportDialog(JFrame parent, Tree tr, Config cfg, boolean rend) {
		
		tree = tr;
		config = cfg;
		render = rend;
		
		frame = new JFrame("Create and export tree");
		frame.setIconImage(parent.getIconImage());
		//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		// FIXME: make this filechoosers static?
		fileChooser = new JFileChooser();

		// FIXME use path from preferences
		fileChooser.setCurrentDirectory(new File(tree.getOutputPath()));
//		System.getProperty("user.dir")+fileSep+"pov"));
		sceneFileChooser = new JFileChooser();
		sceneFileChooser.setCurrentDirectory(new File(tree.getOutputPath()));
//				System.getProperty("user.dir")+fileSep+"pov"));
		renderFileChooser = new JFileChooser();
		renderFileChooser.setCurrentDirectory(new File(tree.getOutputPath()));
//		System.getProperty("user.dir")+fileSep+"pov"));
		
		timer = new Timer(INTERVAL, new TimerListener());
		treeCreationTask = new TreeCreationTask(config);
		
		createGUI();
		frame.setVisible(true);
	}
 
Example #20
Source File: RemotePrinterStatusRefresh.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private RemotePrinterStatusRefresh() {
    frame = new JFrame("RemotePrinterStatusRefresh");
    frame.addWindowListener(this);


    JPanel northPanel = new JPanel(new BorderLayout());
    northPanel.add(createInfoPanel(), BorderLayout.NORTH);
    northPanel.add(createInstructionsPanel(), BorderLayout.SOUTH);


    beforeList = new ServiceItemListModel(
            Collections.unmodifiableList(collectPrinterList()));
    afterList = new ServiceItemListModel(new ArrayList<>());
    logList("Before:", beforeList.list);

    JPanel listPanel = new JPanel(new GridLayout(1, 2));
    listPanel.setBorder(createTitledBorder("Print Services"));
    listPanel.add(createListPanel(beforeList, "Before:", 'b'));
    listPanel.add(createListPanel(afterList, "After:", 'a'));


    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(northPanel, BorderLayout.NORTH);
    mainPanel.add(listPanel, BorderLayout.CENTER);
    mainPanel.add(createButtonPanel(), BorderLayout.SOUTH);


    frame.add(mainPanel);
    frame.pack();
    refreshButton.requestFocusInWindow();
    frame.setVisible(true);


    timer = new Timer(1000, this::updateTimeLeft);
    timer.start();
    startTime = System.currentTimeMillis();
    updateTimeLeft(null);
}
 
Example #21
Source File: Test6559154.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void run() {
    Timer timer = new Timer(1000, this);
    timer.setRepeats(false);
    timer.start();

    JColorChooser chooser = new JColorChooser();
    setEnabledRecursive(chooser, false);

    this.dialog = new JDialog();
    this.dialog.add(chooser);
    this.dialog.setVisible(true);
}
 
Example #22
Source File: ProfilerStatus.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private ProfilerStatus(ProfilerSession session) {
    this.session = session;
    
    refreshTimer = new Timer(STATUS_REFRESH, new ActionListener() {
        public void actionPerformed(ActionEvent e) { updateStatus(); }
    });
    refreshTimer.setRepeats(false);
    
    session.addListener(new SimpleProfilingStateAdapter() {
        public void update() { updateStatus(); }
    });
}
 
Example #23
Source File: SessionBean.java    From tn5250j with GNU General Public License v2.0 5 votes vote down vote up
private void doVisibility()
{
  if (!isVisible() && (visibilityInterval > 0))
  {
    Timer t = new Timer(visibilityInterval, new DoVisible());
    t.setRepeats(false);
    t.start();
  }
  else if (!isVisible())
  {
    new DoVisible().run();
  }
}
 
Example #24
Source File: TTVTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@RandomlyFails // NB-Core-Build #8093
public void testNodesReleasing () {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            fillAndShowTTV();
            // wait for a while to be sure that TTV was completely painted
            // and references between property panels -> properties -> nodes
            // established
            Timer timer = new Timer(5000, new ActionListener () {
                public void actionPerformed (ActionEvent evt) {
                    TTVTest.this.cleanAndCheckTTV();
                }
            });
            timer.setRepeats(false);
            timer.start();
        }
    });
    // wait for results
    synchronized (this) {
        try {
            wait();
            KeyboardFocusManager.getCurrentKeyboardFocusManager ().clearGlobalFocusOwner ();
            for (WeakReference<Node> weakNode : weakNodes) {
                assertGC ("Check Node weakNode", weakNode);
            }
        } catch (InterruptedException exc) {
            fail("Test was interrupted somehow.");
        }
    }
    // result needn't be synced, was set before we were notified
    if (result > 0) {
        System.out.println("OK, TreeTableView released nodes after " + result + " GC cycles");
    } else {
        System.out.println("TreeTableView leaks memory! Nodes were not freed even after 10 GC cycles.");
        fail("TreeTableView leaks memory! Nodes were not freed even after 10 GC cycles.");
    }
}
 
Example #25
Source File: DisplayMulti.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public DisplayMulti() {
    super();
    lcdValue = 0.0;
    oldValue = 0.0;
    lcdThreshold = 0.0;
    lcdThresholdVisible = false;
    lcdThresholdBehaviourInverted = false;
    lcdBackgroundVisible = true;
    lcdTextVisible = true;
    lcdBlinking = false;
    LCD_BLINKING_TIMER = new Timer(500, this);
    lcdDecimals = 1;
    lcdUnitString = "unit";
    lcdUnitStringVisible = true;
    lcdScientificFormat = false;
    digitalFont = false;
    useCustomLcdUnitFont = false;
    customLcdUnitFont = new Font("Verdana", 0, 24);
    LCD_STANDARD_FONT = new Font("Verdana", 0, 30);
    LCD_DIGITAL_FONT = Util.INSTANCE.getDigitalFont().deriveFont(24).deriveFont(Font.PLAIN);
    lcdInfoFont = new Font("Verdana", 0, 24);
    lcdInfoString = "";
    numberSystem = NumberSystem.DEC;
    DISABLED_COLOR = new Color(102, 102, 102, 178);
    timeline = new Timeline(this);
    EASING = new Linear();
    glowVisible = false;
    glowColor = new Color(51, 255, 255);
    glowing = false;
    init(128, 64);
    addComponentListener(COMPONENT_LISTENER);
}
 
Example #26
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 #27
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 #28
Source File: CommonResources.java    From open-ig with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Initiate the timer task.
 */
public void startTimer() {
	stopTimer();
	timer = new Timer(TIMER_DELAY, new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			tick++;
			doTimerTick();
		}
	});
	timer.start();
}
 
Example #29
Source File: KarmaIndicator.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new karma indicator.
 */
private KarmaIndicator() {
	super(new KarmaScalingModel());
	setPainter(new KarmaBarPainter());
	timer = new Timer(HIGHLIGHT_TIME, new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			setForeground(Color.BLACK);
		}
	});
	timer.setRepeats(false);
	setVisible(false);
}
 
Example #30
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);
}