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:edu.ku.brc.specify.Specify.java

/**
 * Creates the initial panels that will be shown at start up and sets up the Application Context
 * @param databaseNameArg the database name
 * @param userNameArg the user name/*from  ww w .  j a  v a 2  s  .c o m*/
 */
protected void initStartUpPanels(final String databaseNameArg, final String userNameArg) {

    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                initStartUpPanels(databaseNameArg, userNameArg);
            }
        });
        return;
    }

    TaskMgr.getInstance().readRegistry(UIRegistry.isMobile());

    TaskMgr.initializePlugins();

    Taskable bkTask = TaskMgr.getTask("BackupTask");
    if (bkTask != null) {
        bkTask.setIconName("MySQL");
    }
    validate();

    add(mainPanel, BorderLayout.CENTER);
    doLayout();

    mainPanel.setBackground(Color.WHITE);

    JToolBar toolBar = (JToolBar) UIRegistry.get(UIRegistry.TOOLBAR);
    if (toolBar != null && toolBar.getComponentCount() < 2) {
        toolBar.setVisible(false);
    }

    //        AttachmentManagerIface attchMgr = AttachmentUtils.getAttachmentManager();
    //        attchMgr.addListener(new AttachmentMgrListener()
    //        {
    //            int max = 0;
    //            @Override
    //            public void filesLoading(final int numberOfFiles)
    //            {
    //                final String statusName = "ATTACH";
    //                SwingUtilities.invokeLater(new Runnable()
    //                {
    //                    @Override
    //                    public void run()
    //                    {
    //                        //System.out.println("N: "+numberOfFiles+" MX: "+max);
    //                        statusField.setIndeterminate(statusName, numberOfFiles > 0);
    //                        
    ////                        if (max == 0) 
    ////                        {
    ////                            statusField.setProgressRange(statusName, 0, 100);
    ////                            statusField.setValue(statusName, 0);
    ////                        }
    ////                        boolean hasFiles = numberOfFiles > 0;
    ////                        if (hasFiles) 
    ////                        {
    ////                            if (numberOfFiles > max) 
    ////                            {
    ////                                max = numberOfFiles;
    ////                            } 
    ////                            int num = (int)((double)(max - numberOfFiles) / (double)max) * 100;
    ////                            System.out.println("N: "+numberOfFiles+" MX: "+max+"  num: "+num);
    ////                            if (numberOfFiles == max && max == 1)
    ////                            {
    ////                                statusField.setIndeterminate(statusName, true);
    ////                                System.out.println("setIndeterminate true");
    ////
    ////                            } else
    ////                            {
    ////                                statusField.setIndeterminate(statusName, false);
    ////                                statusField.setValue(statusName, num);
    ////                                System.out.println("setIndeterminate falsw");
    ////                                //progress.setValue(num);
    ////                                //progress.setString(Integer.toString(num)+"%");
    ////                            }
    ////                            //progress.repaint();
    ////                        } else 
    ////                        {
    ////                            max = 0;
    ////                            statusField.setProgressDone(statusName);
    ////                        }
    //                    }
    //                });
    //            }
    //        });

}

From source file:com.archivas.clienttools.arcmover.gui.panels.ProfilePanel.java

/**
 * This updates the current state, updating tooltips, calling to update the file menu and right
 * click menus. Works on the EDT synchronously.
 * /*from  w  w  w . j a v a2  s .c  o m*/
 * @param dir
 *            The new current directory
 * @param path
 *            The new current path
 * @param profile
 *            The new current profile
 */
private void setCurrent(final ArcMoverDirectory dir, final String path, final String[] paths,
        final AbstractProfileBase profile) {
    if (SwingUtilities.isEventDispatchThread()) {
        String errMsg = "setCurrent is on the EDT but it should not be";
        IllegalStateException ex = new IllegalStateException(errMsg);
        LOG.log(Level.SEVERE, errMsg, ex);
        throw ex;
    }
    GUIHelper.invokeAndWait(new Runnable() {
        public void run() {
            setCurrentAux(dir, path, paths, profile);
        }
    }, "set current state");
}

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

