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:uk.nhs.cfh.dsp.srth.desktop.modules.querycreationtreepanel.SimpleCloseToUserExpressionPanel.java

public void propertyChanged(String property, Object oldValue, Object newValue, Object source) {
    /*/*from   ww  w. j a  va2s  .  c  o m*/
    we check if expression has changed while the expressionBuilderDialog  is visible, which means that this
    panel's expression is being actively edited. This is a proxy for the source of the property change being
    expressionBuilderDialog or any of its contents
     */
    if (EXPRESSION_CHANGED.equalsIgnoreCase(property) && this.expressionBuilderDialog.isVisible()
            && newValue instanceof CloseToUserExpression && isActive()) {
        if (!(source instanceof SimpleCloseToUserExpressionPanel)) {
            this.expression = (CloseToUserExpression) newValue;
            renderingLabel.setExpression(getExpression());
            Runnable runnable = new Runnable() {
                public void run() {
                    SwingUtilities.updateComponentTreeUI(SimpleCloseToUserExpressionPanel.this);
                    SimpleCloseToUserExpressionPanel.this.revalidate();
                }
            };

            SwingUtilities.invokeLater(runnable);
        }
    }
}

From source file:uk.nhs.cfh.dsp.srth.desktop.uiframework.utils.ActionComponentManager.java

/**
 * Adds the action component.//  www .  ja va 2  s  . com
 *
 * @param actionComponent the action component
 */
public synchronized void addActionComponent(final ActionComponent actionComponent) {

    if (actionComponent != null) {
        Runnable runnable = new Runnable() {
            public void run() {
                // set LNF first to avoid component UI errors
                LookAndFeelUtils.setDefaultLNF();

                String menuName = actionComponent.getMenuName();
                int menuLocationIndex = actionComponent.getMenuLocationIndex();
                int toolBarIndex = actionComponent.getToolBarIndex();
                logger.info("Added to menuName = " + menuName);

                // get menu for menu name
                JMenu menu = getMenuWithName(menuName);
                // create menu item with action;
                JMenuItem menuItem = new JMenuItem(actionComponent.getAction());
                SwingUtilities.updateComponentTreeUI(menuItem);
                checkAndAddMenuItem(menu, menuItem, menuLocationIndex);

                // refresh menu
                menu.revalidate();
                SwingUtilities.updateComponentTreeUI(menu);

                // check if set to visible on toolbar
                if (actionComponent.isVisibleOnToolbar()) {
                    JideButton b = new JideButton(actionComponent.getAction());
                    // set text to be empty
                    b.setText("");
                    SwingUtilities.updateComponentTreeUI(b);
                    // check toolbar count and add button
                    checkAndAddToolbarButton(toolBar, b, toolBarIndex);
                }

                // refresh toolbar and menubar
                menuBar.revalidate();
                toolBar.revalidate();
                SwingUtilities.updateComponentTreeUI(toolBar);
                SwingUtilities.updateComponentTreeUI(menuBar);
            }
        };

        SwingUtilities.invokeLater(runnable);
    } else {
        throw new IllegalArgumentException("Argument passed can not be null : " + actionComponent);
    }
}

From source file:uk.nhs.cfh.dsp.srth.desktop.uiframework.utils.ActionComponentManager.java

/**
 * Removes the action component./*  w ww  . j  a v a2  s  .com*/
 *
 * @param actionComponent the action component
 */
public synchronized void removeActionComponent(final ActionComponent actionComponent) {

    Runnable uiUpdater = new Runnable() {
        public void run() {

            // set LNF first to avoid component UI errors
            LookAndFeelUtils.setDefaultLNF();
            removeComponent(actionComponent);

            toolBar.revalidate();
            menuBar.revalidate();
            SwingUtilities.updateComponentTreeUI(toolBar);
            SwingUtilities.updateComponentTreeUI(menuBar);
        }
    };

    SwingUtilities.invokeLater(uiUpdater);
}

From source file:uk.nhs.cfh.dsp.srth.desktop.uiframework.utils.ViewComponentManager.java

/**
 * Adds the view component.//from  w  ww. j ava  2 s. co  m
 *
 * @param component the component
 */
