List of usage examples for javax.swing SwingWorker execute
public final void execute()
From source file:org.jajuk.ui.widgets.JajukJMenuBar.java
/** * Instantiates a new jajuk j menu bar.// w ww.j a v a 2 s . co 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>() { /**//from ww w .j a v a 2 s . c o m * 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 w ww . j a v a 2s. c o m cancel(true); return null; } }; authWorker.execute(); }
From source file:org.n52.ifgicopter.spf.gui.SPFMainFrame.java
protected void shutdownFrame(final int returnCode) { SwingWorker<String, Object> worker = new SwingWorker<String, Object>() { @Override/*from ww w . ja v a2 s .c o m*/ protected String doInBackground() throws Exception { SPFMainFrame.this.statusLabel.setText("SPFramework shutting down... this could take a while."); ShutdownDialog dialog = new ShutdownDialog(SPFMainFrame.this); new Thread(dialog).start(); try { SPFRegistry.getInstance().shutdownSystem(); } catch (Exception e1) { SPFMainFrame.this.log.warn(e1.getMessage(), e1); //check if we have a restart returnCode, then do not error if (returnCode == 0) System.exit(1); } finally { System.exit(returnCode); } return null; } }; worker.execute(); }
From source file:org.orbisgis.dbjobs.service.DriverFunctionContainerImpl.java
private void executeJob(SwingWorker worker) { if (executorService == null) { worker.execute(); } else {/*from ww w .ja va 2s .c om*/ executorService.execute(worker); } }
From source file:org.orbisgis.groovy.GroovyConsolePanel.java
private void execute(SwingWorker swingWorker) { if (executorService != null) { executorService.execute(swingWorker); } else {/*from ww w . java 2 s . c o m*/ swingWorker.execute(); } }
From source file:org.photovault.swingui.FindAddressAction.java
public void actionPerformed(ActionEvent e) { final String geoHashStr = (String) ctrl.getFieldController("shotLocation.geoHashString").getValue(); SwingWorker<Location, Object> w = new SwingWorker<Location, Object>() { @Override//w w w . j av a 2 s.c om protected Location doInBackground() throws Exception { return geocoder.findByGeoHash(geoHashStr); } @Override protected void done() { try { updateAddress(get()); } catch (Exception ignore) { } } }; w.execute(); }
From source file:org.pmedv.blackboard.commands.OpenBoardCommand.java
@Override public void execute(ActionEvent e) { final ApplicationWindow win = ctx.getBean(ApplicationWindow.class); // No file selected before, popup a dialog and query the user which file to open. if (file == null) { String path = System.getProperty("user.home"); if (AppContext.getLastSelectedFolder() != null) { path = AppContext.getLastSelectedFolder(); }/*w ww. j av a 2 s . c o m*/ JFileChooser fc = new JFileChooser(path); fc.setDialogTitle(resources.getResourceByKey("OpenBoardCommand.name")); fc.setFileFilter(new FefaultFileFilter()); int result = fc.showOpenDialog(win); if (result == JFileChooser.APPROVE_OPTION) { if (fc.getSelectedFile() == null) return; file = fc.getSelectedFile(); AppContext.setLastSelectedFolder(file.getParentFile().getAbsolutePath()); } else { return; } } final JWindow topWindow = new JWindow(); topWindow.setSize(390, 50); topWindow.setLayout(new BorderLayout()); topWindow.setBackground(Color.WHITE); final JPanel content = new JPanel(new BorderLayout()); content.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK), BorderFactory.createEmptyBorder(10, 10, 10, 10))); content.setBackground(Color.WHITE); final JLabel infoLabel = new JLabel( resources.getResourceByKey("OpenBoardCommand.waitMsg") + " " + file.getName()); infoLabel.setVerticalAlignment(SwingConstants.CENTER); content.add(infoLabel, BorderLayout.SOUTH); final JBusyComponent<JPanel> busyPanel = new JBusyComponent<JPanel>(content); busyPanel.setBusy(true); topWindow.getContentPane().add(busyPanel, BorderLayout.CENTER); topWindow.setLocationRelativeTo(null); topWindow.add(busyPanel, BorderLayout.CENTER); final SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() { @Override protected Boolean doInBackground() { topWindow.setVisible(true); doOpen(); return Boolean.valueOf(true); } @Override protected void done() { topWindow.setVisible(false); topWindow.dispose(); for (Runnable r : postConfigurators) { SwingUtilities.invokeLater(r); } } }; worker.execute(); }
From source file:org.pmedv.blackboard.components.PartView.java
protected void initializeComponents() { setLayout(new BorderLayout()); partPanel = new PartPanel(); partBusyPanel = new JBusyComponent<PartPanel>(partPanel); setSize(new Dimension(900, 650)); textArea = new RSyntaxTextArea(); textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML); RTextScrollPane textScrollPane = new RTextScrollPane(textArea); CompletionProvider provider = createCompletionProvider(); AutoCompletion ac = new AutoCompletion(provider); ac.install(textArea);//from w w w . ja v a 2 s . c o m JPopupMenu popup = textArea.getPopupMenu(); popup.addSeparator(); popup.add(new JMenuItem(new SaveAction())); tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM); tabbedPane.addTab("Parts", partBusyPanel); tabbedPane.addTab("Part Editor", textScrollPane); tabbedPane.setEnabledAt(1, false); add(tabbedPane, BorderLayout.CENTER); tablePopupMenu = new JPopupMenu(); // We do the part loading in background and display a busy panel while loading SwingWorker<ArrayList<Part>, Void> w = new SwingWorker<ArrayList<Part>, Void>() { @Override protected ArrayList<Part> doInBackground() { partBusyPanel.setBusy(true); try { return AppContext.getContext().getBean(PartFactory.class).getAvailableParts(); } catch (Exception e) { ErrorUtils.showErrorDialog(e); return new ArrayList<Part>(); } } @Override protected void done() { log.info("Done loading parts."); try { model = new PartTableModel(get()); partPanel.getPartTable().setModel(model); } catch (Exception e) { ErrorUtils.showErrorDialog(e); } partBusyPanel.setBusy(false); partPanel.transferFocus(); } }; partPanel.getPartTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { JXTable table = partPanel.getPartTable(); int[] rows = table.getSelectedRows(); if (rows.length == 1) { if (model == null) return; Part selectedPart = model.getParts().get(table.convertRowIndexToModel(rows[0])); currentPart = selectedPart; selectedRow = table.convertRowIndexToModel(rows[0]); partPanel.getImageLabel().setIcon(new ImageIcon(selectedPart.getImage())); partPanel.getImageLabel().setText(null); partPanel.getPartNameField().setText(selectedPart.getName()); partPanel.getDescriptionPane().setText(selectedPart.getDescription()); partPanel.getPackageTypeField().setText(selectedPart.getPackageType()); partPanel.getAuthorField().setText(selectedPart.getAuthor()); partPanel.getLicenseField().setText(selectedPart.getLicense()); tabbedPane.setEnabledAt(1, true); textArea.setText(selectedPart.getXmlContent()); } else { currentPart = null; partPanel.getImageLabel().setText(resources.getResourceByKey("PartDialog.selectmsg")); partPanel.getImageLabel().setIcon(null); tabbedPane.setEnabledAt(1, false); textArea.setText(""); } } }); partPanel.getPartTable().addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { handlePopupTrigger(e); } @Override public void mouseReleased(MouseEvent e) { handlePopupTrigger(e); } }); tablePopupMenu.add(AppContext.getContext().getBean(DeletePartCommand.class)); // this is the filter configuration for the filter text box on the top PartFilter filter = new PartFilter(partPanel.getPartTable()); BindingGroup filterGroup = new BindingGroup(); // bind filter JTextBox's text attribute to part tables filterString // attribute filterGroup.addBinding(Bindings.createAutoBinding(READ, partPanel.getFilterPanel().getFilterTextField(), BeanProperty.create("text"), filter, BeanProperty.create("filterString"))); filterGroup.bind(); w.execute(); }
From source file:org.pmedv.blackboard.dialogs.DatasheetDialog.java
@Override protected void initializeComponents() { sheetProvider = AppContext.getContext().getBean(DataSheetProvider.class); sheetPanel = new DatasheetPanel(); busyPanel = new JBusyComponent<DatasheetPanel>(sheetPanel); setSize(new Dimension(900, 650)); getContentPanel().add(busyPanel);// w ww .j a v a 2 s. com SwingWorker<ArrayList<DatasheetBean>, Void> w = new SwingWorker<ArrayList<DatasheetBean>, Void>() { @Override protected ArrayList<DatasheetBean> doInBackground() throws Exception { busyPanel.setBusy(true); sheetProvider.loadSheets(); return sheetProvider.getDatasheetList().getDatasheets(); } @Override protected void done() { log.info("Done loading sheets."); try { model = new DataSheetTableModel(get()); sheetPanel.getDatasheetTable().setModel(model); } catch (Exception e) { e.printStackTrace(); } busyPanel.setBusy(false); sheetPanel.transferFocus(); } }; getOkButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); getCancelButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { result = OPTION_CANCEL; setVisible(false); } }); sheetPanel.getDatasheetTable().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int modelIndex = sheetPanel.getDatasheetTable() .convertRowIndexToModel(sheetPanel.getDatasheetTable().getSelectedRow()); DatasheetBean sheet = model.getDatasheetBeans().get(modelIndex); if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); try { desktop.open(new File(sheet.getLocation())); } catch (Exception e1) { ErrorUtils.showErrorDialog(e1); } } } } }); sheetPanel.getAddSheetButton().setAction(AppContext.getContext().getBean(AddDatasheetCommand.class)); sheetPanel.getRemoveSheetButton().setAction(AppContext.getContext().getBean(RemoveDatasheetCommand.class)); sheetPanel.getImportFolderButton() .setAction(AppContext.getContext().getBean(ImportDatasheetFolderCommand.class)); // create filter for sheets DataSheetFilter filter = new DataSheetFilter(sheetPanel.getDatasheetTable()); BindingGroup filterGroup = new BindingGroup(); // bind filter JTextBox's text attribute to part tables filterString attribute filterGroup.addBinding(Bindings.createAutoBinding(READ, sheetPanel.getFilterPanel().getFilterTextField(), BeanProperty.create("text"), filter, BeanProperty.create("filterString"))); filterGroup.bind(); w.execute(); }