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:org.yccheok.jstock.gui.JStock.java

private void setLookAndFeel(String lafClassName) {
    boolean uiManagerLookAndFeelSuccess = false;
    String realLafClassName = null;

    try {/*  w ww.  j ava  2  s  .c om*/
        if (lafClassName == null) {
            String className = Utils.setDefaultLookAndFeel();
            if (className != null) {
                SwingUtilities.updateComponentTreeUI(this);
                realLafClassName = className;
                uiManagerLookAndFeelSuccess = true;
            }
        } else {
            UIManager.setLookAndFeel(lafClassName);
            SwingUtilities.updateComponentTreeUI(this);
            realLafClassName = lafClassName;
            uiManagerLookAndFeelSuccess = true;
        }
    } catch (java.lang.ClassNotFoundException | java.lang.InstantiationException
            | java.lang.IllegalAccessException | javax.swing.UnsupportedLookAndFeelException exp) {
        log.error(null, exp);
    }

    if (uiManagerLookAndFeelSuccess) {
        // Don't use realLafClassName.
        this.jStockOptions.setLooknFeel(lafClassName);

        for (Enumeration<AbstractButton> e = this.buttonGroup1.getElements(); e.hasMoreElements();) {
            AbstractButton button = e.nextElement();
            javax.swing.JRadioButtonMenuItem m = (javax.swing.JRadioButtonMenuItem) button;
            ChangeLookAndFeelAction a = (ChangeLookAndFeelAction) m.getActionListeners()[0];

            if (a.getLafClassName().equals(realLafClassName)) {
                m.setSelected(true);
                break;
            }
        }

        // Sequence are important. The AutoCompleteJComboBox itself should have the highest
        // priority.
        ((AutoCompleteJComboBox) jComboBox1).setStockInfoDatabase(this.stockInfoDatabase);
        this.indicatorPanel.setStockInfoDatabase(this.stockInfoDatabase);
    }
}

From source file:org.yccheok.jstock.gui.MainFrame.java

public void setLookAndFeel(String lafClassName) {
    /* Backward compataible purpose. Old JStockOptions may contain null in this field. */
    if (lafClassName == null) {
        return;/*w  w  w .j a  v a2s . co m*/
    }
    try {
        UIManager.setLookAndFeel(lafClassName);
        SwingUtilities.updateComponentTreeUI(this);
    } catch (java.lang.ClassNotFoundException exp) {
        log.error(null, exp);
    } catch (java.lang.InstantiationException exp) {
        log.error(null, exp);
    } catch (java.lang.IllegalAccessException exp) {
        log.error(null, exp);
    } catch (javax.swing.UnsupportedLookAndFeelException exp) {
        log.error(null, exp);
    }

    this.jStockOptions.setLookNFeel(lafClassName);

    for (Enumeration<AbstractButton> e = this.buttonGroup1.getElements(); e.hasMoreElements();) {
        AbstractButton button = e.nextElement();
        javax.swing.JRadioButtonMenuItem m = (javax.swing.JRadioButtonMenuItem) button;
        ChangeLookAndFeelAction a = (ChangeLookAndFeelAction) m.getActionListeners()[0];

        if (a.getLafClassName().equals(lafClassName)) {
            m.setSelected(true);
            break;
        }
    }

    // Sequence are important. The AutoCompleteJComboBox itself should have the highest
    // priority.
    ((AutoCompleteJComboBox) jComboBox1).setStockInfoDatabase(this.stockInfoDatabase);
    this.indicatorPanel.setStockInfoDatabase(this.stockInfoDatabase);
}

From source file:qic.Main.java

