Example usage for javax.swing SwingUtilities updateComponentTreeUI

List of usage examples for javax.swing SwingUtilities updateComponentTreeUI

Introduction

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

Prototype

public static void updateComponentTreeUI(Component c) 

Source Link

Document

A simple minded look and feel change: ask each node in the tree to updateUI() -- that is, to initialize its UI property with the current look and feel.

Usage

From source file:src.gui.ItSIMPLE.java

/**
 * This method initializes defaultItem//ww w  .j  a v a 2s  .c o m
 *
 * @return javax.swing.JMenuItem
 */
private JMenuItem getDefaultMenuItem() {
    if (defaultMenuItem == null) {
        defaultMenuItem = new JMenuItem();
        defaultMenuItem.setText("Default");
        defaultMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    SwingUtilities.updateComponentTreeUI(instance);
                    itSettings.getChild("generalSettings").getChild("graphics").getChild("appearence")
                            .setText("Default");
                    XMLUtilities.writeToFile("resources/settings/itSettings.xml", itSettings.getDocument());
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        });
    }
    return defaultMenuItem;
}

From source file:org.f2o.absurdum.puck.gui.PuckFrame.java

/**
 * Sets the L&F to://from  w ww. j a v  a  2  s.  co  m
 * The default cross-platform look and feel if the passed string is (case-insensitive) "Default",
 * The system look and feel if the passed string is (case-insensitive) "System",
 * The first look and feel found containing (case-insensitive) the string in its name (e.g. "Nimbus"), if any.
 * If the L&F specified is the current L&F, nothing will be done.
 * @param lookAndFeel
 */
public void setLookAndFeel(String lookAndFeel) {
    boolean changed = false;
    try {
        if ("default".equals(lookAndFeel.toLowerCase()) && !UIManager.getLookAndFeel().getClass().getName()
                .equals(UIManager.getCrossPlatformLookAndFeelClassName())) {
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
            changed = true;
        } else if ("system".equals(lookAndFeel.toLowerCase()) && !UIManager.getLookAndFeel().getClass()
                .getName().equals(UIManager.getSystemLookAndFeelClassName())) {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            changed = true;
        } else {
            LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels();
            for (int i = 0; i < lfs.length; i++) {
                if (lfs[i].getName().toLowerCase().contains(lookAndFeel.toLowerCase()) && !UIManager
                        .getLookAndFeel().getName().toLowerCase().contains(lookAndFeel.toLowerCase())) {
                    UIManager.setLookAndFeel(lfs[i].getClassName());
                    changed = true;
                    break;
                }
            }
        }
    } catch (Exception e) //class not found, instantiation exception, etc. (shouldn't happen)
    {
        e.printStackTrace();
    }
    if (changed) {
        SwingUtilities.updateComponentTreeUI(this);
        PuckConfiguration.getInstance().setProperty("look", lookAndFeel);
    }
}

From source file:org.gcaldaemon.gui.ConfigEditor.java

public final void actionPerformed(ActionEvent evt) {

    // Common actions
    Object source = evt.getSource();
    if (source == null) {
        return;/*from   w ww. j a  va  2s  . c o  m*/
    }
    if (source == exitMenu) {
        exit();
        return;
    }
    if (source == saveMenu) {
        save();
        return;
    }
    if (source == logMenu) {
        status(Messages.getString("log.viewer")); //$NON-NLS-1$
        new LogDialog(this, config);
        return;
    }
    if (source == transMenu) {
        status(Messages.getString("translate")); //$NON-NLS-1$
        TranslatorDialog translator = new TranslatorDialog(this);
        String code = translator.getSelectedLanguage();
        if (code != null) {
            setLanguage(code);
        }
        return;
    }
    if (source == aboutMenu) {
        info(Messages.getString("about"), Messages.getString("config.editor") + " - " + Configurator.VERSION); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        return;
    }
    if (source instanceof JMenuItem) {
        JMenuItem item = (JMenuItem) source;
        String param = item.getName();
        if (param != null && param.length() > 1) {
            if (param.charAt(0) == '!') {
                param = param.substring(1);
                int i = param.indexOf('[');
                if (i > 0) {
                    param = param.substring(0, i).trim();
                }
                setLanguage(param);
            } else {
                status(item.getText());
                setLookAndFeel(param.substring(1));
                SwingUtilities.updateComponentTreeUI(this);
            }
        }
    }
}

From source file:org.intermine.install.swing.ProjectEditor.java

