List of usage examples for javax.swing SwingWorker execute
public final void execute()
From source file:op.controlling.PnlControlling.java
private JPanel createContentPanel4Nursing() { JPanel pnlContent = new JPanel(new VerticalLayout()); /***//from w w w. ja v a2 s .c o m * __ __ _ * \ \ / /__ _ _ _ __ __| |___ * \ \ /\ / / _ \| | | | '_ \ / _` / __| * \ V V / (_) | |_| | | | | (_| \__ \ * \_/\_/ \___/ \__,_|_| |_|\__,_|___/ * */ JPanel pnlWounds = new JPanel(new BorderLayout()); final JButton btnWounds = GUITools.createHyperlinkButton("opde.controlling.nursing.wounds", null, null); int woundsMonthsBack; try { woundsMonthsBack = Integer.parseInt(OPDE.getProps().getProperty("opde.controlling::woundsMonthsBack")); } catch (NumberFormatException nfe) { woundsMonthsBack = 7; } final JTextField txtWoundsMonthsBack = GUITools.createIntegerTextField(1, 12, woundsMonthsBack); txtWoundsMonthsBack.setToolTipText(SYSTools.xx("misc.msg.monthsback")); btnWounds.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { SYSPropsTools.storeProp("opde.controlling::woundsMonthsBack", txtWoundsMonthsBack.getText(), OPDE.getLogin().getUser()); SYSFilesTools.print( getWounds(Integer.parseInt(txtWoundsMonthsBack.getText()), progressClosure), false); return null; } @Override protected void done() { OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); pnlWounds.add(btnWounds, BorderLayout.WEST); pnlWounds.add(txtWoundsMonthsBack, BorderLayout.EAST); pnlContent.add(pnlWounds); /*** * ____ _ _ _____ _ * / ___| ___ ___(_) __ _| | |_ _(_)_ __ ___ ___ ___ * \___ \ / _ \ / __| |/ _` | | | | | | '_ ` _ \ / _ \/ __| * ___) | (_) | (__| | (_| | | | | | | | | | | | __/\__ \ * |____/ \___/ \___|_|\__,_|_| |_| |_|_| |_| |_|\___||___/ * */ JPanel pblSocialTimes = new JPanel(new BorderLayout()); final JButton btnSocialTimes = GUITools.createHyperlinkButton("opde.controlling.nursing.social", null, null); final JComboBox cmbSocialTimes = new JComboBox( SYSCalendar.createMonthList(new LocalDate().minusYears(1), new LocalDate())); btnSocialTimes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { LocalDate month = (LocalDate) cmbSocialTimes.getSelectedItem(); SYSFilesTools.print(NReportTools.getTimes4SocialReports(month, progressClosure), false); return null; } @Override protected void done() { OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); cmbSocialTimes.setRenderer(new ListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { return new DefaultListCellRenderer().getListCellRendererComponent(list, monthFormatter.format(((LocalDate) value).toDate()), index, isSelected, cellHasFocus); } }); cmbSocialTimes.setSelectedIndex(cmbSocialTimes.getItemCount() - 2); pblSocialTimes.add(btnSocialTimes, BorderLayout.WEST); pblSocialTimes.add(cmbSocialTimes, BorderLayout.EAST); pnlContent.add(pblSocialTimes); return pnlContent; }
From source file:op.controlling.PnlControlling.java
private JPanel createContentPanel4Drugs() { JPanel pnlContent = new JPanel(new VerticalLayout()); /***//from w ww. ja va2 s . c o m * ____ ____ _ _ _ _ _ * | _ \ _ __ _ _ __ _ / ___|___ _ __ | |_ _ __ ___ | | | | (_)___| |_ * | | | | '__| | | |/ _` | | | / _ \| '_ \| __| '__/ _ \| | | | | / __| __| * | |_| | | | |_| | (_| | | |__| (_) | | | | |_| | | (_) | | | |___| \__ \ |_ * |____/|_| \__,_|\__, | \____\___/|_| |_|\__|_| \___/|_| |_____|_|___/\__| * |___/ */ JPanel pnlDrugControl = new JPanel(new BorderLayout()); final JButton btnDrugControl = GUITools.createHyperlinkButton("opde.controlling.drugs.controllist", null, null); final JComboBox cmbStation = new JComboBox(StationTools.getAll4Combobox(false)); btnDrugControl.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { return MedStockTools.getListForMedControl((Station) cmbStation.getSelectedItem(), progressClosure); } @Override protected void done() { try { SYSFilesTools.print(get().toString(), true); } catch (ExecutionException ee) { OPDE.fatal(ee); } catch (InterruptedException ie) { // nop } OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); pnlDrugControl.add(btnDrugControl, BorderLayout.WEST); pnlDrugControl.add(cmbStation, BorderLayout.EAST); pnlContent.add(pnlDrugControl); /*** * __ __ _ _ _ ____ _ _ _ _ _ _ * \ \ / /__(_) __ _| |__ | |_ / ___|___ _ __ | |_ _ __ ___ | | | \ | | __ _ _ __ ___ ___ | |_(_) ___ ___ * \ \ /\ / / _ \ |/ _` | '_ \| __| | / _ \| '_ \| __| '__/ _ \| | | \| |/ _` | '__/ __/ _ \| __| |/ __/ __| * \ V V / __/ | (_| | | | | |_| |__| (_) | | | | |_| | | (_) | | | |\ | (_| | | | (_| (_) | |_| | (__\__ \ * \_/\_/ \___|_|\__, |_| |_|\__|\____\___/|_| |_|\__|_| \___/|_| |_| \_|\__,_|_| \___\___/ \__|_|\___|___/ * |___/ */ JPanel pnlWeightControllNarcotics = new JPanel(new BorderLayout()); final JButton btnWeightControl = GUITools .createHyperlinkButton("opde.controlling.prescription.narcotics.weightcontrol", null, null); // final JComboBox cmbStation = new JComboBox(StationTools.getAll4Combobox(false)); btnWeightControl.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { return MedStockTools.getNarcoticsWeightList(new LocalDate().minusMonths(1), new LocalDate()); } @Override protected void done() { try { SYSFilesTools.print(get().toString(), true); } catch (ExecutionException ee) { OPDE.fatal(ee); } catch (InterruptedException ie) { // nop } OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); final JToggleButton btnNotify = new JToggleButton(SYSConst.icon22mailOFF); btnNotify.setSelectedIcon(SYSConst.icon22mailON); btnNotify.setSelected(NotificationTools.find(OPDE.getLogin().getUser(), NotificationTools.NKEY_DRUG_WEIGHT_CONTROL) != null); btnNotify.setToolTipText(SYSTools.xx("opde.notification.enable.for.this.topic")); btnNotify.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Users user = em.merge(OPDE.getLogin().getUser()); em.lock(user, LockModeType.OPTIMISTIC_FORCE_INCREMENT); if (e.getStateChange() == ItemEvent.SELECTED) { Notification myNotification = em .merge(new Notification(NotificationTools.NKEY_DRUG_WEIGHT_CONTROL, user)); user.getNotifications().add(myNotification); } else { Notification myNotification = em.merge(NotificationTools.find(OPDE.getLogin().getUser(), NotificationTools.NKEY_DRUG_WEIGHT_CONTROL)); user.getNotifications().remove(myNotification); em.remove(myNotification); } em.getTransaction().commit(); OPDE.getLogin().setUser(user); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception ex) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(ex); } finally { em.close(); } } }); pnlWeightControllNarcotics.add(btnWeightControl, BorderLayout.WEST); pnlWeightControllNarcotics.add(btnNotify, BorderLayout.EAST); pnlContent.add(pnlWeightControllNarcotics); return pnlContent; }
From source file:op.controlling.PnlControlling.java
private JPanel createContentPanel4Nutrition() { JPanel pnlContent = new JPanel(new VerticalLayout()); /***//from w ww .jav a2 s . co m * _ _ _ _ _ _ * | (_) __ _ _ _(_) __| | | |__ __ _| | __ _ _ __ ___ ___ * | | |/ _` | | | | |/ _` | | '_ \ / _` | |/ _` | '_ \ / __/ _ \ * | | | (_| | |_| | | (_| | | |_) | (_| | | (_| | | | | (_| __/ * |_|_|\__, |\__,_|_|\__,_| |_.__/ \__,_|_|\__,_|_| |_|\___\___| * |_| */ JPanel pnlLiquidBalance = new JPanel(new BorderLayout()); final JButton btnLiquidBalance = GUITools.createHyperlinkButton("opde.controlling.nutrition.liquidbalance", null, null); final JComboBox cmbLiquidBalanceMonth = new JComboBox( SYSCalendar.createMonthList(new LocalDate().minusYears(1), new LocalDate())); btnLiquidBalance.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { LocalDate month = (LocalDate) cmbLiquidBalanceMonth.getSelectedItem(); SYSFilesTools.print(ResValueTools.getLiquidBalance(month, progressClosure), false); return null; } @Override protected void done() { OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); cmbLiquidBalanceMonth.setRenderer(new ListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { return new DefaultListCellRenderer().getListCellRendererComponent(list, monthFormatter.format(((LocalDate) value).toDate()), index, isSelected, cellHasFocus); } }); cmbLiquidBalanceMonth.setSelectedIndex(cmbLiquidBalanceMonth.getItemCount() - 2); pnlLiquidBalance.add(btnLiquidBalance, BorderLayout.WEST); pnlLiquidBalance.add(cmbLiquidBalanceMonth, BorderLayout.EAST); pnlContent.add(pnlLiquidBalance); /*** * _ _ _ _ _ _ _ _ * __ _____(_) __ _| |__ | |_ ___| |_ __ _| |_(_)___| |_(_) ___ ___ * \ \ /\ / / _ \ |/ _` | '_ \| __| / __| __/ _` | __| / __| __| |/ __/ __| * \ V V / __/ | (_| | | | | |_ \__ \ || (_| | |_| \__ \ |_| | (__\__ \ * \_/\_/ \___|_|\__, |_| |_|\__| |___/\__\__,_|\__|_|___/\__|_|\___|___/ * |___/ */ JPanel pnlWeight = new JPanel(new BorderLayout()); final JButton btnWeightStats = GUITools.createHyperlinkButton("opde.controlling.nutrition.weightstats", null, null); int wsMonthsBack; try { wsMonthsBack = Integer.parseInt(OPDE.getProps().getProperty("opde.controlling::wsMonthsBack")); } catch (NumberFormatException nfe) { wsMonthsBack = 7; } final JTextField txtWSMonthsBack = GUITools.createIntegerTextField(1, 24, wsMonthsBack); txtWSMonthsBack.setToolTipText(SYSTools.xx("misc.msg.monthsback")); btnWeightStats.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { SYSPropsTools.storeProp("opde.controlling::wsMonthsBack", txtWSMonthsBack.getText(), OPDE.getLogin().getUser()); SYSFilesTools.print(ResValueTools.getWeightStats( Integer.parseInt(txtWSMonthsBack.getText()), progressClosure), false); return null; } @Override protected void done() { OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); pnlWeight.add(btnWeightStats, BorderLayout.WEST); pnlWeight.add(txtWSMonthsBack, BorderLayout.EAST); pnlContent.add(pnlWeight); return pnlContent; }
From source file:org.biomart.configurator.controller.MartController.java
/** * Runs the given {@link ConstructorRunnable} and monitors it's progress. * //from w ww. j ava2 s . c o m * @param constructor * the constructor that will build a mart. */ public void requestMonitorConstructorRunnable(JDialog parent, final ConstructorRunnable constructor) { final ProgressDialog progressMonitor = ProgressDialog.getInstance(parent); final SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { try { constructor.run(); } catch (final Throwable t) { SwingUtilities.invokeLater(new Runnable() { public void run() { StackTrace.showStackTrace(t); } }); } finally { progressMonitor.setVisible(false); } return null; } @Override protected void done() { progressMonitor.setVisible(false); } }; worker.execute(); progressMonitor.start("processing ..."); }
From source file:org.broad.igv.cbio.FilterGeneNetworkUI.java
private void loadcBioData(final List<String> geneLoci) { final IndefiniteProgressMonitor indefMonitor = new IndefiniteProgressMonitor(60); final ProgressBar progressBar = ProgressBar.showProgressDialog((Frame) getOwner(), "Loading cBio data...", indefMonitor, true);/*from w w w . j av a 2 s . c om*/ progressBar.setIndeterminate(true); indefMonitor.start(); final Runnable showUI = new Runnable() { @Override public void run() { initComponents(); initComponentData(); setVisible(true); } }; final Runnable runnable = new Runnable() { @Override public void run() { WaitCursorManager.CursorToken token = null; try { token = WaitCursorManager.showWaitCursor(); network = GeneNetwork.getFromCBIO(geneLoci); if (network.vertexSet().size() == 0) { MessageUtils .showMessage("No results found for " + HttpUtils.buildURLString(geneLoci, ", ")); } else { network.annotateAll(IGV.getInstance().getAllTracks()); UIUtilities.invokeOnEventThread(showUI); } } catch (Exception e) { e.printStackTrace(); log.error(e.getMessage()); MessageUtils.showMessage("Error loading data: " + e.getMessage()); } finally { WaitCursorManager.removeWaitCursor(token); if (progressBar != null) { progressBar.close(); indefMonitor.stop(); } } } }; // If we're on the dispatch thread spawn a worker, otherwise just execute. if (SwingUtilities.isEventDispatchThread()) { SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { runnable.run(); return null; } }; worker.execute(); } else { runnable.run(); } }
From source file:org.gofleet.module.routing.RoutingMap.java
@Override public void actionPerformed(final ActionEvent e) { SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { @Override/*from w w w . j a va 2s . c om*/ protected Object doInBackground() throws Exception { String mapMenuNewPlanning = i18n.getString("map.menu.new.planning"); try { if (e.getActionCommand().equals(mapMenuNewPlanning)) { LatLon from = RoutingMap.this.mapView.getLatLon( RoutingMap.this.mapView.lastMEvent.getPoint().x, RoutingMap.this.mapView.lastMEvent.getPoint().y); newPlan(from); } else { log.error( "ActionCommand desconocido: " + e.getActionCommand() + " vs " + mapMenuNewPlanning); } } catch (Throwable t) { log.error("Error al ejecutar la accion del menu contextual", t); } return null; } }; sw.execute(); }
From source file:org.hypertopic.RESTDatabase.java
/** * On _changes, the cache is cleared and the observers are notified. *///from w ww. j a v a 2 s. c o 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 . ja va 2 s. co m } 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.// www . j a v a2s . co 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.//from www .ja v a 2 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(); }