public static void reloadLookAndFeel() {
    if (Config.getBooleanProperty(Config.LOOK_AND_FEEL_DECORATED, false)) {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);
        System.setProperty("sun.awt.noerasebackground", "true");
    }/* www.  j  a v a  2s . c  om*/
    try {
        String lookAndFeel = Config.getPropety(Config.LOOK_AND_FEEL,
                "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        if (lookAndFeel.startsWith("Substance")) {
            lookAndFeel = "org.pushingpixels.substance.api.skin." + lookAndFeel;
        }
        UIManager.setLookAndFeel(lookAndFeel);
    } catch (Exception e) {
        try {
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    for (Window window : Window.getWindows()) {
        SwingUtilities.updateComponentTreeUI(window);
    }
}

From source file:se.trixon.jota.client.ui.MainFrame.java

private void loadClientOption(ClientOptionsEvent clientOptionEvent) {
    switch (clientOptionEvent) {
    case LOOK_AND_FEEL:
        if (mOptions.isForceLookAndFeel()) {
            SwingUtilities.invokeLater(() -> {
                try {
                    UIManager.setLookAndFeel(SwingHelper.getLookAndFeelClassName(mOptions.getLookAndFeel()));
                    SwingUtilities.updateComponentTreeUI(MainFrame.this);
                    SwingUtilities.updateComponentTreeUI(sPopupMenu);

                    if (mOptions.getLookAndFeel().equalsIgnoreCase("Darcula")) {
                        int iconSize = 32;
                        UIDefaults uiDefaults = UIManager.getLookAndFeelDefaults();
                        uiDefaults.put("OptionPane.informationIcon",
                                MaterialIcon.Action.INFO_OUTLINE.get(iconSize, IconColor.WHITE));
                        uiDefaults.put("OptionPane.errorIcon",
                                MaterialIcon.Alert.ERROR_OUTLINE.get(iconSize, IconColor.WHITE));
                        uiDefaults.put("OptionPane.questionIcon",
                                MaterialIcon.Action.HELP_OUTLINE.get(iconSize, IconColor.WHITE));
                        uiDefaults.put("OptionPane.warningIcon",
                                MaterialIcon.Alert.WARNING.get(iconSize, IconColor.WHITE));
                    }// w w  w  .ja v  a2  s .c  o  m
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                        | UnsupportedLookAndFeelException ex) {
                    //Xlog.timedErr(ex.getMessage());
                }
            });
        }
        break;

    case MENU_ICONS:
        ActionMap actionMap = getRootPane().getActionMap();
        for (Object allKey : actionMap.allKeys()) {
            Action action = actionMap.get(allKey);
            Icon icon = null;
            if (mOptions.isDisplayMenuIcons()) {
                icon = (Icon) action.getValue(ActionManager.JOTA_SMALL_ICON_KEY);
            }
            action.putValue(Action.SMALL_ICON, icon);
        }
        break;

    default:
        throw new AssertionError();
    }

}

From source file:tk.tomby.tedit.core.Workspace.java

/**
 * DOCUMENT ME!/*from   w w  w .  java  2s .c  om*/
 *
 * @param plugin DOCUMENT ME!
 */
public void addPlugin(IPlugin plugin) {
    IDockablePlugin dock = (IDockablePlugin) plugin;

    Dockable wrapper = DockableComponentWrapper.create(dock.getDockable(), dock.getDockTitle(),
            dock.getDockTitle());
    wrapper.addDockingListener(new DockingListener() {
        public void dockingCanceled(DockingEvent evt) {
        }

        public void dockingComplete(DockingEvent evt) {
            DockingPort port = evt.getNewDockingPort();

            int position = PLUGIN_LEFT;
            if (port == bottomPort) {
                position = PLUGIN_BOTTOM;
            } else if (port == leftPort) {
                position = PLUGIN_LEFT;
            } else if (port == rightPort) {
                position = PLUGIN_RIGHT;
            }

            Component component = evt.getComponent();
            if (component instanceof IDockablePlugin) {
                IDockablePlugin plugin = (IDockablePlugin) component;
                plugin.setDockLocation(position);
                plugin.setDockRegion(evt.getRegion());
            }
        }

        public void dragStarted(DockingEvent evt) {
        }

        public void dropStarted(DockingEvent evt) {
        }

        public void undockingComplete(DockingEvent evt) {
        }

        public void undockingStarted(DockingEvent evt) {
        }
    });

    DockingManager.registerDockable(wrapper);

    switch (dock.getDockLocation()) {
    case PLUGIN_BOTTOM:
        bottomPort.dock(wrapper, dock.getDockRegion());

        break;

    case PLUGIN_LEFT:
        leftPort.dock(wrapper, dock.getDockRegion());

        break;

    case PLUGIN_RIGHT:
        rightPort.dock(wrapper, dock.getDockRegion());

        break;

    default:
        log.warn("invalid location");
    }

    SwingUtilities.updateComponentTreeUI(this);
}

From source file:tvbrowser.TVBrowser.java

private static void updateLookAndFeel() {
    try {//from   w  w  w .  j av a2  s.c  om
        if (OperatingSystem.isWindows()) {
            UIManager.installLookAndFeel("Extended Windows", "com.jgoodies.looks.windows.WindowsLookAndFeel");
        }
        UIManager.installLookAndFeel("Plastic", "com.jgoodies.looks.plastic.PlasticLookAndFeel");
        UIManager.installLookAndFeel("Plastic 3D", "com.jgoodies.looks.plastic.Plastic3DLookAndFeel");
        UIManager.installLookAndFeel("Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
        UIManager.installLookAndFeel("Skin", "com.l2fprod.gui.plaf.skin.SkinLookAndFeel");
        /*
              Map<String, SkinInfo> substanceSkins = SubstanceLookAndFeel.getAllSkins();
              if (substanceSkins != null) {
                for (SkinInfo skin : substanceSkins.values()) {
                  String className = skin.getClassName();
                  UIManager.installLookAndFeel("Substance " + skin.getDisplayName(), StringUtils.replace(StringUtils.replace(className, "Skin", "LookAndFeel"), "skin.", "skin.Substance"));
                }
              }
        */
    } catch (Exception e1) {
        // ignore any exception for optional skins
        e1.printStackTrace();
    }

    if (Settings.propLookAndFeel.getString().equals("com.l2fprod.gui.plaf.skin.SkinLookAndFeel")) {
        String themepack = Settings.propSkinLFThemepack.getString();
        try {
            File themepackFile = new File(themepack);
            if (!themepackFile.exists()) {
                themepackFile = new File(Settings.getUserDirectoryName(), themepack);
            }

            if (!themepackFile.exists() && OperatingSystem.isMacOs()) {
                themepackFile = new File("/Library/Application Support/TV-Browser/", themepack);
            }

            SkinLookAndFeel.setSkin(SkinLookAndFeel.loadThemePack(themepackFile.getAbsolutePath()));
        } catch (Exception exc) {
            ErrorHandler.handle("Could not load themepack.\nSkinLF is disabled now", exc);
            Settings.propLookAndFeel.setString(Settings.propLookAndFeel.getDefault());
        }
    } else if (Settings.propLookAndFeel.getString().startsWith("com.jgoodies")) {
        com.jgoodies.looks.Options.setPopupDropShadowEnabled(Settings.propJGoodiesShadow.getBoolean());
        UIManager.put("jgoodies.popupDropShadowEnabled",
                Boolean.valueOf(Settings.propJGoodiesShadow.getBoolean()));
        try {
            LookUtils.setLookAndTheme(
                    (LookAndFeel) Class.forName(Settings.propLookAndFeel.getString()).newInstance(),
                    Class.forName(Settings.propJGoodiesTheme.getString()).newInstance());
        } catch (Throwable e) {
            ErrorHandler.handle("Could not load themepack.\nJGoodies is disabled now", e);
            Settings.propLookAndFeel.setString(Settings.propLookAndFeel.getDefault());
        }
    }

    if (curLookAndFeel == null || !curLookAndFeel.equals(Settings.propLookAndFeel.getString())) {
        try {
            curLookAndFeel = Settings.propLookAndFeel.getString();
            // check if LnF is still available
            boolean foundCurrent = lookAndFeelExists(curLookAndFeel);
            // reset look and feel?
            if (!foundCurrent) {
                if (JOptionPane.showConfirmDialog(null, mLocalizer.msg("lnfMissing",
                        "The look and feel '{0}' is no longer available,\nso the default look and feel will be used.\n\nDo you want to set the look and feel option to the default look and feel?",
                        curLookAndFeel), mLocalizer.msg("lnfMissing.title", "Look and feel missing"),
                        JOptionPane.WARNING_MESSAGE | JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                    Settings.propLookAndFeel.resetToDefault();
                    curLookAndFeel = Settings.propLookAndFeel.getString();
                    foundCurrent = true;
                }
            }
            if (foundCurrent) {
                UIThreadRunner.invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            UIManager.setLookAndFeel(curLookAndFeel);
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        mLog.info("setting look and feel to " + curLookAndFeel);
                    }
                });
            }
        } catch (Exception exc) {
            String msg = mLocalizer.msg("error.1", "Unable to set look and feel.", exc);
            ErrorHandler.handle(msg, exc);
        }
    }

    // set colors for action pane at UIManager
    UIManager.put("TaskPane.foreGround", UIManager.get("Button.foreground"));

    if (UIManager.getColor("List.selectionBackground") == null) {
        UIManager.put("List.selectionBackground", UIManager.getColor("Tree.selectionBackground"));
    }
    if (UIManager.getColor("List.selectionForeground") == null) {
        UIManager.put("List.selectionForeground", UIManager.getColor("Tree.selectionForeground"));
    }
    if (UIManager.getColor("MenuItem.selectionForeground") == null) {
        UIManager.put("MenuItem.selectionForeground", UIManager.getColor("Tree.selectionForeground"));
    }
    if (UIManager.getColor("ComboBox.disabledForeground") == null) {
        UIManager.put("ComboBox.disabledForeground", Color.gray);
    }

    if (mainFrame != null) {
        SwingUtilities.updateComponentTreeUI(mainFrame);
        mainFrame.validate();
    }
    lookAndFeelInitialized = true;
}