/**
 * Passes the message to the contained <code>ChatConversationPanel</code>
 * for processing and appends it at the end of the conversationPanel
 * document./*from w  ww.j  av a2 s . c o m*/
 *
 * @param chatMessage the chat message to add
 */
private void addChatMessage(final ChatMessage chatMessage) {
    // We need to be sure that chat messages are added in the event dispatch
    // thread.
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                addChatMessage(chatMessage);
            }
        });
        return;
    }

    if (ConfigurationUtils.isHistoryShown() && !isHistoryLoaded) {
        synchronized (incomingEventBuffer) {
            incomingEventBuffer.add(chatMessage);
        }
    } else {
        displayChatMessage(chatMessage);
    }

    // change the last history message timestamp after we add one.
    this.lastHistoryMsgTimestamp = chatMessage.getDate();
    if (chatMessage.getMessageType().equals(Chat.OUTGOING_MESSAGE)) {
        this.lastSentMessageUID = chatMessage.getMessageUID();
    }
}

From source file:com.archivas.clienttools.arcmover.gui.panels.ProfilePanel.java

private void setCurrentAux(ArcMoverDirectory dir, String path, String[] paths, AbstractProfileBase profile) {
    if (!SwingUtilities.isEventDispatchThread()) {
        String errMsg = "setCurrentAux is not on the EDT but it should be";
        IllegalStateException ex = new IllegalStateException(errMsg);
        LOG.log(Level.SEVERE, errMsg, ex);
        throw ex;
    }/* w w  w .  j av a2 s .c  o m*/
    // if this is LFS, we want a browse option at the top
    if (getSelectedProfile() == FileSystemProfile.LOCAL_FILESYSTEM_PROFILE) {
        String[] pathsWithBrowse = new String[paths.length + 1];
        pathsWithBrowse[0] = BROWSE_LFS_TEXT;
        System.arraycopy(paths, 0, pathsWithBrowse, 1, paths.length);
        paths = pathsWithBrowse;
    }

    pathCombo.setModel(new DefaultComboBoxModel(paths));
    pathCombo.setEditable(true);
    currentDir = dir;
    pathComboActionListener.setCurrentPath(path);
    pathComboActionListener.setCurrentProfile(profile);
    profile.setDisplayPath(path);
    forceRefresh = false;
    pathCombo.setSelectedItem(path);
    pathCombo.setToolTipText(profile.decode(path));
    HCPDataMigrator.getInstance().updateLockable();
    updateRightClickMenu();
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIComponent.java

/***********************************************************************************************
 * Create or refresh the Chart on a separate thread.
 * Only create or update if asked to do so via the generate flag.
 *
 * @param dao/* w w  w.ja v  a2  s  .c o m*/
 * @param generateflag
 * @param message
 */

private synchronized void doRefreshChart(final ObservatoryInstrumentDAOInterface dao,
        final boolean generateflag, final String message) {
    //final String SOURCE = "ChartUIComponent.refreshChart() ";
    final String SOURCE = message;
    final ChartUIComponentPlugin thisUI;
    final boolean boolDebug;

    boolDebug = true;
    //        boolDebug = LOADER_PROPERTIES.isMetadataDebug()
    //                    || LOADER_PROPERTIES.isChartDebug();

    // For use in inner classes
    thisUI = this;

    // Stop any existing SwingWorker
    if ((getHostInstrument() != null) && (dao != null)) {
        LOGGER.debug(boolDebug, SOURCE + "DAO [dao.classname=" + dao.getClass().getName()
                + "] [instrument.name=" + dao.getInstrumentName() + "] [generate.flag=" + generateflag + "]");

        LOGGER.debug(boolDebug, SOURCE + "SwingWorker.controlledStop()");
    }

    SwingWorker.disposeWorker(workerRefresh, true, SWING_WORKER_STOP_DELAY >> 1);

    // Fire off another thread to process the Chart
    workerRefresh = new SwingWorker(REGISTRY.getThreadGroup(), SOURCE + "SwingWorker [group="
            + REGISTRY.getThreadGroup().getName() + "] [thread=" + getChartName() + "]") {
        public Object construct() {
            LOGGER.debug(boolDebug, SOURCE
                    + "SwingWorker START -------------------------------------------------------------------------!");

            // The result of this Thread is a JFreeChart
            // which may have been produced in a long process...
            if ((!isStopping()) && (getHostInstrument() != null)
                    && (getHostInstrument().getInstrumentState().isOn())) {
                try {
                    final JFreeChart chart;
                    final Calendar calObservatory;

                    // Either find the Current Observatory calendar, or provide a default
                    calObservatory = ObservatoryInstrumentHelper
                            .getCurrentObservatoryCalendar(REGISTRY.getFramework(), dao, boolDebug);

                    //-----------------------------------------------------------------------------
                    // Debug the data we are trying to display

                    if (boolDebug) {
                        // Dump the (partial) contents of each Series in the composite XYdataset
                        ChartHelper.dumpXYDataset(boolDebug, calObservatory, getPrimaryXYDataset(), 4, SOURCE
                                + "Original unmodified Primary XYDataset before channel or domain selection");

                        if ((getSecondaryXYDatasets() != null) && (!getSecondaryXYDatasets().isEmpty())) {
                            for (int intDatasetIndex = 0; intDatasetIndex < getSecondaryXYDatasets()
                                    .size(); intDatasetIndex++) {
                                ChartHelper.dumpXYDataset(boolDebug, calObservatory,
                                        getSecondaryXYDatasets().get(intDatasetIndex), 4,
                                        SOURCE + "Original unmodified Secondary XYDataset [" + intDatasetIndex
                                                + "] before channel or domain selection");
                            }
                        } else {
                            LOGGER.debug(boolDebug,
                                    SOURCE + "There are no SecondaryXYDatasets associated with this Chart");
                        }
                    }

                    //-----------------------------------------------------------------------------
                    // Apply a ChartUI and its Metadata to the specified DAO

                    ChartHelper.associateChartUIWithDAO(thisUI, getMetadata(), dao);

                    //-----------------------------------------------------------------------------
                    // Create a new Channel Selector showing the channels of the Primary Dataset

                    if ((getChannelSelectorOccupant() != null)
                            && (getHostInstrument().getInstrumentState().isOn()) && (dao != null)
                            && (generateflag)) {
                        LOGGER.debug(boolDebug,
                                SOURCE + "SwingWorker --> ChannelSelector --> createOrUpdateSelectors()");

                        // The Channel Selector will be empty until an XYDataset is loaded
                        // Note that ChannelCount etc. must be set before calling createOrUpdateSelectors()
                        getChannelSelectorOccupant().setChannelCount(getChannelCount());
                        getChannelSelectorOccupant().setTemperatureChannel(hasTemperatureChannel());
                        getChannelSelectorOccupant().setMetadata(getMetadata());
                        getChannelSelectorOccupant().setUpdateType(getUpdateType());

                        // Force a rebuild of the Channel Selector only if necessary
                        getChannelSelectorOccupant().createOrUpdateSelectors(getDatasetType(),
                                getPrimaryXYDataset(), getSecondaryXYDatasets(), dao.isDatasetTypeChanged(),
                                dao.isChannelCountChanged(), dao.isMetadataChanged(), dao.isRawDataChanged(),
                                dao.isProcessedDataChanged(), isRefreshable(), isClickRefresh(), boolDebug);
                    } else {
                        // This debug ASSUMES the Instrument is not NULL
                        LOGGER.debug(boolDebug, SOURCE + "Unable to configure the Channel Selector UIComponent"
                                + "  [has.channelselector=" + (hasChannelSelector())
                                + "] [channelselector.notnull=" + (getChannelSelectorOccupant() != null)
                                + "] [isselectedinstrument="
                                + ObservatoryUIHelper.isSelectedInstrument(getHostInstrument())
                                + "] [isinstrument.on=" + getHostInstrument().getInstrumentState().isOn()
                                + "] [dao.notnull=" + (dao != null) + "] [generateflag=" + generateflag + "]");
                    }

                    //-----------------------------------------------------------------------------
                    // Force a rebuild of the DatasetDomain Control only if necessary

                    if ((hasDatasetDomainControl()) && (getDatasetDomainControlOccupant() != null)
                            && (getHostInstrument().getInstrumentState().isOn()) && (dao != null)
                            && (generateflag)) {
                        LOGGER.debug(boolDebug, SOURCE
                                + "SwingWorker --> DatasetDomainControl --> createOrUpdateDomainControl()");

                        // Note that ChannelCount etc. must be set before calling createOrUpdateDomainControl()
                        getDatasetDomainControlOccupant().setRawDataChannelCount(getChannelCount());
                        getDatasetDomainControlOccupant().setTemperatureChannel(hasTemperatureChannel());
                        getDatasetDomainControlOccupant().setMetadata(getMetadata());
                        getDatasetDomainControlOccupant().setUpdateType(getUpdateType());

                        getDatasetDomainControlOccupant().createOrUpdateDomainControl(getDatasetType(),
                                getPrimaryXYDataset(), getSecondaryXYDatasets(), dao.isDatasetTypeChanged(),
                                dao.isChannelCountChanged(), dao.isMetadataChanged(), dao.isRawDataChanged(),
                                dao.isProcessedDataChanged(), isRefreshable(), isClickRefresh(), boolDebug);
                    } else {
                        // This debug ASSUMES the Instrument is not NULL
                        LOGGER.debug(boolDebug, SOURCE
                                + "Unable to configure the DatasetDomainControl UIComponent"
                                + "  [has.domaincontrol=" + (hasDatasetDomainControl())
                                + "] [domaincontrol.notnull=" + (getDatasetDomainControlOccupant() != null)
                                + "] [isselectedinstrument="
                                + ObservatoryUIHelper.isSelectedInstrument(getHostInstrument())
                                + "] [isinstrument.on=" + getHostInstrument().getInstrumentState().isOn()
                                + "] [dao.notnull=" + (dao != null) + "] [generateflag=" + generateflag + "]");
                    }

                    // Do this anyway, because it doesn't affect the UI
                    updateSliderLocalValues();

                    //-----------------------------------------------------------------------------
                    // If the Chart does not exist, create it
                    // If the Chart structure has changed, recreate it using the new configuration
                    // If only the data have changed, update the existing JFreeChart
                    // and return NULL here, to avoid redrawing

                    LOGGER.debug(boolDebug, SOURCE + "SwingWorker --> createOrUpdateChart()");

                    // Use the Observatory ResourceKey
                    setDisplayLimit(
                            REGISTRY.getIntegerProperty(getHostInstrument().getHostAtom().getResourceKey()
                                    + ResourceKeys.KEY_DISPLAY_DATA_MAX));

                    // Only create or update if asked to do so
                    // This is the last step, so can reset the DAO changed status flags
                    chart = ChartHelper.createOrUpdateChart(getHostInstrument(), thisUI, dao, generateflag,
                            getDatasetType(), getPrimaryXYDataset(), getSecondaryXYDatasets(), getUpdateType(),
                            isRefreshable(), isClickRefresh(), getDisplayLimit(), getDatasetDomainStartPoint(),
                            getDatasetDomainEndPoint(), getChannelSelectorOccupant(), boolDebug);
                    return (chart);
                }

                catch (final Exception exception) {
                    LOGGER.debug(boolDebug, SOURCE + "SwingWorker Thread GENERIC EXCEPTION");
                    exception.printStackTrace();
                    return null;
                }
            } else {
                LOGGER.debug(boolDebug,
                        SOURCE + "SwingWorker Thread stopping, or the Instrument has been turned OFF...");
                return (null);
            }
        }

        // Return a JFreeChart or NULL, depending on the outcome of createOrUpdateChart()
        // If NULL, don't affect the ChartPanel contents
        public void finished() {
            MetadataHelper.showMetadataList(getMetadata(), SOURCE + "Chart Metadata on arrival at finished()",
                    boolDebug);

            // Update the Chart on the Event Dispatching Thread
            // Check thoroughly that there is some point to this update...
            if ((workerRefresh != null) && (workerRefresh.get() != null)
                    && (workerRefresh.get() instanceof JFreeChart) && (SwingUtilities.isEventDispatchThread())
                    && (!isStopping()) && (getHostInstrument() != null)
                    && (getHostInstrument().getInstrumentState().isOn())) {
                // See if we already have a ChartPanel to hold the new JFreeChart
                if (getChartPanel() != null) {
                    LOGGER.debug(boolDebug, SOURCE
                            + "finished() Apply the JFreeChart returned by get() to exisiting ChartPanel");

                    getChartPanel().setChart((JFreeChart) workerRefresh.get());
                } else {
                    // There is NO ChartPanel, so start again from scratch
                    LOGGER.debug(boolDebug, SOURCE
                            + "finished() Create a NEW ChartPanel and apply the JFreeChart returned by get()");

                    setChartPanel(ChartPanelFactory.createChartPanel((JFreeChart) workerRefresh.get()));
                }

                // NOTE: Chart applied to the specified DAO which was passed as a parameter
                LOGGER.debug(boolDebug, SOURCE + "finished() returned JFreeChart on a ChartPanel");

                getChartContainer().removeAll();
                getChartContainer().add(getChartPanel(), BorderLayout.CENTER);
                getChartPanel().getChart().fireChartChanged();
                getChartContainer().revalidate();
            } else {
                // We failed to return a JFreeChart for some reason

                if (getPrimaryXYDataset() == null) {
                    LOGGER.debug(boolDebug, SOURCE
                            + "finished() No JFreeChart returned, Dataset is NULL, show BlankUIComponent");

                    // Getting here with a NULL dataset should mean no Chart!
                    // ChartContainer is always NOT NULL
                    getChartContainer().removeAll();
                    getChartContainer().add(
                            new BlankUIComponent(MSG_WAITING_FOR_DATA, DEFAULT_COLOUR_CANVAS, COLOUR_INFO_TEXT),
                            BorderLayout.CENTER);
                    getChartContainer().revalidate();

                    // ToDo Consider setting DAO Chart and ChartPanel Chart to NULL?
                    //SOURCE + "finished() No JFreeChart returned, Dataset is NULL, set Chart to NULL if possible");

                    //                        if (getChartPanel() != null)
                    //                            {
                    //                            getChartPanel().setChart(null);
                    //                            }
                } else {
                    // We have some data, if we also have a Chart, just display it again
                    if ((getChartPanel() != null) && (getChartPanel().getChart() != null)) {
                        LOGGER.debug(boolDebug, SOURCE
                                + "finished() No JFreeChart returned, Dataset is NOT NULL, redraw data on existing ChartPanel");

                        getChartContainer().removeAll();
                        getChartContainer().add(getChartPanel(), BorderLayout.CENTER);
                        getChartPanel().getChart().fireChartChanged();
                        getChartContainer().revalidate();
                    } else {
                        LOGGER.error(SOURCE
                                + "finished() No JFreeChart returned, Dataset is NOT NULL, but no Chart for display, no action taken");
                    }
                }
            }

            // Handle the DatasetDomainControl

            if ((getChartPanel() != null) && (hasDatasetDomainControl())
                    && (getDatasetDomainControlOccupant() != null)
                    && (getDatasetDomainControlOccupant().getDatasetDomainContainer() != null)) {
                final ChartRenderingInfo infoChart;
                final PlotRenderingInfo infoPlot;
                final Rectangle2D rectPlot;
                final Rectangle2D rectData;

                infoChart = getChartPanel().getChartRenderingInfo();
                infoPlot = infoChart.getPlotInfo();
                rectPlot = infoPlot.getPlotArea();
                rectData = infoPlot.getDataArea();

                // Trap the cases where the Plot hasn't been rendered, or there's nothing to lay out,
                // in which cases use the default sizes
                if ((rectPlot != null) && (rectData != null) && ((int) rectData.getWidth() > 0)
                        && ((int) rectData.getHeight() > 0) && ((int) rectData.getX() > 0)
                        && ((int) rectData.getY() > 0)) {
                    int intLeft;
                    int intRight;

                    // Try to get the slider to align with the extents of the data area
                    // Ideally this should happen also after WindowResizing events
                    intLeft = (int) rectData.getX();
                    intRight = (int) (getChartPanel().getWidth() - rectData.getWidth() - rectData.getX());

                    LOGGER.debug(boolDebug,
                            "DatasetDomainControl -- PANEL, PLOT & DATA AREAS" + "  [panel.width="
                                    + getChartPanel().getWidth() + "] [panel.height="
                                    + getChartPanel().getHeight() + "] [plot.width=" + rectPlot.getWidth()
                                    + "] [plot.height=" + rectPlot.getHeight() + "] [plot.x=" + rectPlot.getX()
                                    + "] [plot.y=" + rectPlot.getY() + "] [data.width=" + rectData.getWidth()
                                    + "] [data.height=" + rectData.getHeight() + "] [data.x=" + rectData.getX()
                                    + "] [data.y=" + rectData.getY() + "] [indent.left=" + intLeft
                                    + "] [indent.right=" + intRight + "]");

                    if (intLeft < 0) {
                        intLeft = 0;
                    }

                    if (intRight < 0) {
                        intRight = 0;
                    }

                    if ((intLeft + rectData.getWidth() + intRight) > getChartPanel().getWidth()) {
                        intRight = 5;
                    }

                    getDatasetDomainControlOccupant().getDatasetDomainContainer()
                            .setBorder(BorderFactory.createEmptyBorder(0, intLeft, 5, intRight));
                } else {
                    getDatasetDomainControlOccupant().getDatasetDomainContainer()
                            .setBorder(BorderFactory.createEmptyBorder(0, INDENT_LEFT, 5, INDENT_RIGHT));
                }

                // Layout the Domain slider control again
                getDatasetDomainControlOccupant().getDatasetDomainContainer().revalidate();
            }

            LOGGER.debug(boolDebug, SOURCE
                    + "SwingWorker.finished() STOP ---------------------------------------------------------------!\n");
        }
    };

    // Start the Thread we have prepared...
    workerRefresh.start();
}

From source file:com.opendoorlogistics.studio.AppFrame.java

private void onOpenedDatastore(ODLDatastoreAlterable<ODLTableAlterable> newDs, Workbook workbook, File file) {
    if (loaded != null) {
        closeDatastore();//from   ww w  . j  ava2 s.co  m
    }

    loaded = new LoadedDatastore(newDs, workbook, file, this);

    tables.setDatastore(loaded.getDs());

    // loaded.lastSaveVersionNumber = loaded.ds.getDataVersion();

    loaded.getDs().addListener(scriptManager);
    loaded.getDs().addUndoStateListener(new UndoStateChangedListener<ODLTableAlterable>() {

        @Override
        public void undoStateChanged(ODLDatastoreUndoable<ODLTableAlterable> datastoreUndoable) {
            Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    for (MyAction action : editActions) {
                        action.updateEnabled();
                    }
                }
            };

            if (SwingUtilities.isEventDispatchThread()) {
                runnable.run();
            } else {
                SwingUtilities.invokeLater(runnable);
            }
        }
    });

    updateAppearance();
    scriptManager.datastoreStructureChanged();

}

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

