Example usage for javax.swing SwingUtilities invokeLater

List of usage examples for javax.swing SwingUtilities invokeLater

Introduction

In this page you can find the example usage for javax.swing SwingUtilities invokeLater.

Prototype

public static void invokeLater(Runnable doRun) 

Source Link

Document

Causes doRun.run() to be executed asynchronously on the AWT event dispatching thread.

Usage

From source file:edu.ku.brc.specify.config.init.secwiz.SpecifyDBSecurityWizardFrame.java

/**
 * @throws HeadlessException/* w w  w.  ja v a  2s . c  om*/
 */
public SpecifyDBSecurityWizardFrame() throws HeadlessException {
    super();

    UIRegistry.loadAndPushResourceBundle("specifydbsetupwiz");

    new MacOSAppHandler(this);

    UIRegistry.setTopWindow(this);

    // Now initialize
    AppPreferences localPrefs = AppPreferences.getLocalPrefs();
    localPrefs.setDirPath(UIRegistry.getAppDataDir());

    AppPrefsCache.setUseLocalOnly(true);
    SpecifyAppPrefs.setSkipRemotePrefs(true);
    SpecifyAppPrefs.initialPrefs();

    ImageIcon helpIcon = IconManager.getIcon(SpecifyDBSecurityWizard.getIconName(), IconSize.Std16); //$NON-NLS-1$
    HelpMgr.initializeHelp("SpecifyHelp", helpIcon.getImage()); //$NON-NLS-1$

    JMenuBar menuBar = createMenus();
    if (menuBar != null) {
        setJMenuBar(menuBar);
    }
    UIRegistry.register(UIRegistry.MENUBAR, menuBar);

    setIconImage(
            IconManager.getIcon(SpecifyDBSecurityWizard.getIconName(), IconManager.IconSize.NonStd).getImage());

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    HelpMgr.setAppDefHelpId("security_wiz1");

    SpecifyDBSecurityWizard wizPanel = new SpecifyDBSecurityWizard(
            new SpecifyDBSecurityWizard.WizardListener() {
                @Override
                public void cancelled() {
                    setVisible(false);
                    //dispose();
                    doExit(true);
                }

                @Override
                public void hide() {
                    setVisible(false);
                }

                @Override
                public void finished() {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            dispose();
                            doExit(true);
                        }
                    });
                }

                @Override
                public void panelChanged(String title) {
                    setTitle(getAppTitle(title));
                }
            });

    setTitle(getAppTitle(getResourceString("MAIN_TITLE")));

    setContentPane(wizPanel);

    pack();
}

From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.control.MonitorApplet.java

/** Send the ServletReceiver a SESSION_QUERY_REQUEST, then allow the administrator
 *  to choose a session to monitor. Once the session is chosen, re-create the clients
 *  panel to reflect the number of the clients in the chosen session. Then finish
 *  initialization by exporting this ExpMonitor via RMI to link up officially with the
 *  server. This operation is run on a separate thread so that the applet can finish
 *  initializing (ending its 'init' method) before the main GUI screen appears. This
 *  way the browser does not pop up and block the main GUI screen (since the browser
 *  gains focus when init is finished). If this controller is set up for fast mode then
 *  just monitor the first session without asking */
public void querySessions() {
    final MonitorApplet con = this;

    Runnable sessionFinder = new Runnable() {
        public void run() {
            SessionIdentifier[] identifiers = transmitter.getActiveSessions();

            String fastMode = getParameter("fast");
            if (fastMode != null && fastMode.equalsIgnoreCase("true")) {
                con.sessionId = identifiers[0].getSessionId();
                final int numClients = identifiers[0].getNumClients();

                Runnable doUpdate = new Runnable() {
                    public void run() {
                        ui.constructClientsPanel(numClients);
                    }/*from  ww  w .ja v a 2s .  c o  m*/
                };
                SwingUtilities.invokeLater(doUpdate);

                transmitter.connect(ui, sessionId);
                return;
            }

            sessionSelector = new SessionSelectorDialog(ui, identifiers) {
                public void joinSession(int sessionId, int numClients) {
                    sessionSelector.setVisible(false);
                    sessionSelector.dispose();
                    //log.debug("MonitorApplet is setting its sessionId to:  "+sessionId);
                    con.sessionId = sessionId;
                    //setSessionId(sessionId);
                    System.out.println("Set monitor to session " + sessionId);
                    ui.constructClientsPanel(numClients);

                    transmitter.connect(ui, sessionId);
                }
            };
            sessionSelector.setVisible(true);
        }
    };

    Thread queryThread = new Thread(sessionFinder);
    queryThread.start();
}

