javax.swing.plaf.synth.SynthStyle Java Examples

The following examples show how to use javax.swing.plaf.synth.SynthStyle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SeaGlassInternalFrameUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    SynthStyle oldStyle = style;
    JInternalFrame f = (JInternalFrame) evt.getSource();
    String prop = evt.getPropertyName();

    if (SeaGlassLookAndFeel.shouldUpdateStyle(evt)) {
        updateStyle(f);
    }

    if (style == oldStyle && (prop == JInternalFrame.IS_MAXIMUM_PROPERTY || prop == JInternalFrame.IS_SELECTED_PROPERTY)) {
        // Border (and other defaults) may need to change
        SeaGlassContext context = getContext(f, ENABLED);
        style.uninstallDefaults(context);
        ((SeaGlassStyle) style).installDefaults(context, this);
    }
}
 
Example #2
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * @see javax.swing.plaf.basic.BasicButtonUI#getMaximumSize(javax.swing.JComponent)
 */
public Dimension getMaximumSize(JComponent c) {
    if (c.getComponentCount() > 0 && c.getLayout() != null) {
        return null;
    }

    AbstractButton   b      = (AbstractButton) c;
    SeaGlassContext  ss     = getContext(c);
    final SynthStyle style2 = ss.getStyle();
    Dimension        size   = style2.getGraphicsUtils(ss).getMaximumSize(ss, style2.getFont(ss), b.getText(), getSizingIcon(b),
                                                                         b.getHorizontalAlignment(), b.getVerticalAlignment(),
                                                                         b.getHorizontalTextPosition(), b.getVerticalTextPosition(),
                                                                         b.getIconTextGap(), b.getDisplayedMnemonicIndex());

    ss.dispose();
    return size;
}
 
Example #3
Source File: SeaGlassPopupMenuUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
private void updateStyle(JComponent c) {
    SeaGlassContext context = getContext(c, ENABLED);
    Window window = SwingUtilities.getWindowAncestor(popupMenu);
    if (PlatformUtils.isMac() && window != null) {
        WindowUtils.makeWindowNonOpaque(window);
    }
    SeaGlassStyle oldStyle = style;
    
    SynthStyle s = SeaGlassLookAndFeel.updateStyle(context, this);
    if (s instanceof SeaGlassStyle) {
        style = (SeaGlassStyle) s;
        if (style != oldStyle) {
            if (oldStyle != null) {
                uninstallKeyboardActions();
                installKeyboardActions();
            }
        }
    }
    context.dispose();
}
 
Example #4
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * @see javax.swing.plaf.basic.BasicButtonUI#getPreferredSize(javax.swing.JComponent)
 */
public Dimension getPreferredSize(JComponent c) {
    if (c.getComponentCount() > 0 && c.getLayout() != null) {
        return null;
    }

    AbstractButton     b             = (AbstractButton) c;
    SeaGlassContext    ss            = getContext(c);
    SynthStyle         style2        = ss.getStyle();
    SynthGraphicsUtils graphicsUtils = style2.getGraphicsUtils(ss);
    Dimension          size          = graphicsUtils.getPreferredSize(ss, style2.getFont(ss), b.getText(), getSizingIcon(b),
                                                                      b.getHorizontalAlignment(),
                                                                      b.getVerticalAlignment(), b.getHorizontalTextPosition(),
                                                                      b.getVerticalTextPosition(), b.getIconTextGap(),
                                                                      b.getDisplayedMnemonicIndex());

    ss.dispose();
    // Make height odd.
    size.height &= ~1;
    return size;
}
 
Example #5
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * @see javax.swing.plaf.basic.BasicButtonUI#getMinimumSize(javax.swing.JComponent)
 */
public Dimension getMinimumSize(JComponent c) {
    if (c.getComponentCount() > 0 && c.getLayout() != null) {
        return null;
    }

    AbstractButton   b      = (AbstractButton) c;
    SeaGlassContext  ss     = getContext(c);
    final SynthStyle style2 = ss.getStyle();
    Dimension        size   = style2.getGraphicsUtils(ss).getMinimumSize(ss, style2.getFont(ss), b.getText(), getSizingIcon(b),
                                                                         b.getHorizontalAlignment(), b.getVerticalAlignment(),
                                                                         b.getHorizontalTextPosition(), b.getVerticalTextPosition(),
                                                                         b.getIconTextGap(), b.getDisplayedMnemonicIndex());

    ss.dispose();
    return size;
}
 
