List of usage examples for javax.swing SwingUtilities isEventDispatchThread
public static boolean isEventDispatchThread()
From source file:org.trianacode.gui.main.imp.TrianaTask.java
/** * Called before a data input node is removed. *///from w w w . j av a 2 s.c om public void nodeRemoved(TaskNodeEvent event) { if (SwingUtilities.isEventDispatchThread()) { handleNodeRemoved(event); } else { final TaskNodeEvent evt = event; SwingUtilities.invokeLater(new Runnable() { public void run() { handleNodeRemoved(evt); } }); } }
From source file:org.trianacode.gui.main.imp.TrianaTask.java
/** * Called when the value of a parameter is changed, including when a parameter is removed. *///from w ww. j a v a 2 s . co m public void parameterUpdated(ParameterUpdateEvent event) { if (SwingUtilities.isEventDispatchThread()) { handleParameterUpdated(event); } else { final ParameterUpdateEvent evt = event; SwingUtilities.invokeLater(new Runnable() { public void run() { handleParameterUpdated(evt); } }); } }
From source file:org.tros.logo.swing.LogoPanel.java
@Override public void repaint() { if (SwingUtilities.isEventDispatchThread()) { LogoPanel.super.repaint(); } else {/* w w w . ja v a 2 s. co m*/ java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userNodeForPackage(LogoMenuBar.class); if (prefs.getBoolean(LogoMenuBar.WAIT_FOR_REPAINT, true)) { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { LogoPanel.super.repaint(); } }); } catch (InterruptedException | InvocationTargetException ex) { org.tros.utils.logging.Logging.getLogFactory().getLogger(LogoPanel.class).fatal(null, ex); } } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { LogoPanel.super.repaint(); } }); } } }
From source file:org.yccheok.jstock.gui.AjaxAutoCompleteJComboBox.java
private Observer<AjaxGoogleSearchEngineMonitor, MatchSetType> getGoogleMonitorObserver() { return new Observer<AjaxGoogleSearchEngineMonitor, MatchSetType>() { @Override/*w w w . j av a 2s.co m*/ public void update(final AjaxGoogleSearchEngineMonitor subject, MatchSetType arg) { // Can we further enhance our search result? if (arg.Match.isEmpty()) { StockInfo stockInfo = ajaxStockInfoSearchEngine.search(arg.Query); if (stockInfo != null) { MatchType matchType = new MatchType(stockInfo.code.toString().toUpperCase(), stockInfo.symbol.toString(), null, null); List<MatchType> matchTypes = new ArrayList<>(); matchTypes.add(matchType); MatchSetType matchSetType = MatchSetType.newInstance(arg.Query, matchTypes); // Overwrite! arg = matchSetType; } } final MatchSetType _arg = arg; if (SwingUtilities.isEventDispatchThread()) { _update(subject, _arg); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { _update(subject, _arg); } }); } } public void _update(AjaxGoogleSearchEngineMonitor subject, MatchSetType arg) { final String string = AjaxAutoCompleteJComboBox.this.getEditor().getItem().toString().trim(); if (string.isEmpty() || false == string.equalsIgnoreCase(arg.Query)) { return; } // We are no longer busy. busySubject.notify(AjaxAutoCompleteJComboBox.this, false); // During _update operation, there will be a lot of ListDataListeners // trying to modify the content of our text field. We will not allow // them to do so. // // Without setReadOnly(true), when we type the first character "w", IME // will suggest ... However, when we call removeAllItems and addItem, // JComboBox will "commit" this suggestion to JComboBox's text field. // Hence, if we continue to type second character "m", the string displayed // at JComboBox's text field will be ... // AjaxAutoCompleteJComboBox.this.jComboBoxEditor.setReadOnly(true); // Must hide popup. If not, the pop up windows will not be // resized. But this causes flickering. :( boolean isPopupHide = false; if (canRemoveAllItems) { canRemoveAllItems = false; isPopupHide = true; AjaxAutoCompleteJComboBox.this.hidePopup(); AjaxAutoCompleteJComboBox.this.removeAllItems(); codes.clear(); } for (MatchType match : arg.Match) { if (codes.contains(match.getCode().toString())) { continue; } if (!isPopupHide) { isPopupHide = true; AjaxAutoCompleteJComboBox.this.hidePopup(); } codes.add(match.getCode().toString()); AjaxAutoCompleteJComboBox.this.addItem(match); } if (isPopupHide && AjaxAutoCompleteJComboBox.this.getItemCount() > 0) { AjaxAutoCompleteJComboBox.this.showPopup(); } // Restore. AjaxAutoCompleteJComboBox.this.jComboBoxEditor.setReadOnly(false); } }; }
From source file:org.yccheok.jstock.gui.AjaxAutoCompleteJComboBox.java
private Observer<AjaxYahooSearchEngineMonitor, ResultSetType> getYahooMonitorObserver() { return new Observer<AjaxYahooSearchEngineMonitor, ResultSetType>() { @Override/*from w w w .j av a2s . c o m*/ public void update(final AjaxYahooSearchEngineMonitor subject, ResultSetType arg) { // Can we further enhance our search result? if (arg.Result.isEmpty()) { StockInfo stockInfo = ajaxStockInfoSearchEngine.search(arg.Query); if (stockInfo != null) { ResultType resultType = new ResultType(stockInfo.code.toString().toUpperCase(), stockInfo.symbol.toString()); List<ResultType> resultTypes = new ArrayList<>(); resultTypes.add(resultType); // Overwrite! arg = ResultSetType.newInstance(arg.Query, resultTypes); } } final ResultSetType _arg = arg; if (SwingUtilities.isEventDispatchThread()) { _update(subject, _arg); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { _update(subject, _arg); } }); } } public void _update(AjaxYahooSearchEngineMonitor subject, ResultSetType arg) { final String string = AjaxAutoCompleteJComboBox.this.getEditor().getItem().toString().trim(); if (string.isEmpty() || false == string.equalsIgnoreCase(arg.Query)) { return; } // We are no longer busy. busySubject.notify(AjaxAutoCompleteJComboBox.this, false); // During _update operation, there will be a lot of ListDataListeners // trying to modify the content of our text field. We will not allow // them to do so. // // Without setReadOnly(true), when we type the first character "w", IME // will suggest ... However, when we call removeAllItems and addItem, // JComboBox will "commit" this suggestion to JComboBox's text field. // Hence, if we continue to type second character "m", the string displayed // at JComboBox's text field will be ... // AjaxAutoCompleteJComboBox.this.jComboBoxEditor.setReadOnly(true); // Must hide popup. If not, the pop up windows will not be // resized. But this causes flickering. :( boolean isPopupHide = false; if (canRemoveAllItems) { canRemoveAllItems = false; isPopupHide = true; AjaxAutoCompleteJComboBox.this.hidePopup(); AjaxAutoCompleteJComboBox.this.removeAllItems(); codes.clear(); } boolean shouldShowPopup = false; for (ResultType result : arg.Result) { if (codes.contains(result.symbol)) { continue; } if (!isPopupHide) { isPopupHide = true; AjaxAutoCompleteJComboBox.this.hidePopup(); } codes.add(result.symbol); AjaxAutoCompleteJComboBox.this.addItem(result); } if (isPopupHide && AjaxAutoCompleteJComboBox.this.getItemCount() > 0) { AjaxAutoCompleteJComboBox.this.showPopup(); } // Restore. AjaxAutoCompleteJComboBox.this.jComboBoxEditor.setReadOnly(false); } }; }
From source file:org.yccheok.jstock.gui.AutoCompleteJComboBox.java
private Observer<AjaxGoogleSearchEngineMonitor, MatchSetType> getGoogleMonitorObserver() { return new Observer<AjaxGoogleSearchEngineMonitor, MatchSetType>() { @Override/* ww w. j a v a 2s. c om*/ public void update(final AjaxGoogleSearchEngineMonitor subject, MatchSetType arg) { // Can we further enhance our search result? if (arg.Match.isEmpty()) { StockInfo stockInfo = ajaxStockInfoSearchEngine.search(arg.Query); if (stockInfo != null) { MatchType matchType = new MatchType(stockInfo.code.toString().toUpperCase(), stockInfo.symbol.toString(), null, null); List<MatchType> matchTypes = new ArrayList<>(); matchTypes.add(matchType); MatchSetType matchSetType = MatchSetType.newInstance(arg.Query, matchTypes); // Overwrite! arg = matchSetType; } } final MatchSetType _arg = arg; if (SwingUtilities.isEventDispatchThread()) { _update(subject, _arg); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { _update(subject, _arg); } }); } } public void _update(AjaxGoogleSearchEngineMonitor subject, MatchSetType arg) { final String string = AutoCompleteJComboBox.this.getEditor().getItem().toString().trim(); if (string.isEmpty() || false == string.equalsIgnoreCase(arg.Query)) { return; } // We are no longer busy. busySubject.notify(AutoCompleteJComboBox.this, false); // During _update operation, there will be a lot of ListDataListeners // trying to modify the content of our text field. We will not allow // them to do so. // // Without setReadOnly(true), when we type the first character "w", IME // will suggest ... However, when we call removeAllItems and addItem, // JComboBox will "commit" this suggestion to JComboBox's text field. // Hence, if we continue to type second character "m", the string displayed // at JComboBox's text field will be ... // AutoCompleteJComboBox.this.jComboBoxEditor.setReadOnly(true); // Must hide popup. If not, the pop up windows will not be // resized. But this causes flickering. :( boolean isPopupHide = false; if (canRemoveAllItems) { canRemoveAllItems = false; isPopupHide = true; AutoCompleteJComboBox.this.hidePopup(); AutoCompleteJComboBox.this.removeAllItems(); codes.clear(); } if (arg.Match.isEmpty() == false) { // Change to online mode before adding any item. changeMode(Mode.Online); } for (MatchType match : arg.Match) { if (codes.contains(match.getCode().toString())) { continue; } if (!isPopupHide) { isPopupHide = true; AutoCompleteJComboBox.this.hidePopup(); } codes.add(match.getCode().toString()); AutoCompleteJComboBox.this.addItem(match); } if (isPopupHide && AutoCompleteJComboBox.this.getItemCount() > 0) { AutoCompleteJComboBox.this.showPopup(); } // Restore. AutoCompleteJComboBox.this.jComboBoxEditor.setReadOnly(false); } }; }
From source file:org.yccheok.jstock.gui.AutoCompleteJComboBox.java
private Observer<AjaxYahooSearchEngineMonitor, ResultSetType> getYahooMonitorObserver() { return new Observer<AjaxYahooSearchEngineMonitor, ResultSetType>() { @Override/* ww w . j a v a 2 s. co m*/ public void update(final AjaxYahooSearchEngineMonitor subject, ResultSetType arg) { // Can we further enhance our search result? if (arg.Result.isEmpty()) { StockInfo stockInfo = ajaxStockInfoSearchEngine.search(arg.Query); if (stockInfo != null) { ResultType resultType = new ResultType(stockInfo.code.toString().toUpperCase(), stockInfo.symbol.toString()); List<ResultType> resultTypes = new ArrayList<>(); resultTypes.add(resultType); // Overwrite! arg = ResultSetType.newInstance(arg.Query, resultTypes); } } final ResultSetType _arg = arg; if (SwingUtilities.isEventDispatchThread()) { _update(subject, _arg); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { _update(subject, _arg); } }); } } public void _update(AjaxYahooSearchEngineMonitor subject, ResultSetType arg) { final String string = AutoCompleteJComboBox.this.getEditor().getItem().toString().trim(); if (string.isEmpty() || false == string.equalsIgnoreCase(arg.Query)) { return; } // We are no longer busy. busySubject.notify(AutoCompleteJComboBox.this, false); // During _update operation, there will be a lot of ListDataListeners // trying to modify the content of our text field. We will not allow // them to do so. // // Without setReadOnly(true), when we type the first character "w", IME // will suggest ... However, when we call removeAllItems and addItem, // JComboBox will "commit" this suggestion to JComboBox's text field. // Hence, if we continue to type second character "m", the string displayed // at JComboBox's text field will be ... // AutoCompleteJComboBox.this.jComboBoxEditor.setReadOnly(true); // Must hide popup. If not, the pop up windows will not be // resized. But this causes flickering. :( boolean isPopupHide = false; if (canRemoveAllItems) { canRemoveAllItems = false; isPopupHide = true; AutoCompleteJComboBox.this.hidePopup(); AutoCompleteJComboBox.this.removeAllItems(); codes.clear(); } if (arg.Result.isEmpty() == false) { // Change to online mode before adding any item. changeMode(Mode.Online); } for (ResultType result : arg.Result) { if (codes.contains(result.symbol)) { continue; } if (!isPopupHide) { isPopupHide = true; AutoCompleteJComboBox.this.hidePopup(); } codes.add(result.symbol); AutoCompleteJComboBox.this.addItem(result); } if (isPopupHide && AutoCompleteJComboBox.this.getItemCount() > 0) { AutoCompleteJComboBox.this.showPopup(); } // Restore. AutoCompleteJComboBox.this.jComboBoxEditor.setReadOnly(false); } }; }
From source file:org.yccheok.jstock.gui.JStock.java
/** * Activate specified watchlist.//from w ww. j a va 2s . c o m * * @param watchlist Watchlist name */ public void selectActiveWatchlist(String watchlist) { assert (SwingUtilities.isEventDispatchThread()); // Save current watchlist. JStock.this.saveWatchlist(); // Save current GUI options. // Do not call MainFrame.this.saveGUIOptions() (Pay note on the underscore) // , as that will save portfolio's and indicator scanner's as well. JStock.this._saveGUIOptions(); // And switch to new portfolio. JStock.this.getJStockOptions().setWatchlistName(watchlist); JStock.this.initWatchlist(); // I guess user wants to watch the current active watchlist right now. // We will help him to turn to the stock watchlist page. JStock.this.jTabbedPane1.setSelectedIndex(0); // No matter how, just stop progress bar, and display best message. this.setStatusBar(false, this.getBestStatusBarMessage()); }
From source file:org.yccheok.jstock.gui.JStock.java
/** * Activate specified portfolio.//from w ww . j a v a2 s .c om * * @param portfolio Portfolio name */ public void selectActivePortfolio(String portfolio) { assert (SwingUtilities.isEventDispatchThread()); // Save current portfolio. JStock.this.portfolioManagementJPanel.savePortfolio(); // Save current GUI options. JStock.this.portfolioManagementJPanel.saveGUIOptions(); // And switch to new portfolio. JStock.this.getJStockOptions().setPortfolioName(portfolio); JStock.this.portfolioManagementJPanel.initPortfolio(); // I guess user wants to watch the current active portfolio right now. // We will help him to turn to the portfolio page. JStock.this.jTabbedPane1.setSelectedIndex(3); JStock.this.portfolioManagementJPanel.updateTitledBorder(); // No matter how, just stop progress bar, and display best message. this.setStatusBar(false, this.getBestStatusBarMessage()); }
From source file:org.yccheok.jstock.gui.JStock.java
/** * Set the exchange rate value on status bar. * * @param exchangeRate the exchange rate value. null to reset *//*from ww w. j av a 2s. co m*/ public void setStatusBarExchangeRate(final Double exchangeRate) { if (SwingUtilities.isEventDispatchThread()) { statusBar.setExchangeRate(exchangeRate); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { statusBar.setExchangeRate(exchangeRate); } }); } }