Example usage for javax.swing SwingWorker SwingWorker

List of usage examples for javax.swing SwingWorker SwingWorker

Introduction

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

Prototype

public SwingWorker() 

Source Link

Document

Constructs this SwingWorker .

Usage

From source file:org.hypertopic.RESTDatabase.java

/**
 * On _changes, the cache is cleared and the observers are notified.
 *//*from w w  w . ja va  2 s .  co  m*/
public void startListening() {
    SwingWorker w = new SwingWorker() {
        protected Object doInBackground() {
            boolean retry = true;
            while (retry) {
                try {
                    RESTDatabase.this.listen();
                } catch (JSONException e1) {
                    System.err.println("WARNING: " + RESTDatabase.this + " " + e1);
                    retry = false;
                } catch (Exception e2) {
                    System.err.println("WARNING: " + RESTDatabase.this + " " + e2);
                    try {
                        Thread.sleep(60000);
                    } catch (InterruptedException e3) {
                        System.err.println(e3); //Should not go there...
                    }
                }
            }
            return null;
        }
    };
    w.execute();
}

From source file:org.jajuk.ui.views.ParameterViewGUIHelper.java

@Override
public void actionPerformed(final ActionEvent e) {
    if (e.getSource() == pv.jbClearHistory) {
        // show confirmation message if required
        if (Conf.getBoolean(Const.CONF_CONFIRMATIONS_CLEAR_HISTORY)) {
            final int iResu = Messages.getChoice(Messages.getString("Confirmation_clear_history"),
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
            if (iResu != JOptionPane.YES_OPTION) {
                return;
            }//from  w w  w  .j a  va 2s.c om
        }
        ObservationManager.notify(new JajukEvent(JajukEvents.CLEAR_HISTORY));
    } else if (e.getSource() == pv.scbLAF) {
        // Refresh full GUI at each LAF change as a preview
        UtilGUI.setupSubstanceLookAndFeel((String) pv.scbLAF.getSelectedItem());
        UtilGUI.updateAllUIs();
    } else if (e.getSource() == pv.jbResetRatings) {
        // show confirmation message if required
        if (Conf.getBoolean(Const.CONF_CONFIRMATIONS_RESET_RATINGS)) {
            final int iResu = Messages.getChoice(Messages.getString("Confirmation_reset_ratings"),
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
            if (iResu != JOptionPane.YES_OPTION) {
                return;
            }
        }
        ObservationManager.notify(new JajukEvent(JajukEvents.RATE_RESET));
    } else if (e.getSource() == pv.jbResetPreferences) {
        // show confirmation message if required
        if (Conf.getBoolean(Const.CONF_CONFIRMATIONS_RESET_RATINGS)) {
            final int iResu = Messages.getChoice(Messages.getString("Confirmation_reset_preferences"),
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
            if (iResu != JOptionPane.YES_OPTION) {
                return;
            }
        }
        if (!DeviceManager.getInstance().isAnyDeviceRefreshing()) {
            ObservationManager.notify(new JajukEvent(JajukEvents.PREFERENCES_RESET));
        } else {
            Messages.showErrorMessage(120);
        }
    } else if (e.getSource() == pv.jbOK) {
        updateConfFromGUI();
        // Notify any client than wait for parameters updates
        final Properties details = new Properties();
        details.put(Const.DETAIL_ORIGIN, this);
        ObservationManager.notify(new JajukEvent(JajukEvents.PARAMETERS_CHANGE, details));
        if (someOptionsAppliedAtNextStartup) {
            // Inform user that some parameters will apply only at
            // next startup
            Messages.showInfoMessage(Messages.getString("ParameterView.198"));
            someOptionsAppliedAtNextStartup = false;
        }
        // Update Mute state according to bit-perfect mode
        ActionManager.getAction(JajukActions.MUTE_STATE).setEnabled(!Conf.getBoolean(Const.CONF_BIT_PERFECT));
    } else if (e.getSource() == pv.jbDefault) {
        int resu = Messages.getChoice(Messages.getString("Confirmation_defaults"),
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
        if (resu == JOptionPane.OK_OPTION) {
            Conf.setDefaultProperties();
            updateGUIFromConf();// update UI
            InformationJPanel.getInstance().setMessage(Messages.getString("ParameterView.110"),
                    InformationJPanel.MessageType.INFORMATIVE);
            updateConfFromGUI();
            Messages.showInfoMessage(Messages.getString("ParameterView.198"));
        }
    } else if (e.getSource() == pv.jcbBackup) {
        // if backup option is unchecked, reset backup size
        if (pv.jcbBackup.isSelected()) {
            pv.backupSize.setEnabled(true);
            pv.backupSize.setValue(Conf.getInt(Const.CONF_BACKUP_SIZE));
        } else {
            pv.backupSize.setEnabled(false);
            pv.backupSize.setValue(0);
        }
    } else if ((e.getSource() == pv.jcbProxyNone) || (e.getSource() == pv.jcbProxyHttp)
            || (e.getSource() == pv.jcbProxySocks)) {
        final boolean bUseProxy = !pv.jcbProxyNone.isSelected();
        pv.jtfProxyHostname.setEnabled(bUseProxy);
        pv.jtfProxyPort.setEnabled(bUseProxy);
        pv.jtfProxyLogin.setEnabled(bUseProxy);
        pv.jtfProxyPwd.setEnabled(bUseProxy);
        pv.jlProxyHostname.setEnabled(bUseProxy);
        pv.jlProxyPort.setEnabled(bUseProxy);
        pv.jlProxyLogin.setEnabled(bUseProxy);
        pv.jlProxyPwd.setEnabled(bUseProxy);
    } else if (e.getSource() == pv.jcbAutoCover) {
        if (pv.jcbAutoCover.isSelected()) {
            pv.jcbCoverSize.setEnabled(true);
            pv.jlCoverSize.setEnabled(true);
        } else {
            pv.jlCoverSize.setEnabled(false);
            pv.jcbCoverSize.setEnabled(false);
        }
    } else if (e.getSource() == pv.jcbAudioScrobbler) {
        if (pv.jcbAudioScrobbler.isSelected()) {
            pv.jlASUser.setEnabled(true);
            pv.jtfASUser.setEnabled(true);
            pv.jlASPassword.setEnabled(true);
            pv.jpfASPassword.setEnabled(true);
        } else {
            pv.jlASUser.setEnabled(false);
            pv.jtfASUser.setEnabled(false);
            pv.jlASPassword.setEnabled(false);
            pv.jpfASPassword.setEnabled(false);
        }
    } else if (e.getSource() == pv.scbLanguage) {
        Locale locale = LocaleManager.getLocaleForDesc(((JLabel) pv.scbLanguage.getSelectedItem()).getText());
        final String sLocal = locale.getLanguage();
        final String sPreviousLocal = LocaleManager.getLocale().getLanguage();
        if (!sPreviousLocal.equals(sLocal)) {
            // local has changed
            someOptionsAppliedAtNextStartup = true;
        }
    } else if (e.getSource() == pv.jcbHotkeys) {
        someOptionsAppliedAtNextStartup = true;
    } else if (e.getSource() == pv.jbCatalogRefresh) {
        new Thread("Parameter Catalog refresh Thread") {
            @Override
            public void run() {
                UtilGUI.waiting();
                // Force albums to search for new covers
                AlbumManager.getInstance().resetCoverCache();
                // Clean thumbs
                ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_50X50);
                ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_100X100);
                ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_150X150);
                ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_200X200);
                ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_250X250);
                ThumbnailManager.cleanThumbs(Const.THUMBNAIL_SIZE_300X300);
                UtilGUI.stopWaiting();
                // For catalog view's update
                ObservationManager.notify(new JajukEvent(JajukEvents.DEVICE_REFRESH));
                // Display a message
                Messages.showInfoMessage(Messages.getString("Success"));
            }
        }.start();
    }
    // Bit-perfect and audio normalization/cross fade options are mutually exclusive
    else if (e.getSource().equals(pv.jcbEnableBitPerfect)) {
        pv.jcbUseVolnorm.setEnabled(!pv.jcbEnableBitPerfect.isSelected());
        if (pv.jcbUseVolnorm.isSelected() && pv.jcbEnableBitPerfect.isSelected()) {
            pv.jcbUseVolnorm.setSelected(false);
        }
        pv.crossFadeDuration.setEnabled(!pv.jcbEnableBitPerfect.isSelected());
    } else if (e.getSource().equals(pv.jbReloadRadiosPreset)) {
        SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
            @Override
            protected Boolean doInBackground() throws Exception {
                try {
                    java.io.File fPresets = SessionService.getConfFileByPath(Const.FILE_WEB_RADIOS_PRESET);
                    DownloadManager.download(new URL(Const.URL_WEBRADIO_PRESETS), fPresets);
                    WebRadioHelper.loadPresetsRadios(fPresets);
                    return true;
                } catch (Exception ex) {
                    Log.error(ex);
                    return false;
                }
            }

            @Override
            protected void done() {
                try {
                    boolean result = get();
                    if (result) {
                        Messages.showInfoMessage(Messages.getString("Success"));
                        ObservationManager.notify(new JajukEvent(JajukEvents.DEVICE_REFRESH));
                    } else {
                        Messages.showErrorMessage(9);
                    }
                } catch (Exception e) {
                    Log.error(e);
                }
            }
        };
        worker.execute();
    }
}