/**
 * Selects the given chat transport in the send via box.
 *
 * @param chatTransport The chat transport to be selected.
 * @param isMessageOrFileTransferReceived Boolean telling us if this change
 * of the chat transport correspond to an effective switch to this new
 * transform (a mesaage received from this transport, or a file transfer
 * request received, or if the resource timeouted), or just a status update
 * telling us a new chatTransport is now available (i.e. another device has
 * startup).//from  w ww.  j  a v  a2 s . c o m
 */
public void setSelectedChatTransport(final ChatTransport chatTransport,
        final boolean isMessageOrFileTransferReceived) {
    // We need to be sure that the following code is executed in the event
    // dispatch thread.
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                setSelectedChatTransport(chatTransport, isMessageOrFileTransferReceived);
            }
        });
        return;
    }

    // Check if this contact provider can manages several resources and thus
    // provides a resource timeout via the basic IM operation set.
    long timeout = -1;
    OperationSetBasicInstantMessaging opSetBasicIM = chatTransport.getProtocolProvider()
            .getOperationSet(OperationSetBasicInstantMessaging.class);
    if (opSetBasicIM != null) {
        timeout = opSetBasicIM.getInactivityTimeout();
    }

    if (isMessageOrFileTransferReceived) {
        isOutdatedResource = false;
    }

    // If this contact supports several resources, then schedule the timer:
    // - If the resource is outdated, then trigger the timer now (to try to
    // switch to the bare ID if now available).
    // - If the new reousrce transport is really effective (i.e. we have
    // received a message from this resource).
    if (timeout != -1 && (isMessageOrFileTransferReceived || isOutdatedResource)) {
        // If there was already a timeout, but the bare ID was not available
        // (i.e. a single resource present). Then call the timeout procedure
        // now in order to switch to the bare ID.
        if (isOutdatedResource) {
            timeout = 0;
        }
        // Cancels the preceding timer.
        if (outdatedResourceTimer != null) {
            outdatedResourceTimer.cancel();
            outdatedResourceTimer.purge();
        }
        // Schedules the timer.
        if (chatTransport.getResourceName() != null) {
            OutdatedResourceTimerTask task = new OutdatedResourceTimerTask();
            outdatedResourceTimer = new java.util.Timer();
            outdatedResourceTimer.schedule(task, timeout);
        }
    }

    // Sets the new resource transport is really effective (i.e. we have
    // received a message from this resource).
    // if we do not have any selected resource, or the currently selected
    // if offline
    if (transportSelectorBox != null
            && (isMessageOrFileTransferReceived || (!transportSelectorBox.hasSelectedTransport()
                    || !chatPanel.getChatSession().getCurrentChatTransport().getStatus().isOnline()))) {
        transportSelectorBox.setSelected(chatTransport);
    }
}