private synchronized void addViewComponent(final ViewComponent component) {
    if (component != null) {
        // ensure thread safe UI update
        Runnable runnable = new Runnable() {
            public void run() {
                // add componentToPosition
                addComponentToPosition(component);

                applicationView.getActiveComponent().revalidate();
                SwingUtilities.updateComponentTreeUI(toolWindowManager);
                SwingUtilities.updateComponentTreeUI(applicationView.getActiveComponent());
            }
        };

        SwingUtilities.invokeLater(runnable);
    }
}

From source file:uk.nhs.cfh.dsp.srth.desktop.uiframework.utils.ViewComponentManager.java

private void addComponentToPosition(ViewComponent component) {

    // set LNF first to avoid component UI errors
    LookAndFeelUtils.setDefaultLNF();//  w w w  .j a va 2s.  com
    String name = component.getName();
    String title = component.getTitle();
    Icon icon = component.getIcon();
    ViewComponent.Alignment alignment = component.getAlignment();
    JComponent innerComponent = component.getComponent();
    SwingUtilities.updateComponentTreeUI(innerComponent);
    innerComponent.setName(name);

    /*
    Replace all previous implementations with a simple placement. In the newer, simpler model,
    the following alignments are added as tool windows : LEFT, RIGHT, BOTTOM
    the following alignments are added as tabbed windows : TOP, CENTRE
    */

    if (ViewComponent.Alignment.CENTRE == alignment && !componentNames.contains(name)) {
        // get component and add as tabbed panel
        contentManager.addContent(title, title, icon, innerComponent, null,
                new MultiSplitConstraint(AggregationPosition.BOTTOM));
        logger.info("Added view component : " + name + " to centre window");
        // add to component names
        componentNames.add(component.getName());
    } else if (ViewComponent.Alignment.TOP == alignment && !componentNames.contains(name)) {
        // get component and add as tabbed panel
        contentManager.addContent(title, title, icon, innerComponent, null,
                new MultiSplitConstraint(AggregationPosition.TOP));
        logger.info("Added view component : " + name + " to top window");
        // add to component names
        componentNames.add(component.getName());
    } else if (ViewComponent.Alignment.LEFT == alignment && !componentNames.contains(name)) {
        // create tool window and make it available
        toolWindowManager.registerToolWindow(title, title, icon, innerComponent, ToolWindowAnchor.LEFT);
        toolWindowManager.getToolWindow(title).setAvailable(true);
        // set active if set to show on active
        if (component.isActiveOnInitialise()) {
            toolWindowManager.getToolWindow(title).setActive(true);
        }
        logger.info("Added view component : " + name + " as tool in LEFT position.");
        // add to component names
        componentNames.add(component.getName());
    } else if (ViewComponent.Alignment.RIGHT == alignment && !componentNames.contains(name)) {
        // create tool window and make it available
        toolWindowManager.registerToolWindow(title, title, icon, innerComponent, ToolWindowAnchor.RIGHT);
        toolWindowManager.getToolWindow(title).setAvailable(true);
        // set active if set to show on active
        if (component.isActiveOnInitialise()) {
            toolWindowManager.getToolWindow(title).setActive(true);
        }
        logger.info("Added view component : " + name + " as tool in RIGHT position.");
        // add to component names
        componentNames.add(component.getName());
    } else if (ViewComponent.Alignment.BOTTOM == alignment && !componentNames.contains(name)) {
        // create tool window and make it available
        toolWindowManager.registerToolWindow(title, title, icon, innerComponent, ToolWindowAnchor.BOTTOM);
        toolWindowManager.getToolWindow(title).setAvailable(true);
        // set active if set to show on active
        if (component.isActiveOnInitialise()) {
            toolWindowManager.getToolWindow(title).setActive(true);
        }
        logger.info("Added view component : " + name + " as tool in BOTTOM position.");
        // add to component names
        componentNames.add(component.getName());
    } else if (alignment == null && !componentNames.contains(name)) {
        // warn user that unknown alignment found
        logger.warn("Unknown alignment found. Alignment = " + alignment);
        // add to bottom tool window
        applicationView.getToolWindowManager().registerToolWindow(title, title, icon, innerComponent,
                ToolWindowAnchor.BOTTOM);
        toolWindowManager.getToolWindow(title).setAvailable(true);
        // set active if set to show on active
        if (component.isActiveOnInitialise()) {
            toolWindowManager.getToolWindow(title).setActive(true);
        }
        logger.info("Added view component : " + name + " as bottom tool window");
        // add to component names
        componentNames.add(component.getName());
    } else if (componentNames.contains(name)) {
        logger.warn("Component has already been added to application.");
        throw new IllegalArgumentException("Component has already been added to application.");
    }
}