From source file:org.jajuk.ui.views.SuggestionView.java

/**
 * Refresh local thumbs./*from ww  w . ja  v a 2 s  .c  o  m*/
 */
private void refreshLocalCollectionTabs() {
    // Display a busy panel in the mean-time
    // For some reasons, if we put that code into an invokeLater() call
    // it is executed after the next done() in next swing worker, no clue why
    // As a compromise, we only show busy label when called in EDT (not the case when the 
    // call is from an update() )
    if (SwingUtilities.isEventDispatchThread()) {
        busyLocal1.setBusy(true);
        busyLocal2.setBusy(true);
        busyLocal3.setBusy(true);
        // stop all existing busy labels before we add the new ones...
        //stopAllBusyLabels();
        tabs.setComponentAt(0, UtilGUI.getCentredPanel(busyLocal1));
        tabs.setComponentAt(1, UtilGUI.getCentredPanel(busyLocal2));
        tabs.setComponentAt(2, UtilGUI.getCentredPanel(busyLocal3));
    }
    SwingWorker<Void, Void> sw = new SwingWorker<Void, Void>() {
        JScrollPane jsp1;
        JScrollPane jsp2;
        JScrollPane jsp3;

        @Override
        public Void doInBackground() {
            albumsPrefered = AlbumManager.getInstance()
                    .getBestOfAlbums(Conf.getBoolean(Const.CONF_OPTIONS_HIDE_UNMOUNTED), NB_BESTOF_ALBUMS);
            albumsNewest = AlbumManager.getInstance()
                    .getNewestAlbums(Conf.getBoolean(Const.CONF_OPTIONS_HIDE_UNMOUNTED), NB_BESTOF_ALBUMS);
            albumsRare = AlbumManager.getInstance().getRarelyListenAlbums(
                    Conf.getBoolean(Const.CONF_OPTIONS_HIDE_UNMOUNTED), NB_BESTOF_ALBUMS);
            refreshThumbsForLocalAlbums();
            return null;
        }

        private void refreshThumbsForLocalAlbums() {
            // Refresh thumbs for required albums
            List<Album> albums = new ArrayList<Album>(10);
            albums.addAll(albumsPrefered);
            albums.addAll(albumsNewest);
            albums.addAll(albumsRare);
            if (albums.size() > 0) {
                for (Album album : albums) {
                    // Try creating the thumbnail
                    ThumbnailManager.refreshThumbnail(album, 100);
                }
            }
        }

        @Override
        public void done() {
            jsp1 = getLocalSuggestionsPanel(SuggestionType.BEST_OF);
            jsp2 = getLocalSuggestionsPanel(SuggestionType.NEWEST);
            jsp3 = getLocalSuggestionsPanel(SuggestionType.RARE);
            busyLocal1.setBusy(false);
            busyLocal2.setBusy(false);
            busyLocal3.setBusy(false);
            tabs.setComponentAt(0, jsp1);
            tabs.setComponentAt(1, jsp2);
            tabs.setComponentAt(2, jsp3);
        }
    };
    sw.execute();
}

