List of usage examples for javax.swing SwingUtilities invokeLater
public static void invokeLater(Runnable doRun)
From source file:LiveParenMatcher.java
public void insertUpdate_3(DocumentEvent de) { Document doc = de.getDocument(); int offset = de.getOffset(); int length = de.getLength(); Segment seg = new Segment(); try {//from ww w . j a va 2 s . c om doc.getText(offset, length, seg); // text placed in Segment } catch (BadLocationException ble) { } // iterate through the Segment for (char ch = seg.first(); ch != seg.DONE; ch = seg.next()) if (ch == '(' || ch == '[' || ch == '{' || ch == ')' || ch == ']' || ch == '}') { SwingUtilities.invokeLater(this); // will call run() return; // no need to check further } }
From source file:Solver.java
private static void Solve(Pair<Integer, Integer[]> data, boolean searchAll) { int N = data.getLeft(); Integer[] S = data.getRight(); int nsquares = S.length; Store store = new Store(); IntVar[] X = new IntVar[nsquares]; IntVar[] Y = new IntVar[nsquares]; IntVar[] W = new IntVar[nsquares]; IntVar[] H = new IntVar[nsquares]; IntVar L = new IntVar(store, N, N); ArrayUtils.reverse(S);//from w w w .jav a2 s . c om for (int i = 0; i < nsquares; i++) { X[i] = new IntVar(store, "X" + i, 0, N - S[i]); Y[i] = new IntVar(store, "Y" + i, 0, N - S[i]); W[i] = new IntVar(store, S[i], S[i]); H[i] = new IntVar(store, S[i], S[i]); } Constraint ctr1 = new Diff2(X, Y, W, H); Constraint ctr2 = new Cumulative(X, W, H, L); Constraint ctr3 = new Cumulative(Y, W, H, L); ctr1.impose(store); ctr2.impose(store); ctr3.impose(store); Search<IntVar> searchX = new DepthFirstSearch<IntVar>(); Search<IntVar> searchY = new DepthFirstSearch<IntVar>(); SelectChoicePoint<IntVar> labelX = new SimpleSelect<>(X, new SmallestMin<>(), new SmallestDomain<>(), new IndomainMin<>()); SelectChoicePoint<IntVar> labelY = new SimpleSelect<>(Y, new SmallestMin<>(), new SmallestDomain<>(), new IndomainMin<>()); searchY.setSelectChoicePoint(labelY); searchX.addChildSearch(searchY); if (searchAll) searchX.getSolutionListener().searchAll(true); searchX.getSolutionListener().recordSolutions(true); searchY.getSolutionListener().recordSolutions(true); searchX.setPrintInfo(false); searchY.setPrintInfo(false); searchX.labeling(store, labelX); for (int sid = 1; sid <= searchX.getSolutionListener().solutionsNo(); sid++) { SwingUtilities.invokeLater((new Solver()).new Window(sid - 1, window_size, N, searchX.getSolution(sid), searchY.getSolution(sid), S)); } }
From source file:edu.ku.brc.specify.tasks.StartUpTask.java
/** * If using path then we just check the local prefs, if using the server * then first check the global prefs and then the local prefs */// w w w . j av a 2 s . c om public static void configureAttachmentManager() { AppPreferences localPrefs = AppPreferences.getLocalPrefs(); boolean isUsingPath = localPrefs.getBoolean(USE_FILE_PATH_PREF, true); boolean isUsingGlobalAttchPrefs = AppPreferences.getGlobalPrefs().getBoolean(USE_GLOBAL_PREFS, false); if (isUsingGlobalAttchPrefs) { isUsingPath = false; } boolean wasOK = false; if (isUsingGlobalAttchPrefs) { wasOK = configureAttachmentManager(AppPreferences.getGlobalPrefs()); } else { wasOK = configureAttachmentManager(localPrefs); } if (!wasOK) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { UIRegistry.showLocalizedError("AttachmentUtils.NOT_AVAIL"); } }); } }
From source file:simphy.XYChart.java
public XYChart(Circle c) { this.c = c;//from ww w . j av a 2 s . c o m // Create a simple XY chart type = "circle"; series = new XYSeries("VT Plot"); dataset = new XYSeriesCollection(); dataset.addSeries(series); // Generate the graph chart = ChartFactory.createXYLineChart("Velocity-Time Graph", // Title "time(s)", // x-axis Label "velocity(m/s)", // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); this.setTitle(c.getID()); this.setBounds(950, 0, 400, 700); panel = new ChartPanel(chart, false); this.add(panel, BorderLayout.CENTER); this.setAlwaysOnTop(true); this.addWindowListener(this); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.pack(); SwingUtilities.invokeLater(() -> { XYChart.this.setVisible(true); }); }
From source file:net.pandoragames.far.ui.swing.component.listener.OperationCallBackListener.java
/** * {@inheritDoc}//from w ww .j a va 2s.co m */ public void operationAborted(OperationType type) { for (ComponentContainer comp : startComponents) { if ((comp.type == type) || (comp.type == OperationType.ANY)) { if (comp.endisFlag == ABILITY.ENABLE) { SwingUtilities.invokeLater(new EnDisableComponent(comp.component, ABILITY.DISABLE)); } else if (comp.endisFlag == ABILITY.DISABLE) { SwingUtilities.invokeLater(new EnDisableComponent(comp.component, ABILITY.ENABLE)); } } } }
From source file:com.skcraft.launcher.launch.LaunchSupervisor.java
public void launch(LaunchOptions options) { final Window window = options.getWindow(); final Instance instance = options.getInstance(); final LaunchListener listener = options.getListener(); try {/* ww w . jav a 2s . c o m*/ boolean update = options.getUpdatePolicy().isUpdateEnabled() && instance.isUpdatePending(); // Store last access date Date now = new Date(); instance.setLastAccessed(now); Persistence.commitAndForget(instance); // Perform login final Session session; if (options.getSession() != null) { session = options.getSession(); } else { session = LoginDialog.showLoginRequest(window, launcher); if (session == null) { return; } } // If we have to update, we have to update if (!instance.isInstalled()) { update = true; } if (update) { // Execute the updater Updater updater = new Updater(launcher, instance); updater.setOnline(options.getUpdatePolicy() == UpdatePolicy.ALWAYS_UPDATE || session.isOnline()); ObservableFuture<Instance> future = new ObservableFuture<Instance>( launcher.getExecutor().submit(updater), updater); // Show progress ProgressDialog.showProgress(window, future, SharedLocale.tr("launcher.updatingTitle"), tr("launcher.updatingStatus", instance.getTitle())); SwingHelper.addErrorDialogCallback(window, future); // Update the list of instances after updating future.addListener(new Runnable() { @Override public void run() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { listener.instancesUpdated(); } }); } }, SwingExecutor.INSTANCE); // On success, launch also Futures.addCallback(future, new FutureCallback<Instance>() { @Override public void onSuccess(Instance result) { launch(window, instance, session, listener); } @Override public void onFailure(Throwable t) { } }, SwingExecutor.INSTANCE); } else { launch(window, instance, session, listener); } } catch (ArrayIndexOutOfBoundsException e) { SwingHelper.showErrorDialog(window, SharedLocale.tr("launcher.noInstanceError"), SharedLocale.tr("launcher.noInstanceTitle")); } }
From source file:com.skcraft.launcher.bootstrap.Downloader.java
private void execute() throws Exception { SwingUtilities.invokeAndWait(new Runnable() { @Override/*w w w .ja va 2 s . c o m*/ public void run() { Bootstrap.setSwingLookAndFeel(); dialog = new DownloadFrame(Downloader.this); dialog.setVisible(true); dialog.setDownloader(Downloader.this); } }); File finalFile = new File(bootstrap.getBinariesDir(), System.currentTimeMillis() + ".jar.pack"); File tempFile = new File(finalFile.getParentFile(), finalFile.getName() + ".tmp"); URL updateUrl = HttpRequest.url(bootstrap.getProperties().getProperty("latestUrl")); log.info("Reading update URL " + updateUrl + "..."); try { String data = HttpRequest.get(updateUrl).execute().expectResponseCode(200).returnContent() .asString("UTF-8"); Object object = JSONValue.parse(data); URL url; if (object instanceof JSONObject) { String rawUrl = String.valueOf(((JSONObject) object).get("url")); if (rawUrl != null) { url = HttpRequest.url(rawUrl.trim()); } else { log.warning("Did not get valid update document - got:\n\n" + data); throw new IOException("Update URL did not return a valid result"); } } else { log.warning("Did not get valid update document - got:\n\n" + data); throw new IOException("Update URL did not return a valid result"); } checkInterrupted(); log.info("Downloading " + url + " to " + tempFile.getAbsolutePath()); httpRequest = HttpRequest.get(url); httpRequest.execute().expectResponseCode(200).saveContent(tempFile); finalFile.delete(); tempFile.renameTo(finalFile); } finally { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { dialog.setDownloader(null); dialog.dispose(); } }); } LauncherBinary binary = new LauncherBinary(finalFile); List<LauncherBinary> binaries = new ArrayList<LauncherBinary>(); binaries.add(binary); bootstrap.launchExisting(binaries, false); }
From source file:edu.ku.brc.specify.plugins.SeriesProcCatNumPlugin.java
/** * @param textFieldStart/*from w ww .j a v a2 s . c om*/ * @param textFieldEnd */ public SeriesProcCatNumPlugin(final ValFormattedTextFieldIFace textFieldStart, final ValFormattedTextFieldIFace textFieldEnd) { super(); this.textFieldStart = textFieldStart; this.textFieldEnd = textFieldEnd; this.expandBtn = UIHelper.createIconBtn("move_right", "", null); pb = new PanelBuilder(new FormLayout("p,f:p:g", "c:p"), this); panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.add(textFieldStart.getValidatableUIComp()); panel.add(textFieldEnd.getValidatableUIComp()); panel.add(expandBtn); expandBtn.setEnabled(true); pb.add(panel, cc.xy(1, 1)); expandBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doToggleContract(); } }); textFieldEnd.setAutoNumberEnabled(false); textFieldEnd.getValidatableUIComp().setEnabled(true); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { isExpanded = true; expandBtn.doClick(); expandBtn.setVisible(false); } }); }
From source file:com.github.sgelb.sldownloader.SLDownloader.java
public void runGUI() { SwingUtilities.invokeLater(new Runnable() { public void run() { Gui gb = new Gui(); gb.run();//from ww w .ja v a 2s . c o m } }); }
From source file:net.pandoragames.far.ui.swing.component.listener.AbstractFileOperationListener.java
public void run() { int total = tableModel.getSelectedRowCount(); int count = 1; for (ProgressListener pl : listener) pl.operationStarted(operation);//from www . j a va2 s . co m for (TargetFile row : tableModel.listRows()) { row.clear(); if (row.isSelected()) { execute(row); for (ProgressListener pl : listener) pl.operationProgressed(count++, total, operation); } } SwingUtilities.invokeLater(new Runnable() { public void run() { tableModel.notifyUpdate(); } }); for (ProgressListener pl : listener) pl.operationTerminated(operation); }