Example usage for javax.swing UIManager getSystemLookAndFeelClassName

List of usage examples for javax.swing UIManager getSystemLookAndFeelClassName

Introduction

In this page you can find the example usage for javax.swing UIManager getSystemLookAndFeelClassName.

Prototype

public static String getSystemLookAndFeelClassName() 

Source Link

Document

Returns the name of the LookAndFeel class that implements the native system look and feel if there is one, otherwise the name of the default cross platform LookAndFeel class.

Usage

From source file:org.kevinferrare.meijiChokoSolver.run.GuiSolverStarter.java

@Override
public void start(Puzzle puzzle) {
    log.debug("Starting in GUI mode");
    //set the gui look and feel to the system instead of the java not so beautiful one
    try {//from   ww  w  .j a  v  a2 s  . c  om
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        e.printStackTrace();
    }
    new SolverWindow(puzzle);
}

From source file:org.kse.gui.crypto.DUpgradeCryptoStrength.java

public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    EventQueue.invokeLater(new Runnable() {
        @Override//from  w w w. ja va 2s. com
        public void run() {
            try {
                DUpgradeCryptoStrength dialog = new DUpgradeCryptoStrength(new JFrame());
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }

                    @Override
                    public void windowDeactivated(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:org.languagetool.openoffice.Main.java

private boolean javaVersionOkay() {
    String version = System.getProperty("java.version");
    if (version != null && (version.startsWith("1.0") || version.startsWith("1.1") || version.startsWith("1.2")
            || version.startsWith("1.3") || version.startsWith("1.4") || version.startsWith("1.5")
            || version.startsWith("1.6") || version.startsWith("1.7"))) {
        MessageHandler.showMessage("Error: LanguageTool requires Java 8 or later. Current version: " + version);
        return false;
    }// w  w w .  j  a v  a  2 s  .  c o m
    try {
        // do not set look and feel for on Mac OS X as it causes the following error:
        // soffice[2149:2703] Apple AWT Java VM was loaded on first thread -- can't start AWT.
        if (!System.getProperty("os.name").contains("OS X")) {
            // Cross-Platform Look And Feel @since 3.7
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
    } catch (Exception ignored) {
        // Well, what can we do...
    }
    return true;
}

From source file:org.multibit.viewsystem.swing.action.ShowPreferencesSubmitAction.java

/**
 * Change preferences./*from w w  w . ja va2  s . c o m*/
 */
@Override
public void actionPerformed(ActionEvent event) {
    //        boolean feeValidationError = false;

    boolean wantToFireDataStructureChanged = false;

    try {
        if (mainFrame != null) {
            mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        }

        //            String updateStatusText = "";

        if (dataProvider != null) {
            controller.getModel().setUserPreference(CoreModel.PREVIOUS_UNDO_CHANGES_TEXT,
                    dataProvider.getPreviousUndoChangesText());

            //                String previousSendFee = dataProvider.getPreviousSendFee();
            //                String newSendFee = dataProvider.getNewSendFee();
            //                controller.getModel().setUserPreference(BitcoinModel.PREVIOUS_SEND_FEE, previousSendFee);
            //
            //                // Check fee is set.
            //                if (newSendFee == null || "".equals(newSendFee)) {
            //                    // Fee must be set validation error.
            //                    controller.getModel().setUserPreference(BitcoinModel.SEND_FEE, previousSendFee);
            //                    feeValidationError = true;
            //                    updateStatusText = controller.getLocaliser().getString("showPreferencesPanel.aFeeMustBeSet");
            //                }
            //
            //                if (!feeValidationError) {
            //                    if (newSendFee.startsWith(ShowPreferencesPanel.UNPARSEABLE_FEE)) {
            //                        String newSendFeeTrimmed = newSendFee.substring(ShowPreferencesPanel.UNPARSEABLE_FEE.length() + 1);
            //                        // Recycle the old fee and set status message.
            //                        controller.getModel().setUserPreference(BitcoinModel.SEND_FEE, previousSendFee);
            //                        feeValidationError = true;
            //                        updateStatusText = controller.getLocaliser().getString("showPreferencesPanel.couldNotUnderstandFee",
            //                                new Object[] { newSendFeeTrimmed });
            //                    }
            //                }
            //                
            //                if (!feeValidationError) {
            //                    try {
            //                        // Check fee is a number.
            //                        BigInteger feeAsBigInteger = Utils.toNanoCoins(newSendFee);
            //
            //                        // Check fee is at least the minimum fee.
            //                        if (feeAsBigInteger.compareTo(BitcoinModel.SEND_MINIMUM_FEE) < 0) {
            //                            feeValidationError = true;
            //                            updateStatusText = controller.getLocaliser().getString(
            //                                    "showPreferencesPanel.feeCannotBeSmallerThanMinimumFee");
            //                        } else {
            //                            if (feeAsBigInteger.compareTo(BitcoinModel.SEND_MAXIMUM_FEE) >= 0) {
            //                                feeValidationError = true;
            //                                updateStatusText = controller.getLocaliser().getString(
            //                                        "showPreferencesPanel.feeCannotBeGreaterThanMaximumFee");
            //                            } else {
            //                                // Fee is ok.
            //                                controller.getModel().setUserPreference(BitcoinModel.SEND_FEE, newSendFee);
            //                            }
            //                        }
            //                    } catch (NumberFormatException nfe) {
            //                        // Recycle the old fee and set status message.
            //                        controller.getModel().setUserPreference(BitcoinModel.SEND_FEE, previousSendFee);
            //                        feeValidationError = true;
            //                        updateStatusText = controller.getLocaliser().getString("showPreferencesPanel.couldNotUnderstandFee",
            //                                new Object[] { newSendFee });
            //                    } catch (ArithmeticException ae) {
            //                        // Recycle the old fee and set status message.
            //                        controller.getModel().setUserPreference(BitcoinModel.SEND_FEE, previousSendFee);
            //                        feeValidationError = true;
            //                        updateStatusText = controller.getLocaliser().getString("showPreferencesPanel.couldNotUnderstandFee",
            //                                new Object[] { newSendFee });
            //                    }
            //                }
        }

        // Disable language selection, uncomment to enable
        /*
             String previousLanguageCode = dataProvider.getPreviousUserLanguageCode();
             String newLanguageCode = dataProvider.getNewUserLanguageCode();
             controller.getModel().setUserPreference(CoreModel.PREVIOUS_USER_LANGUAGE_CODE, previousLanguageCode);
                
             if (previousLanguageCode != null && !previousLanguageCode.equals(newLanguageCode)) {
        // New language to set on model.
        controller.getModel().setUserPreference(CoreModel.USER_LANGUAGE_CODE, newLanguageCode);
        wantToFireDataStructureChanged = true;
             }
        */

        // Open URI - use dialog.
        String openUriDialog = dataProvider.getOpenUriDialog();
        if (openUriDialog != null) {
            controller.getModel().setUserPreference(BitcoinModel.OPEN_URI_SHOW_DIALOG, openUriDialog);
        }

        // Open URI - use URI.
        String openUriUseUri = dataProvider.getOpenUriUseUri();
        if (openUriUseUri != null) {
            controller.getModel().setUserPreference(BitcoinModel.OPEN_URI_USE_URI, openUriUseUri);
        }

        // Messaging servers
        boolean messagingServersHasChanged = false;
        String[] previousMessagingServerURLs = dataProvider.getPreviousMessagingServerURLs();
        String[] newMessagingServerURLs = dataProvider.getNewMessagingServerURLs();
        // newMessagingServerURLs might be NULL, and thus clear out the user preference.
        // So let's be explicit and say if no urls are set, we use the default.
        if (newMessagingServerURLs == null) {
            newMessagingServerURLs = CoreModel.DEFAULT_MESSAGING_SERVER_URLS; // not URL encoded but is okay as no strange characters.
        }
        if (!Arrays.equals(previousMessagingServerURLs, newMessagingServerURLs)) {
            messagingServersHasChanged = true;
            String s = StringUtils.join(newMessagingServerURLs, "|");
            controller.getModel().setUserPreference(CoreModel.MESSAGING_SERVERS, s);
        }

        // Font data.
        boolean fontHasChanged = false;
        String previousFontName = dataProvider.getPreviousFontName();
        String newFontName = dataProvider.getNewFontName();

        controller.getModel().setUserPreference(CoreModel.PREVIOUS_FONT_NAME, previousFontName);

        if (newFontName != null) {
            controller.getModel().setUserPreference(CoreModel.FONT_NAME, newFontName);

            if (!newFontName.equals(previousFontName)) {
                fontHasChanged = true;
            }
        }

        String previousFontStyle = dataProvider.getPreviousFontStyle();
        String newFontStyle = dataProvider.getNewFontStyle();

        controller.getModel().setUserPreference(CoreModel.PREVIOUS_FONT_STYLE, previousFontStyle);

        if (newFontStyle != null) {
            controller.getModel().setUserPreference(CoreModel.FONT_STYLE, newFontStyle);

            if (!newFontStyle.equals(previousFontStyle)) {
                fontHasChanged = true;
            }
        }

        String previousFontSize = dataProvider.getPreviousFontSize();
        String newFontSize = dataProvider.getNewFontSize();

        controller.getModel().setUserPreference(CoreModel.PREVIOUS_FONT_SIZE, previousFontSize);

        if (newFontSize != null) {
            controller.getModel().setUserPreference(CoreModel.FONT_SIZE, newFontSize);

            if (!newFontSize.equals(previousFontSize)) {
                fontHasChanged = true;
            }
        }

        // Look and feel.
        boolean lookAndFeelHasChanged = false;
        String previousLookAndFeel = dataProvider.getPreviousLookAndFeel();
        String newLookAndFeel = dataProvider.getNewLookAndFeel();

        controller.getModel().setUserPreference(CoreModel.LOOK_AND_FEEL, previousLookAndFeel);

        if (newLookAndFeel != null && (!newLookAndFeel.equals(previousLookAndFeel)
                && !newLookAndFeel.equals(UIManager.getLookAndFeel().getName()))) {
            controller.getModel().setUserPreference(CoreModel.LOOK_AND_FEEL, newLookAndFeel);

            lookAndFeelHasChanged = true;
        }
        /*
                    // Currency ticker.
                    boolean showTicker = dataProvider.getNewShowTicker();
                    boolean showBitcoinConvertedToFiat = dataProvider.getNewShowBitcoinConvertedToFiat();
                    boolean showCurrency = dataProvider.getNewShowCurrency();
                    boolean showRate = dataProvider.getNewShowRate();
                    boolean showBid = dataProvider.getNewShowBid();
                    boolean showAsk = dataProvider.getNewShowAsk();
                    boolean showExchange = dataProvider.getNewShowExchange();
                
                    boolean restartTickerTimer = false;
                
                    if (dataProvider.getPreviousShowCurrency() != showCurrency) {
        wantToFireDataStructureChanged = true;
        restartTickerTimer = true;
                    } else if (dataProvider.getPreviousShowBitcoinConvertedToFiat() != showBitcoinConvertedToFiat) {
        wantToFireDataStructureChanged = true;
        if (showBitcoinConvertedToFiat) {
            restartTickerTimer = true;
        }
                    } else if (dataProvider.getPreviousShowTicker() != showTicker || showTicker != dataProvider.isTickerVisible()) {
        wantToFireDataStructureChanged = true;
        if (showTicker) {
            restartTickerTimer = true;
        }
                    } else if (dataProvider.getPreviousShowRate() != showRate) {
        wantToFireDataStructureChanged = true;
        restartTickerTimer = true;
                    } else if (dataProvider.getPreviousShowBid() != showBid) {
        wantToFireDataStructureChanged = true;
        restartTickerTimer = true;
                    } else if (dataProvider.getPreviousShowAsk() != showAsk) {
        wantToFireDataStructureChanged = true;
        restartTickerTimer = true;
                    } else if (dataProvider.getPreviousShowExchange() != showExchange) {
        wantToFireDataStructureChanged = true;
        restartTickerTimer = true;
                    } 
                
                    controller.getModel().setUserPreference(ExchangeModel.TICKER_SHOW, Boolean.valueOf(showTicker).toString());
                    controller.getModel().setUserPreference(ExchangeModel.SHOW_BITCOIN_CONVERTED_TO_FIAT,
                      Boolean.valueOf(showBitcoinConvertedToFiat).toString());
                
                    String columnsToShow = "";
                    if (showCurrency)
        columnsToShow = columnsToShow + " " + TickerTableModel.TICKER_COLUMN_CURRENCY;
                    if (showRate)
        columnsToShow = columnsToShow + " " + TickerTableModel.TICKER_COLUMN_LAST_PRICE;
                    if (showBid)
        columnsToShow = columnsToShow + " " + TickerTableModel.TICKER_COLUMN_BID;
                    if (showAsk)
        columnsToShow = columnsToShow + " " + TickerTableModel.TICKER_COLUMN_ASK;
                    if (showExchange)
        columnsToShow = columnsToShow + " " + TickerTableModel.TICKER_COLUMN_EXCHANGE;
                
                    if ("".equals(columnsToShow)) {
        // A user could just switch all the columns off in the settings
        // so
        // put a 'none' in the list of columns
        // this is to stop the default columns appearing.
        columnsToShow = TickerTableModel.TICKER_COLUMN_NONE;
                    }
                    controller.getModel().setUserPreference(ExchangeModel.TICKER_COLUMNS_TO_SHOW, columnsToShow);
                
                    String previousExchange1 = dataProvider.getPreviousExchange1();
                    String newExchange1 = dataProvider.getNewExchange1();
                    if (newExchange1 != null && !newExchange1.equals(previousExchange1)) {
        controller.getModel().setUserPreference(ExchangeModel.TICKER_FIRST_ROW_EXCHANGE, newExchange1);
        ExchangeData newExchangeData = new ExchangeData();
        newExchangeData.setShortExchangeName(newExchange1);
        this.exchangeController.getModel().getShortExchangeNameToExchangeMap().put(newExchange1, newExchangeData);
        wantToFireDataStructureChanged = true;
        restartTickerTimer = true;
                    }
                
                    String previousCurrency1 = dataProvider.getPreviousCurrency1();
                    String newCurrency1 = dataProvider.getNewCurrency1();
                    if (newCurrency1 != null && !newCurrency1.equals(previousCurrency1)) {
        controller.getModel().setUserPreference(ExchangeModel.TICKER_FIRST_ROW_CURRENCY, newCurrency1);
        String newCurrencyCode = newCurrency1;
        if (ExchangeData.BITCOIN_CHARTS_EXCHANGE_NAME.equals(newExchange1)) {
            // Use only the last three characters - the currency code.
             if (newCurrency1.length() >= 3) {
                newCurrencyCode = newCurrency1.substring(newCurrency1.length() - 3);
            }
        }
        try {
            CurrencyConverter.INSTANCE.setCurrencyUnit(CurrencyUnit.of(newCurrencyCode));
        } catch ( org.joda.money.IllegalCurrencyException e) {
            e.printStackTrace();
        }
        wantToFireDataStructureChanged = true;
        restartTickerTimer = true;
                    }
                
                    String previousShowSecondRow = Boolean.valueOf(dataProvider.getPreviousShowSecondRow()).toString();
                    String newShowSecondRow = Boolean.valueOf(dataProvider.getNewShowSecondRow()).toString();
                    if (newShowSecondRow != null && !newShowSecondRow.equals(previousShowSecondRow)) {
        // New show second row is set on model.
        controller.getModel().setUserPreference(ExchangeModel.TICKER_SHOW_SECOND_ROW, newShowSecondRow);
        wantToFireDataStructureChanged = true;
        restartTickerTimer = true;
                    }
                
                    String previousExchange2 = dataProvider.getPreviousExchange2();
                    String newExchange2 = dataProvider.getNewExchange2();
                    if (newExchange2 != null && !newExchange2.equals(previousExchange2)) {
        controller.getModel().setUserPreference(ExchangeModel.TICKER_SECOND_ROW_EXCHANGE, newExchange2);
        ExchangeData newExchangeData = new ExchangeData();
        newExchangeData.setShortExchangeName(newExchange2);
        this.exchangeController.getModel().getShortExchangeNameToExchangeMap().put(newExchange2, newExchangeData);
        wantToFireDataStructureChanged = true;
        restartTickerTimer = true;
                    }
                
                    String previousCurrency2 = dataProvider.getPreviousCurrency2();
                    String newCurrency2 = dataProvider.getNewCurrency2();
                    if (newCurrency2 != null && !newCurrency2.equals(previousCurrency2)) {
        controller.getModel().setUserPreference(ExchangeModel.TICKER_SECOND_ROW_CURRENCY, newCurrency2);
        wantToFireDataStructureChanged = true;
        restartTickerTimer = true;
                    }
                            
                    String previousOerApicode = dataProvider.getPreviousOpenExchangeRatesApiCode();
                    String newOerApiCode = dataProvider.getNewOpenExchangeRatesApiCode();
                    if (newOerApiCode != null && !newOerApiCode.equals(previousOerApicode)) {
        wantToFireDataStructureChanged = true;
        restartTickerTimer = true;
                
        controller.getModel().setUserPreference(ExchangeModel.OPEN_EXCHANGE_RATES_API_CODE, newOerApiCode);
                    }
        */
        // Can undo.
        controller.getModel().setUserPreference(CoreModel.CAN_UNDO_PREFERENCES_CHANGES, "true");
        /*
                    if (restartTickerTimer) {
        // Reinitialise the currency converter.
        CurrencyConverter.INSTANCE.initialise(controller);
                
        // Cancel any existing timer.
        if (mainFrame.getTickerTimer1() != null) {
            mainFrame.getTickerTimer1().cancel();
        }
        if (mainFrame.getTickerTimer2() != null) {
            mainFrame.getTickerTimer2().cancel();
        }                // Start ticker timer.
        Timer tickerTimer1 = new Timer();
        mainFrame.setTickerTimer1(tickerTimer1);
                
        TickerTimerTask tickerTimerTask1 = new TickerTimerTask(this.exchangeController, mainFrame, true);
        tickerTimerTask1.createExchangeObjects(controller.getModel().getUserPreference(ExchangeModel.TICKER_FIRST_ROW_EXCHANGE));
        mainFrame.setTickerTimerTask1(tickerTimerTask1);
                
        tickerTimer1.schedule(tickerTimerTask1, 0, TickerTimerTask.DEFAULT_REPEAT_RATE);
                
        boolean showSecondRow = Boolean.TRUE.toString().equals(
                controller.getModel().getUserPreference(ExchangeModel.TICKER_SHOW_SECOND_ROW));
                
        if (showSecondRow) {
            Timer tickerTimer2 = new Timer();
            mainFrame.setTickerTimer2(tickerTimer2);
                
            TickerTimerTask tickerTimerTask2 = new TickerTimerTask(this.exchangeController, mainFrame, false);
            tickerTimerTask2.createExchangeObjects(controller.getModel().getUserPreference(
                    ExchangeModel.TICKER_SECOND_ROW_EXCHANGE));
            mainFrame.setTickerTimerTask2(tickerTimerTask2);
                
            tickerTimer2.schedule(tickerTimerTask2, TickerTimerTask.TASK_SEPARATION, TickerTimerTask.DEFAULT_REPEAT_RATE);
        }
                    }
        */
        if (messagingServersHasChanged) {
            // TODO: Maybe something here so messaging servers are updated and go live immediately?
            // Currently servers are set here in class SendRequest:
            /*
                    public void setMessage(CoinSparkMessagePart [] MessageParts,String [] DeliveryServers)
            */

        }

        if (fontHasChanged) {
            wantToFireDataStructureChanged = true;
        }

        if (lookAndFeelHasChanged) {
            try {
                if (CoreModel.SYSTEM_LOOK_AND_FEEL.equals(newLookAndFeel)) {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } else {
                    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                        if (newLookAndFeel.equalsIgnoreCase(info.getName())) {
                            UIManager.setLookAndFeel(info.getClassName());
                            break;
                        }
                    }
                }
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (UnsupportedLookAndFeelException e) {
                e.printStackTrace();
            }
        }

        Font newFont = dataProvider.getSelectedFont();
        if (newFont != null) {
            UIManager.put("ToolTip.font", newFont);
        }

        if (wantToFireDataStructureChanged || lookAndFeelHasChanged) {
            ColorAndFontConstants.init();
            FontSizer.INSTANCE.initialise(controller);
            HelpContentsPanel.clearBrowser();

            // Switch off blinks.
            this.bitcoinController.getModel().setBlinkEnabled(false);

            try {
                controller.fireDataStructureChanged();
                SwingUtilities.updateComponentTreeUI(mainFrame);
            } finally {
                // Switch blinks back on.
                this.bitcoinController.getModel().setBlinkEnabled(true);
            }
        }
    } finally {
        if (mainFrame != null) {
            mainFrame.setCursor(Cursor.getDefaultCursor());
        }
    }
}

From source file:org.n52.ifgicopter.spf.SPFRegistry.java

/**
 * Initialize all registered modules./*from  ww  w .  j  a v a 2s .com*/
 * 
 * @throws ClassNotFoundException
 *         if the class to be reflected is not in the classpath.
 * @throws InstantiationException
 *         if the class to be reflected could not be instantiated.
 * @throws IllegalAccessException
 *         if the class to be reflected is not accessible
 */
private void initModules() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e) {
        log.warn(e.getMessage(), e);
    } catch (InstantiationException e) {
        log.warn(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        log.warn(e.getMessage(), e);
    } catch (UnsupportedLookAndFeelException e) {
        log.warn(e.getMessage(), e);
    }

    SplashDialog splash = new SplashDialog();
    Thread t = new Thread(splash);
    t.setPriority(Thread.MAX_PRIORITY);
    t.start();

    this.modules = new ArrayList<IModule>();
    this.engine = new SPFEngine();
    this.mainFrame = new SPFMainFrame();
    this.engine.setMainFrame(this.mainFrame);
    this.engine.addPositionListener(this.mainFrame.getMapPanel());
    this.statusChangeListeners = new ArrayList<IStatusChangeListener>();
    this.outputMessageListeners = new ArrayList<IOutputMessageListener>();

    /*
     * IOutputPlugins
     */
    List<IOutputPlugin> oplugs = new ArrayList<IOutputPlugin>();

    String tmp = this.properties.getProperty(OUTPUT_PLUGINS_PROP);
    if (tmp == null)
        log.warn("No config parameter " + OUTPUT_PLUGINS_PROP + " given.");
    else {

        tmp = tmp.trim();
        String[] oplugins = tmp.split(LIST_SEPARATOR);
        String[] params = null;
        Class<?>[] paramsClassArray = null;

        if (!tmp.equals("")) {

            // int opCount = 1;
            for (String classString : oplugins) {
                classString = classString.trim();

                if (classString.length() == 0)
                    continue;

                /*
                 * do we have any parameters?
                 */
                int pos = classString.indexOf("(");
                if (pos > 0) {
                    params = classString.substring(pos + 1, classString.length() - 1).split(",");
                    paramsClassArray = new Class[params.length];
                    if (params.length > 0) {
                        for (int i = 0; i < params.length; i++) {
                            paramsClassArray[i] = String.class;
                            params[i] = params[i].trim();
                        }
                        classString = classString.substring(0, pos);
                    }
                }

                Class<?> clazz;
                try {
                    clazz = Class.forName(classString);
                } catch (ClassNotFoundException e) {
                    log.error(null, e);
                    continue;
                } catch (NoClassDefFoundError e) {
                    log.error(null, e);
                    continue;
                }

                try {
                    IOutputPlugin oplugin = null;

                    if (params != null && params.length > 0) {
                        Constructor<?> constructor = clazz.getConstructor(paramsClassArray);
                        oplugin = (IOutputPlugin) constructor.newInstance((Object[]) params);
                        params = null;
                        paramsClassArray = null;
                    } else {
                        try {
                            oplugin = ((IOutputPlugin) clazz.newInstance());
                        } catch (InstantiationException e) {
                            log.error(null, e);
                            continue;
                        }
                    }

                    oplugs.add(oplugin);

                } catch (IllegalAccessException e) {
                    log.error("Could not access class with name '" + classString + "'.", e);
                } catch (InstantiationException e) {
                    log.error("Could not instantiate class with name '" + classString + "'.", e);
                } catch (SecurityException e) {
                    log.error(null, e);
                } catch (NoSuchMethodException e) {
                    log.error(
                            "A constructor with "
                                    + ((paramsClassArray == null) ? "NULL"
                                            : Integer.valueOf(paramsClassArray.length))
                                    + " String arguments for Class " + clazz.getName() + " could not be found.",
                            e);
                } catch (IllegalArgumentException e) {
                    log.error(null, e);
                } catch (InvocationTargetException e) {
                    log.error(null, e);
                } catch (ClassCastException e) {
                    log.error(clazz.getName() + " is not an instance of IOutputPlugin! Could not instantiate.",
                            e);
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }

                // opCount++;
            }
        } else
            log.warn(OUTPUT_PLUGINS_PROP + " is empty, no output plugins defined.");
    }

    /*
     * worker threadpool
     */
    this.threadPool = SPFThreadPool.getInstance();
    this.modules.add(this.threadPool);

    /*
     * IInputPlugins
     */
    List<IInputPlugin> iplugs = new ArrayList<IInputPlugin>();

    tmp = this.properties.getProperty(INPUT_PLUGINS_PROP);
    if (tmp == null) {
        log.warn("No config parameter " + INPUT_PLUGINS_PROP + " given.");
    } else {
        tmp = tmp.trim();
        String[] params = null;
        Class<?>[] paramsClassArray = null;
        String[] iplugins = tmp.split(LIST_SEPARATOR);

        if (!tmp.equals("")) {
            for (String classString : iplugins) {
                classString = classString.trim();

                if (classString.length() == 0)
                    continue;

                /*
                 * do we have any parameters?
                 */
                int pos = classString.indexOf("(");
                if (pos > 0) {
                    params = classString.substring(pos + 1, classString.length() - 1).split(",");
                    paramsClassArray = new Class[params.length];
                    if (params.length > 0) {
                        for (int i = 0; i < params.length; i++) {
                            paramsClassArray[i] = String.class;
                            params[i] = params[i].trim();
                        }
                        classString = classString.substring(0, pos);
                    }
                }

                Class<?> clazz;
                try {
                    clazz = Class.forName(classString);
                } catch (ClassNotFoundException e) {
                    log.error(null, e);
                    continue;
                } catch (NoClassDefFoundError e) {
                    log.error(null, e);
                    continue;
                }

                if (clazz != null) {
                    IInputPlugin iplugin = null;
                    if (pos > 0) {
                        try {
                            Constructor<?> constructor = clazz.getConstructor(paramsClassArray);
                            iplugin = (IInputPlugin) constructor.newInstance((Object[]) params);
                        } catch (IllegalAccessException e) {
                            log.error("Could not access class with name '" + classString + "'.", e);
                        } catch (InstantiationException e) {
                            log.error("Could not instantiate class with name '" + classString + "'.", e);
                        } catch (SecurityException e) {
                            log.error(null, e);
                        } catch (NoSuchMethodException e) {
                            log.error("A constructor with "
                                    + ((paramsClassArray == null) ? "NULL"
                                            : Integer.valueOf(paramsClassArray.length))
                                    + " String arguments for Class " + clazz.getName() + " could not be found.",
                                    e);
                        } catch (IllegalArgumentException e) {
                            log.error(null, e);
                        } catch (InvocationTargetException e) {
                            log.error(null, e);
                        } catch (ClassCastException e) {
                            log.error(clazz.getName()
                                    + " is not an instance of IInputPlugin! Could not instantiate.", e);
                        }

                        params = null;
                        paramsClassArray = null;
                    } else {
                        try {
                            iplugin = (IInputPlugin) clazz.newInstance();
                        } catch (InstantiationException e) {
                            log.error(null, e);
                            continue;
                        }
                    }
                    iplugs.add(iplugin);
                }
            }
        } else
            log.warn(INPUT_PLUGINS_PROP + " is empty, no input plugins defined.");
    }

    /*
     * AbstractDataProcessors
     */
    tmp = this.properties.getProperty(ABSTRACT_DATA_PROCESSORS).trim();
    String[] dps = tmp.split(LIST_SEPARATOR);

    this.dataProcessors = new ArrayList<Class<?>>();
    if (!tmp.equals("")) {
        for (String classString : dps) {
            String[] params = null;
            Class<?>[] paramsClassArray = null;
            classString = classString.trim();

            /*
             * do we have any parameters?
             */
            int pos = classString.indexOf("(");
            if (pos > 0) {
                params = classString.substring(pos + 1, classString.length() - 1).split(",");
                paramsClassArray = new Class[params.length];
                if (params.length > 0) {
                    for (int i = 0; i < params.length; i++) {
                        paramsClassArray[i] = String.class;
                        params[i] = params[i].trim();
                    }
                    classString = classString.substring(0, pos);
                }
            }

            Class<?> clazz;
            try {
                clazz = Class.forName(classString);
            } catch (ClassNotFoundException e) {
                log.error(null, e);
                continue;
            } catch (NoClassDefFoundError e) {
                log.error(null, e);
                continue;
            }

            this.dataProcessors.add(clazz);
        }
    }

    loadExtensions();

    splash.activateProgressBar(
            this.modules.size() + this.dataProcessors.size() + iplugs.size() + oplugs.size());

    /*
     * initialise all modules
     */
    for (IModule module : this.modules) {
        if (module != null) {
            try {
                module.init();
            } catch (Exception e) {
                log.warn(null, e);
            }
        }
        splash.processFinished();
    }

    /*
     * as a last step startup of all output and input plugins as they should not create data before other
     * parts are running.
     */
    for (IOutputPlugin iOutputPlugin : oplugs) {
        if (iOutputPlugin == null)
            continue;
        try {
            registerOutputPlugin(iOutputPlugin);
        } catch (Throwable e) {
            log.warn(e.getMessage(), e);
        }
        splash.processFinished();
    }

    for (IInputPlugin iInputPlugin : iplugs) {
        if (iInputPlugin == null)
            continue;
        try {
            registerInputPlugin(iInputPlugin);
        } catch (Throwable e) {
            log.warn(e.getMessage(), e);
        }
        splash.processFinished();
    }

    /*
     * add all status change listeners
     */
    this.statusChangeListeners.add(this.mainFrame);
    this.outputMessageListeners.add(this.mainFrame);

    /*
     * set the default view
     */
    this.mainFrame.switchToDefaultTab();

    splash.removeSelf();

    this.mainFrame.setVisible(true);
    this.engine.start();

    lifecycleLog.info("Module loading completed.");
}

From source file:org.nebulaframework.ui.swing.cluster.ClusterManagerStarter.java

/**
 * Starts execution of a ClusterManager instance on the
 * system./*from ww w .  j av  a  2s .  c  om*/
 * 
 * @param args Command Line Arguments
 */
public static void main(String[] args) {

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        e.printStackTrace();
    }

    JWindow splash = ClusterMainUI.showSplash();

    try {
        Grid.startClusterManager();
    } catch (Exception e) {
        splash.setVisible(false);
        log.error("Exception while starting", e);

        JOptionPane.showMessageDialog(null,
                "Unable to start ClusterManager due to Exception." + "\nSee StackTrace (log) for details",
                "Nebula Cluster", JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }

    ClusterMainUI ui = ClusterMainUI.create();
    ui.setVisible(true);
    splash.setVisible(false);
    splash.dispose();
    log.info("[UI] Initialized");
}

From source file:org.nebulaframework.ui.swing.node.GridNodeStarter.java

/**
 * Starts execution of a ClusterManager instance on the
 * system.//from w w w.j  a v a 2 s  .  co m
 * <p>
 * Note that it is possible to start a GridNode
 * with optional {@code -silent} argument, which is 
 * suitable for setting up GridNodes to start up
 * along with the O/S.
 * 
 * @param args Command Line Arguments
 */
public static void main(String[] args) {

    //Log4JConfiguration.configure();

    // Process Arugments
    processArgs(args);

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        e.printStackTrace();
    }

    JWindow splash = null;
    if (!silentMode) {
        splash = NodeMainUI.showSplash();
    }

    try {
        Grid.startGridNode();
    } catch (DiscoveryFailureException ex) {
        log.warn("Discovery Failed");
    } catch (Exception e) {

        log.error("Exception while starting", e);
        e.printStackTrace();

        if (!silentMode) {
            splash.setVisible(false);
            JOptionPane.showMessageDialog(null,
                    "Unable to start GridNode due to Exception." + "\nSee StackTrace (log) for details",
                    "Nebula Grid", JOptionPane.ERROR_MESSAGE);
        }

        System.exit(1);
    }

    NodeMainUI ui = NodeMainUI.create();

    // Show if not Silent Mode
    if (!silentMode) {
        splash.setVisible(false);
        splash.dispose();
        ui.setVisible(true);
    }

    log.info("[UI] Initialized");

    if (!Grid.isNode()) {
        log.warn("[GridNode] Not connected to Cluster");
    }
}

From source file:org.ngrinder.recorder.Recorder.java

private static String getLookAndFeelClassName() {
    return UIManager.getSystemLookAndFeelClassName();
}

From source file:org.norvelle.addressdiscoverer.AddressDiscoverer.java

@SuppressWarnings("LeakingThisInConstructor")
public AddressDiscoverer() throws Exception {
    AddressDiscoverer.application = this;

    // First setup our logger. The ORMLite logger is prolix and useless,
    // so we redirect it to a temp file.
    System.setProperty(LocalLog.LOCAL_LOG_FILE_PROPERTY,
            System.getProperty("java.io.tmpdir") + File.separator + "addressdiscoverer.ormlite.log");
    this.checkSettingsDirExists();
    logger.setLevel(Level.SEVERE);
    FileHandler fh = new FileHandler(this.settingsDirname + File.separator + "debug.log", 8096, 1, true);
    logger.addHandler(fh);/*from   w w  w. j  a v a 2  s .  c o m*/
    SimpleFormatter formatter = new SimpleFormatter();
    fh.setFormatter(formatter);
    logger.info("Starting AddressDiscoverer");

    // Load our properties and attach the database, creating it if it doesn't exist
    this.loadProperties();
    this.attachDatabase();
    KnownLastName.initialize(this.settingsDirname);
    KnownFirstName.initialize(this.settingsDirname);
    KnownSpanishWord.initialize(this.settingsDirname);
    Abbreviations.initialize(this.settingsDirname);
    GrammarParticles.initialize(this.settingsDirname);
    GenderDeterminer.initialize(this.settingsDirname);

    // Create our GUI
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    window = new MainWindow(this);
    window.setTitle("AddressDiscoverer");
    window.setExtendedState(window.getExtendedState() | java.awt.Frame.MAXIMIZED_BOTH);
    window.setVisible(true);
}

From source file:org.opendatakit.appengine.updater.UpdaterWindow.java

/**
 * Launch the application.//from   w w  w.  j  a v  a 2s.c  o m
 */
public static void main(String[] args) {

    translations = ResourceBundle.getBundle(TranslatedStrings.class.getCanonicalName(), Locale.getDefault());

    Options options = addOptions();

    // get location of this jar
    String reflectedJarPath = UpdaterWindow.class.getProtectionDomain().getCodeSource().getLocation().getFile();
    // remove %20 substitutions.
    reflectedJarPath = reflectedJarPath.replace("%20", " ");
    File myJar = new File(reflectedJarPath, Preferences.JAR_NAME);
    System.out.println("CodeSource Location: " + myJar.getAbsolutePath());
    File cleanJarPath = null;
    if (myJar.exists()) {
        try {
            cleanJarPath = myJar.getCanonicalFile();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
    if (cleanJarPath == null) {
        // try finding this within our working directory
        String dir = System.getProperty("user.dir");
        if (dir != null) {
            File myWD = new File(dir);
            if (myWD.exists()) {
                myJar = new File(myWD, Preferences.JAR_NAME);
                System.out.println("user.dir path: " + myJar.getAbsolutePath());
                if (myJar.exists()) {
                    try {
                        cleanJarPath = myJar.getCanonicalFile();
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
            }
        }
    }

    if (cleanJarPath != null) {
        myJarDir = cleanJarPath.getParentFile();
        System.out.println(fmt(TranslatedStrings.DIR_RUNNABLE_JAR, myJarDir.getAbsolutePath()));
    } else {
        myJarDir = null;
    }

    CommandLineParser parser = new DefaultParser();
    final CommandLine cmdArgs;

    try {
        cmdArgs = parser.parse(options, args);
    } catch (ParseException e1) {
        System.out.println(fmt(TranslatedStrings.LAUNCH_FAILED, e1.getMessage()));
        showHelp(options);
        System.exit(1);
        return;
    }

    if (cmdArgs.hasOption(ArgumentNameConstants.HELP)) {
        showHelp(options);
        System.exit(0);
        return;
    }

    if (cmdArgs.hasOption(ArgumentNameConstants.VERSION)) {
        showVersion();
        System.exit(0);
        return;
    }

    if (myJarDir == null && !cmdArgs.hasOption(ArgumentNameConstants.INSTALL_ROOT)) {
        System.out.println(fmt(TranslatedStrings.INSTALL_ROOT_REQUIRED, Preferences.JAR_NAME,
                ArgumentNameConstants.INSTALL_ROOT));
        showHelp(options);
        System.exit(1);
        return;
    }

    // required for all operations
    if (cmdArgs.hasOption(ArgumentNameConstants.NO_UI) && !cmdArgs.hasOption(ArgumentNameConstants.EMAIL)) {
        System.out.println(fmt(TranslatedStrings.ARG_IS_REQUIRED, ArgumentNameConstants.EMAIL));
        showHelp(options);
        System.exit(1);
        return;
    }

    // update appEngine with the local configuration
    if (cmdArgs.hasOption(ArgumentNameConstants.UPLOAD)) {

        if (cmdArgs.hasOption(ArgumentNameConstants.CLEAR)) {
            System.out.println(fmt(TranslatedStrings.CONFLICTING_ARGS_CMD, ArgumentNameConstants.UPLOAD,
                    ArgumentNameConstants.CLEAR));
        }

        if (cmdArgs.hasOption(ArgumentNameConstants.ROLLBACK)) {
            System.out.println(fmt(TranslatedStrings.CONFLICTING_ARGS_CMD, ArgumentNameConstants.UPLOAD,
                    ArgumentNameConstants.ROLLBACK));
        }

        if (!cmdArgs.hasOption(ArgumentNameConstants.EMAIL)) {
            System.out.println(fmt(TranslatedStrings.ARG_IS_REQUIRED_CMD, ArgumentNameConstants.EMAIL));
        }
        showHelp(options);
        System.exit(1);
        return;
    }

    // rollback any stuck outstanding configuration transaction on appEngine infrastructure
    if (cmdArgs.hasOption(ArgumentNameConstants.ROLLBACK)) {

        if (cmdArgs.hasOption(ArgumentNameConstants.CLEAR)) {
            System.out.println(fmt(TranslatedStrings.CONFLICTING_ARGS_CMD, ArgumentNameConstants.ROLLBACK,
                    ArgumentNameConstants.CLEAR));
        }

        if (cmdArgs.hasOption(ArgumentNameConstants.UPLOAD)) {
            System.out.println(fmt(TranslatedStrings.CONFLICTING_ARGS_CMD, ArgumentNameConstants.ROLLBACK,
                    ArgumentNameConstants.UPLOAD));
        }

        if (!cmdArgs.hasOption(ArgumentNameConstants.EMAIL)) {
            System.out.println(fmt(TranslatedStrings.ARG_IS_REQUIRED_CMD, ArgumentNameConstants.EMAIL));
        }
        showHelp(options);
        System.exit(1);
        return;
    }

    if (cmdArgs.hasOption(ArgumentNameConstants.CLEAR)) {

        if (cmdArgs.hasOption(ArgumentNameConstants.ROLLBACK)) {
            System.out.println(fmt(TranslatedStrings.CONFLICTING_ARGS_CMD, ArgumentNameConstants.CLEAR,
                    ArgumentNameConstants.ROLLBACK));
        }

        if (cmdArgs.hasOption(ArgumentNameConstants.UPLOAD)) {
            System.out.println(fmt(TranslatedStrings.CONFLICTING_ARGS_CMD, ArgumentNameConstants.CLEAR,
                    ArgumentNameConstants.UPLOAD));
        }
        showHelp(options);
        System.exit(1);
        return;
    }

    if (!cmdArgs.hasOption(ArgumentNameConstants.NO_UI)) {

        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    // Set System L&F
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

                    UpdaterWindow window = new UpdaterWindow(cmdArgs);
                    window.frame.setTitle(fmt(TranslatedStrings.AGG_INSTALLER_VERSION, Preferences.VERSION));
                    ImageIcon icon = new ImageIcon(
                            UpdaterWindow.class.getClassLoader().getResource("odkupdater.png"));
                    window.frame.setIconImage(icon.getImage());
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    } else {

        try {

            UpdaterCLI aggregateInstallerCLI = new UpdaterCLI(cmdArgs);
            aggregateInstallerCLI.run();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}