From source file:org.jajuk.ui.views.SuggestionView.java

/**
 * Refresh last fm collection tabs./* ww  w .  j a  v  a2 s  .  c  o m*/
 * 
 */
private void refreshLastFMCollectionTabs() {
    String newArtist = null;
    File current = QueueModel.getPlayingFile();
    if (current != null) {
        newArtist = current.getTrack().getArtist().getName2();
    }
    // if none track playing
    if (current == null
            // Last.FM infos is disable
            || !Conf.getBoolean(Const.CONF_LASTFM_INFO)
            // None internet access option is set
            || Conf.getBoolean(Const.CONF_NETWORK_NONE_INTERNET_ACCESS)
            // If unknown artist
            || (newArtist == null || newArtist.equals(Messages.getString(UNKNOWN_ARTIST)))) {
        // Set empty panels
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                tabs.setComponentAt(3, new JLabel(Messages.getString("SuggestionView.7")));
                tabs.setComponentAt(4, new JLabel(Messages.getString("SuggestionView.7")));
            }
        });
        return;
    }
    // Check if artist changed, otherwise, just leave
    if (newArtist.equals(this.artist)) {
        return;
    }
    // Save current artist
    artist = newArtist;
    // Display a busy panel in the mean-time
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            busyLastFM1.setBusy(true);
            busyLastFM2.setBusy(true);
            tabs.setComponentAt(3, UtilGUI.getCentredPanel(busyLastFM1));
            tabs.setComponentAt(4, UtilGUI.getCentredPanel(busyLastFM2));
        }
    });
    // Use a swing worker as construct takes a lot of time
    SwingWorker<Void, Void> sw = new SwingWorker<Void, Void>() {
        JScrollPane jsp1;
        JScrollPane jsp2;

        @Override
        public Void doInBackground() {
            try {
                // Fetch last.fm calls and downloads covers
                preFetchOthersAlbum();
                preFetchSimilarArtists();
            } catch (Exception e) {
                Log.error(e);
            }
            return null;
        }

        @Override
        public void done() {
            jsp1 = getLastFMSuggestionsPanel(SuggestionType.OTHERS_ALBUMS, false);
            jsp2 = getLastFMSuggestionsPanel(SuggestionType.SIMILAR_ARTISTS, false);
            busyLastFM1.setBusy(false);
            busyLastFM2.setBusy(false);
            tabs.setComponentAt(3, jsp1);
            tabs.setComponentAt(4, jsp2);
        }
    };
    sw.execute();
}

