Example usage for javax.swing SwingUtilities isEventDispatchThread

List of usage examples for javax.swing SwingUtilities isEventDispatchThread

Introduction

In this page you can find the example usage for javax.swing SwingUtilities isEventDispatchThread.

Prototype

public static boolean isEventDispatchThread() 

Source Link

Document

Returns true if the current thread is an AWT event dispatching thread.

Usage

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatPanel.java

/**
 * Updates the status of the given chat transport in the send via selector
 * box and notifies the user for the status change.
 * @param chatTransport the <tt>chatTransport</tt> to update
 *//*  w  w  w  .j a v  a 2s .c om*/
public void updateChatTransportStatus(final ChatTransport chatTransport) {
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                updateChatTransportStatus(chatTransport);
            }
        });
        return;
    }

    writeMessagePanel.updateChatTransportStatus(chatTransport);

    if (!chatTransport.equals(chatSession.getCurrentChatTransport()))
        return;

    if (ConfigurationUtils.isShowStatusChangedInChat()) {
        // Show a status message to the user.
        this.addMessage(chatTransport.getName(), new Date(), Chat.STATUS_MESSAGE,
                GuiActivator.getResources().getI18NString("service.gui.STATUS_CHANGED_CHAT_MESSAGE",
                        new String[] { chatTransport.getStatus().getStatusName() }),
                "text/plain");
    }
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

@Override
public void refreshUi() {
    if (SwingUtilities.isEventDispatchThread()) {
        hexMapPanel.revalidate();// w  w  w .j av  a 2 s .  c  om
        this.hexMapPanel.repaint();
    } else {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                hexMapPanel.revalidate();
                hexMapPanel.repaint();
            }
        });
    }
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

@Override
public void upHexLayer(final HexLayer layer) {
    final Runnable run = new Runnable() {
        @Override/*from   w ww  . j  a  v a2s.  c o  m*/
        public void run() {
            if (layer instanceof LayerRecordPanel) {
                layers.up((LayerRecordPanel) layer);
            }
        }
    };
    if (SwingUtilities.isEventDispatchThread()) {
        run.run();
    } else {
        SwingUtilities.invokeLater(run);
    }
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

@Override
public void downHexLayer(final HexLayer layer) {
    final Runnable run = new Runnable() {
        @Override//ww  w.  j  a  v a  2s  .  c  o m
        public void run() {
            if (layer instanceof LayerRecordPanel) {
                layers.down((LayerRecordPanel) layer);
            }
        }
    };
    if (SwingUtilities.isEventDispatchThread()) {
        run.run();
    } else {
        SwingUtilities.invokeLater(run);
    }
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatPanel.java

/**
 * Updates the contact status.//w w w.j  ava2s  . co  m
 * @param chatContact the chat contact to update
 * @param statusMessage the status message to show
 */
public void updateChatContactStatus(final ChatContact<?> chatContact, final String statusMessage) {
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                updateChatContactStatus(chatContact, statusMessage);
            }
        });
        return;
    }

    this.addMessage(chatContact.getName(), new Date(), Chat.STATUS_MESSAGE, statusMessage,
            ChatHtmlUtils.TEXT_CONTENT_TYPE);
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

@Override
public HexLayer makeHexLayer(final String name, final String comment) {
    if (name == null) {
        throw new NullPointerException("Name must not be null");
    }//from  w ww  . j a va2 s .  c o m
    if (comment == null) {
        throw new NullPointerException("Comments must not be null");
    }

    final AtomicReference<HexLayer> result = new AtomicReference<HexLayer>();

    final Runnable run = new Runnable() {
        @Override
        public void run() {
            result.set(layers.addLayer(layers.makeNewLayerField(name, comment)));
        }
    };

    if (SwingUtilities.isEventDispatchThread()) {
        run.run();
    } else {
        try {
            SwingUtilities.invokeAndWait(run);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
    return result.get();
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatPanel.java

/**
 * Sets the given <tt>subject</tt> to this chat.
 * @param subject the subject to set//from  www  . j  a  va2s.c o m
 */
public void setChatSubject(final String subject) {
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                setChatSubject(subject);
            }
        });

        return;
    }

    if (subjectPanel != null) {
        // Don't do anything if the subject doesn't really change.
        String oldSubject = subjectPanel.getSubject();

        if ((subject == null) || (subject.length() == 0)) {
            if ((oldSubject == null) || (oldSubject.length() == 0))
                return;
        } else if (subject.equals(oldSubject))
            return;

        subjectPanel.setSubject(subject);

        this.addMessage(chatSession.getChatName(), new Date(), Chat.STATUS_MESSAGE,
                GuiActivator.getResources().getI18NString("service.gui.CHAT_ROOM_SUBJECT_CHANGED",
                        new String[] { chatSession.getChatName(), subject }),
                ChatHtmlUtils.TEXT_CONTENT_TYPE);
    }
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatPanel.java

/**
 * Adds the given <tt>IncomingFileTransferRequest</tt> to the conversation
 * panel in order to notify the user of the incoming file.
 *
 * @param fileTransferOpSet the file transfer operation set
 * @param request the request to display in the conversation panel
 * @param date the date on which the request has been received
 *///from  ww  w  .j a v a2 s  .  c o  m
public void addIncomingFileTransferRequest(final OperationSetFileTransfer fileTransferOpSet,
        final IncomingFileTransferRequest request, final Date date) {
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                addIncomingFileTransferRequest(fileTransferOpSet, request, date);
            }
        });
        return;
    }

    this.addActiveFileTransfer(request.getID(), request);

    ReceiveFileConversationComponent component = new ReceiveFileConversationComponent(this, fileTransferOpSet,
            request, date);

    if (ConfigurationUtils.isHistoryShown() && !isHistoryLoaded) {
        synchronized (incomingEventBuffer) {
            incomingEventBuffer.add(component);
        }
    } else
        this.getChatConversationPanel().addComponent(component);
}

From source file:net.sf.jabref.gui.JabRefFrame.java

/**
 * Set the visibility of the progress bar in the right end of the
 * status line at the bottom of the frame.
 * <p>//from  w ww . j  a  v  a  2s.com
 * If not called on the event dispatch thread, this method uses
 * SwingUtilities.invokeLater() to do the actual operation on the EDT.
 */
public void setProgressBarVisible(final boolean visible) {
    if (SwingUtilities.isEventDispatchThread()) {
        progressBar.setVisible(visible);
    } else {
        SwingUtilities.invokeLater(() -> progressBar.setVisible(visible));
    }
}

From source file:net.sf.jabref.gui.JabRefFrame.java

/**
 * Sets the current value of the progress bar.
 * <p>/*from   w w  w  .ja v  a 2s .  c  o m*/
 * If not called on the event dispatch thread, this method uses
 * SwingUtilities.invokeLater() to do the actual operation on the EDT.
 */
public void setProgressBarValue(final int value) {
    if (SwingUtilities.isEventDispatchThread()) {
        progressBar.setValue(value);
    } else {
        SwingUtilities.invokeLater(() -> progressBar.setValue(value));
    }

}