From source file:uk.ac.abdn.csd.p2p.server.ServerGUI.java

/**
 * This method has been overridden as {@code ServerGUI} implements {@code Runnable}.
 * /* w  w w.j  av  a  2s.  c o m*/
 */
@Override
public void run() {
    initializeComponent();
    SwingUtilities.updateComponentTreeUI(this);
    this.setLocationRelativeTo(null);
    settingsColor = new ColourSettingDialog(this, true);
    settingsLayout = new LayoutSettingDialog(this, true);
    labelPosition = new VertexLabelPositionDialog(this, true);
    settingsSpeed = new SpeedSettingDialog(this, true);
    memory = new HashMap<Vertex, String>();
    nodeColour = "white";
    pingColour = "yellow";
    pongColour = "pink";
    queryColour = "Magenta";
    queryHitColour = "green";
    relayorColour = "orange";
    searchColour = "cyan";
    speedPing = 500;
    speedPong = 500;
    speedQuery = 500;
    speedQueryHit = 500;
}

From source file:uk.nhs.cfh.dsp.srth.desktop.modules.querycreationtreepanel.QueryAuthoringTreePanel.java

public void queryChanged(QueryService service, QueryStatement query, Object source) {

    if (query != null) {
        // reset active query
        activeQuery = query;//  ww  w  . j a  v a2  s .  c o m
        logger.debug("Notified model of query change");
        reportingQueryTreeModel.populateModel(activeQuery);
        //            // scroll to active node
        //            if (selectedExpression != null && !(selectedExpression instanceof QueryStatement))
        //            {
        //                TreePath path = new TreePath(reportingQueryTreeModel.getPathToRoot(selectedExpression));
        //                queryInterfaceTree.scrollPathToVisible(path);
        //            }

        // update UI
        Runnable runnable = new Runnable() {
            public void run() {
                queryInterfaceTree.revalidate();
                SwingUtilities.updateComponentTreeUI(queryInterfaceTree);
            }
        };

        SwingUtilities.invokeLater(runnable);
    }
}