From source file:org.jajuk.ui.widgets.JajukJMenuBar.java

/**
 * Instantiates a new jajuk j menu bar.//  w ww .j a v  a 2s.  c o  m
 */
private JajukJMenuBar() {
    setAlignmentX(0.0f);
    // File menu
    file = new JMenu(Messages.getString("JajukJMenuBar.0"));
    jmiFileExit = new JMenuItem(ActionManager.getAction(JajukActions.EXIT));
    file.add(jmiFileExit);
    // Properties menu
    properties = new JMenu(Messages.getString("JajukJMenuBar.5"));
    jmiNewProperty = new JMenuItem(ActionManager.getAction(CUSTOM_PROPERTIES_ADD));
    jmiRemoveProperty = new JMenuItem(ActionManager.getAction(CUSTOM_PROPERTIES_REMOVE));
    jmiActivateTags = new JMenuItem(ActionManager.getAction(EXTRA_TAGS_WIZARD));
    properties.add(jmiNewProperty);
    properties.add(jmiRemoveProperty);
    properties.add(jmiActivateTags);
    // View menu
    views = new JMenu(Messages.getString("JajukJMenuBar.8"));
    jmiRestoreDefaultViews = new JMenuItem(ActionManager.getAction(VIEW_RESTORE_DEFAULTS));
    jmiRestoreDefaultViewsAllPerpsectives = new JMenuItem(
            ActionManager.getAction(JajukActions.ALL_VIEW_RESTORE_DEFAULTS));
    views.add(jmiRestoreDefaultViews);
    views.add(jmiRestoreDefaultViewsAllPerpsectives);
    views.addSeparator();
    // Add the list of available views parsed in XML files at startup
    JMenu jmViews = new JMenu(Messages.getString("JajukJMenuBar.25"));
    for (final Class<? extends IView> view : ViewFactory.getKnownViews()) {
        JMenuItem jmi = null;
        try {
            jmi = new JMenuItem(view.newInstance().getDesc(), IconLoader.getIcon(JajukIcons.LOGO_FRAME));
        } catch (Exception e1) {
            Log.error(e1);
            continue;
        }
        jmi.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // Simply add the new view in the current perspective
                PerspectiveAdapter current = (PerspectiveAdapter) PerspectiveManager.getCurrentPerspective();
                IView newView = ViewFactory.createView(view, current,
                        Math.abs(UtilSystem.getRandom().nextInt()));
                newView.initUI();
                newView.setPopulated();
                current.addDockable(newView);
            }
        });
        jmViews.add(jmi);
    }
    views.add(jmViews);
    // Mode menu
    String modeText = Messages.getString("JajukJMenuBar.9");
    mode = new JMenu(ActionUtil.strip(modeText));
    jcbmiRepeat = new JCheckBoxMenuItem(ActionManager.getAction(REPEAT_MODE));
    jcbmiRepeat.setSelected(Conf.getBoolean(Const.CONF_STATE_REPEAT));
    jcbmiRepeatAll = new JCheckBoxMenuItem(ActionManager.getAction(REPEAT_ALL_MODE));
    jcbmiRepeatAll.setSelected(Conf.getBoolean(Const.CONF_STATE_REPEAT_ALL));
    jcbmiShuffle = new JCheckBoxMenuItem(ActionManager.getAction(SHUFFLE_MODE));
    jcbmiShuffle.setSelected(Conf.getBoolean(Const.CONF_STATE_SHUFFLE));
    jcbmiContinue = new JCheckBoxMenuItem(ActionManager.getAction(CONTINUE_MODE));
    jcbmiContinue.setSelected(Conf.getBoolean(Const.CONF_STATE_CONTINUE));
    jcbmiIntro = new JCheckBoxMenuItem(ActionManager.getAction(INTRO_MODE));
    jcbmiIntro.setSelected(Conf.getBoolean(Const.CONF_STATE_INTRO));
    jcbmiKaraoke = new JCheckBoxMenuItem(ActionManager.getAction(JajukActions.KARAOKE_MODE));
    if (Conf.getBoolean(Const.CONF_BIT_PERFECT)) {
        jcbmiKaraoke.setEnabled(false);
        jcbmiKaraoke.setSelected(false);
        Conf.setProperty(Const.CONF_STATE_KARAOKE, Const.FALSE);
    } else {
        jcbmiKaraoke.setSelected(Conf.getBoolean(Const.CONF_STATE_KARAOKE));
    }
    mode.add(jcbmiRepeat);
    mode.add(jcbmiRepeatAll);
    mode.add(jcbmiShuffle);
    mode.add(jcbmiContinue);
    mode.add(jcbmiIntro);
    mode.add(jcbmiKaraoke);
    // Smart Menu
    smart = new JMenu(Messages.getString("JajukJMenuBar.29"));
    jmiShuffle = new SizedJMenuItem(ActionManager.getAction(JajukActions.SHUFFLE_GLOBAL));
    jmiBestof = new SizedJMenuItem(ActionManager.getAction(JajukActions.BEST_OF));
    jmiNovelties = new SizedJMenuItem(ActionManager.getAction(JajukActions.NOVELTIES));
    jmiFinishAlbum = new SizedJMenuItem(ActionManager.getAction(JajukActions.FINISH_ALBUM));
    smart.add(jmiShuffle);
    smart.add(jmiBestof);
    smart.add(jmiNovelties);
    smart.add(jmiFinishAlbum);
    // Tools Menu
    tools = new JMenu(Messages.getString("JajukJMenuBar.28"));
    jmiduplicateFinder = new JMenuItem(ActionManager.getAction(JajukActions.FIND_DUPLICATE_FILES));
    jmialarmClock = new JMenuItem(ActionManager.getAction(JajukActions.ALARM_CLOCK));
    jmiprepareParty = new JMenuItem(ActionManager.getAction(JajukActions.PREPARE_PARTY));
    tools.add(jmiduplicateFinder);
    tools.add(jmialarmClock);
    tools.add(jmiprepareParty);
    // tools.addSeparator();
    // Configuration menu
    configuration = new JMenu(Messages.getString("JajukJMenuBar.21"));
    jmiDJ = new JMenuItem(ActionManager.getAction(CONFIGURE_DJS));
    // Overwrite default icon
    jmiDJ.setIcon(IconLoader.getIcon(JajukIcons.DIGITAL_DJ_16X16));
    jmiAmbience = new JMenuItem(ActionManager.getAction(CONFIGURE_AMBIENCES));
    jmiWizard = new JMenuItem(ActionManager.getAction(SIMPLE_DEVICE_WIZARD));
    jmiOptions = new JMenuItem(ActionManager.getAction(OPTIONS));
    jmiUnmounted = new JCheckBoxMenuItem(ActionManager.getAction(JajukActions.UNMOUNTED));
    jmiUnmounted.setSelected(Conf.getBoolean(Const.CONF_OPTIONS_HIDE_UNMOUNTED));
    jmiUnmounted.putClientProperty(Const.DETAIL_ORIGIN, jmiUnmounted);
    jcbShowPopups = new JCheckBoxMenuItem(Messages.getString("ParameterView.228"));
    jcbShowPopups.setSelected(Conf.getBoolean(Const.CONF_SHOW_POPUPS));
    jcbShowPopups.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Conf.setProperty(Const.CONF_SHOW_POPUPS, Boolean.toString(jcbShowPopups.isSelected()));
            // force parameter view to take this into account
            ObservationManager.notify(new JajukEvent(JajukEvents.PARAMETERS_CHANGE));
        }
    });
    jcbNoneInternetAccess = new JCheckBoxMenuItem(Messages.getString("ParameterView.264"));
    jcbNoneInternetAccess.setToolTipText(Messages.getString("ParameterView.265"));
    jcbNoneInternetAccess.setSelected(Conf.getBoolean(Const.CONF_NETWORK_NONE_INTERNET_ACCESS));
    jcbNoneInternetAccess.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Conf.setProperty(Const.CONF_NETWORK_NONE_INTERNET_ACCESS,
                    Boolean.toString(jcbNoneInternetAccess.isSelected()));
            // force parameter view to take this into account
            ObservationManager.notify(new JajukEvent(JajukEvents.PARAMETERS_CHANGE));
        }
    });
    configuration.add(jmiUnmounted);
    configuration.add(jcbShowPopups);
    configuration.add(jcbNoneInternetAccess);
    configuration.addSeparator();
    configuration.add(jmiDJ);
    configuration.add(jmiAmbience);
    configuration.add(jmiWizard);
    configuration.add(jmiOptions);
    // Help menu
    String helpText = Messages.getString("JajukJMenuBar.14");
    help = new JMenu(ActionUtil.strip(helpText));
    jmiHelp = new JMenuItem(ActionManager.getAction(HELP_REQUIRED));
    jmiDonate = new JMenuItem(ActionManager.getAction(SHOW_DONATE));
    jmiAbout = new JMenuItem(ActionManager.getAction(SHOW_ABOUT));
    jmiTraces = new JMenuItem(ActionManager.getAction(SHOW_TRACES));
    jmiTraces = new JMenuItem(ActionManager.getAction(SHOW_TRACES));
    jmiCheckforUpdates = new JMenuItem(ActionManager.getAction(JajukActions.CHECK_FOR_UPDATES));
    jmiTipOfTheDay = new JMenuItem(ActionManager.getAction(TIP_OF_THE_DAY));
    help.add(jmiHelp);
    help.add(jmiTipOfTheDay);
    // Install this action only if Desktop class is supported, it is used to
    // open default mail client
    if (UtilSystem.isBrowserSupported()) {
        jmiQualityAgent = new JMenuItem(ActionManager.getAction(QUALITY));
        help.add(jmiQualityAgent);
    }
    help.add(jmiTraces);
    help.add(jmiCheckforUpdates);
    help.add(jmiDonate);
    help.add(jmiAbout);
    mainmenu = new JMenuBar();
    mainmenu.add(file);
    mainmenu.add(views);
    mainmenu.add(properties);
    mainmenu.add(mode);
    mainmenu.add(smart);
    mainmenu.add(tools);
    mainmenu.add(configuration);
    mainmenu.add(help);
    // Apply mnemonics (Alt + first char of the menu keystroke)
    applyMnemonics();
    if (SessionService.isTestMode()) {
        jbGC = new JajukButton(ActionManager.getAction(JajukActions.GC));
    }
    jbSlim = new JajukButton(ActionManager.getAction(JajukActions.SLIM_JAJUK));
    jbFull = new JajukButton(ActionManager.getAction(JajukActions.FULLSCREEN_JAJUK));
    JMenuBar eastmenu = new JMenuBar();
    // only show GC-button in test-mode
    if (SessionService.isTestMode()) {
        eastmenu.add(jbGC);
    }
    eastmenu.add(jbSlim);
    eastmenu.add(jbFull);
    setLayout(new BorderLayout());
    add(mainmenu, BorderLayout.WEST);
    add(eastmenu, BorderLayout.EAST);
    // Check for new release and display the icon if a new release is available
    SwingWorker<Void, Void> sw = new SwingWorker<Void, Void>() {
        @Override
        public Void doInBackground() {
            UpgradeManager.checkForUpdate();
            return null;
        }

        @Override
        public void done() {
            // add the new release label if required
            if (UpgradeManager.getNewVersionName() != null) {
                jlUpdate = new JLabel(" ", IconLoader.getIcon(JajukIcons.UPDATE_MANAGER), SwingConstants.RIGHT);
                String newRelease = UpgradeManager.getNewVersionName();
                if (newRelease != null) {
                    jlUpdate.setToolTipText(Messages.getString("UpdateManager.0") + newRelease
                            + Messages.getString("UpdateManager.1"));
                }
                add(Box.createHorizontalGlue());
                add(jlUpdate);
            }
        }
    };
    // Search online for upgrade if the option is set and if the none Internet
    // access option is not set
    if (Conf.getBoolean(Const.CONF_CHECK_FOR_UPDATE)
            && !Conf.getBoolean(Const.CONF_NETWORK_NONE_INTERNET_ACCESS)) {
        sw.execute();
    }
    ObservationManager.register(this);
}