From source file:com.projity.dialog.FieldDialog.java

protected FieldDialog(Frame owner, String title, boolean modal,
        boolean multipleObjects/*,UndoableEditSupport undoableEditSupport*/) {
    super(owner, title, modal);
    this.multipleObjects = multipleObjects;
    //this.undoableEditSupport=undoableEditSupport;

    // need to update all initially, but do later on once things are set
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            updateAll();// ww  w.  j a va  2  s.c o  m
        }
    });
}

From source file:edu.ku.brc.af.ui.forms.RecordSetTableViewObj.java

/**
 * @param recordSet//from w  w w  .  j  a v  a2 s  .  c  o  m
 */
private void processRecordSet(final RecordSetIFace recordSet) {
    isLoading = true;

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            table.tableChanged(new TableModelEvent(model));
            table.repaint();
        }
    });

    DBTableIdMgr.getInstance().getInClause(recordSet);
    DBTableInfo tableInfo = DBTableIdMgr.getInstance().getInfoById(recordSet.getDbTableId());

    DataProviderFactory.getInstance().evict(tableInfo.getClassObj());

    if (tempSession == null) {
        tempSession = DataProviderFactory.getInstance().createSession();
    }

    String sqlStr = DBTableIdMgr.getInstance().getQueryForTable(recordSet);
    if (StringUtils.isNotBlank(sqlStr)) {
        dataObjList.addAll(tempSession.getDataList(sqlStr));

        for (Object obj : dataObjList) {
            FormDataObjIFace fdi = (FormDataObjIFace) obj;
            fdi.forceLoad();
        }
    }

    if (tempSession != null) {
        tempSession.close();
        tempSession = null;
    }

    isLoading = false;

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            table.repaint();
        }
    });
}

From source file:com.github.rholder.gradle.ui.DependencyViewerStandalone.java

private void initToolingLogger() {
    toolingLogger = new ToolingLogger() {
        public void log(final String line) {
            // note: lots of log messages will freeze the dispatch thread
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    if (gradleBaseDir != null) {
                        setTitle("- " + gradleBaseDir + " - " + line);
                        information.append(line + "\n");
                    }//w  w  w.j  a v a2  s  .c om
                }
            });
        }
    };
}

From source file:ca.sqlpower.enterprise.ServerInfoProvider.java

private static void init(URL url, String username, String password, CookieStore cookieStore)
        throws IOException {

    if (version.containsKey(generateServerKey(url, username, password)))
        return;/*  w ww.j  av  a2  s  .  c o m*/

    try {
        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, 2000);
        DefaultHttpClient httpClient = new DefaultHttpClient(params);
        httpClient.setCookieStore(cookieStore);
        httpClient.getCredentialsProvider().setCredentials(new AuthScope(url.getHost(), AuthScope.ANY_PORT),
                new UsernamePasswordCredentials(username, password));

        HttpUriRequest request = new HttpOptions(url.toURI());
        String responseBody = httpClient.execute(request, new BasicResponseHandler());

        // Decode the message
        String serverVersion;
        Boolean licensedServer;
        final String watermarkMessage;
        try {
            JSONObject jsonObject = new JSONObject(responseBody);
            serverVersion = jsonObject.getString(ServerProperties.SERVER_VERSION.toString());
            licensedServer = jsonObject.getBoolean(ServerProperties.SERVER_LICENSED.toString());
            watermarkMessage = jsonObject.getString(ServerProperties.SERVER_WATERMARK_MESSAGE.toString());
        } catch (JSONException e) {
            throw new IOException(e.getMessage());
        }

        // Save found values
        version.put(generateServerKey(url, username, password), new Version(serverVersion));
        licenses.put(generateServerKey(url, username, password), licensedServer);
        watermarkMessages.put(generateServerKey(url, username, password), watermarkMessage);

        // Notify the user if the server is not licensed.
        if (!licensedServer || (watermarkMessage != null && watermarkMessage.trim().length() > 0)) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    HyperlinkListener hyperlinkListener = new HyperlinkListener() {
                        @Override
                        public void hyperlinkUpdate(HyperlinkEvent e) {
                            try {
                                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                                    if (e.getURL() != null) {
                                        BrowserUtil.launch(e.getURL().toString());
                                    }
                                }
                            } catch (IOException ex) {
                                throw new RuntimeException(ex);
                            }
                        }
                    };
                    HTMLUserPrompter htmlPrompter = new HTMLUserPrompter(UserPromptOptions.OK,
                            UserPromptResponse.OK, null, watermarkMessage, hyperlinkListener, "OK");
                    htmlPrompter.promptUser("");
                }
            });
        }

    } catch (URISyntaxException e) {
        throw new IOException(e.getLocalizedMessage());
    }
}