Example #6
Source File: SeaGlassScrollPaneUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
private void updateStyle(JScrollPane c) {
    SeaGlassContext context = getContext(c, ENABLED);
    SynthStyle oldStyle = style;

    style = SeaGlassLookAndFeel.updateStyle(context, this);
    if (style != oldStyle) {
        Border vpBorder = scrollpane.getViewportBorder();
        if ((vpBorder == null) || (vpBorder instanceof UIResource)) {
            scrollpane.setViewportBorder(new ViewportBorder(context));
        }
        if (oldStyle != null) {
            uninstallKeyboardActions(c);
            installKeyboardActions(c);
        }
    }
    context.dispose();
}
 
Example #7
Source File: SeaGlassToolBarUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
private void updateStyle(JToolBar c) {
    SeaGlassContext context = getContext(c, Region.TOOL_BAR_CONTENT, null, ENABLED);
    contentStyle = SeaGlassLookAndFeel.updateStyle(context, this);
    context.getComponent().setOpaque(false);
    context.dispose();

    context = getContext(c, Region.TOOL_BAR_DRAG_WINDOW, null, ENABLED);
    context.getComponent().setOpaque(false);
    dragWindowStyle = SeaGlassLookAndFeel.updateStyle(context, this);
    context.dispose();

    context = getContext(c, ENABLED);
    context.getComponent().setOpaque(false);
    SynthStyle oldStyle = style;

    style = SeaGlassLookAndFeel.updateStyle(context, this);
    if (oldStyle != style) {
        handleIcon = style.getIcon(context, "ToolBar.handleIcon");
        if (oldStyle != null) {
            uninstallKeyboardActions();
            installKeyboardActions();
        }
    }
    context.dispose();
}
 
Example #8
Source File: SeaGlassInternalFrameUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
private void updateStyle(JComponent c) {
    SeaGlassContext context = getContext(c, ENABLED);
    SynthStyle oldStyle = style;

    style = SeaGlassLookAndFeel.updateStyle(context, this);
    if (style != oldStyle) {
        Icon frameIcon = frame.getFrameIcon();
        if (frameIcon == null || frameIcon instanceof UIResource) {
            frame.setFrameIcon(context.getStyle().getIcon(context, "InternalFrame.icon"));
        }
        if (oldStyle != null) {
            uninstallKeyboardActions();
            installKeyboardActions();
        }
    }
    context.dispose();
}
 
Example #9
Source File: ThemeValue.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Color getColor () {
    SynthStyle style = getSynthStyle (aRegion);
    if (Boolean.TRUE.equals(functioning)) {
        try {
            Color result = (Color) synthStyle_getColorForState.invoke (style,
                new Object [] {
                    getSynthContext (),
                    aColorType
                });
            if (result == null) {
                result = (Color) fallback;
            }
            if (darken) {
                result = result.darker();
            }
            return result;
        } catch (Exception e) {
            functioning = Boolean.FALSE;
            if (log) {
                e.printStackTrace();
            }
        }
    }
    //This will only happen once, after which functioning will be false
    return null;
}
 
Example #10
Source File: ThemeValue.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Font getFont() {
    SynthStyle style = getSynthStyle (aRegion);
    if (Boolean.TRUE.equals(functioning)) {
        try {
            Font result = (Font) synthStyle_getFontForState.invoke (style,
                new Object [] {
                    getSynthContext ()
                });
            if (result == null) {
                result = (Font) fallback;
            }
            return result;
        } catch (Exception e) {
            functioning = Boolean.FALSE;
            if (log) {
                e.printStackTrace();
            }
        }
    }
    //This will only happen once, after which functioning will be false
    return null; 
}
 
Example #11
Source File: SeaGlassTabbedPaneUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * Create a SynthContext for the component, subregion, and state.
 *
 * @param  c         the component.
 * @param  subregion the subregion.
 * @param  state     the state.
 *
 * @return the newly created SynthContext.
 */
