List of usage examples for javax.swing SwingUtilities invokeLater
public static void invokeLater(Runnable doRun)
From source file:net.sf.maltcms.common.charts.ui.CategoryChartTopComponent.java
private void clearSelectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearSelectionActionPerformed if (selectionHandler != null) { SwingUtilities.invokeLater(new Runnable() { @Override/*from ww w . j a v a 2 s. c o m*/ public void run() { selectionHandler.clear(); } }); } }
From source file:org.mongkie.ui.context.GroupsContextPanel.java
@Override public void refresh(final MongkieDisplay display) { SwingUtilities.invokeLater(new Runnable() { @Override//from w w w . j a v a 2 s . c o m public void run() { DefaultPieDataset data = pie.update(display); if (data != null) { ((GroupListView) groupListScrollPane).refresh(display, data); if (!groupListScrollPane.isVisible()) { groupListScrollPane.setVisible(true); revalidate(); repaint(); } } else { ((GroupListView) groupListScrollPane).unload(); groupListScrollPane.setVisible(false); } if (currentDisplay != display) { if (currentDisplay != null) { ((AggregateTable) currentDisplay.getVisualization() .getVisualGroup(Visualization.AGGR_ITEMS)) .removeTableListener(GroupsContextPanel.this); } currentDisplay = display; ((AggregateTable) currentDisplay.getVisualization().getVisualGroup(Visualization.AGGR_ITEMS)) .addTableListener(GroupsContextPanel.this); } if (!isVisible()) { setVisible(true); } } }); }
From source file:com.projity.util.VersionUtils.java
public static boolean versionCheck(boolean warnIfBad) { String version = VersionUtils.getVersion(); if (version == null) // for running in debugger version = "0"; Preferences pref = Preferences.userNodeForPackage(VersionUtils.class); String localVersion = pref.get("Angel Falls Version", "unknown"); boolean updated = !localVersion.equals(version); String javaVersion = System.getProperty("java.version"); log.info("Angel Falls Version: " + version + " local version " + localVersion + " updated=" + updated + " java version=" + javaVersion); pref.put("JavaVersion", javaVersion); if (updated) { Environment.setUpdated(true); pref.put("PODVersion", version); try {//from w w w .ja v a 2s .co m pref.flush(); } catch (BackingStoreException e) { e.printStackTrace(); } if (warnIfBad && Environment.isApplet()) { if (javaVersion.equals("1.6.0_09") || javaVersion.equals("1.6.0_08") || javaVersion.equals("1.6.0_07") || javaVersion.equals("1.6.0_06") || javaVersion.equals("1.6.0_05") || javaVersion.equals("1.6.0_04")) { Environment.setNeedToRestart(true); SwingUtilities.invokeLater(new Runnable() { public void run() { Alert.error(Messages.getString("Error.restart")); } }); } } } else { try { pref.flush(); } catch (BackingStoreException e) { e.printStackTrace(); } } return updated; }
From source file:net.sf.keystore_explorer.gui.CreateApplicationGui.java
private void checkCaCerts(final KseFrame kseFrame) { File caCertificatesFile = applicationSettings.getCaCertificatesFile(); if (caCertificatesFile.exists()) { return;/*from w w w. ja va2 s. com*/ } // cacerts file is not where we expected it => detect location and inform user final File newCaCertsFile = new File(AuthorityCertificates.getDefaultCaCertificatesLocation().toString()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { int selected = JOptionPane.showConfirmDialog(kseFrame.getUnderlyingFrame(), MessageFormat .format(res.getString("CreateApplicationGui.CaCertsFileNotFound.message"), newCaCertsFile), KSE.getApplicationName(), JOptionPane.YES_NO_OPTION); if (selected == JOptionPane.YES_OPTION) { applicationSettings.setCaCertificatesFile(newCaCertsFile); } } }); }
From source file:ca.sqlpower.swingui.object.VariablesPanel.java
/** * Default constructor for the variables panel. * @param variableHelper A helper that will be used in order to * resolve discover and resolve variables. * @param action An implementation of {@link VariableInserter} that * gets called once the variable has been created. This action will be executed * on the Swing Event Dispatch Thread.//w w w . j a v a 2 s.com * @param varDefinition The default variable definition string. */ public VariablesPanel(SPVariableHelper variableHelper, VariableInserter action, String varDefinition) { this.variableHelper = variableHelper; this.action = action; this.generalLabel = new JLabel("General"); this.generalLabel.setFont(this.generalLabel.getFont().deriveFont(Font.BOLD)); this.pickerLabel = new JLabel("Pick a variable"); this.varNameText = new JTextField(); this.varNameText.setEditable(false); this.varNameText.addMouseListener(new MouseListener() { public void mouseReleased(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseClicked(MouseEvent e) { ShowPickerAction act = new ShowPickerAction(); act.actionPerformed(null); } }); this.varPicker = new JButton(new ShowPickerAction()); this.optionsLabel = new JLabel("Options"); this.optionsLabel.setFont(this.optionsLabel.getFont().deriveFont(Font.BOLD)); this.varDefaultLabel = new JLabel("Default value"); this.varDefaultText = new JTextField(); this.varDefaultText.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { currentDefValue = varDefaultText.getText(); updateGUI(); } }); } public void keyReleased(KeyEvent e) { } public void keyPressed(KeyEvent e) { } }); this.varEditLabel = new JLabel("Customization"); this.varEditText = new JTextField(); this.varEditText.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { int carPos = varEditText.getCaretPosition(); String text = varEditText.getText().replace("$", "").replace("{", "").replace("}", ""); currentPickedVariable = SPVariableHelper.stripDefaultValue(text); if (currentPickedVariable == null) { currentPickedVariable = ""; } currentDefValue = SPVariableHelper.getDefaultValue(text); if (currentDefValue == null) { currentDefValue = ""; } if (SPVariableHelper.getNamespace(text) == null) { namespaceBox.setSelected(false); } else { namespaceBox.setSelected(true); } updateGUI(); try { varEditText.setCaretPosition(carPos); } catch (IllegalArgumentException e) { varEditText.setCaretPosition(carPos - 1); } } }); } public void keyReleased(KeyEvent e) { } public void keyPressed(KeyEvent e) { } }); this.namespaceLabel = new JLabel("Constrain to namespace"); this.namespaceBox = new JCheckBox(""); if (SPVariableHelper.getNamespace(varDefinition) != null || "".equals(varDefinition)) { this.namespaceBox.setSelected(true); } else { this.namespaceBox.setSelected(false); } this.namespaceBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { updateGUI(); } }); this.previewLabel = new JLabel("Preview"); this.previewLabel.setFont(this.previewLabel.getFont().deriveFont(Font.BOLD)); this.varPreviewLabel1 = new JLabel("Current value is"); this.varPreviewLabel1.setForeground(Color.GRAY); this.varPreviewLabel2 = new JLabel(); this.varPreviewLabel2.setForeground(Color.GRAY); this.panel = new JPanel(new MigLayout()); this.panel.add(this.generalLabel, "growx, span, wrap"); this.panel.add(new JLabel(" "), "wmin 20, wmax 20"); this.panel.add(this.pickerLabel); this.panel.add(this.varNameText, "growx, wmin 275, wmax 275, gapright 0"); this.panel.add(this.varPicker, "wmax 20, hmax 20, wrap, gapleft 0"); this.panel.add(this.optionsLabel, "growx, span, wrap"); this.panel.add(new JLabel(" "), "wmin 20, wmax 20"); this.panel.add(this.varDefaultLabel); this.panel.add(this.varDefaultText, "span, wrap, wmin 300, wmax 300"); this.panel.add(new JLabel(" "), "wmin 20, wmax 20"); this.panel.add(namespaceLabel); this.panel.add(namespaceBox, "span, wrap"); this.panel.add(new JLabel(" "), "wmin 20, wmax 20"); this.panel.add(this.varEditLabel); this.panel.add(this.varEditText, "span, wmin 300, wmax 300, wrap"); this.panel.add(this.previewLabel, "growx, span, wrap"); this.panel.add(new JLabel(" "), "wmin 20, wmax 20"); this.panel.add(this.varPreviewLabel1); this.panel.add(this.varPreviewLabel2, "span, growx"); this.currentPickedVariable = varDefinition; updateGUI(); }
From source file:com.wet.wired.jsr.player.JPlayer.java
public void showNewImage(final Image image) { if (icon == null) { icon = new ImageIcon(image); JLabel label = new JLabel(icon); scrollPane = new JScrollPane(label); scrollPane.setSize(image.getWidth(this), image.getHeight(this)); SwingUtilities.invokeLater(new Runnable() { public void run() { getContentPane().add(scrollPane, BorderLayout.CENTER); pack();/* ww w . jav a 2s . c om*/ setSize(getWidth() - 100, 400); setVisible(true); repaint(0); } }); } else { SwingUtilities.invokeLater(new Runnable() { public void run() { icon.setImage(image); repaint(0); } }); } }
From source file:SimpleHelp.java
/** * Notification of a change relative to a hyperlink. From: * java.swing.event.HyperlinkListener/* w ww . ja va 2 s . c om*/ */ public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { URL target = e.getURL(); // System.out.println("linkto: " + target); // Get the help panel's cursor and the wait cursor Cursor oldCursor = help.getCursor(); Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); help.setCursor(waitCursor); // Now arrange for the page to get loaded asynchronously, // and the cursor to be set back to what it was. SwingUtilities.invokeLater(new PageLoader(target, oldCursor)); } }
From source file:ee.ioc.cs.vsle.util.Console.java
private void appendToConsole(final String s) { SwingUtilities.invokeLater(new Runnable() { @Override//from w w w .j a v a 2 s . co m public void run() { textArea.append(s); scrollToBottom(); } }); }
From source file:com.skcraft.launcher.launch.LaunchSupervisor.java
private void launch(Window window, Instance instance, Session session, final LaunchListener listener) { final File extractDir = launcher.createExtractDir(); // Get the process Runner task = new Runner(launcher, instance, session, extractDir); ObservableFuture<Process> processFuture = new ObservableFuture<Process>(launcher.getExecutor().submit(task), task);// w ww . j av a 2s .c o m // Show process for the process retrieval ProgressDialog.showProgress(window, processFuture, SharedLocale.tr("launcher.launchingTItle"), tr("launcher.launchingStatus", instance.getTitle())); // If the process is started, get rid of this window Futures.addCallback(processFuture, new FutureCallback<Process>() { @Override public void onSuccess(Process result) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { listener.gameStarted(); } }); } @Override public void onFailure(Throwable t) { } }); // Watch the created process ListenableFuture<?> future = Futures.transform(processFuture, new LaunchProcessHandler(launcher), launcher.getExecutor()); SwingHelper.addErrorDialogCallback(null, future); // Clean up at the very end future.addListener(new Runnable() { @Override public void run() { try { log.info("Process ended; cleaning up " + extractDir.getAbsolutePath()); FileUtils.deleteDirectory(extractDir); } catch (IOException e) { log.log(Level.WARNING, "Failed to clean up " + extractDir.getAbsolutePath(), e); } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { listener.gameClosed(); } }); } }, sameThreadExecutor()); }
From source file:io.github.tavernaextras.biocatalogue.ui.filtertree.FilterTreePane.java
/** * This method loads filter data from API and populates the view. *///from w w w .ja va2 s.com private void loadFiltersAndBuildTheTree() { SwingUtilities.invokeLater(new Runnable() { public void run() { resetTreeActionToolbar(); jpFilters.removeAll(); jpFilters.setLayout(new BorderLayout()); jpFilters.add(new JLabel(" Loading filters..."), BorderLayout.NORTH); jpFilters.add(new JLabel(ResourceManager.getImageIcon(ResourceManager.BAR_LOADER_ORANGE)), BorderLayout.CENTER); thisPanel.validate(); thisPanel.repaint(); // validate and repaint this component to make sure that // scroll bar around the filter tree placeholder panel disappears } }); new Thread("Load filters") { public void run() { try { // load filter data filtersRoot = client.getBioCatalogueFilters(filtersURL); // Create root of the filter tree component FilterTreeNode root = new FilterTreeNode("root"); // populate the tree via its root element for (FilterGroup fgroup : filtersRoot.getGroupList()) { // attach filter group directly to the root node FilterTreeNode fgroupNode = new FilterTreeNode( "<html><span style=\"color: black; font-weight: bold;\">" + StringEscapeUtils.escapeHtml(fgroup.getName().toString()) + "</span></html>"); root.add(fgroupNode); // go through all filter types in this group and add them to the tree for (FilterType ftype : fgroup.getTypeList()) { // if there's more than one filter type in the group, add the type node as another level of nesting // (otherwise, attach filters inside the single type directly to the group node) FilterTreeNode filterTypeNode = fgroupNode; if (fgroup.getTypeList().size() > 1) { filterTypeNode = new FilterTreeNode( "<html><span style=\"color: black; font-weight: bold;\">" + StringEscapeUtils.escapeHtml(ftype.getName().toString()) + "</span></html>"); fgroupNode.add(filterTypeNode); } // For some reason sorting the list of filters before inserting into tree // messes up the tree nodes // Collections.sort(ftype.getFilterList(), new Comparator<Filter>(){ // @Override // public int compare(Filter f1, Filter f2) { // return (f1.getName().compareToIgnoreCase(f2.getName())); // } // }); addFilterChildren(filterTypeNode, ftype.getUrlKey().toString(), ftype.getFilterList()); } } // Create the tree view with the populated root filterTree = new JFilterTree(root); filterTree.setRootVisible(false); // don't want the root to be visible; not a standard thing, so not implemented within JTriStateTree filterTree.setLargeModel(true); // potentially can have many filters! filterTree.addCheckingListener(thisPanel); // insert the created tree view into the filters panel jpFilters.removeAll(); jpFilters.setLayout(new GridLayout(0, 1)); jpFilters.add(filterTree); jpFilters.validate(); // add actions from the contextual menu of the filter tree into the toolbar // that replicates those plus adds additional ones in this panel tbFilterTreeToolbar.removeAll(); for (Action a : filterTree.getContextualMenuActions()) { tbFilterTreeToolbar.add(a); } // enable all actions filterTree.enableAllContextualMenuAction(true); } catch (Exception e) { logger.error("Failed to load filter tree from the following URL: " + filtersURL, e); } } /** * Recursive method to populate a node of the filter tree with all * sub-filters. * * Ontological terms will be underlined. * * @param root Tree node to add children to. * @param filterList A list of Filters to add to "root" as children. */ private void addFilterChildren(FilterTreeNode root, String filterCategory, List<Filter> filterList) { for (Filter f : filterList) { // Is this an ontological term? String ontology = null; if (FilterTreeNode.isTagWithNamespaceNode(filterCategory, f.getUrlValue())) { String nameAndNamespace = f.getUrlValue().substring(1, f.getUrlValue().length() - 1); String[] namePlusNamespace = nameAndNamespace.split("#"); ontology = JFilterTree.getOntologyFromNamespace(namePlusNamespace[0]); } FilterTreeNode fNode = new FilterTreeNode("<html><span color=\"black\"" /*(FilterTreeNode.isTagWithNamespaceNode(filterCategory, f.getUrlValue()) ? " style=\"text-decoration: underline;\"" : "") */ + ">" + StringEscapeUtils.escapeHtml(f.getName()) + " (" + f.getCount() + ")" + "</span>" + /*(FilterTreeNode.isTagWithNamespaceNode(filterCategory, f.getUrlValue()) ? "<span color=\"gray\"> ("+f.getCount().intValue()+")</span></html>" : "</html>"),*/ (ontology != null ? "<span color=\"#3090C7\"> <" + ontology + "></span></html>" : "</html>"), filterCategory, f.getUrlValue()); addFilterChildren(fNode, filterCategory, f.getFilterList()); // Insert the node into the (alphabetically) sorted children nodes List<FilterTreeNode> children = Collections.list(root.children()); // Search for the index the new node should be inserted at int index = Collections.binarySearch(children, fNode, new Comparator<FilterTreeNode>() { @Override public int compare(FilterTreeNode o1, FilterTreeNode o2) { String str1 = ((String) o1.getUserObject()).toString(); String str2 = ((String) o2.getUserObject()).toString(); return (str1.compareToIgnoreCase(str2)); } }); if (index < 0) { // not found - index will be equal to -insertion-point -1 index = -index - 1; } // else node with the same name found in the array - insert it at that position root.insert(fNode, index); //root.add(fNode); } } }.start(); }