From source file:com.mirth.connect.client.ui.editors.RuleBuilderPanel.java

public void updateTable() {
    if (parent.getSelectedRow() != -1 && !parent.getTableModel()
            .getValueAt(parent.getSelectedRow(), parent.STEP_TYPE_COL).toString().equals("JavaScript")) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                parent.getTableModel().setValueAt(rulePlugin.getStepName(), parent.getSelectedRow(),
                        parent.STEP_NAME_COL);
                parent.updateTaskPane(parent.getTableModel()
                        .getValueAt(parent.getSelectedRow(), parent.STEP_TYPE_COL).toString());
            }//  www.j  a  va2s.  c  om
        });
    }
}

From source file:edu.ku.brc.specify.toycode.FixSQLString.java

/**
 * //w  ww. j  ava  2  s  .  c o  m
 */
private void fix() {
    StringBuilder sb = new StringBuilder("sql = \"");
    String srcStr = srcTA.getText();
    boolean wasInner = false;
    for (String line : StringUtils.split(srcStr, "\n")) {
        String str = StringUtils.deleteWhitespace(line);

        if (str.toUpperCase().startsWith("INNER") || str.toUpperCase().startsWith("ORDER")
                || str.toUpperCase().startsWith("GROUP")) {
            if (!wasInner) {
                sb.append(" \" +");
                wasInner = false;
            }
            sb.append("\n    \"" + line.trim() + " \" +");
            wasInner = true;
        } else {
            if (wasInner) {
                sb.append("    \"");
                wasInner = false;
            }
            sb.append(' ');
            sb.append(StringUtils.replace(line.trim(), "\n", " "));
        }
    }

    if (wasInner) {
        sb.setLength(sb.length() - 3);
        sb.append("\";");
    } else {
        sb.append("\";");
    }
    dstTA.setText(sb.toString());

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            dstTA.requestFocus();
            dstTA.selectAll();
            UIHelper.setTextToClipboard(dstTA.getText());
        }
    });

}

From source file:eu.asterics.mw.services.AstericsErrorHandling.java

/**
 * This method is used by the components to report an error. It logs the error in "warning" logger
 *  and sets the status of the ARE to "ERROR" to denote that an error has occurred 
 * @param component the component instance that reports the error
 * @param errorMsg the error message//from  w  w  w  .java 2  s.  c om
 */
public void reportError(IRuntimeComponentInstance component, final String errorMsg) {
    if (component != null) {
        String componentID = DeploymentManager.instance
                .getIRuntimeComponentInstanceIDFromIRuntimeComponentInstance(component);
        if (componentID != null) {
            //System.out.println("componentID: "+componentID);
            logger.warning(componentID + ": " + errorMsg);
            setStatusObject(AREStatus.ERROR.toString(), componentID, errorMsg);
        }
    }

    AREProperties props = AREProperties.instance;
    if (props.checkProperty("showErrorDialogs", "1")) {

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                ErrorLogPane.appendLog(errorMsg);
                DeploymentManager.instance.setStatus(AREStatus.ERROR);

                AstericsErrorHandling.this.notifyAREEventListeners("onAreError", errorMsg);

                JOptionPane op = new JOptionPane(errorMsg, JOptionPane.WARNING_MESSAGE);

                JDialog dialog = op.createDialog("AsTeRICS Runtime Environment:");
                dialog.setAlwaysOnTop(true);
                dialog.setModal(false);
                dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                dialog.setVisible(true);
            }
        });
    }
}

From source file:ru.codemine.pos.ui.salespanel.QuantitySetupWindow.java

public void showWindow() {
    if (!actionListenersInit)
        setupActionListeners();/*  w  ww  . java2s  . c o  m*/
    mainWindow.blockBarcodeInput();

    Product product = salesPanel.getChequeSetupPanel().getSelectedProduct();
    if (product == null) {
        mainWindow.unblockBarcodeInput();
        return;
    }

    int maxQuantity = storeService.getAvaibleStocksOnRetail(product);
    onStoresLabel.setText("?: " + String.valueOf(maxQuantity) + " .");
    setTitle("? - " + product.getName());
    spinner.setModel(new SpinnerNumberModel(1, 1, maxQuantity, 1));

    JTextField ft = ((WebSpinner.DefaultEditor) spinner.getEditor()).getTextField();
    ft.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            final JTextComponent txtcomp = (JTextComponent) e.getSource();
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    txtcomp.selectAll();
                }
            });
        }
    });
    ft.requestFocus();

    setVisible(true);
}