List of usage examples for javax.swing SwingUtilities invokeLater
public static void invokeLater(Runnable doRun)
From source file:sim.util.media.chart.HistogramGenerator.java
/** Adds a series, plus a (possibly null) SeriesChangeListener which will receive a <i>single</i> event if/when the series is deleted from the chart by the user. Returns the series attributes. */ public SeriesAttributes addSeries(double[] vals, int bins, String name, SeriesChangeListener stopper) { if (vals == null || vals.length == 0) vals = new double[] { 0 }; // ya gotta have at least one val HistogramDataset dataset = (HistogramDataset) (getSeriesDataset()); int i = dataset.getSeriesCount(); dataset.setType(histogramType); // It looks like the histograms reset dataset.addSeries(new UniqueString(name), vals, bins); // need to have added the dataset BEFORE calling this since it'll try to change the name of the series HistogramSeriesAttributes csa = new HistogramSeriesAttributes(this, name, i, vals, bins, stopper); seriesAttributes.add(csa);/*from w w w .j a v a2 s . co m*/ revalidate(); // display the new series panel update(); // won't update properly unless I force it here by letting all the existing scheduled events to go through. Dumb design. :-( SwingUtilities.invokeLater(new Runnable() { public void run() { update(); } }); return csa; }
From source file:edu.ku.brc.af.tasks.StatsTrackerTask.java
/** * When it is done sending the statistics: if doExit is true it will shutdown the Hibernate and the DBConnections * and call System.exit(0), if doSendDoneEvent is true then it send a CommandAction(APP_CMD_TYPE, "STATS_SEND_DONE", null) * for someone else to shut everything down. * @param doExit call exit//from w w w .j av a 2 s . c om * @param doSilent don't show any UI while sending stats * @param doSendDoneEvent send a STATS_SEND_DONE command on the UI thread. */ public void sendStats(final boolean doExit, final boolean doSilent, final boolean doSendDoneEvent) { if (!doSilent) { showClosingFrame(); } if (starting()) { worker = new StatsSwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { sendStats(); return null; } @Override protected void done() { super.done(); completed(); if (doExit) { AppPreferences.shutdownAllPrefs(); DataProviderFactory.getInstance().shutdown(); DBConnection.shutdown(); System.exit(0); } else if (doSendDoneEvent) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { Thread.sleep(500); } catch (Exception ex) { } CommandDispatcher.dispatch( new CommandAction(BaseTask.APP_CMD_TYPE, "STATS_SEND_DONE", null)); } }); } } }; if (!doSilent) { PropertyChangeListener pcl = getPCLForWorker(); if (pcl != null) { worker.addPropertyChangeListener(pcl); } } worker.execute(); } }
From source file:com.limegroup.gnutella.gui.mp3.BasicPlayer.java
public boolean play(final File toPlay) throws IOException { String reason;// ww w. j a v a 2 s . c o m try { setDataSource(toPlay); return startPlayback(); } catch (UnsupportedAudioFileException ignored) { reason = "UNSUPPORTED"; } catch (LineUnavailableException ignored) { reason = "UNAVAILABLE"; } catch (FileNotFoundException ignored) { reason = "MISSING"; } catch (EOFException ignored) { reason = "CORRUPT"; } catch (IOException ignored) { reason = "UNKNOWN"; } catch (StringIndexOutOfBoundsException ignored) { reason = "PARSE_PROBLEM"; } final String raisin = reason; SwingUtilities.invokeLater(new Runnable() { public void run() { GUIMediator.showError("PLAYLIST_CANNOT_PLAY_FILE", toPlay, "PLAYLIST_FILE_" + raisin); } }); return false; }
From source file:edu.ku.brc.specify.plugins.FishBase.java
/** * @param dom//from w ww .j a v a2 s . c o m */ protected void setDataIntoframe(@SuppressWarnings("unused") final Element dom) { SwingUtilities.invokeLater(new Runnable() { public void run() { progress.setIndeterminate(false); progress.setVisible(false); frame.setData(getter.getDom()); } }); }
From source file:com.googlecode.pondskum.client.BigpondConnectorImpl.java
private void closeConnections(final DefaultHttpClient httpClient, final LinkTraverser linkTraverser, final ConnectionListener defaultCompositeConnectionListeners) { SwingUtilities.invokeLater(new Runnable() { @Override/*from ww w .j av a 2s .c o m*/ public void run() { //shutdown connection. This is done is a separate thread as we don't want to to affect the current gui thread. new ShutdownConnection(config, linkTraverser, defaultCompositeConnectionListeners).logout(); //shutdown httpclient in a separate thread. This must run AFTER the above....hence the inclusion here. new ShutdownHttpClient(config, httpClient).execute(); } }); }
From source file:edu.gmu.cs.sim.util.media.chart.HistogramGenerator.java
/** Adds a series, plus a (possibly null) SeriesChangeListener which will receive a <i>single</i> event if/when the series is deleted from the chart by the user. Returns the series attributes. */ public SeriesAttributes addSeries(double[] vals, int bins, String name, SeriesChangeListener stopper) { if (vals == null || vals.length == 0) { vals = new double[] { 0 }; // ya gotta have at least one val }//from w w w.j a v a 2 s . c o m HistogramDataset dataset = (HistogramDataset) (getSeriesDataset()); int i = dataset.getSeriesCount(); dataset.setType(histogramType); // It looks like the histograms reset dataset.addSeries(new UniqueString(name), vals, bins); // need to have added the dataset BEFORE calling this since it'll try to change the name of the series HistogramSeriesAttributes csa = new HistogramSeriesAttributes(this, name, i, vals, bins, stopper); seriesAttributes.add(csa); revalidate(); // display the new series panel update(); // won't update properly unless I force it here by letting all the existing scheduled events to go through. Dumb design. :-( SwingUtilities.invokeLater(new Runnable() { public void run() { update(); } }); return csa; }
From source file:cz.muni.fi.javaseminar.kafa.bookregister.gui.MainWindow.java
private void initBooksTable() { booksTable.getColumnModel().getColumn(2) .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy"))); booksTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() { @Override//from w w w . j av a2s. c o m public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected, boolean hasFocus, int row, int column) { if (value instanceof Date) { // You could use SimpleDateFormatter instead value = new SimpleDateFormat("dd. MM. yyyy").format(value); } return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column); } }); booksTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JPopupMenu booksPopupMenu = new JPopupMenu(); JMenuItem deleteBook = new JMenuItem("Delete"); booksPopupMenu.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { int rowAtPoint = booksTable.rowAtPoint( SwingUtilities.convertPoint(booksPopupMenu, new Point(0, 0), booksTable)); if (rowAtPoint > -1) { booksTable.setRowSelectionInterval(rowAtPoint, rowAtPoint); } } }); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // TODO Auto-generated method stub } @Override public void popupMenuCanceled(PopupMenuEvent e) { // TODO Auto-generated method stub } }); deleteBook.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (booksTable.getSelectedRow() == -1) { JOptionPane.showMessageDialog(MainWindow.this, "You haven't selected any book."); return; } Book book = booksTableModel.getBooks().get(booksTable.getSelectedRow()); new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { log.debug("Deleting book: " + book.getName() + " from database."); bookManager.deleteBook(book); return null; } @Override protected void done() { try { get(); } catch (Exception e) { log.error("There was an exception thrown while deleting a book.", e); return; } updateModel(); } }.execute(); } }); booksPopupMenu.add(deleteBook); booksTable.setComponentPopupMenu(booksPopupMenu); }
From source file:com.dbschools.quickquiz.client.giver.MainWindow.java
private void addListeners() { takerTableDisplay.addTableKeyListener(new KeyAdapter() { @Override/* w w w . jav a2 s . com*/ public void keyPressed(KeyEvent e) { char keyChar = e.getKeyChar(); if (Character.isDigit(keyChar) && e.isControlDown()) { awardPoints(Integer.parseInt(Character.toString(keyChar))); } } }); final ListSelectionModel takerTableSelectionModel = takerTableDisplay.getSelectionModel(); takerTableSelectionModel.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { btnAwardPoints.setEnabled(!takerTableSelectionModel.isSelectionEmpty()); } }); countdownMeter.addCountdownFinishListener(new CountdownFinishListener() { public void countdownFinished() { SwingUtilities.invokeLater(new Runnable() { public void run() { btnSendQuestion.setEnabled(true); } }); } }); }
From source file:com.xmage.launcher.XMageLauncher.java
public static void main(String[] args) { try {// w w w. ja va 2s. com UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); XMageLauncher gui = new XMageLauncher(); SwingUtilities.invokeLater(gui); } catch (ClassNotFoundException ex) { logger.error("Error: ", ex); } catch (InstantiationException ex) { logger.error("Error: ", ex); } catch (IllegalAccessException ex) { logger.error("Error: ", ex); } catch (UnsupportedLookAndFeelException ex) { logger.error("Error: ", ex); } }
From source file:edu.cuny.cat.ui.ClientStatePanel.java
@Override protected synchronized void processGameStarting(final GameStartingEvent event) { SwingUtilities.invokeLater(new Runnable() { public void run() { yAxis.setLowerBound(-1);//from w w w .j av a 2 s . c o m yAxis.setUpperBound(days); eventDataset = new DefaultValueListCategoryDataset(); eventDataset.setAutomaticChangedEvent(false); progressDataset = new DefaultIntervalListCategoryDataset(); progressDataset.setAutomaticChangedEvent(false); categoryPlot.setDataset(0, eventDataset); categoryPlot.setDataset(1, progressDataset); // useful only to keep specialists in the same order in the plot final String specialistIds[] = registry.getSpecialistIds(); for (final String specialistId : specialistIds) { eventDataset.add(Double.NaN, event.getClass().getSimpleName(), specialistId); progressDataset.setStartValue(Double.NaN, 0, ClientState.getCodeDesc(ClientState.OK), specialistId); progressDataset.setEndValue(Double.NaN, 0, ClientState.getCodeDesc(ClientState.OK), specialistId); } } }); }