List of usage examples for javax.swing SwingUtilities isEventDispatchThread
public static boolean isEventDispatchThread()
From source file:org.martus.client.swingui.FxInSwingMainWindow.java
public void runInUiThreadAndWait(Runnable toRun) throws InterruptedException, InvocationTargetException { if (SwingUtilities.isEventDispatchThread()) { toRun.run();//www . jav a2 s. c o m return; } SwingUtilities.invokeAndWait(toRun); }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java
/** * Set the columns error message in the ReportQueryDialog.... * This is called from a none swing thread, hence all the invoke and * wait magic./*from www .ja va 2 s . c o m*/ * The message is only set if the query string matches the one the * error message is for. * * @param columns The list of columns to set. */ protected void setColumnErrorFromWork(final String error_msg) { try { Runnable r = new Runnable() { public void run() { getReportQueryDialog().setColumnsError(error_msg); getReportQueryDialog().getQueryEditorPane().requestFocusInWindow(); } }; if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { SwingUtilities.invokeAndWait(r); } } catch (Exception e) { // oh well we got interrupted. } }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatPanel.java
/** * Adds a typing notification message to the conversation panel, * saying that typin notifications has not been delivered. * * @param typingNotification the typing notification to show *///from www. j av a 2s. c o m public void addErrorSendingTypingNotification(final String typingNotification) { if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater(new Runnable() { public void run() { addErrorSendingTypingNotification(typingNotification); } }); return; } typingNotificationLabel.setText(typingNotification); if (typingNotification != null && !typingNotification.equals(" ")) typingNotificationLabel.setIcon(typingIcon); else typingNotificationLabel.setIcon(null); revalidate(); repaint(); }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java
/** * Set the columns in the ReportQueryDialog.... * This is called from a none swing thread, hence all the invoke and * wait magic./* w w w.ja va2 s . c o m*/ * The message is only set if the query string matches the one the * error message is for. * * @param columns The list of columns to set. */ protected void setColumnsFromWorker(final List columns) { try { Runnable r = new Runnable() { public void run() { getReportQueryDialog().setColumns(columns); getReportQueryDialog().getQueryEditorPane().requestFocusInWindow(); } }; if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { SwingUtilities.invokeAndWait(r); } } catch (Exception e) { // oh well we got interrupted. } }
From source file:de.codesourcery.eve.skills.market.impl.EveCentralMarketDataProvider.java
private static Map<InventoryType, PriceInfoQueryResult> runOnEventThread(final PriceCallable r) throws PriceInfoUnavailableException { if (SwingUtilities.isEventDispatchThread()) { return r.call(); }/*from w w w .j av a 2 s . c o m*/ final AtomicReference<Map<InventoryType, PriceInfoQueryResult>> result = new AtomicReference<Map<InventoryType, PriceInfoQueryResult>>(); try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { try { result.set(r.call()); } catch (PriceInfoUnavailableException e) { throw new RuntimeException(e); } } }); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (InvocationTargetException e) { Throwable wrapped = e.getTargetException(); if (wrapped instanceof RuntimeException) { if (wrapped.getCause() instanceof PriceInfoUnavailableException) { throw (PriceInfoUnavailableException) wrapped.getCause(); } throw (RuntimeException) wrapped; } else if (e.getTargetException() instanceof Error) { throw (Error) wrapped; } throw new RuntimeException(e.getTargetException()); } return result.get(); }
From source file:ee.ioc.cs.vsle.editor.Editor.java
/** * Creates and displays the main application window. * /*from w ww. ja va2 s . c o m*/ * @param args the arguments from the command line */ static void createAndInitGUI(String[] args) { assert SwingUtilities.isEventDispatchThread(); // Some of the stuff in this method could be run on the main thread, // but running it in the EDT seems to not hurt. Creating new Canvas // instances combined with PropertyChangeListeners is definitely // unsafe in the main thread and has caused real problems. checkWebStart(args); /* * Remove security manager, because all permissions * are required. This is especially critical when * running from the Java Web Start. (Otherwise * all classes loaded by our own class loaders * will have default sandbox permissions.) */ System.setSecurityManager(null); checkJavaVersion(); String directory = RuntimeProperties.getWorkingDirectory(); logger.info("Working directory: {}", directory); RuntimeProperties.init(); Look.getInstance().initDefaultLnF(); final Editor window = new Editor(); s_instance = window; if (!RuntimeProperties.isFromWebstart() && args.length > 0) { if (args[0].equals("-p")) { String dir = (args.length == 3) ? directory + args[2] + File.separator : directory; Synthesizer.parseFromCommandLine(dir, args[1]); } else { logger.info(args[0] + " read from command line."); File file = new File(directory + args[0]); if (file.exists()) { window.openNewCanvasWithPackage(file); } } } else { for (String packageFile : RuntimeProperties.getPrevOpenPackages()) { File f = new File(packageFile); if (f.exists()) { logger.debug("Found package file name {} from the configuration file.", packageFile); window.openNewCanvasWithPackage(f); } } } window.setTitle(WINDOW_TITLE); //restore window location, size and state final String[] bs = RuntimeProperties.getSchemeEditorWindowProps().split(";"); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { int x = bs[0] != null && bs[0].length() > 0 ? Integer.parseInt(bs[0]) : window.getLocationOnScreen().x; int y = bs[1] != null && bs[1].length() > 0 ? Integer.parseInt(bs[1]) : window.getLocationOnScreen().y; int w = bs[2] != null && bs[2].length() > 0 ? Integer.parseInt(bs[2]) : window.getSize().width; int h = bs[3] != null && bs[3].length() > 0 ? Integer.parseInt(bs[3]) : window.getSize().height; int s = bs[4] != null && bs[4].length() > 0 ? Integer.parseInt(bs[4]) : window.getState(); window.setBounds(x, y, w, h); window.setExtendedState(s); } }); window.setVisible(true); /* ******************** Init Factories ******************** */ SpecGenerator.init(); XMLSpecGenerator.init(); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java
/** * Updates the chart panel to show the provided {@link JFreeChart}. If the chart is * <code>null</code> an empty Plot will be shown. If an overlay has been defined and the chart * is a {@link XYPlot} the overlay is also drawn. *//*from w w w . jav a 2 s.co m*/ private synchronized void updateChartPanel(final JFreeChart chart) { Runnable updateChartPanelRunnable = new Runnable() { @Override public void run() { if (chart != chartPanel.getChart()) { if (chart == null) { chartPanel.setChart(new JFreeChart(new CategoryPlot())); fireChartChanged(new JFreeChart(new CategoryPlot())); } else { RenderingHints renderingHints = chart.getRenderingHints(); // enable antialiasing renderingHints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)); // disable normalization (normalization tries to draw the center of strokes // at whole pixels, which causes e.g. // scaled shapes to appear more like potatoes than like circles) renderingHints.add(new RenderingHints(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE)); chart.setRenderingHints(renderingHints); chartPanel.setChart(chart); fireChartChanged(chart); } } if (chart != null) { chartPanel.removeOverlay(crosshairOverlay); crosshairOverlay = new MultiAxesCrosshairOverlay(); if (chart.getPlot() instanceof XYPlot) { // add overlays for range axes int axisIdx = 0; for (RangeAxisConfig rangeAxisConfig : plotInstance.getCurrentPlotConfigurationClone() .getRangeAxisConfigs()) { for (AxisParallelLineConfiguration line : rangeAxisConfig.getCrossHairLines() .getLines()) { Crosshair crosshair = new Crosshair(line.getValue(), line.getFormat().getColor(), line.getFormat().getStroke()); crosshairOverlay.addRangeCrosshair(axisIdx, crosshair); } ++axisIdx; } // add overlays for domain axis for (AxisParallelLineConfiguration line : plotInstance.getCurrentPlotConfigurationClone() .getDomainConfigManager().getCrosshairLines().getLines()) { Crosshair crosshair = new Crosshair(line.getValue(), line.getFormat().getColor(), line.getFormat().getStroke()); crosshairOverlay.addDomainCrosshair(crosshair); } chartPanel.addOverlay(crosshairOverlay); } } } }; if (SwingUtilities.isEventDispatchThread()) { updateChartPanelRunnable.run(); } else { SwingUtilities.invokeLater(updateChartPanelRunnable); } }
From source file:javazoom.jlgui.player.amp.PlayerUI.java
/** * Process action event.//from w ww . j ava 2s.c o m * @param e */ public void processActionEvent(ActionEvent e) { String cmd = e.getActionCommand(); log.debug("Action=" + cmd + " (EDT=" + SwingUtilities.isEventDispatchThread() + ")"); // Preferences. if (cmd.equalsIgnoreCase(PlayerActionEvent.MIPREFERENCES)) { processPreferences(e.getModifiers()); } // Skin browser else if (cmd.equals(PlayerActionEvent.MISKINBROWSER)) { processSkinBrowser(e.getModifiers()); } // Jump to file else if (cmd.equals(PlayerActionEvent.MIJUMPFILE)) { processJumpToFile(e.getModifiers()); } // Stop else if (cmd.equals(PlayerActionEvent.MISTOP)) { processStop(MouseEvent.BUTTON1_MASK); } // Load skin else if (e.getActionCommand().equals(PlayerActionEvent.MILOADSKIN)) { File[] file = FileSelector.selectFile(loader, FileSelector.OPEN, false, ui.getResource("skin.extension"), ui.getResource("loadskin.dialog.filtername"), new File(config.getLastDir())); if (FileSelector.getInstance().getDirectory() != null) config.setLastDir(FileSelector.getInstance().getDirectory().getPath()); if (file != null) { String fsFile = file[0].getName(); ui.setPath(config.getLastDir() + fsFile); loadSkin(); config.setDefaultSkin(ui.getPath()); } } // Shuffle else if (cmd.equals(PlayerActionEvent.ACSHUFFLE)) { if (ui.getAcShuffle().isSelected()) { config.setShuffleEnabled(true); if (playlist != null) { playlist.shuffle(); playlistUI.initPlayList(); // Play from the top PlaylistItem pli = playlist.getCursor(); setCurrentSong(pli); } } else { config.setShuffleEnabled(false); } } // Repeat else if (cmd.equals(PlayerActionEvent.ACREPEAT)) { if (ui.getAcRepeat().isSelected()) { config.setRepeatEnabled(true); } else { config.setRepeatEnabled(false); } } // Play file else if (cmd.equals(PlayerActionEvent.MIPLAYFILE)) { processEject(MouseEvent.BUTTON1_MASK); } // Play URL else if (cmd.equals(PlayerActionEvent.MIPLAYLOCATION)) { processEject(MouseEvent.BUTTON3_MASK); } // Playlist menu item else if (cmd.equals(PlayerActionEvent.MIPLAYLIST)) { ui.getAcPlaylist().setSelected(miPlaylist.getState()); togglePlaylist(); } // Playlist toggle button else if (cmd.equals(PlayerActionEvent.ACPLAYLIST)) { togglePlaylist(); } // EqualizerUI menu item else if (cmd.equals(PlayerActionEvent.MIEQUALIZER)) { ui.getAcEqualizer().setSelected(miEqualizer.getState()); toggleEqualizer(); } // EqualizerUI else if (cmd.equals(PlayerActionEvent.ACEQUALIZER)) { toggleEqualizer(); } // Exit player else if (cmd.equals(PlayerActionEvent.ACEXIT)) { closePlayer(); } // Minimize else if (cmd.equals(PlayerActionEvent.ACMINIMIZE)) { loader.minimize(); } // Eject else if (cmd.equals(PlayerActionEvent.ACEJECT)) { processEject(e.getModifiers()); } // Play else if (cmd.equals(PlayerActionEvent.ACPLAY)) { processPlay(e.getModifiers()); } // Pause else if (cmd.equals(PlayerActionEvent.ACPAUSE)) { processPause(e.getModifiers()); } // Stop else if (cmd.equals(PlayerActionEvent.ACSTOP)) { processStop(e.getModifiers()); } // Next else if (cmd.equals(PlayerActionEvent.ACNEXT)) { processNext(e.getModifiers()); } // Previous else if (cmd.equals(PlayerActionEvent.ACPREVIOUS)) { processPrevious(e.getModifiers()); } }
From source file:au.org.ala.delta.intkey.model.IntkeyContext.java
/** * Read and execute the specified dataset startup file. This file may be * either a "webstart" file, or a file containing actual directives to * initialize the dataset./*from ww w .ja va2s . co m*/ * * This method will block while the calling thread while the file is read, * the dataset is loaded, and other directives in the file are executed. * * @param datasetFileURL * The dataset initialization file * @return SwingWorker used to load the dataset in a separate thread - unit * tests need this so that they can block until the dataset is * loaded. */ public synchronized void newDataSetFile(final URL datasetFileURL) { Logger.log("Reading in directives from url: %s", datasetFileURL.toString()); // Close any dialogs that have been left open. IntKeyDialogController.closeWindows(); cleanupOldDataset(); initializeIdentification(); // Loading of a new dataset can take a long time and hence can lock up // the UI. If this method is called from the Swing Event Dispatch // Thread, load the // new dataset on a background thread using a SwingWorker. if (SwingUtilities.isEventDispatchThread()) { _appUI.displayBusyMessage(UIUtils.getResourceString("LoadingDataset.caption")); SwingWorker<Void, Void> startupWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { processStartupFile(datasetFileURL); return null; } @Override protected void done() { try { get(); if (_dataset.getHeading() != null) { appendToLog(_dataset.getHeadingWithoutFormatting()); } if (_dataset.getSubHeading() != null) { appendToLog(_dataset.getSubheadingWithoutFormatting()); } _appUI.handleNewDataset(_dataset); } catch (Exception ex) { Logger.error("Error reading dataset file", ex); _appUI.displayErrorMessage(UIUtils.getResourceString("ErrorReadingReadsetFile.error", datasetFileURL.toString(), ex.getMessage())); } finally { _appUI.removeBusyMessage(); } } }; startupWorker.execute(); } else { try { processStartupFile(datasetFileURL); if (_dataset.getHeading() != null) { appendToLog(_dataset.getHeadingWithoutFormatting()); } if (_dataset.getSubHeading() != null) { appendToLog(_dataset.getSubheadingWithoutFormatting()); } _appUI.handleNewDataset(_dataset); } catch (Exception ex) { Logger.error("Error reading dataset file", ex); _appUI.displayErrorMessage(UIUtils.getResourceString("ErrorReadingReadsetFile.error", datasetFileURL.toString(), ex.getMessage())); } } }
From source file:SwingWorker.java
/** * Invokes {@code done} on the EDT.// www . j ava2s . c o m */ private void doneEDT() { Runnable doDone = new Runnable() { public void run() { done(); } }; if (SwingUtilities.isEventDispatchThread()) { doDone.run(); } else { SwingUtilities.invokeLater(doDone); } }