private SeaGlassContext getContext(JComponent c, Region subregion, int state) {
    SynthStyle style = null;
    Class      klass = SeaGlassContext.class;

    if (subregion == Region.TABBED_PANE_TAB) {
        style = tabStyle;
    } else if (subregion == Region.TABBED_PANE_TAB_AREA) {
        style = tabAreaStyle;
    } else if (subregion == Region.TABBED_PANE_CONTENT) {
        style = tabContentStyle;
    } else if (subregion == SeaGlassRegion.TABBED_PANE_TAB_CLOSE_BUTTON) {
        style = tabCloseStyle;
    }

    return SeaGlassContext.getContext(klass, c, subregion, style, state);
}
 
Example #12
Source File: SeaGlassViewportUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
private void updateStyle(JComponent c) {
    SeaGlassContext context = getContext(c, ENABLED);

    // Note: JViewport is special cased as it does not allow for
    // a border to be set. JViewport.setBorder is overriden to throw
    // an IllegalArgumentException. Refer to SynthScrollPaneUI for
    // details of this.
    SynthStyle newStyle = SynthLookAndFeel.getStyle(context.getComponent(), context.getRegion());
    SynthStyle oldStyle = context.getStyle();

    if (newStyle != oldStyle) {
        if (oldStyle != null) {
            oldStyle.uninstallDefaults(context);
        }
        context.setStyle(newStyle);
        newStyle.installDefaults(context);
    }
    this.style = newStyle;
    context.dispose();
}
 
Example #13
Source File: SeaGlassComboBoxUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
private void updateStyle(JComboBox comboBox) {
    SeaGlassStyle oldStyle = style;
    SeaGlassContext context = getContext(comboBox, ENABLED);

    SynthStyle s = SeaGlassLookAndFeel.updateStyle(context, this);
    if (s instanceof SeaGlassStyle) {
        style = (SeaGlassStyle) s;
        if (style != oldStyle) {
            popupInsets = (Insets) style.get(context, "ComboBox.popupInsets");
            useListColors = style.getBoolean(context, "ComboBox.rendererUseListColors", true);
            buttonWhenNotEditable = style.getBoolean(context, "ComboBox.buttonWhenNotEditable", false);
            pressedWhenPopupVisible = style.getBoolean(context, "ComboBox.pressedWhenPopupVisible", false);

            if (oldStyle != null) {
                uninstallKeyboardActions();
                installKeyboardActions();
            }
            forceOpaque = style.getBoolean(context, "ComboBox.forceOpaque", false);
        }
    }
    context.dispose();
}
 
Example #14
Source File: SeaGlassLookAndFeel.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * Called by UIManager when this look and feel is installed.
 */
@Override
public void initialize() {
    super.initialize();

    // create synth style factory
    setStyleFactory(new SynthStyleFactory() {
            @Override
            public SynthStyle getStyle(JComponent c, Region r) {
                SynthStyle style = getSeaGlassStyle(c, r);

                if (!(style instanceof SeaGlassStyle)) {
                    style = new SeaGlassStyleWrapper(style);
                }

                return style;
            }
        });
}
 
Example #15
Source File: SeaGlassContext.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a SeaGlassContext with the specified values. This is meant for
 * subclasses and custom UI implementors. You very rarely need to construct
 * a SeaGlassContext, though some methods will take one.
 *
 * @param component JComponent
 * @param region    Identifies the portion of the JComponent
 * @param style     Style associated with the component
 * @param state     State of the component as defined in SynthConstants.
 */
public SeaGlassContext(JComponent component, Region region, SynthStyle style, int state) {
    super(component, region, style, state);

    if (component == fakeComponent) {
        this.component = null;
        this.region    = null;
        this.style     = null;

        return;
    }

    if (component == null || region == null || style == null) {
        throw new NullPointerException("You must supply a non-null component, region and style");
    }

    reset(component, region, style, state);
}
 