/**
 * Change the look and feel of the application.
 *
 * @param laf The new Look and Feel information.
 *
 * @return <code>true</code> if the look and feel changed ok, <code>false</code>
 * if not.//from   w  ww . j a v  a  2  s.  c  o m
 *
 * @see <a href="http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/plaf.html#dynamic">
 * The Swing Tutorial</a>
 */
public boolean changeLookAndFeel(LookAndFeelInfo laf) {
    assert SwingUtilities.isEventDispatchThread() : "Can only change L&F from event thread";

    if (laf.getName().equals(UIManager.getLookAndFeel().getName())) {
        return true;
    }

    boolean changeOk = false;
    try {
        UIManager.setLookAndFeel(laf.getClassName());
        SwingUtilities.updateComponentTreeUI(this);
        SwingUtilities.updateComponentTreeUI(modelViewerFrame);
        for (Window w : getOwnedWindows()) {
            SwingUtilities.updateComponentTreeUI(w);
        }

        changeOk = true;
    } catch (Exception e) {
        logger.error("Failed to change look and feel: " + e.getMessage());
        logger.debug("", e);

        int choice = JOptionPane.showConfirmDialog(this,
                Messages.getMessage("preferences.lookandfeel.changefailed.message", e.getMessage()),
                Messages.getMessage("preferences.lookandfeel.changefailed.title"), JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.WARNING_MESSAGE);

        changeOk = choice == JOptionPane.OK_OPTION;
    }

    return changeOk;
}

From source file:org.jab.docsearch.DocSearch.java

private void doHandlers() {
    DsProperties hd = new DsProperties(this, I18n.getString("windowtitle.settings"), true);
    hd.init();// w  w w . j av  a2 s  . co  m
    hd.setVisible(true);

    if (hd.getConfirmed()) {
        // check everything
        switch (hd.getReturnInt()) {
        default: // nothing
            break;
        case 0: // default hdnler
            defaultHndlr = hd.defltHndlrText();
            break;
        case 1: // look and feel
            String newLafChosen = hd.lafSelected();
            // set new LAF if a new one is set
            if ((!newLafChosen.equals("")) && (!newLafChosen.equals(lafChosen))) {
                lafChosen = newLafChosen;
                try {
                    UIManager.setLookAndFeel(lafChosen);
                    SwingUtilities.updateComponentTreeUI(this);
                    setSize(new Dimension(kDefaultX, kDefaultY));
                } catch (Exception e) {
                    logger.error("doHandler() failed", e);
                    showMessage(I18n.getString("error"), e.toString());
                }
            }

            // now for max file size to index
            try {
                long newMFSI = Long.parseLong(hd.maxSizeField());
                if (newMFSI > 0) {
                    newMFSI = newMFSI * 1024;
                }
                setMaxFileSize(newMFSI);
            } catch (NumberFormatException nfe) {
                logger.error("doHandler() failed ", nfe);
                showMessage(I18n.getString("error"), nfe.toString());
            }

            // now for max hits to show
            String newMaxInt = hd.maxFieldText().trim();
            if (!newMaxInt.equals("")) {
                try {
                    int newMaxN = Integer.parseInt(newMaxInt);
                    if ((newMaxN > 0) && (newMaxN < 1000)) {
                        maxNumHitsShown = newMaxN;
                    }
                } catch (NumberFormatException nfe) {
                    logger.error("doHandler() failed", nfe);
                    showMessage(I18n.getString("error"), nfe.toString());
                }
            }

            if (hd.loadExternalSelected()) {
                loadExternal = true;
            } else {
                loadExternal = false;
            }
            break;
        case 2: // index directory
            //
            String newIndexDir = hd.getDsDirFieldText().trim();
            if (!newIndexDir.equals("")) {
                // copy over our files
                if (hd.copyDirFilesSelected()) {
                    // including our index list file
                    copyFiles(fEnv.getIndexDirectory(), newIndexDir);
                    // change the file settings on the DsIndex objects
                    Iterator<DocSearcherIndex> iterator = indexes.iterator();
                    DocSearcherIndex curI;
                    String curIdxrStr = "";
                    while (iterator.hasNext()) {
                        curI = iterator.next();
                        curIdxrStr = curI.getIndexPath();
                        if (curIdxrStr.startsWith(fEnv.getIndexDirectory())) {
                            curI.setIndexPath(newIndexDir + curIdxrStr
                                    .substring(fEnv.getIndexDirectory().length(), curIdxrStr.length()));
                        }
                    }
                    setStatus(I18n.getString("finished_copying"));
                }
                fEnv.setIndexDirectory(newIndexDir);
            }
            String newDirFieldTExt = hd.getTmpFieldText().trim();
            //
            if (!newDirFieldTExt.equals("")) {
                resetTempDir(newDirFieldTExt);
            }
            //
            String newWorkingDirFieldTExt = hd.workingDirFieldText().trim();
            if (!newWorkingDirFieldTExt.equals("")) {
                resetWorkingDir(newWorkingDirFieldTExt);
            }
            break;
        case 3: // email stuff
            gateway = hd.getGateWayFieldText();
            gatewayPwd = hd.gatewayPwdFieldText();
            gatewayUser = hd.gatewayUserFieldText();
            if (hd.sendEmailBxSelected()) {
                sendEmailNotice = "true";
            } else {
                sendEmailNotice = "false";
            }
            if (hd.textRBSelected()) {
                emailFormat = hd.TEXT_FORMAT;
            } else {
                emailFormat = hd.HTML_FORMAT;
            }
            break;
        }
    }
}

