List of usage examples for java.awt EventQueue invokeLater
public static void invokeLater(Runnable runnable)
From source file:org.zaproxy.zap.model.Context.java
public void restructureSiteTree() { if (EventQueue.isDispatchThread()) { restructureSiteTreeEventHandler(); } else {//w w w . j a va 2 s . co m try { EventQueue.invokeLater(new Runnable() { @Override public void run() { restructureSiteTreeEventHandler(); } }); } catch (Exception e) { log.error(e.getMessage(), e); } } }
From source file:eu.delving.sip.Application.java
private static void memoryNotConfigured() { String os = System.getProperty("os.name"); Runtime rt = Runtime.getRuntime(); int totalMemory = (int) (rt.totalMemory() / 1024 / 1024); StringBuilder out = new StringBuilder(); String JAR_NAME = "SIP-Creator-2014-XX-XX.jar"; if (os.startsWith("Windows")) { out.append(":: SIP-Creator Startup Batch file for Windows (more memory than ").append(totalMemory) .append("Mb)\n"); out.append("java -jar -Xms1024m -Xmx1024m ").append(JAR_NAME); } else if (os.startsWith("Mac")) { out.append("# SIP-Creator Startup Script for Mac OSX (more memory than ").append(totalMemory) .append("Mb)\n"); out.append("java -jar -Xms1024m -Xmx1024m ").append(JAR_NAME); } else {// www.j a v a 2 s .c om System.out.println("Unrecognized OS: " + os); } String script = out.toString(); final JDialog dialog = new JDialog(null, "Memory Not Configured Yet!", Dialog.ModalityType.APPLICATION_MODAL); JTextArea scriptArea = new JTextArea(3, 40); scriptArea.setText(script); scriptArea.setSelectionStart(0); scriptArea.setSelectionEnd(script.length()); JPanel scriptPanel = new JPanel(new BorderLayout()); scriptPanel.setBorder(BorderFactory.createTitledBorder("Script File")); scriptPanel.add(scriptArea, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)); JButton ok = new JButton("OK, Continue anyway"); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.setVisible(false); EventQueue.invokeLater(LAUNCH); } }); buttonPanel.add(ok); JPanel centralPanel = new JPanel(new GridLayout(0, 1)); centralPanel.setBorder(BorderFactory.createEmptyBorder(15, 25, 15, 25)); centralPanel.add( new JLabel("<html><b>The SIP-Creator started directly can have too little default memory allocated." + "<br>It should be started with the following script:</b>")); centralPanel.add(scriptPanel); centralPanel.add(new JLabel( "<html><b>Please copy the above text into a batch or script file and execute that instead.</b>")); dialog.getContentPane().add(centralPanel, BorderLayout.CENTER); dialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH); dialog.pack(); Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - dialog.getWidth()) / 2); int y = (int) ((dimension.getHeight() - dialog.getHeight()) / 2); dialog.setLocation(x, y); dialog.setVisible(true); }
From source file:org.n52.ifgicopter.spf.output.GpxOutputPlugin.java
/** * /*from w w w . j av a2 s. com*/ * @return */ private JPanel makeGUI() { if (this.panel == null) { this.panel = new JPanel(new BorderLayout()); JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); JButton selectFileButton = new JButton(SELECT_GPX_FILE_TEXT); selectFileButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectGpxFileAction(); } }); controlPanel.add(selectFileButton); this.outputFileLabel = new JLabel(); controlPanel.add(this.outputFileLabel); JButton saveFileButton = new JButton(SAVE_CURRENT_FILE_TEXT); saveFileButton.setToolTipText("Does also save manual changes undless model changes were made."); saveFileButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveCurrentFile(); } }); controlPanel.add(saveFileButton); // JCheckBox scrollLockCheckBox = new JCheckBox("scroll lock"); // scrollLockCheckBox.setSelected(true); // scrollLockCheckBox.addActionListener(new ActionListener() { // @Override // public void actionPerformed(final ActionEvent e) { // EventQueue.invokeLater(new Runnable() { // // @Override // public void run() { // JCheckBox source = (JCheckBox) e.getSource(); // // GpxOutputPlugin.this.textPane.setAutoscrolls(source.isSelected()); // } // }); // } // }); // controlPanel.add(scrollLockCheckBox); this.panel.add(controlPanel, BorderLayout.NORTH); JPanel valuesPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT)); DefaultListModel listModel = new DefaultListModel(); listModel.addElement(NO_DATA_LIST_ELEMENT); this.valuesToSaveList = new JList(listModel); this.valuesToSaveList.setVisibleRowCount(2); this.valuesToSaveList .setToolTipText("Select (multiple) values to include in the GPX file [Multiple using <Ctrl>]."); this.valuesToSaveList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { JList list = (JList) e.getSource(); // DefaultListModel listModel = (DefaultListModel) list.getModel(); Object[] selectedValues = list.getSelectedValues(); log.debug("New selection in value list:" + Arrays.toString(selectedValues)); GpxOutputPlugin.this.valuesToSave.clear(); for (Object o : selectedValues) { if (o instanceof String) { String s = (String) o; if (!GpxOutputPlugin.this.valuesToSave.contains(s)) GpxOutputPlugin.this.valuesToSave.add(s); } } } }); } }); this.valuesToSaveList.setSize(200, 22); this.valuesToSaveList.setAlignmentY(Component.CENTER_ALIGNMENT); valuesPanel.add(new JLabel("Saved attributes:")); valuesPanel.add(this.valuesToSaveList); valuesPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); this.panel.add(valuesPanel, BorderLayout.EAST); this.textPane = new XmlTextPane(); this.textPane.setEditable(true); this.textPane.setFont(Font.getFont(Font.MONOSPACED)); JScrollPane scrollPane = new JScrollPane(this.textPane); this.panel.add(scrollPane, BorderLayout.CENTER); JButton refreshTextFieldButton = new JButton("Update"); refreshTextFieldButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { updateGUI(); } }); } }); this.panel.add(refreshTextFieldButton, BorderLayout.SOUTH); updateGUI(); } return this.panel; }
From source file:org.pentaho.ui.xul.swing.tags.SwingDialog.java
public void invokeLater(Runnable runnable) { EventQueue.invokeLater(runnable); }
From source file:org.n52.ifgicopter.spf.input.GpxInputPlugin.java
/** * /*from w ww .ja v a2 s . c o m*/ */ protected void selectGpxFileAction() { EventQueue.invokeLater(new Runnable() { @Override public void run() { JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Select GPX File"); fc.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.getName().toLowerCase().endsWith("gpx") || f.getName().toLowerCase().endsWith("xml")) return true; if (f.isDirectory()) return true; return false; } @Override public String getDescription() { return "GPX file"; } }); File gpxfile = new File(getGpxFilePath()); if (gpxfile.isFile()) { fc.setCurrentDirectory(gpxfile.getParentFile()); } int returnVal = fc.showOpenDialog(getUserInterface().getGui()); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); setGpxFilePath(file.getAbsolutePath()); } else { getLog().debug("Open command cancelled by user."); } fc = null; } }); }
From source file:org.nuclos.client.common.Utils.java
/** * sets the input focus to a certain collectable component in a LayoutML mask. * @param sFocusFieldName field name of the component that is to receive to focus. * @param clctcompprovider map of all collectable components in the layout * @param frame frame of the layout (for possible warning dialogs only) * @param bShowWarnings displays warnings for components not found for focussing * @precondition eafnInitialFocus != null *//*www . jav a2s.co m*/ public static void setComponentFocus(final String sFocusFieldName, final CollectableComponentsProvider clctcompprovider, final MainFrameTab frame, final boolean bShowWarnings) { // Must be invoked later, else focus is not set with compound components like LOVs EventQueue.invokeLater(new Runnable() { @Override public void run() { try { if (sFocusFieldName != null) { final Collection<CollectableComponent> collclctcomp = clctcompprovider .getCollectableComponentsFor(sFocusFieldName); if (collclctcomp.isEmpty()) { if (bShowWarnings) { final String sMessage = SpringLocaleDelegate.getInstance().getMessage( "ClientUtils.1", "Das angegebene Feld f\u00fcr den initialen Fokus existiert nicht."); JOptionPane.showMessageDialog(frame, sMessage, SpringLocaleDelegate.getInstance().getMessage("ClientUtils.2", "Hinweis"), JOptionPane.WARNING_MESSAGE); } } else { final CollectableComponent clctcomp = collclctcomp.iterator().next(); final JComponent compFocus = clctcomp.getFocusableComponent(); compFocus.requestFocusInWindow(); } } } catch (Exception e) { LOG.error("setComponentFocus failed: " + e, e); } } }); }
From source file:fur.shadowdrake.minecraft.InstallPanel.java
public void begin(boolean first) { workingDir = dirBox.getText();/*from w w w .j a va 2s.c om*/ workingPack = (String) modpackChooser.getSelectedItem(); parentFrame.dropAllProceedListeners(); new Thread(() -> { try { JTabbedPane tabPane; tabPane = (JTabbedPane) getParent(); if (force.isSelected()) { log.println("Cleaning up."); cleanUp(new File(workingDir)); Manifest mf = manifest.get(workingPack); if (mf != null) { mf.clear(); } } Pack detected = detectPack(new File(workingDir)); if ((detected == null) && checkDir(new File(workingDir), 2)) { try { EventQueue.invokeAndWait(() -> { JOptionPane.showMessageDialog(parentFrame, "This directory contains an unknown modpack.\nChoose another directory or force reinstall."); }); } catch (InterruptedException | InvocationTargetException ex) { } completedListener.actionPerformed(new ActionEvent(this, 2, "Install")); } else if (detected == null) { try { EventQueue.invokeAndWait(() -> { tabPane.remove(this); }); } catch (InterruptedException | InvocationTargetException ex) { } if (first && !addonsOpenedOnce) { addonsPanel = new AddonsPanel( availablePacks.get(modpackChooser.getSelectedIndex()).addons.toArray(new Addon[0])); tabPane.add("Addons", addonsPanel); tabPane.setSelectedComponent(addonsPanel); addonsOpenedOnce = true; parentFrame.setAbortListener((ActionEvent e) -> { tabPane.remove(addonsPanel); tabPane.add("Install", this); tabPane.setSelectedComponent(this); parentFrame.setProceedListener((ActionEvent ev) -> { begin(false); }); parentFrame.setAbortListener((ActionEvent ev) -> { tabPane.remove(this); parentFrame.state = 0; parentFrame.dropAllAbortListeners(); parentFrame.dropAllProceedListeners(); }); }); parentFrame.setProceedListener((ActionEvent e) -> { tabPane.remove(addonsPanel); boolean s[]; s = addonsPanel.getSelected(); for (int n = 0; n < s.length; n++) { availablePacks.get(modpackChooser.getSelectedIndex()).addons.get(n).install = s[n]; } begin(false); }); return; } if (downloadPack() && downloadAddons() && doPostDownload()) { log.println("Installation completed successful."); log.setStatusText("Ok"); completedListener.actionPerformed(new ActionEvent(this, 1, "Install")); } else { log.println("Installation completed with errors."); log.setStatusText("Error"); EventQueue.invokeLater(() -> { JOptionPane.showMessageDialog(parentFrame, "Installation failed"); }); completedListener.actionPerformed(new ActionEvent(this, 0, "Install")); } } else if (detected.name.equals(modpackChooser.getSelectedItem())) { if (!isInstalled(detected)) { try { Gson gson = new GsonBuilder().create(); tabPane.remove(this); packList.add(detected); String latestVersion = ftpClient.getLatestVersion(detected.name); if (!latestVersion.equals(detected.version)) { updatePack(detected); } try (FileWriter fw = new FileWriter( new File(config.getInstallDir(), "modpacks.json"))) { gson.toJson(packList, fw); } log.println("Installation completed successful."); completedListener.actionPerformed(new ActionEvent(this, 1, "Install")); } catch (IOException ex1) { log.println("Installation failed."); Logger.getLogger(InstallPanel.class.getName()).log(Level.SEVERE, null, ex1); } } else { try { EventQueue.invokeAndWait(() -> { tabPane.remove(this); }); } catch (InterruptedException | InvocationTargetException ex) { } if (downloadAddons()) { log.println("Installation completed successful."); log.setStatusText("Ok"); log.reset(); completedListener.actionPerformed(new ActionEvent(this, 1, "Install")); } else { log.println("Installation failed."); EventQueue.invokeLater(() -> { JOptionPane.showMessageDialog(parentFrame, "Installation failed"); }); } } } else { try { EventQueue.invokeAndWait(() -> { JOptionPane.showMessageDialog(parentFrame, "This directory contains modpack " + detected.name + ".\nSelect the correct pack or force reinstall."); }); } catch (InterruptedException | InvocationTargetException ex) { } completedListener.actionPerformed(new ActionEvent(this, 2, "Install")); } writeFiles(); } catch (NetworkException ex) { Logger.getLogger(InstallPanel.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(parentFrame, ex.getMessage(), "Network error", JOptionPane.ERROR_MESSAGE); ftpClient.close(); log.println( "Timeout. Previous command wasn't received by the server. This is a network error. Please try again later."); log.setStatusText("Error"); } }, "Installer").start(); }
From source file:org.apache.log4j.chainsaw.LogUI.java
/** * Creates, activates, and then shows the Chainsaw GUI, optionally showing * the splash screen, and using the passed shutdown action when the user * requests to exit the application (if null, then Chainsaw will exit the vm) * * @param model/*from www .j a va2 s . c o m*/ * @param newShutdownAction * DOCUMENT ME! */ public static void createChainsawGUI(ApplicationPreferenceModel model, Action newShutdownAction) { if (model.isOkToRemoveSecurityManager()) { MessageCenter.getInstance() .addMessage("User has authorised removal of Java Security Manager via preferences"); System.setSecurityManager(null); // this SHOULD set the Policy/Permission stuff for any // code loaded from our custom classloader. // crossing fingers... Policy.setPolicy(new Policy() { public void refresh() { } public PermissionCollection getPermissions(CodeSource codesource) { Permissions perms = new Permissions(); perms.add(new AllPermission()); return (perms); } }); } final LogUI logUI = new LogUI(); logUI.applicationPreferenceModel = model; if (model.isShowSplash()) { showSplash(logUI); } logUI.cyclicBufferSize = model.getCyclicBufferSize(); logUI.pluginRegistry = repositoryExImpl.getPluginRegistry(); logUI.handler = new ChainsawAppenderHandler(); logUI.handler.addEventBatchListener(logUI.new NewTabEventBatchReceiver()); /** * TODO until we work out how JoranConfigurator might be able to have * configurable class loader, if at all. For now we temporarily replace the * TCCL so that Plugins that need access to resources in * the Plugins directory can find them (this is particularly * important for the Web start version of Chainsaw */ //configuration initialized here logUI.ensureChainsawAppenderHandlerAdded(); logger = LogManager.getLogger(LogUI.class); //set hostname, application and group properties which will cause Chainsaw and other apache-generated //logging events to route (by default) to a tab named 'chainsaw-log' PropertyRewritePolicy policy = new PropertyRewritePolicy(); policy.setProperties("hostname=chainsaw,application=log,group=chainsaw"); RewriteAppender rewriteAppender = new RewriteAppender(); rewriteAppender.setRewritePolicy(policy); Enumeration appenders = Logger.getLogger("org.apache").getAllAppenders(); if (!appenders.hasMoreElements()) { appenders = Logger.getRootLogger().getAllAppenders(); } while (appenders.hasMoreElements()) { Appender nextAppender = (Appender) appenders.nextElement(); rewriteAppender.addAppender(nextAppender); } Logger.getLogger("org.apache").removeAllAppenders(); Logger.getLogger("org.apache").addAppender(rewriteAppender); Logger.getLogger("org.apache").setAdditivity(false); //commons-vfs uses httpclient for http filesystem support, route this to the chainsaw-log tab as well appenders = Logger.getLogger("httpclient").getAllAppenders(); if (!appenders.hasMoreElements()) { appenders = Logger.getRootLogger().getAllAppenders(); } while (appenders.hasMoreElements()) { Appender nextAppender = (Appender) appenders.nextElement(); rewriteAppender.addAppender(nextAppender); } Logger.getLogger("httpclient").removeAllAppenders(); Logger.getLogger("httpclient").addAppender(rewriteAppender); Logger.getLogger("httpclient").setAdditivity(false); //set the commons.vfs.cache logger to info, since it can contain password information Logger.getLogger("org.apache.commons.vfs.cache").setLevel(Level.INFO); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { e.printStackTrace(); logger.error("Uncaught exception in thread " + t, e); } }); String config = configurationURLAppArg; if (config != null) { logger.info("Command-line configuration arg provided (overriding auto-configuration URL) - using: " + config); } else { config = model.getConfigurationURL(); } if (config != null && (!config.trim().equals(""))) { config = config.trim(); try { URL configURL = new URL(config); logger.info("Using '" + config + "' for auto-configuration"); logUI.loadConfigurationUsingPluginClassLoader(configURL); } catch (MalformedURLException e) { logger.error("Initial configuration - failed to convert config string to url", e); } catch (IOException e) { logger.error("Unable to access auto-configuration URL: " + config); } } //register a listener to load the configuration when it changes (avoid having to restart Chainsaw when applying a new configuration) //this doesn't remove receivers from receivers panel, it just triggers DOMConfigurator.configure. model.addPropertyChangeListener("configurationURL", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { String newConfiguration = evt.getNewValue().toString(); if (newConfiguration != null && !(newConfiguration.trim().equals(""))) { newConfiguration = newConfiguration.trim(); try { logger.info("loading updated configuration: " + newConfiguration); URL newConfigurationURL = new URL(newConfiguration); File file = new File(newConfigurationURL.toURI()); if (file.exists()) { logUI.loadConfigurationUsingPluginClassLoader(newConfigurationURL); } else { logger.info("Updated configuration but file does not exist"); } } catch (MalformedURLException e) { logger.error("Updated configuration - failed to convert config string to URL", e); } catch (URISyntaxException e) { logger.error("Updated configuration - failed to convert config string to URL", e); } } } }); LogManager.getRootLogger().setLevel(Level.TRACE); EventQueue.invokeLater(new Runnable() { public void run() { logUI.activateViewer(); } }); logger.info("SecurityManager is now: " + System.getSecurityManager()); if (newShutdownAction != null) { logUI.setShutdownAction(newShutdownAction); } else { logUI.setShutdownAction(new AbstractAction() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); } }
From source file:wsattacker.plugin.dos.dosExtension.gui.DosResultJFrame.java
private void jSpinner1StateChanged(javax.swing.event.ChangeEvent evt) {// GEN-FIRST:event_jSpinner1StateChanged // TODO add your handling code here: int spinnerValue = Integer.parseInt(jSpinner1.getValue().toString()); EventQueue.invokeLater(new RedrawChartRunnable(resultGenerator, spinnerValue)); }
From source file:com.kenai.redminenb.query.RedmineQueryController.java
protected final void postPopulate() { final RequestProcessor.Task[] t = new RequestProcessor.Task[1]; Cancellable c = new Cancellable() { @Override//w w w . j av a 2s. c o m public boolean cancel() { if (t[0] != null) { return t[0].cancel(); } return true; } }; final String msgPopulating = Bundle.MSG_Populating(repository.getDisplayName()); final ProgressHandle handle = ProgressHandleFactory.createHandle(msgPopulating, c); EventQueue.invokeLater(new Runnable() { @Override public void run() { enableFields(false); queryPanel.showRetrievingProgress(true, msgPopulating, !query.isSaved()); handle.start(); } }); t[0] = rp.post(new Runnable() { @Override public void run() { try { populate(); } finally { EventQueue.invokeLater(new Runnable() { @Override public void run() { enableFields(true); handle.finish(); queryPanel.showRetrievingProgress(false, null, !query.isSaved()); } }); } } }); }