From source file:uk.nhs.cfh.dsp.srth.desktop.modules.querycreationtreepanel.renderer.ReportingQueryStatementTreeCellRenderer.java

public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {

    final JLabel label = new JLabel();
    if (value instanceof QueryExpression) {
        QueryExpression expression = (QueryExpression) value;

        if (expression instanceof QueryStatement) {
            label.setText("Get patients who have");
        } else if (expression instanceof QueryIntersectionExpression) {
            QueryIntersectionExpression intersectionObject = (QueryIntersectionExpression) expression;
            QueryExpression.QueryOperatorType operatorType = intersectionObject.getOperator();
            if (operatorType != QueryExpression.QueryOperatorType.AND) {
                label.setText("ALL of the following (" + operatorType.toString() + ")");
            } else {
                label.setText("ALL of the following");
            }/*from  w  ww  . j av  a 2 s  .co  m*/
        } else if (expression instanceof QueryUnionExpression) {
            label.setText("ANY of the following");
        } else if (expression instanceof QueryComponentExpression) {
            QueryComponentExpression componentExpression = (QueryComponentExpression) value;
            TerminologyConstraint includedConstraint = componentExpression.getIncludedConstraint();
            if (includedConstraint != null) {
                String text = humanReadableRender
                        .getHumanReadableLabel((CloseToUserExpression) includedConstraint.getExpression());
                label.setText(text);
            }

            final Collection<TerminologyConstraint> excludedTerms = componentExpression
                    .getExcludedConstraints();
            if (excludedTerms.size() > 0) {
                label.setIcon(icon);
            }

            SwingUtilities.updateComponentTreeUI(label);
        }

        // set label text color based on run time status
        setFontColor(expression, label);
    }

    if (hasFocus) {
        Color lineColor = UIManager.getColor("Tree.selectionBorderColor");
        label.setBorder(BorderFactory.createLineBorder(lineColor));
        label.setBackground(UIManager.getColor("Tree.selectionBackground"));
    } else {
        label.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
        label.setBackground(UIManager.getColor("Tree.background"));
    }

    return label;
}

From source file:uk.nhs.cfh.dsp.srth.desktop.modules.querycreationtreepanel.SimpleCloseToUserExpressionPanel.java

/**
 * Sets the expression./*from   www.  j  av  a 2  s . c o m*/
 *
 * @param expression the new expression
 */
public void setExpression(CloseToUserExpression expression) {
    if (expression != null) {
        this.expression = expression;
        renderingLabel.setExpression(getExpression());
        expressionBuilderPanel.setCloseToUserExpression(getExpression());
        logger.info("Setting expression in simple close to user panel");
        Runnable runnable = new Runnable() {
            public void run() {
                SwingUtilities.updateComponentTreeUI(SimpleCloseToUserExpressionPanel.this);
                SimpleCloseToUserExpressionPanel.this.revalidate();
            }
        };

        SwingUtilities.invokeLater(runnable);
    }
}