From source file:org.jab.docsearch.DocSearch.java

/**
 * Load settings/*  w  w  w .  j  av a 2  s. c o m*/
 */
private void loadSettings() {
    logger.info("loadSettings() entered");

    Properties props = null;

    // check for old incorrect setting file format
    File oldPropsFile = new File(fEnv.getOldUserPreferencesFile());
    if (oldPropsFile.isFile()) {
        logger.log(NoticeLevel.NOTICE, "loadSettings() found old settings file and convert it now");

        props = new Properties();

        // read file and set the properties
        FileReader fileReader = null;
        try {
            fileReader = new FileReader(oldPropsFile);
            int c;
            StringBuilder line = new StringBuilder();
            while ((c = fileReader.read()) != -1) {
                // is end of line
                if (c == '\n' || c == '\r') {
                    String str = line.toString();
                    int pos = str.indexOf('=');
                    if (pos != -1 && pos + 1 != str.length()) {
                        String key = str.substring(0, pos);
                        String value = str.substring(pos + 1);
                        logger.debug("loadSettings() convert " + key + "=" + value);
                        props.setProperty(key, value);
                    }

                    line = new StringBuilder();
                } else {
                    line.append((char) c);
                }
            }
        } catch (IOException ioe) {
            logger.fatal("loadSettings() failed", ioe);
            showMessage(dsErrLdgFi, "\n" + oldPropsFile + "\n\n : " + ioe.toString());
        } finally {
            IOUtils.closeQuietly(fileReader);
        }

        // delete old properties file
        if (!isCDSearchTool) {
            if (!oldPropsFile.delete()) {
                logger.error("loadSettings() can't delete old properties file (" + oldPropsFile + ")");
            }
        }
    } else {
        // loads prefs stored in saveSettings
        props = loadProperties(fEnv.getUserPreferencesFile());
    }

    // sendEmailNotice
    String tmpStr = props.getProperty("sendEmailNotice", "");
    if (!"".equals(tmpStr)) {
        sendEmailNotice = tmpStr;
    }

    // numAdminEmails
    tmpStr = props.getProperty("numAdminEmails", "");
    int adminEmNo = 0;
    try {
        adminEmNo = Integer.parseInt(tmpStr);
    } catch (NumberFormatException nfe) {
        logger.error("loadSettings() failure with numAdminEmails (" + nfe.getMessage() + ")");
        adminEmNo = 0;
    }
    if (adminEmNo > 0) {
        // add to arraylist of emails
        for (int i = 0; i < adminEmNo; i++) {
            tmpStr = props.getProperty("email" + i, "");
            if (!"".equals(tmpStr)) {
                addEmail(tmpStr);
            }
        }
    }

    // maxFileSizeToIndex
    tmpStr = props.getProperty("maxFileSizeToIndex", "");
    long newMaxFiSiInt = 0;
    if (!"".equals(tmpStr)) {
        try {
            newMaxFiSiInt = Long.parseLong(tmpStr);
            setMaxFileSize(newMaxFiSiInt);
        } catch (NumberFormatException nfe) {
            logger.error("loadSettings() failure with maxFileSizeToIndex (" + nfe.getMessage() + ")");
        }
    } else {
        logger.info("loadSettings() no prefs for maxFileSizeToIndex found, using default: " + getMaxFileSize());
    }

    // emailFormat
    tmpStr = props.getProperty("emailFormat", "");
    if (!"".equals(tmpStr)) {
        emailFormat = tmpStr;
    }

    // gatewayUser
    tmpStr = props.getProperty("gatewayUser", "");
    if (!"".equals(tmpStr)) {
        gatewayUser = tmpStr;
    }

    // loadExternal
    tmpStr = props.getProperty("loadExternal", "");
    if ("false".equals(tmpStr)) {
        loadExternal = false;
    } else {
        loadExternal = true;
    }

    // gatewayPWD
    tmpStr = props.getProperty("gatewayPwd", "");
    if (!"".equals(tmpStr)) {
        gatewayPwd = tmpStr;
    }

    // gateway
    tmpStr = props.getProperty("gateway", "");
    if (!"".equals(tmpStr)) {
        gateway = tmpStr;
    }

    // browser
    tmpStr = props.getProperty("browser", "");
    // TODO if browser empty, try to get from system with method
    // getBrowserFile()
    if (!"".equals(tmpStr)) {
        defaultHndlr = tmpStr;
    }

    // maxNumHitsShown
    tmpStr = props.getProperty("maxNumHitsShown", "");
    if (!"".equals(tmpStr)) {
        try {
            maxNumHitsShown = Integer.parseInt(tmpStr);
        } catch (NumberFormatException nfe) {
            logger.error("loadSettings() failure with maxNumHitsShown", nfe);
            maxNumHitsShown = 250;
        }
    }

    // tempDir
    tmpStr = props.getProperty("tempDir", "");
    if (!"".equals(tmpStr)) {
        resetTempDir(tmpStr);
    }

    // laf
    tmpStr = props.getProperty("laf", "");
    if (!"".equals(tmpStr) && !"de.muntjak.tinylookandfeel.TinyLookAndFeel".equals(tmpStr)) {
        lafChosen = tmpStr;
        if (env.isGUIMode()) {
            try {
                UIManager.setLookAndFeel(lafChosen);
                SwingUtilities.updateComponentTreeUI(this);
                pack();
            } catch (Exception e) {
                logger.error("loadSettings() failure with laf", e);
                setStatus(ERROR + " : " + e.toString());
            }
        }
    }

    // indexDir
    tmpStr = props.getProperty("indexDir", "");
    if (!"".equals(tmpStr)) {
        File testIdxDir = new File(tmpStr);
        if (testIdxDir.isDirectory()) {
            fEnv.setIndexDirectory(tmpStr);
        } else {
            logger.info("loadSettings() index dir doesn't exist (" + tmpStr + "). Using Default:"
                    + fEnv.getIndexDirectory());
        }
    }

    // workingDir
    tmpStr = props.getProperty("workingDir", "");
    if (!"".equals(tmpStr)) {
        File testworkingDir = new File(tmpStr);
        if (testworkingDir.isDirectory()) {
            resetWorkingDir(tmpStr);
        } else {
            logger.info("loadSettings() index dir doesn't exist (" + tmpStr + "). Using Default:"
                    + fEnv.getWorkingDirectory());
        }
    }
}