Example #16
Source File: SeaGlassLookAndFeel.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
     * A convience method that will reset the Style of StyleContext if
     * necessary.
     *
     * @return newStyle
     */
   
    public static SynthStyle updateSeaglassStyle(SynthContext context, SeaglassUI ui) {
        SynthStyle newStyle = getStyle(context.getComponent(), context.getRegion());
        // TODO rossi 04.07.2011 this code is now private in the Synth L&F
//        SynthStyle oldStyle = context.getStyle();
//
//        if (newStyle != oldStyle) {
//            if (oldStyle != null) {
//                oldStyle.uninstallDefaults(context);
//            }
//            context.setStyle(newStyle);
//            newStyle.installDefaults(context, ui);
//        }
        return newStyle;
    }
 
Example #17
Source File: SeaGlassGraphicsUtils.java    From seaglass with Apache License 2.0 6 votes vote down vote up
public static void paint(SynthContext context, SynthContext accContext, Graphics g, Icon checkIcon, Icon arrowIcon,
    String acceleratorDelimiter, int defaultTextIconGap, String propertyPrefix) {
    JMenuItem mi = (JMenuItem) context.getComponent();
    SynthStyle style = context.getStyle();
    g.setFont(style.getFont(context));

    Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight());
    boolean leftToRight = SeaGlassLookAndFeel.isLeftToRight(mi);
    applyInsets(viewRect, mi.getInsets(), leftToRight);

    SeaGlassMenuItemLayoutHelper lh = new SeaGlassMenuItemLayoutHelper(context, accContext, mi, checkIcon, arrowIcon, viewRect,
        defaultTextIconGap, acceleratorDelimiter, leftToRight, MenuItemLayoutHelper.useCheckAndArrow(mi), propertyPrefix);
    MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem();

    paintMenuItem(g, lh, lr);
}
 
Example #18
Source File: SeaGlassEditorPaneUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
private void updateStyle(JTextComponent comp) {
    SeaGlassContext context = getContext(comp, ENABLED);
    SynthStyle oldStyle = style;

    style = SeaGlassLookAndFeel.updateStyle(context, this);

    if (style != oldStyle) {
        SeaGlassTextFieldUI.updateStyle(comp, context, getPropertyPrefix());

        if (oldStyle != null) {
            uninstallKeyboardActions();
            installKeyboardActions();
        }
    }
    context.dispose();
}
 
Example #19
Source File: SeaGlassLookAndFeel.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * A convience method that will reset the Style of StyleContext if
 * necessary.
 *
 * @param  context the SynthContext corresponding to the current state.
 * @param  ui      the UI delegate.
 *
 * @return the new, updated style.
 */
public static SynthStyle updateStyle(SeaGlassContext context, SeaglassUI ui) {
    SynthStyle newStyle = SynthLookAndFeel.getStyle(context.getComponent(), context.getRegion());
    SynthStyle oldStyle = context.getStyle();

    if (newStyle != oldStyle) {

        if (oldStyle != null) {
            oldStyle.uninstallDefaults(context);
        }

        context.setStyle(newStyle);
        if (newStyle instanceof SeaGlassStyle) {
            ((SeaGlassStyle) newStyle).installDefaults(context, ui);
        }
    }

    return newStyle;
}
 
Example #20
Source File: SeaGlassTitlePane.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * Update the Synth Style.
 *
 * @param c the title pane.
 */
private void updateStyle(JComponent c) {
    SeaGlassContext context  = getContext(this, ENABLED);
    SynthStyle      oldStyle = style;

    style = SeaGlassLookAndFeel.updateSeaglassStyle(context, this);

    if (style != oldStyle) {
        titleSpacing = style.getInt(context, "InternalFrameTitlePane.titleSpacing", 2);
    }

    context.dispose();
}
 
Example #21
Source File: SeaGlassInternalFrameTitlePane.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * Update the Synth Style.
 *
 * @param c the component.
 */
private void updateStyle(JComponent c) {
    SeaGlassContext context  = getContext(this, ENABLED);
    SynthStyle      oldStyle = style;

    style = SeaGlassLookAndFeel.updateStyle(context, this);

    if (style != oldStyle) {
        titleSpacing = style.getInt(context, "InternalFrameTitlePane.titleSpacing", 2);
    }

    context.dispose();
}
 