From source file:org.kepler.gui.AuthenticateAction.java

protected void doAction() {
    log.debug("starting domain prompt worker");
    SwingWorker domainWorker = new SwingWorker<Void, Void>() {
        /**/* www  .java 2s. c om*/
         * Collect the domain, which will then prompt for username/password.
         */
        public Void doInBackground() {
            // Display the prompt window.
            promptForDomain();
            // Check if we get a selected domain.
            if (waitForDomain()) {
                // Try the authentication.
                fireAuthentication();
            }
            cancel(true);
            return null;
        }
    };

    domainWorker.execute();
}

From source file:org.kepler.gui.AuthenticateAction.java

protected void fireAuthentication() {
    log.debug("starting to authenticate with domain=" + this.domainName);
    SwingWorker authWorker = new SwingWorker<Void, Void>() {

        // Display the login window.
        public Void doInBackground() {
            login();/*from ww  w. j  ava2  s. c  om*/
            cancel(true);
            return null;
        }
    };

    authWorker.execute();
}

From source file:org.kuali.test.ui.components.dialogs.ImportPlatformTestsDlg.java

@Override
protected boolean save() {
    new SwingWorker() {
        @Override/*from   w  w  w  .  j  a va 2s.  co m*/
        protected Object doInBackground() throws Exception {
            return importTests();
        }

        @Override
        protected void done() {
            try {
                Boolean b = (Boolean) get();
                setSaved(b);

                if (b) {
                    dispose();
                }
            } catch (Exception ex) {
                LOG.warn(ex.toString(), ex);
            }
        }

    }.execute();

    return false;
}

