List of usage examples for java.awt EventQueue invokeLater
public static void invokeLater(Runnable runnable)
From source file:org.n52.ifgicopter.spf.input.TimeSeriesSimulation.java
@Override public void init() throws Exception { this.gui = new ModuleGUI(); JPanel panel = new JPanel(new FlowLayout()); JLabel label = new JLabel("<html><h1>Time Series Simulation</h1><p>Running time: " + LOOP_SEC + " seconds with a new value interval of " + this.sleeptime + " milliseconds.</p><p></p><p>Go to <b>Menu -> Start</b> to start the time series. Once started, you cannot stop it (<b>Menu -> Stop</b> does not work!).</p></html>"); panel.add(label);//from w w w .j a v a 2 s. co m this.gui.setGui(panel); JMenu menu = new JMenu(); JMenuItem start = new JMenuItem("Start"); start.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { start(); } }); } }); menu.add(start); JMenuItem stop = new JMenuItem("Stop"); stop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { stop(); } }); } }); menu.add(stop); this.gui.setMenu(menu); new Thread(new Runnable() { @Override public void run() { while (!TimeSeriesSimulation.this.initialized) { try { Thread.sleep(THREAD_SLEEP_TIME_MASTER_WHILE_LOOP); } catch (InterruptedException e) { e.printStackTrace(); } } try { while (true) { if (TimeSeriesSimulation.this.running) { innerRun(); } else { try { Thread.sleep(THREAD_SLEEP_TIME_MASTER_WHILE_LOOP); } catch (InterruptedException e) { e.printStackTrace(); } } } } catch (Exception e) { log.error("error in run()", e); } } private void innerRun() { int humicount = 0; Random rand = new Random(); Map<String, Object> posData = null; Map<String, Object> sensorData = null; long starttime = System.currentTimeMillis(); posData = new HashMap<String, Object>(); /* * do loop of LOOP_SEC seconds */ log.debug("starting time series for " + LOOP_SEC + " seconds."); while (System.currentTimeMillis() - starttime < LOOP_SEC * 1000) { posData.put("time", Long.valueOf(System.currentTimeMillis())); posData.put("latitude", Double.valueOf(52.0 + rand.nextDouble() * 0.0025)); posData.put("longitude", Double.valueOf(7.0 + rand.nextDouble() * 0.0025)); posData.put("altitude", Double.valueOf(34.0 + rand.nextDouble() * 7)); TimeSeriesSimulation.this.populateNewData(posData); try { Thread.sleep(500); } catch (InterruptedException e) { log.error(e); } /* * now with humidity */ sensorData = new HashMap<String, Object>(); sensorData.put("time", Long.valueOf(System.currentTimeMillis())); sensorData.put("humidity", Double.valueOf(70.2 + (rand.nextInt(200) / 10.0))); sensorData.put("humiditay", Double.valueOf(70.2 + (rand.nextInt(200) / 10.0))); sensorData.put("temperature", Double.valueOf(20.0 + (rand.nextInt(40) / 10.0))); humicount++; TimeSeriesSimulation.this.populateNewData(sensorData); try { Thread.sleep(TimeSeriesSimulation.this.sleeptime); } catch (InterruptedException e) { log.error(e); } } try { Thread.sleep(500); } catch (InterruptedException e) { log.error(e); } posData.put("time", Long.valueOf(System.currentTimeMillis())); TimeSeriesSimulation.this.populateNewData(posData); log.info("humicount=" + humicount); // just one run! stop(); } }).start(); this.initialized = true; }
From source file:com.croer.javaorange.diviner.SimpleOrangeTextPane.java
protected void colorStyledDocument(final DefaultStyledDocument document) { EventQueue.invokeLater(new Runnable() { @Override/*from w ww . j av a 2 s . c o m*/ public void run() { String input = ""; try { input = document.getText(0, document.getLength()); } catch (BadLocationException ex) { Logger.getLogger(SimpleOrangeTextPane.class.getName()).log(Level.SEVERE, null, ex); } StringBuilder inputMut = new StringBuilder(input); String[] split = StringUtils.split(inputMut.toString()); int i = 0; for (String string : split) { int start = inputMut.indexOf(string); int end = start + string.length(); inputMut.replace(start, end, StringUtils.repeat(" ", string.length())); document.setCharacterAttributes(start, string.length(), styles[i++ % styles.length], true); } } }); }
From source file:org.fseek.simon.swing.util.TreeUtil.java
public static void deleteAllChilds(final LinkTreeNode node, final DefaultTreeModel model, DefaultMutableTreeNode clearNode) { for (int i = 0; i < node.getChildCount(); i++) { if (Thread.interrupted()) { break; }// ww w . java 2 s . c om final MutableTreeNode childAt = (MutableTreeNode) node.getChildAt(i); if (childAt != null && clearNode != null && clearNode != childAt) { EventQueue.invokeLater(new Runnable() { @Override public void run() { model.removeNodeFromParent(childAt); } }); } } }
From source file:org.zaproxy.zap.extension.fuzz.httpfuzzer.ui.HttpFuzzerResultsTableModel.java
public void addResult(final HttpFuzzResult result) { try {// w w w . ja v a2 s .c o m final HistoryReference href = result.getHttpMessage().getHistoryRef() != null ? result.getHttpMessage().getHistoryRef() : new HistoryReference(Model.getSingleton().getSession(), // TODO Replace 20 with HistoryReference.TYPE_FUZZER_TEMPORARY // once available. 20, result.getHttpMessage()); EventQueue.invokeLater(new Runnable() { @Override public void run() { final int row = results.size(); idsToRows.put(Integer.valueOf(href.getHistoryId()), Integer.valueOf(row)); results.add(new FuzzResultTableEntry(href, result.getTaskId(), result.getType(), result.getCustomStates(), result.getPayloads())); fireTableRowsInserted(row, row); } }); } catch (HttpMalformedHeaderException | DatabaseException e) { logger.error("Failed to persist (and show) the message:", e); } }
From source file:SwingThreadTest.java
public void run() { try {//from w w w . j a v a 2 s .c o m while (true) { EventQueue.invokeLater(new Runnable() { public void run() { int i = Math.abs(generator.nextInt()); if (i % 2 == 0) combo.insertItemAt(i, 0); else if (combo.getItemCount() > 0) combo.removeItemAt(i % combo.getItemCount()); } }); Thread.sleep(1); } } catch (InterruptedException e) { } }
From source file:com.simplexrepaginator.RepaginateFrame.java
public RepaginateFrame(FileRepaginator repaginator) { super("Simplex Repaginator version " + Repaginate.getVersion()); setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.repaginator = repaginator; setJMenuBar(createMenuBar());/*from ww w . j ava2 s . c o m*/ input = createInputButton(); repaginate = createRepaginateButton(); unrepaginate = createUnrepaginateButton(); output = creatOutputButton(); setLayout(new GridBagLayout()); final GridBagConstraints c = new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0); c.gridwidth = 2; add(input, c); c.gridy++; c.gridwidth = 1; c.fill = GridBagConstraints.VERTICAL; add(repaginate, c); c.gridx++; add(unrepaginate, c); c.gridy++; c.gridx = 0; c.gridwidth = 2; c.fill = GridBagConstraints.BOTH; add(output, c); Runnable r = new Runnable() { @Override public void run() { UpdateChecker uc = new UpdateChecker(); try { if (!uc.isUpdateAvailable()) return; final JLabel label = new JLabel("<html>Simplex Repaginator version " + uc.getLatestVersion() + " is available. " + "Choose <b>File > Check For Updates</b> to download."); EventQueue.invokeLater(new Runnable() { @Override public void run() { c.gridy++; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; add(label, c); revalidate(); } }); } catch (IOException ioe) { } } }; new Thread(r).start(); pack(); setSize(800, 400); }
From source file:net.technicpack.launcher.ui.components.discover.DiscoverInfoPanel.java
public DiscoverInfoPanel(final ResourceLoader loader, String discoverUrl, final IPlatformApi platform, final LauncherDirectories directories, final ModpackSelector modpackSelector) { super(loader.getImage("background_repeat2.png")); this.directories = directories; this.resources = loader; if (discoverUrl == null) discoverUrl = "http://endermedia.com/discover.html"; final String runnableAccessDiscover = discoverUrl; setLayout(new BorderLayout()); this.panel = new XHTMLPanel(); panel.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16)); panel.setDefaultFontFromComponent(true); panel.addDocumentListener(new DocumentListener() { private boolean hasReloaded = false; @Override// ww w . ja v a 2 s . com public void documentStarted() { } @Override public void documentLoaded() { triggerLoadListener(); } @Override public void onLayoutException(Throwable throwable) { throwable.printStackTrace(); if (!hasReloaded) { hasReloaded = true; EventQueue.invokeLater(new Runnable() { @Override public void run() { panel.setDocument(getDiscoverDocumentFromResource(), runnableAccessDiscover); } }); } } @Override public void onRenderException(Throwable throwable) { throwable.printStackTrace(); if (!hasReloaded) { hasReloaded = true; EventQueue.invokeLater(new Runnable() { @Override public void run() { panel.setDocument(getDiscoverDocumentFromResource(), runnableAccessDiscover); } }); } } }); for (Object listener : panel.getMouseTrackingListeners()) { panel.removeMouseTrackingListener((FSMouseListener) listener); } panel.addMouseTrackingListener(new DiscoverLinkListener(platform, modpackSelector)); final DelegatingUserAgent uac = new DelegatingUserAgent(); ImageResourceLoader imageLoader = new DiscoverResourceLoader(); imageLoader.setRepaintListener(panel); imageLoader.clear(); uac.setImageResourceLoader(imageLoader); panel.getSharedContext().getTextRenderer().setSmoothingThreshold(6.0f); panel.getSharedContext().setUserAgentCallback(uac); SwingReplacedElementFactory factory = new SwingReplacedElementFactory(panel, imageLoader); factory.reset(); panel.getSharedContext().setReplacedElementFactory(factory); panel.getSharedContext().setFontMapping("Raleway", resources.getFont(ResourceLoader.FONT_RALEWAY, 12)); EventQueue.invokeLater(new Runnable() { @Override public void run() { try { File localCache = new File(directories.getCacheDirectory(), "discover.html"); panel.setDocument(getDiscoverDocument(runnableAccessDiscover, localCache), runnableAccessDiscover); } catch (Exception ex) { //Can't load document from internet- don't beef ex.printStackTrace(); triggerLoadListener(); } } }); add(panel, BorderLayout.CENTER); }
From source file:org.jivesoftware.sparkimpl.plugin.viewer.PluginViewer.java
public PluginViewer() { _prefs = SettingsManager.getLocalPreferences(); _deactivatedPlugins = _prefs.getDeactivatedPlugins(); EventQueue.invokeLater(new Runnable() { public void run() { tabbedPane = new JTabbedPane(); installedPanel = new JPanel(); availablePanel = new JPanel(); deactivatedPanel = new JPanel(); setLayout(new GridBagLayout()); installedPanel.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false)); installedPanel.setBackground(Color.white); availablePanel.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false)); availablePanel.setBackground(Color.white); // Add TabbedPane add(tabbedPane, new GridBagConstraints(0, 1, 2, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); // Add Tabs tabbedPane.addTab(Res.getString("tab.installed.plugins"), new JScrollPane(installedPanel)); if (!Default.getBoolean(Default.INSTALL_PLUGINS_DISABLED)) { tabbedPane.addTab(Res.getString("tab.available.plugins"), new JScrollPane(availablePanel)); }//from w w w .ja va2 s. com loadInstalledPlugins(); loadDeactivatedPlugins(); tabbedPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { if (tabbedPane.getSelectedComponent() .equals(((JViewport) availablePanel.getParent()).getParent())) { loadAvailablePlugins(); loaded = true; } } }); } }); }
From source file:Data.java
/** * @param args the command line arguments *//*from w w w . j a va2s .c o m*/ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Data.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Data.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Data.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Data.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ EventQueue.invokeLater(new Runnable() { public void run() { try { new Data().setVisible(true); } catch (ClassNotFoundException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); }
From source file:com.antelink.sourcesquare.gui.controller.ExitController.java
public void display() { EventQueue.invokeLater(new Runnable() { @Override//from www. j a v a 2s. c o m public void run() { try { ExitController.this.view.setVisible(true); } catch (Exception e) { logger.error("Error launching the exit UI", e); } } }); }