List of usage examples for javax.swing Timer Timer
public Timer(int delay, ActionListener listener)
From source file:org.isatools.gui.optionselector.OptionGroup.java
public void mouseEntered(MouseEvent mouseEvent) { if (mouseEvent.getSource() instanceof OptionItem) { final OptionItem<T> item = (OptionItem<T>) mouseEvent.getSource(); item.setForeground(item.getOverBackgroundColor()); final Timer[] timers = new Timer[1]; timers[0] = new Timer(750, new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { item.setForeground(item.getNormalBackground()); timers[0].stop();/*from w w w .j av a 2s .c om*/ } }); timers[0].start(); } }
From source file:org.isatools.isacreatorconfigurator.configui.MenuPanel.java
private void startAnimation() { Timer timer = new Timer(75, new ActionListener() { public void actionPerformed(ActionEvent e) { generic.animate();/*from w ww . ja v a2 s .c o m*/ generic.repaint(); } }); timer.start(); }
From source file:org.openiot.gsn.wrappers.SystemTime.java
public boolean initialize() { setName("LocalTimeWrapper-Thread" + (++threadCounter)); AddressBean addressBean = getActiveAddressBean(); // TODO: negative values? timer = new Timer(addressBean.getPredicateValueAsInt(CLOCK_PERIOD_KEY, DEFAULT_CLOCK_PERIODS), this); maximumDelay = addressBean.getPredicateValueAsInt(MAX_DELAY_KEY, DEFAULT_MAX_DELAY); if (maximumDelay > 0) { streamElementBuffer = SynchronizedBuffer.decorate(new UnboundedFifoBuffer()); delayPostingElements = true;/*from w w w . ja va2 s . c o m*/ if (timer.getDelay() < maximumDelay) logger.warn( "Maximum delay is greater than element production interval. Running for a long time may lead to an OutOfMemoryException"); } return true; }
From source file:org.orbisgis.sqlconsole.ui.SQLConsolePanel.java
private JToolBar getStatusToolBar() { if (infoToolBar == null) { infoToolBar = new JToolBar(); infoToolBar.setTransferHandler(new ScriptPanelTransferHandler(scriptPanel, dataSource)); statusMessage = new JLabel(); infoToolBar.add(statusMessage);// w w w . j a va 2 s. c o m infoToolBar.setFloatable(false); messageCleanTimer = new Timer(5000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setStatusMessage(""); } }); messageCleanTimer.setRepeats(false); setStatusMessage(""); } return infoToolBar; }
From source file:org.orbisgis.view.beanshell.BshConsolePanel.java
private void setStatusMessage(String message) { currentStatusMessage = message;// w w w . java2s. co m if (messageClearTimer == null) { messageClearTimer = new Timer(MESSAGE_CLEAR_INTERVAL, EventHandler.create(ActionListener.class, this, "onClearMessage")); messageClearTimer.setRepeats(false); } if (!message.isEmpty()) { messageClearTimer.restart(); } statusMessage.setText(String.format(MESSAGEBASE, line, character, message)); }
From source file:org.orbisgis.view.sqlconsole.ui.SQLConsolePanel.java
private JToolBar getStatusToolBar() { if (infoToolBar == null) { infoToolBar = new JToolBar(); statusMessage = new JLabel(); infoToolBar.add(statusMessage);/*from w w w .j a va 2 s. c om*/ infoToolBar.setFloatable(false); messageCleanTimer = new Timer(5000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setStatusMessage(""); } }); messageCleanTimer.setRepeats(false); } return infoToolBar; }
From source file:org.signserver.admin.gui.MainView.java
public MainView(SingleFrameApplication app) { super(app);/*from w w w .j a va 2s .c o m*/ initComponents(); final int rowHeights = new JComboBox/*<String>*/().getPreferredSize().height; // workaround a bug in the NetBeans form editor where the download // archive entries button sometimes looses its default disabled state downloadArchiveEntriesButton.setEnabled(false); statusSummaryTextPane.setContentType("text/html"); auditlogConditionsModel.addCondition(AuditlogColumn.EVENTTYPE, RelationalOperator.NEQ, "ACCESS_CONTROL"); auditLogTable.setModel(auditlogModel); archiveTable.setModel(archiveModel); conditionsTable.setModel(auditlogConditionsModel); conditionsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { jButtonAuditConditionRemove.setEnabled(conditionsTable.getSelectedRowCount() > 0); } } }); jTabbedPane1.setSelectedComponent(mainPanel); archiveConditionsTable.setModel(archiveConditionsModel); archiveConditionsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { jButtonArchiveConditionRemove.setEnabled(archiveConditionsTable.getSelectedRowCount() > 0); } } }); tokenEntriesTable.setModel(tokenEntriesModel); tokenEntriesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final boolean exactlyOneSelected = tokenEntriesTable.getSelectedRowCount() == 1; final boolean anySelected = tokenEntriesTable.getSelectedRowCount() > 0; tokenEntriesTestButton.setEnabled(exactlyOneSelected); tokenEntriesGenerateCSRButton.setEnabled(anySelected); tokenEntriesImportButton.setEnabled(anySelected); tokenEntriesRemoveButton.setEnabled(exactlyOneSelected); tokenEntriesDetailsButton.setEnabled(exactlyOneSelected); } } }); final String action = "DetailsOnEnter"; KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); tokenEntriesTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(enter, action); tokenEntriesTable.getActionMap().put(action, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (tokenEntriesTable.getSelectedRows().length > 0) { tokenEntriesDetailsButton.doClick(); } } }); workersList.setCellRenderer(new MyListCellRenderer()); workersList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { selectedWorkers = new ArrayList<Worker>(); for (Object o : workersList.getSelectedValues()) { if (o instanceof Worker) { selectedWorkers.add((Worker) o); } } workerComboBox.setModel(new MyComboBoxModel(selectedWorkers)); // removeKey should only be enabled iff one selected removeKeyMenu.setEnabled(selectedWorkers.size() == 1); if (selectedWorkers.size() > 0) { if (LOG.isDebugEnabled()) { LOG.debug("Previously selected: " + selectedWorkerBeforeRefresh); } int comboBoxSelection = 0; // Try to set the previously selected if (selectedWorkerBeforeRefresh != null) { comboBoxSelection = selectedWorkers.indexOf(selectedWorkerBeforeRefresh); if (comboBoxSelection == -1) { comboBoxSelection = 0; } } workerComboBox.setSelectedIndex(comboBoxSelection); } else { displayWorker(null); } } } }); workerComboBox.setRenderer(new SmallWorkerListCellRenderer()); workerComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { if (workerComboBox.getSelectedItem() instanceof Worker) { displayWorker((Worker) workerComboBox.getSelectedItem()); } } }); propertiesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final int row = propertiesTable.getSelectedRow(); final boolean enable; if (row == -1) { enable = false; } else { final Object o = propertiesTable.getValueAt(row, 1); enable = o instanceof X509Certificate || o instanceof Collection; // TODO: Too weak } statusPropertiesDetailsButton.setEnabled(enable); } } }); propertiesTable.setRowHeight(rowHeights); configurationTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final boolean enable = configurationTable.getSelectedRowCount() == 1; editButton.setEnabled(enable); removeButton.setEnabled(enable); } } }); configurationTable.setRowHeight(rowHeights); authTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final boolean enable = authTable.getSelectedRowCount() == 1; authEditButton.setEnabled(enable); authRemoveButton.setEnabled(enable); } } }); authTable.setRowHeight(rowHeights); archiveTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { downloadArchiveEntriesButton .setEnabled(!fetchArchiveDataInProgress && archiveTable.getSelectedRowCount() > 0); } } }); archiveTable.setRowHeight(rowHeights); auditLogTable.setRowHeight(rowHeights); conditionsTable.setRowHeight(rowHeights); archiveConditionsTable.setRowHeight(rowHeights); tokenEntriesTable.setRowHeight(rowHeights); displayWorker(null); // status bar initialization - message timeout, idle icon and busy // animation, etc ResourceMap resourceMap = getResourceMap(); int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout"); messageTimer = new Timer(messageTimeout, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { statusMessageLabel.setText(""); } }); messageTimer.setRepeats(false); int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate"); for (int i = 0; i < busyIcons.length; i++) { busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]"); } busyIconTimer = new Timer(busyAnimationRate, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { busyIconIndex = (busyIconIndex + 1) % busyIcons.length; statusAnimationLabel.setIcon(busyIcons[busyIconIndex]); } }); idleIcon = resourceMap.getIcon("StatusBar.idleIcon"); statusAnimationLabel.setIcon(idleIcon); progressBar.setVisible(false); // connecting action tasks to status bar via TaskMonitor TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext()); taskMonitor.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { String propertyName = evt.getPropertyName(); if ("started".equals(propertyName)) { if (!busyIconTimer.isRunning()) { statusAnimationLabel.setIcon(busyIcons[0]); busyIconIndex = 0; busyIconTimer.start(); } progressBar.setVisible(true); progressBar.setIndeterminate(true); } else if ("done".equals(propertyName)) { busyIconTimer.stop(); statusAnimationLabel.setIcon(idleIcon); progressBar.setVisible(false); progressBar.setValue(0); } else if ("message".equals(propertyName)) { String text = (String) evt.getNewValue(); statusMessageLabel.setText((text == null) ? "" : text); messageTimer.restart(); } else if ("progress".equals(propertyName)) { int value = (Integer) evt.getNewValue(); progressBar.setVisible(true); progressBar.setIndeterminate(false); progressBar.setValue(value); } } }); getContext().getTaskService().execute(refreshWorkers()); }
From source file:org.sleuthkit.autopsy.corecomponents.ThumbnailViewNode.java
@Override @NbBundle.Messages({ "# {0} - file name", "ThumbnailViewNode.progressHandle.text=Generating thumbnail for {0}" }) public Image getIcon(int type) { Image icon = null;/*from w w w .j av a2 s . c om*/ if (iconCache != null) { icon = iconCache.get(); } if (icon != null) { return icon; } else { final Content content = this.getLookup().lookup(Content.class); if (content == null) { return ImageUtils.getDefaultThumbnail(); } if (swingWorker == null || swingWorker.isDone()) { swingWorker = new SwingWorker<Image, Object>() { final private ProgressHandle progressHandle = ProgressHandle .createHandle(Bundle.ThumbnailViewNode_progressHandle_text(content.getName())); @Override protected Image doInBackground() throws Exception { progressHandle.start(); return ImageUtils.getThumbnail(content, iconSize); } @Override protected void done() { super.done(); try { iconCache = new SoftReference<>(super.get()); fireIconChange(); } catch (InterruptedException | ExecutionException ex) { Logger.getLogger(ThumbnailViewNode.class.getName()).log(Level.SEVERE, "Error getting thumbnail icon for " + content.getName(), ex); //NON-NLS } finally { progressHandle.finish(); if (timer != null) { timer.stop(); timer = null; } swingWorker = null; } } }; swingWorker.execute(); } if (timer == null) { timer = new Timer(100, (ActionEvent e) -> { fireIconChange(); }); timer.start(); } return waitingIcon; } }
From source file:org.sleuthkit.autopsy.keywordsearch.KeywordSearchIngestService.java
/** * Initializes the service for new ingest run Sets up threads, timers, * retrieves settings, keyword lists to run on * * @param managerProxy// www.jav a 2 s . c om */ @Override public void init(IngestManagerProxy managerProxy) { logger.log(Level.INFO, "init()"); initialized = false; caseHandle = Case.getCurrentCase().getSleuthkitCase(); this.managerProxy = managerProxy; Server solrServer = KeywordSearch.getServer(); ingester = solrServer.getIngester(); ingestStatus = new HashMap<Long, IngestStatus>(); keywords = new ArrayList<Keyword>(); keywordLists = new ArrayList<String>(); keywordToList = new HashMap<String, KeywordSearchList>(); initKeywords(); if (keywords.isEmpty() || keywordLists.isEmpty()) { managerProxy.postMessage(IngestMessage.createWarningMessage(++messageID, instance, "No keywords in keyword list.", "Only indexing will be done and and keyword search will be skipped (it can be executed later again as ingest or using toolbar search feature).")); } processedFiles = false; finalSearcherDone = false; searcherDone = true; //make sure to start the initial currentSearcher //keeps track of all results per run not to repeat reporting the same hits currentResults = new HashMap<Keyword, List<ContentHit>>(); indexer = new Indexer(); final int updateIntervalMs = managerProxy.getUpdateFrequency() * 60 * 1000; logger.log(Level.INFO, "Using commit interval (ms): " + updateIntervalMs); logger.log(Level.INFO, "Using searcher interval (ms): " + updateIntervalMs); commitTimer = new Timer(updateIntervalMs, new CommitTimerAction()); searchTimer = new Timer(updateIntervalMs, new SearchTimerAction()); initialized = true; commitTimer.start(); searchTimer.start(); managerProxy.postMessage(IngestMessage.createMessage(++messageID, MessageType.INFO, this, "Started")); }
From source file:org.tinymediamanager.ui.MainWindow.java
private void checkForUpdate() { try {/* w ww.j av a 2s.c om*/ final UpdaterTask updateWorker = new UpdaterTask(); updateWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if ("state".equals(evt.getPropertyName()) && evt.getNewValue() == StateValue.DONE) { try { boolean update = updateWorker.get(); LOGGER.debug("update result was: " + update); if (update) { // we might need this somewhen... if (updateWorker.isForcedUpdate()) { LOGGER.info("Updating (forced)..."); closeTmmAndStart(Utils.getPBforTMMupdate()); return; } // show whatsnewdialog with the option to update if (StringUtils.isNotBlank(updateWorker.getChangelog())) { UpdateDialog dialog = new UpdateDialog(updateWorker.getChangelog()); dialog.setVisible(true); } else { // do the update without changelog popup int answer = JOptionPane.showConfirmDialog(null, BUNDLE.getString("tmm.update.message"), BUNDLE.getString("tmm.update.title"), JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.OK_OPTION) { LOGGER.info("Updating..."); // spawn getdown and exit TMM closeTmmAndStart(Utils.getPBforTMMupdate()); } } } } catch (Exception e) { LOGGER.error("Update task failed!" + e.getMessage()); } } } }); // update task start a few secs after GUI... Timer timer = new Timer(5000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateWorker.execute(); } }); timer.setRepeats(false); timer.start(); } catch (Exception e) { LOGGER.error("Update task failed!" + e.getMessage()); } }