From source file:org.jreversepro.gui.ClassEditPanel.java

/**
 * Creates the tree model of the GUI version.
 * /*from  www  .j  a  v  a2 s .  co m*/
 * @param aParent
 *          Parent Frame
 * @param aFileName
 *          Name of the File.
 * @param aChildren
 *          Children nodes of the tree root.
 **/
public void createModel(JFrame aParent, String aFileName, List<String> aChildren) {
    mRoot.removeAllChildren();
    DefaultMutableTreeNode ClassName = new DefaultMutableTreeNode(aFileName);

    for (String str : aChildren) {
        ClassName.add(new DefaultMutableTreeNode(str));
    }
    mRoot.add(ClassName);
    SwingUtilities.updateComponentTreeUI(aParent);
    mTreeFieldMethod.expandRow(1);
}

From source file:org.languagetool.gui.ConfigurationDialog.java

public boolean show(List<Rule> rules) {
    configChanged = false;/*from w  ww . java  2s . c om*/
    if (original != null) {
        config.restoreState(original);
    }
    dialog = new JDialog(owner, true);
    dialog.setTitle(messages.getString("guiConfigWindowTitle"));
    // close dialog when user presses Escape key:
    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    ActionListener actionListener = new ActionListener() {
        @Override
        public void actionPerformed(@SuppressWarnings("unused") ActionEvent actionEvent) {
            dialog.setVisible(false);
        }
    };
    JRootPane rootPane = dialog.getRootPane();
    rootPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);

    configurableRules.clear();

    Language lang = config.getLanguage();
    if (lang == null) {
        lang = Languages.getLanguageForLocale(Locale.getDefault());
    }

    String specialTabNames[] = config.getSpecialTabNames();
    int numConfigTrees = 2 + specialTabNames.length;
    configTree = new JTree[numConfigTrees];
    JPanel checkBoxPanel[] = new JPanel[numConfigTrees];
    DefaultMutableTreeNode rootNode;
    GridBagConstraints cons;

    for (int i = 0; i < numConfigTrees; i++) {
        checkBoxPanel[i] = new JPanel();
        cons = new GridBagConstraints();
        checkBoxPanel[i].setLayout(new GridBagLayout());
        cons.anchor = GridBagConstraints.NORTHWEST;
        cons.gridx = 0;
        cons.weightx = 1.0;
        cons.weighty = 1.0;
        cons.fill = GridBagConstraints.HORIZONTAL;
        Collections.sort(rules, new CategoryComparator());
        if (i == 0) {
            rootNode = createTree(rules, false, null); //  grammar options
        } else if (i == 1) {
            rootNode = createTree(rules, true, null); //  Style options
        } else {
            rootNode = createTree(rules, true, specialTabNames[i - 2]); //  Special tab options
        }
        configTree[i] = new JTree(getTreeModel(rootNode));

        configTree[i].applyComponentOrientation(ComponentOrientation.getOrientation(lang.getLocale()));

        configTree[i].setRootVisible(false);
        configTree[i].setEditable(false);
        configTree[i].setCellRenderer(new CheckBoxTreeCellRenderer());
        TreeListener.install(configTree[i]);
        checkBoxPanel[i].add(configTree[i], cons);
        configTree[i].addMouseListener(getMouseAdapter());
    }

    JPanel portPanel = new JPanel();
    portPanel.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(0, 4, 0, 0);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.anchor = GridBagConstraints.WEST;
    cons.fill = GridBagConstraints.NONE;
    cons.weightx = 0.0f;
    if (!insideOffice) {
        createNonOfficeElements(cons, portPanel);
    } else {
        createOfficeElements(cons, portPanel);
    }

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    JButton okButton = new JButton(Tools.getLabel(messages.getString("guiOKButton")));
    okButton.setMnemonic(Tools.getMnemonic(messages.getString("guiOKButton")));
    okButton.setActionCommand(ACTION_COMMAND_OK);
    okButton.addActionListener(this);
    JButton cancelButton = new JButton(Tools.getLabel(messages.getString("guiCancelButton")));
    cancelButton.setMnemonic(Tools.getMnemonic(messages.getString("guiCancelButton")));
    cancelButton.setActionCommand(ACTION_COMMAND_CANCEL);
    cancelButton.addActionListener(this);
    cons = new GridBagConstraints();
    cons.insets = new Insets(0, 4, 0, 0);
    buttonPanel.add(okButton, cons);
    buttonPanel.add(cancelButton, cons);

    JTabbedPane tabpane = new JTabbedPane();

    JPanel jPane = new JPanel();
    jPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);

    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 0.0f;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.NORTHWEST;
    cons.gridy++;
    cons.anchor = GridBagConstraints.WEST;
    jPane.add(getMotherTonguePanel(cons), cons);

    if (insideOffice) {
        cons.gridy += 3;
    } else {
        cons.gridy++;
    }
    cons.anchor = GridBagConstraints.WEST;
    jPane.add(getNgramPanel(cons), cons);

    cons.gridy++;
    cons.anchor = GridBagConstraints.WEST;
    jPane.add(getWord2VecPanel(cons), cons);

    cons.gridy++;
    cons.anchor = GridBagConstraints.WEST;
    jPane.add(portPanel, cons);
    cons.fill = GridBagConstraints.HORIZONTAL;
    cons.anchor = GridBagConstraints.WEST;
    for (JPanel extra : extraPanels) {
        //in case it wasn't in a containment hierarchy when user changed L&F
        SwingUtilities.updateComponentTreeUI(extra);
        cons.gridy++;
        jPane.add(extra, cons);
    }

    cons.gridy++;
    cons.fill = GridBagConstraints.BOTH;
    cons.weighty = 1.0f;
    jPane.add(new JPanel(), cons);

    tabpane.addTab(messages.getString("guiGeneral"), jPane);

    jPane = new JPanel();
    jPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 10.0f;
    cons.fill = GridBagConstraints.BOTH;
    jPane.add(new JScrollPane(checkBoxPanel[0]), cons);
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;

    cons.gridx = 0;
    cons.gridy++;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.LINE_END;
    jPane.add(getTreeButtonPanel(0), cons);

    tabpane.addTab(messages.getString("guiGrammarRules"), jPane);

    jPane = new JPanel();
    jPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 10.0f;
    cons.fill = GridBagConstraints.BOTH;
    jPane.add(new JScrollPane(checkBoxPanel[1]), cons);
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;

    cons.gridx = 0;
    cons.gridy++;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.LINE_END;
    jPane.add(getTreeButtonPanel(1), cons);

    cons.gridx = 0;
    cons.gridy++;
    cons.weightx = 5.0f;
    cons.weighty = 5.0f;
    cons.fill = GridBagConstraints.BOTH;
    cons.anchor = GridBagConstraints.WEST;
    jPane.add(new JScrollPane(getSpecialRuleValuePanel()), cons);

    tabpane.addTab(messages.getString("guiStyleRules"), jPane);

    for (int i = 0; i < specialTabNames.length; i++) {
        jPane = new JPanel();
        jPane.setLayout(new GridBagLayout());
        cons = new GridBagConstraints();
        cons.insets = new Insets(4, 4, 4, 4);
        cons.gridx = 0;
        cons.gridy = 0;
        cons.weightx = 10.0f;
        cons.weighty = 10.0f;
        cons.fill = GridBagConstraints.BOTH;
        jPane.add(new JScrollPane(checkBoxPanel[i + 2]), cons);
        cons.weightx = 0.0f;
        cons.weighty = 0.0f;

        cons.gridx = 0;
        cons.gridy++;
        cons.fill = GridBagConstraints.NONE;
        cons.anchor = GridBagConstraints.LINE_END;
        jPane.add(getTreeButtonPanel(i + 2), cons);

        tabpane.addTab(specialTabNames[i], jPane);
    }

    jPane = new JPanel();
    jPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    if (insideOffice) {
        JLabel versionText = new JLabel(messages.getString("guiUColorHint"));
        versionText.setForeground(Color.blue);
        jPane.add(versionText, cons);
        cons.gridy++;
    }

    cons.weightx = 2.0f;
    cons.weighty = 2.0f;
    cons.fill = GridBagConstraints.BOTH;

    jPane.add(new JScrollPane(getUnderlineColorPanel(rules)), cons);

    Container contentPane = dialog.getContentPane();
    contentPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 10.0f;
    cons.fill = GridBagConstraints.BOTH;
    cons.anchor = GridBagConstraints.NORTHWEST;
    contentPane.add(tabpane, cons);
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;
    cons.gridy++;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.EAST;
    contentPane.add(buttonPanel, cons);

    dialog.pack();
    // center on screen:
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = dialog.getSize();
    dialog.setLocation(screenSize.width / 2 - frameSize.width / 2,
            screenSize.height / 2 - frameSize.height / 2);
    dialog.setLocationByPlatform(true);
    //  add Color tab after dimension was set
    tabpane.addTab(messages.getString("guiUnderlineColor"), jPane);

    for (JPanel extra : this.extraPanels) {
        if (extra instanceof SavablePanel) {
            ((SavablePanel) extra).componentShowing();
        }
    }
    dialog.setVisible(true);
    return configChanged;
}

From source file:org.mbs3.juniuploader.gui.pnlSettings.java

private void cmbLFItemStateChanged(ItemEvent evt) {
    int sel = cmbLF.getSelectedIndex();
    if (sel != -1) {
        // we have selected a new item
        LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels();
        try {/*  w  w w  .j av a  2s  .  co m*/
            String lfClass = lfs[sel].getClassName();
            UIManager.setLookAndFeel(lfClass);
            System.setProperty(Prefs.class.getName() + ".lookandfeelclassname", lfClass);
            SwingUtilities.updateComponentTreeUI(this.getParent());
        } catch (Exception ex) {
            log.error("Error setting a new Look and Feel", ex);
        }
    }
}

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

/**
 * Change preferences./*from www. jav  a2 s.co 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());
        }
    }
}