From source file:uk.nhs.cfh.dsp.srth.desktop.uiframework.utils.ViewComponentManager.java

/**
 * Removes the view component./*  ww  w  .jav  a 2 s.com*/
 *
 * @param component the component
 */
private synchronized void removeViewComponent(final ViewComponent component) {
    if (component != null) {
        // ensure thread safe UI update
        Runnable runnable = new Runnable() {
            public void run() {
                // set LNF first to avoid component UI errors
                LookAndFeelUtils.setDefaultLNF();

                String name = component.getName();
                String title = component.getTitle();
                ViewComponent.Alignment alignment = component.getAlignment();
                JComponent innerComponent = component.getComponent();
                // remove component from alignment map
                alignmentMap.remove(component);

                if (ViewComponent.Alignment.CENTRE == alignment || ViewComponent.Alignment.TOP == alignment) {
                    // remove from contentManager
                    contentManager.removeContent(contentManager.getContentByComponent(innerComponent));
                    componentNames.remove(name);
                } else {
                    // unregister toolwindow from toolWindowManager
                    applicationView.getToolWindowManager().unregisterToolWindow(title);
                    logger.info("Removed component : " + name + " from " + alignment.name() + " position.");
                    // remove from component names
                    componentNames.remove(name);
                }

                applicationView.getActiveComponent().revalidate();
                SwingUtilities.updateComponentTreeUI(applicationView.getActiveComponent());
            }
        };

        SwingUtilities.invokeLater(runnable);
    }
}

From source file:uk.nhs.cfh.dsp.yasb.expression.builder.panels.ConceptPanel.java

/**
 * Populate fields./*from   w ww.  ja v a  2s . co  m*/
 *
 * @param snomedConcept the snomed concept
 */
private void populateFields(SnomedConcept snomedConcept) {
    // set text in conceptLabel
    conceptLabel.setText(humanReadableRender.getHumanReadableLabel(snomedConcept));
    // refresh UI
    SwingUtilities.updateComponentTreeUI(this);
}

From source file:uk.nhs.cfh.dsp.yasb.expression.builder.panels.SnomedRelationshipPropertyExpressionPanel.java

/**
 * Populate fields.//from w  w w . jav a 2  s . c o m
 *
 * @param propertyExpression the property expression
 */
public void populateFields(SnomedRelationshipPropertyExpression propertyExpression) {

    if (propertyExpression != null) {
        SnomedRelationship relationship = propertyExpression.getRelationship();
        String relationshipType = relationship.getRelationshipType();
        // get relationship name and set as text
        String attributeText = relationship.getName();
        if (isRenderConceptId()) {
            attributeText = attributeText + "(" + relationshipType + ")";
        }

        // set text in attributeLabel
        attributeLabel.setText(attributeText);

        // get operator and set as operatorLabel text
        if (attributeOperatorMap.containsKey(relationshipType)) {
            operatorLabel.setText(attributeOperatorMap.get(relationshipType));
        } else {
            operatorLabel.setText(" = ");
        }

        // update UI in a thread safe manner
        SwingUtilities.updateComponentTreeUI(this);
    }
}

From source file:uk.nhs.cfh.dsp.yasb.expression.builder.SimpleCloseToUserExpressionPanel.java

public synchronized void propertyChanged(String property, Object oldValue, Object newValue, Object source) {
    /*/* www  . j ava 2  s .  c o m*/
    we check if expression has changed while the expressionBuilderDialog  is visible, which means that this
    panel's expression is being actively edited. This is a proxy for the source of the property change being
    expressionBuilderDialog or any of its contents
     */
    if (EXPRESSION_CHANGED.equalsIgnoreCase(property) && expressionBuilderDialog.isVisible()
            && newValue instanceof CloseToUserExpression
            && !(source instanceof SimpleCloseToUserExpressionPanel)) {
        // propagate event to other listeners (used by terminology constraint panel)
        propertyChangeTrackerService.firePropertyChanged(EXPRESSION_CHANGED, getExpression(), newValue, this);
        logger.info("Propagated event from simple close to user expression panel");
        this.expression = (CloseToUserExpression) newValue;
        renderingLabel.setExpression(getExpression());
        SwingUtilities.updateComponentTreeUI(this);
    }
}