From source file:org.kuali.test.ui.components.panels.WebTestPanel.java

@Override
protected void handleStartTest() {
    getMainframe().startSpinner("Initializing browser interface...");

    new SwingWorker() {
        @Override/*from  w  w w . j a v a  2  s .  c om*/
        protected Object doInBackground() throws Exception {
            testProxyServer = new TestProxyServer(WebTestPanel.this);
            addNewBrowserPanel(true);
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    getCurrentBrowser().navigate(getPlatform().getWebUrl());
                }
            });
            return null;
        }

        ;

        @Override
        protected void done() {
            getMainframe().stopSpinner();
        }
    }.execute();

    getMainframe().getCreateTestButton().setEnabled(false);
    getMainframe().getCreateTestMenuItem().setEnabled(false);
}

From source file:org.kuali.test.ui.components.panels.WebTestPanel.java

/**
 *
 * @return/*w w w.  j a  v a  2 s  . co  m*/
 */
@Override
protected boolean handleSaveTest() {
    boolean retval = false;

    new SwingWorker() {
        @Override
        protected Object doInBackground() throws Exception {
            Boolean retval = false;
            getMainframe().startSpinner("Saving test...");

            if (moveAttachmentFiles(testProxyServer.getTestOperations())) {
                retval = saveTest(getMainframe().getConfiguration().getRepositoryLocation(), getTestHeader(),
                        testProxyServer.getTestOperations());
            }

            return retval;
        }

        @Override
        protected void done() {
            Boolean b = false;
            try {
                b = (Boolean) get();
            }

            catch (Exception ex) {
            }
            ;

            if (b) {
                getMainframe().getTestRepositoryTree().saveConfiguration();
                getMainframe().getCreateTestPanel()
                        .clearPanel("test '" + getTestHeader().getTestName() + "' created");
            }
            closeProxyServer();
            getMainframe().getPlatformTestsPanel().populateList(getPlatform());
            getMainframe().stopSpinner();
        }

    }.execute();

    return retval;
}