List of usage examples for javax.swing SwingUtilities isEventDispatchThread
public static boolean isEventDispatchThread()
From source file:org.yccheok.jstock.gui.PortfolioManagementJPanel.java
public void updateTitledBorder() { final JStockOptions jStockOptions = JStock.instance().getJStockOptions(); if (SwingUtilities.isEventDispatchThread()) { final TitledBorder titledBorder = (TitledBorder) PortfolioManagementJPanel.this.jPanel1.getBorder(); titledBorder.setTitle(jStockOptions.getPortfolioName()); // So that title will refresh immediately. PortfolioManagementJPanel.this.jPanel1.repaint(); } else {//from www.j a v a 2 s .com SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final TitledBorder titledBorder = (TitledBorder) PortfolioManagementJPanel.this.jPanel1 .getBorder(); titledBorder.setTitle(jStockOptions.getPortfolioName()); // So that title will refresh immediately. PortfolioManagementJPanel.this.jPanel1.repaint(); } }); } }
From source file:org.yccheok.jstock.gui.SaveToCloudJDialog.java
private boolean promptUserToContinue(final List<Country> countryWithWatchlistFilesBeingIgnored) { if (countryWithWatchlistFilesBeingIgnored.isEmpty()) { // No watchlist file(s) is ignored. return true; }// ww w . jav a 2s . c o m int size = countryWithWatchlistFilesBeingIgnored.size(); final String message; final String title; if (size == 1) { message = MessageFormat.format( MessagesBundle.getString("question_message_too_many_stocks_during_save_to_cloud_template"), countryWithWatchlistFilesBeingIgnored.get(0)); title = MessagesBundle.getString("question_title_too_many_stocks_during_save_to_cloud"); } else { message = MessageFormat.format( MessagesBundle.getString( "question_message_too_many_stocks_in_multiple_countries_during_save_to_cloud_template"), size); title = MessagesBundle .getString("question_title_too_many_stocks_in_multiple_countries_during_save_to_cloud"); } // Ensure thread safety when we pop up confirmation dialog box. Is it // possible to cause deadlock due to invokeAndWait? final int[] choice = new int[1]; choice[0] = JOptionPane.NO_OPTION; if (SwingUtilities.isEventDispatchThread()) { choice[0] = JOptionPane.showConfirmDialog(SaveToCloudJDialog.this, message, title, JOptionPane.YES_NO_OPTION); } else { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { choice[0] = JOptionPane.showConfirmDialog(SaveToCloudJDialog.this, message, title, JOptionPane.YES_NO_OPTION); } }); } catch (InterruptedException ex) { log.error(null, ex); } catch (InvocationTargetException ex) { log.error(null, ex); } } return choice[0] == JOptionPane.YES_OPTION; }
From source file:org.yccheok.jstock.gui.StockDatabaseJDialog.java
private Observer<AjaxAutoCompleteJComboBox, DispType> getDispObserver() { return new Observer<AjaxAutoCompleteJComboBox, DispType>() { @Override/* w w w. java 2s.c om*/ public void update(AjaxAutoCompleteJComboBox subject, DispType arg) { assert (arg != null); assert (SwingUtilities.isEventDispatchThread()); // Ensure arg is in the correct format. final DispType result = org.yccheok.jstock.engine.Utils.rectifyDisp(arg); if (result == null) { // Invalid format. Nothing we can do about it. Returns // early. return; } // Check for duplication. // Symbol from Yahoo means Code in JStock. String message_string = result.getDispCode(); IndexEx indexEx = getIndexEx(result.getDispCode(), Code.class); if (indexEx != null) { if (indexEx.table == jTable1) { selectStockExchangeServerDatabaseTable(indexEx.index); } else { assert (indexEx.table == jTable2); selectUserDefinedDatabaseTable(indexEx.index); } // Warn the user. final String message = MessageFormat.format( MessagesBundle.getString("warning_message_duplicated_stock_template"), message_string); final String title = MessagesBundle.getString("warning_title_duplicated_stock"); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JOptionPane.showMessageDialog(StockDatabaseJDialog.this, message, title, JOptionPane.INFORMATION_MESSAGE); } }); // No thanks! I will ignore the result. return; } // Everything just looks fine. Let's insert it into the table. addNewStockInfo(result); } }; }
From source file:pipeline.GUI_utils.ListOfPointsView.java
private void setupTableModel(List<T> pointList) { tableModel = points.getBeanTableModel(); try {// w w w . ja v a 2s . com Runnable r = () -> { synchronized (modelSemaphore) { tableModel.removeTableModelListener(ListOfPointsView.this); tableModel.addTableModelListener(ListOfPointsView.this); if (table != null) { table.silenceUpdates.incrementAndGet(); table.setModel(tableModel); table.needToInitializeFilterModel = true; table.initializeFilterModel(); setSpreadsheetColumnEditorAndRenderer(); modelForColumnDescriptions = new dataModelAllEditable(1, tableModel.getColumnCount()); @SuppressWarnings("unchecked") Vector<String> rowVector0 = (Vector<String>) modelForColumnDescriptions.getDataVector() .get(0); for (int j = 0; j < tableModel.getColumnCount(); j++) { // FIXME This ignores the names the user may have set rowVector0.setElementAt(tableModel.getColumnName(j), j); } modelForColumnDescriptions.fireTableDataChanged(); table.silenceUpdates.decrementAndGet(); ((AbstractTableModel) table.getModel()).fireTableStructureChanged(); } } }; if (SwingUtilities.isEventDispatchThread()) r.run(); else SwingUtilities.invokeAndWait(r); } catch (InvocationTargetException | InterruptedException e) { throw new RuntimeException(e); } }
From source file:pl.otros.vfs.browser.auth.AbstractUiUserAuthenticator.java
@Override public UserAuthenticationData requestAuthentication(Type[] types) { try {//from w w w .j a v a2 s.c o m Runnable doRun = new Runnable() { @Override public void run() { if (saveCredentialsCheckBox == null) { saveCredentialsCheckBox = new JCheckBox(Messages.getMessage("authenticator.savePassword"), true); } JPanel authOptionPanel = getOptionsPanel(); JPanel panel = new JPanel(new BorderLayout()); panel.add(authOptionPanel); panel.add(saveCredentialsCheckBox, BorderLayout.SOUTH); String[] options = { Messages.getMessage("general.okButtonText"), Messages.getMessage("general.cancelButtonText") }; int showConfirmDialog = JOptionPane.showOptionDialog(null, panel, Messages.getMessage("authenticator.enterCredentials"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); if (showConfirmDialog != JOptionPane.OK_OPTION) { throw new AuthorisationCancelledException("Authorization cancelled by user"); } data = new UserAuthenticationDataWrapper(); getAuthenticationData(data); } }; if (SwingUtilities.isEventDispatchThread()) { doRun.run(); } else { SwingUtilities.invokeAndWait(doRun); } } catch (Exception e) { if (Throwables.getRootCause(e) instanceof AuthorisationCancelledException) { throw (AuthorisationCancelledException) Throwables.getRootCause(e); } } return data; }
From source file:processing.app.Sketch.java
private void setCurrentCode(int which, boolean forceUpdate) { // if current is null, then this is the first setCurrent(0) if (!forceUpdate && (currentIndex == which) && (current != null)) { return;// w w w.ja v a 2 s . co m } // get the text currently being edited if (current != null) { current.getCode().setProgram(editor.getText()); current.setSelectionStart(editor.getSelectionStart()); current.setSelectionStop(editor.getSelectionStop()); current.setScrollPosition(editor.getScrollPosition()); } current = (SketchCodeDocument) data.getCode(which).getMetadata(); currentIndex = which; if (SwingUtilities.isEventDispatchThread()) { editor.setCode(current); } else { try { SwingUtilities.invokeAndWait(() -> editor.setCode(current)); } catch (Exception e) { e.printStackTrace(); } } editor.header.rebuild(); }
From source file:shuffle.fwk.ShuffleController.java
@Override public void repaint() { if (SwingUtilities.isEventDispatchThread()) { setChanged();// w ww . j a v a 2s. c o m notifyObservers(); getFrame().repaint(); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { setChanged(); notifyObservers(); getFrame().repaint(); } }); } }
From source file:tk.tomby.tedit.core.ThreadSafeRepaintManager.java
/** * DOCUMENT ME!/*from w ww . j a va 2 s. co m*/ * * @return DOCUMENT ME! */ private boolean isThreadValid() { return (SwingUtilities.isEventDispatchThread() || Thread.currentThread().getName().equals("SyntheticImageGenerator")); }
From source file:umich.ms.batmass.filesupport.core.actions.importing.ImportFileByCategory.java
/** * It's in here, that we determine the activation condition. By default * a DataFolder must be in ActionsGlobalContext, which means, that a * DataNode for a folder must be selected. * Make sure we're running on EDT./*from ww w . j a v a 2 s . c o m*/ */ protected void init() { assert SwingUtilities.isEventDispatchThread() : "This shall be called only from AWT thread (EDT)"; Lookup.Result<DataFolder> tmp = lkpResult; if (tmp == null) { synchronized (this) { tmp = lkpResult; if (tmp == null) { // The thing we want to listen for the presence or absence of // in the global selection tmp = context.lookupResult(DataFolder.class); lkpResult = tmp; tmp.addLookupListener(this); resultChanged(null); } } } }