From source file:uk.nhs.cfh.dsp.yasb.searchpanel.SearchPanel.java

/**
 * Creates the control panel.//from   ww w .j  a  v a 2 s.  c  om
 */
private synchronized void createControlPanel() {
    // set controls for rendering concept ids and labels in a collapsible pane
    controlsPane = new JXCollapsiblePane(new GridLayout(0, 1));
    controlsPane.setName("controlsPane");

    final JComboBox conceptTypeBox = new JComboBox(ConceptType.values());
    // set default value to UNKNOWN, which will return all types
    conceptTypeBox.setSelectedItem(ConceptType.UNKNOWN);

    conceptTypeBox.setAction(new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            // get selected value
            Object selection = conceptTypeBox.getSelectedItem();
            if (selection instanceof ConceptType) {
                selectedConceptType = (ConceptType) conceptTypeBox.getSelectedItem();
                doSearch();
            }

        }
    });
    JPanel panel1 = new JPanel();
    panel1.setLayout(new BoxLayout(panel1, BoxLayout.LINE_AXIS));
    panel1.add(new JLabel("Concept Type"));
    panel1.add(Box.createHorizontalStrut(10));
    panel1.add(conceptTypeBox);

    final JComboBox statusBox = new JComboBox(ComponentStatus.values());
    statusBox.setSelectedItem(ComponentStatus.CURRENT);
    statusBox.setAction(new AbstractAction() {

        public void actionPerformed(ActionEvent arg0) {

            Object selection = statusBox.getSelectedItem();
            if (selection instanceof ComponentStatus) {
                selectedConceptStatus = (ComponentStatus) statusBox.getSelectedItem();
                doSearch();
            }
        }
    });
    JPanel panel2 = new JPanel();
    panel2.setLayout(new BoxLayout(panel2, BoxLayout.LINE_AXIS));
    panel2.add(new JLabel("Concept Status"));
    panel2.add(Box.createHorizontalStrut(10));
    panel2.add(statusBox);

    // create stemming enabling checkbox
    final JCheckBox enableStemmingCheckBox = new JCheckBox();
    enableStemmingCheckBox.setAction(new AbstractAction("Enable Stemming") {
        public void actionPerformed(ActionEvent arg0) {
            if (enableStemmingCheckBox.isSelected()) {
                // change analyser
                selectedAnalyzer = new SnowballAnalyzer("English");
                logger.debug("Enabled Stemming");
                doSearch();
            } else {
                selectedAnalyzer = new StandardAnalyzer();
                logger.debug("Disabled Stemming");
                doSearch();
            }
        }

    });

    renderConceptIdsBox = new JCheckBox(new AbstractAction("Render Concept IDs") {

        public void actionPerformed(ActionEvent e) {
            // toggle status in tree cell renderer
            renderer.setRenderConceptId(renderConceptIdsBox.isSelected());
            // refresh tree
            SwingUtilities.updateComponentTreeUI(resultsList);
        }
    });
    renderConceptIdsBox.setName("preferFSNOverPTJCheckBox");

    preferFSNOverPTJCheckBox = new JCheckBox(new AbstractAction("Prefer FSN over PT") {
        public void actionPerformed(ActionEvent e) {
            // toggle preference in renderer
            renderer.setPreferFSNOverPT(preferFSNOverPTJCheckBox.isSelected());
            // refresh tree
            SwingUtilities.updateComponentTreeUI(resultsList);
        }
    });
    preferFSNOverPTJCheckBox.setName("preferFSNOverPTJCheckBox");

    // add panels to controlsPane
    controlsPane.add(panel1);
    controlsPane.add(panel2);
    controlsPane.add(enableStemmingCheckBox);
    controlsPane.add(renderConceptIdsBox);
    controlsPane.add(preferFSNOverPTJCheckBox);
    controlsPane.setCollapsed(true);
}