List of usage examples for javax.swing SwingUtilities isEventDispatchThread
public static boolean isEventDispatchThread()
From source file:WorkThreadPool.java
/** * Waits until all requests are complete. *//*from ww w . j a va 2s . com*/ public void waitForRequests() { if (threads == null) return; synchronized (waitForAllLock) { while (requestCount != 0) { try { waitForAllLock.wait(); } catch (InterruptedException ie) { } } } if (SwingUtilities.isEventDispatchThread()) { // do any queued AWT runnables doAWTRequests(); } else { try { SwingUtilities.invokeAndWait(new RunRequestsInAWTThread()); } catch (Exception e) { } } }
From source file:com.diversityarrays.util.DefaultDALClientProvider.java
protected void fireStateChanged() { if (SwingUtilities.isEventDispatchThread()) { // We want to run OUTSIDE the event dispatch thread. new Thread(() -> fireStateChanged()).start(); return;/* w ww . j av a2 s. co m*/ } for (ChangeListener l : listenerList.getListeners(ChangeListener.class)) { try { l.stateChanged(changeEvent); } catch (Throwable t) { t.printStackTrace(); if (t instanceof OutOfMemoryError) { // Give up ! break; } } } }
From source file:com.aw.swing.mvp.action.ActionManager.java
public void executeAction(final Action action) { atBeginningOfAction(action);/*from w w w.j a v a2 s .c o m*/ AWActionTipPainter.instance().hideTipWindow(); if (action instanceof RoundTransitionAction) { ((RoundTransitionAction) action).setTransitionStoppedWithException(false); } GridProviderManager gridProviderManager = action.getPst().getGridProviderMgr(); gridProviderManager.removeEditors(); try { action.checkBasicConditions(); } catch (FlowBreakSilentlyException ex) { logger.info("Exit flow method silently"); return; } catch (AWException ex) { logger.error("AW Exception:", ex); if (action instanceof RoundTransitionAction) { ((RoundTransitionAction) action).setTransitionStoppedWithException(true); } PainterMessages.paintException(ex); return; } String confirmMsg = action.getConfirmMsg(); if (StringUtils.hasText(confirmMsg)) { boolean isCancelAction = action instanceof CancelAction; boolean isFindPst = action.getPst() instanceof FindPresenter; boolean isModeReadOnly = ViewMode.MODE_READONLY.equals(action.getPst().getViewMode()); boolean isShowCancelMsgConfirmation = action.getPst().isShowCancelMsgConfirmation(); if (!isCancelAction || (isShowCancelMsgConfirmation && !isModeReadOnly && !isFindPst)) { if (!MsgDisplayer.showConfirmMessage(confirmMsg)) { logger.debug( "The action:<" + action.toString() + ">will not be executed because was not confirmed"); return; } } } try { action.checkConditions(); AWInputVerifier.getInstance().disable(); Presenter pst = action.getPst(); if (action.execBinding) { pst.setValuesToBean(); } if (action.execValidation) { pst.validate(); } } catch (AWException ex) { if (action instanceof RoundTransitionAction) { ((RoundTransitionAction) action).setTransitionStoppedWithException(true); } if (ex instanceof FlowBreakSilentlyException) { return; } logger.error("AW Exception:", ex); PainterMessages.paintException(ex); return; } finally { AWInputVerifier.getInstance().enable(); } if (action.useMessageBlocker) { try { if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeAndWait(new Runnable() { public void run() { ProcessMsgBlocker.instance().showMessage("Procesando ..."); } }); } else { ProcessMsgBlocker.instance().showMessage("Procesando ..."); } } catch (Throwable e) { e.printStackTrace(); } SwingWorker swingWorker = new SwingWorker() { protected Object doInBackground() throws Exception { executeActionInternal(action); return null; } protected void done() { ProcessMsgBlocker.instance().removeMessage(); action.afterExecute(); } }; swingWorker.execute(); } else { executeActionInternal(action); action.afterExecute(); } }
From source file:com.aw.swing.mvp.Presenter.java
/** * Init the presenter//from www . j a v a 2 s . c o m */ public final void init() { if (SwingUtilities.isEventDispatchThread()) { initInternal(); } else { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { initInternal(); } }); } catch (Throwable e) { throw new AWBusinessException("Problems initializing the presenter:" + this, e); } } }
From source file:com.moss.greenshell.wizard.ProcessPanel.java
private void runOnEventDispatchThread(Runnable action) { try {//from w w w . java 2 s . c o m if (SwingUtilities.isEventDispatchThread()) { action.run(); } else { SwingUtilities.invokeLater(action); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.archivas.clienttools.arcmover.gui.panels.ProfilePanel.java
/** * Enables/disables all subcomponents of this panel. This also toggles the ability to drag and * drop and conditionally freezes the ability to resize the file list column headers. * * @param enabled//w w w. j ava2 s .c om * Whether or not this panel is enabled */ private void subSetEnabled(final boolean enabled) { if (!SwingUtilities.isEventDispatchThread()) { String errMsg = "subSetEnabled is not on the EDT but it should be"; IllegalStateException ex = new IllegalStateException(errMsg); LOG.log(Level.SEVERE, errMsg, ex); throw ex; } enableDragAndDrop(enabled); GUIHelper.enableComponent(this, enabled); setEnabled(true); // Re-enable the panel since GUIHelper.enableComponent disables it sslButton.setEnabled(enabled && profileModel.getProfileAdapter() != null && profileModel.getProfileAdapter().getSSLCertChain() != null); browseDirectoryButton.setEnabled(enabled && getSelectedProfile().getType() == ProfileType.FILESYSTEM); JTableHeader header = fileList.getTableHeader(); if (header != null) { header.setResizingAllowed(enabled); } }
From source file:dk.dma.epd.common.prototype.gui.voct.VOCTAdditionalInfoPanel.java
/** * Updates the chat message panel in the Swing event thread *///from w ww . j a v a2 s .c om public void updateChatMessagePanel() { // Ensure that we operate in the Swing event thread if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { updateChatMessagePanel(); } }); return; } // Only enable send-function when there is chat data, and hence a target addBtn.setEnabled(true); messageText.setEditable(true); // Remove all components from the messages panel messagesPanel.removeAll(); Insets insets = new Insets(0, 2, 2, 2); Insets insets2 = new Insets(6, 2, 0, 2); // if (chatData != null && chatData.getMessageCount() > 0) { // First, add a filler component int y = 0; messagesPanel.add(new JLabel(""), new GridBagConstraints(0, y++, 1, 1, 0.0, 1.0, NORTH, VERTICAL, insets, 0, 0)); // Add the messages long lastMessageTime = 0; long ownMMSI = MaritimeCloudUtils.toMmsi(EPD.getInstance().getMaritimeId()); for (VOCTSARInfoMessage message : EPD.getInstance().getVoctHandler().getAdditionalInformationMsgs()) { boolean ownMessage = false; if (message.getSender() == ownMMSI) { ownMessage = true; } // EPD.getInstance().getIdentityHandler().getActor(mmsi) // Check if we need to add a time label if (message.getDate() - lastMessageTime > PRINT_DATE_INTERVAL) { JLabel dateLabel = new JLabel(String.format(ownMessage ? "Added %s" : "Received %s", Formatter.formatShortDateTimeNoTz(new Date(message.getDate())))); dateLabel.setFont(dateLabel.getFont().deriveFont(9.0f).deriveFont(Font.PLAIN)); dateLabel.setHorizontalAlignment(SwingConstants.CENTER); dateLabel.setForeground(Color.LIGHT_GRAY); messagesPanel.add(dateLabel, new GridBagConstraints(0, y++, 1, 1, 1.0, 0.0, NORTH, HORIZONTAL, insets2, 0, 0)); } // Add a chat message field JPanel msg = new JPanel(); msg.setBorder(new ChatMessageBorder(message, ownMessage)); JLabel msgLabel = new ChatMessageLabel(message.getMessage(), ownMessage); msg.add(msgLabel); messagesPanel.add(msg, new GridBagConstraints(0, y++, 1, 1, 1.0, 0.0, NORTH, HORIZONTAL, insets, 0, 0)); lastMessageTime = message.getDate(); } // Scroll to the bottom validate(); scrollPane.getVerticalScrollBar().setValue(scrollPane.getVerticalScrollBar().getMaximum()); messagesPanel.repaint(); // } else if (chatData == null && noDataComponent != null) { // // The noDataComponent may e.g. be a message // messagesPanel.add(noDataComponent, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, NORTH, BOTH, insets, 0, 0)); // } }
From source file:edu.ku.brc.af.ui.forms.validation.ValComboBox.java
/** * Constructor with dbAdapter.// w w w. ja v a 2 s. c om * @param dbAdapter the adaptor for enabling auto complete */ public ValComboBox(final PickListDBAdapterIFace adapter) { if (!adapter.isReadOnly()) { Java2sAutoComboBox cbx = new Java2sAutoComboBox(adapter.getList()); adapter.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (ValComboBox.this.comboBox instanceof Java2sAutoComboBox) { final Java2sAutoComboBox c = (Java2sAutoComboBox) ValComboBox.this.comboBox; if (SwingUtilities.isEventDispatchThread()) { c.setDataList(adapter.getList()); } else { SwingUtilities.invokeLater(new Runnable() { /* (non-Javadoc) * @see java.lang.Runnable#run() */ @Override public void run() { c.setDataList(adapter.getList()); } }); } } } }); comboBox = cbx; setControlSize(comboBox); cbx.setStrict(false); } else if (adapter instanceof ComboBoxModel) { comboBox = new ClearableComboBox((ComboBoxModel) adapter); setControlSize(comboBox); } else { String msg = "PickListDBAdapterIFace is not an instanceof ComboBoxModel and MUST BE!"; FormDevHelper.appendFormDevError(msg); } this.adapter = adapter; adapter.setAutoSaveOnAdd(false); init(!adapter.isReadOnly()); }
From source file:com.moss.appprocs.swing.ProgressDialog.java
private void runOnEventDispatchThread(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run();//w w w .ja va2 s . c om } else { SwingUtilities.invokeLater(r); } }
From source file:com.archivas.clienttools.arcmover.gui.panels.ProfilePanel.java
private void lock() { if (!SwingUtilities.isEventDispatchThread()) { String errMsg = "lock is not on the EDT but it should be"; IllegalStateException ex = new IllegalStateException(errMsg); LOG.log(Level.SEVERE, errMsg, ex); throw ex; }// ww w . j ava2 s . c o m lockCount++; updateLockState(); if (lockCount == 1) { firePropertyChange(LOCK_PROPERTY, false, true); } }