From source file:com.archivas.clienttools.arcmover.gui.panels.ProfilePanel.java

private void setPathAndFileListUpDirectory() {
    if (!SwingUtilities.isEventDispatchThread()) {
        String errMsg = "setPathAndFileListUpDirectory is not on the EDT but it should be";
        IllegalStateException ex = new IllegalStateException(errMsg);
        LOG.log(Level.SEVERE, errMsg, ex);
        throw ex;
    }/*  w  w w.ja v a 2  s  .  c  om*/
    try {
        ArcMoverDirectory parent = currentDir.getParent();
        if (parent != null) {
            setPathAndFileListToDirectory(parent.getPath());
        }
    } catch (Exception e1) {
        JOptionPane.showMessageDialog(this,
                "An error occurred opening directory.  See logs for more information.",
                "Error Opening Directory", JOptionPane.ERROR_MESSAGE);
        LOG.log(Level.WARNING, "An error occurred getting a directory listing: " + e1.toString(), e1);
    }
}

From source file:com.aw.swing.mvp.binding.component.BndSJTable.java

/**
 * Add a rows to the list that is shown/* w ww  .  j a v  a  2s. c o  m*/
 *
 * @param rows
 */
public void addAllRows(final List rows) {
    if (logger.isDebugEnabled()) {
        logger.debug("Adding rows to the JTable:<" + rows.size() + ">");
    }
    if (SwingUtilities.isEventDispatchThread()) {
        addAllRowsInternal(rows);
    } else {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    addAllRowsInternal(rows);
                }
            });
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

}