List of usage examples for javax.swing SwingUtilities invokeLater
public static void invokeLater(Runnable doRun)
From source file:net.brtly.monkeyboard.MonkeyBoard.java
private static void createAndShowGui() { if (System.getProperty("os.name").toLowerCase().startsWith("mac")) { LOG.debug("MAC OS detected (" + System.getProperty("os.name") + "), applying extra UIManager configuration"); // UIManager.put("TabbedPaneUI", // "javax.swing.plaf.metal.MetalTabbedPaneUI"); // UIManager.put("TabbedPane.selectedTabPadInsets", new Insets(2, 2, // 2, 1)); // UIManager.put("TabbedPane.tabsOpaque", Boolean.TRUE); // UIManager.put("TabbedPane.darkShadow", new Color(122, 138, 153)); // // UIManager.put("TabbedPane.background", new Color(184,207,229)); // UIManager.put("TabbedPane.selectHighlight", // new Color(255, 255, 255)); // // UIManager.put("TabbedPane.foreground", new Color(51,51,51)); // UIManager.put("TabbedPane.textIconGap", 4); // UIManager.put("TabbedPane.highlight", new Color(255, 255, 255)); // UIManager.put("TabbedPane.unselectedBackground", new Color(238, // 238, 238)); // UIManager.put("TabbedPane.tabRunOverlay", 2); // UIManager.put("TabbedPane.light", new Color(238, 238, 238)); // UIManager.put("TabbedPane.tabsOverlapBorder", Boolean.FALSE); // UIManager.put("TabbedPane.selected", new Color(200, 221, 242)); // UIManager.put("TabbedPane.contentBorderInsets", new Insets(4, 2, 3, // 3)); // UIManager.put("TabbedPane.contentAreaColor", new Color(220, 221, // 242)); // UIManager.put("TabbedPane.tabAreaInsets", new Insets(2, 2, 0, 6)); // UIManager.put("TabbedPane.contentOpaque", Boolean.TRUE); // UIManager.put("TabbedPane.focus", new Color(99, 130, 191)); // UIManager.put("TabbedPane.tabAreaBackground", new Color(218, 218, // 218)); // UIManager.put("TabbedPane.shadow", new Color(184, 207, 229)); // UIManager.put("TabbedPane.tabInsets", new Insets(0, 9, 1, 9)); // UIManager.put("TabbedPane.borderHightlightColor", new Color(99, // 130, 191)); System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Monkey Board"); }//from w w w.j a va2 s .com SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JFrame frame = new JFrame("Monkey Board"); frame.setBounds(120, 80, 600, 400); MasterControlPanel mcp = new MasterControlPanel(frame); frame.setVisible(true); } }); }
From source file:misc.TablePrintDemo1.java
/** * Start the application./*from w ww . j av a 2s . c o m*/ */ public static void main(final String[] args) { /* Schedule for the GUI to be created and shown on the EDT */ SwingUtilities.invokeLater(new Runnable() { public void run() { /* Don't want bold fonts if we end up using metal */ UIManager.put("swing.boldMetal", false); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { } new TablePrintDemo1().setVisible(true); } }); }
From source file:net.sf.jabref.JabRefMain.java
private static void start(String[] args) { JabRefPreferences preferences = JabRefPreferences.getInstance(); ProxyPreferences proxyPreferences = ProxyPreferences.loadFromPreferences(preferences); ProxyRegisterer.register(proxyPreferences); if (proxyPreferences.isUseProxy() && proxyPreferences.isUseAuthentication()) { Authenticator.setDefault(new ProxyAuthenticator()); }//from w ww . jav a 2 s .c o m Globals.startBackgroundTasks(); Globals.prefs = preferences; Localization.setLanguage(preferences.get(JabRefPreferences.LANGUAGE)); Globals.prefs.setLanguageDependentDefaultValues(); // Update which fields should be treated as numeric, based on preferences: InternalBibtexFields.setNumericFields(Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS)); /* Build list of Import and Export formats */ Globals.IMPORT_FORMAT_READER.resetImportFormats(); CustomEntryTypesManager.loadCustomEntryTypes(preferences); ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs)); // Read list(s) of journal names and abbreviations Globals.journalAbbreviationLoader = new JournalAbbreviationLoader(); // Check for running JabRef RemotePreferences remotePreferences = new RemotePreferences(Globals.prefs); if (remotePreferences.useRemoteServer()) { Globals.REMOTE_LISTENER.open(new JabRefMessageHandler(), remotePreferences.getPort()); if (!Globals.REMOTE_LISTENER.isOpen()) { // we are not alone, there is already a server out there, try to contact already running JabRef: if (RemoteListenerClient.sendToActiveJabRefInstance(args, remotePreferences.getPort())) { // We have successfully sent our command line options through the socket to another JabRef instance. // So we assume it's all taken care of, and quit. LOGGER.info( Localization.lang("Arguments passed on to running JabRef instance. Shutting down.")); JabRefExecutorService.INSTANCE.shutdownEverything(); return; } } // we are alone, we start the server Globals.REMOTE_LISTENER.start(); } // override used newline character with the one stored in the preferences // The preferences return the system newline character sequence as default Globals.NEWLINE = Globals.prefs.get(JabRefPreferences.NEWLINE); // Process arguments ArgumentProcessor argumentProcessor = new ArgumentProcessor(args, ArgumentProcessor.Mode.INITIAL_START); // See if we should shut down now if (argumentProcessor.shouldShutDown()) { JabRefExecutorService.INSTANCE.shutdownEverything(); return; } // If not, start GUI SwingUtilities.invokeLater( () -> new JabRefGUI(argumentProcessor.getParserResults(), argumentProcessor.isBlank())); }
From source file:WorkThreadPool.java
/** * Adds a work request to the queue.// ww w. ja v a 2 s . c o m * * @param run * The runnable * @param inAWT * If true, will be executed in AWT thread. Otherwise, will be * executed in work thread */ public void addWorkRequest(Runnable run, boolean inAWT) { if (threads == null) { run.run(); return; } synchronized (lock) { // {{{ if there are no requests, execute AWT requests immediately if (started && inAWT && requestCount == 0 && awtRequestCount == 0) { // Log.log(Log.DEBUG,this,"AWT immediate: " + run); if (SwingUtilities.isEventDispatchThread()) run.run(); else SwingUtilities.invokeLater(run); return; } // }}} Request request = new Request(run); // {{{ Add to AWT queue... if (inAWT) { if (firstAWTRequest == null && lastAWTRequest == null) firstAWTRequest = lastAWTRequest = request; else { lastAWTRequest.next = request; lastAWTRequest = request; } awtRequestCount++; // if no requests are running, requestDone() // will not be called, so we must queue the // AWT runner ourselves. if (started && requestCount == 0) queueAWTRunner(); } // }}} // {{{ Add to work thread queue... else { if (firstRequest == null && lastRequest == null) firstRequest = lastRequest = request; else { lastRequest.next = request; lastRequest = request; } requestCount++; } // }}} lock.notifyAll(); } }
From source file:com.dbschools.quickquiz.client.taker.MainWindow.java
@Override public void processReceivedMsg(final Message msg) { final Object msgObj = msg.getObject(); SwingUtilities.invokeLater(new Runnable() { public void run() { if (msgObj instanceof ChatMsg) { processIncomingChatMsg((ChatMsg) msgObj); } else if (msgObj instanceof QuizOverMsg) { processQuizOverMsg();/*www .j a v a 2 s . co m*/ } else if (msgObj instanceof JoiningMsg) { processJoiningMsg(msg.getSrc(), msgObj); } else if (msgObj instanceof QuestionMsg) { processQuestionMsg((QuestionMsg) msgObj); } else if (msgObj instanceof QuestionOverMsg) { processQuestionOver(); } else if (msgObj instanceof TakerUpdateMsg) { processUpdatedTaker(((TakerUpdateMsg) msgObj).getTaker()); } else if (msgObj instanceof PointsAwardedMsg) { processPointsAwardedMsg(((PointsAwardedMsg) msgObj)); } else if (msgObj instanceof ChatEnableMsg) { processChatEnableMsg(msgObj); } } }); }
From source file:biomine.bmvis2.pipeline.sources.QueryGraphSource.java
@Override public BMGraph getBMGraph() throws GraphOperationException { try {// w w w .java 2s . c o m if (fetch == null) { fetch = new CrawlerFetch(query, neighborhood, database); } if (ret == null) { final JDialog dial = new JDialog((JFrame) null); dial.setTitle("BMVIS II - Query to database"); dial.setSize(400, 200); dial.setMinimumSize(new Dimension(400, 200)); dial.setResizable(false); final JTextArea text = new JTextArea(); text.setEditable(false); dial.add(text); text.setText("..."); class Z { Exception runExc = null; } final Z z = new Z(); Runnable fetchThread = new Runnable() { public void run() { try { long startTime = System.currentTimeMillis(); while (!fetch.isDone()) { fetch.update(); Thread.sleep(500); long time = System.currentTimeMillis(); long elapsed = time - startTime; if (elapsed > 30000) { throw new GraphOperationException("Timeout while querying " + query); } final String newText = fetch.getState() + ":\n" + fetch.getMessages(); SwingUtilities.invokeLater(new Runnable() { public void run() { text.setText(newText); } }); } SwingUtilities.invokeAndWait(new Runnable() { public void run() { dial.setVisible(false); } }); } catch (Exception e) { z.runExc = e; } } }; new Thread(fetchThread).start(); dial.setModalityType(ModalityType.APPLICATION_MODAL); dial.setVisible(true); ret = fetch.getBMGraph(); if (ret == null) throw new GraphOperationException(fetch.getMessages()); if (z.runExc != null) { if (z.runExc instanceof GraphOperationException) throw (GraphOperationException) z.runExc; else throw new GraphOperationException(z.runExc); } } } catch (IOException e) { throw new GraphOperationException(e); } updateInfo(); return ret; }
From source file:org.pmedv.jake.commands.PlayFileCommand.java
@Override public void execute() { final ApplicationContext ctx = AppContext.getApplicationContext(); playing = true;/*from www . j a va2s .com*/ if (controller.getPlayer() != null) controller.getPlayer().close(); if (controller.getSelectedFile() == null) return; try { FileInputStream fis = new FileInputStream(controller.getSelectedFile()); player = new Player(fis); controller.setPlayer(player); String fileIndex = "(" + controller.getCurrentIndex() + "/" + controller.getModel().getFiles().size() + ") "; controller.getPlayerView().getTitleField().setText(fileIndex + controller.getSelectedFile().getName()); controller.getPlayerView().getTitleField().startAnimation(); Thread play = new Thread(new Runnable() { @Override public void run() { try { player.play(); } catch (JavaLayerException e) { controller.nextSong(); } } }); Thread endSongThread = new Thread(new Runnable() { @Override public void run() { while (player != null && !player.isComplete()) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } if (isPlaying()) controller.nextSong(); log.info("Player complete."); } }); Thread displayTime = new Thread(new Runnable() { @Override public void run() { while (player != null && !player.isComplete() && isPlaying()) { try { Thread.sleep(900); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { int playerSeconds = player.getPosition() / 1000; int minutes = (playerSeconds - (playerSeconds % 60)) / 60; int seconds = playerSeconds % 60; StringBuffer time = new StringBuffer(); time.append(minutes); time.append(":"); if (seconds < 10) time.append("0"); time.append(seconds); controller.getPlayerView().getTimeField().setText(time.toString()); } }); } catch (InterruptedException e) { e.printStackTrace(); } } log.info("Display ended."); } }); play.start(); endSongThread.start(); displayTime.start(); } catch (Exception e) { ErrorUtils.showErrorDialog(e); } }
From source file:com.frostwire.gui.library.DeviceDiscoveryClerk.java
private void handleDeviceNew(String key, InetAddress address, final Device device) { deviceCache.put(key, device);//from w w w . j a v a2 s . c o m device.setTimestamp(System.currentTimeMillis()); //LOG.info("Device New: " + device); SwingUtilities.invokeLater(new Runnable() { public void run() { LibraryMediator.instance().handleDeviceNew(device); } }); }
From source file:com.romraider.logger.ecu.ui.handler.dash.DialGaugeStyle.java
private void updateMinMax(final double value) { SwingUtilities.invokeLater(new Runnable() { public void run() { if (value > maxValue) { maxValue = value;//from w ww . j a v a 2 s.co m max.setValue(value); } if (value < minValue) { minValue = value; min.setValue(value); } } }); }
From source file:edu.ku.brc.specify.config.init.DisciplinePanel.java
/** * Creates a dialog for entering database name and selecting the appropriate driver. *//*from w w w . j a v a2s .c o m*/ public DisciplinePanel(final String helpContext, final JButton nextBtn, final JButton prevBtn) { super("DISCIPLINE", helpContext, nextBtn, prevBtn); String header = getResourceString("DISP_INFO") + ":"; CellConstraints cc = new CellConstraints(); PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,p,f:p:g", "p,6px,p,2px,p"), this); int row = 1; builder.add(createLabel(header, SwingConstants.CENTER), cc.xywh(1, row, 3, 1)); row += 2; Vector<DisciplineType> dispList = new Vector<DisciplineType>(); for (DisciplineType disciplineType : DisciplineType.getDisciplineList()) { if (disciplineType.getType() == 0) { dispList.add(disciplineType); } } Collections.sort(dispList); disciplines = createComboBox(dispList); disciplines.setSelectedIndex(-1); // Discipline JLabel lbl = createI18NFormLabel("DSP_TYPE", SwingConstants.RIGHT); lbl.setFont(bold); builder.add(lbl, cc.xy(1, row)); builder.add(disciplines, cc.xy(3, row)); row += 2; makeStretchy = true; disciplineName = createField(builder, "DISP_NAME", true, row, 64); row += 2; updateBtnUI(); disciplines.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateBtnUI(); if (disciplines.getSelectedIndex() > -1) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { DisciplineType dt = (DisciplineType) disciplines.getSelectedItem(); disciplineName.setText(dt.getTitle()); } }); } } }); }