下面列出了javax.swing.plaf.synth.SynthLookAndFeel#getStyle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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;
}
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();
}
private static void testSynthIcon() {
if (!checkAndSetNimbusLookAndFeel()) {
return;
}
JMenuItem menu = new JMenuItem();
Icon subMenuIcon = UIManager.getIcon("Menu.arrowIcon");
if (!(subMenuIcon instanceof SynthIcon)) {
throw new RuntimeException("Icon is not a SynthIcon!");
}
Region region = SynthLookAndFeel.getRegion(menu);
SynthStyle style = SynthLookAndFeel.getStyle(menu, region);
SynthContext synthContext = new SynthContext(menu, region, style, SynthConstants.ENABLED);
int width = SynthGraphicsUtils.getIconWidth(subMenuIcon, synthContext);
int height = SynthGraphicsUtils.getIconHeight(subMenuIcon, synthContext);
paintAndCheckIcon(subMenuIcon, synthContext, width, height);
int newWidth = width * 17;
int newHeight = height * 37;
Icon centeredIcon = new CenteredSynthIcon((SynthIcon) subMenuIcon,
newWidth, newHeight);
paintAndCheckIcon(centeredIcon, synthContext, newWidth, newHeight);
}
private static void patchOptionPaneIcons(final UIDefaults defaults) {
if (UIUtil.isUnderGTKLookAndFeel() && defaults.get(ourOptionPaneIconKeys[0]) == null) {
// GTK+ L&F keeps icons hidden in style
final SynthStyle style = SynthLookAndFeel.getStyle(new JOptionPane(""), Region.DESKTOP_ICON);
if (style != null) {
for (final String key : ourOptionPaneIconKeys) {
final Object icon = style.get(null, key);
if (icon != null) defaults.put(key, icon);
}
}
}
}
private Insets getSynthInsets(Region region) {
SynthStyle style = SynthLookAndFeel.getStyle(this, region);
SynthContext context = new SynthContext(this, region, style, SynthConstants.ENABLED);
return style.getInsets(context, null);
}
private Insets getSynthInsets(Region region) {
SynthStyle style = SynthLookAndFeel.getStyle(this, region);
SynthContext context = new SynthContext(this, region, style, SynthConstants.ENABLED);
return style.getInsets(context, null);
}
private static SynthStyle getSynthStyle (Region region) {
return SynthLookAndFeel.getStyle(getDummyButton(), region);
}
private Insets getSynthInsets(Region region) {
SynthStyle style = SynthLookAndFeel.getStyle(this, region);
SynthContext context = new SynthContext(this, region, style, SynthConstants.ENABLED);
return style.getInsets(context, null);
}
private Insets getSynthInsets(Region region) {
SynthStyle style = SynthLookAndFeel.getStyle(this, region);
SynthContext context = new SynthContext(this, region, style, SynthConstants.ENABLED);
return style.getInsets(context, null);
}
private Insets getSynthInsets(Region region) {
SynthStyle style = SynthLookAndFeel.getStyle(this, region);
SynthContext context = new SynthContext(this, region, style, SynthConstants.ENABLED);
return style.getInsets(context, null);
}
/**
* Gets the style associated with the given component and region. This
* will never return null. If an appropriate component and region cannot
* be determined, then a default style is returned.
*
* @param c a non-null reference to a JComponent
* @param r a non-null reference to the region of the component c
* @return a non-null reference to a NimbusStyle.
*/
public static NimbusStyle getStyle(JComponent c, Region r) {
return (NimbusStyle)SynthLookAndFeel.getStyle(c, r);
}
/**
* Gets the style associated with the given component and region. This
* will never return null. If an appropriate component and region cannot
* be determined, then a default style is returned.
*
* @param c a non-null reference to a JComponent
* @param r a non-null reference to the region of the component c
* @return a non-null reference to a NimbusStyle.
*/
public static NimbusStyle getStyle(JComponent c, Region r) {
return (NimbusStyle)SynthLookAndFeel.getStyle(c, r);
}
/**
* Gets the style associated with the given component and region. This
* will never return null. If an appropriate component and region cannot
* be determined, then a default style is returned.
*
* @param c a non-null reference to a JComponent
* @param r a non-null reference to the region of the component c
* @return a non-null reference to a NimbusStyle.
*/
public static NimbusStyle getStyle(JComponent c, Region r) {
return (NimbusStyle)SynthLookAndFeel.getStyle(c, r);
}
/**
* Gets the style associated with the given component and region. This
* will never return null. If an appropriate component and region cannot
* be determined, then a default style is returned.
*
* @param c a non-null reference to a JComponent
* @param r a non-null reference to the region of the component c
* @return a non-null reference to a NimbusStyle.
*/
public static NimbusStyle getStyle(JComponent c, Region r) {
return (NimbusStyle)SynthLookAndFeel.getStyle(c, r);
}
/**
* Gets the style associated with the given component and region. This
* will never return null. If an appropriate component and region cannot
* be determined, then a default style is returned.
*
* @param c a non-null reference to a JComponent
* @param r a non-null reference to the region of the component c
* @return a non-null reference to a NimbusStyle.
*/
public static NimbusStyle getStyle(JComponent c, Region r) {
return (NimbusStyle)SynthLookAndFeel.getStyle(c, r);
}
/**
* Gets the style associated with the given component and region. This
* will never return null. If an appropriate component and region cannot
* be determined, then a default style is returned.
*
* @param c a non-null reference to a JComponent
* @param r a non-null reference to the region of the component c
* @return a non-null reference to a NimbusStyle.
*/
public static NimbusStyle getStyle(JComponent c, Region r) {
return (NimbusStyle)SynthLookAndFeel.getStyle(c, r);
}
/**
* Gets the style associated with the given component and region. This
* will never return null. If an appropriate component and region cannot
* be determined, then a default style is returned.
*
* @param c a non-null reference to a JComponent
* @param r a non-null reference to the region of the component c
* @return a non-null reference to a NimbusStyle.
*/
public static NimbusStyle getStyle(JComponent c, Region r) {
return (NimbusStyle)SynthLookAndFeel.getStyle(c, r);
}
/**
* Gets the style associated with the given component and region. This
* will never return null. If an appropriate component and region cannot
* be determined, then a default style is returned.
*
* @param c a non-null reference to a JComponent
* @param r a non-null reference to the region of the component c
* @return a non-null reference to a NimbusStyle.
*/
public static NimbusStyle getStyle(JComponent c, Region r) {
return (NimbusStyle)SynthLookAndFeel.getStyle(c, r);
}
/**
* Gets the style associated with the given component and region. This
* will never return null. If an appropriate component and region cannot
* be determined, then a default style is returned.
*
* @param c a non-null reference to a JComponent
* @param r a non-null reference to the region of the component c
* @return a non-null reference to a NimbusStyle.
*/
public static NimbusStyle getStyle(JComponent c, Region r) {
return (NimbusStyle)SynthLookAndFeel.getStyle(c, r);
}
/**
* Gets the style associated with the given component and region. This
* will never return null. If an appropriate component and region cannot
* be determined, then a default style is returned.
*
* @param c a non-null reference to a JComponent
* @param r a non-null reference to the region of the component c
* @return a non-null reference to a NimbusStyle.
*/
public static NimbusStyle getStyle(JComponent c, Region r) {
return (NimbusStyle)SynthLookAndFeel.getStyle(c, r);
}