Example #22
Source File: SeaGlassRootPaneUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * Update te control style.
 *
 * @param c the component.
 */
private void updateStyle(JComponent c) {
    SeaGlassContext context  = getContext(c, ENABLED);
    SynthStyle      oldStyle = style;

    style = SeaGlassLookAndFeel.updateStyle(context, this);
    if (style != oldStyle) {
        if (oldStyle != null) {
            uninstallKeyboardActions((JRootPane) c);
            installKeyboardActions((JRootPane) c);
        }
    }

    context.dispose();
}
 
Example #23
Source File: SeaGlassContext.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * The method used to get a context.
 *
 * @param  type      the class of the context.
 * @param  component the component.
 * @param  region    the region.
 * @param  style     the style.
 * @param  state     the state.
 *
 * @return the newly constructed context, corresponding to the arguments.
 */
public static SeaGlassContext getContext(Class type, JComponent component, Region region, SynthStyle style, int state) {
    SeaGlassContext context = null;

    synchronized (contextMap) {
        List instances = (List) contextMap.get(type);

        if (instances != null) {
            int size = instances.size();

            if (size > 0) {
                context = (SeaGlassContext) instances.remove(size - 1);
            }
        }
    }

    if (context == null) {

        try {
            context = (SeaGlassContext) type.newInstance();
        } catch (IllegalAccessException iae) {
            iae.printStackTrace();
        } catch (InstantiationException ie) {
            ie.printStackTrace();
        }
    }

    context.reset(component, region, style, state);

    return context;
}
 
Example #24
Source File: SeaGlassScrollBarUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
private SeaGlassContext getContext(JComponent c, Region region, int state) {
    SynthStyle style = trackStyle;

    if (region == Region.SCROLL_BAR_THUMB) {
        style = thumbStyle;
    } else if (region == SeaGlassRegion.SCROLL_BAR_CAP) {
        style = capStyle;
    }
    return SeaGlassContext.getContext(SeaGlassContext.class, c, region, style, state);
}
 
Example #25
Source File: SeaGlassTextFieldUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * DOCUMENT ME!
 *
 * @param c DOCUMENT ME!
 */
private void updateStyle(JTextComponent c) {
    SeaGlassContext context  = getContext(c, ENABLED);
    SynthStyle      oldStyle = style;

    SynthStyle s = SeaGlassLookAndFeel.updateStyle(context, this);
    if (s instanceof SeaGlassStyle) {
        style = (SeaGlassStyle) s;

        updateSearchStyle(c, context, getPropertyPrefix());

        if (style != oldStyle) {
            updateStyle(c, context, getPropertyPrefix());

            if (oldStyle != null) {
                uninstallKeyboardActions();
                installKeyboardActions();
            }
        }
    }
    
    context.dispose();

    context   = getContext(c, SeaGlassRegion.SEARCH_FIELD_FIND_BUTTON, ENABLED);
    findStyle = SeaGlassLookAndFeel.updateStyle(context, this);
    context.dispose();

    context     = getContext(c, SeaGlassRegion.SEARCH_FIELD_CANCEL_BUTTON, ENABLED);
    cancelStyle = SeaGlassLookAndFeel.updateStyle(context, this);
    context.dispose();
}
 
Example #26
Source File: NimbusLookAndFeel.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/** Called by UIManager when this look and feel is installed. */
@Override public void initialize() {
    super.initialize();
    defaults.initialize();
    // create synth style factory
    setStyleFactory(new SynthStyleFactory() {
        @Override
        public SynthStyle getStyle(JComponent c, Region r) {
            return defaults.getStyle(c, r);
        }
    });
}
 
Example #27
Source File: SeaGlassDesktopPaneUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
private void updateStyle(JDesktopPane c) {
    SynthStyle oldStyle = style;
    SeaGlassContext context = getContext(c, ENABLED);
    style = SeaGlassLookAndFeel.updateStyle(context, this);
    if (oldStyle != null) {
        uninstallKeyboardActions();
        installKeyboardActions();
    }
    context.dispose();
}
 
Example #28
Source File: SeaGlassMenuItemUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
private void updateStyle(JMenuItem mi) {
    SeaGlassContext context = getContext(mi, ENABLED);
    SynthStyle oldStyle = style;

    style = SeaGlassLookAndFeel.updateStyle(context, this);
    if (oldStyle != style) {
        String prefix = getPropertyPrefix();

        Object value = style.get(context, prefix + ".textIconGap");
        if (value != null) {
            LookAndFeel.installProperty(mi, "iconTextGap", value);
        }
        defaultTextIconGap = mi.getIconTextGap();

        if (menuItem.getMargin() == null || (menuItem.getMargin() instanceof UIResource)) {
            Insets insets = (Insets) style.get(context, prefix + ".margin");

            if (insets == null) {
                // Some places assume margins are non-null.
                insets = SeaGlassLookAndFeel.EMPTY_UIRESOURCE_INSETS;
            }
            menuItem.setMargin(insets);
        }
        acceleratorDelimiter = style.getString(context, prefix + ".acceleratorDelimiter", "+");

        arrowIcon = style.getIcon(context, prefix + ".arrowIcon");

        checkIcon = style.getIcon(context, prefix + ".checkIcon");
        if (oldStyle != null) {
            uninstallKeyboardActions();
            installKeyboardActions();
        }
    }
    context.dispose();

    SeaGlassContext accContext = getContext(mi, Region.MENU_ITEM_ACCELERATOR, ENABLED);

    accStyle = SeaGlassLookAndFeel.updateStyle(accContext, this);
    accContext.dispose();
}
 
Example #29
Source File: SeaGlassSliderUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
private SeaGlassContext getContext(JComponent c, Region subregion, int state) {
    SynthStyle style = null;
    Class klass = SeaGlassContext.class;

    if (subregion == Region.SLIDER_TRACK) {
        style = sliderTrackStyle;
    } else if (subregion == Region.SLIDER_THUMB) {
        style = sliderThumbStyle;
    }
    return SeaGlassContext.getContext(klass, c, subregion, style, state);
}
 
Example #30
Source File: NimbusDefaults.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Locate the style associated with the given region, and component.
 * This is called from NimbusLookAndFeel in the SynthStyleFactory
 * implementation.</p>
 *
 * <p>Lookup occurs as follows:<br/>
 * Check the map of styles <code>m</code>. If the map contains no styles at
 * all, then simply return the defaultStyle. If the map contains styles,
 * then iterate over all of the styles for the Region <code>r</code> looking
 * for the best match, based on prefix. If a match was made, then return
 * that SynthStyle. Otherwise, return the defaultStyle.</p>
 *
 * @param comp The component associated with this region. For example, if
 *        the Region is Region.Button then the component will be a JButton.
 *        If the Region is a subregion, such as ScrollBarThumb, then the
 *        associated component will be the component that subregion belongs
 *        to, such as JScrollBar. The JComponent may be named. It may not be
 *        null.
 * @param r The region we are looking for a style for. May not be null.
 */
SynthStyle getStyle(JComponent comp, Region r) {
    //validate method arguments
    if (comp == null || r == null) {
        throw new IllegalArgumentException(
                "Neither comp nor r may be null");
    }

    //if there are no lazy styles registered for the region r, then return
    //the default style
    List<LazyStyle> styles = m.get(r);
    if (styles == null || styles.size() == 0) {
        return defaultStyle;
    }

    //Look for the best SynthStyle for this component/region pair.
    LazyStyle foundStyle = null;
    for (LazyStyle s : styles) {
        if (s.matches(comp)) {
            //replace the foundStyle if foundStyle is null, or
            //if the new style "s" is more specific (ie, its path was
            //longer), or if the foundStyle was "simple" and the new style
            //was not (ie: the foundStyle was for something like Button and
            //the new style was for something like "MyButton", hence, being
            //more specific.) In all cases, favor the most specific style
            //found.
            if (foundStyle == null ||
               (foundStyle.parts.length < s.parts.length) ||
               (foundStyle.parts.length == s.parts.length 
                && foundStyle.simple && !s.simple)) {
                foundStyle = s;
            }
        }
    }

    //return the style, if found, or the default style if not found
    return foundStyle == null ? defaultStyle : foundStyle.getStyle(comp, r);
}